Skip to content

Commit

Permalink
added new function
Browse files Browse the repository at this point in the history
  • Loading branch information
laspsandoval committed Aug 13, 2024
1 parent 9d7bd05 commit 419f96e
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 12 deletions.
41 changes: 29 additions & 12 deletions imap_processing/tests/ultra/unit/test_ultra_l1b_extended.py
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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)
27 changes: 27 additions & 0 deletions imap_processing/ultra/l1b/ultra_l1b_extended.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 419f96e

Please sign in to comment.