Skip to content

Commit

Permalink
Merge branch 'tickets/DM-28004' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
kfindeisen committed Dec 14, 2020
2 parents e3f3753 + f2480be commit 484459b
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 9 deletions.
7 changes: 6 additions & 1 deletion include/lsst/afw/image/Exposure.h
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,12 @@ class Exposure {
void setDetector(std::shared_ptr<lsst::afw::cameraGeom::Detector const> detector) {
_info->setDetector(detector);
}
/// Set the Exposure's filter
/**
* Set the Exposure's filter
*
* @param filter The filter to set. If this is the default filter
* ("_unknown_"), it is interpreted as "no filter".
*/
// TODO: deprecate in DM-27170, remove in DM-27177
void setFilter(Filter const& filter) { _info->setFilter(filter); }
/// Set the Exposure's filter information
Expand Down
7 changes: 6 additions & 1 deletion include/lsst/afw/image/ExposureInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,12 @@ class ExposureInfo final {
// TODO: deprecate in DM-27170, remove in DM-27177
Filter getFilter() const;

/// Set the exposure's filter
/**
* Set the exposure's filter
*
* @param filter The filter to set. If this is the default filter
* ("_unknown_"), it is interpreted as "no filter".
*/
// TODO: deprecate in DM-27170, remove in DM-27177
void setFilter(Filter const& filter);

Expand Down
13 changes: 13 additions & 0 deletions src/image/ExposureFitsReader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ bool _isBand(std::string const& name) {
* @returns A FilterLabel containing that name.
*/
std::shared_ptr<FilterLabel> makeFilterLabelDirect(std::string const& name) {
static Filter const DEFAULT;
// Avoid turning dummy filters into real FilterLabels.
if (name == DEFAULT.getName()) {
return nullptr;
}

// FilterLabel::from* returns a statically allocated object, so only way
// to get it into shared_ptr is to copy it.
if (_isBand(name)) {
Expand All @@ -113,6 +119,13 @@ std::shared_ptr<FilterLabel> makeFilterLabelDirect(std::string const& name) {
*/
// TODO: compatibility code to be removed in DM-27177
std::shared_ptr<FilterLabel> makeFilterLabel(Filter const& filter) {
static Filter const DEFAULT;
// Avoid turning dummy filters into real FilterLabels.
// Default filter has id=UNKNOWN, but others do too.
if (filter.getId() == DEFAULT.getId() && filter.getName() == DEFAULT.getName()) {
return nullptr;
}

// Filter has no self-consistency guarantees whatsoever, and most methods
// are unsafe. Program extremely defensively.
if (filter.getId() == Filter::UNKNOWN) {
Expand Down
9 changes: 2 additions & 7 deletions src/image/ExposureInfo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,8 @@ ExposureInfo::ExposureInfo(std::shared_ptr<geom::SkyWcs const> const& wcs,
: std::shared_ptr<daf::base::PropertySet>(new daf::base::PropertyList())),
_visitInfo(visitInfo),
_components(std::make_unique<MapClass>()) {
static Filter const DEFAULT;
// Avoid putting dummy filters into the FilterLabel store. getFilter()
// will preserve old default behavior.
// Default filter has id=UNKNOWN, but others do too.
if (filter.getId() != DEFAULT.getId() || filter.getName() != DEFAULT.getName()) {
setFilter(filter);
}
// setFilter guards against default filters
setFilter(filter);
setWcs(wcs);
setPsf(psf);
setPhotoCalib(photoCalib);
Expand Down
9 changes: 9 additions & 0 deletions tests/test_exposure.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,15 @@ def testSetExposureInfo(self):
self.assertEqual(exposure.getFilter(), gFilter)
self.assertEqual(exposure.getFilterLabel(), gFilterLabel)

def testDefaultFilter(self):
"""Test that old convention of having a "default" filter replaced with `None`.
"""
exposureInfo = afwImage.ExposureInfo()
noFilter = afwImage.Filter()
exposureInfo.setFilter(noFilter)
self.assertFalse(exposureInfo.hasFilterLabel())
self.assertIsNone(exposureInfo.getFilterLabel())

def testVisitInfoFitsPersistence(self):
"""Test saving an exposure to FITS and reading it back in preserves (some) VisitInfo fields"""
exposureId = 5
Expand Down

0 comments on commit 484459b

Please sign in to comment.