Skip to content

Commit

Permalink
added back position
Browse files Browse the repository at this point in the history
  • Loading branch information
laspsandoval committed Aug 27, 2024
1 parent 3e71692 commit 45f7141
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
14 changes: 14 additions & 0 deletions imap_processing/tests/ultra/unit/test_ultra_l1b_extended.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
get_front_y_position,
get_path_length,
get_ph_tof_and_back_positions,
get_ssd_back_position,
)


Expand Down Expand Up @@ -85,3 +86,16 @@ def test_get_ph_tof_and_back_positions(

np.testing.assert_array_equal(ph_xb, selected_rows["Xb"].astype("float"))
np.testing.assert_array_equal(ph_yb, selected_rows["Yb"].astype("float"))


def test_get_ssd_back_position(
de_dataset,
events_fsw_comparison_theta_0,
):
"""Tests get_ssd_back_position function."""
ssd_yb = get_ssd_back_position(de_dataset)

df = pd.read_csv(events_fsw_comparison_theta_0)
df_filt = df[(df["StartType"] != -1) & (df["StopType"] >= 8)]

np.testing.assert_array_equal(ssd_yb, df_filt["Yb"].astype("float"))
44 changes: 43 additions & 1 deletion imap_processing/ultra/l1b/ultra_l1b_extended.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
"""Calculates Extended Raw Events for ULTRA L1b."""

from enum import Enum
from typing import ClassVar

import numpy as np
import xarray
from numpy import ndarray
from numpy.typing import NDArray

from imap_processing.ultra.l1b.lookup_utils import (
get_back_position,
Expand All @@ -24,10 +26,11 @@


class StopType(Enum):
"""Stop Type: 1=Top, 2=Bottom."""
"""Stop Type: 1=Top, 2=Bottom, SSD: 8-15."""

Top = 1
Bottom = 2
SSD: ClassVar[list[int]] = [8, 9, 10, 11, 12, 13, 14, 15]


def get_front_x_position(start_type: ndarray, start_position_tdc: ndarray) -> ndarray:
Expand Down Expand Up @@ -258,3 +261,42 @@ def get_path_length(front_position: tuple, back_position: tuple, d: float) -> fl
)

return r


def get_ssd_back_position(
de_dataset: xarray.Dataset,
) -> NDArray[np.float64]:
"""
Calculate the Y SSD positions (yb) for the specified dataset.
This function calculates the back positions in the Y direction (yb)
for SSDs, expressed in hundredths of a millimeter.
Parameters
----------
de_dataset : xarray.Dataset
The input dataset containing STOP_TYPE and SSD_FLAG data.
Returns
-------
yb : np.ndarray
A NumPy array containing the calculated Y SSD positions
in hundredths of a millimeter for each relevant epoch
in the dataset. The length of this array matches the number
of epochs where the STOP_TYPE is SSD.
Notes
-----
The X back position (xb) is assumed to be 0 for SSD.
"""
indices = np.nonzero(np.isin(de_dataset["STOP_TYPE"], StopType.SSD.value))[0]
yb = np.zeros(len(indices), dtype=np.float64)
de_filtered = de_dataset.isel(epoch=indices)

for i in range(8):
# Multiply ybs times 100 to convert to hundredths of a millimeter.
yb[de_filtered[f"SSD_FLAG_{i}"].data == 1] = (
get_image_params(f"YBKSSD{i}") * 100
)

return np.asarray(yb, dtype=np.float64)

0 comments on commit 45f7141

Please sign in to comment.