From b2153b2de76a0b85659cf57344f5ebf1f600e220 Mon Sep 17 00:00:00 2001 From: Maxine Hartnett Date: Tue, 2 Apr 2024 09:03:32 -0600 Subject: [PATCH] Updating from PR comments --- imap_processing/mag/l0/mag_l0_data.py | 18 ++++++++---------- imap_processing/mag/l1a/mag_l1a_data.py | 14 ++++---------- imap_processing/tests/mag/test_mag_l1a.py | 2 +- 3 files changed, 13 insertions(+), 21 deletions(-) diff --git a/imap_processing/mag/l0/mag_l0_data.py b/imap_processing/mag/l0/mag_l0_data.py index 63f7c6db3..5e9f5d34c 100644 --- a/imap_processing/mag/l0/mag_l0_data.py +++ b/imap_processing/mag/l0/mag_l0_data.py @@ -1,4 +1,5 @@ """Dataclasses for Level 0 MAG data.""" +from __future__ import annotations from dataclasses import dataclass from enum import IntEnum @@ -92,7 +93,7 @@ class MagL0: PRI_FNTM: int SEC_COARSETM: int SEC_FNTM: int - VECTORS: np.ndarray + VECTORS: np.ndarray | str def __post_init__(self): """Convert Vectors attribute from string to bytearray if needed. @@ -100,15 +101,12 @@ def __post_init__(self): Also convert encoded "VECSEC" (vectors per second) into proper vectors per second values """ - if isinstance(self.VECTORS, str): - # Convert string output from space_packet_parser to bytearray - self.VECTORS = np.frombuffer( - int(self.VECTORS, 2).to_bytes(len(self.VECTORS) // 8, "big"), - dtype=np.dtype(">b"), - ) - - if isinstance(self.VECTORS, bytearray): - self.VECTORS = np.array(self.VECTORS, dtype=np.dtype(">b")) + # Convert string output from space_packet_parser to numpy array of + # big-endian bytes + self.VECTORS = np.frombuffer( + int(self.VECTORS, 2).to_bytes(len(self.VECTORS) // 8, "big"), + dtype=np.dtype(">b"), + ) # Remove buffer from end of vectors if len(self.VECTORS) % 2: diff --git a/imap_processing/mag/l1a/mag_l1a_data.py b/imap_processing/mag/l1a/mag_l1a_data.py index 93ca5401d..3ee2addaf 100644 --- a/imap_processing/mag/l1a/mag_l1a_data.py +++ b/imap_processing/mag/l1a/mag_l1a_data.py @@ -25,7 +25,7 @@ def __add__(self, seconds: float): Parameters ---------- - seconds : int + seconds : float Number of seconds to add Returns @@ -119,16 +119,10 @@ def __post_init__(self): This replaces self.vectors with a list of Vector objects. """ sample_time_interval = 1 / self.vectors_per_second - previous_time = self.start_time + current_time = self.start_time for index, vector in enumerate(self.vectors): - if index == 0: - new_vector = Vector(vector, self.start_time) - else: - new_vector = Vector(vector, previous_time + sample_time_interval) - - previous_time = new_vector.timestamp - - self.vectors[index] = new_vector + self.vectors[index] = Vector(vector, current_time) + current_time = self.vectors[index].timestamp + sample_time_interval @staticmethod def process_vector_data( diff --git a/imap_processing/tests/mag/test_mag_l1a.py b/imap_processing/tests/mag/test_mag_l1a.py index 300f80b4b..42826c26a 100644 --- a/imap_processing/tests/mag/test_mag_l1a.py +++ b/imap_processing/tests/mag/test_mag_l1a.py @@ -17,7 +17,7 @@ def test_compare_validation_data(): current_directory = Path(__file__).parent test_file = current_directory / "mag_l1_test_data.pkts" # Test file contains only normal packets - l0 = decom_packets(str(test_file)) + l0 = decom_packets(test_file) l1 = process_packets(l0["norm"]) l1_mago = l1["mago"]