Skip to content

Commit 7bdae5d

Browse files
authored
ENH save truth (#18)
* ENH save truth * Update eastlake_step.py (#19)
1 parent 45fb783 commit 7bdae5d

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

montara/eastlake_step.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import eastlake
1010

1111
from eastlake.step import Step
12-
from .utils import safe_mkdir, get_truth_from_image_file
12+
from .utils import safe_mkdir, get_truth_from_image_file, safe_rm
1313
from eastlake.rejectlist import RejectList
1414
from eastlake.des_files import read_pizza_cutter_yaml
1515

@@ -352,7 +352,25 @@ def _write_truth(self, fnames, tilename, base_dir, stash, bands):
352352
)
353353

354354
data = np.concatenate(data)
355-
data = np.sort(data, order="id")
355+
data = np.sort(data, order=["id", "band"])
356+
357+
# we'll stash this for later
358+
truth_filename = os.path.join(
359+
base_dir,
360+
"truth_files",
361+
"%s-truthfile.fits" % tilename,
362+
)
363+
safe_mkdir(os.path.dirname(truth_filename))
364+
self.logger.error(
365+
"writing truth data to %s" % truth_filename)
366+
fitsio.write(truth_filename, data, clobber=True)
367+
stash.set_filepaths("truth_file",
368+
truth_filename,
369+
tilename)
370+
for fname in fnames:
371+
safe_rm(fname)
372+
373+
# now combine by band to make true positions files
356374
uids, uinds = np.unique(data["id"], return_index=True)
357375
n_pos_data = len(uids)
358376
_pos_data = np.zeros(

montara/utils.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@
55
import numpy as np
66

77

8+
def safe_rm(pth, verbose=False):
9+
try:
10+
os.remove(pth)
11+
except Exception as e:
12+
if verbose:
13+
print("removing file %s failed w/ error %r" % (pth, e))
14+
pass
15+
16+
817
def safe_mkdir(d):
918
try:
1019
os.makedirs(d)

0 commit comments

Comments
 (0)