LSSTApplications  17.0+10,17.0+52,17.0+91,18.0.0+11,18.0.0+16,18.0.0+38,18.0.0+4,18.0.0-2-ge43143a+8,18.1.0-1-g0001055+4,18.1.0-1-g1349e88+13,18.1.0-1-g2505f39+10,18.1.0-1-g380d4d4+13,18.1.0-1-g5315e5e,18.1.0-1-g5e4b7ea+4,18.1.0-1-g7e8fceb,18.1.0-1-g85f8cd4+10,18.1.0-1-g9a6769a+4,18.1.0-1-ga1a4c1a+9,18.1.0-1-gd55f500+5,18.1.0-1-ge10677a+10,18.1.0-11-gb2589d7b,18.1.0-13-g451e75588+2,18.1.0-13-gbfe7f7f+4,18.1.0-14-g2e73c10+1,18.1.0-2-g31c43f9+10,18.1.0-2-g919ecaf,18.1.0-2-g9c63283+13,18.1.0-2-gdf0b915+13,18.1.0-2-gfefb8b5+2,18.1.0-3-g52aa583+4,18.1.0-3-g8f4a2b1+4,18.1.0-3-g9cb968e+12,18.1.0-3-gab23065,18.1.0-4-g7bbbad0+4,18.1.0-5-g510c42a+12,18.1.0-5-gaeab27e+13,18.1.0-6-gc4bdb98+2,18.1.0-6-gdda7f3e+15,18.1.0-9-g9613d271+1,w.2019.34
LSSTDataManagementBasePackage
Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | List of all members
lsst.pipe.tasks.multiBand.DeblendCoaddSourcesRunner Class Reference
Inheritance diagram for lsst.pipe.tasks.multiBand.DeblendCoaddSourcesRunner:
lsst.pipe.tasks.multiBandUtils.MergeSourcesRunner lsst.pipe.base.cmdLineTask.TaskRunner

Public Member Functions

def makeTask (self, parsedCmd=None, args=None)
 
def prepareForMultiProcessing (self)
 
def run (self, parsedCmd)
 
def precall (self, parsedCmd)
 
def __call__ (self, args)
 
def runTask (self, task, dataRef, kwargs)
 

Static Public Member Functions

def getTargetList (parsedCmd, kwargs)
 
def buildRefDict (parsedCmd)
 

Public Attributes

 TaskClass
 
 doReturnResults
 
 config
 
 log
 
 doRaise
 
 clobberConfig
 
 doBackup
 
 numProcesses
 
 timeout
 

Static Public Attributes

int TIMEOUT = 3600*24*30
 

Detailed Description

Task runner for the `MergeSourcesTask`

Required because the run method requires a list of
dataRefs rather than a single dataRef.

Definition at line 369 of file multiBand.py.

Member Function Documentation

◆ __call__()

def lsst.pipe.base.cmdLineTask.TaskRunner.__call__ (   self,
  args 
)
inherited
Run the Task on a single target.

Parameters
----------
args
    Arguments for Task.runDataRef()

Returns
-------
struct : `lsst.pipe.base.Struct`
    Contains these fields if ``doReturnResults`` is `True`:

    - ``dataRef``: the provided data reference.
    - ``metadata``: task metadata after execution of run.
    - ``result``: result returned by task run, or `None` if the task fails.
    - ``exitStatus``: 0 if the task completed successfully, 1 otherwise.

    If ``doReturnResults`` is `False` the struct contains:

    - ``exitStatus``: 0 if the task completed successfully, 1 otherwise.

Notes
-----
This default implementation assumes that the ``args`` is a tuple containing a data reference and a
dict of keyword arguments.

.. warning::

   If you override this method and wish to return something when ``doReturnResults`` is `False`,
   then it must be picklable to support multiprocessing and it should be small enough that pickling
   and unpickling do not add excessive overhead.

Definition at line 341 of file cmdLineTask.py.

341  def __call__(self, args):
342  """Run the Task on a single target.
343 
344  Parameters
345  ----------
346  args
347  Arguments for Task.runDataRef()
348 
349  Returns
350  -------
351  struct : `lsst.pipe.base.Struct`
352  Contains these fields if ``doReturnResults`` is `True`:
353 
354  - ``dataRef``: the provided data reference.
355  - ``metadata``: task metadata after execution of run.
356  - ``result``: result returned by task run, or `None` if the task fails.
357  - ``exitStatus``: 0 if the task completed successfully, 1 otherwise.
358 
359  If ``doReturnResults`` is `False` the struct contains:
360 
361  - ``exitStatus``: 0 if the task completed successfully, 1 otherwise.
362 
363  Notes
364  -----
365  This default implementation assumes that the ``args`` is a tuple containing a data reference and a
366  dict of keyword arguments.
367 
368  .. warning::
369 
370  If you override this method and wish to return something when ``doReturnResults`` is `False`,
371  then it must be picklable to support multiprocessing and it should be small enough that pickling
372  and unpickling do not add excessive overhead.
373  """
374  dataRef, kwargs = args
375  if self.log is None:
376  self.log = Log.getDefaultLogger()
377  if hasattr(dataRef, "dataId"):
378  self.log.MDC("LABEL", str(dataRef.dataId))
379  elif isinstance(dataRef, (list, tuple)):
380  self.log.MDC("LABEL", str([ref.dataId for ref in dataRef if hasattr(ref, "dataId")]))
381  task = self.makeTask(args=args)
382  result = None # in case the task fails
383  exitStatus = 0 # exit status for the shell
384  if self.doRaise:
385  result = self.runTask(task, dataRef, kwargs)
386  else:
387  try:
388  result = self.runTask(task, dataRef, kwargs)
389  except Exception as e:
390  # The shell exit value will be the number of dataRefs returning
391  # non-zero, so the actual value used here is lost.
392  exitStatus = 1
393 
394  # don't use a try block as we need to preserve the original exception
395  eName = type(e).__name__
396  if hasattr(dataRef, "dataId"):
397  task.log.fatal("Failed on dataId=%s: %s: %s", dataRef.dataId, eName, e)
398  elif isinstance(dataRef, (list, tuple)):
399  task.log.fatal("Failed on dataIds=[%s]: %s: %s",
400  ", ".join(str(ref.dataId) for ref in dataRef), eName, e)
401  else:
402  task.log.fatal("Failed on dataRef=%s: %s: %s", dataRef, eName, e)
403 
404  if not isinstance(e, TaskError):
405  traceback.print_exc(file=sys.stderr)
406 
407  # Ensure all errors have been logged and aren't hanging around in a buffer
408  sys.stdout.flush()
409  sys.stderr.flush()
410 
411  task.writeMetadata(dataRef)
412 
413  # remove MDC so it does not show up outside of task context
414  self.log.MDCRemove("LABEL")
415 
416  if self.doReturnResults:
417  return Struct(
418  exitStatus=exitStatus,
419  dataRef=dataRef,
420  metadata=task.metadata,
421  result=result,
422  )
423  else:
424  return Struct(
425  exitStatus=exitStatus,
426  )
427 
table::Key< int > type
Definition: Detector.cc:167

◆ buildRefDict()

def lsst.pipe.tasks.multiBandUtils.MergeSourcesRunner.buildRefDict (   parsedCmd)
staticinherited
Build a hierarchical dictionary of patch references

Parameters
----------
parsedCmd:
    The parsed command

Returns
-------
refDict: dict
    A reference dictionary of the form {patch: {tract: {filter: dataRef}}}

Raises
------
RuntimeError
    Thrown when multiple references are provided for the same
    combination of tract, patch and filter

Definition at line 41 of file multiBandUtils.py.

41  def buildRefDict(parsedCmd):
42  """Build a hierarchical dictionary of patch references
43 
44  Parameters
45  ----------
46  parsedCmd:
47  The parsed command
48 
49  Returns
50  -------
51  refDict: dict
52  A reference dictionary of the form {patch: {tract: {filter: dataRef}}}
53 
54  Raises
55  ------
56  RuntimeError
57  Thrown when multiple references are provided for the same
58  combination of tract, patch and filter
59  """
60  refDict = {} # Will index this as refDict[tract][patch][filter] = ref
61  for ref in parsedCmd.id.refList:
62  tract = ref.dataId["tract"]
63  patch = ref.dataId["patch"]
64  filter = ref.dataId["filter"]
65  if tract not in refDict:
66  refDict[tract] = {}
67  if patch not in refDict[tract]:
68  refDict[tract][patch] = {}
69  if filter in refDict[tract][patch]:
70  raise RuntimeError("Multiple versions of %s" % (ref.dataId,))
71  refDict[tract][patch][filter] = ref
72  return refDict
73 

◆ getTargetList()

def lsst.pipe.tasks.multiBand.DeblendCoaddSourcesRunner.getTargetList (   parsedCmd,
  kwargs 
)
static
Provide a list of patch references for each patch, tract, filter combo.

Parameters
----------
parsedCmd:
    The parsed command
kwargs:
    Keyword arguments passed to the task

Returns
-------
targetList: list
    List of tuples, where each tuple is a (dataRef, kwargs) pair.

Definition at line 376 of file multiBand.py.

