Skip to content

Commit

Permalink
Merge pull request #166 from lsst/tickets/DM-27170
Browse files Browse the repository at this point in the history
DM-27170: Deprecate and phase out afw::image::Filter
  • Loading branch information
parejkoj committed Jan 29, 2021
2 parents 722ad07 + b207b58 commit c8ca178
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 37 deletions.
60 changes: 28 additions & 32 deletions python/lsst/jointcal/jointcal.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ class JointcalInputData:
"""The WCS of this exposure."""
bbox: lsst.geom.Box2I
"""The bounding box of this exposure."""
filter: lsst.afw.image.Filter
filter: lsst.afw.image.FilterLabel
"""The filter of this exposure."""


Expand Down Expand Up @@ -483,8 +483,8 @@ def _build_ccdImage(self, data, associations, jointcalControl):
``key``
A key to identify this dataRef by its visit and ccd ids
(`namedtuple`).
``filter``
This calexp's filter (`str`).
``band``
This calexp's filter band (`str`) (used to e.g. load refcats)
"""
goodSrc = self.sourceSelector.run(data.catalog)

Expand All @@ -498,16 +498,16 @@ def _build_ccdImage(self, data, associations, jointcalControl):
data.wcs,
data.visitInfo,
data.bbox,
data.filter.getName(),
data.filter.physicalLabel,
data.photoCalib,
data.detector,
data.visit,
data.detector.getId(),
jointcalControl)

Result = collections.namedtuple('Result_from_build_CcdImage', ('wcs', 'key', 'filter'))
Result = collections.namedtuple('Result_from_build_CcdImage', ('wcs', 'key', 'band'))
Key = collections.namedtuple('Key', ('visit', 'ccd'))
return Result(data.wcs, Key(data.visit, data.detector.getId()), data.filter.getName())
return Result(data.wcs, Key(data.visit, data.detector.getId()), data.filter.bandLabel)

def _readDataId(self, butler, dataId):
"""Read all of the data for one dataId from the butler. (gen2 version)"""
Expand All @@ -527,13 +527,13 @@ def _readDataId(self, butler, dataId):
photoCalib=butler.get('calexp_photoCalib', dataId=dataId),
wcs=butler.get('calexp_wcs', dataId=dataId),
bbox=butler.get('calexp_bbox', dataId=dataId),
filter=butler.get('calexp_filter', dataId=dataId))
filter=butler.get('calexp_filterLabel', dataId=dataId))

def loadData(self, dataRefs, associations, jointcalControl, profile_jointcal=False):
"""Read the data that jointcal needs to run. (Gen2 version)"""
visit_ccd_to_dataRef = {}
oldWcsList = []
filters = []
bands = []
load_cat_prof_file = 'jointcal_loadData.prof' if profile_jointcal else ''
with pipeBase.cmdLineTask.profile(load_cat_prof_file):
# Need the bounding-box of the focal plane (the same for all visits) for photometry visit models
Expand All @@ -544,17 +544,17 @@ def loadData(self, dataRefs, associations, jointcalControl, profile_jointcal=Fal
result = self._build_ccdImage(data, associations, jointcalControl)
oldWcsList.append(result.wcs)
visit_ccd_to_dataRef[result.key] = dataRef
filters.append(result.filter)
filters = collections.Counter(filters)
bands.append(result.band)
bands = collections.Counter(bands)

return oldWcsList, filters, visit_ccd_to_dataRef
return oldWcsList, bands, visit_ccd_to_dataRef

def _getDebugPath(self, filename):
"""Constructs a path to filename using the configured debug path.
"""
return os.path.join(self.config.debugOutputPath, filename)

def _prep_sky(self, associations, filters):
def _prep_sky(self, associations, bands):
"""Prepare on-sky and other data that must be computed after data has
been read.
"""
Expand All @@ -566,11 +566,11 @@ def _prep_sky(self, associations, filters):

self.log.info(f"Data has center={center} with radius={radius.asDegrees()} degrees.")

# Determine a default filter associated with the catalog. See DM-9093
defaultFilter = filters.most_common(1)[0][0]
self.log.debug("Using %s band for reference flux", defaultFilter)
# Determine a default filter band associated with the catalog. See DM-9093
defaultBand = bands.most_common(1)[0][0]
self.log.debug("Using '%s' filter band for reference flux", defaultBand)

return boundingCircle, center, radius, defaultFilter
return boundingCircle, center, radius, defaultBand

@pipeBase.timeMethod
def runDataRef(self, dataRefs, profile_jointcal=False):
Expand Down Expand Up @@ -607,17 +607,17 @@ def runDataRef(self, dataRefs, profile_jointcal=False):
jointcalControl = lsst.jointcal.JointcalControl(sourceFluxField)
associations = lsst.jointcal.Associations()

oldWcsList, filters, visit_ccd_to_dataRef = self.loadData(dataRefs,
associations,
jointcalControl,
profile_jointcal=profile_jointcal)
oldWcsList, bands, visit_ccd_to_dataRef = self.loadData(dataRefs,
associations,
jointcalControl,
profile_jointcal=profile_jointcal)

boundingCircle, center, radius, defaultFilter = self._prep_sky(associations, filters)
boundingCircle, center, radius, defaultBand = self._prep_sky(associations, bands)

tract = dataRefs[0].dataId['tract']

if self.config.doAstrometry:
astrometry = self._do_load_refcat_and_fit(associations, defaultFilter, center, radius,
astrometry = self._do_load_refcat_and_fit(associations, defaultBand, center, radius,
name="astrometry",
refObjLoader=self.astrometryRefObjLoader,
referenceSelector=self.astrometryReferenceSelector,
Expand All @@ -629,14 +629,13 @@ def runDataRef(self, dataRefs, profile_jointcal=False):
astrometry = Astrometry(None, None, None)

if self.config.doPhotometry:
photometry = self._do_load_refcat_and_fit(associations, defaultFilter, center, radius,
photometry = self._do_load_refcat_and_fit(associations, defaultBand, center, radius,
name="photometry",
refObjLoader=self.photometryRefObjLoader,
referenceSelector=self.photometryReferenceSelector,
fit_function=self._fit_photometry,
profile_jointcal=profile_jointcal,
tract=tract,
filters=filters,
reject_bad_fluxes=True)
self._write_photometry_results(associations, photometry.model, visit_ccd_to_dataRef)
else:
Expand All @@ -647,7 +646,7 @@ def runDataRef(self, dataRefs, profile_jointcal=False):
job=self.job,
astrometryRefObjLoader=self.astrometryRefObjLoader,
photometryRefObjLoader=self.photometryRefObjLoader,
defaultFilter=defaultFilter,
defaultBand=defaultBand,
exitStatus=exitStatus)

def _get_refcat_coordinate_error_override(self, refCat, name):
Expand Down Expand Up @@ -713,8 +712,7 @@ def _compute_proper_motion_epoch(self, ccdImageList):
mjds = [ccdImage.getMjd() for ccdImage in ccdImageList]
return astropy.time.Time(np.mean(mjds), format='mjd', scale="tai")

def _do_load_refcat_and_fit(self, associations, defaultFilter, center, radius,
filters=[],
def _do_load_refcat_and_fit(self, associations, defaultBand, center, radius,
tract="", profile_jointcal=False, match_cut=3.0,
reject_bad_fluxes=False, *,
name="", refObjLoader=None, referenceSelector=None,
Expand All @@ -725,7 +723,7 @@ def _do_load_refcat_and_fit(self, associations, defaultFilter, center, radius,
----------
associations : `lsst.jointcal.Associations`
The star/reference star associations to fit.
defaultFilter : `str`
defaultBand : `str`
filter to load from reference catalog.
center : `lsst.geom.SpherePoint`
ICRS center of field to load from reference catalog.
Expand All @@ -739,8 +737,6 @@ def _do_load_refcat_and_fit(self, associations, defaultFilter, center, radius,
Selector to use to pick objects from the loaded reference catalog.
fit_function : callable
Function to call to perform fit (takes Associations object).
filters : `list` [`str`], optional
List of filters to load from the reference catalog.
tract : `str`, optional
Name of tract currently being fit.
profile_jointcal : `bool`, optional
Expand All @@ -766,7 +762,7 @@ def _do_load_refcat_and_fit(self, associations, defaultFilter, center, radius,
applyColorterms = False if name.lower() == "astrometry" else self.config.applyColorTerms
epoch = self._compute_proper_motion_epoch(associations.getCcdImageList())
refCat, fluxField = self._load_reference_catalog(refObjLoader, referenceSelector,
center, radius, defaultFilter,
center, radius, defaultBand,
applyColorterms=applyColorterms,
epoch=epoch)
refCoordErr = self._get_refcat_coordinate_error_override(refCat, name)
Expand All @@ -790,7 +786,7 @@ def _do_load_refcat_and_fit(self, associations, defaultFilter, center, radius,
associations.nCcdImagesValidForFit())

load_cat_prof_file = 'jointcal_fit_%s.prof'%name if profile_jointcal else ''
dataName = "{}_{}".format(tract, defaultFilter)
dataName = "{}_{}".format(tract, defaultBand)
with pipeBase.cmdLineTask.profile(load_cat_prof_file):
result = fit_function(associations, dataName)
# TODO DM-12446: turn this into a "butler save" somehow.
Expand Down
2 changes: 1 addition & 1 deletion python/lsst/jointcal/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def compute_rms(self, data_refs, reference):
"""

