Skip to content

Commit

Permalink
Replace deprecated Filter interface with FilterLabel
Browse files Browse the repository at this point in the history
FilterInfo was now just used for the labels, so is now just a label.
  • Loading branch information
parejkoj committed Jan 29, 2021
1 parent d1c1571 commit c87a66f
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 29 deletions.
38 changes: 18 additions & 20 deletions python/lsst/ip/diffim/dcrModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ class DcrModel:
iterations of forward modeling or between the subfilters of the model.
"""

def __init__(self, modelImages, effectiveWavelength, bandwidth, filterInfo=None, psf=None,
def __init__(self, modelImages, effectiveWavelength, bandwidth, filterLabel=None, psf=None,
mask=None, variance=None, photoCalib=None):
self.dcrNumSubfilters = len(modelImages)
self.modelImages = modelImages
self._filterInfo = filterInfo
self._filterLabel = filterLabel
self._effectiveWavelength = effectiveWavelength
self._bandwidth = bandwidth
self._psf = psf
Expand All @@ -63,7 +63,7 @@ def __init__(self, modelImages, effectiveWavelength, bandwidth, filterInfo=None,

@classmethod
def fromImage(cls, maskedImage, dcrNumSubfilters, effectiveWavelength, bandwidth,
filterInfo=None, psf=None, photoCalib=None):
filterLabel=None, psf=None, photoCalib=None):
"""Initialize a DcrModel by dividing a coadd between the subfilters.
Parameters
Expand All @@ -77,9 +77,8 @@ def fromImage(cls, maskedImage, dcrNumSubfilters, effectiveWavelength, bandwidth
The effective wavelengths of the current filter, in nanometers.
bandwidth : `float`
The bandwidth of the current filter, in nanometers.
filterInfo : `lsst.afw.image.Filter`, optional
The filter definition, set in the current instruments' obs package.
Note: this object will be changed in DM-21333.
filterLabel : `lsst.afw.image.FilterLabel`, optional
The filter label, set in the current instruments' obs package.
Required for any calculation of DCR, including making matched
templates.
psf : `lsst.afw.detection.Psf`, optional
Expand Down Expand Up @@ -110,7 +109,7 @@ def fromImage(cls, maskedImage, dcrNumSubfilters, effectiveWavelength, bandwidth
for subfilter in range(1, dcrNumSubfilters):
modelImages.append(model.clone())
return cls(modelImages, effectiveWavelength, bandwidth,
filterInfo=filterInfo, psf=psf, mask=mask, variance=variance, photoCalib=photoCalib)
filterLabel=filterLabel, psf=psf, mask=mask, variance=variance, photoCalib=photoCalib)

@classmethod
def fromDataRef(cls, dataRef, effectiveWavelength, bandwidth, datasetType="dcrCoadd", numSubfilters=None,
Expand Down Expand Up @@ -143,7 +142,7 @@ def fromDataRef(cls, dataRef, effectiveWavelength, bandwidth, datasetType="dcrCo
Best fit model of the true sky after correcting chromatic effects.
"""
modelImages = []
filterInfo = None
filterLabel = None
psf = None
mask = None
variance = None
Expand All @@ -153,8 +152,8 @@ def fromDataRef(cls, dataRef, effectiveWavelength, bandwidth, datasetType="dcrCo
for subfilter in range(numSubfilters):
dcrCoadd = dataRef.get(datasetType, subfilter=subfilter,
numSubfilters=numSubfilters, **kwargs)
if filterInfo is None:
filterInfo = dcrCoadd.getFilter()
if filterLabel is None:
filterLabel = dcrCoadd.getFilterLabel()
if psf is None:
psf = dcrCoadd.getPsf()
if mask is None:
Expand All @@ -164,7 +163,7 @@ def fromDataRef(cls, dataRef, effectiveWavelength, bandwidth, datasetType="dcrCo
if photoCalib is None:
photoCalib = dcrCoadd.getPhotoCalib()
modelImages.append(dcrCoadd.image)
return cls(modelImages, effectiveWavelength, bandwidth, filterInfo, psf, mask, variance, photoCalib)
return cls(modelImages, effectiveWavelength, bandwidth, filterLabel, psf, mask, variance, photoCalib)

@classmethod
def fromQuantum(cls, availableCoaddRefs, effectiveWavelength, bandwidth):
Expand All @@ -186,7 +185,7 @@ def fromQuantum(cls, availableCoaddRefs, effectiveWavelength, bandwidth):
dcrModel : `lsst.pipe.tasks.DcrModel`
Best fit model of the true sky after correcting chromatic effects.
"""
filterInfo = None
filterLabel = None
psf = None
mask = None
variance = None
Expand All @@ -196,8 +195,8 @@ def fromQuantum(cls, availableCoaddRefs, effectiveWavelength, bandwidth):
for coaddRef in availableCoaddRefs:
subfilter = coaddRef.dataId["subfilter"]
dcrCoadd = coaddRef.get()
if filterInfo is None:
filterInfo = dcrCoadd.getFilter()
if filterLabel is None:
filterLabel = dcrCoadd.getFilterLabel()
if psf is None:
psf = dcrCoadd.getPsf()
if mask is None:
Expand All @@ -207,7 +206,7 @@ def fromQuantum(cls, availableCoaddRefs, effectiveWavelength, bandwidth):
if photoCalib is None:
photoCalib = dcrCoadd.getPhotoCalib()
modelImages[subfilter] = dcrCoadd.image
return cls(modelImages, effectiveWavelength, bandwidth, filterInfo, psf, mask, variance, photoCalib)
return cls(modelImages, effectiveWavelength, bandwidth, filterLabel, psf, mask, variance, photoCalib)

def __len__(self):
"""Return the number of subfilters.
Expand Down Expand Up @@ -285,11 +284,10 @@ def filter(self):
Returns
-------
filterInfo : `lsst.afw.image.Filter`
The name of the filter used for the input observations.
Note: this object will be changed in DM-21333.
filterLabel : `lsst.afw.image.FilterLabel`
The filter used for the input observations.
"""
return self._filterInfo
return self._filterLabel

@property
def bandwidth(self):
Expand Down Expand Up @@ -493,7 +491,7 @@ def buildMatchedExposure(self, exposure=None,
templateExposure = afwImage.ExposureF(bbox, wcs)
templateExposure.setMaskedImage(maskedImage[bbox])
templateExposure.setPsf(self.psf)
templateExposure.setFilter(self.filterInfo)
templateExposure.setFilterLabel(self.filterLabel)
if self.photoCalib is None:
raise RuntimeError("No PhotoCalib set for the DcrModel. "
"If the DcrModel was created from a masked image"
Expand Down
8 changes: 4 additions & 4 deletions python/lsst/ip/diffim/getTemplate.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def run(self, tractInfo, patchList, skyCorners, availableCoaddRefs,
coaddExposure = afwImage.ExposureF(coaddBBox, coaddWcs)
coaddExposure.maskedImage.set(np.nan, afwImage.Mask.getPlaneBitMask("NO_DATA"), np.nan)
nPatchesFound = 0
coaddFilter = None
coaddFilterLabel = None
coaddPsf = None
coaddPhotoCalib = None
for patchInfo in patchList:
Expand Down Expand Up @@ -327,8 +327,8 @@ def run(self, tractInfo, patchList, skyCorners, availableCoaddRefs,
overlapBox.clip(coaddBBox)
coaddExposure.maskedImage.assign(coaddPatch.maskedImage[overlapBox], overlapBox)

if coaddFilter is None:
coaddFilter = coaddPatch.getFilter()
if coaddFilterLabel is None:
coaddFilterLabel = coaddPatch.getFilterLabel()

# Retrieve the PSF for this coadd tract, if not already retrieved
if coaddPsf is None and coaddPatch.hasPsf():
Expand All @@ -347,7 +347,7 @@ def run(self, tractInfo, patchList, skyCorners, availableCoaddRefs,

coaddExposure.setPhotoCalib(coaddPhotoCalib)
coaddExposure.setPsf(coaddPsf)
coaddExposure.setFilter(coaddFilter)
coaddExposure.setFilterLabel(coaddFilterLabel)
return coaddExposure

def getCoaddDatasetName(self):
Expand Down
2 changes: 1 addition & 1 deletion python/lsst/ip/diffim/imagePsfMatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ def matchExposures(self, templateExposure, scienceExposure,
templateFwhmPix=scienceFwhmPix, scienceFwhmPix=templateFwhmPix)

psfMatchedExposure = afwImage.makeExposure(results.matchedImage, scienceExposure.getWcs())
psfMatchedExposure.setFilter(templateExposure.getFilter())
psfMatchedExposure.setFilterLabel(templateExposure.getFilterLabel())
psfMatchedExposure.setPhotoCalib(scienceExposure.getPhotoCalib())
results.warpedExposure = templateExposure
results.matchedExposure = psfMatchedExposure
Expand Down
2 changes: 1 addition & 1 deletion python/lsst/ip/diffim/modelPsfMatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ def run(self, exposure, referencePsfModel, kernelSum=1.0):

self.log.info("Psf-match science exposure to reference")
psfMatchedExposure = afwImage.ExposureF(exposure.getBBox(), exposure.getWcs())
psfMatchedExposure.setFilter(exposure.getFilter())
psfMatchedExposure.setFilterLabel(exposure.getFilterLabel())
psfMatchedExposure.setPhotoCalib(exposure.getPhotoCalib())
psfMatchedExposure.getInfo().setVisitInfo(exposure.getInfo().getVisitInfo())
psfMatchedExposure.setPsf(referencePsfModel)
Expand Down
3 changes: 0 additions & 3 deletions tests/test_dcrModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -546,9 +546,6 @@ def calculateAstropyDcr(visitInfo, wcs, effectiveWavelength, bandwidth, dcrNumSu
VisitInfo for the exposure.
wcs : `lsst.afw.geom.skyWcs.SkyWcs`
A wcs that matches the inputs.
filterInfo : `lsst.afw.image.Filter`
The filter definition, set in the current instruments' obs package.
Note: this object will be changed in DM-21333.
dcrNumSubfilters : `int`
Number of sub-filters used to model chromatic effects within a band.
Expand Down

0 comments on commit c87a66f

Please sign in to comment.