Skip to content

Commit

Permalink
Fixing error with update from MAG team
Browse files Browse the repository at this point in the history
  • Loading branch information
maxinelasp committed Sep 3, 2024
1 parent 7bb2cc4 commit 4827866
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
18 changes: 9 additions & 9 deletions imap_processing/mag/l1a/mag_l1a_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -708,15 +708,15 @@ def process_compressed_vectors( # noqa: PLR0912, PLR0915
secondary_vectors[vector_index] = decoded_vector
vector_index += 1

# TODO: should the range vectors include the first vector?
if has_range_data_section:
primary_vectors = MagL1a.process_range_data_section(
bit_array[end_vector : end_vector + primary_count * 2], primary_vectors
bit_array[end_vector : end_vector + (primary_count - 1) * 2],
primary_vectors,
)
secondary_vectors = MagL1a.process_range_data_section(
bit_array[
end_vector + primary_count * 2 : end_vector
+ (primary_count + secondary_count) * 2
end_vector + (primary_count - 1) * 2 : end_vector
+ (primary_count + secondary_count - 2) * 2
],
secondary_vectors,
)
Expand Down Expand Up @@ -748,17 +748,17 @@ def process_range_data_section(
Updated array of vectors, identical to vectors with the range values
updated from range_data.
"""
if len(range_data) != len(vectors) * 2:
if len(range_data) != (len(vectors) - 1) * 2:
raise ValueError(
"Incorrect length for range_data, there should be two bits per vector."
"Incorrect length for range_data, there should be two bits per vector, "
"excluding the first."
)

updated_vectors: np.ndarray = np.copy(vectors)
range_str = "".join([str(i) for i in range_data])
for i in range(len(vectors)):
for i in range(len(vectors) - 1):
range_int = int(range_str[i * 2 : i * 2 + 2], 2)
updated_vectors[i][3] = range_int

updated_vectors[i + 1][3] = range_int
return updated_vectors

@staticmethod
Expand Down
9 changes: 5 additions & 4 deletions imap_processing/tests/mag/test_mag_l1a.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,12 +360,13 @@ def test_compressed_vector_data(expected_vectors):
assert np.array_equal(secondary, secondary_expected)

# range data has 2 bits per vector, primary and then secondary in sequence.
range_primary = "00000000000000000101101011111111"
# It excludes the first vector, making the length (primary_count - 1) * 2
range_primary = "000000000000000101101011111111"

expected_range_primary = [0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 3, 3]
expected_range_primary = [3, 0, 0, 0, 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 3, 3]

range_secondary = "01000000000000000101101011111101"
expected_range_secondary = [1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 3, 1]
range_secondary = "000000000000000101101011111101"
expected_range_secondary = [3, 0, 0, 0, 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 3, 1]
# 16 bit width with range section
headers = "01000010"
# TODO: if there is a number of vectors that is not a multiple of 8,
Expand Down

0 comments on commit 4827866

Please sign in to comment.