Skip to content

Commit

Permalink
Replace deprecated Filter interface with FilterLabel
Browse files Browse the repository at this point in the history
* bandLabel is the closest replacement for `getCanonicalName()[0]`,
though it is not guaranteed to be a single character.
* defineFilter is no longer needed.
  • Loading branch information
parejkoj committed Jan 7, 2021
1 parent 97b6447 commit e2ed3c7
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 60 deletions.
4 changes: 1 addition & 3 deletions python/lsst/ap/association/diaForcedSource.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,7 @@ def _calibrate_and_merge(self,
midPointTaiMJD = visit_info.getDate().get(system=DateTime.MJD)
output_catalog["ccdVisitId"] = ccdVisitId
output_catalog["midPointTai"] = midPointTaiMJD
# TODO DM-27170: fix this [0] workaround which gets a single character
# representation of the band.
output_catalog["filterName"] = diff_exp.getFilter().getCanonicalName()[0]
output_catalog["filterName"] = diff_exp.getFilterLabel().bandLabel

# Drop superfluous columns from output DataFrame.
output_catalog.drop(columns=self.config.dropColumns, inplace=True)
Expand Down
4 changes: 1 addition & 3 deletions python/lsst/ap/association/mapApData.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,7 @@ def run(self, inputCatalog, exposure, return_pandas=False):
visit_info = exposure.getInfo().getVisitInfo()
ccdVisitId = visit_info.getExposureId()
midPointTaiMJD = visit_info.getDate().get(system=DateTime.MJD)
# TODO DM-27170: fix this [0] workaround which gets a single character
# representation of the band.
filterName = exposure.getFilter().getCanonicalName()[0]
filterName = exposure.getFilterLabel().bandLabel
wcs = exposure.getWcs()

photoCalib = exposure.getPhotoCalib()
Expand Down
15 changes: 2 additions & 13 deletions tests/test_association_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
from lsst.afw.cameraGeom.testUtils import DetectorWrapper
import lsst.afw.geom as afwGeom
import lsst.afw.image as afwImage
import lsst.afw.image.utils as afwImageUtils
import lsst.afw.table as afwTable
import lsst.daf.base as dafBase
import lsst.geom as geom
Expand Down Expand Up @@ -162,15 +161,7 @@ class TestAssociationTask(unittest.TestCase):
def setUp(self):
"""Create a sqlite3 database with default tables and schemas.
"""
# CFHT Filters from the camera mapper.
self.filter_names = ["u", "g", "r", "i", "z"]
afwImageUtils.resetFilters()
afwImageUtils.defineFilter('u', lambdaEff=374, alias="u.MP9301")
afwImageUtils.defineFilter('g', lambdaEff=487, alias="g.MP9401")
afwImageUtils.defineFilter('r', lambdaEff=628, alias="r.MP9601")
afwImageUtils.defineFilter('i', lambdaEff=778, alias="i.MP9701")
afwImageUtils.defineFilter('z', lambdaEff=1170, alias="z.MP9801")

self.dia_object_schema = make_dia_object_schema()

# metadata taken from CFHT data
Expand Down Expand Up @@ -210,7 +201,7 @@ def setUp(self):
dafBase.DateTime.Timescale.TAI))
self.exposure.setDetector(detector)
self.exposure.getInfo().setVisitInfo(visit)
self.exposure.setFilter(afwImage.Filter('g'))
self.exposure.setFilterLabel(afwImage.FilterLabel(band='g'))
self.flux0 = 10000
self.flux0_err = 100
self.exposure.setPhotoCalib(
Expand Down Expand Up @@ -323,9 +314,7 @@ def _run_association_and_retrieve_objects(self, create_objects=False):
dia_source=dia_source,
flux=10000,
fluxErr=100,
# TODO DM-27170: fix this [0] workaround which gets a
# single character representation of the band.
filterName=self.exposure.getFilter().getCanonicalName()[0],
filterName=self.exposure.getFilterLabel().bandLabel,
ccdVisitId=self.exposure.getInfo().getVisitInfo().getExposureId(),
midPointTai=self.exposure.getInfo().getVisitInfo().getDate().get(system=dafBase.DateTime.MJD))

