Skip to content

Commit

Permalink
Deprecate components in Registry.findDataset and getDatasetType.
Browse files Browse the repository at this point in the history
  • Loading branch information
TallJimbo committed Sep 21, 2022
1 parent 4701b2d commit dcde14f
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 7 deletions.
22 changes: 19 additions & 3 deletions python/lsst/daf/butler/_butler.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,10 @@ def _standardizeArgs(
if isinstance(datasetRefOrType, DatasetType):
externalDatasetType = datasetRefOrType
else:
internalDatasetType = self.registry.getDatasetType(datasetRefOrType)
parent_dataset_type, component = DatasetType.splitDatasetTypeName(datasetRefOrType)
internalDatasetType = self.registry.getDatasetType(parent_dataset_type)
if component is not None:
internalDatasetType = internalDatasetType.makeComponentDatasetType(component)

# Check that they are self-consistent
if externalDatasetType is not None:
Expand Down Expand Up @@ -1093,17 +1096,30 @@ def _findDatasetRef(
)
# Always lookup the DatasetRef, even if one is given, to ensure it is
# present in the current collection.
ref = self.registry.findDataset(datasetType, dataId, collections=collections, timespan=timespan)
if datasetType.isComponent():
parent_dataset_type = datasetType.makeCompositeDatasetType()
component = datasetType.component()
else:
parent_dataset_type = datasetType
component = None
ref = self.registry.findDataset(
parent_dataset_type, dataId, collections=collections, timespan=timespan
)
if ref is None:
if allowUnresolved:
return DatasetRef(datasetType, dataId)
ref = DatasetRef(datasetType, dataId)
if component is not None:
ref = ref.makeComponentRef(component)
return ref
else:
if collections is None:
collections = self.registry.defaults.collections
raise LookupError(
f"Dataset {datasetType.name} with data ID {dataId} "
f"could not be found in collections {collections}."
)
if component is not None:
ref = ref.makeComponentRef(component)
if idNumber is not None and idNumber != ref.id:
if collections is None:
collections = self.registry.defaults.collections
Expand Down
6 changes: 5 additions & 1 deletion python/lsst/daf/butler/core/datasets/type.py
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,11 @@ def from_simple(
raise ValueError(
f"Unable to convert a DatasetType name '{simple}' to DatasetType without a Registry"
)
return registry.getDatasetType(simple.name)
parent_name, component = cls.splitDatasetTypeName(simple.name)
dataset_type = registry.getDatasetType(parent_name)
if component is not None:
dataset_type = dataset_type.makeComponentDatasetType(component)
return dataset_type

if universe is None and registry is None:
raise ValueError("One of universe or registry must be provided.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,11 @@ def find(self, name: str) -> DatasetRecordStorage | None:
compositeName, componentName = DatasetType.splitDatasetTypeName(name)
storage = self._byName.get(compositeName)
if storage is not None and componentName is not None:
warnings.warn(
"Registry component dataset operations are deprecated in favor of DatasetRef methods, and "
"will be removed after v26.",
FutureWarning,
)
componentStorage = copy.copy(storage)
componentStorage.datasetType = storage.datasetType.makeComponentDatasetType(componentName)
return componentStorage
Expand Down
8 changes: 6 additions & 2 deletions python/lsst/daf/butler/registry/tests/_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -658,14 +658,18 @@ def testComponentLookups(self):
# DatasetRef.makeComponentRef.
collection = "imported_g"
parentType = registry.getDatasetType("bias")
childType = registry.getDatasetType("bias.wcs")
with self.assertWarns(FutureWarning):
childType = registry.getDatasetType("bias.wcs")
parentRefResolved = registry.findDataset(
parentType, collections=collection, instrument="Cam1", detector=1
)
self.assertIsInstance(parentRefResolved, DatasetRef)
self.assertEqual(childType, parentRefResolved.makeComponentRef("wcs").datasetType)
# Search for a single dataset with findDataset.
childRef1 = registry.findDataset("bias.wcs", collections=collection, dataId=parentRefResolved.dataId)
with self.assertWarns(FutureWarning):
childRef1 = registry.findDataset(
"bias.wcs", collections=collection, dataId=parentRefResolved.dataId
)
self.assertEqual(childRef1, parentRefResolved.makeComponentRef("wcs"))
# Search for detector data IDs constrained by component dataset
# existence with queryDataIds.
Expand Down
2 changes: 1 addition & 1 deletion tests/test_butler.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ def runPutGetTest(self, storageClass, datasetTypeName):
)
self.assertEqual(count, stop)

compRef = butler.registry.findDataset(compNameS, dataId, collections=butler.collections)
compRef = ref.makeComponentRef("summary")
summary = butler.getDirect(compRef)
self.assertEqual(summary, metric.summary)

Expand Down

0 comments on commit dcde14f

Please sign in to comment.