LSSTApplications  19.0.0,19.0.0+1,19.0.0+10,19.0.0+13,19.0.0+3,19.0.0+5,19.0.0+9,tickets.DM-22703-ga158cbef15,w.2019.51
LSSTDataManagementBasePackage
Public Member Functions | Public Attributes | Static Public Attributes | List of all members
lsst.pipe.tasks.ingestDefects.IngestDefectsTask Class Reference
Inheritance diagram for lsst.pipe.tasks.ingestDefects.IngestDefectsTask:
lsst.pipe.tasks.ingestCalibs.IngestCalibsTask lsst.pipe.tasks.ingest.IngestTask lsst.pipe.base.task.Task

Public Member Functions

def run (self, args)
 
def parseAndRun (cls)
 
def ingest (self, infile, outfile, mode="move", dryrun=False)
 
def isBadFile (self, filename, badFileList)
 
def isBadId (self, info, badIdList)
 
def expandFiles (self, fileNameList)
 Expand a set of filenames and globs, returning a list of filenames. More...
 
def runFile (self, infile, registry, args)
 Examine and ingest a single file. More...
 
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)
 

Public Attributes

 metadata
 
 log
 
 config
 

Static Public Attributes

 ArgumentParser
 
 ConfigClass
 

Detailed Description

Task that generates registry for calibration images

Definition at line 29 of file ingestDefects.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

◆ expandFiles()

def lsst.pipe.tasks.ingest.IngestTask.expandFiles (   self,
  fileNameList 
)
inherited

Expand a set of filenames and globs, returning a list of filenames.

Parameters
fileNameListA list of files and glob patterns

N.b. globs obey Posix semantics, so a pattern that matches nothing is returned unchanged

Definition at line 499 of file ingest.py.

499  def expandFiles(self, fileNameList):
500  """!Expand a set of filenames and globs, returning a list of filenames
501 
502  @param fileNameList A list of files and glob patterns
503 
504  N.b. globs obey Posix semantics, so a pattern that matches nothing is returned unchanged
505  """
506  filenameList = []
507  for globPattern in fileNameList:
508  files = glob(globPattern)
509 
510  if not files: # posix behaviour is to return pattern unchanged
511  self.log.warn("%s doesn't match any file" % globPattern)
512  continue
513 
514  filenameList.extend(files)
515 
516  return filenameList
517 

◆ 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 

◆ 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 
std::vector< SchemaItem< Flag > > * items
Class for storing generic metadata.
Definition: PropertySet.h:67

◆ 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 

◆ 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="")

◆ ingest()

def lsst.pipe.tasks.ingest.IngestTask.ingest (   self,
  infile,
  outfile,
  mode = "move",
  dryrun = False 
)
inherited
Ingest a file into the image repository.

@param infile  Name of input file
@param outfile Name of output file (file in repository)
@param mode    Mode of ingest (copy/link/move/skip)
@param dryrun  Only report what would occur?
@param Success boolean

Definition at line 427 of file ingest.py.

427  def ingest(self, infile, outfile, mode="move", dryrun=False):
428  """Ingest a file into the image repository.
429 
430  @param infile Name of input file
431  @param outfile Name of output file (file in repository)
432  @param mode Mode of ingest (copy/link/move/skip)
433  @param dryrun Only report what would occur?
434  @param Success boolean
435  """
436  if mode == "skip":
437  return True
438  if dryrun:
439  self.log.info("Would %s from %s to %s" % (mode, infile, outfile))
440  return True
441  try:
442  outdir = os.path.dirname(outfile)
443  if not os.path.isdir(outdir):
444  try:
445  os.makedirs(outdir)
446  except OSError:
447  # Silently ignore mkdir failures due to race conditions
448  if not os.path.isdir(outdir):
449  raise
450  if os.path.lexists(outfile):
451  if self.config.clobber:
452  os.unlink(outfile)
453  else:
454  raise RuntimeError("File %s already exists; consider --config clobber=True" % outfile)
455 
456  if mode == "copy":
457  assertCanCopy(infile, outfile)
458  shutil.copyfile(infile, outfile)
459  elif mode == "link":
460  os.symlink(os.path.abspath(infile), outfile)
461  elif mode == "move":
462  assertCanCopy(infile, outfile)
463  shutil.move(infile, outfile)
464  else:
465  raise AssertionError("Unknown mode: %s" % mode)
466  self.log.info("%s --<%s>--> %s" % (infile, mode, outfile))
467  except Exception as e:
468  self.log.warn("Failed to %s %s to %s: %s" % (mode, infile, outfile, e))
469  if not self.config.allowError:
470  raise
471  return False
472  return True
473 
def assertCanCopy(fromPath, toPath)
Definition: ingest.py:566

◆ isBadFile()

def lsst.pipe.tasks.ingest.IngestTask.isBadFile (   self,
  filename,
  badFileList 
)
inherited
Return whether the file qualifies as bad

We match against the list of bad file patterns.

