LSST Applications  21.0.0+04719a4bac,21.0.0-1-ga51b5d4+f5e6047307,21.0.0-10-g17396bd+0db626c9d4,21.0.0-11-ga42c5b2+8e919b1fde,21.0.0-11-gf32158d+0ebe75d2c4,21.0.0-12-g21f7bf3+5457518a9a,21.0.0-12-g9de0849+524af766c8,21.0.0-14-gbfe4b77+9a33cf3f69,21.0.0-16-g0fb55c1+2e80f2f4c5,21.0.0-19-g4cded4ca+da87cab2e2,21.0.0-2-g103fe59+7aa255a7ca,21.0.0-2-g45278ab+04719a4bac,21.0.0-2-g5242d73+7df4c6fa3d,21.0.0-2-g7f82c8f+0b5b78a3be,21.0.0-2-g8f08a60+06509c8b61,21.0.0-2-g8faa9b5+616205b9df,21.0.0-2-ga326454+0b5b78a3be,21.0.0-2-gde069b7+5e4aea9c2f,21.0.0-2-gecfae73+632ec57a44,21.0.0-2-gfc62afb+7df4c6fa3d,21.0.0-25-g1d57be3cd+e9f70389b0,21.0.0-3-g357aad2+3b365e1178,21.0.0-3-g4a4ce7f+7df4c6fa3d,21.0.0-3-g4be5c26+7df4c6fa3d,21.0.0-3-g65f322c+79dc209d58,21.0.0-3-g7d9da8d+616205b9df,21.0.0-3-ge02ed75+0db626c9d4,21.0.0-4-g591bb35+0db626c9d4,21.0.0-4-g65b4814+2e80f2f4c5,21.0.0-4-gccdca77+0de219a2bc,21.0.0-4-ge8a399c+7b7c27da6e,21.0.0-5-gd00fb1e+52bf7bf9f3,21.0.0-6-gc675373+7df4c6fa3d,21.0.0-61-ge77b8116+a869d0a5a5,21.0.0-7-g04766d7+5bf495eb54,21.0.0-7-g98eecf7+d1bd76f71f,21.0.0-7-gdf92d54+04719a4bac,master-gac4afde19b+0db626c9d4,w.2021.13
LSST Data Management Base Package
Public Member Functions | Public Attributes | Static Public Attributes | List of all members
lsst.pipe.tasks.postprocess.WriteSourceTableTask Class Reference
Inheritance diagram for lsst.pipe.tasks.postprocess.WriteSourceTableTask:
lsst.pipe.base.cmdLineTask.CmdLineTask lsst.pipe.base.task.Task

Public Member Functions

def runDataRef (self, dataRef)
 
def runQuantum (self, butlerQC, inputRefs, outputRefs)
 
def run (self, catalog, ccdVisitId=None)
 
def addCalibColumns (self, catalog, dataRef)
 
def writeMetadata (self, dataRef)
 
def applyOverrides (cls, config)
 
def parseAndRun (cls, args=None, config=None, log=None, doReturnResults=False)
 
def writeConfig (self, butler, clobber=False, doBackup=True)
 
def writeSchemas (self, butler, clobber=False, doBackup=True)
 
def writePackageVersions (self, butler, clobber=False, doBackup=True, dataset="packages")
 
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

 ConfigClass = WriteSourceTableConfig
 
 RunnerClass = TaskRunner
 
bool canMultiprocess = True
 

Detailed Description

Write source table to parquet

Definition at line 233 of file postprocess.py.

Member Function Documentation

◆ __reduce__()

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

Reimplemented in lsst.pipe.drivers.multiBandDriver.MultiBandDriverTask, and lsst.pipe.drivers.coaddDriver.CoaddDriverTask.

Definition at line 432 of file task.py.

432  def __reduce__(self):
433  """Pickler.
434  """
435  return self._unpickle_via_factory, (self.__class__, [], self._reduce_kwargs())

◆ addCalibColumns()

def lsst.pipe.tasks.postprocess.WriteSourceTableTask.addCalibColumns (   self,
  catalog,
  dataRef 
)
Add columns with local calibration evaluated at each centroid

