9
9
from adam_core .observers import Observers
10
10
from adam_core .time import Timestamp
11
11
12
+ from .photometry import Photometry
13
+
12
14
13
15
class ObserversWithStates (qv .Table ):
14
16
state_id = qv .Int64Column ()
@@ -26,19 +28,12 @@ class Observations(qv.Table):
26
28
assign a unique state ID. If not using this constructor, please ensure that the detections are sorted
27
29
by time and observatory code and that each unique combination of time and observatory code has a unique
28
30
state ID.
29
-
30
- Columns
31
- -------
32
- detections : `~adam_core.observations.detections.PointSourceDetections`
33
- A table of point source detections.
34
- observatory_code : `~qv.StringColumn`
35
- The observatory code for each detection.
36
- state_id : `~qv.Int64Column`
37
- The state ID for each detection.
38
31
"""
39
32
40
- detections = PointSourceDetections .as_column ()
41
- observatory_code = qv .StringColumn ()
33
+ id = qv .StringColumn ()
34
+ exposure_id = qv .StringColumn ()
35
+ coordinates = SphericalCoordinates .as_column ()
36
+ photometry = Photometry .as_column ()
42
37
state_id = qv .Int64Column ()
43
38
44
39
@classmethod
@@ -100,13 +95,15 @@ def from_detections_and_exposures(
100
95
)
101
96
102
97
# Extract the exposure IDs and the observatory codes from the exposures table
103
- exposure_obscodes = pa .table (
104
- [exposures .id , exposures .observatory_code ],
105
- names = ["exposure_id" , "observatory_code" ],
98
+ exposure_filters_obscodes = pa .table (
99
+ [exposures .id , exposures .filter , exposures . observatory_code ],
100
+ names = ["exposure_id" , "filter" , " observatory_code" ],
106
101
)
107
102
108
103
# Join the detection times and the exposure IDs so that each detection has an observatory code
109
- obscode_times = detections_flattened .join (exposure_obscodes , ["exposure_id" ])
104
+ obscode_times = detections_flattened .join (
105
+ exposure_filters_obscodes , ["exposure_id" ]
106
+ )
110
107
111
108
# Group the detections by the observatory code and the detection times and then grab the unique ones
112
109
unique_obscode_times = obscode_times .group_by (
@@ -139,23 +136,34 @@ def from_detections_and_exposures(
139
136
[("state_id" , "ascending" )]
140
137
)
141
138
139
+ sigmas = np .zeros ((len (detections_with_states ), 6 ))
140
+ sigmas [:, 1 ] = detections_with_states ["ra_sigma" ].to_numpy (zero_copy_only = False )
141
+ sigmas [:, 2 ] = detections_with_states ["dec_sigma" ].to_numpy (
142
+ zero_copy_only = False
143
+ )
144
+
142
145
return cls .from_kwargs (
143
- detections = PointSourceDetections .from_kwargs (
144
- id = detections_with_states ["id" ],
145
- exposure_id = detections_with_states ["exposure_id" ],
146
+ id = detections_with_states ["id" ],
147
+ exposure_id = detections_with_states ["exposure_id" ],
148
+ coordinates = SphericalCoordinates .from_kwargs (
149
+ lon = detections_with_states ["ra" ],
150
+ lat = detections_with_states ["dec" ],
146
151
time = Timestamp .from_kwargs (
147
152
days = detections_with_states ["days" ],
148
153
nanos = detections_with_states ["nanos" ],
149
154
scale = "utc" ,
150
155
),
151
- ra = detections_with_states ["ra" ],
152
- ra_sigma = detections_with_states ["ra_sigma" ],
153
- dec = detections_with_states ["dec" ],
154
- dec_sigma = detections_with_states ["dec_sigma" ],
156
+ covariance = CoordinateCovariances .from_sigmas (sigmas ),
157
+ origin = Origin .from_kwargs (
158
+ code = detections_with_states ["observatory_code" ]
159
+ ),
160
+ frame = "equatorial" ,
161
+ ),
162
+ photometry = Photometry .from_kwargs (
163
+ filter = detections_with_states ["filter" ],
155
164
mag = detections_with_states ["mag" ],
156
165
mag_sigma = detections_with_states ["mag_sigma" ],
157
166
),
158
- observatory_code = detections_with_states ["observatory_code" ],
159
167
state_id = detections_with_states ["state_id" ],
160
168
)
161
169
@@ -174,7 +182,7 @@ def get_observers(self) -> ObserversWithStates:
174
182
for code , observations_i in self .group_by_observatory_code ():
175
183
# Extract unique times and make sure they are sorted
176
184
# by time in ascending order
177
- unique_times = observations_i .detections .time .unique ()
185
+ unique_times = observations_i .coordinates .time .unique ()
178
186
unique_times = unique_times .sort_by (["days" , "nanos" ])
179
187
180
188
# States are defined by unique times and observatory codes and
@@ -194,28 +202,6 @@ def get_observers(self) -> ObserversWithStates:
194
202
observers = qv .concatenate (observers_with_states )
195
203
return observers .sort_by ("state_id" )
196
204
197
- def to_spherical_coordinates (self ) -> SphericalCoordinates :
198
- """
199
- Convert the observations to spherical coordinates which can be used
200
- to calculate residuals.
201
-
202
- Returns
203
- -------
204
- coordinates : `~adam_core.coordinates.spherical.SphericalCoordinates`
205
- The detections represented as spherical coordinates.
206
- """
207
- sigmas = np .zeros ((len (self ), 6 ))
208
- sigmas [:, 1 ] = self .detections .ra_sigma .to_numpy (zero_copy_only = False )
209
- sigmas [:, 2 ] = self .detections .dec_sigma .to_numpy (zero_copy_only = False )
210
- return SphericalCoordinates .from_kwargs (
211
- lon = self .detections .ra ,
212
- lat = self .detections .dec ,
213
- time = self .detections .time ,
214
- covariance = CoordinateCovariances .from_sigmas (sigmas ),
215
- origin = Origin .from_kwargs (code = self .observatory_code ),
216
- frame = "equatorial" ,
217
- )
218
-
219
205
def select_exposure (self , exposure_id : int ) -> "Observations" :
220
206
"""
221
207
Select observations from a single exposure.
@@ -230,7 +216,7 @@ def select_exposure(self, exposure_id: int) -> "Observations":
230
216
observations : `~Observations`
231
217
Observations from the specified exposure.
232
218
"""
233
- return self .apply_mask (pc .equal (self .detections . exposure_id , exposure_id ))
219
+ return self .apply_mask (pc .equal (self .exposure_id , exposure_id ))
234
220
235
221
def group_by_exposure (self ) -> Iterator [Tuple [str , "Observations" ]]:
236
222
"""
@@ -242,7 +228,7 @@ def group_by_exposure(self) -> Iterator[Tuple[str, "Observations"]]:
242
228
observations : Iterator[`~thor.observations.observations.Observations`]
243
229
Observations belonging to individual exposures.
244
230
"""
245
- exposure_ids = self .detections . exposure_id
231
+ exposure_ids = self .exposure_id
246
232
for exposure_id in exposure_ids .unique ().sort ():
247
233
yield exposure_id .as_py (), self .select_exposure (exposure_id )
248
234
@@ -260,7 +246,7 @@ def select_observatory_code(self, observatory_code) -> "Observations":
260
246
observations : `~Observations`
261
247
Observations from the specified observatory.
262
248
"""
263
- return self .apply_mask (pc .equal (self .observatory_code , observatory_code ))
249
+ return self .apply_mask (pc .equal (self .coordinates . origin . code , observatory_code ))
264
250
265
251
def group_by_observatory_code (self ) -> Iterator [Tuple [str , "Observations" ]]:
266
252
"""
@@ -271,7 +257,7 @@ def group_by_observatory_code(self) -> Iterator[Tuple[str, "Observations"]]:
271
257
observations : Iterator[`~thor.observations.observations.Observations`]
272
258
Observations belonging to individual observatories.
273
259
"""
274
- observatory_codes = self .observatory_code
260
+ observatory_codes = self .coordinates . origin . code
275
261
for observatory_code in observatory_codes .unique ().sort ():
276
262
yield observatory_code .as_py (), self .select_observatory_code (
277
263
observatory_code
0 commit comments