Expand Down
14 changes: 2 additions & 12 deletions tests/test_diaForcedSource.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
from lsst.afw.cameraGeom.testUtils import DetectorWrapper
import lsst.afw.geom as afwGeom
import lsst.afw.image as afwImage
import lsst.afw.image.utils as afwImageUtils
import lsst.afw.table as afwTable
import lsst.daf.base as dafBase
import lsst.meas.algorithms as measAlg
Expand Down Expand Up @@ -67,15 +66,6 @@ def create_test_dia_objects(n_points, wcs, startPos=100):
class TestDiaForcedSource(unittest.TestCase):

def setUp(self):
# CFHT Filters from the camera mapper.
self.filter_names = ["u", "g", "r", "i", "z"]
afwImageUtils.resetFilters()
afwImageUtils.defineFilter('u', lambdaEff=374, alias="u.MP9301")
afwImageUtils.defineFilter('g', lambdaEff=487, alias="g.MP9401")
afwImageUtils.defineFilter('r', lambdaEff=628, alias="r.MP9601")
afwImageUtils.defineFilter('i', lambdaEff=778, alias="i.MP9701")
afwImageUtils.defineFilter('z', lambdaEff=1170, alias="z.MP9801")

# metadata taken from CFHT data
# v695856-e0/v695856-e0-c000-a00.sci_img.fits
self.metadata = dafBase.PropertySet()
Expand Down Expand Up @@ -132,7 +122,7 @@ def setUp(self):
dafBase.DateTime.Timescale.TAI))
self.exposure.setDetector(detector)
self.exposure.getInfo().setVisitInfo(visit)
self.exposure.setFilter(afwImage.Filter('g'))
self.exposure.setFilterLabel(afwImage.FilterLabel(band='g', physical='g.MP9401'))
self.exposure.setPhotoCalib(afwImage.PhotoCalib(self.calibration, self.calibrationErr))

# Difference Image
Expand All @@ -148,7 +138,7 @@ def setUp(self):
self.diffim = afwImage.makeExposure(masked_image, self.wcs)
self.diffim.setDetector(detector)
self.diffim.getInfo().setVisitInfo(visit)
self.diffim.setFilter(afwImage.Filter('g'))
self.diffim.setFilterLabel(afwImage.FilterLabel(band='g', physical='g.MP9401'))
self.diffim.setPhotoCalib(afwImage.PhotoCalib(self.calibration, self.calibrationErr))

self.expIdBits = 16
Expand Down
8 changes: 1 addition & 7 deletions tests/test_loadDiaCatalogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
from lsst.afw.cameraGeom.testUtils import DetectorWrapper
import lsst.afw.geom as afwGeom
import lsst.afw.image as afwImage
import lsst.afw.image.utils as afwImageUtils
from lsst.ap.association import (LoadDiaCatalogsTask,
LoadDiaCatalogsConfig,
make_dia_source_schema,
Expand Down Expand Up @@ -117,7 +116,7 @@ def makeExposure(flipX=False, flipY=False):
dafBase.DateTime.Timescale.TAI))
exposure.setDetector(detector)
exposure.getInfo().setVisitInfo(visit)
exposure.setFilter(afwImage.Filter('g'))
exposure.setFilterLabel(afwImage.FilterLabel(band='g'))

return exposure

Expand Down Expand Up @@ -249,11 +248,6 @@ class TestLoadDiaCatalogs(unittest.TestCase):
def setUp(self):
np.random.seed(1234)

# CFHT Filters from the camera mapper.
self.filter_names = ["g"]
afwImageUtils.resetFilters()
afwImageUtils.defineFilter('g', lambdaEff=487, alias="g.MP9401")

self.db_file_fd, self.db_file = tempfile.mkstemp(
dir=os.path.dirname(__file__))

