Skip to content

Commit be80f46

Browse files
committed
MNT: Move IMAP Lo star sensor l1b back into l1a
1 parent ed1ee15 commit be80f46

File tree

4 files changed

+16
-51
lines changed

4 files changed

+16
-51
lines changed

imap_processing/lo/l0/lo_star_sensor.py

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
logger.setLevel(logging.INFO)
1515

1616

17-
def unpack_star_sensor(ds: xr.Dataset) -> xr.Dataset:
17+
def process_star_sensor(ds: xr.Dataset) -> xr.Dataset:
1818
"""
19-
Unpack Lo star sensor data.
19+
Process Lo star sensor data.
2020
2121
Parameters
2222
----------
@@ -34,37 +34,15 @@ def unpack_star_sensor(ds: xr.Dataset) -> xr.Dataset:
3434
buffer = b"".join(ds["data_compressed"].values)
3535
data = np.frombuffer(buffer, dtype=np.uint8).reshape(-1, 720)
3636

37+
# Decompress from 8 -> 12 bits using the decompression tables
38+
decompression = DECOMPRESSION_TABLES[Decompress.DECOMPRESS8TO12].astype(np.uint16)
39+
# Use the mean value column (2)
40+
data = decompression[data, 2]
41+
3742
# There is already a variable called "count" in the dataset that
3843
# came with the packet
3944
ds["data_index"] = xr.DataArray(np.arange(720), dims="data_index")
4045
ds["data"] = xr.DataArray(data, dims=("epoch", "data_index"))
4146
# Remove the original compressed data field
4247
ds = ds.drop_vars("data_compressed")
4348
return ds
44-
45-
46-
def process_star_sensor(ds: xr.Dataset) -> xr.Dataset:
47-
"""
48-
Process Lo star sensor data.
49-
50-
Parameters
51-
----------
52-
ds : xr.Dataset
53-
The packet dataset containing Lo star sensor data.
54-
55-
Returns
56-
-------
57-
xr.Dataset
58-
Processed dataset with unpacked and decompressed data.
59-
"""
60-
# Decompress from 8 -> 12 bits using the decompression tables
61-
decompression = DECOMPRESSION_TABLES[Decompress.DECOMPRESS8TO12].astype(np.uint16)
62-
63-
# Use the mean value column (2)
64-
ds["data"].values = decompression[ds["data"].values, 2]
65-
66-
# We don't want the original l1a ccsds variables, only data
67-
vars_to_drop = [x for x in ds.data_vars if x != "data"]
68-
ds = ds.drop_vars(vars_to_drop)
69-
70-
return ds

imap_processing/lo/l1a/lo_l1a.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
parse_events,
1616
parse_histogram,
1717
)
18-
from imap_processing.lo.l0.lo_star_sensor import process_star_sensor, unpack_star_sensor
18+
from imap_processing.lo.l0.lo_star_sensor import process_star_sensor
1919
from imap_processing.utils import convert_to_binary_string, packet_file_to_datasets
2020

2121
logger = logging.getLogger(__name__)
@@ -98,17 +98,10 @@ def lo_l1a(dependency: Path) -> list[xr.Dataset]:
9898
)
9999
logical_source = "imap_lo_l1a_star"
100100
ds = datasets_by_apid[LoAPID.ILO_STAR]
101-
ds = unpack_star_sensor(ds)
101+
ds = process_star_sensor(ds)
102102
ds = add_dataset_attrs(ds, attr_mgr, logical_source)
103103
datasets_to_return.append(ds)
104104

105-
# Also create l1b at the same time
106-
logical_source_l1b = "imap_lo_l1b_prostar"
107-
ds_l1b = ds.copy(deep=True)
108-
ds_l1b = process_star_sensor(ds_l1b)
109-
ds_l1b.attrs.update(attr_mgr.get_global_attributes(logical_source_l1b))
110-
datasets_to_return.append(ds_l1b)
111-
112105
logger.info(f"Returning [{len(datasets_to_return)}] datasets")
113106
return datasets_to_return
114107

imap_processing/tests/lo/test_lo_l1a.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ def test_lo_l1a():
1515
"imap_lo_l1a_histogram",
1616
"imap_lo_l1a_de",
1717
"imap_lo_l1a_star",
18-
"imap_lo_l1b_prostar",
1918
]
2019
output_dataset = lo_l1a(dependency)
2120

imap_processing/tests/lo/test_star_sensor.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from imap_processing import imap_module_directory
55
from imap_processing.lo.l0.lo_apid import LoAPID
6-
from imap_processing.lo.l0.lo_star_sensor import process_star_sensor, unpack_star_sensor
6+
from imap_processing.lo.l0.lo_star_sensor import process_star_sensor
77
from imap_processing.utils import packet_file_to_datasets
88

99

@@ -30,29 +30,24 @@ def test_star_sensor(star_sensor_ds):
3030
validation_arr = np.loadtxt(validation_file, delimiter=",", skiprows=1, dtype=int)
3131
validation_shcoarse = validation_arr[:, 0]
3232
validation_count = validation_arr[:, 1]
33-
validation_data_l1a = validation_arr[:, 2:722]
34-
validation_data_l1b = validation_arr[:, 722:-1]
33+
# The first 720
34+
# validation_data_compressed = validation_arr[:, 2:722]
35+
validation_data_decompressed = validation_arr[:, 722:-1]
3536
validation_checksum = validation_arr[:, -1]
3637

3738
## Act
38-
ds = unpack_star_sensor(star_sensor_ds)
39+
ds = process_star_sensor(star_sensor_ds)
3940

4041
## Assert
4142
# 45 times and 720 count values
4243
assert ds["data"].shape == (45, 720)
43-
assert ds["data"].dtype == np.uint8
44+
assert ds["data"].dtype == np.uint16
4445

4546
# We are only spot checking a few values from the validation file
4647
# the first 3 and the final value.
4748
small_ds = ds.isel(epoch=[0, 1, 2, -1])
4849
assert len(small_ds["epoch"]) == 4
4950
np.testing.assert_array_equal(small_ds["shcoarse"], validation_shcoarse)
5051
np.testing.assert_array_equal(small_ds["count"], validation_count)
51-
np.testing.assert_array_equal(small_ds["data"], validation_data_l1a)
52+
np.testing.assert_array_equal(small_ds["data"], validation_data_decompressed)
5253
np.testing.assert_array_equal(small_ds["chksum"], validation_checksum)
53-
54-
# Now test the l1b processed data
55-
ds_l1b = process_star_sensor(small_ds)
56-
# The 12 bit unpacking should be expanded to uint16
57-
assert ds_l1b["data"].dtype == np.uint16
58-
np.testing.assert_array_equal(ds_l1b["data"], validation_data_l1b)

0 commit comments

Comments
 (0)