LSSTApplications  19.0.0-10-g920eed2,19.0.0-11-g48a0200+2,19.0.0-18-gfc4e62b+13,19.0.0-2-g3b2f90d+2,19.0.0-2-gd671419+5,19.0.0-20-g5a5a17ab+11,19.0.0-21-g2644856+13,19.0.0-23-g84eeccb+1,19.0.0-24-g878c510+1,19.0.0-25-g6c8df7140,19.0.0-25-gb330496+1,19.0.0-3-g2b32d65+5,19.0.0-3-g8227491+12,19.0.0-3-g9c54d0d+12,19.0.0-3-gca68e65+8,19.0.0-3-gcfc5f51+5,19.0.0-3-ge110943+11,19.0.0-3-ge74d124,19.0.0-3-gfe04aa6+13,19.0.0-30-g9c3fd16+1,19.0.0-4-g06f5963+5,19.0.0-4-g3d16501+13,19.0.0-4-g4a9c019+5,19.0.0-4-g5a8b323,19.0.0-4-g66397f0+1,19.0.0-4-g8278b9b+1,19.0.0-4-g8557e14,19.0.0-4-g8964aba+13,19.0.0-4-ge404a01+12,19.0.0-5-g40f3a5a,19.0.0-5-g4db63b3,19.0.0-5-gfb03ce7+13,19.0.0-6-gbaebbfb+12,19.0.0-61-gec4c6e08+1,19.0.0-7-g039c0b5+11,19.0.0-7-gbea9075+4,19.0.0-7-gc567de5+13,19.0.0-71-g41c0270,19.0.0-9-g2f02add+1,19.0.0-9-g463f923+12,w.2020.22
LSSTDataManagementBasePackage
ingestCalibs.py
Go to the documentation of this file.
1 
2 import collections.abc
3 import re
4 from lsst.pipe.tasks.ingestCalibs import CalibsParseTask
5 
6 __all__ = ["DecamCalibsParseTask"]
7 
8 
10 
11  def getInfo(self, filename):
12  """Get information about the image from the filename and/or its contents.
13 
14  Parameters
15  ----------
16  filename: `str`
17  Name of file to inspect.
18 
19  Returns
20  -------
21  phuInfo : `dict`
22  Primary header unit info.
23  infoList : `list` of `dict`
24  File properties; list of file properties for each extension.
25  """
26  phuInfo, infoList = CalibsParseTask.getInfo(self, filename)
27  # Single-extension fits without EXTNAME can be a valid CP calibration product
28  # Use info of primary header unit
29  if not infoList:
30  infoList.append(phuInfo)
31  for info in infoList:
32  info['path'] = filename
33  # Try to fetch a date from filename
34  # and use as the calibration dates if not already set
35  found = re.search(r'(\d\d\d\d-\d\d-\d\d)', filename)
36  for item in infoList:
37  try:
38  item['calib_hdu'] = item['hdu']
39  except KeyError: # workaround for pre- DM-19730 defect ingestion
40  item['calib_hdu'] = 1
41  if not found:
42  return phuInfo, infoList
43  date = found.group(1)
44  for info in infoList:
45  if 'calibDate' not in info or info['calibDate'] == "unknown":
46  info['calibDate'] = date
47  return phuInfo, infoList
48 
49  def _translateFromCalibId(self, field, md):
50  """Fetch the ID from the CALIB_ID header.
51 
52  Calibration products made with constructCalibs have some metadata
53  saved in its FITS header CALIB_ID.
54  """
55  data = md.getScalar("CALIB_ID")
56  match = re.search(r".*%s=(\S+)" % field, data)
57  return match.groups()[0]
58 
59  def translate_ccdnum(self, md):
60  """Return CCDNUM as a integer.
61 
62  Parameters
63  ----------
64  md : `lsst.daf.base.PropertySet`
65  FITS header metadata.
66  """
67  if md.exists("CCDNUM"):
68  ccdnum = md.getScalar("CCDNUM")
69  else:
70  return self._translateFromCalibId("ccdnum", md)
71  # Some MasterCal from NOAO Archive has 2 CCDNUM keys in each HDU
72  # Make sure only one integer is returned.
73  if isinstance(ccdnum, collections.abc.Sequence):
74  try:
75  ccdnum = ccdnum[0]
76  except IndexError:
77  ccdnum = None
78  return ccdnum
79 
80  def translate_date(self, md):
81  """Extract the date as a strong in format YYYY-MM-DD from the FITS header DATE-OBS.
82  Return "unknown" if the value cannot be found or converted.
83 
84  Parameters
85  ----------
86  md : `lsst.daf.base.PropertySet`
87  FITS header metadata.
88  """
89  if md.exists("DATE-OBS"):
90  date = md.getScalar("DATE-OBS")
91  found = re.search(r'(\d\d\d\d-\d\d-\d\d)', date)
92  if found:
93  date = found.group(1)
94  else:
95  self.log.warn("DATE-OBS does not match format YYYY-MM-DD")
96  date = "unknown"
97  elif md.exists("CALIB_ID"):
98  date = self._translateFromCalibId("calibDate", md)
99  else:
100  date = "unknown"
101  return date
102 
103  def translate_filter(self, md):
104  """Extract the filter name.
105 
106  Translate a full filter description into a mere filter name.
107  Return "unknown" if the keyword FILTER does not exist in the header,
108  which can happen for some valid Community Pipeline products.
109 
110  Parameters
111  ----------
112  md : `lsst.daf.base.PropertySet`
113  FITS header metadata.
114  """
115  if md.exists("FILTER"):
116  if md.exists("OBSTYPE") and "zero" in md.getScalar("OBSTYPE").strip().lower():
117  return "NONE"
118  return CalibsParseTask.translate_filter(self, md)
119  elif md.exists("CALIB_ID"):
120  return self._translateFromCalibId("filter", md)
121  else:
122  return "unknown"
123 
124  @staticmethod
126  """Get the name of the extension.
127 
128  Parameters
129  ----------
130  md : `lsst.daf.base.PropertySet`
131  FITS header metadata.
132 
133  Returns
134  -------
135  result : `str`
136  The string from the EXTNAME header card.
137  """
138  return md.getScalar('EXTNAME')
139 
140  def getDestination(self, butler, info, filename):
141  """Get destination for the file.
142 
143  Parameters
144  ----------
145  butler : `lsst.daf.persistence.Butler`
146  Data butler.
147  info : data ID
148  File properties, used as dataId for the butler.
149  filename : `str`
150  Input filename.
151 
152  Returns
153  -------
154  raw : `str`
155  Destination filename.
156  """
157  # Arbitrarily set ccdnum and calib_hdu to 1 to make the mapper template happy
158  info["ccdnum"] = 1
159  info["calib_hdu"] = 1
160  calibType = self.getCalibType(filename)
161  if "flat" in calibType.lower():
162  raw = butler.get("cpFlat_filename", info)[0]
163  elif ("bias" or "zero") in calibType.lower():
164  raw = butler.get("cpBias_filename", info)[0]
165  elif ("illumcor") in calibType.lower():
166  raw = butler.get("cpIllumcor_filename", info)[0]
167  else:
168  assert False, "Invalid calibType '{:s}'".format(calibType)
169  # Remove HDU extension (ccdnum) since we want to refer to the whole file
170  c = raw.find("[")
171  if c > 0:
172  raw = raw[:c]
173  return raw
lsst.obs.decam.ingestCalibs.DecamCalibsParseTask.getExtensionName
def getExtensionName(md)
Definition: ingestCalibs.py:125
lsst::log.log.logContinued.warn
def warn(fmt, *args)
Definition: logContinued.py:202
lsst.obs.decam.ingestCalibs.DecamCalibsParseTask
Definition: ingestCalibs.py:9
lsst.obs.decam.ingestCalibs.DecamCalibsParseTask._translateFromCalibId
def _translateFromCalibId(self, field, md)
Definition: ingestCalibs.py:49
lsst.obs.decam.ingestCalibs.DecamCalibsParseTask.translate_date
def translate_date(self, md)
Definition: ingestCalibs.py:80
pex.config.history.format
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
Definition: history.py:174
strip
bool strip
Definition: fits.cc:911
lsst.obs.decam.ingestCalibs.DecamCalibsParseTask.translate_filter
def translate_filter(self, md)
Definition: ingestCalibs.py:103
lsst.pipe.tasks.ingestCalibs
Definition: ingestCalibs.py:1
lsst.obs.decam.ingestCalibs.DecamCalibsParseTask.translate_ccdnum
def translate_ccdnum(self, md)
Definition: ingestCalibs.py:59
lsst.pipe.base.task.Task.log
log
Definition: task.py:148
lsst.obs.decam.ingestCalibs.DecamCalibsParseTask.getInfo
def getInfo(self, filename)
Definition: ingestCalibs.py:11
lsst.pipe.tasks.ingestCalibs.CalibsParseTask
Definition: ingestCalibs.py:17
lsst.obs.decam.ingestCalibs.DecamCalibsParseTask.getDestination
def getDestination(self, butler, info, filename)
Definition: ingestCalibs.py:140
lsst.pipe.tasks.ingestCalibs.CalibsParseTask.getCalibType
def getCalibType(self, filename)
Definition: ingestCalibs.py:21