Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ultra l1b extended events #686

Open
wants to merge 36 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
5aae68e
adding apids
laspsandoval Feb 9, 2024
ca8e1e4
first pass at more apids
laspsandoval Feb 14, 2024
31f7e5b
second pass at more apids
laspsandoval Feb 14, 2024
0d4594a
improvement for events
laspsandoval Feb 15, 2024
a47cbf1
formatting decom_tools.py
laspsandoval Feb 22, 2024
63b44c1
spice examples
laspsandoval Apr 2, 2024
c882282
response to pr
laspsandoval Apr 3, 2024
5f44642
remove updates to kernels
laspsandoval Apr 4, 2024
03b7ca4
annotated events
laspsandoval Apr 9, 2024
6ce4698
backing up
laspsandoval May 8, 2024
4e01b85
working test
laspsandoval May 8, 2024
563eec2
test
laspsandoval May 13, 2024
fac6c72
ssd addition
laspsandoval May 14, 2024
86d1a58
update to confest
laspsandoval Jun 25, 2024
41f40c6
extended
laspsandoval Jun 25, 2024
dedcf8f
progress
laspsandoval Jun 25, 2024
ff41c8b
progress
laspsandoval Jun 25, 2024
f99f705
update to code
laspsandoval Jun 27, 2024
02e8f0a
updates to code
laspsandoval Jun 27, 2024
1f6553a
edits
laspsandoval Jun 27, 2024
919518f
update
laspsandoval Jul 1, 2024
1b94c20
update
laspsandoval Jul 1, 2024
56fb4cc
tests pass
laspsandoval Jul 2, 2024
e474206
update to code
laspsandoval Jul 2, 2024
df4e6fa
update formatting
laspsandoval Jul 3, 2024
c34571c
update
laspsandoval Jul 3, 2024
2033867
update
laspsandoval Jul 3, 2024
03fd4ca
delete files
laspsandoval Jul 3, 2024
50b0390
remove unnecessary files
laspsandoval Jul 3, 2024
47312d5
update tests
laspsandoval Jul 3, 2024
ca6382d
new test data may revert
laspsandoval Jul 8, 2024
ec31267
response to pr
laspsandoval Jul 19, 2024
3079bcb
response to pr
laspsandoval Jul 19, 2024
aa77ea5
added luts
laspsandoval Jul 19, 2024
3de48f9
minor edit
laspsandoval Jul 19, 2024
ffe6b11
minor edit
laspsandoval Jul 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 82 additions & 29 deletions imap_processing/cdf/config/imap_ultra_l1b_variable_attrs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,113 +26,157 @@ x_front:
CATDESC: x front position
FIELDNAM: Event x-position on front foil
LABLAXIS: x front position
# TODO: come back to format
UNITS: mm
VALIDMIN: -1e6
FORMAT: F12.6
UNITS: mm / 100

y_front:
<<: *default
CATDESC: y front position
FIELDNAM: Event y-position on front foil
LABLAXIS: y front position
# TODO: come back to format
UNITS: mm
VALIDMIN: -1e6
FORMAT: F12.6
UNITS: mm / 100

x_back:
<<: *default
CATDESC: x back position
FIELDNAM: x_back
LABLAXIS: x back position
# TODO: come back to format
UNITS: mm
VALIDMIN: -1e6
FORMAT: F12.6
UNITS: mm / 100

y_back:
<<: *default
CATDESC: y back position
FIELDNAM: y_back
LABLAXIS: y back position
# TODO: come back to format
UNITS: mm
VALIDMIN: -1e6
FORMAT: F12.6
UNITS: mm / 100

x_coin:
<<: *default
CATDESC: x coincidence position
FIELDNAM: x_coin
LABLAXIS: x coincidence position
# TODO: come back to format
UNITS: mm
VALIDMIN: -1e6
FORMAT: F12.6
UNITS: mm / 100

tof_start_stop:
<<: *default
CATDESC: Particle time of flight from start to stop
FIELDNAM: tof_start_stop
LABLAXIS: tof start stop
# TODO: come back to format
UNITS: ns
VALIDMIN: -1e6
FORMAT: F12.6
UNITS: nanosecond / 10

tof_stop_coin:
<<: *default
CATDESC: Particle time of flight from stop to coincidence
FIELDNAM: tof_stop_coin
LABLAXIS: tof stop coin
# TODO: come back to format
UNITS: ns
VALIDMIN: -1e6
FORMAT: F12.6
UNITS: nanosecond / 10

tof_corrected:
<<: *default
CATDESC: Corrected time of flight
FIELDNAM: tof_corrected
LABLAXIS: tof corrected
# TODO: come back to format
UNITS: ns
VALIDMIN: -1e6
FORMAT: F12.6
UNITS: nanosecond / 10

