Skip to content

Commit

Permalink
Merge pull request #220 from lsst/tickets/DM-24337
Browse files Browse the repository at this point in the history
DM-24337: Change raw formatters to use base API changes
  • Loading branch information
timj committed Apr 3, 2020
2 parents 58bbfa5 + 6c3acc2 commit 74b054e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 27 deletions.
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):
"""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

0 comments on commit 74b054e

Please sign in to comment.