LSST Applications g0b6bd0c080+a72a5dd7e6,g1182afd7b4+2a019aa3bb,g17e5ecfddb+2b8207f7de,g1d67935e3f+06cf436103,g38293774b4+ac198e9f13,g396055baef+6a2097e274,g3b44f30a73+6611e0205b,g480783c3b1+98f8679e14,g48ccf36440+89c08d0516,g4b93dc025c+98f8679e14,g5c4744a4d9+a302e8c7f0,g613e996a0d+e1c447f2e0,g6c8d09e9e7+25247a063c,g7271f0639c+98f8679e14,g7a9cd813b8+124095ede6,g9d27549199+a302e8c7f0,ga1cf026fa3+ac198e9f13,ga32aa97882+7403ac30ac,ga786bb30fb+7a139211af,gaa63f70f4e+9994eb9896,gabf319e997+ade567573c,gba47b54d5d+94dc90c3ea,gbec6a3398f+06cf436103,gc6308e37c7+07dd123edb,gc655b1545f+ade567573c,gcc9029db3c+ab229f5caf,gd01420fc67+06cf436103,gd877ba84e5+06cf436103,gdb4cecd868+6f279b5b48,ge2d134c3d5+cc4dbb2e3f,ge448b5faa6+86d1ceac1d,gecc7e12556+98f8679e14,gf3ee170dca+25247a063c,gf4ac96e456+ade567573c,gf9f5ea5b4d+ac198e9f13,gff490e6085+8c2580be5c,w.2022.27
LSST Data Management Base Package
demoTask.py
Go to the documentation of this file.
1import math
2import collections
3import operator
4from lsst.ctrl.pool.parallel import BatchPoolTask
5from lsst.ctrl.pool.pool import Pool
6from lsst.pipe.base import ArgumentParser
7from 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.logOperationlogOperation("master"):
54 total = pool.reduce(operator.add, self.runrun, 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.logOperationlogOperation("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 logOperation(self, operation, catch=False, trace=True)
Provide a context manager for logging an operation.
Definition: parallel.py:502
def batchWallTime(cls, time, parsedCmd, numCores)
Definition: demoTask.py:26
def runDataRef(self, visitRef)
Definition: demoTask.py:40
def run(self, cache, dataId, butler=None)
Definition: demoTask.py:58
daf::base::PropertyList * list
Definition: fits.cc:913