diff --git a/imap_processing/mag/l1a/mag_l1a_data.py b/imap_processing/mag/l1a/mag_l1a_data.py index d6b593b48..33a2fafb0 100644 --- a/imap_processing/mag/l1a/mag_l1a_data.py +++ b/imap_processing/mag/l1a/mag_l1a_data.py @@ -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, ) @@ -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 diff --git a/imap_processing/tests/mag/test_mag_l1a.py b/imap_processing/tests/mag/test_mag_l1a.py index fcb54079e..42e8288f0 100644 --- a/imap_processing/tests/mag/test_mag_l1a.py +++ b/imap_processing/tests/mag/test_mag_l1a.py @@ -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,