Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM-27178: Standardize aliases on Gen 2 Exposure get #336

Merged
merged 5 commits into from Dec 17, 2020

Conversation

kfindeisen
Copy link
Member

@kfindeisen kfindeisen commented Dec 16, 2020

This PR rewrites the Gen 2 filter-patching code to use FilterLabel instead of the less precise Filter, using any FilterDefinition objects as the source of truth for band and physical filter designations. For obs packages that do not use FilterDefinition (or, equivalently, Instrument), it falls back to the old behavior.

The new algorithm is intended to remove references to filter aliases from Exposure objects, and to disambiguate imperfectly converted old-style Filters. It is most important for calexps, which previously stored only the band name.

Copy link
Contributor

@erykoff erykoff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be out of scope for this ticket, but I am not quite sure how the alias system is going to continue into the Gen3 Future. Specifically, are short-hand terms like r2 essentially deprecated and we must use full names (HSC-R2, which thankfully isn't too verbose), or are these aliases going to live on?

@@ -1028,36 +1029,100 @@ def _setCcdDetector(self, item, dataId, trimmed=True):
detector = self.camera[detectorName]
item.setDetector(detector)

@staticmethod
def _resolveFilters(definitions, idFilter, filterLabel):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be better to have this as idFilter=None, filterLabel=None, to make it clear what the defaults are?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's my experience that default values tend to lead to error-prone code, so I'd prefer not to use them unless there's a specific benefit.

python/lsst/obs/base/cameraMapper.py Outdated Show resolved Hide resolved
item.setFilter(afwImage.Filter(filterName))
except pexExcept.NotFoundError:
self.log.warn("Filter %s not defined. Set to UNKNOWN." % (filterName))
filterDefinitions = self.getGen3Instrument()().filterDefinitions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are there two sets of parentheses here? Also, I guess I don't understand the call from gen2 code into gen3 code here or how that works.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because getGen3Instrument() returns an Instrument class, and not an object (though all Instrument subclasses are required to be constructible with no arguments). No idea why it was designed that way.

As for the Gen 2/3 distinction, I think Instrument was intended to be a bridge between the two, so it's not a violation to use it in Gen 2 code. Though I'll admit I'm calling it mostly out of laziness (there is a way to get at the filter definitions without using Instrument, but it would require making an API change to CameraMapper and all its subclasses, and getGen3Instrument was already there).

python/lsst/obs/base/cameraMapper.py Outdated Show resolved Hide resolved
newLabel = list(definitions)[0].makeFilterLabel()
if newLabel != itemFilter:
item.setFilterLabel(newLabel)
elif definitions:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be len(definitions) > 1 to be explicit?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was told that's Unpythonic, and that if definitions is the preferred style?

python/lsst/obs/base/cameraMapper.py Outdated Show resolved Hide resolved
python/lsst/obs/base/cameraMapper.py Outdated Show resolved Hide resolved
@kfindeisen
Copy link
Member Author

This might be out of scope for this ticket, but I am not quite sure how the alias system is going to continue into the Gen3 Future. Specifically, are short-hand terms like r2 essentially deprecated and we must use full names (HSC-R2, which thankfully isn't too verbose), or are these aliases going to live on?

Yes, aliases are going away -- Gen 3 can't handle them, and FilterLabel is specifically designed to not need them (see RFC-730 or the Community post). Half the point of this PR is to ensure they don't lurk around in old files indefinitely.

As for references to old names, in-code references will be rewritten to use either physical or band names. I think the case of r2 in obs_subaru will be handled on DM-27170. If you mean on the command line, I think you can use the band as long as the Butler doesn't consider it unambiguous (I don't know whether that depends on whether there's also R1 data in the repository).

The new standardizer uses FilterDefinitions as input, where possible,
and uses the enhanced precision of FilterLabel to write exactly the
desired filter.
Not having access to FilterDefinition is an edge case, but one that
might persist for a while.
@kfindeisen kfindeisen merged commit 972c18d into master Dec 17, 2020
@kfindeisen kfindeisen deleted the tickets/DM-27178 branch December 17, 2020 17:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants