Skip to content

Commit

Permalink
Add LimitedButler.get_many_uris
Browse files Browse the repository at this point in the history
  • Loading branch information
timj committed Jul 7, 2023
1 parent fb703ab commit 75f3408
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 4 deletions.
41 changes: 40 additions & 1 deletion python/lsst/daf/butler/_limited_butler.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from deprecated.sphinx import deprecated

from ._deferredDatasetHandle import DeferredDatasetHandle
from .core import DatasetRef, Datastore, DimensionUniverse, StorageClass, StorageClassFactory
from .core import DatasetRef, DatasetRefURIs, Datastore, DimensionUniverse, StorageClass, StorageClassFactory

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -274,6 +274,45 @@ def getDeferred(
"""
return DeferredDatasetHandle(butler=self, ref=ref, parameters=parameters, storageClass=storageClass)

def get_many_uris(
self,
refs: Iterable[DatasetRef],
predict: bool = False,
allow_missing: bool = False,
) -> dict[DatasetRef, DatasetRefURIs]:
"""Return URIs associated with many datasets.
Parameters
----------
refs : iterable of `DatasetIdRef`
References to the required datasets.
predict : `bool`, optional
If the datastore does not know about a dataset, should it
return a predicted URI or not?
allow_missing : `bool`
If `False`, and `predict` is `False`, will raise if a `DatasetRef`
does not exist.
Returns
-------
URIs : `dict` of [`DatasetRef`, `DatasetRefUris`]
A dict of primary and component URIs, indexed by the passed-in
refs.
Raises
------
FileNotFoundError
A URI has been requested for a dataset that does not exist and
guessing is not allowed.
Notes
-----
In file-based datastores, get_many_uris does not check that the file is
present. It assumes that if datastore is aware of the file then it
actually exists.
"""
return self._datastore.getManyURIs(refs, predict=predict, allow_missing=allow_missing)

def stored(self, ref: DatasetRef) -> bool:
"""Indicate whether the dataset's artifacts are present in the
Datastore.
Expand Down
2 changes: 1 addition & 1 deletion python/lsst/daf/butler/core/datastore.py
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ def getManyURIs(
Notes
-----
In file-based datastores, getManuURIs does not check that the file is
In file-based datastores, getManyURIs does not check that the file is
really there, it's assuming it is if datastore is aware of the file
then it actually exists.
"""
Expand Down
5 changes: 3 additions & 2 deletions tests/test_butler.py
Original file line number Diff line number Diff line change
Expand Up @@ -1642,8 +1642,9 @@ def testPruneDatasets(self) -> None:
# Simulate execution butler setup by deleting the datastore
# record but keeping the file around and trusting.
butler._datastore.trustGetRequest = True
uri2 = butler.getURI(ref2)
uri3 = butler.getURI(ref3)
uris = butler.get_many_uris([ref2, ref3])
uri2 = uris[ref2].primaryURI
uri3 = uris[ref3].primaryURI
self.assertTrue(uri2.exists())
self.assertTrue(uri3.exists())

Expand Down

0 comments on commit 75f3408

Please sign in to comment.