lsst.pipe.tasks  18.0.0-7-g4840a288+4
ingestDefects.py
Go to the documentation of this file.
1 from .ingestCalibs import IngestCalibsTask
2 from .read_defects import read_all_defects
3 from lsst.pipe.base import InputOnlyArgumentParser
4 
5 import tempfile
6 import shutil
7 import os
8 
9 
10 class IngestDefectsArgumentParser(InputOnlyArgumentParser):
11  """Argument parser to support ingesting calibration images into the repository"""
12 
13  def __init__(self, *args, **kwargs):
14  InputOnlyArgumentParser.__init__(self, *args, **kwargs)
15  self.add_argument("-n", "--dry-run", dest="dryrun", action="store_true",
16  default=False, help="Don't perform any action?")
17  self.add_argument("--create", action="store_true", help="Create new registry?")
18  self.add_argument("--ignore-ingested", dest="ignoreIngested", action="store_true",
19  help="Don't register files that have already been registered")
20  self.add_argument("root", help="Root directory to scan for defects.")
21 
22 
24  """Task that generates registry for calibration images"""
25  ArgumentParser = IngestDefectsArgumentParser
26  _DefaultName = "ingestDefects"
27 
28  def run(self, args):
29  """Ingest all defect files and add them to the registry"""
30 
31  try:
32  camera = args.butler.get('camera')
33  temp_dir = tempfile.mkdtemp()
34  defects = read_all_defects(args.root, camera)
35  file_names = []
36  for d in defects:
37  for s in defects[d]:
38  file_name = f'defects_{d}_{s.isoformat()}.fits'
39  full_file_name = os.path.join(temp_dir, file_name)
40  self.log.info('%i defects written for sensor: %s and calibDate: %s' %
41  (len(defects[d][s]), d, s.isoformat()))
42  defects[d][s].writeFits(full_file_name)
43  file_names.append(full_file_name)
44  args.files = file_names
45  args.mode = 'move'
46  args.validity = None # Validity range is determined from the files
47  IngestCalibsTask.run(self, args)
48  except Exception:
49  raise(Exception)
50  finally:
51  shutil.rmtree(temp_dir)
def read_all_defects(root, camera)
Definition: read_defects.py:77