LSST Applications  21.0.0-172-gfb10e10a+18fedfabac,22.0.0+297cba6710,22.0.0+80564b0ff1,22.0.0+8d77f4f51a,22.0.0+a28f4c53b1,22.0.0+dcf3732eb2,22.0.1-1-g7d6de66+2a20fdde0d,22.0.1-1-g8e32f31+297cba6710,22.0.1-1-geca5380+7fa3b7d9b6,22.0.1-12-g44dc1dc+2a20fdde0d,22.0.1-15-g6a90155+515f58c32b,22.0.1-16-g9282f48+790f5f2caa,22.0.1-2-g92698f7+dcf3732eb2,22.0.1-2-ga9b0f51+7fa3b7d9b6,22.0.1-2-gd1925c9+bf4f0e694f,22.0.1-24-g1ad7a390+a9625a72a8,22.0.1-25-g5bf6245+3ad8ecd50b,22.0.1-25-gb120d7b+8b5510f75f,22.0.1-27-g97737f7+2a20fdde0d,22.0.1-32-gf62ce7b1+aa4237961e,22.0.1-4-g0b3f228+2a20fdde0d,22.0.1-4-g243d05b+871c1b8305,22.0.1-4-g3a563be+32dcf1063f,22.0.1-4-g44f2e3d+9e4ab0f4fa,22.0.1-42-gca6935d93+ba5e5ca3eb,22.0.1-5-g15c806e+85460ae5f3,22.0.1-5-g58711c4+611d128589,22.0.1-5-g75bb458+99c117b92f,22.0.1-6-g1c63a23+7fa3b7d9b6,22.0.1-6-g50866e6+84ff5a128b,22.0.1-6-g8d3140d+720564cf76,22.0.1-6-gd805d02+cc5644f571,22.0.1-8-ge5750ce+85460ae5f3,master-g6e05de7fdc+babf819c66,master-g99da0e417a+8d77f4f51a,w.2021.48
LSST Data Management Base Package
Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
lsst.pipe.tasks.ingest.ParseTask Class Reference
Inheritance diagram for lsst.pipe.tasks.ingest.ParseTask:
lsst.obs.decam.ingest.DecamParseTask lsst.pipe.tasks.ingestCalibs.CalibsParseTask lsst.obs.decam.ingestCalibs.DecamCalibsParseTask

Public Member Functions

def getInfo (self, filename)
 
def getInfoFromMetadata (self, md, info=None)
 
def translate_date (self, md)
 
def translate_filter (self, md)
 
def getDestination (self, butler, info, filename)
 

Static Public Member Functions

def getExtensionName (md)
 

Static Public Attributes

 ConfigClass = ParseConfig
 
 translator_class = None
 

Detailed Description

Task that will parse the filename and/or its contents to get the required information
for putting the file in the correct location and populating the registry.

Definition at line 67 of file ingest.py.

Member Function Documentation

◆ getDestination()

def lsst.pipe.tasks.ingest.ParseTask.getDestination (   self,
  butler,
  info,
  filename 
)
Get destination for the file

@param butler      Data butler
@param info        File properties, used as dataId for the butler
@param filename    Input filename
@return Destination filename

Reimplemented in lsst.pipe.tasks.ingestCalibs.CalibsParseTask, and lsst.obs.decam.ingestCalibs.DecamCalibsParseTask.

Definition at line 207 of file ingest.py.

207  def getDestination(self, butler, info, filename):
208  """Get destination for the file
209 
210  @param butler Data butler
211  @param info File properties, used as dataId for the butler
212  @param filename Input filename
213  @return Destination filename
214  """
215  raw = butler.get("raw_filename", info)[0]
216  # Ensure filename is devoid of cfitsio directions about HDUs
217  c = raw.find("[")
218  if c > 0:
219  raw = raw[:c]
220  return raw
221 
222 

◆ getExtensionName()

def lsst.pipe.tasks.ingest.ParseTask.getExtensionName (   md)
static
 Get the name of a FITS extension.

Parameters
----------
md : `lsst.daf.base.PropertySet`
    FITS header metadata.

Returns
-------
result : `str` or `None`
    The string from the EXTNAME header card if it exists. None otherwise.

Definition at line 126 of file ingest.py.

126  def getExtensionName(md):
127  """ Get the name of a FITS extension.
128 
129  Parameters
130  ----------
131  md : `lsst.daf.base.PropertySet`
132  FITS header metadata.
133 
134  Returns
135  -------
136  result : `str` or `None`
137  The string from the EXTNAME header card if it exists. None otherwise.
138  """
139  try:
140  ext = md["EXTNAME"]
141  except KeyError:
142  ext = None
143  return ext
144 

◆ getInfo()

def lsst.pipe.tasks.ingest.ParseTask.getInfo (   self,
  filename 
)
Get information about the image from the filename and its contents

Here, we open the image and parse the header, but one could also look at the filename itself
and derive information from that, or set values from the configuration.

Parameters
----------
filename : `str`
    Name of file to inspect

Returns
-------
phuInfo : `dict`
    File properties
infoList : `list`
    List of file properties for each extension

Reimplemented in lsst.obs.decam.ingestCalibs.DecamCalibsParseTask.

Definition at line 80 of file ingest.py.

