LSSTApplications  18.1.0
LSSTDataManagementBasePackage
Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | List of all members
lsst.pipe.tasks.ingest.ParseTask Class Reference
Inheritance diagram for lsst.pipe.tasks.ingest.ParseTask:
lsst.pipe.base.task.Task 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)
 
def emptyMetadata (self)
 
def getSchemaCatalogs (self)
 
def getAllSchemaCatalogs (self)
 
def getFullMetadata (self)
 
def getFullName (self)
 
def getName (self)
 
def getTaskDict (self)
 
def makeSubtask (self, name, keyArgs)
 
def timer (self, name, logLevel=Log.DEBUG)
 
def makeField (cls, doc)
 
def __reduce__ (self)
 

Static Public Member Functions

def getExtensionName (md)
 

Public Attributes

 metadata
 
 log
 
 config
 

Static Public Attributes

 ConfigClass = ParseConfig
 

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

◆ __reduce__()

def lsst.pipe.base.task.Task.__reduce__ (   self)
inherited
Pickler.

Definition at line 373 of file task.py.

373  def __reduce__(self):
374  """Pickler.
375  """
376  return self.__class__, (self.config, self._name, self._parentTask, None)
377 

◆ emptyMetadata()

def lsst.pipe.base.task.Task.emptyMetadata (   self)
inherited
Empty (clear) the metadata for this Task and all sub-Tasks.

Definition at line 153 of file task.py.

153  def emptyMetadata(self):
154  """Empty (clear) the metadata for this Task and all sub-Tasks.
155  """
156  for subtask in self._taskDict.values():
157  subtask.metadata = dafBase.PropertyList()
158 
Class for storing ordered metadata with comments.
Definition: PropertyList.h:68

◆ getAllSchemaCatalogs()

def lsst.pipe.base.task.Task.getAllSchemaCatalogs (   self)
inherited
Get schema catalogs for all tasks in the hierarchy, combining the results into a single dict.

Returns
-------
schemacatalogs : `dict`
    Keys are butler dataset type, values are a empty catalog (an instance of the appropriate
    lsst.afw.table Catalog type) for all tasks in the hierarchy, from the top-level task down
    through all subtasks.

Notes
-----
This method may be called on any task in the hierarchy; it will return the same answer, regardless.

The default implementation should always suffice. If your subtask uses schemas the override
`Task.getSchemaCatalogs`, not this method.

Definition at line 188 of file task.py.

188  def getAllSchemaCatalogs(self):
189  """Get schema catalogs for all tasks in the hierarchy, combining the results into a single dict.
190 
191  Returns
192  -------
193  schemacatalogs : `dict`
194  Keys are butler dataset type, values are a empty catalog (an instance of the appropriate
195  lsst.afw.table Catalog type) for all tasks in the hierarchy, from the top-level task down
196  through all subtasks.
197 
198  Notes
199  -----
200  This method may be called on any task in the hierarchy; it will return the same answer, regardless.
201 
202  The default implementation should always suffice. If your subtask uses schemas the override
203  `Task.getSchemaCatalogs`, not this method.
204  """
205  schemaDict = self.getSchemaCatalogs()
206  for subtask in self._taskDict.values():
207  schemaDict.update(subtask.getSchemaCatalogs())
208  return schemaDict
209 

◆ 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

Definition at line 181 of file ingest.py.

181  def getDestination(self, butler, info, filename):
182  """Get destination for the file
183 
184  @param butler Data butler
185  @param info File properties, used as dataId for the butler
186  @param filename Input filename
187  @return Destination filename
188  """
189  raw = butler.get("raw_filename", info)[0]
190  # Ensure filename is devoid of cfitsio directions about HDUs
191  c = raw.find("[")
192  if c > 0:
193  raw = raw[:c]
194  return raw
195 
196 

◆ getExtensionName()

def lsst.pipe.tasks.ingest.ParseTask.getExtensionName (   md)
static
Get the name of an extension.
@param md: PropertySet like one obtained from lsst.afw.fits.readMetadata)
@return Name of the extension if it exists.  None otherwise.

Definition at line 107 of file ingest.py.

107  def getExtensionName(md):
108  """ Get the name of an extension.
109  @param md: PropertySet like one obtained from lsst.afw.fits.readMetadata)
110  @return Name of the extension if it exists. None otherwise.
111  """
112  try:
113  # This returns a tuple
114  ext = md.getScalar("EXTNAME")
115  return ext[1]
117  return None
118 
Provides consistent interface for LSST exceptions.
Definition: Exception.h:107

◆ getFullMetadata()

def lsst.pipe.base.task.Task.getFullMetadata (   self)
inherited
Get metadata for all tasks.

