Skip to content

Commit

Permalink
Improve old-style filter translation.
Browse files Browse the repository at this point in the history
Code will now recognize that filters identified by an afw_name are
unlikely to be referred to by any other name.
  • Loading branch information
kfindeisen committed Mar 30, 2021
1 parent 93d8575 commit d2fb979
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
9 changes: 9 additions & 0 deletions python/lsst/obs/base/cameraMapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -1106,6 +1106,15 @@ def _getBestFilter(self, storedLabel, idFilter):
newLabel = list(definitions)[0].makeFilterLabel()
return newLabel
elif definitions:
# Some instruments have many filters for the same band, of
# which one is known by band name and the others always by
# afw name (e.g., i, i2).
nonAfw = {f for f in definitions if f.afw_name is None}
if len(nonAfw) == 1:
newLabel = list(nonAfw)[0].makeFilterLabel()
self.log.debug("Assuming %r is the correct match.", newLabel)
return newLabel

self.log.warn("Multiple matches for filter %r with data ID %r.", storedLabel, idFilter)
# Can we at least add a band?
# Never expect multiple definitions with same physical filter.
Expand Down
15 changes: 5 additions & 10 deletions tests/test_cameraMapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,11 +416,12 @@ def testStandardize(self):
self.assertEqual(mapper.canStandardize("notPresent"), False)

def testStandardizeFiltersFilterDefs(self):
# tuples are (input, desired output)
testLabels = [
(None, None),
(afwImage.FilterLabel(band="i", physical="i.MP9701"),
afwImage.FilterLabel(band="i", physical="i.MP9701")),
(afwImage.FilterLabel(band="i"), afwImage.FilterLabel(band="r", physical="i.MP9701")),
(afwImage.FilterLabel(band="i"), afwImage.FilterLabel(band="i", physical="i.MP9701")),
(afwImage.FilterLabel(physical="i.MP9701"),
afwImage.FilterLabel(band="i", physical="i.MP9701")),
(afwImage.FilterLabel(band="i", physical="old-i"),
Expand All @@ -437,18 +438,12 @@ def testStandardizeFiltersFilterDefs(self):
for input, corrected in testLabels:
for dataId in testIds:
if input is None:
if dataId["filter"] == "i":
data = (input, dataId, afwImage.FilterLabel(band="i"))
elif dataId["filter"] == "i2":
if dataId["filter"] == "i2":
data = (input, dataId, afwImage.FilterLabel(band="i", physical="HSC-I2"))
else:
data = (input, dataId, afwImage.FilterLabel(band="i", physical="i.MP9701"))
elif input == afwImage.FilterLabel(band="i"):
if dataId["filter"] == "i":
# There are two "i" filters, can't tell which
data = (input, dataId, input)
elif dataId["filter"] == "i2":
data = (input, dataId, afwImage.FilterLabel(band="i", physical="HSC-I2"))
elif input == afwImage.FilterLabel(band="i") and dataId["filter"] == "i2":
data = (input, dataId, afwImage.FilterLabel(band="i", physical="HSC-I2"))
elif corrected.physicalLabel == "HSC-I2" and dataId["filter"] in ("i.MP9701", "old-i"):
# Contradictory inputs, leave as-is
data = (input, dataId, input)
Expand Down

0 comments on commit d2fb979

Please sign in to comment.