Expand Down
12 changes: 1 addition & 11 deletions tests/test_map_ap_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import lsst.afw.table as afwTable
import lsst.daf.base as dafBase
import lsst.afw.image as afwImage
import lsst.afw.image.utils as afwImageUtils
import lsst.geom as geom
import lsst.meas.base.tests as measTests
from lsst.utils import getPackageDir
Expand Down Expand Up @@ -88,16 +87,7 @@ def make_input_source_catalog(dataset, add_flags=False):
class TestAPDataMapperTask(unittest.TestCase):

def setUp(self):

nSources = 10
# CFHT Filters from the camera mapper.
afwImageUtils.resetFilters()
afwImageUtils.defineFilter('u', lambdaEff=374, alias="u.MP9301")
afwImageUtils.defineFilter('g', lambdaEff=487, alias="g.MP9401")
afwImageUtils.defineFilter('r', lambdaEff=628, alias="r.MP9601")
afwImageUtils.defineFilter('i', lambdaEff=778, alias="i.MP9701")
afwImageUtils.defineFilter('z', lambdaEff=1170, alias="z.MP9801")

self.bbox = geom.Box2I(geom.Point2I(0, 0),
geom.Extent2I(1024, 1153))
dataset = measTests.TestDataset(self.bbox)
Expand All @@ -114,7 +104,7 @@ def setUp(self):
date=dafBase.DateTime(nsecs=1400000000 * 10**9))
self.exposure.setDetector(detector)
self.exposure.getInfo().setVisitInfo(visit)
self.exposure.setFilter(afwImage.Filter('g.MP9401'))
self.exposure.setFilterLabel(afwImage.FilterLabel(band='g', physical='g.MP9401'))
scale = 2
scaleErr = 1
self.photoCalib = afwImage.PhotoCalib(scale, scaleErr)
Expand Down
14 changes: 3 additions & 11 deletions tests/test_packageAlerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
make_dia_object_schema)
from lsst.afw.cameraGeom.testUtils import DetectorWrapper
import lsst.afw.image as afwImage
import lsst.afw.image.utils as afwImageUtils
import lsst.daf.base as dafBase
from lsst.dax.apdb import Apdb, ApdbConfig
import lsst.geom as geom
Expand Down Expand Up @@ -157,9 +156,7 @@ def makeDiaSources(nSources, diaObjectIds, exposure):
"diaSourceId": idx,
"pixelId": htmIdx,
"midPointTai": midPointTaiMJD + 1.0 * idx,
# TODO DM-27170: fix this [0] workaround which gets a
# single character representation of the band.
"filterName": exposure.getFilter().getCanonicalName()[0],
"filterName": exposure.getFilterLabel().bandLabel,
"psNdata": 0,
"trailNdata": 0,
"dipNdata": 0,
Expand Down Expand Up @@ -198,9 +195,7 @@ def makeDiaForcedSources(nSources, diaObjectIds, exposure):
"ccdVisitId": ccdVisitId + idx,
"diaObjectId": objId,
"midPointTai": midPointTaiMJD + 1.0 * idx,
# TODO DM-27170: fix this [0] workaround which gets a
# single character representation of the band.
"filterName": exposure.getFilter().getCanonicalName()[0],
"filterName": exposure.getFilterLabel().bandLabel,
"flags": 0})

return pd.DataFrame(data=data)
Expand Down Expand Up @@ -305,10 +300,7 @@ def setUp(self):
dafBase.DateTime.Timescale.TAI))
self.exposure.getInfo().setVisitInfo(visit)

self.filter_names = ["g"]
afwImageUtils.resetFilters()
afwImageUtils.defineFilter('g', lambdaEff=487, alias="g.MP9401")
self.exposure.setFilter(afwImage.Filter('g'))
self.exposure.setFilterLabel(afwImage.FilterLabel(band='g', physical="g.MP9401"))

diaObjects = makeDiaObjects(2, self.exposure)
diaSourceHistory = makeDiaSources(10,
Expand Down

0 comments on commit e2ed3c7

Please sign in to comment.