Coverage for python/lsst/daf/butler/_deferredDatasetHandle.py: 51%
29 statements
« prev ^ index » next coverage.py v6.4.4, created at 2022-08-26 09:24 +0000
« prev ^ index » next coverage.py v6.4.4, created at 2022-08-26 09:24 +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
32if TYPE_CHECKING: 32 ↛ 33line 32 didn't jump to line 33, because the condition on line 32 was never true
33 from ._limited_butler import LimitedButler
34 from .core import DataCoordinate, DatasetRef
37@dataclasses.dataclass(frozen=True)
38class DeferredDatasetHandle:
39 """Proxy class that provides deferred loading of datasets from a butler."""
41 def get(
42 self, *, component: Optional[str] = None, parameters: Optional[dict] = None, **kwargs: dict
43 ) -> Any:
44 """Retrieves the dataset pointed to by this handle
46 This handle may be used multiple times, possibly with different
47 parameters.
49 Parameters
50 ----------
51 component : `str` or None
52 If the deferred object is a component dataset type, this parameter
53 may specify the name of the component to use in the get operation.
54 parameters : `dict` or None
55 The parameters argument will be passed to the butler get method.
56 It defaults to None. If the value is not None, this dict will
57 be merged with the parameters dict used to construct the
58 `DeferredDatasetHandle` class.
59 **kwargs
60 This argument is deprecated and only exists to support legacy
61 gen2 butler code during migration. It is completely ignored
62 and will be removed in the future.
64 Returns
65 -------
66 return : `Object`
67 The dataset pointed to by this handle
68 """
69 if self.parameters is not None:
70 mergedParameters = self.parameters.copy()
71 if parameters is not None:
72 mergedParameters.update(parameters)
73 elif parameters is not None:
74 mergedParameters = parameters
75 else:
76 mergedParameters = {}
78 ref = self.ref.makeComponentRef(component) if component is not None else self.ref
79 return self.butler.getDirect(ref, parameters=mergedParameters)
81 @property
82 def dataId(self) -> DataCoordinate:
83 """The full data ID associated with the dataset
84 (`DataCoordinate`).
86 Guaranteed to contain records.
87 """
88 return self.ref.dataId
90 butler: LimitedButler
91 """The butler that will be used to fetch the dataset (`LimitedButler`).
92 """
94 ref: DatasetRef
95 """Reference to the dataset (`DatasetRef`).
96 """
98 parameters: Optional[dict]
99 """Optional parameters that may be used to specify a subset of the dataset
100 to be loaded (`dict` or `None`).
101 """