for backwards compatibility with old repos.
This exists for the purpose of converting old src catalogs
(which don't have the expected local calib columns) to Source Tables.

Parameters
----------
catalog: `afwTable.SourceCatalog`
    catalog to which calib columns will be added
dataRef: `lsst.daf.persistence.ButlerDataRef
    for fetching the calibs from disk.

Returns
-------
newCat:  `afwTable.SourceCatalog`
    Source Catalog with requested local calib columns

Definition at line 276 of file postprocess.py.

276  def addCalibColumns(self, catalog, dataRef):
277  """Add columns with local calibration evaluated at each centroid
278 
279  for backwards compatibility with old repos.
280  This exists for the purpose of converting old src catalogs
281  (which don't have the expected local calib columns) to Source Tables.
282 
283  Parameters
284  ----------
285  catalog: `afwTable.SourceCatalog`
286  catalog to which calib columns will be added
287  dataRef: `lsst.daf.persistence.ButlerDataRef
288  for fetching the calibs from disk.
289 
290  Returns
291  -------
292  newCat: `afwTable.SourceCatalog`
293  Source Catalog with requested local calib columns
294  """
295  mapper = afwTable.SchemaMapper(catalog.schema)
296  measureConfig = SingleFrameMeasurementTask.ConfigClass()
297  measureConfig.doReplaceWithNoise = False
298 
299  # Just need the WCS or the PhotoCalib attached to an exposue
300  exposure = dataRef.get('calexp_sub',
302 
303  mapper = afwTable.SchemaMapper(catalog.schema)
304  mapper.addMinimalSchema(catalog.schema, True)
305  schema = mapper.getOutputSchema()
306 
307  exposureIdInfo = dataRef.get("expIdInfo")
308  measureConfig.plugins.names = []
309  if self.config.doApplyExternalSkyWcs:
310  plugin = 'base_LocalWcs'
311  if plugin in schema:
312  raise RuntimeError(f"{plugin} already in src catalog. Set doApplyExternalSkyWcs=False")
313  else:
314  measureConfig.plugins.names.add(plugin)
315 
316  if self.config.doApplyExternalPhotoCalib:
317  plugin = 'base_LocalPhotoCalib'
318  if plugin in schema:
319  raise RuntimeError(f"{plugin} already in src catalog. Set doApplyExternalPhotoCalib=False")
320  else:
321  measureConfig.plugins.names.add(plugin)
322 
323  measurement = SingleFrameMeasurementTask(config=measureConfig, schema=schema)
324  newCat = afwTable.SourceCatalog(schema)
325  newCat.extend(catalog, mapper=mapper)
326  measurement.run(measCat=newCat, exposure=exposure, exposureId=exposureIdInfo.expId)
327  return newCat
328 
A mapping between the keys of two Schemas, used to copy data between them.
Definition: SchemaMapper.h:21
An integer coordinate rectangle.
Definition: Box.h:55

◆ applyOverrides()

def lsst.pipe.base.cmdLineTask.CmdLineTask.applyOverrides (   cls,
  config 
)
inherited
A hook to allow a task to change the values of its config *after*
the camera-specific overrides are loaded but before any command-line
overrides are applied.

Parameters
----------
config : instance of task's ``ConfigClass``
    Task configuration.

Notes
-----
This is necessary in some cases because the camera-specific overrides
may retarget subtasks, wiping out changes made in
ConfigClass.setDefaults. See LSST Trac ticket #2282 for more
discussion.

.. warning::

   This is called by CmdLineTask.parseAndRun; other ways of
   constructing a config will not apply these overrides.

Reimplemented in lsst.pipe.drivers.constructCalibs.FringeTask, lsst.pipe.drivers.constructCalibs.FlatTask, lsst.pipe.drivers.constructCalibs.DarkTask, and lsst.pipe.drivers.constructCalibs.BiasTask.

Definition at line 587 of file cmdLineTask.py.

587  def applyOverrides(cls, config):
588  """A hook to allow a task to change the values of its config *after*
589  the camera-specific overrides are loaded but before any command-line
590  overrides are applied.
591 
592  Parameters
593  ----------
594  config : instance of task's ``ConfigClass``
595  Task configuration.
596 
597  Notes
598  -----
599  This is necessary in some cases because the camera-specific overrides
600  may retarget subtasks, wiping out changes made in
601  ConfigClass.setDefaults. See LSST Trac ticket #2282 for more
602  discussion.
603 
604  .. warning::
605 
606  This is called by CmdLineTask.parseAndRun; other ways of
607  constructing a config will not apply these overrides.
608  """
609  pass
610 

◆ emptyMetadata()

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

Definition at line 166 of file task.py.

166  def emptyMetadata(self):
167  """Empty (clear) the metadata for this Task and all sub-Tasks.
168  """
169  for subtask in self._taskDict.values():
170  subtask.metadata = dafBase.PropertyList()
171 
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 204 of file task.py.

204  def getAllSchemaCatalogs(self):
205  """Get schema catalogs for all tasks in the hierarchy, combining the
206  results into a single dict.
207 
208  Returns
209  -------
210  schemacatalogs : `dict`
211  Keys are butler dataset type, values are a empty catalog (an
212  instance of the appropriate `lsst.afw.table` Catalog type) for all
213  tasks in the hierarchy, from the top-level task down
214  through all subtasks.
215 
216  Notes
217  -----
218  This method may be called on any task in the hierarchy; it will return
219  the same answer, regardless.
220 
221  The default implementation should always suffice. If your subtask uses
222  schemas the override `Task.getSchemaCatalogs`, not this method.
223  """
224  schemaDict = self.getSchemaCatalogs()
225  for subtask in self._taskDict.values():
226  schemaDict.update(subtask.getSchemaCatalogs())
227  return schemaDict
228 

◆ 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 229 of file task.py.

229  def getFullMetadata(self):
230  """Get metadata for all tasks.
231 
232  Returns
233  -------
234  metadata : `lsst.daf.base.PropertySet`
235  The `~lsst.daf.base.PropertySet` keys are the full task name.
236  Values are metadata for the top-level task and all subtasks,
237  sub-subtasks, etc.
238 
239  Notes
240  -----
241  The returned metadata includes timing information (if
242  ``@timer.timeMethod`` is used) and any metadata set by the task. The
243  name of each item consists of the full task name with ``.`` replaced
244  by ``:``, followed by ``.`` and the name of the item, e.g.::
245 
246  topLevelTaskName:subtaskName:subsubtaskName.itemName
247 
248  using ``:`` in the full task name disambiguates the rare situation
249  that a task has a subtask and a metadata item with the same name.
250  """
251  fullMetadata = dafBase.PropertySet()
252  for fullName, task in self.getTaskDict().items():
253  fullMetadata.set(fullName.replace(".", ":"), task.metadata)
254  return fullMetadata
255 
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 256 of file task.py.

256  def getFullName(self):
257  """Get the task name as a hierarchical name including parent task
258  names.
259 
260  Returns
261  -------
262  fullName : `str`
263  The full name consists of the name of the parent task and each
264  subtask separated by periods. For example:
265 
266  - The full name of top-level task "top" is simply "top".
267  - The full name of subtask "sub" of top-level task "top" is
268  "top.sub".
269  - The full name of subtask "sub2" of subtask "sub" of top-level
270  task "top" is "top.sub.sub2".
271  """
272  return self._fullName
273 

◆ 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 274 of file task.py.

274  def getName(self):
275  """Get the name of the task.
276 
277  Returns
278  -------
279  taskName : `str`
280  Name of the task.
281 
282  See also
283  --------
284  getFullName
285  """
286  return self._name
287 
std::string const & getName() const noexcept
Return a filter's name.
Definition: Filter.h:78

◆ 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
   implementation 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 172 of file task.py.

172  def getSchemaCatalogs(self):
173  """Get the schemas generated by this task.
174 
175  Returns
176  -------
177  schemaCatalogs : `dict`
178  Keys are butler dataset type, values are an empty catalog (an
179  instance of the appropriate `lsst.afw.table` Catalog type) for
180  this task.
181 
182  Notes
183  -----
184 
185  .. warning::
186 
187  Subclasses that use schemas must override this method. The default
188  implementation returns an empty dict.
189 
190  This method may be called at any time after the Task is constructed,
191  which means that all task schemas should be computed at construction
192  time, *not* when data is actually processed. This reflects the
193  philosophy that the schema should not depend on the data.
194 
195  Returning catalogs rather than just schemas allows us to save e.g.
196  slots for SourceCatalog as well.
197 
198  See also
199  --------
200  Task.getAllSchemaCatalogs
201  """
202  return {}
203 

◆ 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 288 of file task.py.

288  def getTaskDict(self):
289  """Get a dictionary of all tasks as a shallow copy.
290 
291  Returns
292  -------
293  taskDict : `dict`
294  Dictionary containing full task name: task object for the top-level
295  task and all subtasks, sub-subtasks, etc.
296  """
297  return self._taskDict.copy()
298 
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:

.. code-block:: python

    class OtherTaskConfig(lsst.pex.config.Config):
        aSubtask = ATaskClass.makeField("brief description of task")

Definition at line 359 of file task.py.

359  def makeField(cls, doc):
360  """Make a `lsst.pex.config.ConfigurableField` for this task.
361 
362  Parameters
363  ----------
364  doc : `str`
365  Help text for the field.
366 
367  Returns
368  -------
369  configurableField : `lsst.pex.config.ConfigurableField`
370  A `~ConfigurableField` for this task.
371 
372  Examples
373  --------
374  Provides a convenient way to specify this task is a subtask of another
375  task.
376 
377  Here is an example of use:
378 
379  .. code-block:: python
380 
381  class OtherTaskConfig(lsst.pex.config.Config):
382  aSubtask = ATaskClass.makeField("brief description of task")
383  """
384  return ConfigurableField(doc=doc, target=cls)
385 

◆ 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
`~lsst.pex.config.ConfigurableField` or
`~lsst.pex.config.RegistryField`.

Definition at line 299 of file task.py.

299  def makeSubtask(self, name, **keyArgs):
300  """Create a subtask as a new instance as the ``name`` attribute of this
301  task.
302 
303  Parameters
304  ----------
305  name : `str`
306  Brief name of the subtask.
307  keyArgs
308  Extra keyword arguments used to construct the task. The following
309  arguments are automatically provided and cannot be overridden:
310 
311  - "config".
312  - "parentTask".
313 
314  Notes
315  -----
316  The subtask must be defined by ``Task.config.name``, an instance of
317  `~lsst.pex.config.ConfigurableField` or
318  `~lsst.pex.config.RegistryField`.
319  """
320  taskField = getattr(self.config, name, None)
321  if taskField is None:
322  raise KeyError(f"{self.getFullName()}'s config does not have field {name!r}")
323  subtask = taskField.apply(name=name, parentTask=self, **keyArgs)
324  setattr(self, name, subtask)
325 

◆ parseAndRun()

def lsst.pipe.base.cmdLineTask.CmdLineTask.parseAndRun (   cls,
  args = None,
  config = None,
  log = None,
  doReturnResults = False 
)
inherited
Parse an argument list and run the command.

Parameters
----------
args : `list`, optional
    List of command-line arguments; if `None` use `sys.argv`.
config : `lsst.pex.config.Config`-type, optional
    Config for task. If `None` use `Task.ConfigClass`.
log : `lsst.log.Log`-type, optional
    Log. If `None` use the default log.
doReturnResults : `bool`, optional
    If `True`, return the results of this task. Default is `False`.
    This is only intended for unit tests and similar use. It can
    easily exhaust memory (if the task returns enough data and you
    call it enough times) and it will fail when using multiprocessing
    if the returned data cannot be pickled.

Returns
-------
struct : `lsst.pipe.base.Struct`
    Fields are:

    ``argumentParser``
        the argument parser (`lsst.pipe.base.ArgumentParser`).
    ``parsedCmd``
        the parsed command returned by the argument parser's
        `~lsst.pipe.base.ArgumentParser.parse_args` method
        (`argparse.Namespace`).
    ``taskRunner``
        the task runner used to run the task (an instance of
        `Task.RunnerClass`).
    ``resultList``
        results returned by the task runner's ``run`` method, one entry
        per invocation (`list`). This will typically be a list of
        `Struct`, each containing at least an ``exitStatus`` integer
        (0 or 1); see `Task.RunnerClass` (`TaskRunner` by default) for
        more details.

Notes
-----
Calling this method with no arguments specified is the standard way to
run a command-line task from the command-line. For an example see
``pipe_tasks`` ``bin/makeSkyMap.py`` or almost any other file in that
directory.

If one or more of the dataIds fails then this routine will exit (with
a status giving the number of failed dataIds) rather than returning
this struct;  this behaviour can be overridden by specifying the
``--noExit`` command-line option.

Definition at line 612 of file cmdLineTask.py.

612  def parseAndRun(cls, args=None, config=None, log=None, doReturnResults=False):
613  """Parse an argument list and run the command.
614 
615  Parameters
616  ----------
617  args : `list`, optional
618  List of command-line arguments; if `None` use `sys.argv`.
619  config : `lsst.pex.config.Config`-type, optional
620  Config for task. If `None` use `Task.ConfigClass`.
621  log : `lsst.log.Log`-type, optional
622  Log. If `None` use the default log.
623  doReturnResults : `bool`, optional
624  If `True`, return the results of this task. Default is `False`.
625  This is only intended for unit tests and similar use. It can
626  easily exhaust memory (if the task returns enough data and you
627  call it enough times) and it will fail when using multiprocessing
628  if the returned data cannot be pickled.
629 
630  Returns
631  -------
632  struct : `lsst.pipe.base.Struct`
633  Fields are:
634 
635  ``argumentParser``
636  the argument parser (`lsst.pipe.base.ArgumentParser`).
637  ``parsedCmd``
638  the parsed command returned by the argument parser's
639  `~lsst.pipe.base.ArgumentParser.parse_args` method
640  (`argparse.Namespace`).
641  ``taskRunner``
642  the task runner used to run the task (an instance of
643  `Task.RunnerClass`).
644  ``resultList``
645  results returned by the task runner's ``run`` method, one entry
646  per invocation (`list`). This will typically be a list of
647  `Struct`, each containing at least an ``exitStatus`` integer
648  (0 or 1); see `Task.RunnerClass` (`TaskRunner` by default) for
649  more details.
650 
651  Notes
652  -----
653  Calling this method with no arguments specified is the standard way to
654  run a command-line task from the command-line. For an example see
655  ``pipe_tasks`` ``bin/makeSkyMap.py`` or almost any other file in that
656  directory.
657 
658  If one or more of the dataIds fails then this routine will exit (with
659  a status giving the number of failed dataIds) rather than returning
660  this struct; this behaviour can be overridden by specifying the
661  ``--noExit`` command-line option.
662  """
663  if args is None:
664  commandAsStr = " ".join(sys.argv)
665  args = sys.argv[1:]
666  else:
667  commandAsStr = "{}{}".format(lsst.utils.get_caller_name(skip=1), tuple(args))
668 
669  argumentParser = cls._makeArgumentParser()
670  if config is None:
671  config = cls.ConfigClass()
672  parsedCmd = argumentParser.parse_args(config=config, args=args, log=log, override=cls.applyOverrides)
673  # print this message after parsing the command so the log is fully
674  # configured
675  parsedCmd.log.info("Running: %s", commandAsStr)
676 
677  taskRunner = cls.RunnerClass(TaskClass=cls, parsedCmd=parsedCmd, doReturnResults=doReturnResults)
678  resultList = taskRunner.run(parsedCmd)
679 
680  try:
681  nFailed = sum(((res.exitStatus != 0) for res in resultList))
682  except (TypeError, AttributeError) as e:
683  # NOTE: TypeError if resultList is None, AttributeError if it
684  # doesn't have exitStatus.
685  parsedCmd.log.warn("Unable to retrieve exit status (%s); assuming success", e)
686  nFailed = 0
687 
688  if nFailed > 0:
689  if parsedCmd.noExit:
690  parsedCmd.log.error("%d dataRefs failed; not exiting as --noExit was set", nFailed)
691  else:
692  sys.exit(nFailed)
693 
694  return Struct(
695  argumentParser=argumentParser,
696  parsedCmd=parsedCmd,
697  taskRunner=taskRunner,
698  resultList=resultList,
699  )
700 
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
Definition: history.py:174

◆ run()

def lsst.pipe.tasks.postprocess.WriteSourceTableTask.run (   self,
  catalog,
  ccdVisitId = None 
)
Convert `src` catalog to parquet

Parameters
----------
catalog: `afwTable.SourceCatalog`
    catalog to be converted
ccdVisitId: `int`
    ccdVisitId to be added as a column

Returns
-------
result : `lsst.pipe.base.Struct`
    ``table``
        `ParquetTable` version of the input catalog

Definition at line 255 of file postprocess.py.

255  def run(self, catalog, ccdVisitId=None):
256  """Convert `src` catalog to parquet
257 
258  Parameters
259  ----------
260  catalog: `afwTable.SourceCatalog`
261  catalog to be converted
262  ccdVisitId: `int`
263  ccdVisitId to be added as a column
264 
265  Returns
266  -------
267  result : `lsst.pipe.base.Struct`
268  ``table``
269  `ParquetTable` version of the input catalog
270  """
271  self.log.info("Generating parquet table from src catalog %s", ccdVisitId)
272  df = catalog.asAstropy().to_pandas().set_index('id', drop=True)
273  df['ccdVisitId'] = ccdVisitId
274  return pipeBase.Struct(table=ParquetTable(dataFrame=df))
275 
def run(self, skyInfo, tempExpRefList, imageScalerList, weightList, altMaskList=None, mask=None, supplementaryData=None)

◆ runDataRef()

def lsst.pipe.tasks.postprocess.WriteSourceTableTask.runDataRef (   self,
  dataRef 
)

Definition at line 239 of file postprocess.py.

239  def runDataRef(self, dataRef):
240  src = dataRef.get('src')
241  if self.config.doApplyExternalPhotoCalib or self.config.doApplyExternalSkyWcs:
242  src = self.addCalibColumns(src, dataRef)
243 
244  ccdVisitId = dataRef.get('ccdExposureId')
245  result = self.run(src, ccdVisitId=ccdVisitId)
246  dataRef.put(result.table, 'source')
247 

◆ runQuantum()

def lsst.pipe.tasks.postprocess.WriteSourceTableTask.runQuantum (   self,
  butlerQC,
  inputRefs,
  outputRefs 
)

Definition at line 248 of file postprocess.py.

248  def runQuantum(self, butlerQC, inputRefs, outputRefs):
249  inputs = butlerQC.get(inputRefs)
250  inputs['ccdVisitId'] = butlerQC.quantum.dataId.pack("visit_detector")
251  result = self.run(**inputs).table
252  outputs = pipeBase.Struct(outputCatalog=result.toDataFrame())
253  butlerQC.put(outputs, outputRefs)
254 

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

.. code-block:: python

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

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

Definition at line 327 of file task.py.

327  def timer(self, name, logLevel=Log.DEBUG):
328  """Context manager to log performance data for an arbitrary block of
329  code.
330 
331  Parameters
332  ----------
333  name : `str`
334  Name of code being timed; data will be logged using item name:
335  ``Start`` and ``End``.
336  logLevel
337  A `lsst.log` level constant.
338 
339  Examples
340  --------
341  Creating a timer context:
342 
343  .. code-block:: python
344 
345  with self.timer("someCodeToTime"):
346  pass # code to time
347 
348  See also
349  --------
350  timer.logInfo
351  """
352  logInfo(obj=self, prefix=name + "Start", logLevel=logLevel)
353  try:
354  yield
355  finally:
356  logInfo(obj=self, prefix=name + "End", logLevel=logLevel)
357 
def logInfo(obj, prefix, logLevel=Log.DEBUG)
Definition: timer.py:63

◆ writeConfig()

def lsst.pipe.base.cmdLineTask.CmdLineTask.writeConfig (   self,
  butler,
  clobber = False,
  doBackup = True 
)
inherited
Write the configuration used for processing the data, or check that
an existing one is equal to the new one if present.

Parameters
----------
butler : `lsst.daf.persistence.Butler`
    Data butler used to write the config. The config is written to
    dataset type `CmdLineTask._getConfigName`.
clobber : `bool`, optional
    A boolean flag that controls what happens if a config already has
    been saved:

    - `True`: overwrite or rename the existing config, depending on
      ``doBackup``.
    - `False`: raise `TaskError` if this config does not match the
      existing config.
doBackup : `bool`, optional
    Set to `True` to backup the config files if clobbering.

Reimplemented in lsst.pipe.tasks.postprocess.ConsolidateSourceTableTask.

Definition at line 727 of file cmdLineTask.py.

727  def writeConfig(self, butler, clobber=False, doBackup=True):
728  """Write the configuration used for processing the data, or check that
729  an existing one is equal to the new one if present.
730 
731  Parameters
732  ----------
733  butler : `lsst.daf.persistence.Butler`
734  Data butler used to write the config. The config is written to
735  dataset type `CmdLineTask._getConfigName`.
736  clobber : `bool`, optional
737  A boolean flag that controls what happens if a config already has
738  been saved:
739 
740  - `True`: overwrite or rename the existing config, depending on
741  ``doBackup``.
742  - `False`: raise `TaskError` if this config does not match the
743  existing config.
744  doBackup : `bool`, optional
745  Set to `True` to backup the config files if clobbering.
746  """
747  configName = self._getConfigName()
748  if configName is None:
749  return
750  if clobber:
751  butler.put(self.config, configName, doBackup=doBackup)
752  elif butler.datasetExists(configName, write=True):
753  # this may be subject to a race condition; see #2789
754  try:
755  oldConfig = butler.get(configName, immediate=True)
756  except Exception as exc:
757  raise type(exc)(f"Unable to read stored config file {configName} (exc); "
758  "consider using --clobber-config")
759 
760  def logConfigMismatch(msg):
761  self.log.fatal("Comparing configuration: %s", msg)
762 
763  if not self.config.compare(oldConfig, shortcut=False, output=logConfigMismatch):
764  raise TaskError(
765  f"Config does not match existing task config {configName!r} on disk; "
766  "tasks configurations must be consistent within the same output repo "
767  "(override with --clobber-config)")
768  else:
769  butler.put(self.config, configName)
770 
table::Key< int > type
Definition: Detector.cc:163

◆ writeMetadata()

def lsst.pipe.tasks.postprocess.WriteSourceTableTask.writeMetadata (   self,
  dataRef 
)
No metadata to write.

Reimplemented from lsst.pipe.base.cmdLineTask.CmdLineTask.

Definition at line 329 of file postprocess.py.

329  def writeMetadata(self, dataRef):
330  """No metadata to write.
331  """
332  pass
333 
def writeMetadata(self, dataRefList)
No metadata to write, and not sure how to write it for a list of dataRefs.

◆ writePackageVersions()

def lsst.pipe.base.cmdLineTask.CmdLineTask.writePackageVersions (   self,
  butler,
  clobber = False,
  doBackup = True,
  dataset = "packages" 
)
inherited
Compare and write package versions.

Parameters
----------
butler : `lsst.daf.persistence.Butler`
    Data butler used to read/write the package versions.
clobber : `bool`, optional
    A boolean flag that controls what happens if versions already have
    been saved:

    - `True`: overwrite or rename the existing version info, depending
      on ``doBackup``.
    - `False`: raise `TaskError` if this version info does not match
      the existing.
doBackup : `bool`, optional
    If `True` and clobbering, old package version files are backed up.
dataset : `str`, optional
    Name of dataset to read/write.

Raises
------
TaskError
    Raised if there is a version mismatch with current and persisted
    lists of package versions.

Notes
-----
Note that this operation is subject to a race condition.

Definition at line 829 of file cmdLineTask.py.

829  def writePackageVersions(self, butler, clobber=False, doBackup=True, dataset="packages"):
830  """Compare and write package versions.
831 
832  Parameters
833  ----------
834  butler : `lsst.daf.persistence.Butler`
835  Data butler used to read/write the package versions.
836  clobber : `bool`, optional
837  A boolean flag that controls what happens if versions already have
838  been saved:
839 
840  - `True`: overwrite or rename the existing version info, depending
841  on ``doBackup``.
842  - `False`: raise `TaskError` if this version info does not match
843  the existing.
844  doBackup : `bool`, optional
845  If `True` and clobbering, old package version files are backed up.
846  dataset : `str`, optional
847  Name of dataset to read/write.
848 
849  Raises
850  ------
851  TaskError
852  Raised if there is a version mismatch with current and persisted
853  lists of package versions.
854 
855  Notes
856  -----
857  Note that this operation is subject to a race condition.
858  """
859  packages = Packages.fromSystem()
860 
861  if clobber:
862  return butler.put(packages, dataset, doBackup=doBackup)
863  if not butler.datasetExists(dataset, write=True):
864  return butler.put(packages, dataset)
865 
866  try:
867  old = butler.get(dataset, immediate=True)
868  except Exception as exc:
869  raise type(exc)(f"Unable to read stored version dataset {dataset} ({exc}); "
870  "consider using --clobber-versions or --no-versions")
871  # Note that because we can only detect python modules that have been
872  # imported, the stored list of products may be more or less complete
873  # than what we have now. What's important is that the products that
874  # are in common have the same version.
875  diff = packages.difference(old)
876  if diff:
877  versions_str = "; ".join(f"{pkg}: {diff[pkg][1]} vs {diff[pkg][0]}" for pkg in diff)
878  raise TaskError(
879  f"Version mismatch ({versions_str}); consider using --clobber-versions or --no-versions")
880  # Update the old set of packages in case we have more packages that
881  # haven't been persisted.
882  extra = packages.extra(old)
883  if extra:
884  old.update(packages)
885  butler.put(old, dataset, doBackup=doBackup)
886 

◆ writeSchemas()

def lsst.pipe.base.cmdLineTask.CmdLineTask.writeSchemas (   self,
  butler,
  clobber = False,
  doBackup = True 
)
inherited
Write the schemas returned by
`lsst.pipe.base.Task.getAllSchemaCatalogs`.

Parameters
----------
butler : `lsst.daf.persistence.Butler`
    Data butler used to write the schema. Each schema is written to the
    dataset type specified as the key in the dict returned by
    `~lsst.pipe.base.Task.getAllSchemaCatalogs`.
clobber : `bool`, optional
    A boolean flag that controls what happens if a schema already has
    been saved:

    - `True`: overwrite or rename the existing schema, depending on
      ``doBackup``.
    - `False`: raise `TaskError` if this schema does not match the
      existing schema.
doBackup : `bool`, optional
    Set to `True` to backup the schema files if clobbering.

Notes
-----
If ``clobber`` is `False` and an existing schema does not match a
current schema, then some schemas may have been saved successfully
and others may not, and there is no easy way to tell which is which.

Definition at line 771 of file cmdLineTask.py.

771  def writeSchemas(self, butler, clobber=False, doBackup=True):
772  """Write the schemas returned by
773  `lsst.pipe.base.Task.getAllSchemaCatalogs`.
774 
775  Parameters
776  ----------
777  butler : `lsst.daf.persistence.Butler`
778  Data butler used to write the schema. Each schema is written to the
779  dataset type specified as the key in the dict returned by
780  `~lsst.pipe.base.Task.getAllSchemaCatalogs`.
781  clobber : `bool`, optional
782  A boolean flag that controls what happens if a schema already has
783  been saved:
784 
785  - `True`: overwrite or rename the existing schema, depending on
786  ``doBackup``.
787  - `False`: raise `TaskError` if this schema does not match the
788  existing schema.
789  doBackup : `bool`, optional
790  Set to `True` to backup the schema files if clobbering.
791 
792  Notes
793  -----
794  If ``clobber`` is `False` and an existing schema does not match a
795  current schema, then some schemas may have been saved successfully
796  and others may not, and there is no easy way to tell which is which.
797  """
798  for dataset, catalog in self.getAllSchemaCatalogs().items():
799  schemaDataset = dataset + "_schema"
800  if clobber:
801  butler.put(catalog, schemaDataset, doBackup=doBackup)
802  elif butler.datasetExists(schemaDataset, write=True):
803  oldSchema = butler.get(schemaDataset, immediate=True).getSchema()
804  if not oldSchema.compare(catalog.getSchema(), afwTable.Schema.IDENTICAL):
805  raise TaskError(
806  f"New schema does not match schema {dataset!r} on disk; "
807  "schemas must be consistent within the same output repo "
808  "(override with --clobber-config)")
809  else:
810  butler.put(catalog, schemaDataset)
811 

Member Data Documentation

◆ canMultiprocess

bool lsst.pipe.base.cmdLineTask.CmdLineTask.canMultiprocess = True
staticinherited

Definition at line 584 of file cmdLineTask.py.

◆ config

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

Definition at line 162 of file task.py.

◆ ConfigClass

lsst.pipe.tasks.postprocess.WriteSourceTableTask.ConfigClass = WriteSourceTableConfig
static

Definition at line 237 of file postprocess.py.

◆ log

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

Definition at line 161 of file task.py.

◆ metadata

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

Definition at line 134 of file task.py.

◆ RunnerClass

lsst.pipe.base.cmdLineTask.CmdLineTask.RunnerClass = TaskRunner
staticinherited

Definition at line 583 of file cmdLineTask.py.


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