-
Notifications
You must be signed in to change notification settings - Fork 22
ULTRA L1C HELIO index maps #2492
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
Open
lacoak21
wants to merge
21
commits into
IMAP-Science-Operations-Center:dev
Choose a base branch
from
lacoak21:ultra_l1c_helio_index_maps
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
a9252f8
helio map func
lacoak21 f10a637
refactor slightly
lacoak21 ca49a6c
validation test
lacoak21 c9d2003
fix tests and pr comments
lacoak21 953de2c
explicitely download validation files for test
lacoak21 0aee193
updated fucntions to handle energy dependent fov and theta and phi lo…
lacoak21 ef3ad9c
remove test for helio adjusted data
lacoak21 7a43d4b
more test updates
lacoak21 4a6e90b
fix inside fov function.
lacoak21 7967b7d
constants for helio maps and inside fov
lacoak21 9a47f06
update pset code and eff, gf functions to handle energy dependent ind…
lacoak21 16ecb7d
Helio pset validation test and fix other tests
lacoak21 f80efb6
rename module
lacoak21 caa4a72
remove kernel hcanges to conftest
lacoak21 c7ad31c
fix test
lacoak21 d020552
full healpy import"
lacoak21 08e0d4c
PR comments. Remove hardcoded constants and offsets.
lacoak21 922aa10
more PR comments addressed
lacoak21 d01fda3
corrected wrong kernel
lacoak21 e22d67e
fix kernel issue
lacoak21 e8c2287
add sim kernel folder to project include list
lacoak21 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,3 +15,4 @@ coverage: | |
| ignore: | ||
| - "**/conftest.py" | ||
| - "**/test_spacecraft_pset.py" | ||
| - "**/test_make_helio_index_maps.py" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| from unittest import mock | ||
|
|
||
| import numpy as np | ||
| import pandas as pd | ||
| import pytest | ||
| import xarray as xr | ||
|
|
||
| from imap_processing import imap_module_directory | ||
| from imap_processing.cdf.utils import load_cdf | ||
| from imap_processing.tests.conftest import _download_external_data | ||
| from imap_processing.ultra.constants import UltraConstants | ||
| from imap_processing.ultra.l1c.helio_pset import calculate_helio_pset | ||
|
|
||
| TEST_PATH = imap_module_directory / "tests" / "ultra" / "data" / "l1" | ||
|
|
||
|
|
||
| @pytest.mark.skip(reason="Long running test for validation purposes.") | ||
| def test_validate_exposure_time_and_sensitivities( | ||
| ancillary_files, deadtime_datasets, imap_ena_sim_metakernel | ||
| ): | ||
| """Validates exposure time and sensitivities for ebin 0.""" | ||
| sens_filename = "SENS-IMAP_ULTRA_90-IMAP_DPS-HELIO-nside32-ebin0.csv" | ||
| exposure_filename = "Exposures-IMAP_ULTRA_90-IMAP_DPS-HELIO-nside32-ebin0.csv" | ||
| de_filename = "imap_ultra_l1b_90sensor-de_20000101-repoint00000_v000.cdf" | ||
| test_data = [ | ||
| (sens_filename, "ultra/data/l1/"), | ||
| (exposure_filename, "ultra/data/l1/"), | ||
| (de_filename, "ultra/data/l1/"), | ||
| ] | ||
| _download_external_data(test_data) | ||
| l1b_de = TEST_PATH / de_filename | ||
| l1b_de = load_cdf(l1b_de) | ||
| sensitivities_ebin_0 = pd.read_csv(TEST_PATH / sens_filename) | ||
| exposure_factor_ebin_0 = pd.read_csv(TEST_PATH / exposure_filename) | ||
|
|
||
| test_deadtimes = ( | ||
| pd.read_csv(TEST_PATH / "test_p0_ebin0_deadtimes.csv", header=None) | ||
| .to_numpy() | ||
| .squeeze() | ||
| ) | ||
| npix = 12288 # nside 32 | ||
| # Create a minimal dataset to pass to the function | ||
| dataset = xr.Dataset( | ||
| { | ||
| "spin_number": (["epoch"], np.array([1, 2, 3])), | ||
| } | ||
| ) | ||
| dataset.attrs["Repointing"] = "repoint00000" | ||
|
|
||
| pointing_range_met = (472374890.0, 582378000.0) | ||
| # Create mock spin data that has 5525 nominal spins | ||
| # Create DataFrame | ||
| nspins = 5522 | ||
| nominal_spin_seconds = 15.0 | ||
| spin_data = pd.DataFrame( | ||
| { | ||
| "spin_start_met": np.linspace( | ||
| pointing_range_met[0], pointing_range_met[1], nspins | ||
| ), | ||
| "spin_period_sec": np.full(nspins, nominal_spin_seconds), | ||
| "spin_phase_valid": np.ones(nspins), | ||
| "spin_period_valid": np.ones(nspins), | ||
| } | ||
| ) | ||
| with ( | ||
| # Mock the pointing times | ||
| mock.patch( | ||
| "imap_processing.ultra.l1c.helio_pset.get_pointing_times_from_id", | ||
| return_value=pointing_range_met, | ||
| ), | ||
| mock.patch( | ||
| "imap_processing.ultra.l1c.ultra_l1c_pset_bins.ttj2000ns_to_met", | ||
| side_effect=lambda x: x, | ||
| ), | ||
| # Mock deadtimes to be all ones | ||
| mock.patch( | ||
| "imap_processing.ultra.l1c.ultra_l1c_pset_bins." | ||
| "get_deadtime_ratios_by_spin_phase", | ||
| return_value=xr.DataArray(test_deadtimes, dims="spin_phase_step"), | ||
| ), | ||
| # Mock spin data to match nominal spins in a pointing period | ||
| mock.patch( | ||
| "imap_processing.ultra.l1c.ultra_l1c_pset_bins.get_spin_data", | ||
| return_value=spin_data, | ||
| ), | ||
| # Mock background rates to be constant 0.1 | ||
| mock.patch( | ||
| "imap_processing.ultra.l1c.helio_pset.get_spacecraft_background_rates", | ||
| return_value=np.ones((46, npix)), | ||
| ), | ||
| # Mock culling mask (no culling) | ||
| mock.patch("imap_processing.ultra.l1c.helio_pset.compute_culling_mask"), | ||
| ): | ||
| pset = calculate_helio_pset( | ||
| l1b_de, | ||
| dataset, | ||
| deadtime_datasets["rates"], | ||
| deadtime_datasets["params"], | ||
| "imap_ultra_l1c_90sensor-heliopset", | ||
| ancillary_files, | ||
| 90, | ||
| UltraConstants.TOFXPH_SPECIES_GROUPS["proton"], | ||
| ) | ||
|
|
||
| # Validate exposure times for ebin 0 | ||
| exposure_times = pset["exposure_factor"][0, 0, :].values | ||
| expected_exposure_times = exposure_factor_ebin_0["P0"].to_numpy() | ||
| np.testing.assert_allclose( | ||
| exposure_times, | ||
| expected_exposure_times, | ||
| atol=95, # TODO This is due to the helio index map differences | ||
| err_msg="Exposure times do not match expected values for ebin 0.", | ||
| ) | ||
| # Validate sensitivities for ebin 0 | ||
| sensitivity = pset["sensitivity"][0, :].values | ||
| expected_sensitivity = sensitivities_ebin_0["Sensitivity (cm2)"].to_numpy() | ||
| np.testing.assert_allclose( | ||
| sensitivity, | ||
| expected_sensitivity, | ||
| atol=0.0006, # TODO This is due to the helio index map differences | ||
| err_msg="Sensitivities times do not match expected values for ebin 0.", | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a utility function
use_fake_spin_data_for_timeandgenerate_fake_spin_datathat youmight be able to use here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use_fake_spin_data_for_time is not giving me the correct number of nominal spins because it is marking some as invalid. I did it this way so I can explicitly set the number of valid spins.