Hi, I am wondering if there is a way to obtain just the metadata (or FITS headers) from a calexp
dataset type using the butler. Right now, I am scraping through just the metadata of many exposures, something like:
refs = registry.queryDatasets("calexp", collections=collection)
for ref in refs:
calexp = butler.get(ref, collections=ref.run)
metadata = calexp.getMetadata()
del calexp # so I don't run out of memory
This is going quite slowly as the butler is loading each exposure into memory. I see there is a parameters
option in the butler.get
docstring:
Signature:
butler.get(
datasetRefOrType: 'Union[DatasetRef, DatasetType, str]',
dataId: 'Optional[DataId]' = None,
*,
parameters: 'Optional[Dict[str, Any]]' = None,
collections: 'Any' = None,
**kwds: 'Any',
) -> 'Any'
Docstring:
Retrieve a stored dataset.
Parameters
----------
datasetRefOrType : `DatasetRef`, `DatasetType`, or `str`
When `DatasetRef` the `dataId` should be `None`.
Otherwise the `DatasetType` or name thereof.
dataId : `dict` or `DataCoordinate`
A `dict` of `Dimension` link name, value pairs that label the
`DatasetRef` within a Collection. When `None`, a `DatasetRef`
should be provided as the first argument.
parameters : `dict`
Additional StorageClass-defined options to control reading,
typically used to efficiently read only a subset of the dataset.
Can I use this parameters
to select just the metadata? I’ve tried a test
butler.get(ref, collections=ref.run, parameters={"test": "123"})
and get an error:
KeyError: "Parameter 'test' not understood by StorageClass ExposureF"
and if I try a test with a parameter I find by examining ref.datasetType.storageClass
: StorageClassExposureF('ExposureF', pytype='lsst.afw.image.ExposureF', delegate='lsst.obs.base.exposureAssembler.ExposureAssembler', parameters=frozenset({'origin', 'bbox'}),
butler.get(ref, collections=ref.run, parameters={"origin": '123'})
I get an error
/home/admin/lsst/lsst_22_0_0/stack/miniconda3-py38_4.9.2-0.4.3/Linux64/obs_base/22.0.0+6225f1ba97/python/lsst/obs/base/formatters/fitsExposure.py in readFull(self, parameters)
243 self._reader = self._readerClass(fileDescriptor.location.path)
--> 244 return self._reader.read(**parameters)
245
TypeError: read(): incompatible function arguments. The following argument types are supported:
1. (self: lsst.afw.image.ExposureFitsReader, bbox: lsst.geom.Box2I = Box2I(minimum=Point2I(0, 0), dimensions=Extent2I(0, 0)), origin: lsst.afw.image.image.ImageOrigin = <ImageOrigin.PARENT: 0>, conformMasks: bool = False, allowUnsafe: bool = False, dtype: object = None) -> object
Invoked with: <lsst.afw.image.ExposureFitsReader object at 0x7febb2bfc8b0>; kwargs: origin='123'
which tells me parameters
controls the constructor of the ExpsoureFitsReader
…if that’s true, is there a constructor that loads just the metadata?
This is all the snooping I’ve done so far.
Thanks.