From f9cce2c52e7275ed45557b3289a35800d15be676 Mon Sep 17 00:00:00 2001 From: Laura Sandoval <46567335+laspsandoval@users.noreply.github.com> Date: Wed, 14 Aug 2024 10:33:09 -0600 Subject: [PATCH] Calculate the path length for L1b Ultra (#749) * Calculate the path length for L1b Ultra --- .../ultra/unit/test_ultra_l1b_extended.py | 39 ++++++++++++++----- .../ultra/l1b/ultra_l1b_extended.py | 27 +++++++++++++ 2 files changed, 56 insertions(+), 10 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..b48c62afe 100644 --- a/imap_processing/tests/ultra/unit/test_ultra_l1b_extended.py +++ b/imap_processing/tests/ultra/unit/test_ultra_l1b_extended.py @@ -6,9 +6,23 @@ 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 +40,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