Returns
-------
metadata : `lsst.daf.base.PropertySet`
    The `~lsst.daf.base.PropertySet` keys are the full task name. Values are metadata
    for the top-level task and all subtasks, sub-subtasks, etc..

Notes
-----
The returned metadata includes timing information (if ``@timer.timeMethod`` is used)
and any metadata set by the task. The name of each item consists of the full task name
with ``.`` replaced by ``:``, followed by ``.`` and the name of the item, e.g.::

    topLevelTaskName:subtaskName:subsubtaskName.itemName

using ``:`` in the full task name disambiguates the rare situation that a task has a subtask
and a metadata item with the same name.

Definition at line 210 of file task.py.

210  def getFullMetadata(self):
211  """Get metadata for all tasks.
212 
213  Returns
214  -------
215  metadata : `lsst.daf.base.PropertySet`
216  The `~lsst.daf.base.PropertySet` keys are the full task name. Values are metadata
217  for the top-level task and all subtasks, sub-subtasks, etc..
218 
219  Notes
220  -----
221  The returned metadata includes timing information (if ``@timer.timeMethod`` is used)
222  and any metadata set by the task. The name of each item consists of the full task name
223  with ``.`` replaced by ``:``, followed by ``.`` and the name of the item, e.g.::
224 
225  topLevelTaskName:subtaskName:subsubtaskName.itemName
226 
227  using ``:`` in the full task name disambiguates the rare situation that a task has a subtask
228  and a metadata item with the same name.
229  """
230  fullMetadata = dafBase.PropertySet()
231  for fullName, task in self.getTaskDict().items():
232  fullMetadata.set(fullName.replace(".", ":"), task.metadata)
233  return fullMetadata
234 
Class for storing generic metadata.
Definition: PropertySet.h:68
std::vector< SchemaItem< Flag > > * items

◆ getFullName()

def lsst.pipe.base.task.Task.getFullName (   self)
inherited
Get the task name as a hierarchical name including parent task names.

Returns
-------
fullName : `str`
    The full name consists of the name of the parent task and each subtask separated by periods.
    For example:

    - The full name of top-level task "top" is simply "top".
    - The full name of subtask "sub" of top-level task "top" is "top.sub".
    - The full name of subtask "sub2" of subtask "sub" of top-level task "top" is "top.sub.sub2".

Definition at line 235 of file task.py.

235  def getFullName(self):
236  """Get the task name as a hierarchical name including parent task names.
237 
238  Returns
239  -------
240  fullName : `str`
241  The full name consists of the name of the parent task and each subtask separated by periods.
242  For example:
243 
244  - The full name of top-level task "top" is simply "top".
245  - The full name of subtask "sub" of top-level task "top" is "top.sub".
246  - The full name of subtask "sub2" of subtask "sub" of top-level task "top" is "top.sub.sub2".
247  """
248  return self._fullName
249 

◆ 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.

@param filename    Name of file to inspect
@return File properties; list of file properties for each extension

Definition at line 72 of file ingest.py.

72  def getInfo(self, filename):
73  """Get information about the image from the filename and its contents
74 
75  Here, we open the image and parse the header, but one could also look at the filename itself
76  and derive information from that, or set values from the configuration.
77 
78  @param filename Name of file to inspect
79  @return File properties; list of file properties for each extension
80  """
81  md = readMetadata(filename, self.config.hdu)
82  phuInfo = self.getInfoFromMetadata(md)
83  if len(self.config.extnames) == 0:
84  # No extensions to worry about
85  return phuInfo, [phuInfo]
86  # Look in the provided extensions
87  extnames = set(self.config.extnames)
88  extnum = 0
89  infoList = []
90  while len(extnames) > 0:
91  extnum += 1
92  try:
93  md = readMetadata(filename, extnum)
94  except Exception as e:
95  self.log.warn("Error reading %s extensions %s: %s" % (filename, extnames, e))
96  break
97  ext = self.getExtensionName(md)
98  if ext in extnames:
99  hduInfo = self.getInfoFromMetadata(md, info=phuInfo.copy())
100  # We need the HDU number when registering MEF files.
101  hduInfo["hdu"] = extnum
102  infoList.append(hduInfo)
103  extnames.discard(ext)
104  return phuInfo, infoList
105 
daf::base::PropertySet * set
Definition: fits.cc:884

◆ 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 119 of file ingest.py.

