Skip to content

Commit

Permalink
Updating from PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
maxinelasp committed Apr 3, 2024
1 parent d64c974 commit b2153b2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 21 deletions.
18 changes: 8 additions & 10 deletions imap_processing/mag/l0/mag_l0_data.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Dataclasses for Level 0 MAG data."""
from __future__ import annotations

from dataclasses import dataclass
from enum import IntEnum
Expand Down Expand Up @@ -92,23 +93,20 @@ 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.
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:
Expand Down
14 changes: 4 additions & 10 deletions imap_processing/mag/l1a/mag_l1a_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def __add__(self, seconds: float):
Parameters
----------
seconds : int
seconds : float
Number of seconds to add
Returns
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion imap_processing/tests/mag/test_mag_l1a.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down

0 comments on commit b2153b2

Please sign in to comment.