# DECAM doesn't have "filter" in its registry, so we have to get the filter names directly.
self.filters = [ref.get('calexp_filter').getName() for ref in data_refs]
self.filters = [ref.get('calexp_filterLabel').bandLabel for ref in data_refs]
self.visits_per_dataRef = [ref.dataId['visit'] for ref in data_refs]

def compute(catalogs, photoCalibs):
Expand Down
4 changes: 2 additions & 2 deletions tests/jointcalTestBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,10 @@ def _testJointcalTask(self, nCatalogs, dist_rms_relative, dist_rms_absolute, pa1
data_refs = result.resultList[0].result.dataRefs
oldWcsList = result.resultList[0].result.oldWcsList

defaultFilter = result.resultList[0].result.defaultFilter
defaultBand = result.resultList[0].result.defaultBand

def compute_statistics(refObjLoader):
refCat = refObjLoader.loadSkyCircle(self.center, self.radius, defaultFilter).refCat
refCat = refObjLoader.loadSkyCircle(self.center, self.radius, defaultBand).refCat
rms_result = self.jointcalStatistics.compute_rms(data_refs, refCat)
# Make plots before testing, if requested, so we still get plots if tests fail.
if self.do_plot:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_astrometryModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ def setUp(self):
ccdId = detector.getId()
wcs = dataRef.get('calexp_wcs')
bbox = dataRef.get('calexp_bbox')
filt = dataRef.get('calexp_filter')
filterName = filt.getName()
filt = dataRef.get('calexp_filterLabel')
filterName = filt.physicalLabel
photoCalib = lsst.afw.image.PhotoCalib(100.0, 1.0)

self.catalogs.append(goodSrc)
Expand Down

0 comments on commit c8ca178

Please sign in to comment.