119  def getInfoFromMetadata(self, md, info=None):
120  """Attempt to pull the desired information out of the header
121 
122  This is done through two mechanisms:
123  * translation: a property is set directly from the relevant header keyword
124  * translator: a property is set with the result of calling a method
125 
126  The translator methods receive the header metadata and should return the
127  appropriate value, or None if the value cannot be determined.
128 
129  @param md FITS header
130  @param info File properties, to be supplemented
131  @return info
132  """
133  if info is None:
134  info = {}
135  for p, h in self.config.translation.items():
136  if md.exists(h):
137  value = md.getScalar(h)
138  if isinstance(value, str):
139  value = value.strip()
140  info[p] = value
141  elif p in self.config.defaults:
142  info[p] = self.config.defaults[p]
143  else:
144  self.log.warn("Unable to find value for %s (derived from %s)" % (p, h))
145  for p, t in self.config.translators.items():
146  func = getattr(self, t)
147  try:
148  value = func(md)
149  except Exception as e:
150  self.log.warn("%s failed to translate %s: %s", t, p, e)
151  value = None
152  if value is not None:
153  info[p] = value
154  return info
155 

◆ getName()

def lsst.pipe.base.task.Task.getName (   self)
inherited
Get the name of the task.

Returns
-------
taskName : `str`
    Name of the task.

See also
--------
getFullName

Definition at line 250 of file task.py.

250  def getName(self):
251  """Get the name of the task.
252 
253  Returns
254  -------
255  taskName : `str`
256  Name of the task.
257 
258  See also
259  --------
260  getFullName
261  """
262  return self._name
263 

◆ getSchemaCatalogs()

def lsst.pipe.base.task.Task.getSchemaCatalogs (   self)
inherited
Get the schemas generated by this task.

Returns
-------
schemaCatalogs : `dict`
    Keys are butler dataset type, values are an empty catalog (an instance of the appropriate
    `lsst.afw.table` Catalog type) for this task.

Notes
-----

.. warning::

   Subclasses that use schemas must override this method. The default implemenation returns
   an empty dict.

This method may be called at any time after the Task is constructed, which means that all task
schemas should be computed at construction time, *not* when data is actually processed. This
reflects the philosophy that the schema should not depend on the data.

Returning catalogs rather than just schemas allows us to save e.g. slots for SourceCatalog as well.

See also
--------
Task.getAllSchemaCatalogs

Definition at line 159 of file task.py.

159  def getSchemaCatalogs(self):
160  """Get the schemas generated by this task.
161 
162  Returns
163  -------
164  schemaCatalogs : `dict`
165  Keys are butler dataset type, values are an empty catalog (an instance of the appropriate
166  `lsst.afw.table` Catalog type) for this task.
167 
168  Notes
169  -----
170 
171  .. warning::
172 
173  Subclasses that use schemas must override this method. The default implemenation returns
174  an empty dict.
175 
176  This method may be called at any time after the Task is constructed, which means that all task
177  schemas should be computed at construction time, *not* when data is actually processed. This
178  reflects the philosophy that the schema should not depend on the data.
179 
180  Returning catalogs rather than just schemas allows us to save e.g. slots for SourceCatalog as well.
181 
182  See also
183  --------
184  Task.getAllSchemaCatalogs
185  """
186  return {}
187 

◆ getTaskDict()

def lsst.pipe.base.task.Task.getTaskDict (   self)
inherited
Get a dictionary of all tasks as a shallow copy.

Returns
-------
taskDict : `dict`
    Dictionary containing full task name: task object for the top-level task and all subtasks,
    sub-subtasks, etc..

Definition at line 264 of file task.py.

264  def getTaskDict(self):
265  """Get a dictionary of all tasks as a shallow copy.
266 
267  Returns
268  -------
269  taskDict : `dict`
270  Dictionary containing full task name: task object for the top-level task and all subtasks,
271  sub-subtasks, etc..
272  """
273  return self._taskDict.copy()
274 
def getTaskDict(config, taskDict=None, baseName="")

◆ makeField()

def lsst.pipe.base.task.Task.makeField (   cls,
  doc 
)
inherited
Make a `lsst.pex.config.ConfigurableField` for this task.

Parameters
----------
doc : `str`
    Help text for the field.

Returns
-------
configurableField : `lsst.pex.config.ConfigurableField`
    A `~ConfigurableField` for this task.

Examples
--------
Provides a convenient way to specify this task is a subtask of another task.

Here is an example of use::

    class OtherTaskConfig(lsst.pex.config.Config)
aSubtask = ATaskClass.makeField("a brief description of what this task does")

Definition at line 329 of file task.py.

