Skip to content

Commit cbe72eb

Browse files
authored
Lo L1B DE - Binning fixes (IMAP-Science-Operations-Center#2334)
* changed HAE to DPS binning * fixed unit tests * fixed energy edges bug that was reintroduced * added comment for goodtimes bin condition
1 parent 474ef5c commit cbe72eb

4 files changed

Lines changed: 29 additions & 12 deletions

File tree

imap_processing/lo/l1b/lo_l1b.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from imap_processing.spice.geometry import (
2020
SpiceFrame,
2121
cartesian_to_latitudinal,
22+
frame_transform,
2223
instrument_pointing,
2324
)
2425
from imap_processing.spice.repoint import get_pointing_times
@@ -760,8 +761,10 @@ def set_bad_or_goodtimes(
760761
# the bin_start and bin_end are 6 degree bins and need to be converted to
761762
# 0.1 degree bins to align with the spin_bins, so multiply by 60
762763
time_mask = (epochs[:, None] >= times_start) & (epochs[:, None] <= times_end)
764+
# The ancillary file binning uses 0-59 for the 6 degree bins, so add 1 to bin_end
765+
# so the upper bound is inclusive of the full bin range.
763766
bin_mask = (spin_bins[:, None] >= times_df["bin_start"].values * 60) & (
764-
spin_bins[:, None] <= times_df["bin_end"].values * 60
767+
spin_bins[:, None] < (times_df["bin_end"].values + 1) * 60
765768
)
766769

767770
# Combined mask for epochs that fall within the time and bin ranges
@@ -853,8 +856,15 @@ def set_pointing_bin(l1b_de: xr.Dataset) -> xr.Dataset:
853856
x = l1b_de["hae_x"]
854857
y = l1b_de["hae_y"]
855858
z = l1b_de["hae_z"]
859+
# Convert from HAE to DPS coordinates
860+
dps_xyz = frame_transform(
861+
ttj2000ns_to_et(l1b_de["epoch"]),
862+
np.column_stack((x, y, z)),
863+
SpiceFrame.IMAP_HAE,
864+
SpiceFrame.IMAP_DPS,
865+
)
856866
# convert the pointing direction to latitudinal coordinates
857-
direction = cartesian_to_latitudinal(np.column_stack((x, y, z)))
867+
direction = cartesian_to_latitudinal(dps_xyz)
858868
# first column: radius (Not needed)
859869
# second column: longitude
860870
lons = direction[:, 1]

imap_processing/lo/l1c/lo_l1c.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,8 @@ def create_pset_counts(
295295
data = np.column_stack(
296296
(
297297
de_filtered["esa_step"],
298-
de_filtered["pointing_bin_lon"],
299-
de_filtered["pointing_bin_lat"],
298+
de_filtered["spin_bin"],
299+
de_filtered["off_angle_bin"],
300300
)
301301
)
302302
# Create the histogram with 3600 longitude bins, 40 latitude bins, and 7 energy bins
@@ -341,7 +341,7 @@ def calculate_exposure_times(counts: xr.DataArray, l1b_de: xr.Dataset) -> xr.Dat
341341
The exposure times for the L1B Direct Event dataset.
342342
"""
343343
data = np.column_stack(
344-
(l1b_de["esa_step"], l1b_de["pointing_bin_lon"], l1b_de["pointing_bin_lat"])
344+
(l1b_de["esa_step"], l1b_de["spin_bin"], l1b_de["off_angle_bin"])
345345
)
346346

347347
result = binned_statistic_dd(

imap_processing/tests/lo/test_lo_l1b.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ def attr_mgr_l1a():
7777
return attr_mgr
7878

7979

80+
@patch(
81+
"imap_processing.lo.l1b.lo_l1b.frame_transform",
82+
return_value=np.array([[0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0]]),
83+
)
8084
@patch(
8185
"imap_processing.lo.l1b.lo_l1b.instrument_pointing",
8286
return_value=np.zeros((2000, 3)),
@@ -91,6 +95,7 @@ def attr_mgr_l1a():
9195
return_value=np.zeros((2000, 3)),
9296
)
9397
def test_lo_l1b(
98+
mock_frame_transform,
9499
mock_instrument_pointing,
95100
mocked_get_pointing_times,
96101
mock_spin_number,
@@ -630,11 +635,15 @@ def test_set_direction(imap_ena_sim_metakernel):
630635
)
631636

632637

638+
@patch(
639+
"imap_processing.lo.l1b.lo_l1b.frame_transform",
640+
return_value=np.array([[0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0]]),
641+
)
633642
@patch(
634643
"imap_processing.lo.l1b.lo_l1b.cartesian_to_latitudinal",
635644
return_value=np.array([[0, -180, -2], [0, 0, 0], [0, 90, 1], [0, 180, 2]]),
636645
)
637-
def test_pointing_bins(imap_ena_sim_metakernel):
646+
def test_pointing_bins(mock_cartesian_to_latitudinal, mock_frame_transform):
638647
# Arrange
639648
l1b_de = xr.Dataset(
640649
{

imap_processing/tests/lo/test_lo_l1c.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
def l1b_de():
2424
l1b_de = xr.Dataset(
2525
{
26-
"pointing_bin_lon": ("epoch", [20, 0, 20, 2000, 3500]),
27-
"pointing_bin_lat": ("epoch", [20, 20, 20, 20, 20]),
26+
"spin_bin": ("epoch", [20, 0, 20, 2000, 3500]),
27+
"off_angle_bin": ("epoch", [20, 20, 20, 20, 20]),
2828
"esa_step": ("epoch", [1, 2, 1, 4, 5]),
2929
"coincidence_type": (
3030
"epoch",
@@ -39,7 +39,6 @@ def l1b_de():
3939
"species": ("epoch", ["H", "O", "H", "H", "O"]),
4040
"spin_cycle": ("epoch", [1, 2, 3, 4, 5]),
4141
"avg_spin_durations": ("epoch", [15.2, 15.2, 14.9, 15, 14.9]),
42-
"spin_bin": ("epoch", [1900, 2000, 3000, 3000, 3000]),
4342
},
4443
coords={
4544
"epoch": [
@@ -64,8 +63,8 @@ def repoint_met():
6463
def l1b_de_spin():
6564
l1b_de = xr.Dataset(
6665
{
67-
"pointing_bin_lon": ("epoch", [20, 0, 20, 2000, 3500]),
68-
"pointing_bin_lat": ("epoch", [20, 20, 20, 20, 20]),
66+
"spin_bin": ("epoch", [20, 0, 20, 2000, 3500]),
67+
"off_angle_bin": ("epoch", [20, 20, 20, 20, 20]),
6968
"esa_step": ("epoch", [1, 2, 1, 4, 5]),
7069
"coincidence_type": (
7170
"epoch",
@@ -80,7 +79,6 @@ def l1b_de_spin():
8079
"species": ("epoch", ["H", "O", "H", "H", "O"]),
8180
"spin_cycle": ("epoch", [1, 2, 3, 4, 5]),
8281
"avg_spin_durations": ("epoch", [15.2, 15.2, 14.9, 15, 14.9]),
83-
"spin_bin": ("epoch", [1900, 2000, 3000, 3000, 3000]),
8482
},
8583
coords={
8684
"epoch": met_to_ttj2000ns(np.arange(511000000, 511000000 + 200, 40) + 902),

0 commit comments

Comments
 (0)