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-25152: Pre-import all known instruments before running ingest #254

Merged
merged 4 commits into from
May 29, 2020
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 4 additions & 0 deletions python/lsst/obs/base/ingest.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ def __init__(self, config: Optional[RawIngestConfig] = None, *, butler: Butler,
self.universe = self.butler.registry.dimensions
self.datasetType = self.getDatasetType()

# Import all the instrument classes so that we ensure that we
# have all the relevant metadata translators loaded.
Instrument.importAll(self.butler.registry)

def extractMetadata(self, filename: str) -> RawFileData:
"""Extract and process metadata from a single raw file.

Expand Down
30 changes: 28 additions & 2 deletions python/lsst/obs/base/instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

if TYPE_CHECKING:
from .gen2to3 import TranslatorFactory
from lsst.daf.butler import Registry

# To be a standard text curated calibration means that we use a
# standard definition for the corresponding DatasetType.
Expand Down Expand Up @@ -130,8 +131,8 @@ def obsDataPackageDir(self):
self._obsDataPackageDir = getPackageDir(self.obsDataPackage)
return self._obsDataPackageDir

@classmethod
def fromName(cls, name, registry):
@staticmethod
def fromName(name: str, registry: Registry) -> Instrument:
"""Given an instrument name and a butler, retrieve a corresponding
instantiated instrument object.

Expand Down Expand Up @@ -168,6 +169,31 @@ def fromName(cls, name, registry):
instrument = doImport(cls)
return instrument()

@staticmethod
def importAll(registry: Registry) -> None:
"""Import all the instruments known to this registry.

This will ensure that all metadata translators have been registered.

Parameters
----------
registry : `lsst.daf.butler.Registry`
Butler registry to query to find the information.

Notes
-----
It is allowed for a particular instrument class to fail on import.
This might simply indicate that a particular obs package has
not been setup.
"""
dimensions = list(registry.queryDimensions("instrument"))
for dim in dimensions:
cls = dim.records["instrument"].class_name
try:
doImport(cls)
except Exception:
pass
timj marked this conversation as resolved.
Show resolved Hide resolved

def _registerFilters(self, registry):
"""Register the physical and abstract filter Dimension relationships.
This should be called in the ``register`` implementation.
Expand Down