80  def getInfo(self, filename):
81  """Get information about the image from the filename and its contents
82 
83  Here, we open the image and parse the header, but one could also look at the filename itself
84  and derive information from that, or set values from the configuration.
85 
86  Parameters
87  ----------
88  filename : `str`
89  Name of file to inspect
90 
91  Returns
92  -------
93  phuInfo : `dict`
94  File properties
95  infoList : `list`
96  List of file properties for each extension
97  """
98  md = readMetadata(filename, self.config.hdu)
99  fix_header(md, translator_class=self.translator_class)
100  phuInfo = self.getInfoFromMetadata(md)
101  if len(self.config.extnames) == 0:
102  # No extensions to worry about
103  return phuInfo, [phuInfo]
104  # Look in the provided extensions
105  extnames = set(self.config.extnames)
106  extnum = 0
107  infoList = []
108  while len(extnames) > 0:
109  extnum += 1
110  try:
111  md = readMetadata(filename, extnum)
112  fix_header(md, translator_class=self.translator_class)
113  except Exception as e:
114  self.log.warning("Error reading %s extensions %s: %s", filename, extnames, e)
115  break
116  ext = self.getExtensionName(md)
117  if ext in extnames:
118  hduInfo = self.getInfoFromMetadata(md, info=phuInfo.copy())
119  # We need the HDU number when registering MEF files.
120  hduInfo["hdu"] = extnum
121  infoList.append(hduInfo)
122  extnames.discard(ext)
123  return phuInfo, infoList
124 
daf::base::PropertySet * set
Definition: fits.cc:912
std::shared_ptr< daf::base::PropertyList > readMetadata(std::string const &fileName, int hdu=DEFAULT_HDU, bool strip=false)
Read FITS header.
Definition: fits.cc:1657

◆ getInfoFromMetadata()

def lsst.pipe.tasks.ingest.ParseTask.getInfoFromMetadata (   self,
  md,
  info = None 
)
Attempt to pull the desired information out of the header

This is done through two mechanisms:
* translation: a property is set directly from the relevant header keyword
* translator: a property is set with the result of calling a method

The translator methods receive the header metadata and should return the
appropriate value, or None if the value cannot be determined.

@param md      FITS header
@param info    File properties, to be supplemented
@return info

Definition at line 145 of file ingest.py.

145  def getInfoFromMetadata(self, md, info=None):
146  """Attempt to pull the desired information out of the header
147 
148  This is done through two mechanisms:
149  * translation: a property is set directly from the relevant header keyword
150  * translator: a property is set with the result of calling a method
151 
152  The translator methods receive the header metadata and should return the
153  appropriate value, or None if the value cannot be determined.
154 
155  @param md FITS header
156  @param info File properties, to be supplemented
157  @return info
158  """
159  if info is None:
160  info = {}
161  for p, h in self.config.translation.items():
162  value = md.get(h, None)
163  if value is not None:
164  if isinstance(value, str):
165  value = value.strip()
166  info[p] = value
167  elif p in self.config.defaults:
168  info[p] = self.config.defaults[p]
169  else:
170  self.log.warning("Unable to find value for %s (derived from %s)", p, h)
171  for p, t in self.config.translators.items():
172  func = getattr(self, t)
173  try:
174  value = func(md)
175  except Exception as e:
176  self.log.warning("%s failed to translate %s: %s", t, p, e)
177  value = None
178  if value is not None:
179  info[p] = value
180  return info
181 

◆ translate_date()

def lsst.pipe.tasks.ingest.ParseTask.translate_date (   self,
  md 
)
Convert a full DATE-OBS to a mere date

Besides being an example of a translator, this is also generally useful.
It will only be used if listed as a translator in the configuration.

Reimplemented in lsst.obs.decam.ingestCalibs.DecamCalibsParseTask.

Definition at line 182 of file ingest.py.

182  def translate_date(self, md):
183  """Convert a full DATE-OBS to a mere date
184 
185  Besides being an example of a translator, this is also generally useful.
186  It will only be used if listed as a translator in the configuration.
187  """
188  date = md.getScalar("DATE-OBS").strip()
189  c = date.find("T")
190  if c > 0:
191  date = date[:c]
192  return date
193 
bool strip
Definition: fits.cc:911

◆ translate_filter()

def lsst.pipe.tasks.ingest.ParseTask.translate_filter (   self,
  md 
)
Translate a full filter description into a mere filter name

Besides being an example of a translator, this is also generally useful.
It will only be used if listed as a translator in the configuration.

Reimplemented in lsst.obs.decam.ingestCalibs.DecamCalibsParseTask.

Definition at line 194 of file ingest.py.

194  def translate_filter(self, md):
195  """Translate a full filter description into a mere filter name
196 
197  Besides being an example of a translator, this is also generally useful.
198  It will only be used if listed as a translator in the configuration.
199  """
200  filterName = md.getScalar("FILTER").strip()
201  filterName = filterName.strip()
202  c = filterName.find(" ")
203  if c > 0:
204  filterName = filterName[:c]
205  return filterName
206 

Member Data Documentation

◆ ConfigClass

lsst.pipe.tasks.ingest.ParseTask.ConfigClass = ParseConfig
static

Definition at line 70 of file ingest.py.

◆ translator_class

lsst.pipe.tasks.ingest.ParseTask.translator_class = None
static

Definition at line 71 of file ingest.py.


The documentation for this class was generated from the following file: