LSSTApplications  10.0-2-g4f67435,11.0.rc2+1,11.0.rc2+12,11.0.rc2+3,11.0.rc2+4,11.0.rc2+5,11.0.rc2+6,11.0.rc2+7,11.0.rc2+8
LSSTDataManagementBasePackage
Functions
lsst.ip.isr.isr Namespace Reference

Functions

def createPsf
 
def calcEffectiveGain
 
def transposeMaskedImage
 
def interpolateDefectList
 
def defectListFromFootprintList
 
def transposeDefectList
 
def maskPixelsFromDefectList
 
def getDefectListFromMask
 
def makeThresholdMask
 
def interpolateFromMask
 
def saturationCorrection
 
def biasCorrection
 
def darkCorrection
 
def updateVariance
 
def flatCorrection
 
def illuminationCorrection
 
def overscanCorrection
 

Function Documentation

def lsst.ip.isr.isr.biasCorrection (   maskedImage,
  biasMaskedImage 
)
Apply bias correction in place

@param[in,out] maskedImage  masked image to correct
@param[in] biasMaskedImage  bias, as a masked image

Definition at line 206 of file isr.py.

207 def biasCorrection(maskedImage, biasMaskedImage):
208  """Apply bias correction in place
209 
210  @param[in,out] maskedImage masked image to correct
211  @param[in] biasMaskedImage bias, as a masked image
212  """
213  if maskedImage.getBBox(afwImage.LOCAL) != biasMaskedImage.getBBox(afwImage.LOCAL):
214  raise RuntimeError("maskedImage bbox %s != biasMaskedImage bbox %s" % \
215  (maskedImage.getBBox(afwImage.LOCAL), biasMaskedImage.getBBox(afwImage.LOCAL)))
216  maskedImage -= biasMaskedImage
def biasCorrection
Definition: isr.py:206
def lsst.ip.isr.isr.calcEffectiveGain (   maskedImage)
Calculate effective gain

@param[in] maskedImage  afw.image.MaskedImage to process
@return (median gain, mean gain) in e-/ADU

Definition at line 42 of file isr.py.

42 
43 def calcEffectiveGain(maskedImage):
44  """Calculate effective gain
45 
46  @param[in] maskedImage afw.image.MaskedImage to process
47  @return (median gain, mean gain) in e-/ADU
48  """
49  im = afwImage.ImageF(maskedImage.getImage(), True)
50  var = maskedImage.getVariance()
51  im /= var
52  medgain = afwMath.makeStatistics(im, afwMath.MEDIAN).getValue()
53  meangain = afwMath.makeStatistics(im, afwMath.MEANCLIP).getValue()
54  return medgain, meangain
def calcEffectiveGain
Definition: isr.py:42
Statistics makeStatistics(afwImage::Mask< afwImage::MaskPixel > const &msk, int const flags, StatisticsControl const &sctrl)
Specialization to handle Masks.
Definition: Statistics.cc:1082
def lsst.ip.isr.isr.createPsf (   fwhm)
Make a double Gaussian PSF

@param[in] fwhm  FWHM of double Gaussian smoothing kernel
@return measAlg.DoubleGaussianPsf

Definition at line 33 of file isr.py.

33 
34 def createPsf(fwhm):
35  """Make a double Gaussian PSF
36 
37  @param[in] fwhm FWHM of double Gaussian smoothing kernel
38  @return measAlg.DoubleGaussianPsf
39  """
40  ksize = 4*int(fwhm) + 1
41  return measAlg.DoubleGaussianPsf(ksize, ksize, fwhm/(2*math.sqrt(2*math.log(2))))
Represent a Psf as a circularly symmetrical double Gaussian.
def createPsf
Definition: isr.py:33
def lsst.ip.isr.isr.darkCorrection (   maskedImage,
  darkMaskedImage,
  expScale,
  darkScale 
)
Apply dark correction in place

maskedImage -= dark * expScaling / darkScaling

@param[in,out] maskedImage  afw.image.MaskedImage to correct
@param[in] darkMaskedImage  dark afw.image.MaskedImage
@param[in] expScale  exposure scale
@param[in] darkScale  dark scale

Definition at line 217 of file isr.py.

218 def darkCorrection(maskedImage, darkMaskedImage, expScale, darkScale):
219  """Apply dark correction in place
220 
221  maskedImage -= dark * expScaling / darkScaling
222 
223  @param[in,out] maskedImage afw.image.MaskedImage to correct
224  @param[in] darkMaskedImage dark afw.image.MaskedImage
225  @param[in] expScale exposure scale
226  @param[in] darkScale dark scale
227  """
228  if maskedImage.getBBox(afwImage.LOCAL) != darkMaskedImage.getBBox(afwImage.LOCAL):
229  raise RuntimeError("maskedImage bbox %s != darkMaskedImage bbox %s" % \
230  (maskedImage.getBBox(afwImage.LOCAL), darkMaskedImage.getBBox(afwImage.LOCAL)))
231 
232  scale = expScale / darkScale
233  maskedImage.scaledMinus(scale, darkMaskedImage)
def darkCorrection
Definition: isr.py:217
def lsst.ip.isr.isr.defectListFromFootprintList (   fpList,
  growFootprints = 1 
)
Compute a defect list from a footprint list, optionally growing the footprints

@param[in] fpList  footprint list
@param[in] growFootprints  amount by which to grow footprints of detected regions
@return meas.algorithms.DefectListT

Definition at line 83 of file isr.py.

83 
84 def defectListFromFootprintList(fpList, growFootprints=1):
85  """Compute a defect list from a footprint list, optionally growing the footprints
86 
87  @param[in] fpList footprint list
88  @param[in] growFootprints amount by which to grow footprints of detected regions
89  @return meas.algorithms.DefectListT
90  """
91  defectList = measAlg.DefectListT()
92  for fp in fpList:
93  if growFootprints > 0:
94  # if "True", growing requires a convolution
95  # if "False", its faster
96  fpGrow = afwDetection.growFootprint(fp, growFootprints, False)
97  else:
98  fpGrow = fp
99  for bbox in afwDetection.footprintToBBoxList(fpGrow):
100  defect = measAlg.Defect(bbox)
101  defectList.push_back(defect)
102  return defectList
boost::shared_ptr< Footprint > growFootprint(Footprint const &foot, int nGrow, bool left, bool right, bool up, bool down)
Grow a Footprint in at least one of the cardinal directions, returning a new Footprint.
std::vector< lsst::afw::geom::Box2I > footprintToBBoxList(Footprint const &foot)
Encapsulate information about a bad portion of a detector.
Definition: Interp.h:70
def defectListFromFootprintList
Definition: isr.py:83
def lsst.ip.isr.isr.flatCorrection (   maskedImage,
  flatMaskedImage,
  scalingType,
  userScale = 1.0 
)
Apply flat correction in place

@param[in,out] maskedImage  afw.image.MaskedImage to correct
@param[in] flatMaskedImage  flat field afw.image.MaskedImage
@param[in] scalingType  how to compute flat scale; one of 'MEAN', 'MEDIAN' or 'USER'
@param[in] userScale  scale to use if scalingType is 'USER', else ignored

Definition at line 246 of file isr.py.

247 def flatCorrection(maskedImage, flatMaskedImage, scalingType, userScale=1.0):
248  """Apply flat correction in place
249 
250  @param[in,out] maskedImage afw.image.MaskedImage to correct
251  @param[in] flatMaskedImage flat field afw.image.MaskedImage
252  @param[in] scalingType how to compute flat scale; one of 'MEAN', 'MEDIAN' or 'USER'
253  @param[in] userScale scale to use if scalingType is 'USER', else ignored
254  """
255  if maskedImage.getBBox(afwImage.LOCAL) != flatMaskedImage.getBBox(afwImage.LOCAL):
256  raise RuntimeError("maskedImage bbox %s != flatMaskedImage bbox %s" % \
257  (maskedImage.getBBox(afwImage.LOCAL), flatMaskedImage.getBBox(afwImage.LOCAL)))
258 
259  # Figure out scale from the data
260  # Ideally the flats are normalized by the calibration product pipelin, but this allows some flexibility
261  # in the case that the flat is created by some other mechanism.
262  if scalingType == 'MEAN':
263  flatScale = afwMath.makeStatistics(flatMaskedImage.getImage(), afwMath.MEAN).getValue(afwMath.MEAN)
264  elif scalingType == 'MEDIAN':
265  flatScale = afwMath.makeStatistics(flatMaskedImage.getImage(), afwMath.MEDIAN).getValue(afwMath.MEDIAN)
266  elif scalingType == 'USER':
267  flatScale = userScale
268  else:
269  raise pexExcept.Exception, '%s : %s not implemented' % ("flatCorrection", scalingType)
270 
271  maskedImage.scaledDivides(1.0/flatScale, flatMaskedImage)
def flatCorrection
Definition: isr.py:246
Statistics makeStatistics(afwImage::Mask< afwImage::MaskPixel > const &msk, int const flags, StatisticsControl const &sctrl)
Specialization to handle Masks.
Definition: Statistics.cc:1082
def lsst.ip.isr.isr.getDefectListFromMask (   maskedImage,
  maskName,
  growFootprints = 1 
)
Compute a defect list from a specified mask plane

@param[in] maskedImage  masked image to process
@param[in] maskName  mask plane name, or list of names
@param[in] growFootprints  amount by which to grow footprints of detected regions
@return meas.algrithms.DefectListT of regions in mask

Definition at line 131 of file isr.py.

132 def getDefectListFromMask(maskedImage, maskName, growFootprints=1):
133  """Compute a defect list from a specified mask plane
134 
135  @param[in] maskedImage masked image to process
136  @param[in] maskName mask plane name, or list of names
137  @param[in] growFootprints amount by which to grow footprints of detected regions
138  @return meas.algrithms.DefectListT of regions in mask
139  """
140  mask = maskedImage.getMask()
141  workmask = afwImage.MaskU(mask, True)
142  workmask &= mask.getPlaneBitMask(maskName)
143  thresh = afwDetection.Threshold(0.5)
144  maskimg = afwImage.ImageU(workmask.getBBox())
145  maskimg <<= workmask
146  ds = afwDetection.FootprintSet(maskimg, thresh)
147  fpList = ds.getFootprints()
148  return defectListFromFootprintList(fpList, growFootprints)
A Threshold is used to pass a threshold value to detection algorithms.
Definition: Threshold.h:44
def getDefectListFromMask
Definition: isr.py:131
A set of Footprints, associated with a MaskedImage.
Definition: FootprintSet.h:53
def defectListFromFootprintList
Definition: isr.py:83
def lsst.ip.isr.isr.illuminationCorrection (   maskedImage,
  illumMaskedImage,
  illumScale 
)
Apply illumination correction in place

@param[in,out] maskedImage  afw.image.MaskedImage to correct
@param[in] illumMaskedImage  illumination correction masked image
@param[in] illumScale  scale value for illumination correction

Definition at line 272 of file isr.py.

273 def illuminationCorrection(maskedImage, illumMaskedImage, illumScale):
274  """Apply illumination correction in place
275 
276  @param[in,out] maskedImage afw.image.MaskedImage to correct
277  @param[in] illumMaskedImage illumination correction masked image
278  @param[in] illumScale scale value for illumination correction
279  """
280  if maskedImage.getBBox(afwImage.LOCAL) != illumMaskedImage.getBBox(afwImage.LOCAL):
281  raise RuntimeError("maskedImage bbox %s != illumMaskedImage bbox %s" % \
282  (maskedImage.getBBox(afwImage.LOCAL), illumMaskedImage.getBBox(afwImage.LOCAL)))
283 
284  maskedImage.scaledDivides(1./illumScale, illumMaskedImage)
def illuminationCorrection
Definition: isr.py:272
def lsst.ip.isr.isr.interpolateDefectList (   maskedImage,
  defectList,
  fwhm,
  fallbackValue = None 
)
Interpolate over defects specified in a defect list

@param[in,out] maskedImage  masked image to process
@param[in] defectList  defect list
@param[in] fwhm  FWHM of double Gaussian smoothing kernel
@param[in] fallbackValue  fallback value if an interpolated value cannot be determined;
                          if None then use clipped mean image value

Definition at line 67 of file isr.py.

67 
68 def interpolateDefectList(maskedImage, defectList, fwhm, fallbackValue=None):
69  """Interpolate over defects specified in a defect list
70 
71  @param[in,out] maskedImage masked image to process
72  @param[in] defectList defect list
73  @param[in] fwhm FWHM of double Gaussian smoothing kernel
74  @param[in] fallbackValue fallback value if an interpolated value cannot be determined;
75  if None then use clipped mean image value
76  """
77  psf = createPsf(fwhm)
78  if fallbackValue is None:
79  fallbackValue = afwMath.makeStatistics(maskedImage.getImage(), afwMath.MEANCLIP).getValue()
80  if 'INTRP' not in maskedImage.getMask().getMaskPlaneDict().keys():
81  maskedImage.getMask.addMaskPlane('INTRP')
82  measAlg.interpolateOverDefects(maskedImage, psf, defectList, fallbackValue, True)
void interpolateOverDefects(MaskedImageT &image, lsst::afw::detection::Psf const &psf, std::vector< Defect::Ptr > &badList, double fallbackValue=0.0, bool useFallbackValueAtEdge=false)
Process a set of known bad pixels in an image.
Definition: Interp.cc:2058
def interpolateDefectList
Definition: isr.py:67
def createPsf
Definition: isr.py:33
Statistics makeStatistics(afwImage::Mask< afwImage::MaskPixel > const &msk, int const flags, StatisticsControl const &sctrl)
Specialization to handle Masks.
Definition: Statistics.cc:1082
def lsst.ip.isr.isr.interpolateFromMask (   maskedImage,
  fwhm,
  growFootprints = 1,
  maskName = 'SAT',
  fallbackValue = None 
)
Interpolate over defects identified by a particular mask plane

@param[in,out] maskedImage  afw.image.MaskedImage to process
@param[in] fwhm  FWHM of double Gaussian smoothing kernel
@param[in] growFootprints  amount by which to grow footprints of detected regions
@param[in] maskName  mask plane name
@param[in] fallbackValue  value of last resort for interpolation

Definition at line 173 of file isr.py.

174 def interpolateFromMask(maskedImage, fwhm, growFootprints=1, maskName='SAT', fallbackValue=None):
175  """Interpolate over defects identified by a particular mask plane
176 
177  @param[in,out] maskedImage afw.image.MaskedImage to process
178  @param[in] fwhm FWHM of double Gaussian smoothing kernel
179  @param[in] growFootprints amount by which to grow footprints of detected regions
180  @param[in] maskName mask plane name
181  @param[in] fallbackValue value of last resort for interpolation
182  """
183  defectList = getDefectListFromMask(maskedImage, maskName, growFootprints)
184  interpolateDefectList(maskedImage, defectList, fwhm, fallbackValue=fallbackValue)
def interpolateDefectList
Definition: isr.py:67
def getDefectListFromMask
Definition: isr.py:131
def interpolateFromMask
Definition: isr.py:173
def lsst.ip.isr.isr.makeThresholdMask (   maskedImage,
  threshold,
  growFootprints = 1,
  maskName = 'SAT' 
)
Mask pixels based on threshold detection

@param[in,out] maskedImage  afw.image.MaskedImage to process; the mask is altered
@param[in] threshold  detection threshold
@param[in] growFootprints  amount by which to grow footprints of detected regions
@param[in] maskName  mask plane name
@return meas.algorihtms.DefectListT of regions set in the mask.

Definition at line 149 of file isr.py.

150 def makeThresholdMask(maskedImage, threshold, growFootprints=1, maskName = 'SAT'):
151  """Mask pixels based on threshold detection
152 
153  @param[in,out] maskedImage afw.image.MaskedImage to process; the mask is altered
154  @param[in] threshold detection threshold
155  @param[in] growFootprints amount by which to grow footprints of detected regions
156  @param[in] maskName mask plane name
157  @return meas.algorihtms.DefectListT of regions set in the mask.
158  """
159  # find saturated regions
160  thresh = afwDetection.Threshold(threshold)
161  fs = afwDetection.FootprintSet(maskedImage, thresh)
162 
163  if growFootprints > 0:
164  fs = afwDetection.FootprintSet(fs, growFootprints)
165 
166  fpList = fs.getFootprints()
167  # set mask
168  mask = maskedImage.getMask()
169  bitmask = mask.getPlaneBitMask(maskName)
170  afwDetection.setMaskFromFootprintList(mask, fpList, bitmask)
171 
172  return defectListFromFootprintList(fpList, growFootprints=0)
A Threshold is used to pass a threshold value to detection algorithms.
Definition: Threshold.h:44
def makeThresholdMask
Definition: isr.py:149
A set of Footprints, associated with a MaskedImage.
Definition: FootprintSet.h:53
MaskT setMaskFromFootprintList(lsst::afw::image::Mask< MaskT > *mask, boost::shared_ptr< std::vector< boost::shared_ptr< Footprint >> const > const &footprints, MaskT const bitmask)
OR bitmask into all the Mask&#39;s pixels which are in the set of Footprints.
def defectListFromFootprintList
Definition: isr.py:83
def lsst.ip.isr.isr.maskPixelsFromDefectList (   maskedImage,
  defectList,
  maskName = 'BAD' 
)
Set mask plane based on a defect list

@param[in,out] maskedImage  afw.image.MaskedImage to process; mask plane is updated
@param[in] defectList  meas.algorithms.DefectListT
@param[in] maskName  mask plane name

Definition at line 117 of file isr.py.

118 def maskPixelsFromDefectList(maskedImage, defectList, maskName='BAD'):
119  """Set mask plane based on a defect list
120 
121  @param[in,out] maskedImage afw.image.MaskedImage to process; mask plane is updated
122  @param[in] defectList meas.algorithms.DefectListT
123  @param[in] maskName mask plane name
124  """
125  # mask bad pixels
126  mask = maskedImage.getMask()
127  bitmask = mask.getPlaneBitMask(maskName)
128  for defect in defectList:
129  bbox = defect.getBBox()
def maskPixelsFromDefectList
Definition: isr.py:117
A set of pixels in an Image.
Definition: Footprint.h:62
MaskT setMaskFromFootprint(lsst::afw::image::Mask< MaskT > *mask, Footprint const &footprint, MaskT const bitmask)
OR bitmask into all the Mask&#39;s pixels that are in the Footprint.
def lsst.ip.isr.isr.overscanCorrection (   ampMaskedImage,
  overscanImage,
  fitType = 'MEDIAN',
  order = 1,
  collapseRej = 3.0,
  statControl = None 
)
Apply overscan correction in place

@param[in,out] ampMaskedImage  masked image to correct
@param[in] overscanImage  overscan data as an afw.image.Image or afw.image.MaskedImage.
                          If a masked image is passed in the mask plane will be used
                          to constrain the fit of the bias level.
@param[in] fitType  type of fit for overscan correction; one of:
                    - 'MEAN'
                    - 'MEDIAN'
                    - 'POLY' (ordinary polynomial)
                    - 'CHEB' (Chebyshev polynomial)
                    - 'LEG' (Legendre polynomial)
                    - 'NATURAL_SPLINE', 'CUBIC_SPLINE', 'AKIMA_SPLINE' (splines)
@param[in] order  polynomial order or spline knots (ignored unless fitType
                  indicates a polynomial or spline)
@param[in] collapseRej  Rejection threshold (sigma) for collapsing dimension of overscan
@param[in] statControl  Statistics control object

Definition at line 286 of file isr.py.

287  statControl=None):
288  """Apply overscan correction in place
289 
290  @param[in,out] ampMaskedImage masked image to correct
291  @param[in] overscanImage overscan data as an afw.image.Image or afw.image.MaskedImage.
292  If a masked image is passed in the mask plane will be used
293  to constrain the fit of the bias level.
294  @param[in] fitType type of fit for overscan correction; one of:
295  - 'MEAN'
296  - 'MEDIAN'
297  - 'POLY' (ordinary polynomial)
298  - 'CHEB' (Chebyshev polynomial)
299  - 'LEG' (Legendre polynomial)
300  - 'NATURAL_SPLINE', 'CUBIC_SPLINE', 'AKIMA_SPLINE' (splines)
301  @param[in] order polynomial order or spline knots (ignored unless fitType
302  indicates a polynomial or spline)
303  @param[in] collapseRej Rejection threshold (sigma) for collapsing dimension of overscan
304  @param[in] statControl Statistics control object
305  """
306  ampImage = ampMaskedImage.getImage()
307  if statControl is None:
308  statControl = afwMath.StatisticsControl()
309  if fitType == 'MEAN':
310  offImage = afwMath.makeStatistics(overscanImage, afwMath.MEAN, statControl).getValue(afwMath.MEAN)
311  elif fitType == 'MEDIAN':
312  offImage = afwMath.makeStatistics(overscanImage, afwMath.MEDIAN, statControl).getValue(afwMath.MEDIAN)
313  elif fitType in ('POLY', 'CHEB', 'LEG', 'NATURAL_SPLINE', 'CUBIC_SPLINE', 'AKIMA_SPLINE'):
314  if hasattr(overscanImage, "getImage"):
315  biasArray = overscanImage.getImage().getArray()
316  biasArray = numpy.ma.masked_where(overscanImage.getMask().getArray() & statControl.getAndMask(),
317  biasArray)
318  else:
319  biasArray = overscanImage.getArray()
320  # Fit along the long axis, so collapse along each short row and fit the resulting array
321  shortInd = numpy.argmin(biasArray.shape)
322  if shortInd == 0:
323  # Convert to some 'standard' representation to make things easier
324  biasArray = numpy.transpose(biasArray)
325 
326  # Do a single round of clipping to weed out CR hits and signal leaking into the overscan
327  percentiles = numpy.percentile(biasArray, [25.0, 50.0, 75.0], axis=1)
328  medianBiasArr = percentiles[1]
329  stdevBiasArr = 0.74*(percentiles[2] - percentiles[0]) # robust stdev
330  diff = numpy.abs(biasArray - medianBiasArr[:,numpy.newaxis])
331  biasMaskedArr = numpy.ma.masked_where(diff > collapseRej*stdevBiasArr[:,numpy.newaxis], biasArray)
332  collapsed = numpy.mean(biasMaskedArr, axis=1)
333  del biasArray, percentiles, stdevBiasArr, diff, biasMaskedArr
334 
335  if shortInd == 0:
336  collapsed = numpy.transpose(collapsed)
337 
338  num = len(collapsed)
339  indices = 2.0*numpy.arange(num)/float(num) - 1.0
340 
341  if fitType in ('POLY', 'CHEB', 'LEG'):
342  # A numpy polynomial
343  poly = numpy.polynomial
344  fitter, evaler = {"POLY": (poly.polynomial.polyfit, poly.polynomial.polyval),
345  "CHEB": (poly.chebyshev.chebfit, poly.chebyshev.chebval),
346  "LEG": (poly.legendre.legfit, poly.legendre.legval),
347  }[fitType]
348 
349  coeffs = fitter(indices, collapsed, order)
350  fitBiasArr = evaler(indices, coeffs)
351  elif 'SPLINE' in fitType:
352  # An afw interpolation
353  numBins = order
354  #
355  # numpy.histogram needs a real array for the mask, but numpy.ma "optimises" the case
356  # no-values-are-masked by replacing the mask array by a scalar, numpy.ma.nomask
357  #
358  # Issue DM-415
359  #
360  collapsedMask = collapsed.mask
361  try:
362  if collapsedMask == numpy.ma.nomask:
363  collapsedMask = numpy.array(len(collapsed)*[numpy.ma.nomask])
364  except ValueError: # If collapsedMask is an array the test fails [needs .all()]
365  pass
366 
367  numPerBin, binEdges = numpy.histogram(indices, bins=numBins,
368  weights=1-collapsedMask.astype(int))
369  # Binning is just a histogram, with weights equal to the values.
370  # Use a similar trick to get the bin centers (this deals with different numbers per bin).
371  values = numpy.histogram(indices, bins=numBins, weights=collapsed)[0]/numPerBin
372  binCenters = numpy.histogram(indices, bins=numBins, weights=indices)[0]/numPerBin
373  interp = afwMath.makeInterpolate(binCenters.astype(float)[numPerBin > 0],
374  values.astype(float)[numPerBin > 0],
376  fitBiasArr = numpy.array([interp.interpolate(i) for i in indices])
377 
378  import lsstDebug
379  if lsstDebug.Info(__name__).display:
380  import matplotlib.pyplot as plot
381  figure = plot.figure(1)
382  figure.clear()
383  axes = figure.add_axes((0.1, 0.1, 0.8, 0.8))
384  axes.plot(indices, collapsed, 'k+')
385  axes.plot(indices, fitBiasArr, 'r-')
386  figure.show()
387  prompt = "Press Enter or c to continue [chp]... "
388  while True:
389  ans = raw_input(prompt).lower()
390  if ans in ("", "c",):
391  break
392  if ans in ("p",):
393  import pdb; pdb.set_trace()
394  elif ans in ("h", ):
395  print "h[elp] c[ontinue] p[db]"
396  figure.close()
397 
398  offImage = ampImage.Factory(ampImage.getDimensions())
399  offArray = offImage.getArray()
400  if shortInd == 1:
401  offArray[:,:] = fitBiasArr[:,numpy.newaxis]
402  else:
403  offArray[:,:] = fitBiasArr[numpy.newaxis,:]
404 
405  # We don't trust any extrapolation: mask those pixels as SUSPECT
406  # This will occur when the top and or bottom edges of the overscan
407  # contain saturated values. The values will be extrapolated from
408  # the surrounding pixels, but we cannot entirely trust the value of
409  # the extrapolation, and will mark the image mask plane to flag the
410  # image as such.
411  mask = ampMaskedImage.getMask()
412  maskArray = mask.getArray() if shortInd == 1 else mask.getArray().transpose()
413  suspect = mask.getPlaneBitMask("SUSPECT")
414  try:
415  if collapsed.mask == numpy.ma.nomask:
416  # There is no mask, so the whole array is fine
417  pass
418  except ValueError: # If collapsed.mask is an array the test fails [needs .all()]
419  for low in xrange(num):
420  if not collapsed.mask[low]:
421  break
422  if low > 0:
423  maskArray[:low,:] |= suspect
424  for high in xrange(1, num):
425  if not collapsed.mask[-high]:
426  break
427  if high > 1:
428  maskArray[-high:,:] |= suspect
429 
430  else:
431  raise pexExcept.Exception, '%s : %s an invalid overscan type' % \
432  ("overscanCorrection", fitType)
433  ampImage -= offImage
434 
Interpolate::Style stringToInterpStyle(std::string const &style)
Conversion function to switch a string to an Interpolate::Style.
Definition: Interpolate.cc:262
boost::shared_ptr< Interpolate > makeInterpolate(std::vector< double > const &x, std::vector< double > const &y, Interpolate::Style const style=Interpolate::AKIMA_SPLINE)
Definition: Interpolate.cc:353
Pass parameters to a Statistics objectA class to pass parameters which control how the stats are calc...
Definition: Statistics.h:92
Statistics makeStatistics(afwImage::Mask< afwImage::MaskPixel > const &msk, int const flags, StatisticsControl const &sctrl)
Specialization to handle Masks.
Definition: Statistics.cc:1082
def lsst.ip.isr.isr.saturationCorrection (   maskedImage,
  saturation,
  fwhm,
  growFootprints = 1,
  interpolate = True,
  maskName = 'SAT',
  fallbackValue = None 
)
Mark saturated pixels and optionally interpolate over them

@param[in,out] maskedImage  afw.image.MaskedImage to process
@param[in] saturation  saturation level (used as a detection threshold)
@param[in] fwhm  FWHM of double Gaussian smoothing kernel
@param[in] growFootprints  amount by which to grow footprints of detected regions
@param[in] interpolate  interpolate over saturated pixels?
@param[in] maskName  mask plane name
@param[in] fallbackValue  value of last resort for interpolation

Definition at line 186 of file isr.py.

187  fallbackValue=None):
188  """Mark saturated pixels and optionally interpolate over them
189 
190  @param[in,out] maskedImage afw.image.MaskedImage to process
191  @param[in] saturation saturation level (used as a detection threshold)
192  @param[in] fwhm FWHM of double Gaussian smoothing kernel
193  @param[in] growFootprints amount by which to grow footprints of detected regions
194  @param[in] interpolate interpolate over saturated pixels?
195  @param[in] maskName mask plane name
196  @param[in] fallbackValue value of last resort for interpolation
197  """
198  defectList = makeThresholdMask(
199  maskedImage = maskedImage,
200  threshold = saturation,
201  growFootprints = growFootprints,
202  maskName = maskName,
203  )
204  if interpolate:
205  interpolateDefectList(maskedImage, defectList, fwhm, fallbackValue=fallbackValue)
def interpolateDefectList
Definition: isr.py:67
def makeThresholdMask
Definition: isr.py:149
def lsst.ip.isr.isr.transposeDefectList (   defectList)
Make a transposed copy of a defect list

