Coverage for python/lsst/daf/butler/_deferredDatasetHandle.py: 52%
30 statements
« prev ^ index » next coverage.py v7.3.1, created at 2023-10-02 08:00 +0000
« prev ^ index » next coverage.py v7.3.1, created at 2023-10-02 08:00 +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 software is dual licensed under the GNU General Public License and also
10# under a 3-clause BSD license. Recipients may choose which of these licenses
11# to use; please see the files gpl-3.0.txt and/or bsd_license.txt,
12# respectively. If you choose the GPL option then the following text applies
13# (but note that there is still no warranty even if you opt for BSD instead):
14#
15# This program is free software: you can redistribute it and/or modify
16# it under the terms of the GNU General Public License as published by
17# the Free Software Foundation, either version 3 of the License, or
18# (at your option) any later version.
19#
20# This program is distributed in the hope that it will be useful,
21# but WITHOUT ANY WARRANTY; without even the implied warranty of
22# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23# GNU General Public License for more details.
24#
25# You should have received a copy of the GNU General Public License
26# along with this program. If not, see <http://www.gnu.org/licenses/>.
28"""Module containing classes used with deferring dataset loading.
29"""
30from __future__ import annotations
32__all__ = ("DeferredDatasetHandle",)
34import dataclasses
35from typing import TYPE_CHECKING, Any
37if TYPE_CHECKING:
38 from ._limited_butler import LimitedButler
39 from .core import DataCoordinate, DatasetRef, StorageClass
42@dataclasses.dataclass(frozen=True)
43class DeferredDatasetHandle:
44 """Proxy class that provides deferred loading of datasets from a butler."""
46 def get(
47 self,
48 *,
49 component: str | None = None,
50 parameters: dict | None = None,
51 storageClass: str | StorageClass | None = None,
52 ) -> Any:
53 """Retrieve the dataset pointed to by this handle.
55 This handle may be used multiple times, possibly with different
56 parameters.
58 Parameters
59 ----------
60 component : `str` or None
61 If the deferred object is a component dataset type, this parameter
62 may specify the name of the component to use in the get operation.
63 parameters : `dict` or None
64 The parameters argument will be passed to the butler get method.
65 It defaults to None. If the value is not None, this dict will
66 be merged with the parameters dict used to construct the
67 `DeferredDatasetHandle` class.
68 storageClass : `StorageClass` or `str`, optional
69 The storage class to be used to override the Python type
70 returned by this method. By default the returned type matches
71 the dataset type definition for this dataset or the storage
72 class specified when this object was created. Specifying a
73 read `StorageClass` can force a different type to be returned.
74 This type must be compatible with the original type.
76 Returns
77 -------
78 return : `Object`
79 The dataset pointed to by this handle
80 """
81 if self.parameters is not None:
82 mergedParameters = self.parameters.copy()
83 if parameters is not None:
84 mergedParameters.update(parameters)
85 elif parameters is not None:
86 mergedParameters = parameters
87 else:
88 mergedParameters = {}
89 if storageClass is None:
90 storageClass = self.storageClass
92 ref = self.ref.makeComponentRef(component) if component is not None else self.ref
93 return self.butler.get(ref, parameters=mergedParameters, storageClass=storageClass)
95 @property
96 def dataId(self) -> DataCoordinate:
97 """The full data ID associated with the dataset
98 (`DataCoordinate`).
100 Guaranteed to contain records.
101 """
102 return self.ref.dataId
104 butler: LimitedButler
105 """The butler that will be used to fetch the dataset (`LimitedButler`).
106 """
108 ref: DatasetRef
109 """Reference to the dataset (`DatasetRef`).
110 """
112 parameters: dict | None
113 """Optional parameters that may be used to specify a subset of the dataset
114 to be loaded (`dict` or `None`).
115 """
117 storageClass: str | StorageClass | None = None
118 """Optional storage class override that can be applied on ``get()``."""