Skip to content

Commit ca3b498

Browse files
authored
Fix data array shapes for CoDICE-Lo products (IMAP-Science-Operations-Center#1234)
* Fixed indexing issue in decompression table lookup * Fixed order of data array shaping
1 parent 868ea28 commit ca3b498

File tree

5 files changed

+32
-28
lines changed

5 files changed

+32
-28
lines changed

imap_processing/codice/codice_l1a.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,12 @@ def define_coordinates(self) -> None:
129129
for name in self.config["coords"]:
130130
if name == "epoch":
131131
values = self.dataset.epoch.data
132+
elif name == "esa_step":
133+
values = np.arange(self.config["num_energy_steps"])
132134
elif name == "inst_az":
133135
values = np.arange(self.config["num_positions"])
134136
elif name == "spin_sector":
135137
values = np.arange(self.config["num_spin_sectors"])
136-
elif name == "esa_step":
137-
values = np.arange(self.config["num_energy_steps"])
138138
else:
139139
# TODO: Need to implement other types of coords
140140
continue
@@ -170,8 +170,8 @@ def define_data_variables(self) -> xr.Dataset:
170170
# Stack the data so that it is easier to reshape and iterate over
171171
all_data = np.stack(self.data)
172172

173-
# The dimension of all data is (epoch, num_counters, num_positions,
174-
# num_spin_sectors, num_energy_steps) (or may be slightly different
173+
# The dimension of all data is (epoch, num_counters, num_energy_steps,
174+
# num_positions, num_spin_sectors) (or may be slightly different
175175
# depending on the data product). In any case, iterate over the
176176
# num_counters dimension to isolate the data for each counter so
177177
# that it can be placed in a CDF data variable.
@@ -353,9 +353,9 @@ def reshape_data(self) -> None:
353353
).reshape(
354354
(
355355
self.config["num_counters"],
356+
self.config["num_energy_steps"],
356357
self.config["num_positions"],
357358
self.config["num_spin_sectors"],
358-
self.config["num_energy_steps"],
359359
)
360360
)
361361
self.data.append(reshaped_packet_data)

imap_processing/codice/constants.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@
184184
"energy_label",
185185
], # TODO: These will likely change
186186
"dataset_name": "imap_codice_l1a_lo-counters-aggregated",
187-
"dims": ["epoch", "inst_az", "spin_sector", "esa_step"],
187+
"dims": ["epoch", "esa_step", "inst_az", "spin_sector"],
188188
"instrument": "lo",
189189
"num_counters": 1,
190190
"num_energy_steps": 128,
@@ -205,7 +205,7 @@
205205
"energy_label",
206206
], # TODO: These will likely change
207207
"dataset_name": "imap_codice_l1a_lo-counters-singles",
208-
"dims": ["epoch", "inst_az", "spin_sector", "esa_step"],
208+
"dims": ["epoch", "esa_step", "inst_az", "spin_sector"],
209209
"instrument": "lo",
210210
"num_counters": 1,
211211
"num_energy_steps": 128,
@@ -225,9 +225,9 @@
225225
"variable_names": LO_INST_COUNTS_SINGLES_VARIABLE_NAMES,
226226
},
227227
CODICEAPID.COD_LO_SW_ANGULAR_COUNTS: {
228-
"coords": ["epoch", "inst_az", "spin_sector", "esa_step", "energy_label"],
228+
"coords": ["epoch", "energy_label", "esa_step", "inst_az", "spin_sector"],
229229
"dataset_name": "imap_codice_l1a_lo-sw-angular",
230-
"dims": ["epoch", "inst_az", "spin_sector", "esa_step"],
230+
"dims": ["epoch", "esa_step", "inst_az", "spin_sector"],
231231
"instrument": "lo",
232232
"num_counters": 4,
233233
"num_energy_steps": 128,
@@ -248,7 +248,7 @@
248248
CODICEAPID.COD_LO_NSW_ANGULAR_COUNTS: {
249249
"coords": ["epoch", "inst_az", "spin_sector", "esa_step", "energy_label"],
250250
"dataset_name": "imap_codice_l1a_lo-nsw-angular",
251-
"dims": ["epoch", "inst_az", "spin_sector", "esa_step"],
251+
"dims": ["epoch", "esa_step", "inst_az", "spin_sector"],
252252
"instrument": "lo",
253253
"num_counters": 1,
254254
"num_energy_steps": 128,
@@ -269,7 +269,7 @@
269269
CODICEAPID.COD_LO_SW_PRIORITY_COUNTS: {
270270
"coords": ["epoch", "inst_az", "spin_sector", "esa_step", "energy_label"],
271271
"dataset_name": "imap_codice_l1a_lo-sw-priority",
272-
"dims": ["epoch", "inst_az", "spin_sector", "esa_step"],
272+
"dims": ["epoch", "esa_step", "inst_az", "spin_sector"],
273273
"instrument": "lo",
274274
"num_counters": 5,
275275
"num_energy_steps": 128,
@@ -290,7 +290,7 @@
290290
CODICEAPID.COD_LO_NSW_PRIORITY_COUNTS: {
291291
"coords": ["epoch", "inst_az", "spin_sector", "esa_step", "energy_label"],
292292
"dataset_name": "imap_codice_l1a_lo-nsw-priority",
293-
"dims": ["epoch", "inst_az", "spin_sector", "esa_step"],
293+
"dims": ["epoch", "esa_step", "inst_az", "spin_sector"],
294294
"instrument": "lo",
295295
"num_counters": 2,
296296
"num_energy_steps": 128,
@@ -311,7 +311,7 @@
311311
CODICEAPID.COD_LO_SW_SPECIES_COUNTS: {
312312
"coords": ["epoch", "inst_az", "spin_sector", "esa_step", "energy_label"],
313313
"dataset_name": "imap_codice_l1a_lo-sw-species",
314-
"dims": ["epoch", "inst_az", "spin_sector", "esa_step"],
314+
"dims": ["epoch", "esa_step", "inst_az", "spin_sector"],
315315
"instrument": "lo",
316316
"num_counters": 16,
317317
"num_energy_steps": 128,
@@ -332,7 +332,7 @@
332332
CODICEAPID.COD_LO_NSW_SPECIES_COUNTS: {
333333
"coords": ["epoch", "inst_az", "spin_sector", "esa_step", "energy_label"],
334334
"dataset_name": "imap_codice_l1a_lo-nsw-species",
335-
"dims": ["epoch", "inst_az", "spin_sector", "esa_step"],
335+
"dims": ["epoch", "esa_step", "inst_az", "spin_sector"],
336336
"instrument": "lo",
337337
"num_counters": 8,
338338
"num_energy_steps": 128,

imap_processing/codice/decompress.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ def _apply_lossy_a(compressed_bytes: bytes) -> list[int]:
5050
The 24- or 32-bit decompressed values.
5151
"""
5252
compressed_values = list(compressed_bytes)
53-
decompressed_values = [LOSSY_A_TABLE[item] for item in compressed_values]
53+
decompressed_values = [
54+
LOSSY_A_TABLE[item - 1] if item > 0 else 0 for item in compressed_values
55+
]
5456
return decompressed_values
5557

5658

@@ -71,7 +73,9 @@ def _apply_lossy_b(compressed_bytes: bytes) -> list[int]:
7173
The 24- or 32-bit decompressed values.
7274
"""
7375
compressed_values = list(compressed_bytes)
74-
decompressed_values = [LOSSY_B_TABLE[item] for item in compressed_values]
76+
decompressed_values = [
77+
LOSSY_B_TABLE[item - 1] if item > 0 else 0 for item in compressed_values
78+
]
7579
return decompressed_values
7680

7781

imap_processing/tests/codice/test_codice_l1a.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@
1818
(), # hi-ialirt # TODO: Need to implement
1919
(), # lo-ialirt # TODO: Need to implement
2020
(31778,), # hskp
21-
(77, 6, 6, 128), # lo-counters-aggregated
22-
(77, 24, 6, 128), # lo-counters-singles
23-
(77, 1, 12, 128), # lo-sw-priority
24-
(77, 1, 12, 128), # lo-nsw-priority
25-
(77, 1, 1, 128), # lo-sw-species
26-
(77, 1, 1, 128), # lo-nsw-species
27-
(77, 5, 12, 128), # lo-sw-angular
28-
(77, 19, 12, 128), # lo-nsw-angular
21+
(77, 128, 6, 6), # lo-counters-aggregated
22+
(77, 128, 24, 6), # lo-counters-singles
23+
(77, 128, 1, 12), # lo-sw-priority
24+
(77, 128, 1, 12), # lo-nsw-priority
25+
(77, 128, 1, 1), # lo-sw-species
26+
(77, 128, 1, 1), # lo-nsw-species
27+
(77, 128, 5, 12), # lo-sw-angular
28+
(77, 128, 19, 12), # lo-nsw-angular
2929
(77, 1, 6, 1), # hi-counters-aggregated
3030
(77, 1, 12, 1), # hi-counters-singles
3131
(77, 15, 4, 1), # hi-omni

imap_processing/tests/codice/test_decompress.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
# LZMA_EXAMPLE = "".join(format(byte, "08b") for byte in lzma_bytes)
1414
TEST_DATA = [
1515
(b"\xea", CoDICECompression.NO_COMPRESSION, [234]),
16-
(b"\xea", CoDICECompression.LOSSY_A, [221184]),
17-
(b"\xea", CoDICECompression.LOSSY_B, [1441792]),
16+
(b"\xea", CoDICECompression.LOSSY_A, [212992]),
17+
(b"\xea", CoDICECompression.LOSSY_B, [1310720]),
1818
(lzma_bytes, CoDICECompression.LOSSLESS, [234]),
19-
(lzma_bytes, CoDICECompression.LOSSY_A_LOSSLESS, [221184]),
20-
(lzma_bytes, CoDICECompression.LOSSY_B_LOSSLESS, [1441792]),
19+
(lzma_bytes, CoDICECompression.LOSSY_A_LOSSLESS, [212992]),
20+
(lzma_bytes, CoDICECompression.LOSSY_B_LOSSLESS, [1310720]),
2121
]
2222

2323

0 commit comments

Comments
 (0)