Skip to content

Commit cab2d05

Browse files
authored
Merge pull request #133 from lsst/tickets/DM-47919
DM-47919: Add configuration for cutting visits from the fit by PSF FWHM
2 parents df1533e + e1aca95 commit cab2d05

File tree

3 files changed

+36
-10
lines changed

3 files changed

+36
-10
lines changed

python/lsst/fgcmcal/fgcmBuildStarsBase.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
from lsst.meas.algorithms.sourceSelector import sourceSelectorRegistry
3434

3535
from .fgcmLoadReferenceCatalog import FgcmLoadReferenceCatalogTask
36+
from .utilities import computeReferencePixelScale
3637

3738
import fgcm
3839

@@ -259,13 +260,15 @@ def fgcmMakeVisitCatalog(self, camera, groupedHandles):
259260
visitCat['used'] = 0
260261
visitCat['sources_read'] = False
261262

263+
defaultPixelScale = computeReferencePixelScale(camera)
264+
262265
# No matter what, fill the catalog. This will check if it was
263266
# already read.
264-
self._fillVisitCatalog(visitCat, groupedHandles)
267+
self._fillVisitCatalog(visitCat, groupedHandles, defaultPixelScale)
265268

266269
return visitCat
267270

268-
def _fillVisitCatalog(self, visitCat, groupedHandles):
271+
def _fillVisitCatalog(self, visitCat, groupedHandles, defaultPixelScale):
269272
"""
270273
Fill the visit catalog with visit metadata
271274
@@ -275,6 +278,8 @@ def _fillVisitCatalog(self, visitCat, groupedHandles):
275278
Visit catalog. See _makeFgcmVisitSchema() for schema definition.
276279
groupedHandles : `dict` [`list` [`lsst.daf.butler.DeferredDatasetHandle`]]
277280
Dataset handles, grouped by visit.
281+
defaultPixelScale : `float`
282+
Default pixel scale to use if not in visit summary (arcsecond/pixel).
278283
"""
279284

280285
# Guarantee that these are sorted.
@@ -292,15 +297,24 @@ def _fillVisitCatalog(self, visitCat, groupedHandles):
292297

293298
visitInfo = summaryRow.getVisitInfo()
294299
physicalFilter = summaryRow['physical_filter']
295-
# Compute the median psf sigma if possible
296-
goodSigma, = np.where(summary['psfSigma'] > 0)
300+
# Compute the median psf sigma and fwhm if possible.
301+
if 'pixelScale' in summary.schema:
302+
# This is not available in the older test summaries
303+
pixelScales = summary['pixelScale']
304+
else:
305+
pixelScales = np.full(len(summary['psfSigma']), defaultPixelScale)
306+
psfSigmas = summary['psfSigma']
307+
goodSigma, = np.where((np.nan_to_num(psfSigmas) > 0) & (np.nan_to_num(pixelScales) > 0))
297308
if goodSigma.size > 2:
298-
psfSigma = np.median(summary['psfSigma'][goodSigma])
309+
psfSigma = np.median(psfSigmas[goodSigma])
310+
psfFwhm = np.median(psfSigmas[goodSigma] * pixelScales[goodSigma]) * np.sqrt(8.*np.log(2.))
299311
elif goodSigma.size > 0:
300-
psfSigma = summary['psfSigma'][goodSigma[0]]
312+
psfSigma = psfSigmas[goodSigma[0]]
313+
psfFwhm = psfSigmas[goodSigma[0]] * pixelScales[goodSigma[0]] * np.sqrt(8.)*np.log(2.)
301314
else:
302315
self.log.warning("Could not find any good summary psfSigma for visit %d", visit)
303316
psfSigma = 0.0
317+
psfFwhm = 0.0
304318
# Compute median background if possible
305319
goodBackground, = np.where(np.nan_to_num(summary['skyBg']) > 0.0)
306320
if goodBackground.size > 2:
@@ -332,6 +346,7 @@ def _fillVisitCatalog(self, visitCat, groupedHandles):
332346
# Median delta aperture, to be measured from stars
333347
rec['deltaAper'] = 0.0
334348
rec['psfSigma'] = psfSigma
349+
rec['psfFwhm'] = psfFwhm
335350
rec['skyBackground'] = skyBackground
336351
rec['used'] = 1
337352