329  def makeField(cls, doc):
330  """Make a `lsst.pex.config.ConfigurableField` for this task.
331 
332  Parameters
333  ----------
334  doc : `str`
335  Help text for the field.
336 
337  Returns
338  -------
339  configurableField : `lsst.pex.config.ConfigurableField`
340  A `~ConfigurableField` for this task.
341 
342  Examples
343  --------
344  Provides a convenient way to specify this task is a subtask of another task.
345 
346  Here is an example of use::
347 
348  class OtherTaskConfig(lsst.pex.config.Config)
349  aSubtask = ATaskClass.makeField("a brief description of what this task does")
350  """
351  return ConfigurableField(doc=doc, target=cls)
352 

◆ makeSubtask()

def lsst.pipe.base.task.Task.makeSubtask (   self,
  name,
  keyArgs 
)
inherited
Create a subtask as a new instance as the ``name`` attribute of this task.

Parameters
----------
name : `str`
    Brief name of the subtask.
keyArgs
    Extra keyword arguments used to construct the task. The following arguments are automatically
    provided and cannot be overridden:

    - "config".
    - "parentTask".

Notes
-----
The subtask must be defined by ``Task.config.name``, an instance of pex_config ConfigurableField
or RegistryField.

Definition at line 275 of file task.py.

275  def makeSubtask(self, name, **keyArgs):
276  """Create a subtask as a new instance as the ``name`` attribute of this task.
277 
278  Parameters
279  ----------
280  name : `str`
281  Brief name of the subtask.
282  keyArgs
283  Extra keyword arguments used to construct the task. The following arguments are automatically
284  provided and cannot be overridden:
285 
286  - "config".
287  - "parentTask".
288 
289  Notes
290  -----
291  The subtask must be defined by ``Task.config.name``, an instance of pex_config ConfigurableField
292  or RegistryField.
293  """
294  taskField = getattr(self.config, name, None)
295  if taskField is None:
296  raise KeyError("%s's config does not have field %r" % (self.getFullName(), name))
297  subtask = taskField.apply(name=name, parentTask=self, **keyArgs)
298  setattr(self, name, subtask)
299 

◆ timer()

def lsst.pipe.base.task.Task.timer (   self,
  name,
  logLevel = Log.DEBUG 
)
inherited
Context manager to log performance data for an arbitrary block of code.

Parameters
----------
name : `str`
    Name of code being timed; data will be logged using item name: ``Start`` and ``End``.
logLevel
    A `lsst.log` level constant.

Examples
--------
Creating a timer context::

    with self.timer("someCodeToTime"):
pass  # code to time

See also
--------
timer.logInfo

Definition at line 301 of file task.py.

301  def timer(self, name, logLevel=Log.DEBUG):
302  """Context manager to log performance data for an arbitrary block of code.
303 
304  Parameters
305  ----------
306  name : `str`
307  Name of code being timed; data will be logged using item name: ``Start`` and ``End``.
308  logLevel
309  A `lsst.log` level constant.
310 
311  Examples
312  --------
313  Creating a timer context::
314 
315  with self.timer("someCodeToTime"):
316  pass # code to time
317 
318  See also
319  --------
320  timer.logInfo
321  """
322  logInfo(obj=self, prefix=name + "Start", logLevel=logLevel)
323  try:
324  yield
325  finally:
326  logInfo(obj=self, prefix=name + "End", logLevel=logLevel)
327 
def logInfo(obj, prefix, logLevel=Log.DEBUG)
Definition: timer.py:62

◆ 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.

Definition at line 156 of file ingest.py.

156  def translate_date(self, md):
157  """Convert a full DATE-OBS to a mere date
158 
159  Besides being an example of a translator, this is also generally useful.
160  It will only be used if listed as a translator in the configuration.
161  """
162  date = md.getScalar("DATE-OBS").strip()
163  c = date.find("T")
164  if c > 0:
165  date = date[:c]
166  return date
167 
bool strip
Definition: fits.cc:883

◆ 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.

Definition at line 168 of file ingest.py.

168  def translate_filter(self, md):
169  """Translate a full filter description into a mere filter name
170 
171  Besides being an example of a translator, this is also generally useful.
172  It will only be used if listed as a translator in the configuration.
173  """
174  filterName = md.getScalar("FILTER").strip()
175  filterName = filterName.strip()
176  c = filterName.find(" ")
177  if c > 0:
178  filterName = filterName[:c]
179  return filterName
180 
bool strip
Definition: fits.cc:883

Member Data Documentation

◆ config

lsst.pipe.base.task.Task.config
inherited

Definition at line 149 of file task.py.

◆ ConfigClass

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

Definition at line 70 of file ingest.py.

◆ log

lsst.pipe.base.task.Task.log
inherited

Definition at line 148 of file task.py.

◆ metadata

lsst.pipe.base.task.Task.metadata
inherited

Definition at line 121 of file task.py.


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