Skip to content

Commit 677d110

Browse files
Merge pull request #696 from martinkilbinger/get_ccds
Get ccd list
2 parents aba5ffd + c40c58c commit 677d110

File tree

4 files changed

+206
-7
lines changed

4 files changed

+206
-7
lines changed

example/cfis/final_cat.param

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ NGMIX_MCAL_FLAGS
1515
NGMIX_ELL_PSFo_NOSHEAR
1616

1717
# spread class
18-
SPREAD_CLASS
18+
#SPREAD_CLASS
1919

2020
# spread model flag and error
21-
SPREAD_MODEL
22-
SPREADERR_MODEL
21+
#SPREAD_MODEL
22+
#SPREADERR_MODEL
2323

2424
# Number of epochs (exposures)
2525
N_EPOCH

scripts/python/check_nobj_ngmix_mc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ def get_naxis2_value(file_path):
8787
# Check run time of 128, 256, and 512 jobs
8888
if (
8989
os.path.getmtime(ngmix_file) > os.path.getmtime(mc_file)
90-
or os.path.getmtime(mc_file) > os.path.getmtime(sep_ngmix_file)
90+
or os.path.getmtime(mc_file) < os.path.getmtime(sep_ngmix_file)
9191
):
92-
print("{ID} -- mc, sep, and/or merged ngmix file out of order")
92+
print(f"{ID} -- mc, sep, and/or merged ngmix file out of order")
9393

9494
# Compare values and output ID if they differ
9595
elif ngmix_naxis2 != sep_naxis2:
Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
#!/usr/bin/env python3
2+
3+
"""GET_CCDS_WITH_PSF
4+
5+
Obtain list of CCDs (single-exposure single-HDU files) for which valid PSF information
6+
is available. This can serve to create a footprint coverage mask.
7+
8+
Author: Martin Kilbinger <martin.kilbinger@cea.fr>
9+
10+
"""
11+
12+
13+
import sys
14+
import numpy as np
15+
16+
from shapepipe.utilities import summary
17+
18+
19+
def get_lines(fname):
20+
"""Get Lines.
21+
22+
Return list of lines read from a text file.
23+
24+
Parameters
25+
----------
26+
fname: str
27+
input file name
28+
29+
Returns:
30+
list
31+
IDs
32+
33+
"""
34+
IDs = []
35+
with open(fname) as f:
36+
lines = f.readlines()
37+
for line in lines:
38+
IDs.append(line.rstrip())
39+
40+
return IDs
41+
42+
43+
def get_exp_shdu_missing(patches):
44+
"""Get Exp Shdu Missing.
45+
46+
Returns set of missing CCDs (single-exposure single-HDU IDs) from a list of patches.
47+
48+
Parameters
49+
----------
50+
patches: list
51+
input patches
52+
53+
Returns
54+
-------
55+
set
56+
missing CCD IDs
57+
58+
"""
59+
exp_shdu_missing_all = set()
60+
61+
for patch in patches:
62+
63+
path_exp_shdu_missing = f"{patch}/summary/missing_job_32_all.txt"
64+
exp_shdu_missing = get_lines(path_exp_shdu_missing)
65+
66+
print(f"Patch {patch}: Found {len(exp_shdu_missing)} missing ccds", end="; ")
67+
68+
exp_shdu_missing_all.update(exp_shdu_missing)
69+
70+
print(f"cumulative {len(exp_shdu_missing_all)} missing ccds")
71+
72+
print()
73+
74+
return exp_shdu_missing_all
75+
76+
77+
def get_exp(patches):
78+
"""Get Exp.
79+
80+
Return set of exposures from a list of patches.
81+
82+
Parameters
83+
----------
84+
patches: list
85+
input patches
86+
87+
Returns
88+
-------
89+
set
90+
exposure IDs
91+
92+
"""
93+
exp_all = set()
94+
95+
for patch in patches:
96+
97+
path_exp = f"{patch}/exp_numbers.txt"
98+
exp = get_lines(path_exp)
99+
100+
print(f"Patch {patch}: Found {len(exp)} exposures", end="; ")
101+
102+
exp_all.update(exp)
103+
104+
print(f"cumulative {len(exp_all)} exposures")
105+
106+
print()
107+
108+
return exp_all
109+
110+
111+
def get_ccds_with_psf(patches, n_CCD=40):
112+
"""Get CCDs With PSF.
113+
114+
Return set of CCDs from list of patches.
115+
116+
Parameters
117+
----------
118+
patches: list
119+
input patches
120+
121+
Returns
122+
-------
123+
set
124+
CCD IDs
125+
126+
"""
127+
# Get missing CCDs
128+
print("=== get missing CCDs ===")
129+
exp_shdu_missing_all = get_exp_shdu_missing(patches)
130+
131+
# Get all exposures used in tiles
132+
print("=== get exposures ===")
133+
exp_all = get_exp(patches)
134+
135+
# Turn exposures into exposure-single-HDU names (CCDs)
136+
exp_shdu_all = summary.get_all_shdus(exp_all, n_CCD)
137+
138+
print(f"Found {len(exp_shdu_all)} CCDs")
139+
140+
return exp_shdu_all
141+
142+
143+
def get_ccds_with_psf_method_2(patches, n_CCD=40):
144+
145+
for patch in patches:
146+
directory = f"{patch}/exp_runs"
147+
148+
for entry in os.scandir(directory):
149+
pass
150+
151+
def save(IDs, path):
152+
"""Save.
153+
154+
Save list of IDs to text file.
155+
156+
Parameters
157+
----------
158+
IDs: set
159+
input IDs
160+
161+
path: str
162+
output file name
163+
164+
"""
165+
with open(path, "w") as f_out:
166+
for ID in IDs:
167+
print(ID, file=f_out)
168+
169+
def main(argv):
170+
"""Main.
171+
172+
Main program.
173+
174+
"""
175+
version = "v1.5"
176+
177+
if version == "v1.4":
178+
n_patch = 7
179+
elif version == "v1.5":
180+
n_patch = 8
181+
else:
182+
raise ValueError(f"Invalid version {version}")
183+
184+
patches = [f'P{x}' for x in np.arange(n_patch) + 1]
185+
186+
print(f"=== get_ccds_with_psf for version {version}, patches {patches} ===")
187+
188+
print("=== method 1: exp_list - missing === ")
189+
exp_shdu_all = get_ccds_with_psf(patches)
190+
191+
save(exp_shdu_all, f"ccds_with_psf_{version}.txt")
192+
193+
#print("=== method 2: star cats === ")
194+
#exp_shdu_all_method_2 = get_ccds_with_psf_method_2(patches)
195+
#save(exp_shdu_all_method_2, f"ccds_with_psf_{version}_method_2.txt")
196+
197+
return 0
198+
199+
200+
if __name__ == "__main__":
201+
sys.exit(main(sys.argv))

src/shapepipe/utilities/summary.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515

1616
from tqdm import tqdm
1717

18-
print("summary v1.5")
19-
2018

2119
def init_par_runtime(list_tile_IDs):
2220

0 commit comments

Comments
 (0)