439 def debugHistogram(self, stepname, ampImage, nSigmaUsed, exp):
441 Make a histogram of the distribution of pixel values for each amp.
443 The main image data histogram is plotted in blue. Edge pixels,
444 if masked, are in red. Note that masked edge pixels do not contribute
445 to the underflow and overflow numbers.
447 Note that this currently only supports the 16-amp LSST detectors.
451 dataRef : `lsst.daf.persistence.ButlerDataRef`
452 dataRef for the detector.
453 exp : `lsst.afw.image.exposure.Exposure`
454 The exposure in which the defects were found.
458 The number of sigma used for detection
462 import matplotlib.pyplot
as plt
464 detector = exp.getDetector()
465 nX = np.floor(np.sqrt(len(detector)))
466 nY = len(detector) // nX
467 fig, ax = plt.subplots(nrows=nY, ncols=nX, sharex=
'col', sharey=
'row', figsize=(13, 10))
469 expTime = exp.getInfo().getVisitInfo().getExposureTime()
471 for (amp, a)
in zip(reversed(detector), ax.flatten()):
472 mi = exp.maskedImage[amp.getBBox()]
475 mi.image.array /= expTime
477 mean, sigma = stats.getValue(afwMath.MEANCLIP), stats.getValue(afwMath.STDEVCLIP)
479 EDGEBIT = exp.maskedImage.mask.getPlaneBitMask(
"EDGE")
480 imgData = mi.image.array[(mi.mask.array & EDGEBIT) == 0].flatten()
481 edgeData = mi.image.array[(mi.mask.array & EDGEBIT) != 0].flatten()
483 thrUpper = mean + nSigmaUsed*sigma
484 thrLower = mean - nSigmaUsed*sigma
486 nRight = len(imgData[imgData > thrUpper])
487 nLeft = len(imgData[imgData < thrLower])
489 nsig = nSigmaUsed + 1.2
490 leftEdge = mean - nsig * nSigmaUsed*sigma
491 rightEdge = mean + nsig * nSigmaUsed*sigma
492 nbins = np.linspace(leftEdge, rightEdge, 1000)
493 ey, bin_borders, patches = a.hist(edgeData, histtype=
'step', bins=nbins,
494 lw=1, edgecolor=
'red')
495 y, bin_borders, patches = a.hist(imgData, histtype=
'step', bins=nbins,
496 lw=3, edgecolor=
'blue')
499 nOverflow = len(imgData[imgData > rightEdge])
500 nUnderflow = len(imgData[imgData < leftEdge])
503 a.axvline(thrUpper, c=
'k')
504 a.axvline(thrLower, c=
'k')
505 msg = f
"{amp.getName()}\nmean:{mean: .2f}\n$\\sigma$:{sigma: .2f}"
506 a.text(0.65, 0.6, msg, transform=a.transAxes, fontsize=11)
507 msg = f
"nLeft:{nLeft}\nnRight:{nRight}\nnOverflow:{nOverflow}\nnUnderflow:{nUnderflow}"
508 a.text(0.03, 0.6, msg, transform=a.transAxes, fontsize=11.5)
511 a.set_ylim([1., 1.7*np.max(y)])
512 lPlot, rPlot = a.get_xlim()
513 a.set_xlim(np.array([lPlot, rPlot]))
515 a.set_xlabel(
"ADU/s")
Statistics makeStatistics(lsst::afw::image::Image< Pixel > const &img, lsst::afw::image::Mask< image::MaskPixel > const &msk, int const flags, StatisticsControl const &sctrl=StatisticsControl())
Handle a watered-down front-end to the constructor (no variance)
def getDebugFrame(debugDisplay, name)