LSSTApplications  18.0.0+106,18.0.0+50,19.0.0,19.0.0+1,19.0.0+10,19.0.0+11,19.0.0+13,19.0.0+17,19.0.0+2,19.0.0-1-g20d9b18+6,19.0.0-1-g425ff20,19.0.0-1-g5549ca4,19.0.0-1-g580fafe+6,19.0.0-1-g6fe20d0+1,19.0.0-1-g7011481+9,19.0.0-1-g8c57eb9+6,19.0.0-1-gb5175dc+11,19.0.0-1-gdc0e4a7+9,19.0.0-1-ge272bc4+6,19.0.0-1-ge3aa853,19.0.0-10-g448f008b,19.0.0-12-g6990b2c,19.0.0-2-g0d9f9cd+11,19.0.0-2-g3d9e4fb2+11,19.0.0-2-g5037de4,19.0.0-2-gb96a1c4+3,19.0.0-2-gd955cfd+15,19.0.0-3-g2d13df8,19.0.0-3-g6f3c7dc,19.0.0-4-g725f80e+11,19.0.0-4-ga671dab3b+1,19.0.0-4-gad373c5+3,19.0.0-5-ga2acb9c+2,19.0.0-5-gfe96e6c+2,w.2020.01
LSSTDataManagementBasePackage
Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | List of all members
lsst.pipe.drivers.constructCalibs.CalibTaskRunner Class Reference
Inheritance diagram for lsst.pipe.drivers.constructCalibs.CalibTaskRunner:
lsst.pipe.base.cmdLineTask.TaskRunner

Public Member Functions

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

Static Public Member Functions

def getTargetList (parsedCmd, kwargs)
 

Public Attributes

 TaskClass
 
 doReturnResults
 
 config
 
 log
 
 doRaise
 
 clobberConfig
 
 doBackup
 
 numProcesses
 
 timeout
 

Static Public Attributes

int TIMEOUT = 3600*24*30
 

Detailed Description

Get parsed values into the CalibTask.run

Definition at line 351 of file constructCalibs.py.

Member Function Documentation

◆ __call__()

def lsst.pipe.drivers.constructCalibs.CalibTaskRunner.__call__ (   self,
  args 
)
Call the Task with the kwargs from getTargetList

Definition at line 357 of file constructCalibs.py.

357  def __call__(self, args):
358  """Call the Task with the kwargs from getTargetList"""
359  task = self.TaskClass(config=self.config, log=self.log)
360  exitStatus = 0 # exit status for the shell
361  if self.doRaise:
362  result = task.runDataRef(**args)
363  else:
364  try:
365  result = task.runDataRef(**args)
366  except Exception as e:
367  # n.b. The shell exit value is the number of dataRefs returning
368  # non-zero, so the actual value used here is lost
369  exitStatus = 1
370 
371  task.log.fatal("Failed: %s" % e)
372  traceback.print_exc(file=sys.stderr)
373 
374  if self.doReturnResults:
375  return Struct(
376  exitStatus=exitStatus,
377  args=args,
378  metadata=task.metadata,
379  result=result,
380  )
381  else:
382  return Struct(
383  exitStatus=exitStatus,
384  )
385 
386 

◆ getTargetList()

def lsst.pipe.drivers.constructCalibs.CalibTaskRunner.getTargetList (   parsedCmd,
  kwargs 
)
static

Definition at line 354 of file constructCalibs.py.

354  def getTargetList(parsedCmd, **kwargs):
355  return [dict(expRefList=parsedCmd.id.refList, butler=parsedCmd.butler, calibId=parsedCmd.calibId)]
356 

◆ makeTask()

def lsst.pipe.base.cmdLineTask.TaskRunner.makeTask (   self,
  parsedCmd = None,
  args = None 
)
inherited
Create a Task instance.

Parameters
----------
parsedCmd
    Parsed command-line options (used for extra task args by some task runners).
args
    Args tuple passed to `TaskRunner.__call__` (used for extra task arguments by some task runners).

Notes
-----
``makeTask`` can be called with either the ``parsedCmd`` argument or ``args`` argument set to None,
but it must construct identical Task instances in either case.

Subclasses may ignore this method entirely if they reimplement both `TaskRunner.precall` and
`TaskRunner.__call__`.

Definition at line 282 of file cmdLineTask.py.

282  def makeTask(self, parsedCmd=None, args=None):
283  """Create a Task instance.
284 
285  Parameters
286  ----------
287  parsedCmd
288  Parsed command-line options (used for extra task args by some task runners).
289  args
290  Args tuple passed to `TaskRunner.__call__` (used for extra task arguments by some task runners).
291 
292  Notes
293  -----
294  ``makeTask`` can be called with either the ``parsedCmd`` argument or ``args`` argument set to None,
295  but it must construct identical Task instances in either case.
296 
297  Subclasses may ignore this method entirely if they reimplement both `TaskRunner.precall` and
298  `TaskRunner.__call__`.
299  """
300  return self.TaskClass(config=self.config, log=self.log)
301 

◆ 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
def run(self, skyInfo, tempExpRefList, imageScalerList, weightList, altMaskList=None, mask=None, supplementaryData=None)
daf::base::PropertyList * list
Definition: fits.cc:903

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