From 7b9395b3a21176cd3b3c254d50df3097ac078142 Mon Sep 17 00:00:00 2001 From: Laura Sandoval <46567335+laspsandoval@users.noreply.github.com> Date: Mon, 9 Sep 2024 09:23:37 -0600 Subject: [PATCH] Create Ultra pset energy bins (#811) * pset energy bins --- .../ultra/unit/test_ultra_l1c_pset_bins.py | 19 ++++++++++++ .../ultra/l1c/ultra_l1c_pset_bins.py | 29 +++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 imap_processing/tests/ultra/unit/test_ultra_l1c_pset_bins.py create mode 100644 imap_processing/ultra/l1c/ultra_l1c_pset_bins.py diff --git a/imap_processing/tests/ultra/unit/test_ultra_l1c_pset_bins.py b/imap_processing/tests/ultra/unit/test_ultra_l1c_pset_bins.py new file mode 100644 index 000000000..2f3ec7721 --- /dev/null +++ b/imap_processing/tests/ultra/unit/test_ultra_l1c_pset_bins.py @@ -0,0 +1,19 @@ +"Tests bins for pointing sets" + +import numpy as np + +from imap_processing.ultra.l1c.ultra_l1c_pset_bins import build_energy_bins + + +def test_build_energy_bins(): + """Tests build_energy_bins function.""" + energy_bin_start, energy_bin_end = build_energy_bins() + + assert energy_bin_start[0] == 3.5 + assert len(energy_bin_start) == 90 + assert len(energy_bin_end) == 90 + + # Comparison to expected values + np.testing.assert_allclose(energy_bin_end[0], 3.6795, atol=1e-4) + np.testing.assert_allclose(energy_bin_start[-1], 299.9724, atol=1e-4) + np.testing.assert_allclose(energy_bin_end[-1], 315.3556, atol=1e-4) diff --git a/imap_processing/ultra/l1c/ultra_l1c_pset_bins.py b/imap_processing/ultra/l1c/ultra_l1c_pset_bins.py new file mode 100644 index 000000000..f33e7f47c --- /dev/null +++ b/imap_processing/ultra/l1c/ultra_l1c_pset_bins.py @@ -0,0 +1,29 @@ +"""Module to create energy bins for pointing sets.""" + +import numpy as np + + +def build_energy_bins() -> tuple[np.ndarray, np.ndarray]: + """ + Build energy bin boundaries. + + Returns + ------- + energy_bin_start : np.ndarray + Array of energy bin start values. + energy_bin_end : np.ndarray + Array of energy bin end values. + """ + alpha = 0.05 # deltaE/E + energy_start = 3.5 # energy start for the Ultra grids + n_bins = 90 # number of energy bins + + # Calculate energy step + energy_step = (1 + alpha / 2) / (1 - alpha / 2) + + # Create energy bins. + bin_edges = energy_start * energy_step ** np.arange(n_bins + 1) + energy_bin_start = bin_edges[:-1] + energy_bin_end = bin_edges[1:] + + return energy_bin_start, energy_bin_end