376  def getTargetList(parsedCmd, **kwargs):
377  """Provide a list of patch references for each patch, tract, filter combo.
378 
379  Parameters
380  ----------
381  parsedCmd:
382  The parsed command
383  kwargs:
384  Keyword arguments passed to the task
385 
386  Returns
387  -------
388  targetList: list
389  List of tuples, where each tuple is a (dataRef, kwargs) pair.
390  """
391  refDict = MergeSourcesRunner.buildRefDict(parsedCmd)
392  kwargs["psfCache"] = parsedCmd.psfCache
393  return [(list(p.values()), kwargs) for t in refDict.values() for p in t.values()]
394 
395 
daf::base::PropertyList * list
Definition: fits.cc:885

◆ makeTask()

def lsst.pipe.tasks.multiBandUtils.MergeSourcesRunner.makeTask (   self,
  parsedCmd = None,
  args = None 
)
inherited
Provide a butler to the Task constructor.

Parameters
----------
parsedCmd:
    The parsed command
args: tuple
    Tuple of a list of data references and kwargs (un-used)

Raises
------
RuntimeError
    Thrown if both `parsedCmd` & `args` are `None`

Definition at line 16 of file multiBandUtils.py.

16  def makeTask(self, parsedCmd=None, args=None):
17  """Provide a butler to the Task constructor.
18 
19  Parameters
20  ----------
21  parsedCmd:
22  The parsed command
23  args: tuple
24  Tuple of a list of data references and kwargs (un-used)
25 
26  Raises
27  ------
28  RuntimeError
29  Thrown if both `parsedCmd` & `args` are `None`
30  """
31  if parsedCmd is not None:
32  butler = parsedCmd.butler
33  elif args is not None:
34  dataRefList, kwargs = args
35  butler = dataRefList[0].getButler()
36  else:
37  raise RuntimeError("Neither parsedCmd or args specified")
38  return self.TaskClass(config=self.config, log=self.log, butler=butler)
39 

◆ precall()

def lsst.pipe.base.cmdLineTask.TaskRunner.precall (   self,
  parsedCmd 
)
inherited
Hook for code that should run exactly once, before multiprocessing.

Notes
-----
Must return True if `TaskRunner.__call__` should subsequently be called.

.. warning::

   Implementations must take care to ensure that no unpicklable attributes are added to the
   TaskRunner itself, for compatibility with multiprocessing.

The default implementation writes package versions, schemas and configs, or compares them to existing
files on disk if present.

Definition at line 312 of file cmdLineTask.py.

312  def precall(self, parsedCmd):
313  """Hook for code that should run exactly once, before multiprocessing.
314 
315  Notes
316  -----
317  Must return True if `TaskRunner.__call__` should subsequently be called.
318 
319  .. warning::
320 
321  Implementations must take care to ensure that no unpicklable attributes are added to the
322  TaskRunner itself, for compatibility with multiprocessing.
323 
324  The default implementation writes package versions, schemas and configs, or compares them to existing
325  files on disk if present.
326  """
327  task = self.makeTask(parsedCmd=parsedCmd)
328 
329  if self.doRaise:
330  self._precallImpl(task, parsedCmd)
331  else:
332  try:
333  self._precallImpl(task, parsedCmd)
334  except Exception as e:
335  task.log.fatal("Failed in task initialization: %s", e)
336  if not isinstance(e, TaskError):
337  traceback.print_exc(file=sys.stderr)
338  return False
339  return True
340 

◆ prepareForMultiProcessing()

def lsst.pipe.base.cmdLineTask.TaskRunner.prepareForMultiProcessing (   self)
inherited
Prepare this instance for multiprocessing

Optional non-picklable elements are removed.

This is only called if the task is run under multiprocessing.

Definition at line 174 of file cmdLineTask.py.

174  def prepareForMultiProcessing(self):
175  """Prepare this instance for multiprocessing
176 
177  Optional non-picklable elements are removed.
178 
179  This is only called if the task is run under multiprocessing.
180  """
181  self.log = None
182 

◆ run()

def lsst.pipe.base.cmdLineTask.TaskRunner.run (   self,
  parsedCmd 
)
inherited
Run the task on all targets.

Parameters
----------
parsedCmd : `argparse.Namespace`
    Parsed command `argparse.Namespace`.

Returns
-------
resultList : `list`
    A list of results returned by `TaskRunner.__call__`, or an empty list if `TaskRunner.__call__`
    is not called (e.g. if `TaskRunner.precall` returns `False`). See `TaskRunner.__call__`
    for details.

Notes
-----
The task is run under multiprocessing if `TaskRunner.numProcesses` is more than 1; otherwise
processing is serial.

Definition at line 183 of file cmdLineTask.py.

183  def run(self, parsedCmd):
184  """Run the task on all targets.
185 
186  Parameters
187  ----------
188  parsedCmd : `argparse.Namespace`
189  Parsed command `argparse.Namespace`.
190 
191  Returns
192  -------
193  resultList : `list`
194  A list of results returned by `TaskRunner.__call__`, or an empty list if `TaskRunner.__call__`
195  is not called (e.g. if `TaskRunner.precall` returns `False`). See `TaskRunner.__call__`
196  for details.
197 
198  Notes
199  -----
200  The task is run under multiprocessing if `TaskRunner.numProcesses` is more than 1; otherwise
201  processing is serial.
202  """
203  resultList = []
204  disableImplicitThreading() # To prevent thread contention
205  if self.numProcesses > 1:
206  import multiprocessing
207  self.prepareForMultiProcessing()
208  pool = multiprocessing.Pool(processes=self.numProcesses, maxtasksperchild=1)
209  mapFunc = functools.partial(_runPool, pool, self.timeout)
210  else:
211  pool = None
212  mapFunc = map
213 
214  if self.precall(parsedCmd):
215  profileName = parsedCmd.profile if hasattr(parsedCmd, "profile") else None
216  log = parsedCmd.log
217  targetList = self.getTargetList(parsedCmd)
218  if len(targetList) > 0:
219  with profile(profileName, log):
220  # Run the task using self.__call__
221  resultList = list(mapFunc(self, targetList))
222  else:
223  log.warn("Not running the task because there is no data to process; "
224  "you may preview data using \"--show data\"")
225 
226  if pool is not None:
227  pool.close()
228  pool.join()
229 
230  return resultList
231 
bool disableImplicitThreading()
Disable threading that has not been set explicitly.
Definition: threads.cc:132
def profile(filename, log=None)
Definition: cmdLineTask.py:49
daf::base::PropertyList * list
Definition: fits.cc:885

◆ runTask()

def lsst.pipe.base.cmdLineTask.TaskRunner.runTask (   self,
  task,
  dataRef,
  kwargs 
)
inherited
Make the actual call to `runDataRef` for this task.

Parameters
----------
task : `lsst.pipe.base.CmdLineTask` class
    The class of the task to run.
dataRef
    Butler data reference that contains the data the task will process.
kwargs
    Any additional keyword arguments.  See `TaskRunner.getTargetList` above.

Notes
-----
The default implementation of `TaskRunner.runTask` works for any command-line task which has a
runDataRef method that takes a data reference and an optional set of additional keyword arguments.
This method returns the results generated by the task's `runDataRef` method.

Definition at line 428 of file cmdLineTask.py.

428  def runTask(self, task, dataRef, kwargs):
429  """Make the actual call to `runDataRef` for this task.
430 
431  Parameters
432  ----------
433  task : `lsst.pipe.base.CmdLineTask` class
434  The class of the task to run.
435  dataRef
436  Butler data reference that contains the data the task will process.
437  kwargs
438  Any additional keyword arguments. See `TaskRunner.getTargetList` above.
439 
440  Notes
441  -----
442  The default implementation of `TaskRunner.runTask` works for any command-line task which has a
443  runDataRef method that takes a data reference and an optional set of additional keyword arguments.
444  This method returns the results generated by the task's `runDataRef` method.
445 
446  """
447  return task.runDataRef(dataRef, **kwargs)
448 
449 

Member Data Documentation

◆ clobberConfig

lsst.pipe.base.cmdLineTask.TaskRunner.clobberConfig
inherited

Definition at line 161 of file cmdLineTask.py.

◆ config

lsst.pipe.base.cmdLineTask.TaskRunner.config
inherited

Definition at line 158 of file cmdLineTask.py.

◆ doBackup

lsst.pipe.base.cmdLineTask.TaskRunner.doBackup
inherited

Definition at line 162 of file cmdLineTask.py.

◆ doRaise

lsst.pipe.base.cmdLineTask.TaskRunner.doRaise
inherited

Definition at line 160 of file cmdLineTask.py.

◆ doReturnResults

lsst.pipe.base.cmdLineTask.TaskRunner.doReturnResults
inherited

Definition at line 157 of file cmdLineTask.py.

◆ log

lsst.pipe.base.cmdLineTask.TaskRunner.log
inherited

Definition at line 159 of file cmdLineTask.py.

◆ numProcesses

lsst.pipe.base.cmdLineTask.TaskRunner.numProcesses
inherited

Definition at line 163 of file cmdLineTask.py.

◆ TaskClass

lsst.pipe.base.cmdLineTask.TaskRunner.TaskClass
inherited

Definition at line 156 of file cmdLineTask.py.

◆ TIMEOUT

int lsst.pipe.base.cmdLineTask.TaskRunner.TIMEOUT = 3600*24*30
staticinherited

Definition at line 152 of file cmdLineTask.py.

◆ timeout

lsst.pipe.base.cmdLineTask.TaskRunner.timeout
inherited

Definition at line 165 of file cmdLineTask.py.


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