Skip to content

Commit

Permalink
added luts
Browse files Browse the repository at this point in the history
  • Loading branch information
laspsandoval committed Jul 19, 2024
1 parent 6523879 commit aed95ae
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 48 deletions.
14 changes: 7 additions & 7 deletions imap_processing/tests/ultra/unit/test_lookup_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
get_y_adjust,
)

base_path = f"{imap_module_directory}/ultra/lookup_tables"
base_path = imap_module_directory / "ultra" / "lookup_tables"


def test_get_y_adjust():
"""Tests function get_y_adjust."""

yadjust_path = f"{base_path}/yadjust.csv"
yadjust_path = base_path / "yadjust.csv"
yadjust_df = pd.read_csv(yadjust_path).set_index("dYLUT")

array = np.array([8])
Expand All @@ -28,8 +28,8 @@ def test_get_y_adjust():
def test_get_stop_norm():
"""Tests function get_stop_norm."""

tdc_norm_path = f"{base_path}/Ultra45_tdc_norm_LUT_IntPulser_20230901.csv"
tdc_norm_df = pd.read_csv(tdc_norm_path, header=0)
tdc_norm_path = base_path / "ultra45_tdc_norm.csv"
tdc_norm_df = pd.read_csv(tdc_norm_path, header=1)

array = np.array([378])
stop_norm = get_norm(array, "SpE", "ultra45")
Expand All @@ -40,7 +40,7 @@ def test_get_stop_norm():
def test_get_back_position():
"""Tests function get_back_position."""

back_pos_path = f"{base_path}/back-pos-luts_SN202_20230216.csv"
back_pos_path = base_path / "ultra45_back-pos-luts.csv"
back_pos_df = pd.read_csv(back_pos_path, index_col="Index_offset")

array = np.array([-2000])
Expand All @@ -52,7 +52,7 @@ def test_get_back_position():
def test_get_egy_norm():
"""Tests function get_egy_norm."""

egy_norm_path = f"{base_path}/EgyNorm.mem.csv"
egy_norm_path = base_path / "EgyNorm.mem.csv"
egy_norm_df = pd.read_csv(egy_norm_path)

norm_composite_energy = get_energy_norm(np.array([2]), np.array([2]))
Expand All @@ -65,4 +65,4 @@ def test_get_image_params():

image_params = get_image_params("XFTLTOFF")

assert image_params == 47.5
assert image_params == 49.3
24 changes: 3 additions & 21 deletions imap_processing/tests/ultra/unit/test_ultra_l1b_extended.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,34 +22,16 @@ def test_get_front_x_position(
events_fsw_comparison_theta_0,
):
"""Tests get_front_x_position function."""
# Left Start Type
indices_left = np.where(de_dataset["START_TYPE"] == 1)[0]
# Right Start Type
indices_right = np.where(de_dataset["START_TYPE"] == 2)[0]

df = pd.read_csv(events_fsw_comparison_theta_0)
df_filt = df[df["StartType"] != -1]
selected_rows_1 = df_filt.iloc[indices_left]
selected_rows_2 = df_filt.iloc[indices_right]

xf = get_front_x_position(
de_dataset["START_TYPE"].data,
de_dataset["START_POS_TDC"].data,
)

# TODO: Need new lookup tables for "XFTLTOFF", "XFTRTOFF"
# Need new lookup table.
# The value 180 was added to xf_1 since that
# is the offset from the FSW xft_off
assert np.allclose(
xf[indices_left] + 180, selected_rows_1.Xf.values.astype("float"), rtol=1e-3
)

# The value 25 was subtracted from xf_2 bc that
# is the offset from the FSW xft_off
assert np.allclose(
xf[indices_right] - 25, selected_rows_2.Xf.values.astype("float"), rtol=1e-3
)
assert np.allclose(xf, df_filt.Xf.values.astype("float"), rtol=1e-5)


def test_xb_yb(
Expand Down Expand Up @@ -167,11 +149,11 @@ def test_get_ssd_offset_and_positions(

# -4 is a value of an offset for SSD3 for Left Start Type and
# SSD0 for Right Start Type.
offset_length = len(tof_offsets[tof_offsets == -4])
offset_length = len(tof_offsets[tof_offsets == -4.2])
expected_offset_length = len(
selected_rows[
((selected_rows["StartType"] == 1) & (selected_rows["SSDS3"] == 1))
| ((selected_rows["StartType"] == 2) & (selected_rows["SSDS4"] == 1))
| ((selected_rows["StartType"] == 2) & (selected_rows["SSDS5"] == 1))
]
)

Expand Down
26 changes: 8 additions & 18 deletions imap_processing/ultra/l1b/lookup_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def get_y_adjust(dy_lut: np.ndarray):
return yadj.values


def get_norm(dn: np.ndarray, key: str, sensor: str):
def get_norm(dn: np.ndarray, key: str, file_label: str):
"""
Correct mismatches between the stop Time to Digital Converters (TDCs).
Expand All @@ -53,7 +53,7 @@ def get_norm(dn: np.ndarray, key: str, sensor: str):
key : str
TpSpNNorm, TpSpSNorm, TpSpENorm, or TpSpWNorm.
BtSpNNorm, BtSpSNorm, BtSpENorm, or BtSpWNorm.
sensor : str
file_label : str
Instrument (ultra45 or ultra90).
Returns
Expand All @@ -62,20 +62,15 @@ def get_norm(dn: np.ndarray, key: str, sensor: str):
Normalized DNs.
"""
# We only need the center string, i.e. SpN, SpS, SpE, SpW
if sensor == "ultra45":
file_label = "Ultra45_tdc_norm_LUT_IntPulser_20230901.csv"
else:
file_label = "Ultra90_tdc_norm_LUT_IntPulser_20230614.csv"

tdc_norm_path = base_path / file_label
tdc_norm_df = pd.read_csv(tdc_norm_path, header=0, index_col="Index")
tdc_norm_path = base_path / f"{file_label}_tdc_norm.csv"
tdc_norm_df = pd.read_csv(tdc_norm_path, header=1, index_col="Index")

dn_norm = tdc_norm_df[key].iloc[dn]

return dn_norm.values


def get_back_position(back_index: np.ndarray, key: str, sensor: str):
def get_back_position(back_index: np.ndarray, key: str, file_label: str):
"""
Convert normalized TDC values using lookup tables.
Expand All @@ -92,20 +87,15 @@ def get_back_position(back_index: np.ndarray, key: str, sensor: str):
SpSNorm - SpNNorm + 2047, or SpENorm - SpWNorm + 2047.
key : str
XBkTp, YBkTp, XBkBt, or YBkBt.
sensor : str
file_label : str
Instrument (ultra45 or ultra90).
Returns
-------
dn_converted : np.ndarray
Converted DNs to Units of hundredths of a millimeter.
"""
if sensor == "ultra45":
file_label = "back-pos-luts_SN202_20230216.csv"
else:
file_label = "back-pos-luts_SN201_20230717.csv"

back_pos_path = base_path / file_label
back_pos_path = base_path / f"{file_label}_back-pos-luts.csv"
back_pos_df = pd.read_csv(back_pos_path, index_col="Index_offset")

dn_converted = back_pos_df[key].iloc[back_index]
Expand Down Expand Up @@ -161,7 +151,7 @@ def get_image_params(image: str):
value : np.float64
Image parameter value from the CSV file.
"""
csv_file_path = base_path / "FM45_Startup1_ULTRA_IMGPARAMS_20240207T134735_.csv"
csv_file_path = base_path / "FM45_Startup1_ULTRA_IMGPARAMS_20240719.csv"
df = pd.read_csv(csv_file_path)
value = df[image].iloc[0]

Expand Down
2 changes: 0 additions & 2 deletions imap_processing/ultra/l1b/ultra_l1b_extended.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,6 @@ def get_front_x_position(start_type: np.array, start_position_tdc: np.array):
xft_off = np.where(start_type[indices] == 1, xft_lt_off, xft_rt_off)

# Calculate xf and convert to hundredths of a millimeter
# Note FSW uses xft_off+1.8, but the lookup table uses xft_off
# Note FSW uses xft_off-.25, but the lookup table uses xft_off
xf = (xftsc * -start_position_tdc[indices] + xft_off) * 100

return xf
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
SHCOARSE,XFTSC,XFTLTOFF,XFTRTOFF,TOFSC,TOFTPOFF,TOFBTOFF,XFTTOF,XCOINTPSC,XCOINTPOFF,XCOINBTSC,XCOINBTOFF,ETOFSC,ETOFTPOFF,ETOFBTOFF,TOFDIFFTPMIN,TOFDIFFTPMAX,TOFDIFFBTMIN,TOFDIFFBTMAX,ETOFMIN,ETOFMAX,ETOFSLOPE1,ETOFOFF1,ETOFSLOPE2,ETOFOFF2,SPTPPHOFF,SPBTPHOFF,YBKSSD0,YBKSSD1,YBKSSD2,YBKSSD3,YBKSSD4,YBKSSD5,YBKSSD6,YBKSSD7,TOFSSDSC,TOFSSDLTOFF0,TOFSSDLTOFF1,TOFSSDLTOFF2,TOFSSDLTOFF3,TOFSSDLTOFF4,TOFSSDLTOFF5,TOFSSDLTOFF6,TOFSSDLTOFF7,TOFSSDRTOFF0,TOFSSDRTOFF1,TOFSSDRTOFF2,TOFSSDRTOFF3,TOFSSDRTOFF4,TOFSSDRTOFF5,TOFSSDRTOFF6,TOFSSDRTOFF7,TOFSSDTOTOFF,PATHSTEEPTHRESH,PATHMEDIUMTHRESH
,0.172998047,49.3,48.25,0.5,-528,-525,0.001831055,0.067929688,41.75,0.067929688,-39.79492188,0.1,-44.5,-44.5,,,,,,,,,,,,,29.3,37.3,7.1,15.1,-15.1,-7.1,-37.3,-29.3,0.196484375,-6,-7.3,-3.8,-4.2,-3.8,-3.7,-6.3,-5,-5,-6.3,-3.7,-3.8,-4,-4.2,-7.3,-6,5.9,,
445027647,0.172998047,47.5,48.5,0.5,-528,-525,0.001831055,0.068486328,42.25,0.068486328,-39.75,0.1,-44.5,-44.5,22.6,26.6,22.6,26.6,-40,9,0.666699219,10,0.75,-5,540,540,29.3,37.300000000000004,7.1000000000000005,15.1,-15.1,-7.1,-37.3,-29.3,0.196484375,-6,-7,-3.5,-4,-3.8,-3.5,-6.8,-5.5,-5.5,-6.8,-3.5,-3.8,-4,-3.5,-7,-6,5.300000000000001,50,65
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

0 comments on commit aed95ae

Please sign in to comment.