28 from lsstDebug
import getDebugFrame
30 __all__ = [
"AssembleCcdTask"]
34 doTrim = pexConfig.Field(
35 doc=
"trim out non-data regions?",
39 keysToRemove = pexConfig.ListField(
40 doc=
"FITS headers to remove (in addition to DATASEC, BIASSEC, TRIMSEC and perhaps GAIN)",
55 @anchor AssembleCcdTask_ 57 @brief Assemble a set of amplifier images into a full detector size set of pixels. 59 @section ip_isr_assemble_Contents Contents 61 - @ref ip_isr_assemble_Purpose 62 - @ref ip_isr_assemble_Initialize 63 - @ref ip_isr_assemble_IO 64 - @ref ip_isr_assemble_Config 65 - @ref ip_isr_assemble_Debug 66 - @ref ip_isr_assemble_Example 68 @section ip_isr_assemble_Purpose Description 70 This task assembles sections of an image into a larger mosaic. The sub-sections 71 are typically amplifier sections and are to be assembled into a detector size pixel grid. 72 The assembly is driven by the entries in the raw amp information. The task can be configured 73 to return a detector image with non-data (e.g. overscan) pixels included. The task can also 74 renormalize the pixel values to a nominal gain of 1. The task also removes exposure metadata that 75 has context in raw amps, but not in trimmed detectors (e.g. 'BIASSEC'). 77 @section ip_isr_assemble_Initialize Task initialization 81 @section ip_isr_assemble_IO Inputs/Outputs to the assembleCcd method 85 @section ip_isr_assemble_Config Configuration parameters 87 See @ref AssembleCcdConfig 89 @section ip_isr_assemble_Debug Debug variables 91 The @link lsst.pipe.base.cmdLineTask.CmdLineTask command line task@endlink interface supports a 92 flag @c -d to import @b debug.py from your @c PYTHONPATH; see <a 93 href="http://lsst-web.ncsa.illinois.edu/~buildbot/doxygen/x_masterDoxyDoc/base_debug.html"> 94 Using lsstDebug to control debugging output</a> for more about @b debug.py files. 96 The available variables in AssembleCcdTask are: 99 <DD> A dictionary containing debug point names as keys with frame number as value. Valid keys are: 101 <DT> assembledExposure 102 <DD> display assembled exposure 106 @section ip_isr_assemble_Example A complete example of using AssembleCcdTask 108 This code is in runAssembleTask.py in the examples directory, and can be run as @em e.g. 110 python examples/runAssembleTask.py 113 @dontinclude runAssembleTask.py 114 Import the task. There are other imports. Read the source file for more info. 115 @skipline AssembleCcdTask 117 @dontinclude exampleUtils.py 118 Create some input images with the help of some utilities in examples/exampleUtils.py 119 @skip makeAssemblyInput 121 The above numbers can be changed. The assumption that the readout corner is flipped on every other amp is 122 hardcoded in createDetector. 124 @dontinclude runAssembleTask.py 125 Run the assembler task 130 To investigate the @ref ip_isr_assemble_Debug, put something like 134 di = lsstDebug.getInfo(name) # N.b. lsstDebug.Info(name) would call us recursively 135 if name == "lsst.ip.isr.assembleCcdTask": 136 di.display = {'assembledExposure':2} 139 lsstDebug.Info = DebugInfo 141 into your debug.py file and run runAssembleTask.py with the @c --debug flag. 145 Display code should be updated once we settle on a standard way of controlling what is displayed. 147 ConfigClass = AssembleCcdConfig
148 _DefaultName =
"assembleCcd" 151 """!Initialize the AssembleCcdTask 153 The keys for removal specified in the config are added to a default set: 154 ('DATASEC', 'BIASSEC', 'TRIMSEC', 'GAIN') 156 pipeBase.Task.__init__(self, **kwargs)
158 self.
allKeysToRemove = (
'DATASEC',
'BIASSEC',
'TRIMSEC',
'GAIN') + tuple(self.config.keysToRemove)
161 """!Assemble a set of amps into a single CCD size image 162 @param[in] assembleInput -- Either a dictionary of amp lsst.afw.image.Exposures or a single 163 lsst.afw.image.Exposure containing all raw 164 amps. If a dictionary of amp exposures, 165 the key should be the amp name. 166 @return assembledCcd -- An lsst.afw.image.Exposure of the assembled amp sections. 168 @throws TypeError with the following string: 171 <DT> Expected either a dictionary of amp exposures or a single raw exposure 172 <DD> The input exposures to be assembled do not adhere to the required format. 175 @throws RuntimeError with the following string: 178 <DT> No ccd detector found 179 <DD> The detector set on the input exposure is not set. 183 if isinstance(assembleInput, dict):
187 ccd = next(iter(assembleInput.values())).getDetector()
189 def getNextExposure(amp):
190 return assembleInput[amp.getName()]
191 elif hasattr(assembleInput,
"getMaskedImage"):
193 ccd = assembleInput.getDetector()
195 def getNextExposure(amp):
198 raise TypeError(
"Expected either a dictionary of amp exposures or a single raw exposure")
201 raise RuntimeError(
"No ccd detector found")
203 if not self.config.doTrim:
204 outBox = cameraGeomUtils.calcRawCcdBBox(ccd)
206 outBox = ccd.getBBox()
207 outExposure = afwImage.ExposureF(outBox)
208 outMI = outExposure.getMaskedImage()
210 if self.config.doTrim:
211 assemble = cameraGeom.assembleAmplifierImage
213 assemble = cameraGeom.assembleAmplifierRawImage
216 inMI = getNextExposure(amp).getMaskedImage()
217 assemble(outMI, inMI, amp)
223 if not self.config.doTrim:
224 ccd = cameraGeom.makeUpdatedDetector(ccd)
226 outExposure.setDetector(ccd)
232 """Set exposure non-image attributes, including wcs and metadata and display exposure (if requested) 234 Call after assembling the pixels 236 @param[in,out] outExposure assembled exposure: 237 - removes unwanted keywords 238 - sets photoCalib, filter, and detector 239 @param[in] inExposure input exposure 241 self.
setWcs(outExposure=outExposure, inExposure=inExposure)
243 exposureMetadata = inExposure.getMetadata()
245 if exposureMetadata.exists(key):
246 exposureMetadata.remove(key)
247 outExposure.setMetadata(exposureMetadata)
250 outExposure.setFilter(inExposure.getFilter())
251 outExposure.getInfo().setVisitInfo(inExposure.getInfo().getVisitInfo())
255 afwDisplay.Display(frame=frame).
mtv(outExposure, title=
"postprocessExposure")
257 def setWcs(self, outExposure, inExposure):
258 """Set output WCS = input WCS, adjusted as required for datasecs not starting at lower left corner 260 @param[in,out] outExposure assembled exposure; wcs is set 261 @param[in] inExposure input exposure 263 if inExposure.hasWcs():
264 wcs = inExposure.getWcs()
265 ccd = outExposure.getDetector()
268 raise RuntimeError(
"No amplifier detector information found")
269 adjustedWcs = cameraGeomUtils.prepareWcsData(wcs, amp0, isTrimmed=self.config.doTrim)
270 outExposure.setWcs(adjustedWcs)
Assemble a set of amplifier images into a full detector size set of pixels.
def setWcs(self, outExposure, inExposure)
def __init__(self, kwargs)
Initialize the AssembleCcdTask.
def mtv(data, frame=None, title="", wcs=None, args, kwargs)
def getDebugFrame(debugDisplay, name)
def postprocessExposure(self, outExposure, inExposure)
def assembleCcd(self, assembleInput)
Assemble a set of amps into a single CCD size image.
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects...