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

Calculate the path length for L1b Ultra #749

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
39 changes: 29 additions & 10 deletions imap_processing/tests/ultra/unit/test_ultra_l1b_extended.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
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
Loading