eventtype:
event_type:
<<: *default
VALIDMAX: 15
CATDESC: Eventtype (1-2 top and bottom stop types; 8-15 ssd stop types)
FIELDNAM: eventtype
LABLAXIS: eventtype
# TODO: come back to format
UNITS: " "
FIELDNAM: Event type
FORMAT: I2
LABLAXIS: event type

coincidence_type:
<<: *default
VALIDMAX: 2
CATDESC: Coincidence type for the direct event (1-2 top and bottom)
FIELDNAM: Coincidence type
FORMAT: I1
LABLAXIS: coincidence type

start_type:
<<: *default
VALIDMAX: 2
CATDESC: Start type for the direct event (1-2 left and right)
FIELDNAM: Start type
FORMAT: I1
LABLAXIS: start type

vx_ultra:
<<: *default
CATDESC: Normalized component of the velocity vector in x direction in the instrument frame.
FIELDNAM: vx_ultra
LABLAXIS: vx ultra
# TODO: come back to format
VALIDMIN: -1e6
FORMAT: F12.6
UNITS: " "

vy_ultra:
<<: *default
CATDESC: Normalized component of the velocity vector in y direction in the instrument frame.
FIELDNAM: vy_ultra
LABLAXIS: vy ultra
# TODO: come back to format
VALIDMIN: -1e6
FORMAT: F12.6
UNITS: " "

vz_ultra:
<<: *default
CATDESC: Normalized component of the velocity vector in z direction in the instrument frame.
FIELDNAM: vz_ultra
LABLAXIS: vz ultra
# TODO: come back to format
VALIDMIN: -1e6
FORMAT: F12.6
UNITS: " "

energy:
<<: *default
CATDESC: Energy measured using the pulse height from the stop anode (DN) or Energy measured using the SSD (keV) depending on eventtype.
FIELDNAM: energy
LABLAXIS: energy
# TODO: come back to format
VALIDMIN: -1e6
FORMAT: F12.6
UNITS: keV

species:
<<: *default
CATDESC: Species bin.
CATDESC: Species bin (0-255).
FIELDNAM: species
LABLAXIS: species
# TODO: come back to format
FORMAT: I2
UNITS: " "

front_back_distance:
<<: *default
CATDESC: Distance front to back.
FIELDNAM: front_back_distance
LABLAXIS: front_back_distance
FORMAT: F12.6
UNITS: mm / 100

path_length:
<<: *default
CATDESC: Path length.
FIELDNAM: path_length
LABLAXIS: path_length
FORMAT: F12.6
UNITS: mm / 100

event_efficiency:
<<: *default
CATDESC: Estimated event efficiency for this path through the instrument.
Expand Down Expand Up @@ -218,8 +262,17 @@ eventtimes:
CATDESC: Event times calculated from event and universal spin table.
FIELDNAM: eventtimes
LABLAXIS: event times
# TODO: come back to format
UNITS: " "
FORMAT: F20.6
UNITS: seconds

de_event_met:
<<: *default
CATDESC: Mission Elapsed Time (MET) of Direct Event
DISPLAY_TYPE: no_plot
FIELDNAM: Mission Elapsed Time
LABLAXIS: DE MET
FORMAT: I20
UNITS: seconds

spin_number:
<<: *default
Expand Down

Large diffs are not rendered by default.

51 changes: 49 additions & 2 deletions imap_processing/tests/ultra/unit/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@
import pytest

from imap_processing import decom
from imap_processing.cdf.defaults import GlobalConstants
from imap_processing.ultra.l0.decom_ultra import process_ultra_apids
from imap_processing.ultra.l0.ultra_utils import (
ULTRA_AUX,
ULTRA_EVENTS,
)
from imap_processing.ultra.l1a import ultra_l1a
from imap_processing.utils import group_by_apid


Expand Down Expand Up @@ -36,7 +42,7 @@ def ccsds_path_events():
)


@pytest.fixture()
@pytest.fixture(scope="session")
def ccsds_path_theta_0():
"""Returns the ccsds directory."""
return (
Expand All @@ -63,7 +69,7 @@ def ccsds_path_tof():
)


