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
visualizeVisit.py
Go to the documentation of this file.
1import numpy as np
2
3import lsst.afw.math as afwMath
4import lsst.afw.image as afwImage
5
6from lsst.afw.cameraGeom.utils import makeImageFromCamera
7from lsst.pipe.base import ArgumentParser
8from lsst.pex.config import Config, Field
9from lsst.ctrl.pool.pool import Pool
10from lsst.ctrl.pool.parallel import BatchPoolTask
11
12
13def makeCameraImage(camera, exposures, binning):
14 """Make and write an image of an entire focal plane
15
16 Parameters
17 ----------
19 Camera description.
20 exposures : `dict` mapping detector ID to `lsst.afw.image.Exposure`
21 CCD exposures, binned by `binning`.
22 binning : `int`
23 Binning size that has been applied to images.
24 """
25 class ImageSource:
26 """Source of images for makeImageFromCamera"""
27 def __init__(self, exposures):
28 """Constructor
29
30 Parameters
31 ----------
32 exposures : `dict` mapping detector ID to `lsst.afw.image.Exposure`
33 CCD exposures, already binned.
34 """
35 self.isTrimmed = True
36 self.exposures = exposures
37 self.background = np.nan
38
39 def getCcdImage(self, detector, imageFactory, binSize):
40 """Provide image of CCD to makeImageFromCamera"""
41 detId = detector.getId()
42 if detId not in self.exposures:
43 dims = detector.getBBox().getDimensions()/binSize
44 image = imageFactory(*[int(xx) for xx in dims])
45 image.set(self.background)
46 else:
47 image = self.exposures[detector.getId()]
48 if hasattr(image, "getMaskedImage"):
49 image = image.getMaskedImage()
50 if hasattr(image, "getMask"):
51 mask = image.getMask()
52 isBad = mask.getArray() & mask.getPlaneBitMask("NO_DATA") > 0
53 image = image.clone()
54 image.getImage().getArray()[isBad] = self.background
55 if hasattr(image, "getImage"):
56 image = image.getImage()
57
58 image = afwMath.rotateImageBy90(image, detector.getOrientation().getNQuarter())
59
60 return image, detector
61
62 image = makeImageFromCamera(
63 camera,
64 imageSource=ImageSource(exposures),
65 imageFactory=afwImage.ImageF,
66 binSize=binning
67 )
68 return image
69
70
72 binning = Field(dtype=int, default=8, doc="Binning factor to apply")
73
74
76 ConfigClass = VisualizeVisitConfig
77 _DefaultName = "visualizeVisit"
78
79 def __init__(self, *args, **kwargs):
80 BatchPoolTask.__init__(self, *args, **kwargs)
81 self._storedButler_storedButler = False # Stored butler in the Pool? Doing this once increases efficiency
82
83 @classmethod
84 def _makeArgumentParser(cls, *args, **kwargs):
85 kwargs.pop("doBatch", False)
86 parser = ArgumentParser(name="visualizeVisit", *args, **kwargs)
87 parser.add_id_argument("--id", datasetType="calexp", level="visit",
88 help="data ID, e.g. --id visit=12345")
89 return parser
90
91 @classmethod
92 def batchWallTime(cls, time, parsedCmd, numCores):
93 """Return walltime request for batch job
94
95 Subclasses should override if the walltime should be calculated
96 differently (e.g., addition of some serial time).
97
98 Parameters
99 ----------
100 time : `float`
101 Requested time per iteration.
102 parsedCmd : `argparse.Namespace`
103 Results of argument parsing.
104 numCores : `int`
105 Number of cores.
106 """
107 numTargets = len(cls.RunnerClass.getTargetList(parsedCmd))
108 return time*numTargets
109
110 def runDataRef(self, expRef):
111 """Generate an image of the entire visit
112
113 Only the master node executes this method; it controls the slave nodes,
114 which do the data retrieval.
115
116 Parameters
117 ----------
119 Data reference for exposure.
120 """
121 pool = Pool()
122
123 if not self._storedButler_storedButler:
124 pool.storeSet(butler=expRef.getButler())
125
126 with self.logOperationlogOperation("processing %s" % (expRef.dataId,)):
127 camera = expRef.get("camera")
128 dataIdList = [ccdRef.dataId for ccdRef in expRef.subItems("ccd") if
129 ccdRef.datasetExists("calexp")]
130
131 exposures = pool.map(self.readImagereadImage, dataIdList)
132 exposures = dict(keyValue for keyValue in exposures if keyValue is not None)
133 image = makeCameraImage(camera, exposures, self.config.binning)
134 expRef.put(image, "calexp_camera")
135
136 def readImage(self, cache, dataId):
137 """Collect original image for visualisation
138
139 This method runs on the slave nodes.
140
141 Parameters
142 ----------
143 cache : `lsst.pipe.base.Struct`
144 Process pool cache.
145 dataId : `dict`
146 Data identifier.
147
148 Returns
149 -------
150 detId : `int`
151 Detector identifier.
153 Binned image.
154 """
155 exposure = cache.butler.get("calexp", dataId)
156 return (exposure.getDetector().getId(),
157 afwMath.binImage(exposure.getMaskedImage(), self.config.binning))
158
159 def _getConfigName(self):
160 """It's not worth preserving the configuration"""
161 return None
162
163 def _getMetadataName(self):
164 """There's no metadata to write out"""
165 return None
An immutable representation of a camera.
Definition: Camera.h:43
A class to contain the data, WCS, and other information needed to describe an image of the sky.
Definition: Exposure.h:72
A class to manipulate images, masks, and variance as a single object.
Definition: MaskedImage.h:73
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)
def makeImageFromCamera(camera, detectorNameList=None, background=numpy.nan, bufferSize=10, imageSource=FakeImageDataSource(), imageFactory=afwImage.ImageU, binSize=1)
Definition: utils.py:859
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects.
std::shared_ptr< ImageT > rotateImageBy90(ImageT const &image, int nQuarter)
Rotate an image by an integral number of quarter turns.
Definition: rotateImage.cc:39
std::shared_ptr< ImageT > binImage(ImageT const &inImage, int const binX, int const binY, lsst::afw::math::Property const flags=lsst::afw::math::MEAN)
Definition: binImage.cc:44
def makeCameraImage(camera, exposures, binning)