23 import astropy.units
as units
24 from astropy.time
import Time
25 from astropy.coordinates
import AltAz, SkyCoord, EarthLocation
35 __all__ = (
"ComputeExposureSummaryStatsTask",
"ComputeExposureSummaryStatsConfig")
39 """Config for ComputeExposureSummaryTask"""
40 sigmaClip = pexConfig.Field(
42 doc=
"Sigma for outlier rejection for sky noise.",
45 clipIter = pexConfig.Field(
47 doc=
"Number of iterations of outlier rejection for sky noise.",
50 badMaskPlanes = pexConfig.ListField(
52 doc=
"Mask planes that, if set, the associated pixel should not be included sky noise calculation.",
53 default=(
"NO_DATA",
"SUSPECT"),
58 """Task to compute exposure summary statistics.
60 This task computes various quantities suitable for DPDD and other
61 downstream processing at the detector centers, including:
77 ConfigClass = ComputeExposureSummaryStatsConfig
78 _DefaultName =
"computeExposureSummaryStats"
81 def run(self, exposure, sources, background):
82 """Measure exposure statistics from the exposure, sources, and background.
86 exposure : `lsst.afw.image.ExposureF`
87 sources : `lsst.afw.table.SourceCatalog`
88 background : `lsst.afw.math.BackgroundList`
92 summary : `lsst.afw.image.ExposureSummary`
94 self.log.
info(
"Measuring exposure statistics")
96 bbox = exposure.getBBox()
98 psf = exposure.getPsf()
100 shape = psf.computeShape(bbox.getCenter())
101 psfSigma = shape.getDeterminantRadius()
102 psfIxx = shape.getIxx()
103 psfIyy = shape.getIyy()
104 psfIxy = shape.getIxy()
105 im = psf.computeKernelImage(bbox.getCenter())
110 psfArea = np.sum(im.array)/np.sum(im.array**2.)
118 wcs = exposure.getWcs()
121 raCorners = [float(sph.getRa().asDegrees())
for sph
in sph_pts]
122 decCorners = [float(sph.getDec().asDegrees())
for sph
in sph_pts]
124 sph_pt = wcs.pixelToSky(bbox.getCenter())
125 ra = sph_pt.getRa().asDegrees()
126 decl = sph_pt.getDec().asDegrees()
128 raCorners = [float(np.nan)]*4
129 decCorners = [float(np.nan)]*4
133 photoCalib = exposure.getPhotoCalib()
134 if photoCalib
is not None:
135 zeroPoint = 2.5*np.log10(photoCalib.getInstFluxAtZeroMagnitude())
139 visitInfo = exposure.getInfo().getVisitInfo()
140 date = visitInfo.getDate()
146 observatory = visitInfo.getObservatory()
147 loc = EarthLocation(lat=observatory.getLatitude().asDegrees()*units.deg,
148 lon=observatory.getLongitude().asDegrees()*units.deg,
149 height=observatory.getElevation()*units.m)
150 obstime = Time(visitInfo.getDate().get(system=DateTime.MJD),
151 location=loc, format=
'mjd')
152 coord = SkyCoord(ra*units.degree, decl*units.degree, obstime=obstime, location=loc)
153 with warnings.catch_warnings():
154 warnings.simplefilter(
'ignore')
155 altaz = coord.transform_to(AltAz)
157 zenithDistance = altaz.alt.degree
159 zenithDistance = np.nan
161 if background
is not None:
162 bgStats = (bg[0].getStatsImage().getImage().array
163 for bg
in background)
164 skyBg = sum(np.median(bg[np.isfinite(bg)])
for bg
in bgStats)
169 statsCtrl.setNumSigmaClip(self.config.sigmaClip)
170 statsCtrl.setNumIter(self.config.clipIter)
171 statsCtrl.setAndMask(afwImage.Mask.getPlaneBitMask(self.config.badMaskPlanes))
172 statsCtrl.setNanSafe(
True)
176 skyNoise, _ = statObj.getResult(afwMath.STDEVCLIP)
179 exposure.getMaskedImage().getMask(),
180 afwMath.MEANCLIP, statsCtrl)
181 meanVar, _ = statObj.getResult(afwMath.MEANCLIP)
184 psfArea=float(psfArea),
185 psfIxx=float(psfIxx),
186 psfIyy=float(psfIyy),
187 psfIxy=float(psfIxy),
190 zenithDistance=float(zenithDistance),
191 zeroPoint=float(zeroPoint),
193 skyNoise=float(skyNoise),
194 meanVar=float(meanVar),
196 decCorners=decCorners)
Pass parameters to a Statistics object.
A floating-point coordinate rectangle geometry.
def run(self, exposure, sources, background)
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects.
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)