LSSTApplications  17.0+1,17.0+10,17.0+16,17.0+17,17.0+2,17.0+21,17.0+3,17.0+4,17.0-1-g377950a+9,17.0.1-1-g444bd44+9,17.0.1-1-g46e6382+10,17.0.1-1-g4d4fbc4+4,17.0.1-1-g703d48b+6,17.0.1-1-g8de6c91,17.0.1-1-g9deacb5+9,17.0.1-1-gf4e0155+10,17.0.1-1-gfc65f5f+9,17.0.1-1-gfc6fb1f+5,17.0.1-2-g3bdf598,17.0.1-2-g3e5d191+1,17.0.1-2-ga5d6a7c+4,17.0.1-2-gd73ec07+10,17.0.1-3-gcbbb95d+5,17.0.1-3-geaa4c8a+4,17.0.1-4-g088434c+4,17.0.1-4-ga7077188,17.0.1-4-gf25f8e6,17.0.1-5-g5a10bbc+1,17.0.1-5-gf0ac6446+12,17.0.1-6-g7bb9714,17.0.1-7-g69836a1+10,17.0.1-7-gf7766dbc3,w.2019.13
LSSTDataManagementBasePackage
Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | List of all members
lsst.meas.algorithms.debugger.MeasurementDebuggerRunner Class Reference
Inheritance diagram for lsst.meas.algorithms.debugger.MeasurementDebuggerRunner:
lsst.pipe.base.cmdLineTask.TaskRunner

Public Member Functions

def prepareForMultiProcessing (self)
 
def run (self, parsedCmd)
 
def makeTask (self, parsedCmd=None, args=None)
 
def precall (self, parsedCmd)
 
def __call__ (self, args)
 
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

Provide the image and catalog names to the Task

We provide a dummy dataRef only to avoid further overrides
of this class.

Definition at line 52 of file debugger.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:164

◆ getTargetList()

def lsst.meas.algorithms.debugger.MeasurementDebuggerRunner.getTargetList (   parsedCmd,
  kwargs 
)
static

Definition at line 59 of file debugger.py.

59  def getTargetList(parsedCmd, **kwargs):
60  kwargs["image"] = parsedCmd.image
61  kwargs["catalog"] = parsedCmd.catalog
62  return [(Struct(dataId="<none>"), kwargs)]
63 
64 

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