LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
LSSTDataManagementBasePackage
Public Member Functions | Public Attributes | Static Public Attributes | Static Private Attributes | List of all members
lsst.ip.isr.assembleCcdTask.AssembleCcdTask Class Reference

Assemble a set of amplifier images into a full detector size set of pixels. More...

Inheritance diagram for lsst.ip.isr.assembleCcdTask.AssembleCcdTask:

Public Member Functions

def __init__
 Initialize the AssembleCcdTask. More...
 
def assembleCcd
 Assemble a set of amps into a single CCD size image. More...
 
def postprocessExposure
 
def setWcs
 
def setGain
 

Public Attributes

 allKeysToRemove
 

Static Public Attributes

 ConfigClass = AssembleCcdConfig
 

Static Private Attributes

string _DefaultName = "assembleCcd"
 

Detailed Description

Assemble a set of amplifier images into a full detector size set of pixels.

Contents

Description

This task assembles sections of an image into a larger mosaic. The sub-sections are typically amplifier sections and are to be assembled into a detector size pixel grid. The assembly is driven by the entries in the raw amp information. The task can be configured to return a detector image with non-data (e.g. overscan) pixels included. The task can also renormalize the pixel values to a nominal gain of 1. The task also removes exposure metadata that has context in raw amps, but not in trimmed detectors (e.g. 'BIASSEC').

Task initialization

Initialize the AssembleCcdTask. The keys for removal specified in the config are added to a default set: ('DATASEC', 'BIASSEC', 'TRIMSEC', 'GAIN')

Inputs/Outputs to the assembleCcd method

Assemble a set of amps into a single CCD size image.

Parameters
[in]assembleInput– Either a dictionary of amp lsst.afw.image.Exposures or a single lsst.afw.image.Exposure containing all raw amps. If a dictionary of amp exposures, the key should be the amp name.
Returns
assembledCcd – An lsst.afw.image.Exposure of the assembled amp sections.
Exceptions
TypeErrorwith the following string:
Expected either a dictionary of amp exposures or a single raw exposure
The input exposures to be assembled do not adhere to the required format.
Exceptions
RuntimeErrorwith the following string:
No ccd detector found
The detector set on the input exposure is not set.

Configuration parameters

See AssembleCcdConfig

Debug variables

The command line task interface supports a flag -d to import debug.py from your PYTHONPATH; see Using lsstDebug to control debugging output for more about debug.py files.

The available variables in AssembleCcdTask are:

display
A dictionary containing debug point names as keys with frame number as value. Valid keys are:
assembledExposure
display assembled exposure

A complete example of using AssembleCcdTask

This code is in runAssembleTask.py in the examples directory, and can be run as e.g.

1 python examples/runAssembleTask.py
Import the task. There are other imports. Read the source file for more info.
1 from lsst.ip.isr import AssembleCcdTask

Create some input images with the help of some utilities in examples/exampleUtils.py
The above numbers can be changed. The assumption that the readout corner is flipped on every other amp is hardcoded in createDetector.

Run the assembler task
1 def runAssembler():
2  '''Run the task to assemble amps into a ccd'''
3 
4  #Create the assemble task with default config
5  assembleConfig = AssembleCcdTask.ConfigClass()
6  assembleTask = AssembleCcdTask(config=assembleConfig)
7  frame = 0
8 
9  #The assemble task can operate in two ways:
10  #1. On a dictionary of amp size images
11  #2. On a single amp mosaic image
12  #Both methods should produce the same output.
13  for isPerAmp in (True, False):
14  assemblyInput = exampleUtils.makeAssemblyInput(isPerAmp)
15  assembledExposure = assembleTask.assembleCcd(assemblyInput)
16  ds9.mtv(assembledExposure.getMaskedImage(), frame=frame, title="Per amp input is %s"%(isPerAmp))
17  frame += 1


To investigate the Debug variables, put something like

1 import lsstDebug
2 def DebugInfo(name):
3  di = lsstDebug.getInfo(name) # N.b. lsstDebug.Info(name) would call us recursively
4  if name == "lsst.ip.isr.assembleCcdTask":
5  di.display = {'assembledExposure':2}
6  return di
7 
8 lsstDebug.Info = DebugInfo

into your debug.py file and run runAssembleTask.py with the –debug flag.

Conversion notes: Display code should be updated once we settle on a standard way of controlling what is displayed.

Definition at line 60 of file assembleCcdTask.py.

Constructor & Destructor Documentation

def lsst.ip.isr.assembleCcdTask.AssembleCcdTask.__init__ (   self,
  kwargs 
)

Initialize the AssembleCcdTask.

The keys for removal specified in the config are added to a default set: ('DATASEC', 'BIASSEC', 'TRIMSEC', 'GAIN')

Definition at line 157 of file assembleCcdTask.py.

158  def __init__(self, **kwargs):
159  """!Initialize the AssembleCcdTask
160 
161  The keys for removal specified in the config are added to a default set:
162  ('DATASEC', 'BIASSEC', 'TRIMSEC', 'GAIN')
163  """
164  pipeBase.Task.__init__(self, **kwargs)
166  self.allKeysToRemove = ('DATASEC', 'BIASSEC', 'TRIMSEC', 'GAIN') + tuple(self.config.keysToRemove)
def __init__
Initialize the AssembleCcdTask.

Member Function Documentation

def lsst.ip.isr.assembleCcdTask.AssembleCcdTask.assembleCcd (   self,
  assembleInput 
)

Assemble a set of amps into a single CCD size image.

Parameters
[in]assembleInput– Either a dictionary of amp lsst.afw.image.Exposures or a single lsst.afw.image.Exposure containing all raw amps. If a dictionary of amp exposures, the key should be the amp name.
Returns
assembledCcd – An lsst.afw.image.Exposure of the assembled amp sections.
Exceptions
TypeErrorwith the following string:
Expected either a dictionary of amp exposures or a single raw exposure
The input exposures to be assembled do not adhere to the required format.
Exceptions
RuntimeErrorwith the following string:
No ccd detector found
The detector set on the input exposure is not set.

Definition at line 167 of file assembleCcdTask.py.

168  def assembleCcd(self, assembleInput):
169  """!Assemble a set of amps into a single CCD size image
170  \param[in] assembleInput -- Either a dictionary of amp lsst.afw.image.Exposures or a single
171  lsst.afw.image.Exposure containing all raw
172  amps. If a dictionary of amp exposures,
173  the key should be the amp name.
174  \return assembledCcd -- An lsst.afw.image.Exposure of the assembled amp sections.
175 
176  \throws TypeError with the following string:
177 
178  <DL>
179  <DT> Expected either a dictionary of amp exposures or a single raw exposure
180  <DD> The input exposures to be assembled do not adhere to the required format.
181  </DL>
182 
183  \throws RuntimeError with the following string:
184 
185  <DL>
186  <DT> No ccd detector found
187  <DD> The detector set on the input exposure is not set.
188  </DL>
189  """
190  ccd = None
191  if hasattr(assembleInput, "has_key"):
192  # Get a detector object for this set of amps
193  ccd = assembleInput.itervalues().next().getDetector()
194  # Sent a dictionary of input exposures, assume one amp per key keyed on amp name
195  def getNextExposure(amp):
196  return assembleInput[amp.getName()]
197  elif hasattr(assembleInput, "getMaskedImage"):
198  ccd = assembleInput.getDetector()
199  # A single exposure was sent. Use this to assemble.
200  def getNextExposure(amp):
201  return assembleInput
202  else:
203  raise TypeError("Expected either a dictionary of amp exposures or a single raw exposure")
204 
205  if ccd is None:
206  raise RuntimeError("No ccd detector found")
207 
208  if not self.config.doTrim:
209  outBox = cameraGeomUtils.calcRawCcdBBox(ccd)
210  else:
211  outBox = ccd.getBBox()
212  outExposure = afwImage.ExposureF(outBox)
213  outMI = outExposure.getMaskedImage()
214 
215  if self.config.doTrim:
216  assemble = cameraGeom.assembleAmplifierImage
217  else:
218  assemble = cameraGeom.assembleAmplifierRawImage
219 
220  for amp in ccd:
221  inMI = getNextExposure(amp).getMaskedImage()
222  assemble(outMI, inMI, amp)
223  outExposure.setDetector(ccd)
224  self.postprocessExposure(outExposure=outExposure, inExposure=getNextExposure(ccd[0]))
225 
226  return outExposure
def assembleCcd
Assemble a set of amps into a single CCD size image.
def lsst.ip.isr.assembleCcdTask.AssembleCcdTask.postprocessExposure (   self,
  outExposure,
  inExposure 
)
Set exposure non-image attributes, including wcs and metadata and display exposure (if requested)

Call after assembling the pixels

@param[in,out]  outExposure assembled exposure:
                    - removes unwanted keywords
                    - sets calib, filter, and detector
@param[in]      inExposure  input exposure

Definition at line 227 of file assembleCcdTask.py.

228  def postprocessExposure(self, outExposure, inExposure):
229  """Set exposure non-image attributes, including wcs and metadata and display exposure (if requested)
230 
231  Call after assembling the pixels
232 
233  @param[in,out] outExposure assembled exposure:
234  - removes unwanted keywords
235  - sets calib, filter, and detector
236  @param[in] inExposure input exposure
237  """
238  self.setWcs(outExposure = outExposure, inExposure = inExposure)
239 
240  exposureMetadata = inExposure.getMetadata()
241  for key in self.allKeysToRemove:
242  if exposureMetadata.exists(key):
243  exposureMetadata.remove(key)
244  outExposure.setMetadata(exposureMetadata)
245 
246  if self.config.setGain:
247  self.setGain(outExposure = outExposure)
248 
249  inCalib = inExposure.getCalib()
250  outCalib = outExposure.getCalib()
251  outCalib.setExptime(inCalib.getExptime())
252  outCalib.setMidTime(inCalib.getMidTime())
253 
254  outExposure.setFilter(inExposure.getFilter())
255 
256  self.display("assembledExposure", exposure=outExposure)
def lsst.ip.isr.assembleCcdTask.AssembleCcdTask.setGain (   self,
  outExposure 
)
Renormalize, if requested, and set gain metadata

@param[in,out]  outExposure     assembled exposure:
                        - scales the pixels if config.doRenorm is true
                        - adds some gain keywords to the metadata

Definition at line 274 of file assembleCcdTask.py.

275  def setGain(self, outExposure):
276  """Renormalize, if requested, and set gain metadata
277 
278  @param[in,out] outExposure assembled exposure:
279  - scales the pixels if config.doRenorm is true
280  - adds some gain keywords to the metadata
281  """
282  if outExposure.getMaskedImage().getVariance().getArray().max() == 0:
283  raise RuntimeError("Can't calculate the effective gain since the variance plane is set to zero")
284  ccd = outExposure.getDetector()
285  exposureMetadata = outExposure.getMetadata()
286  gain = 0.
287  namps = 0
288  for amp in ccd:
289  gain += amp.getGain()
290  namps += 1
291  gain /= namps
292  if self.config.doRenorm:
293  mi = outExposure.getMaskedImage()
294  mi *= gain
295  exposureMetadata.set("GAIN", 1.0)
296  medgain, meangain = calcEffectiveGain(outExposure.getMaskedImage())
297  exposureMetadata.add("MEDGAIN", medgain)
298  exposureMetadata.add("MEANGAIN", meangain)
299  exposureMetadata.add("GAINEFF", medgain)
def calcEffectiveGain
Definition: isr.py:42
def lsst.ip.isr.assembleCcdTask.AssembleCcdTask.setWcs (   self,
  outExposure,
  inExposure 
)
Set output WCS = input WCS, adjusted as required for datasecs not starting at lower left corner

@param[in,out]  outExposure     assembled exposure; wcs is set
@param[in]      inExposure      input exposure

Definition at line 257 of file assembleCcdTask.py.

258  def setWcs(self, outExposure, inExposure):
259  """Set output WCS = input WCS, adjusted as required for datasecs not starting at lower left corner
260 
261  @param[in,out] outExposure assembled exposure; wcs is set
262  @param[in] inExposure input exposure
263  """
264  if inExposure.hasWcs():
265  wcs = inExposure.getWcs()
266  ccd = outExposure.getDetector()
267  amp0 = ccd[0]
268  if amp0 is None:
269  raise RuntimeError("No amplifier detector information found")
270  cameraGeomUtils.prepareWcsData(wcs, amp0)
271  outExposure.setWcs(wcs)
272  else:
273  self.log.log(self.log.WARN, "No WCS found in input exposure")

Member Data Documentation

string lsst.ip.isr.assembleCcdTask.AssembleCcdTask._DefaultName = "assembleCcd"
staticprivate

Definition at line 155 of file assembleCcdTask.py.

lsst.ip.isr.assembleCcdTask.AssembleCcdTask.allKeysToRemove

Definition at line 165 of file assembleCcdTask.py.

lsst.ip.isr.assembleCcdTask.AssembleCcdTask.ConfigClass = AssembleCcdConfig
static

Definition at line 154 of file assembleCcdTask.py.


The documentation for this class was generated from the following file: