Skip to content

Commit 2636313

Browse files
authored
BUG fix galsim random seeding again (#28)
* BUG fix galsim random seeding again * Update des_tile.py * Update des_tile.py * ENH allow for missing truth data * ENH more carveouts for missing truth data
1 parent cc0df22 commit 2636313

File tree

2 files changed

+66
-59
lines changed

2 files changed

+66
-59
lines changed

montara/des_tile.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,10 @@ def setup(self, config, base, file_num, logger):
626626
if not isinstance(rs, list):
627627
first = galsim.config.ParseValue(
628628
base['image'], 'random_seed', base, int)[0]
629+
630+
# launder through the RNG to randomize
631+
first = galsim.BaseDeviate(first).raw()
632+
629633
base['image']['random_seed'] = []
630634
# The first one is the original random_seed specification,
631635
# used for noise, since that should be different for each band,

montara/eastlake_step.py

Lines changed: 62 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -370,70 +370,73 @@ def _write_truth(self, fnames, tilename, base_dir, stash, bands):
370370
else:
371371
self.logger.warning("skipped zero-length truth file %r", fname)
372372

373-
if len(data) == 0:
373+
if len(data) == 0 and self.config["output"].get("n_se_test", None) is None:
374374
raise RuntimeError(
375375
"No objects drawn for tile %s when using a grid!" % tilename
376376
)
377377

378-
data = np.concatenate(data)
379-
data = np.sort(data, order=["id", "band"])
378+
if len(data) > 0:
379+
data = np.concatenate(data)
380+
data = np.sort(data, order=["id", "band"])
380381

381-
# we'll stash this for later
382-
truth_filename = os.path.join(
383-
base_dir,
384-
"truth_files",
385-
"%s-truthfile.fits" % tilename,
386-
)
387-
safe_mkdir(os.path.dirname(truth_filename))
388-
self.logger.error(
389-
"writing truth data to %s" % truth_filename)
390-
fitsio.write(truth_filename, data, clobber=True)
391-
stash.set_filepaths("truth_file",
392-
truth_filename,
393-
tilename)
394-
for fname in fnames:
395-
safe_rm(fname)
396-
397-
# now combine by band to make true positions files
398-
uids, uinds = np.unique(data["id"], return_index=True)
399-
n_pos_data = len(uids)
400-
_pos_data = np.zeros(
401-
n_pos_data,
402-
dtype=[
403-
('ra', 'f8'), ('dec', 'f8'),
404-
('x', 'f8'), ('y', 'f8'),
405-
('id', 'i8'),
406-
] + [(f"mag_{b}", "f8") for b in bands],
407-
)
408-
_pos_data['id'] = data['id'][uinds]
409-
_pos_data['ra'] = data['ra'][uinds]
410-
_pos_data['dec'] = data['dec'][uinds]
411-
_pos_data['x'] = data['x_coadd'][uinds]
412-
_pos_data['y'] = data['y_coadd'][uinds]
413-
_pos_data = np.sort(_pos_data, order="id")
414-
415-
for band in bands:
416-
mskb = data["band"] == band
417-
assert np.any(mskb)
418-
bdata = data[mskb]
419-
inds = np.searchsorted(_pos_data["id"], bdata["id"])
420-
assert np.array_equal(_pos_data["id"][inds], bdata["id"])
421-
_pos_data[f"mag_{band}"][:] = np.nan
422-
_pos_data[f"mag_{band}"][inds] = bdata["mag"]
423-
424-
# we'll stash this for later
425-
truepos_filename = os.path.join(
426-
base_dir,
427-
"true_positions",
428-
"%s-truepositions.fits" % tilename,
429-
)
430-
safe_mkdir(os.path.dirname(truepos_filename))
431-
self.logger.error(
432-
"writing true position data to %s" % truepos_filename)
433-
fitsio.write(truepos_filename, _pos_data, clobber=True)
434-
stash.set_filepaths("truepositions_file",
435-
truepos_filename,
436-
tilename)
382+
# we'll stash this for later
383+
truth_filename = os.path.join(
384+
base_dir,
385+
"truth_files",
386+
"%s-truthfile.fits" % tilename,
387+
)
388+
safe_mkdir(os.path.dirname(truth_filename))
389+
self.logger.error(
390+
"writing truth data to %s" % truth_filename)
391+
fitsio.write(truth_filename, data, clobber=True)
392+
stash.set_filepaths("truth_file",
393+
truth_filename,
394+
tilename)
395+
for fname in fnames:
396+
safe_rm(fname)
397+
398+
# now combine by band to make true positions files
399+
uids, uinds = np.unique(data["id"], return_index=True)
400+
n_pos_data = len(uids)
401+
_pos_data = np.zeros(
402+
n_pos_data,
403+
dtype=[
404+
('ra', 'f8'), ('dec', 'f8'),
405+
('x', 'f8'), ('y', 'f8'),
406+
('id', 'i8'),
407+
] + [(f"mag_{b}", "f8") for b in bands],
408+
)
409+
_pos_data['id'] = data['id'][uinds]
410+
_pos_data['ra'] = data['ra'][uinds]
411+
_pos_data['dec'] = data['dec'][uinds]
412+
_pos_data['x'] = data['x_coadd'][uinds]
413+
_pos_data['y'] = data['y_coadd'][uinds]
414+
_pos_data = np.sort(_pos_data, order="id")
415+
416+
for band in bands:
417+
mskb = data["band"] == band
418+
if self.config["output"].get("n_se_test", None) is None:
419+
assert np.any(mskb)
420+
if np.any(mskb):
421+
bdata = data[mskb]
422+
inds = np.searchsorted(_pos_data["id"], bdata["id"])
423+
assert np.array_equal(_pos_data["id"][inds], bdata["id"])
424+
_pos_data[f"mag_{band}"][:] = np.nan
425+
_pos_data[f"mag_{band}"][inds] = bdata["mag"]
426+
427+
# we'll stash this for later
428+
truepos_filename = os.path.join(
429+
base_dir,
430+
"true_positions",
431+
"%s-truepositions.fits" % tilename,
432+
)
433+
safe_mkdir(os.path.dirname(truepos_filename))
434+
self.logger.error(
435+
"writing true position data to %s" % truepos_filename)
436+
fitsio.write(truepos_filename, _pos_data, clobber=True)
437+
stash.set_filepaths("truepositions_file",
438+
truepos_filename,
439+
tilename)
437440

438441
@classmethod
439442
def from_config_file(cls, config_file, logger=None):

0 commit comments

Comments
 (0)