Skip to content

Commit

Permalink
l1b extended test pass
Browse files Browse the repository at this point in the history
  • Loading branch information
laspsandoval committed Sep 4, 2024
1 parent 0e3f984 commit 1590f1e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 51 deletions.
49 changes: 18 additions & 31 deletions imap_processing/tests/ultra/unit/test_ultra_l1b_extended.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from imap_processing.ultra.l1b.ultra_l1b_extended import (
StartType,
StopType,
CoinType,
get_coincidence_positions,
get_front_x_position,
get_front_y_position,
Expand Down Expand Up @@ -88,7 +87,9 @@ 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"))
np.testing.assert_allclose(ph_tof, selected_rows["TOF"].astype("float"), atol=1e-5, rtol=0)
np.testing.assert_allclose(
ph_tof, selected_rows["TOF"].astype("float"), atol=1e-5, rtol=0
)


def test_get_ssd_back_position_and_tof_offset(
Expand Down Expand Up @@ -134,36 +135,22 @@ def test_get_ssd_back_position_and_tof_offset(
def test_get_coincidence_positions(de_dataset, yf_fixture):
"""Tests get_coincidence_positions function."""
df_filt, _, _ = yf_fixture
tof = df_filt["TOF"].astype("float").values

etof, xc = get_coincidence_positions(de_dataset, tof, "ultra45")

coin_indices = np.nonzero(
np.isin(de_dataset["COIN_TYPE"], [CoinType.Top.value, CoinType.Bottom.value])
)[0]

coin_rows = df_filt.iloc[coin_indices]

np.testing.assert_allclose(xc[coin_indices],
coin_rows["Xc"].astype("float"), atol=1e-4, rtol=0)
# Get particle tof (t2).
_, t2, _, _ = get_ph_tof_and_back_positions(
de_dataset, df_filt.Xf.astype("float").values, "ultra45"
)

# look at etof
coin_top_indices = np.nonzero(
np.isin(de_dataset["COIN_TYPE"], [CoinType.Top.value])
)[0]
coin_bottom_indices = np.nonzero(
np.isin(de_dataset["COIN_TYPE"], [CoinType.Bottom.value])
# Filter for stop type.
indices = np.nonzero(
np.isin(de_dataset["STOP_TYPE"], [StopType.Top.value, StopType.Bottom.value])
)[0]
de_filtered = de_dataset.isel(epoch=indices)
rows = df_filt.iloc[indices]

top_rows = df_filt.iloc[coin_top_indices]
bottom_rows = df_filt.iloc[coin_bottom_indices]

np.testing.assert_allclose(etof[coin_bottom_indices],
bottom_rows["eTOF"].astype("float"))
# Get coincidence position and eTOF.
etof, xc = get_coincidence_positions(de_filtered, t2, "ultra45")

# assert top
np.testing.assert_allclose(etof[coin_top_indices],
top_rows["eTOF"].astype("float"))


print('hi')
np.testing.assert_allclose(xc, rows["Xc"].astype("float"), atol=1e-4, rtol=0)
np.testing.assert_allclose(
etof, rows["eTOF"].astype("float").values, rtol=0, atol=1e-06
)
47 changes: 27 additions & 20 deletions imap_processing/ultra/l1b/ultra_l1b_extended.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,25 +350,25 @@ def get_coincidence_positions(
Returns
-------
etof_sorted : np.ndarray
etof : np.ndarray
Time for the electrons to travel back to
coincidence anode (tenths of a nanosecond).
xc_sorted : np.ndarray
xc : np.ndarray
X coincidence position (hundredths of a millimeter).
"""
index_top = np.nonzero(np.isin(de_dataset["COIN_TYPE"], CoinType.Top.value))[0]
de_top = de_dataset.isel(epoch=index_top)

index_bottom = np.nonzero(np.isin(de_dataset["COIN_TYPE"], CoinType.Bottom.value))[0]
index_bottom = np.nonzero(np.isin(de_dataset["COIN_TYPE"], CoinType.Bottom.value))[
0
]
de_bottom = de_dataset.isel(epoch=index_bottom)

t1 = np.zeros(len(de_dataset["COIN_TYPE"]), dtype=np.float64)
t2 = np.zeros(len(de_dataset["COIN_TYPE"]), dtype=np.float64)

# TODO: what should this fill value be?
fill_value = np.iinfo(np.int64).min
xc = np.full(len(de_dataset["COIN_TYPE"]), fill_value, dtype=np.float64)
etof = np.full(len(de_dataset["COIN_TYPE"]), fill_value, dtype=np.float64)
xc = np.zeros(len(de_dataset["COIN_TYPE"]), dtype=np.float64)
etof = np.zeros(len(de_dataset["COIN_TYPE"]), dtype=np.float64)

# Normalized TDCs
# For the stop anode, there are mismatches between the coincidence TDCs,
Expand All @@ -384,24 +384,31 @@ def get_coincidence_positions(
coin_s_norm_top - coin_n_norm_top
) + get_image_params("XCOINTPOFF") # millimeter
# Time for the electrons to travel back to coincidence anode.
t2[index_top] = get_image_params("ETOFSC") * t1[index_top] + get_image_params("ETOFTPOFF")
etof[index_top] = t2[index_top] - particle_tof[index_top]
t2[index_top] = get_image_params("ETOFSC") * t1[index_top] + get_image_params(
"ETOFTPOFF"
)

# Multiply by 10 to convert to tenths of a nanosecond.
etof[index_top] = t2[index_top] * 10 - particle_tof[index_top]

# TpCoinNNorm Bottom
coin_n_norm_bottom = get_norm(
de_bottom["COIN_NORTH_TDC"], "CoinN", sensor
)
coin_n_norm_bottom = get_norm(de_bottom["COIN_NORTH_TDC"], "CoinN", sensor)
# TpCoinSNorm Bottom
coin_s_norm_bottom = get_norm(
de_bottom["COIN_SOUTH_TDC"], "CoinS", sensor
)
t1[index_bottom] = coin_n_norm_bottom + coin_s_norm_bottom # /2 incorporated into scale
coin_s_norm_bottom = get_norm(de_bottom["COIN_SOUTH_TDC"], "CoinS", sensor)
t1[index_bottom] = (
coin_n_norm_bottom + coin_s_norm_bottom
) # /2 incorporated into scale
xc[index_bottom] = get_image_params("XCOINBTSC") * (
coin_s_norm_bottom - coin_n_norm_bottom
coin_s_norm_bottom - coin_n_norm_bottom
) + get_image_params("XCOINBTOFF") # millimeter

# Time for the electrons to travel back to coincidence anode.
t2[index_bottom] = get_image_params("ETOFSC") * t1[index_bottom] + get_image_params("ETOFBTOFF")
etof[index_bottom] = t2[index_bottom] - particle_tof[index_bottom]
t2[index_bottom] = get_image_params("ETOFSC") * t1[index_bottom] + get_image_params(
"ETOFBTOFF"
)

# Multiply by 10 to convert to tenths of a nanosecond.
etof[index_bottom] = t2[index_bottom] * 10 - particle_tof[index_bottom]

# Convert to hundredths of a millimeter by multiplying times 100
return etof, xc*100
return etof, xc * 100

0 comments on commit 1590f1e

Please sign in to comment.