@@ -559,7 +574,8 @@ def _makeFgcmVisitSchema(self, nCcd):
559574
schema.addField('mjd', type=np.float64, doc="MJD of visit")
560575
schema.addField('exptime', type=np.float32, doc="Exposure time")
561576
schema.addField('pmb', type=np.float32, doc="Pressure (millibar)")
562-
schema.addField('psfSigma', type=np.float32, doc="PSF sigma (reference CCD)")
577+
schema.addField('psfSigma', type=np.float32, doc="PSF sigma (median); pixels")
578+
schema.addField('psfFwhm', type=np.float32, doc="PSF FWHM (median); arcseconds")
563579
schema.addField('deltaAper', type=np.float32, doc="Delta-aperture")
564580
schema.addField('skyBackground', type=np.float32, doc="Sky background (ADU) (reference CCD)")
565581
# the following field is not used yet

python/lsst/fgcmcal/fgcmFitCycle.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,15 @@ class FgcmFitCycleConfig(pipeBase.PipelineTaskConfig,
772772
dtype=float,
773773
default=-0.25,
774774
)
775+
expFwhmCutDict = pexConfig.DictField(
776+
doc=("Per-band specification on maximum exposure FWHM (arcseconds) that will "
777+
"be considered for the model fit. Exposures with median FWHM larger "
778+
"than this threshold will get zeropoints based on matching to good "
779+
"stars."),
780+
keytype=str,
781+
itemtype=float,
782+
default={},
783+
)
775784
expGrayPhotometricCutDict = pexConfig.DictField(
776785
doc=("Per-band specification on maximum (negative) achromatic exposure residual "
777786
"('gray term') for a visit to be considered photometric. Must have one "

python/lsst/fgcmcal/utilities.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def makeConfigDict(config, log, camera, maxIter,
138138
'expField': FGCM_EXP_FIELD,
139139
'ccdField': FGCM_CCD_FIELD,
140140
'seeingField': 'DELTA_APER',
141-
'fwhmField': 'PSFSIGMA',
141+
'fwhmField': 'PSFFWHM',
142142
'skyBrightnessField': 'SKYBACKGROUND',
143143
'deepFlag': 'DEEPFLAG', # unused
144144
'bands': list(config.bands),
@@ -183,6 +183,7 @@ def makeConfigDict(config, log, camera, maxIter,
183183
'minStarPerExp': config.minStarPerExp,
184184
'minExpPerNight': config.minExpPerNight,
185185
'expGrayInitialCut': config.expGrayInitialCut,
186+
'expFwhmCutDict': dict(config.expFwhmCutDict),
186187
'expGrayPhotometricCutDict': dict(config.expGrayPhotometricCutDict),
187188
'expGrayHighCutDict': dict(config.expGrayHighCutDict),
188189
'expGrayRecoverCut': config.expGrayRecoverCut,
@@ -404,7 +405,7 @@ def translateVisitCatalog(visitCat):
404405
fgcmExpInfo = np.zeros(len(visitCat), dtype=[('VISIT', 'i8'),
405406
('MJD', 'f8'),
406407
('EXPTIME', 'f8'),
407-
('PSFSIGMA', 'f8'),
408+
('PSFFWHM', 'f8'),
408409
('DELTA_APER', 'f8'),
409410
('SKYBACKGROUND', 'f8'),
410411
('DEEPFLAG', 'i2'),
@@ -423,7 +424,7 @@ def translateVisitCatalog(visitCat):
423424
fgcmExpInfo['TELDEC'][:] = visitCat['teldec']
424425
fgcmExpInfo['TELROT'][:] = visitCat['telrot']
425426
fgcmExpInfo['PMB'][:] = visitCat['pmb']
426-
fgcmExpInfo['PSFSIGMA'][:] = visitCat['psfSigma']
427+
fgcmExpInfo['PSFFWHM'][:] = visitCat['psfFwhm']
427428
fgcmExpInfo['DELTA_APER'][:] = visitCat['deltaAper']
428429
fgcmExpInfo['SKYBACKGROUND'][:] = visitCat['skyBackground']
429430
# Note that we have to go through asAstropy() to get a string

0 commit comments

Comments
 (0)