@param[in] defectList  defect list
@return meas.algorithms.DefectListT with transposed defects

Definition at line 103 of file isr.py.

104 def transposeDefectList(defectList):
105  """Make a transposed copy of a defect list
106 
107  @param[in] defectList defect list
108  @return meas.algorithms.DefectListT with transposed defects
109  """
110  retDefectList = measAlg.DefectListT()
111  for defect in defectList:
112  bbox = defect.getBBox()
113  nbbox = afwGeom.Box2I(afwGeom.Point2I(bbox.getMinY(), bbox.getMinX()),
114  afwGeom.Extent2I(bbox.getDimensions()[1], bbox.getDimensions()[0]))
115  retDefectList.push_back(measAlg.Defect(nbbox))
116  return retDefectList
def transposeDefectList
Definition: isr.py:103
An integer coordinate rectangle.
Definition: Box.h:53
Encapsulate information about a bad portion of a detector.
Definition: Interp.h:70
def lsst.ip.isr.isr.transposeMaskedImage (   maskedImage)
Make a transposed copy of a masked image

@param[in] maskedImage  afw.image.MaskedImage to process
@return transposed masked image

Definition at line 55 of file isr.py.

55 
56 def transposeMaskedImage(maskedImage):
57  """Make a transposed copy of a masked image
58 
59  @param[in] maskedImage afw.image.MaskedImage to process
60  @return transposed masked image
61  """
62  transposed = maskedImage.Factory(afwGeom.Extent2I(maskedImage.getHeight(), maskedImage.getWidth()))
63  transposed.getImage().getArray()[:] = maskedImage.getImage().getArray().T
64  transposed.getMask().getArray()[:] = maskedImage.getMask().getArray().T
65  transposed.getVariance().getArray()[:] = maskedImage.getVariance().getArray().T
66  return transposed
def transposeMaskedImage
Definition: isr.py:55
def lsst.ip.isr.isr.updateVariance (   maskedImage,
  gain,
  readNoise 
)
Set the variance plane based on the image plane

@param[in,out] maskedImage  afw.image.MaskedImage; image plane is read and variance plane is written
@param[in] gain  amplifier gain (e-/ADU)
@param[in] readNoise  amplifier read noise (ADU/pixel)

Definition at line 234 of file isr.py.

235 def updateVariance(maskedImage, gain, readNoise):
236  """Set the variance plane based on the image plane
237 
238  @param[in,out] maskedImage afw.image.MaskedImage; image plane is read and variance plane is written
239  @param[in] gain amplifier gain (e-/ADU)
240  @param[in] readNoise amplifier read noise (ADU/pixel)
241  """
242  var = maskedImage.getVariance()
243  var <<= maskedImage.getImage()
244  var /= gain
245  var += readNoise**2
def updateVariance
Definition: isr.py:234