Coverage for python / lsst / dax / apdb / recordIds.py: 70%

63 statements  

« prev     ^ index     » next       coverage.py v7.13.1, created at 2026-01-22 02:00 -0800

1# This file is part of dax_apdb. 

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 

22from __future__ import annotations 

23 

24__all__ = ["DiaForcedSourceId", "DiaObjectId", "DiaSourceId"] 

25 

26from dataclasses import dataclass 

27from typing import Any 

28 

29 

30@dataclass(kw_only=True, slots=True) 

31class DiaObjectId: 

32 """Collection of data items identifying DIAObject records. 

33 

34 DIAObject primary key is ``diaObjectId``, in Cassandra the table is 

35 partitioned by spatial coordinates (``ra`` and ``dec``). 

36 """ 

37 

38 diaObjectId: int 

39 """ID of DIAObject record.""" 

40 

41 ra: float 

42 """DIAObject ra, in degrees. Not required to be exact, but needs to be 

43 close to the value in database record. 

44 """ 

45 

46 dec: float 

47 """DIAObject dec, in degrees. Not required to be exact, but needs to be 

48 close to the value in database record. 

49 """ 

50 

51 @classmethod 

52 def from_named_tuple(cls, named_tuple: Any) -> DiaObjectId: 

53 """Construct DiaObjectId from a named tuple. 

54 

55 Parameters 

56 ---------- 

57 named_tuple : 

58 Named tuple which includes the same attributes as this class, e.g. 

59 a tuple returned from ``pandas.DataFrame.itertuples()``. Any 

60 additional attributes are ignored. 

61 

62 Returns 

63 ------- 

64 object_id : `DiaObjectId` 

65 Instance of this class. 

66 """ 

67 return cls(diaObjectId=named_tuple.diaObjectId, ra=named_tuple.ra, dec=named_tuple.dec) 

68 

69 def __eq__(self, other: Any) -> bool: 

70 if isinstance(other, DiaObjectId): 

71 return self.diaObjectId == other.diaObjectId 

72 return NotImplemented 

73 

74 def __hash__(self) -> int: 

75 return hash(self.diaObjectId) 

76 

77 

78@dataclass(kw_only=True, slots=True) 

79class DiaSourceId: 

80 """Collection of data items identifying DIASource records. 

81 

82 DIASource primary key is ``diaSourceId``, in Cassandra the table is 

83 partitioned by both spatial coordinates (``ra`` and ``dec``) and time 

84 (``midpointMjdTai``). 

85 """ 

86 

87 diaSourceId: int 

88 """ID of DIASource record.""" 

89 

90 ra: float 

91 """DIASource ra, in degrees. Not required to be exact, but needs to be 

92 close to the value in database record. 

93 """ 

94 

95 dec: float 

96 """DIASource dec, in degrees. Not required to be exact, but needs to be 

97 close to the value in database record. 

98 """ 

99 

100 midpointMjdTai: float 

101 """DIASource midpointMjdTai, not required to be exact, but needs to be 

102 close to the value in database record. 

103 """ 

104 

105 @classmethod 

106 def from_named_tuple(cls, named_tuple: Any) -> DiaSourceId: 

107 """Construct DiaSourceId from a named tuple. 

108 

109 Parameters 

110 ---------- 

111 named_tuple : 

112 Named tuple which includes the same attributes as this class, e.g. 

113 a tuple returned from ``pandas.DataFrame.itertuples()``. Any 

114 additional attributes are ignored. 

115 

116 Returns 

117 ------- 

118 object_id : `DiaSourceId` 

119 Instance of this class. 

120 """ 

121 return cls( 

122 diaSourceId=named_tuple.diaSourceId, 

123 ra=named_tuple.ra, 

124 dec=named_tuple.dec, 

125 midpointMjdTai=named_tuple.midpointMjdTai, 

126 ) 

127 

128 def __eq__(self, other: Any) -> bool: 

129 if isinstance(other, DiaSourceId): 

130 return self.diaSourceId == other.diaSourceId 

131 return NotImplemented 

132 

133 def __hash__(self) -> int: 

134 return hash(self.diaSourceId) 

135 

136 

137@dataclass(kw_only=True, slots=True) 

138class DiaForcedSourceId: 

139 """Collection of data items identifying DIAForcedSource records. 

140 

141 DIAForcedSource primary key is ``(diaObjectId, visit, detector)``, in 

142 Cassandra the table is partitioned by both spatial coordinates (``ra`` and 

143 ``dec``) and time (``midpointMjdTai``). 

144 """ 

145 

146 diaObjectId: int 

147 """ID of parent DIAObject record.""" 

148 

149 visit: int 

150 """Visit ID.""" 

151 

152 detector: int 

153 """Detector ID.""" 

154 

155 ra: float 

156 """DIAForcedSource ra, in degrees. Not required to be exact, but needs to 

157 be close to the value in database record. 

158 """ 

159 

160 dec: float 

161 """DIAForcedSource dec, in degrees. Not required to be exact, but needs to 

162 be close to the value in database record. 

163 """ 

164 

165 midpointMjdTai: float 

166 """DIAForcedSource midpointMjdTai, not required to be exact, but needs to 

167 be close to the value in database record. 

168 """ 

169 

170 @classmethod 

171 def from_named_tuple(cls, named_tuple: Any) -> DiaForcedSourceId: 

172 """Construct DiaForcedSourceId from a named tuple. 

173 

174 Parameters 

175 ---------- 

176 named_tuple : 

177 Named tuple which includes the same attributes as this class, e.g. 

178 a tuple returned from ``pandas.DataFrame.itertuples()``. Any 

179 additional attributes are ignored. 

180 

181 Returns 

182 ------- 

183 object_id : `DiaForcedSourceId` 

184 Instance of this class. 

185 """ 

186 return cls( 

187 diaObjectId=named_tuple.diaObjectId, 

188 visit=named_tuple.visit, 

189 detector=named_tuple.detector, 

190 ra=named_tuple.ra, 

191 dec=named_tuple.dec, 

192 midpointMjdTai=named_tuple.midpointMjdTai, 

193 ) 

194 

195 def __eq__(self, other: Any) -> bool: 

196 if isinstance(other, DiaForcedSourceId): 

197 return ( 

198 self.diaObjectId == other.diaObjectId 

199 and self.visit == other.visit 

200 and self.detector == other.detector 

201 ) 

202 return NotImplemented 

203 

204 def __hash__(self) -> int: 

205 return hash((self.diaObjectId, self.visit, self.detector))