Skip to content

Commit

Permalink
Merge pull request #62 from lsst-camera-dh/LSSTTD-1449_skip_bad_data
Browse files Browse the repository at this point in the history
Lssttd 1449 skip bad data
  • Loading branch information
jchiang87 authored Nov 3, 2019
2 parents e12aa3d + 5023772 commit 74bafc5
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions harnessed_jobs/BOT_acq_recovery/v0/producer_BOT_acq_recovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,34 @@
# lcatr.cfg.
acq_run = os.environ['LCATR_ACQ_RUN']

# Get any bad frames from a text file specified in lcatr.cfg.
try:
with open(os.environ['LCATR_BAD_FRAME_LIST'], 'r') as fd:
bad_frames = [_.strip() for _ in fd]
except KeyError:
bad_frames = []

staging_dir = os.path.join(os.environ['LCATR_STAGE_ROOT'],
siteUtils.getUnitType(), siteUtils.getUnitId())
outdir = '.'
acqs_dir = os.path.join(staging_dir, acq_run, 'BOT_acq', 'v0')
job_id_dirs = sorted(glob.glob(os.path.join(acqs_dir, '[0-9]*')), reverse=True)
for job_id_dir in job_id_dirs:
items = glob.glob(os.path.join(job_id_dir, '*'))
for item in items:
dest = os.path.join(outdir, os.path.basename(item))
if ((os.path.islink(item) or item.endswith('.cfg'))
frame_dirs = glob.glob(os.path.join(job_id_dir, '*'))
for frame_dir in frame_dirs:
dest = os.path.join(outdir, os.path.basename(frame_dir))
if ((os.path.islink(frame_dir) or frame_dir.endswith('.cfg'))
and not os.path.lexists(dest)):
shutil.copyfile(item, dest, follow_symlinks=False)
shutil.copyfile(frame_dir, dest, follow_symlinks=False)

# Delete any folders with bad data
for bad_frame in bad_frames:
fits_images = []
for bad_frame in bad_frames:
pattern = os.path.join('*', f'*{bad_frame}*.fits')
fits_images.extend(glob.glob(pattern))
bad_symlinks = set([os.path.dirname(_) for _ in fits_images])
for bad_symlink in bad_symlinks:
os.remove(bad_symlink)

pathlib.Path('PRESERVE_SYMLINKS').touch()

0 comments on commit 74bafc5

Please sign in to comment.