@pytest.fixture()
@pytest.fixture(scope="session")
def xtce_path():
"""Returns the xtce image rates directory."""
return (
Expand Down Expand Up @@ -161,3 +167,44 @@ def decom_test_data(request, xtce_path):

data_packet_list = process_ultra_apids(grouped_data[apid], apid)
return data_packet_list, packets


@pytest.fixture()
def events_fsw_comparison_theta_0():
"""Returns the xtce auxiliary test data directory."""
filename = (
"FM45_40P_Phi28p5_BeamCal_LinearScan_phi28.50_theta-0.00"
"_Ultra_Image_Raw_Event_20240207T102746_withFSWcalcs.csv"
)
return (
Path(sys.modules[__name__.split(".")[0]].__file__).parent
/ "tests"
/ "ultra"
/ "test_data"
/ "l0"
/ filename
)


@pytest.fixture()
def de_dataset(ccsds_path_theta_0, xtce_path):
"""L1A test data"""
packets = decom.decom_packets(ccsds_path_theta_0, xtce_path)
grouped_data = group_by_apid(packets)
decom_ultra_events = process_ultra_apids(
grouped_data[ULTRA_EVENTS.apid[0]], ULTRA_EVENTS.apid[0]
)
decom_ultra_aux = process_ultra_apids(
grouped_data[ULTRA_AUX.apid[0]], ULTRA_AUX.apid[0]
)
dataset = ultra_l1a.create_dataset(
{
ULTRA_EVENTS.apid[0]: decom_ultra_events,
ULTRA_AUX.apid[0]: decom_ultra_aux,
}
)
# Remove start_type with fill values
l1a_de_dataset = dataset.where(
dataset["START_TYPE"] != GlobalConstants.INT_FILLVAL, drop=True
)
return l1a_de_dataset
68 changes: 68 additions & 0 deletions imap_processing/tests/ultra/unit/test_lookup_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import numpy as np
import pandas as pd

from imap_processing import imap_module_directory
from imap_processing.ultra.l1b.lookup_utils import (
get_back_position,
get_energy_norm,
get_image_params,
get_norm,
get_y_adjust,
)

base_path = imap_module_directory / "ultra" / "lookup_tables"


def test_get_y_adjust():
"""Tests function get_y_adjust."""

yadjust_path = base_path / "yadjust.csv"
yadjust_df = pd.read_csv(yadjust_path).set_index("dYLUT")

array = np.array([8])
res = get_y_adjust(array)

assert res == yadjust_df["dYAdj"][8]


def test_get_stop_norm():
"""Tests function get_stop_norm."""

tdc_norm_path = base_path / "ultra45_tdc_norm.csv"
tdc_norm_df = pd.read_csv(tdc_norm_path, header=1)

array = np.array([378])
stop_norm = get_norm(array, "SpE", "ultra45")

assert stop_norm == tdc_norm_df["SpE"][378]


def test_get_back_position():
"""Tests function get_back_position."""

back_pos_path = base_path / "ultra45_back-pos-luts.csv"
back_pos_df = pd.read_csv(back_pos_path, index_col="Index_offset")

array = np.array([-2000])
dn_converted = get_back_position(array, "XBkBt", "ultra45")

assert dn_converted == back_pos_df["XBkBt"].iloc[-2000]


def test_get_egy_norm():
"""Tests function get_egy_norm."""

egy_norm_path = base_path / "EgyNorm.mem.csv"
egy_norm_df = pd.read_csv(egy_norm_path)

norm_composite_energy = get_energy_norm(np.array([2]), np.array([2]))

assert norm_composite_energy == egy_norm_df.iloc[2 * 4096 + 2]["NormEnergy"]


def test_get_image_params():
"""Tests function get_image_params."""

image_params = get_image_params("XFTLTOFF")

assert image_params == 49.3
9 changes: 6 additions & 3 deletions imap_processing/tests/ultra/unit/test_ultra_l1b.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def test_create_dataset(mock_data_l1b_dict):
assert "epoch" in dataset.coords
assert dataset.coords["epoch"].dtype == "datetime64[ns]"
assert dataset.attrs["Logical_source"] == "imap_ultra_l1b_45sensor-de"
assert dataset["x_front"].attrs["UNITS"] == "mm"
assert dataset["x_front"].attrs["UNITS"] == "mm / 100"
np.testing.assert_array_equal(dataset["x_front"], np.zeros(3))


Expand All @@ -99,9 +99,12 @@ def test_ultra_l1b_rates(mock_data_l1a_rates_dict):
)


def test_ultra_l1b_de(mock_data_l1a_de_aux_dict):
def test_ultra_l1b_de(de_dataset):
"""Tests that L1b data is created."""
output_datasets = ultra_l1b(mock_data_l1a_de_aux_dict, data_version="001")
data_dict = {}
data_dict[de_dataset.attrs["Logical_source"]] = de_dataset
data_dict["imap_ultra_l1a_45sensor-aux"] = de_dataset
output_datasets = ultra_l1b(data_dict, data_version="001")

assert len(output_datasets) == 1
assert output_datasets[0].attrs["Logical_source"] == "imap_ultra_l1b_45sensor-de"
Expand Down
Loading
Loading