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-24337: Change raw formatters to use base API changes #220

Merged
merged 2 commits into from
Apr 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 14 additions & 26 deletions python/lsst/obs/base/fitsRawFormatterBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,46 +271,34 @@ def makeFilter(self):
"""
return lsst.afw.image.Filter(self.observationInfo.physical_filter)

def readImageComponent(self, component):
"""Read the image, mask, or variance component of an Exposure.
def readComponent(self, component, parameters=None):
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't see parameters used anywhere in the method.

Copy link
Member Author

Choose a reason for hiding this comment

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

Correct. The base class requires the argument though since the butler may pass parameters in. Parameters are not used by any of the raw formatter code so this is a long standing issue. I made a comment on the Jira ticket. At some point we need to decide what parameters make sense for raw formatter (maybe only bounding box) and complain if any others turn up. Currently the storage class defines the allowed parameters and that might lead to a special RawExposure storage class that defines a different set.

"""Read a component held by the Exposure.

Parameters
----------
component : `str`, optional
Component to read from the file. Always one of "image",
"variance", or "mask".
Component to read from the file.
parameters : `dict`, optional
If specified, a dictionary of slicing parameters that
overrides those in ``fileDescriptor``.

Returns
-------
image : `~lsst.afw.image.Image` or `~lsst.afw.image.Mask`
In-memory image, variance, or mask component.
obj : component-dependent
In-memory component object.

Raises
------
KeyError
Raised if the requested component cannot be handled.
"""
if component == "image":
return self.readImage()
elif component == "mask":
return self.readMask()
elif component == "variance":
return self.readVariance()

def readInfoComponent(self, component):
"""Read a component held by ExposureInfo.

The implementation provided by FitsRawFormatter provides only "wcs"
and "visitInfo". When adding support for other components, subclasses
should delegate to `super()` for those and update `readFull` with
similar logic.

Parameters
----------
component : `str`, optional
Component to read from the file.

Returns
-------
obj : component-dependent
In-memory component object.
"""
if component == "filter":
elif component == "filter":
return self.makeFilter()
elif component == "visitInfo":
return self.makeVisitInfo()
Expand Down
14 changes: 13 additions & 1 deletion python/lsst/obs/base/ingest_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,20 @@ def runIngestTest(self, files=None):
for dataId in self.dataIds:
exposure = self.butler.get("raw", dataId)
metadata = self.butler.get("raw.metadata", dataId)
# only check the metadata, not the images, to speed up tests
self.assertEqual(metadata.toDict(), exposure.getMetadata().toDict())

# Since components follow a different code path we check that
# WCS match and also we check that at least the shape
# of the image is the same (rather than doing per-pixel equality)
# Check the observation type before trying to check WCS
obsType = self.butler.registry.expandDataId(dataId).records["exposure"].observation_type
if obsType == "science":
wcs = self.butler.get("raw.wcs", dataId)
self.assertEqual(wcs, exposure.getWcs())

rawImage = self.butler.get("raw.image", dataId)
self.assertEqual(rawImage.getBBox(), exposure.getBBox())

self.checkRepo(files=files)

def checkRepo(self, files=None):
Expand Down