LSSTApplications  16.0-10-g0ee56ad+5,16.0-11-ga33d1f2+5,16.0-12-g3ef5c14+3,16.0-12-g71e5ef5+18,16.0-12-gbdf3636+3,16.0-13-g118c103+3,16.0-13-g8f68b0a+3,16.0-15-gbf5c1cb+4,16.0-16-gfd17674+3,16.0-17-g7c01f5c+3,16.0-18-g0a50484+1,16.0-20-ga20f992+8,16.0-21-g0e05fd4+6,16.0-21-g15e2d33+4,16.0-22-g62d8060+4,16.0-22-g847a80f+4,16.0-25-gf00d9b8+1,16.0-28-g3990c221+4,16.0-3-gf928089+3,16.0-32-g88a4f23+5,16.0-34-gd7987ad+3,16.0-37-gc7333cb+2,16.0-4-g10fc685+2,16.0-4-g18f3627+26,16.0-4-g5f3a788+26,16.0-5-gaf5c3d7+4,16.0-5-gcc1f4bb+1,16.0-6-g3b92700+4,16.0-6-g4412fcd+3,16.0-6-g7235603+4,16.0-69-g2562ce1b+2,16.0-8-g14ebd58+4,16.0-8-g2df868b+1,16.0-8-g4cec79c+6,16.0-8-gadf6c7a+1,16.0-8-gfc7ad86,16.0-82-g59ec2a54a+1,16.0-9-g5400cdc+2,16.0-9-ge6233d7+5,master-g2880f2d8cf+3,v17.0.rc1
LSSTDataManagementBasePackage
demoTask.py
Go to the documentation of this file.
1 import math
2 import collections
3 import operator
4 from lsst.ctrl.pool.parallel import BatchPoolTask
5 from lsst.ctrl.pool.pool import Pool
6 from lsst.pipe.base import ArgumentParser
7 from lsst.pex.config import Config
8 
9 __all__ = ["DemoTask", ]
10 
11 
13  """Task for demonstrating the BatchPoolTask functionality"""
14  ConfigClass = Config
15  _DefaultName = "demo"
16 
17  @classmethod
18  def _makeArgumentParser(cls, *args, **kwargs):
19  kwargs.pop('doBatch', False) # Unused
20  parser = ArgumentParser(name="demo", *args, **kwargs)
21  parser.add_id_argument("--id", datasetType="raw", level="visit",
22  help="data ID, e.g. --id visit=12345")
23  return parser
24 
25  @classmethod
26  def batchWallTime(cls, time, parsedCmd, numCores):
27  """Return walltime request for batch job
28 
29  Subclasses should override if the walltime should be calculated
30  differently (e.g., addition of some serial time).
31 
32  @param time: Requested time per iteration
33  @param parsedCmd: Results of argument parsing
34  @param numCores: Number of cores
35  """
36  numTargets = [sum(1 for ccdRef in visitRef.subItems("ccd") if ccdRef.datasetExists("raw")) for
37  visitRef in parsedCmd.id.refList]
38  return time*sum(math.ceil(tt/numCores) for tt in numTargets)
39 
40  def runDataRef(self, visitRef):
41  """Main entry-point
42 
43  Only the master node runs this method. It will dispatch jobs to the
44  slave nodes.
45  """
46  pool = Pool("test")
47 
48  # Less overhead to transfer the butler once rather than in each dataRef
49  dataIdList = dict([(ccdRef.get("ccdExposureId"), ccdRef.dataId)
50  for ccdRef in visitRef.subItems("ccd") if ccdRef.datasetExists("raw")])
51  dataIdList = collections.OrderedDict(sorted(dataIdList.items()))
52 
53  with self.logOperation("master"):
54  total = pool.reduce(operator.add, self.run, list(dataIdList.values()),
55  butler=visitRef.getButler())
56  self.log.info("Total number of pixels read: %d" % (total,))
57 
58  def run(self, cache, dataId, butler=None):
59  """Read image and return number of pixels
60 
61  Only the slave nodes run this method.
62  """
63  assert butler is not None
64  with self.logOperation("read %s" % (dataId,)):
65  raw = butler.get("raw", dataId, immediate=True)
66  dims = raw.getDimensions()
67  num = dims.getX()*dims.getY()
68  self.log.info("Read %d pixels for %s" % (num, dataId,))
69  return num
70 
71  def _getConfigName(self):
72  return None
73 
74  def _getMetadataName(self):
75  return None
76 
77  def _getEupsVersionsName(self):
78  return None
def batchWallTime(cls, time, parsedCmd, numCores)
Definition: demoTask.py:26
def runDataRef(self, visitRef)
Definition: demoTask.py:40
def logOperation(self, operation, catch=False, trace=True)
Provide a context manager for logging an operation.
Definition: parallel.py:497
def run(self, cache, dataId, butler=None)
Definition: demoTask.py:58
daf::base::PropertyList * list
Definition: fits.cc:833