Skip to content

Commit

Permalink
Add support for day_obs/seq_num to Butler.find_dataset
Browse files Browse the repository at this point in the history
  • Loading branch information
timj committed Oct 31, 2023
1 parent b22a5f3 commit faa1b00
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
8 changes: 8 additions & 0 deletions python/lsst/daf/butler/direct_butler.py
Original file line number Diff line number Diff line change
Expand Up @@ -1334,6 +1334,14 @@ def find_dataset(
datastore_records: bool = False,
**kwargs: Any,
) -> DatasetRef | None:
# Handle any parts of the dataID that are not using primary dimension
# keys.
if isinstance(dataset_type, str):
actual_type = self.get_dataset_type(dataset_type)
else:
actual_type = dataset_type
data_id, kwargs = self._rewrite_data_id(data_id, actual_type, **kwargs)

return self._registry.findDataset(
dataset_type,
data_id,
Expand Down
9 changes: 6 additions & 3 deletions python/lsst/daf/butler/remote_butler/server/_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,11 @@ def find_dataset(
) -> SerializedDatasetRef | None:
collection_query = query.collections if query.collections else None

# Get the simple dict from the SerializedDataCoordinate. We do not know
# if it is a well-defined DataCoordinate or needs some massaging first.
# find_dataset will use dimension record queries if necessary.
data_id = query.data_id.dataId

butler = factory.create_butler()
ref = butler.find_dataset(
dataset_type, data_id=unpack_dataId(butler, query.data_id), collections=collection_query
)
ref = butler.find_dataset(dataset_type, None, collections=collection_query, **data_id)
return ref.to_simple() if ref else None
9 changes: 9 additions & 0 deletions tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,15 @@ def test_find_dataset(self):
ref2 = self.butler.get_dataset(ref.id)
self.assertEqual(ref2, ref)

# Use detector name to find it.
ref3 = self.butler.find_dataset(
ref.datasetType,
collections="imported_g",
instrument="Cam1",
full_name="Aa",
)
self.assertEqual(ref2, ref3)

# Unknown dataset should not fail.
self.assertIsNone(self.butler.get_dataset(uuid.uuid4()))

Expand Down
2 changes: 1 addition & 1 deletion tests/test_simpleButler.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ def testButlerGet(self):
# Find the DatasetRef for a flat
coll = "imported_g"
flat2g = butler.find_dataset(
"flat", instrument="Cam1", detector=2, physical_filter="Cam1-G", collections=coll
"flat", instrument="Cam1", full_name="Ab", physical_filter="Cam1-G", collections=coll
)

# Create a numpy integer to check that works fine
Expand Down

0 comments on commit faa1b00

Please sign in to comment.