Skip to content
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
8 changes: 8 additions & 0 deletions imap_processing/lo/l1b/lo_l1b.py
Original file line number Diff line number Diff line change
Expand Up @@ -1313,6 +1313,14 @@ def set_pointing_bin(l1b_de: xr.Dataset) -> xr.Dataset:
lons = (lons + 360) % 360
# third column: latitude
lats = direction[:, 2]
# we want this relative to the pivot angle
# i.e. the off_angle is +/- 2 degrees from the pivot angle
lats = lats - (90 - l1b_de["pivot_angle"].values[0])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if you really want to modify the lats here, or if it would make more sense to modify the lat_bins. The concern is that the off_angle values sort of lose the fact that they relative to the pivot angle. I would think that a user would want off_angle_bins to be in latitudinal degrees.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was also not sure, but I spoke with Lo yesterday and they want off_angle to be the range +/- 2, so relative to the pivot_angle no matter what the pivot_angle is. I agree this adds confusion though.

if np.any(lats < -2) or np.any(lats > 2):
logger.warning(
"Some latitude values are outside of the +/-2 degree range "
f"for off-angle binning. Range: ({np.min(lats)}, {np.max(lats)})"
)

# Define bin edges
# 3600 bins, 0.1° each
Expand Down
85 changes: 50 additions & 35 deletions imap_processing/tests/lo/test_lo_l1b.py
Original file line number Diff line number Diff line change
Expand Up @@ -833,44 +833,59 @@ def test_set_direction(mock_lo_instrument_pointing, imap_ena_sim_metakernel):
)


@patch(
"imap_processing.lo.l1b.lo_l1b.frame_transform",
return_value=np.array([[0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0]]),
)
@patch(
"imap_processing.lo.l1b.lo_l1b.cartesian_to_latitudinal",
# Longitudes: -180 -> 180, 0 -> 0, 90 -> 90, 180 -> 180
# After shift to 0-360: 180, 0, 90, 180
return_value=np.array([[0, -180, -2], [0, 0, 0], [0, 90, 1], [0, 180, 2]]),
)
def test_pointing_bins(mock_cartesian_to_latitudinal, mock_frame_transform):
# Arrange
l1b_de = xr.Dataset(
{
"hae_x": ("epoch", [1, 1, 1, 1]),
"hae_y": ("epoch", [0, 0, 0, 0]),
"hae_z": ("epoch", [0, 0, 0, 0]),
},
coords={
"epoch": [
7.9794907049e17,
7.9794907153e17,
7.9794907254e17,
7.9794907354e17,
],
},
)
@pytest.mark.parametrize("pivot_angle", [75, 90, 105])
def test_pointing_bins(pivot_angle):
# Arrange - Mock returns depend on pivot_angle
# Calculate offset based on pivot angle: lats = lats - (90 - pivot_angle)
offset = 90 - pivot_angle

with (
patch(
"imap_processing.lo.l1b.lo_l1b.frame_transform",
return_value=np.array([[0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0]]),
),
patch(
"imap_processing.lo.l1b.lo_l1b.cartesian_to_latitudinal",
# Adjust latitude values based on pivot angle offset
# Longitudes: -180 -> 180, 0 -> 0, 90 -> 90, 180 -> 180
# After shift to 0-360: 180, 0, 90, 180
return_value=np.array(
[
[0, -180, -2 + offset],
[0, 0, 0 + offset],
[0, 90, 1 + offset],
[0, 180, 2 + offset],
]
),
),
):
l1b_de = xr.Dataset(
{
"hae_x": ("epoch", [1, 1, 1, 1]),
"hae_y": ("epoch", [0, 0, 0, 0]),
"hae_z": ("epoch", [0, 0, 0, 0]),
},
coords={
"epoch": [
7.9794907049e17,
7.9794907153e17,
7.9794907254e17,
7.9794907354e17,
],
"pivot_angle": [pivot_angle],
},
)

expected_pointing_lats = np.array([0, 20, 30, 40])
# Longitude bins are now in 0-360 range after the shift
expected_pointing_lons = np.array([1800, 0, 900, 1800])
expected_pointing_lats = np.array([0, 20, 30, 40])
# Longitude bins are now in 0-360 range after the shift
expected_pointing_lons = np.array([1800, 0, 900, 1800])

# Act
l1b_de = set_pointing_bin(l1b_de)
# Act
l1b_de = set_pointing_bin(l1b_de)

# Assert
np.testing.assert_array_equal(l1b_de["off_angle_bin"], expected_pointing_lats)
np.testing.assert_array_equal(l1b_de["spin_bin"], expected_pointing_lons)
# Assert
np.testing.assert_array_equal(l1b_de["off_angle_bin"], expected_pointing_lats)
np.testing.assert_array_equal(l1b_de["spin_bin"], expected_pointing_lons)


def test_badtimes_no_spin():
Expand Down