Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add placeholder function for converting from esa_step to esa_energy_step #1146

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
43 changes: 36 additions & 7 deletions imap_processing/hi/l1b/hi_l1b.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,14 @@ def annotate_direct_events(l1a_dataset: xr.Dataset) -> xr.Dataset:
l1b_dataset.update(compute_coincidence_type_and_time_deltas(l1b_dataset))
l1b_dataset.update(de_nominal_bin_and_spin_phase(l1b_dataset))
l1b_dataset.update(compute_hae_coordinates(l1b_dataset))
l1b_de_var_names = [
"esa_energy_step",
"quality_flag",
]
new_data_vars = create_dataset_variables(
l1b_de_var_names, l1b_dataset["epoch"].size, att_manager_lookup_str="hi_de_{0}"
l1b_dataset.update(de_esa_energy_step(l1b_dataset))
l1b_dataset.update(
create_dataset_variables(
["quality_flag"],
l1b_dataset["epoch"].size,
att_manager_lookup_str="hi_de_{0}",
)
)
l1b_dataset.update(new_data_vars)
l1b_dataset = l1b_dataset.drop_vars(
["tof_1", "tof_2", "tof_3", "de_tag", "ccsds_met", "meta_event_met"]
)
Expand Down Expand Up @@ -341,3 +341,32 @@ def compute_hae_coordinates(dataset: xr.Dataset) -> dict[str, xr.DataArray]:
new_vars["hae_longitude"].values = pointing_coordinates[:, 1]

return new_vars


def de_esa_energy_step(dataset: xr.Dataset) -> dict[str, xr.DataArray]:
Copy link
Contributor

Choose a reason for hiding this comment

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

Just clarification question. Is this function to figure out ESA voltages of input energy steps?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not quite. The esa_step in telemetry references an index in the sweep table that was used. The sweep table determines the voltages that the ESA inner and outer are set to and thus the energy bandpass of what particles get through. I don't quite understand all of the details of the algorithm that will be implemented in this function yet. But it will use the housekeeping data to look at voltages and then maybe map those voltages to an energy step. This ticket has some additional detail: #779

"""
Compute esa_energy_step for each direct event.

TODO: For now this function just returns the esa_step from the input dataset.
Eventually, it will take L1B housekeeping data and determine the esa
energy steps from that data.

Parameters
----------
dataset : xarray.Dataset
The partial L1B dataset.

Returns
-------
new_vars : dict[str, xarray.DataArray]
Keys are variable names and values are `xarray.DataArray`.
"""
new_vars = create_dataset_variables(
["esa_energy_step"],
len(dataset.epoch),
att_manager_lookup_str="hi_de_{0}",
)
# TODO: Implement this algorithm
new_vars["esa_energy_step"].values = dataset.esa_step.values

return new_vars
18 changes: 18 additions & 0 deletions imap_processing/tests/hi/test_hi_l1b.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
CoincidenceBitmap,
compute_coincidence_type_and_time_deltas,
compute_hae_coordinates,
de_esa_energy_step,
de_nominal_bin_and_spin_phase,
hi_l1b,
)
Expand Down Expand Up @@ -235,3 +236,20 @@ def side_effect_func(et, inst_frame: SpiceFrame, to_frame):
assert "hae_longitude" in new_vars
assert new_vars["hae_longitude"].shape == fake_dataset.epoch.shape
np.testing.assert_allclose(new_vars["hae_longitude"].values, sensor_number)


def test_de_esa_energy_step():
"""Test coverage for de_esa_energy_step function."""
n_epoch = 20
fake_dataset = xr.Dataset(
coords={
"epoch": xr.DataArray(np.arange(n_epoch), name="epoch", dims=["epoch"])
},
data_vars={"esa_step": xr.DataArray(np.arange(n_epoch) % 9, dims=["epoch"])},
)
esa_energy_step_var = de_esa_energy_step(fake_dataset)
# TODO: The below check is for the temporary implementation and should be
# removed when the function is update.
np.testing.assert_array_equal(
esa_energy_step_var["esa_energy_step"].values, fake_dataset.esa_step.values
)
Loading