Coverage for python/lsst/daf/butler/_deferredDatasetHandle.py: 50%
30 statements
« prev ^ index » next coverage.py v7.2.7, created at 2023-07-12 10:56 -0700
« prev ^ index » next coverage.py v7.2.7, created at 2023-07-12 10:56 -0700
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"""Module containing classes used with deferring dataset loading.
23"""
24from __future__ import annotations
26__all__ = ("DeferredDatasetHandle",)
28import dataclasses
29from typing import TYPE_CHECKING, Any
31if TYPE_CHECKING:
32 from ._limited_butler import LimitedButler
33 from .core import DataCoordinate, DatasetRef, StorageClass
36@dataclasses.dataclass(frozen=True)
37class DeferredDatasetHandle:
38 """Proxy class that provides deferred loading of datasets from a butler."""
40 def get(
41 self,
42 *,
43 component: str | None = None,
44 parameters: dict | None = None,
45 storageClass: str | StorageClass | None = None,
46 ) -> Any:
47 """Retrieve the dataset pointed to by this handle.
49 This handle may be used multiple times, possibly with different
50 parameters.
52 Parameters
53 ----------
54 component : `str` or None
55 If the deferred object is a component dataset type, this parameter
56 may specify the name of the component to use in the get operation.
57 parameters : `dict` or None
58 The parameters argument will be passed to the butler get method.
59 It defaults to None. If the value is not None, this dict will
60 be merged with the parameters dict used to construct the
61 `DeferredDatasetHandle` class.
62 storageClass : `StorageClass` or `str`, optional
63 The storage class to be used to override the Python type
64 returned by this method. By default the returned type matches
65 the dataset type definition for this dataset or the storage
66 class specified when this object was created. Specifying a
67 read `StorageClass` can force a different type to be returned.
68 This type must be compatible with the original type.
70 Returns
71 -------
72 return : `Object`
73 The dataset pointed to by this handle
74 """
75 if self.parameters is not None:
76 mergedParameters = self.parameters.copy()
77 if parameters is not None:
78 mergedParameters.update(parameters)
79 elif parameters is not None:
80 mergedParameters = parameters
81 else:
82 mergedParameters = {}
83 if storageClass is None:
84 storageClass = self.storageClass
86 ref = self.ref.makeComponentRef(component) if component is not None else self.ref
87 return self.butler.get(ref, parameters=mergedParameters, storageClass=storageClass)
89 @property
90 def dataId(self) -> DataCoordinate:
91 """The full data ID associated with the dataset
92 (`DataCoordinate`).
94 Guaranteed to contain records.
95 """
96 return self.ref.dataId
98 butler: LimitedButler
99 """The butler that will be used to fetch the dataset (`LimitedButler`).
100 """
102 ref: DatasetRef
103 """Reference to the dataset (`DatasetRef`).
104 """
106 parameters: dict | None
107 """Optional parameters that may be used to specify a subset of the dataset
108 to be loaded (`dict` or `None`).
109 """
111 storageClass: str | StorageClass | None = None
112 """Optional storage class override that can be applied on ``get()``."""