Definition at line 474 of file ingest.py.

474  def isBadFile(self, filename, badFileList):
475  """Return whether the file qualifies as bad
476 
477  We match against the list of bad file patterns.
478  """
479  filename = os.path.basename(filename)
480  if not badFileList:
481  return False
482  for badFile in badFileList:
483  if fnmatch(filename, badFile):
484  return True
485  return False
486 

◆ isBadId()

def lsst.pipe.tasks.ingest.IngestTask.isBadId (   self,
  info,
  badIdList 
)
inherited
Return whether the file information qualifies as bad

We match against the list of bad data identifiers.

Definition at line 487 of file ingest.py.

487  def isBadId(self, info, badIdList):
488  """Return whether the file information qualifies as bad
489 
490  We match against the list of bad data identifiers.
491  """
492  if not badIdList:
493  return False
494  for badId in badIdList:
495  if all(info[key] == value for key, value in badId.items()):
496  return True
497  return False
498 
bool all(CoordinateExpr< N > const &expr) noexcept
Return true if all elements are true.

◆ 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 

◆ parseAndRun()

def lsst.pipe.tasks.ingest.IngestTask.parseAndRun (   cls)
inherited
Parse the command-line arguments and run the Task

Definition at line 419 of file ingest.py.

419  def parseAndRun(cls):
420  """Parse the command-line arguments and run the Task"""
421  config = cls.ConfigClass()
422  parser = cls.ArgumentParser(name=cls._DefaultName)
423  args = parser.parse_args(config)
424  task = cls(config=args.config)
425  task.run(args)
426 

◆ run()

def lsst.pipe.tasks.ingestDefects.IngestDefectsTask.run (   self,
  args 
)
Ingest all defect files and add them to the registry

Definition at line 35 of file ingestDefects.py.

35  def run(self, args):
36  """Ingest all defect files and add them to the registry"""
37 
38  try:
39  camera = args.butler.get('camera')
40  temp_dir = tempfile.mkdtemp()
41  defects = read_all_defects(args.root, camera)
42  file_names = []
43  for d in defects:
44  for s in defects[d]:
45  file_name = f'defects_{d}_{s.isoformat()}.fits'
46  full_file_name = os.path.join(temp_dir, file_name)
47  self.log.info('%i defects written for sensor: %s and calibDate: %s' %
48  (len(defects[d][s]), d, s.isoformat()))
49  defects[d][s].writeFits(full_file_name)
50  file_names.append(full_file_name)
51  args.files = file_names
52  args.mode = 'move'
53  args.validity = None # Validity range is determined from the files
54  IngestCalibsTask.run(self, args)
55  finally:
56  shutil.rmtree(temp_dir)
57 
def read_all_defects(root, camera)
Definition: read_defects.py:78
def run(self, skyInfo, tempExpRefList, imageScalerList, weightList, altMaskList=None, mask=None, supplementaryData=None)

◆ runFile()

def lsst.pipe.tasks.ingest.IngestTask.runFile (   self,
  infile,
  registry,
  args 
)
inherited

Examine and ingest a single file.

Parameters
infileFile to process
argsParsed command-line arguments
Returns
parsed information from FITS HDUs or None

Definition at line 518 of file ingest.py.

518  def runFile(self, infile, registry, args):
519  """!Examine and ingest a single file
520 
521  @param infile: File to process
522  @param args: Parsed command-line arguments
523  @return parsed information from FITS HDUs or None
524  """
525  if self.isBadFile(infile, args.badFile):
526  self.log.info("Skipping declared bad file %s" % infile)
527  return None
528  try:
529  fileInfo, hduInfoList = self.parse.getInfo(infile)
530  except Exception as e:
531  if not self.config.allowError:
532  raise
533  self.log.warn("Error parsing %s (%s); skipping" % (infile, e))
534  return None
535  if self.isBadId(fileInfo, args.badId.idList):
536  self.log.info("Skipping declared bad file %s: %s" % (infile, fileInfo))
537  return
538  if registry is not None and self.register.check(registry, fileInfo):
539  if args.ignoreIngested:
540  return None
541  self.log.warn("%s: already ingested: %s" % (infile, fileInfo))
542  outfile = self.parse.getDestination(args.butler, fileInfo, infile)
543  if not self.ingest(infile, outfile, mode=args.mode, dryrun=args.dryrun):
544  return None
545  return hduInfoList
546 

◆ 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

Member Data Documentation

◆ ArgumentParser

lsst.pipe.tasks.ingestDefects.IngestDefectsTask.ArgumentParser
static

Definition at line 31 of file ingestDefects.py.

◆ config

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

Definition at line 149 of file task.py.

◆ ConfigClass

lsst.pipe.tasks.ingestDefects.IngestDefectsTask.ConfigClass
static

Definition at line 33 of file ingestDefects.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:
  • /j/snowflake/release/lsstsw/stack/Linux64/pipe_tasks/19.0.0+3/python/lsst/pipe/tasks/ingestDefects.py