Coverage for python/lsst/daf/butler/_deferredDatasetHandle.py: 50%
30 statements
« prev ^ index » next coverage.py v7.2.5, created at 2023-05-02 09:50 +0000
« prev ^ index » next coverage.py v7.2.5, created at 2023-05-02 09:50 +0000
1# This file is part of daf_butler.
2#
3# Developed for the LSST Data Management System.
4# This product includes software developed by the LSST Project
5# (http://www.lsst.org).
6# See the COPYRIGHT file at the top-level directory of this distribution
7# for details of code ownership.
8#
9# This program is free software: you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation, either version 3 of the License, or
12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program. If not, see <http://www.gnu.org/licenses/>.
22"""
23Module containing classes used with deferring dataset loading
24"""
25from __future__ import annotations
27__all__ = ("DeferredDatasetHandle",)
29import dataclasses
30from typing import TYPE_CHECKING, Any, Optional, Union
32if TYPE_CHECKING:
33 from ._limited_butler import LimitedButler
34 from .core import DataCoordinate, DatasetRef, StorageClass
37@dataclasses.dataclass(frozen=True)
38class DeferredDatasetHandle:
39 """Proxy class that provides deferred loading of datasets from a butler."""
41 def get(
42 self,
43 *,
44 component: Optional[str] = None,
45 parameters: Optional[dict] = None,
46 storageClass: str | StorageClass | None = None,
47 ) -> Any:
48 """Retrieves the dataset pointed to by this handle
50 This handle may be used multiple times, possibly with different
51 parameters.
53 Parameters
54 ----------
55 component : `str` or None
56 If the deferred object is a component dataset type, this parameter
57 may specify the name of the component to use in the get operation.
58 parameters : `dict` or None
59 The parameters argument will be passed to the butler get method.
60 It defaults to None. If the value is not None, this dict will
61 be merged with the parameters dict used to construct the
62 `DeferredDatasetHandle` class.
63 storageClass : `StorageClass` or `str`, optional
64 The storage class to be used to override the Python type
65 returned by this method. By default the returned type matches
66 the dataset type definition for this dataset or the storage
67 class specified when this object was created. Specifying a
68 read `StorageClass` can force a different type to be returned.
69 This type must be compatible with the original type.
71 Returns
72 -------
73 return : `Object`
74 The dataset pointed to by this handle
75 """
76 if self.parameters is not None:
77 mergedParameters = self.parameters.copy()
78 if parameters is not None:
79 mergedParameters.update(parameters)
80 elif parameters is not None:
81 mergedParameters = parameters
82 else:
83 mergedParameters = {}
84 if storageClass is None:
85 storageClass = self.storageClass
87 ref = self.ref.makeComponentRef(component) if component is not None else self.ref
88 return self.butler.get(ref, parameters=mergedParameters, storageClass=storageClass)
90 @property
91 def dataId(self) -> DataCoordinate:
92 """The full data ID associated with the dataset
93 (`DataCoordinate`).
95 Guaranteed to contain records.
96 """
97 return self.ref.dataId
99 butler: LimitedButler
100 """The butler that will be used to fetch the dataset (`LimitedButler`).
101 """
103 ref: DatasetRef
104 """Reference to the dataset (`DatasetRef`).
105 """
107 parameters: Optional[dict]
108 """Optional parameters that may be used to specify a subset of the dataset
109 to be loaded (`dict` or `None`).
110 """
112 storageClass: Optional[Union[str, StorageClass]] = None
113 """Optional storage class override that can be applied on ``get()``."""