-
Notifications
You must be signed in to change notification settings - Fork 19
I-ALiRT: Create SWAPI count rate optimization function #1705
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
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
"""Module for constants and useful shared classes used in I-ALiRT processing.""" | ||
|
||
from dataclasses import dataclass | ||
|
||
import numpy as np | ||
|
||
|
||
@dataclass(frozen=True) | ||
class IalirtSwapiConstants: | ||
""" | ||
Constants for I-ALiRT SWAPI which can be used across different levels or classes. | ||
|
||
Attributes | ||
---------- | ||
BOLTZ: float | ||
Boltzmann constant [J/K] | ||
AT_MASS: float | ||
Atomic mass [kg] | ||
PROT_MASS: float | ||
Mass of proton [kg] | ||
EFF_AREA: float | ||
Instrument effective area [m^2] | ||
AZ_FOV: float | ||
Azimuthal width of the field of view for solar wind [radians] | ||
FWHM_WIDTH: float | ||
Full Width at Half Maximum of energy width [unitless] | ||
SPEED_EW: float | ||
Speed width of energy passband [unitless] | ||
""" | ||
|
||
# Scientific constants used in optimization model | ||
boltz = 1.380649e-23 # Boltzmann constant, J/K | ||
at_mass = 1.6605390666e-27 # atomic mass, kg | ||
prot_mass = 1.007276466621 * at_mass # mass of proton, kg | ||
eff_area = 3.3e-5 * 1e-4 # effective area, meters squared | ||
az_fov = np.deg2rad(30) # azimuthal width of the field of view, radians | ||
fwhm_width = 0.085 # FWHM of energy width | ||
speed_ew = 0.5 * fwhm_width # speed width of energy passband |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
Energy [eV/q],Count Rates [Hz],Count Rates Error [Hz] | ||
19098.3579,0.00E+00,0 | ||
19098.3579,0.00E+00,0 | ||
17541.17689,0.00E+00,0 | ||
16113.17733,0.00E+00,0 | ||
14798.37998,0.00E+00,0 | ||
13591.36578,0.00E+00,0 | ||
12485.77704,0.00E+00,0 | ||
11467.61829,0.00E+00,0 | ||
10532.60822,0.00E+00,0 | ||
9675.514168,0.00E+00,0 | ||
8885.04638,0.00E+00,0 | ||
8165.393845,0.00E+00,0 | ||
7501.760233,0.00E+00,0 | ||
6888.477149,0.00E+00,0 | ||
6327.926581,0.00E+00,0 | ||
5811.486083,0.00E+00,0 | ||
5338.867546,0.00E+00,0 | ||
4901.30318,0.00E+00,0 | ||
4504.29887,6.00E+00,5.988024 | ||
4138.38252,0.00E+00,0 | ||
3800.760624,0.00E+00,0 | ||
3490.866227,6.00E+00,5.988024 | ||
3205.462334,2.40E+01,11.976048 | ||
2944.699516,3.00E+01,13.389629 | ||
2705.519228,1.20E+01,8.468345 | ||
2485.023495,6.00E+00,5.988024 | ||
2281.728846,6.00E+00,5.988024 | ||
2094.335628,1.80E+01,10.371562 | ||
1921.410538,2.58E+02,39.266099 | ||
1764.61444,8.70E+02,72.105357 | ||
1621.075258,1.37E+03,90.615245 | ||
1489.379616,1.25E+03,86.567858 | ||
1369.25523,6.72E+02,63.371289 | ||
1257.562068,2.46E+02,38.342061 | ||
1155.04315,3.00E+01,13.389629 | ||
1061.325411,6.00E+00,5.988024 | ||
974.875126,0.00E+00,0 | ||
895.314188,0.00E+00,0 | ||
822.018852,0.00E+00,0 | ||
754.982368,0.00E+00,0 | ||
693.547324,0.00E+00,0 | ||
636.793361,0.00E+00,0 | ||
584.81978,0.00E+00,0 | ||
537.016673,0.00E+00,0 | ||
493.208286,0.00E+00,0 | ||
453.103315,0.00E+00,0 | ||
416.133867,0.00E+00,0 | ||
382.037059,0.00E+00,0 | ||
350.921008,0.00E+00,0 | ||
322.396008,0.00E+00,0 | ||
296.176976,0.00E+00,0 | ||
271.952917,0.00E+00,0 | ||
249.936708,0.00E+00,0 | ||
229.494886,0.00E+00,0 | ||
210.757138,0.00E+00,0 | ||
193.581931,0.00E+00,0 | ||
177.766309,0.00E+00,0 | ||
163.295895,0.00E+00,0 | ||
150.015166,0.00E+00,0 | ||
137.803904,0.00E+00,0 | ||
126.579577,0.00E+00,0 | ||
116.253172,0.00E+00,0 | ||
106.797953,0.00E+00,0 | ||
1764.61444,8.70E+02,72.105357 | ||
1727.604298,9.18E+02,73.913169 | ||
1691.370389,9.66E+02,75.720982 | ||
1655.896431,1.01E+03,77.528795 | ||
1621.166486,1.06E+03,79.336607 | ||
1587.16495,1.11E+03,81.14442 | ||
1553.876545,1.16E+03,82.952233 | ||
1521.286315,1.21E+03,84.760045 | ||
1489.379616,1.25E+03,86.567858 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,11 @@ | |
import pytest | ||
|
||
from imap_processing import imap_module_directory | ||
from imap_processing.ialirt.l0.process_swapi import process_swapi_ialirt | ||
from imap_processing.ialirt.l0.process_swapi import ( | ||
count_rate, | ||
optimize_pseudo_parameters, | ||
process_swapi_ialirt, | ||
) | ||
from imap_processing.utils import packet_file_to_datasets | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make certain to add a test for the count_rates function. |
||
|
||
|
@@ -87,7 +91,36 @@ def test_decom_packets(xarray_data, swapi_test_data): | |
|
||
|
||
def test_process_swapi_ialirt(xarray_data): | ||
"""Placeholder test for the process_swapi_ialirt function.""" | ||
"""Test that the process_swapi_ialirt function returns expected keys.""" | ||
|
||
swapi_result = process_swapi_ialirt(xarray_data) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Based on the description of the test, add some more keys to test. |
||
assert swapi_result["met"] is not None | ||
assert len(swapi_result["met"]) == len(swapi_result["pseudo_temperature"]) | ||
assert len(swapi_result["pseudo_density"]) == len(swapi_result["pseudo_speed"]) | ||
|
||
|
||
def test_count_rate(): | ||
"""Use random realistic values to test for expected output of count_rate.""" | ||
actual_result = count_rate(1370, *[550, 5.27, 1e5]) | ||
expected_result = 621.0028766348703 | ||
assert actual_result == expected_result | ||
|
||
|
||
def test_optimize_parameters(xarray_data): | ||
"""Test the optimize_pseudo_parameters function.""" | ||
|
||
energy_data = pd.read_csv( | ||
f"{imap_module_directory}/tests/ialirt/test_data/ialirt_test_data.csv" | ||
) | ||
count_rates = energy_data["Count Rates [Hz]"].to_numpy() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So will count_rates be a lookup table that is used in operations? Or is it just test data? If it's a lookup table we should put it in the ialirt (not test) directory. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @bishwassth are the energy steps in the spreadsheet you sent me (in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The first 63 energy steps are very close to what will be used for real-time processing, but may not be exactly similar. The energies for real-time processing will be from the ESA unit conversion ADP and will be in the form of a lookup table (e.g., Table 3 in the algorithms document). BTW, could you confirm if the I-ALiRT code is using "ESA unit conversion ADP" or not? If not, we have to supply them in a different lookup table. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see the file called There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, that is the correct file to use. You have to read the columns for "Energy" in this file from ESA step # 0-62. Note that the energy values for the first 34 ESA step # (0-33) are fixed to "1,163", which will be updated to realistic values in space. |
||
count_rates = np.tile(count_rates, (2, 1)) | ||
result = optimize_pseudo_parameters(count_rates) | ||
|
||
# Test values corresponding to this exact set and values of the test input. | ||
expected_speed = [542.9522302014949, 542.9522302014949] | ||
expected_density = [4.504282147321004, 4.504282147321004] | ||
expected_temperature = [143238.45841298936, 143238.45841298936] | ||
|
||
assert result["pseudo_speed"] == expected_speed | ||
assert result["pseudo_density"] == expected_density | ||
assert result["pseudo_temperature"] == expected_temperature |
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.
Why is this the guess 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.
I thought it should go before the function call. Do you think it should be elsewhere?
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.
Laura suggested adding a comment explaining where this guess was pulled from in the algorithm document.
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.
The initial guess for the pseudo-speed can be obtained from the energy corresponding to the maximum/peak count rate (energy_peak_rate), i.e.,
speed_guess = sqrt(2 * energy_peak_rate * 1.60218e-19 / proton_mass)/1000 km/s.
It is not straightforward to come up with a good initial guess for the pseudo-density and temperature. Some nominal values, like the following, should be okay.
dens_guess = 5 cm^-3, and
T_guess = 1e5 K.