Coverage for python/lsst/daf/butler/_deferredDatasetHandle.py: 49%

33 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2022-10-28 09:59 +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/>. 

21 

22""" 

23Module containing classes used with deferring dataset loading 

24""" 

25from __future__ import annotations 

26 

27__all__ = ("DeferredDatasetHandle",) 

28 

29import dataclasses 

30from typing import TYPE_CHECKING, Any, Optional, Union 

31 

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, StorageClass 

35 

36 

37@dataclasses.dataclass(frozen=True) 

38class DeferredDatasetHandle: 

39 """Proxy class that provides deferred loading of datasets from a butler.""" 

40 

41 def get( 

42 self, 

43 *, 

44 component: Optional[str] = None, 

45 parameters: Optional[dict] = None, 

46 storageClass: str | StorageClass | None = None, 

47 **kwargs: dict, 

48 ) -> Any: 

49 """Retrieves the dataset pointed to by this handle 

50 

51 This handle may be used multiple times, possibly with different 

52 parameters. 

53 

54 Parameters 

55 ---------- 

56 component : `str` or None 

57 If the deferred object is a component dataset type, this parameter 

58 may specify the name of the component to use in the get operation. 

59 parameters : `dict` or None 

60 The parameters argument will be passed to the butler get method. 

61 It defaults to None. If the value is not None, this dict will 

62 be merged with the parameters dict used to construct the 

63 `DeferredDatasetHandle` class. 

64 storageClass : `StorageClass` or `str`, optional 

65 The storage class to be used to override the Python type 

66 returned by this method. By default the returned type matches 

67 the dataset type definition for this dataset or the storage 

68 class specified when this object was created. Specifying a 

69 read `StorageClass` can force a different type to be returned. 

70 This type must be compatible with the original type. 

71 **kwargs 

72 This argument is deprecated and only exists to support legacy 

73 gen2 butler code during migration. It is completely ignored 

74 and will be removed in the future. 

75 

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 

91 

92 ref = self.ref.makeComponentRef(component) if component is not None else self.ref 

93 return self.butler.getDirect(ref, parameters=mergedParameters, storageClass=storageClass) 

94 

95 @property 

96 def dataId(self) -> DataCoordinate: 

97 """The full data ID associated with the dataset 

98 (`DataCoordinate`). 

99 

100 Guaranteed to contain records. 

101 """ 

102 return self.ref.dataId 

103 

104 butler: LimitedButler 

105 """The butler that will be used to fetch the dataset (`LimitedButler`). 

106 """ 

107 

108 ref: DatasetRef 

109 """Reference to the dataset (`DatasetRef`). 

110 """ 

111 

112 parameters: Optional[dict] 

113 """Optional parameters that may be used to specify a subset of the dataset 

114 to be loaded (`dict` or `None`). 

115 """ 

116 

117 storageClass: Optional[Union[str, StorageClass]] = None 

118 """Optional storage class override that can be applied on ``get()``."""