|
1 | 1 | # mypy: disable-error-code="unused-ignore" |
2 | 2 | """Data classes for MAG L1D processing.""" |
3 | 3 |
|
| 4 | +import logging |
4 | 5 | from dataclasses import InitVar, dataclass |
5 | 6 |
|
6 | 7 | import numpy as np |
|
14 | 15 | from imap_processing.mag.l2.mag_l2_data import MagL2L1dBase, ValidFrames |
15 | 16 | from imap_processing.spice import spin |
16 | 17 | from imap_processing.spice.geometry import frame_transform |
17 | | -from imap_processing.spice.time import ttj2000ns_to_met |
| 18 | +from imap_processing.spice.time import ttj2000ns_to_et, ttj2000ns_to_met |
| 19 | + |
| 20 | +logger = logging.getLogger(__name__) |
18 | 21 |
|
19 | 22 |
|
20 | 23 | @dataclass |
@@ -166,6 +169,9 @@ def __post_init__(self, day: np.datetime64) -> None: |
166 | 169 | The day we are processing, in np.datetime64[D] format. This is used to |
167 | 170 | truncate the data to exactly 24 hours. |
168 | 171 | """ |
| 172 | + # The main data frame is MAGO, even though we have MAGI data included. |
| 173 | + self.frame = ValidFrames.MAGO |
| 174 | + |
169 | 175 | # set the magnitude before truncating |
170 | 176 | self.magnitude = np.zeros(self.vectors.shape[0], dtype=np.float64) # type: ignore[has-type] |
171 | 177 | self.truncate_to_24h(day) |
@@ -272,15 +278,42 @@ def rotate_frame(self, end_frame: ValidFrames) -> None: |
272 | 278 | end_frame : ValidFrames |
273 | 279 | The frame to rotate to. Should be one of the ValidFrames enum. |
274 | 280 | """ |
| 281 | + # Self.frame should refer to the main data in self.vectors, which is MAGO |
| 282 | + # data. For most frames, MAGO and MAGI are in the same frame, except the |
| 283 | + # instrument reference frame. |
| 284 | + if ValidFrames.MAGI in (self.frame, end_frame): |
| 285 | + raise ValueError( |
| 286 | + "MAGL1d.frame should never be equal to MAGI frame. If the " |
| 287 | + "data is in the instrument frame, use MAGO." |
| 288 | + ) |
| 289 | + |
275 | 290 | start_frame = self.frame |
276 | | - super().rotate_frame(end_frame) |
| 291 | + |
| 292 | + if self.epoch_et is None: |
| 293 | + self.epoch_et: np.ndarray = ttj2000ns_to_et(self.epoch) |
| 294 | + self.magi_epoch_et: np.ndarray = ttj2000ns_to_et(self.magi_epoch) |
| 295 | + |
| 296 | + self.vectors = frame_transform( |
| 297 | + self.epoch_et, |
| 298 | + self.vectors, |
| 299 | + from_frame=start_frame.value, |
| 300 | + to_frame=end_frame.value, |
| 301 | + ) |
| 302 | + |
| 303 | + # If we were in MAGO frame, we need to rotate MAGI vectors from MAGI to |
| 304 | + # end_frame |
| 305 | + if start_frame == ValidFrames.MAGO: |
| 306 | + start_frame = ValidFrames.MAGI |
| 307 | + |
277 | 308 | self.magi_vectors = frame_transform( |
278 | | - self.magi_epoch, |
| 309 | + self.magi_epoch_et, |
279 | 310 | self.magi_vectors, |
280 | 311 | from_frame=start_frame.value, |
281 | 312 | to_frame=end_frame.value, |
282 | 313 | ) |
283 | 314 |
|
| 315 | + self.frame = end_frame |
| 316 | + |
284 | 317 | def _calibrate_and_offset_vectors( |
285 | 318 | self, |
286 | 319 | mago_calibration: np.ndarray, |
|
0 commit comments