From 419f96e1e521cd396b4a768e4e4e6afd4b7f43f0 Mon Sep 17 00:00:00 2001 From: Laura Sandoval Date: Tue, 13 Aug 2024 10:25:03 -0600 Subject: [PATCH 1/2] added new function --- .../ultra/unit/test_ultra_l1b_extended.py | 41 +++++++++++++------ .../ultra/l1b/ultra_l1b_extended.py | 27 ++++++++++++ 2 files changed, 56 insertions(+), 12 deletions(-) diff --git a/imap_processing/tests/ultra/unit/test_ultra_l1b_extended.py b/imap_processing/tests/ultra/unit/test_ultra_l1b_extended.py index 88989edd5..33f634a31 100644 --- a/imap_processing/tests/ultra/unit/test_ultra_l1b_extended.py +++ b/imap_processing/tests/ultra/unit/test_ultra_l1b_extended.py @@ -1,14 +1,26 @@ -"""Tests Extended Raw Events for ULTRA L1b.""" - import pandas as pd import pytest from imap_processing.ultra.l1b.ultra_l1b_extended import ( get_front_x_position, get_front_y_position, + get_path_length, ) +@pytest.fixture() +def yf_fixture(de_dataset, events_fsw_comparison_theta_0): + """Fixture to compute and return yf and related data.""" + df = pd.read_csv(events_fsw_comparison_theta_0) + df_filt = df[df["StartType"] != -1] + + d, yf = get_front_y_position( + de_dataset["START_TYPE"].data, df_filt.Yb.values.astype("float") + ) + + return df_filt, d, yf + + def test_get_front_x_position( de_dataset, events_fsw_comparison_theta_0, @@ -26,17 +38,22 @@ def test_get_front_x_position( assert xf == pytest.approx(df_filt["Xf"].astype("float"), 1e-5) -def test_get_front_y_position( - de_dataset, - events_fsw_comparison_theta_0, -): +def test_get_front_y_position(yf_fixture): """Tests get_front_y_position function.""" + df_filt, d, yf = yf_fixture - df = pd.read_csv(events_fsw_comparison_theta_0) - df_filt = df[df["StartType"] != -1] + assert yf == pytest.approx(df_filt["Yf"].astype("float"), abs=1e-5) - d, yf = get_front_y_position( - de_dataset["START_TYPE"].data, df_filt.Yb.values.astype("float") - ) - assert yf == pytest.approx(df_filt["Yf"].astype("float"), abs=1e-5) +def test_get_path_length(de_dataset, yf_fixture): + """Tests get_path_length function.""" + + df_filt, d, yf = yf_fixture + + test_xf = df_filt["Xf"].astype("float").values + test_yf = df_filt["Yf"].astype("float").values + + test_xb = df_filt["Xb"].astype("float").values + test_yb = df_filt["Yb"].astype("float").values + r = get_path_length((test_xf, test_yf), (test_xb, test_yb), d) + assert r == pytest.approx(df_filt["r"].astype("float"), abs=1e-5) diff --git a/imap_processing/ultra/l1b/ultra_l1b_extended.py b/imap_processing/ultra/l1b/ultra_l1b_extended.py index 52e3a42dc..c977981fb 100644 --- a/imap_processing/ultra/l1b/ultra_l1b_extended.py +++ b/imap_processing/ultra/l1b/ultra_l1b_extended.py @@ -109,3 +109,30 @@ def get_front_y_position(start_type: ndarray, yb: ndarray) -> tuple[ndarray, nda d[index_right] = (SLIT_Z - distance_adjust_right) * 100 return np.array(d), np.array(yf) + + +def get_path_length(front_position: tuple, back_position: tuple, d: float) -> float: + """ + Calculate the path length. + + Parameters + ---------- + front_position : tuple of floats + Front position (xf,yf) (hundredths of a millimeter). + back_position : tuple of floats + Back position (xb,yb) (hundredths of a millimeter). + d : float + Distance from slit to foil (hundredths of a millimeter). + + Returns + ------- + r : float + Path length (hundredths of a millimeter). + """ + r: float = np.sqrt( + (front_position[0] - back_position[0]) ** 2 + + (front_position[1] - back_position[1]) ** 2 + + (d) ** 2 + ) + + return r From af63c91bb41626e7192a82d2dda49f93ec02ab76 Mon Sep 17 00:00:00 2001 From: Laura Sandoval Date: Tue, 13 Aug 2024 10:26:52 -0600 Subject: [PATCH 2/2] added new function --- imap_processing/tests/ultra/unit/test_ultra_l1b_extended.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/imap_processing/tests/ultra/unit/test_ultra_l1b_extended.py b/imap_processing/tests/ultra/unit/test_ultra_l1b_extended.py index 33f634a31..b48c62afe 100644 --- a/imap_processing/tests/ultra/unit/test_ultra_l1b_extended.py +++ b/imap_processing/tests/ultra/unit/test_ultra_l1b_extended.py @@ -1,3 +1,5 @@ +"""Tests Extended Raw Events for ULTRA L1b.""" + import pandas as pd import pytest