Skip to content

Commit

Permalink
Merge 51fb642 into c7654ac
Browse files Browse the repository at this point in the history
  • Loading branch information
jchiang87 committed Aug 5, 2019
2 parents c7654ac + 51fb642 commit 2a83adc
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
7 changes: 6 additions & 1 deletion bin.src/imsim.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@
"This will be prepended to any existing IMSIM_IMAGE_PATH "
"environment variable, for which $CWD is included by "
"default.")
parser.add_argument('--ckpt_archive_dir', type=str, default=None,
help="Archive directory for checkpoint files. "
"If None, then delete them (if the checkpointing.cleanup "
"configuration is True).")

args = parser.parse_args()

Expand Down Expand Up @@ -89,6 +93,7 @@
apply_sensor_model=apply_sensor_model,
create_centroid_file=args.create_centroid_file,
file_id=args.file_id,
log_level=args.log_level)
log_level=args.log_level,
ckpt_archive_dir=args.ckpt_archive_dir)

image_simulator.run(processes=args.processes)
27 changes: 22 additions & 5 deletions python/desc/imsim/ImageSimulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ class ImageSimulator:
"""
def __init__(self, instcat, psf, numRows=None, config=None, seed=267,
outdir='fits', sensor_list=None, apply_sensor_model=True,
create_centroid_file=False, file_id=None, log_level='WARN'):
create_centroid_file=False, file_id=None, log_level='WARN',
ckpt_archive_dir=None):
"""
Parameters
----------
Expand Down Expand Up @@ -80,6 +81,12 @@ def __init__(self, instcat, psf, numRows=None, config=None, seed=267,
If None, then no checkpoint file will be used
log_level: str ['WARN']
Logging level ('DEBUG', 'INFO', 'WARN', 'ERROR', 'CRITICAL').
ckpt_archive_dir: str [None]
If this is not None, then after a sensor-visit has written
its output FITS file(s), the associated checkpoint file will
be moved to this directory instead of deleted. If set to
`None`, then delete the checkpoint file (assuming the
`checkpointing.cleanup` config parameter is True).
"""
self.config = read_config(config)
self.log_level = log_level
Expand All @@ -103,6 +110,10 @@ def __init__(self, instcat, psf, numRows=None, config=None, seed=267,
self._make_gs_interpreters(seed, sensor_list, file_id)
self.log_level = log_level
self.logger = get_logger(self.log_level, name='ImageSimulator')
self.ckpt_archive_dir = ckpt_archive_dir
if (self.ckpt_archive_dir is not None and
not os.path.isdir(self.ckpt_archive_dir)):
os.makedirs(self.ckpt_archive_dir)

def _gather_checkpoint_files(self, sensor_list, file_id=None):
"""
Expand Down Expand Up @@ -423,13 +434,19 @@ def __call__(self, gs_objects):
# Write out the centroid files if they were made.
gs_interpreter.write_centroid_files()

# The image for the sensor-visit has been drawn, so delete any
# existing checkpoint file if the config says to do so.
# The image for the sensor-visit has been drawn, so delete or
# move to the archive area any existing checkpoint file if the
# config says perform the cleanup.
if (gs_interpreter.checkpoint_file is not None
and os.path.isfile(gs_interpreter.checkpoint_file)
and IMAGE_SIMULATOR.config['checkpointing']['cleanup']):
os.remove(gs_interpreter.checkpoint_file)

if IMAGE_SIMULATOR.ckpt_archive_dir is None:
os.remove(gs_interpreter.checkpoint_file)
else:
src_file = gs_interpreter.checkpoint_file
dest_file = os.path.join(IMAGE_SIMULATOR.ckpt_archive_dir,
os.path.basename(src_file))
shutil.move(src_file, dest_file)
# Remove reference to gs_interpreter in order to recover the
# memory associated with that object.
IMAGE_SIMULATOR.gs_interpreters[self.sensor_name] = None
Expand Down

0 comments on commit 2a83adc

Please sign in to comment.