diff --git a/imap_processing/cdf/config/imap_ialirt_global_cdf_attrs.yaml b/imap_processing/cdf/config/imap_ialirt_global_cdf_attrs.yaml index bab66ac8a..395ee6ba9 100644 --- a/imap_processing/cdf/config/imap_ialirt_global_cdf_attrs.yaml +++ b/imap_processing/cdf/config/imap_ialirt_global_cdf_attrs.yaml @@ -9,7 +9,11 @@ instrument_base: &instrument_base HIT (High-energy Ion Telescope), MAG (Magnetometer), and SWAPI (Solar Wind and Pickup Ion). See https://imap.princeton.edu for more details. - Instrument_type: Particles (space), Magnetic Fields (space), Plasma and Solar Wind (space), Ephemeris/Attitude/Ancillary +Instrument_type: + - "Particles (space)" + - "Magnetic Fields (space)" + - "Plasma and Solar Wind (space)" + - "Ephemeris/Attitude/Ancillary" imap_ialirt_l1_realtime: <<: *instrument_base diff --git a/imap_processing/cdf/config/imap_ialirt_l1_variable_attrs.yaml b/imap_processing/cdf/config/imap_ialirt_l1_variable_attrs.yaml index 833ef14a5..b8bb683b0 100644 --- a/imap_processing/cdf/config/imap_ialirt_l1_variable_attrs.yaml +++ b/imap_processing/cdf/config/imap_ialirt_l1_variable_attrs.yaml @@ -183,6 +183,7 @@ codice_hi_energy_center: FILLVAL: -1.0e31 FORMAT: F12.6 dtype: float32 + LABLAXIS: Proton energy bin codice_hi_energy_minus: CATDESC: CoDICE-Hi proton energy bin lower delta (MeV) @@ -194,6 +195,7 @@ codice_hi_energy_minus: FILLVAL: -1.0e31 FORMAT: F12.6 dtype: float32 + LABLAXIS: Energy lower delta codice_hi_energy_plus: CATDESC: CoDICE-Hi proton energy bin upper delta (MeV) @@ -205,6 +207,7 @@ codice_hi_energy_plus: FILLVAL: -1.0e31 FORMAT: F12.6 dtype: float32 + LABLAXIS: Energy upper delta codice_hi_elevation: CATDESC: Elevation Angle @@ -235,6 +238,7 @@ codice_hi_spin_sector: VALIDMIN: 0 VALIDMAX: 3 dtype: int32 + LABLAXIS: Spin sector index codice_hi_spin_sector_labels: CATDESC: CoDICE-Hi spin sector labels @@ -252,7 +256,7 @@ swe_electron_energy: VALIDMIN: 0.0 VALIDMAX: 2000.0 FILLVAL: -1.0e31 - FORMAT: F12.6 + FORMAT: F6.1 dtype: float32 # Variables @@ -269,7 +273,7 @@ codice_hi_h: DEPEND_2: codice_hi_spin_sector DEPEND_3: codice_hi_elevation DISPLAY_TYPE: no_plot - FORMAT: F16.6 + FORMAT: F6.1 VAR_NOTES: Energy ranges (MeV) are 0.0200 to 0.0283, 0.0283 to 0.0400, 0.0400 to 0.0566, 0.0566 to 0.0800, 0.0800 to 0.113, 0.113 to 0.160, 0.160 to 0.226, 0.226 to 0.320, 0.320 to 0.453, 0.453 to 0.640, 0.640 to 0.905, 0.905 to 1.28, 1.28 to 1.81, 1.81 to 2.56, 2.56 to 3.62. codice_lo_c_over_o_abundance: @@ -339,135 +343,135 @@ codice_lo_fe_low_over_fe_high: FORMAT: F16.6 hit_e_a_side_low_en: - <<: *default_uint32 + <<: *default_float32 CATDESC: Count rates from HIT for electrons above 0.5 MeV, A-side aperture (anti-sunward) look direction FIELDNAM: Low energy electron count rate (A-side) LABLAXIS: A-side e- >0.5 MeV DEPEND_0: hit_epoch UNITS: counts per second VALIDMIN: 0 - VALIDMAX: 1000000000 + VALIDMAX: 1000000000.0 VAR_NOTES: A-side indicates the HIT aperture that is nominally looking in the anti-sunward direction. B-side indicates the aperture looking nominally in the sunward direction. hit_e_a_side_med_en: - <<: *default_uint32 + <<: *default_float32 CATDESC: Count rates from HIT for electrons below 1 MeV, A-side aperture (anti-sunward) look direction FIELDNAM: Medium energy electron count rate (A-side) LABLAXIS: A-side e- <1 MeV DEPEND_0: hit_epoch UNITS: counts per second VALIDMIN: 0 - VALIDMAX: 1000000000 + VALIDMAX: 1000000000.0 VAR_NOTES: A-side indicates the HIT aperture that is nominally looking in the anti-sunward direction. B-side indicates the aperture looking nominally in the sunward direction. hit_e_a_side_high_en: - <<: *default_uint32 + <<: *default_float32 CATDESC: High energy (>3 MeV) electron count rate (A-side, anti-sunward) FIELDNAM: High energy electron count rate (A-side) LABLAXIS: A-side e- >3 MeV DEPEND_0: hit_epoch UNITS: counts per second VALIDMIN: 0 - VALIDMAX: 1000000000 + VALIDMAX: 1000000000.0 VAR_NOTES: A-side indicates the HIT aperture that is nominally looking in the anti-sunward direction. B-side indicates the aperture looking nominally in the sunward direction. hit_e_b_side_low_en: - <<: *default_uint32 + <<: *default_float32 CATDESC: Count rates from HIT for electrons above 0.5 MeV, B-side aperture (sunward) look direction FIELDNAM: Low energy electron count rate (B-side) LABLAXIS: B-side e- >0.5 MeV DEPEND_0: hit_epoch UNITS: counts per second VALIDMIN: 0 - VALIDMAX: 1000000000 + VALIDMAX: 1000000000.0 VAR_NOTES: A-side indicates the HIT aperture that is nominally looking in the anti-sunward direction. B-side indicates the aperture looking nominally in the sunward direction. hit_e_b_side_med_en: - <<: *default_uint32 + <<: *default_float32 CATDESC: Count rates from HIT for electrons below 1 MeV, B-side aperture (sunward) look direction FIELDNAM: Medium energy electron count rate (B-side) LABLAXIS: B-side e- <1 MeV DEPEND_0: hit_epoch UNITS: counts per second VALIDMIN: 0 - VALIDMAX: 1000000000 + VALIDMAX: 1000000000.0 VAR_NOTES: A-side indicates the HIT aperture that is nominally looking in the anti-sunward direction. B-side indicates the aperture looking nominally in the sunward direction. hit_e_b_side_high_en: - <<: *default_uint32 + <<: *default_float32 CATDESC: High energy (>3 MeV) electron count rate (B-side, sunward) FIELDNAM: High energy electron count rate (B-side) LABLAXIS: B-side e- >3 MeV DEPEND_0: hit_epoch UNITS: counts per second VALIDMIN: 0 - VALIDMAX: 1000000000 + VALIDMAX: 1000000000.0 VAR_NOTES: A-side indicates the HIT aperture that is nominally looking in the anti-sunward direction. B-side indicates the aperture looking nominally in the sunward direction. hit_h_omni_low_en: - <<: *default_uint32 + <<: *default_float32 CATDESC: Count rates from HIT for protons between 6 to 8 MeV, omnidirectional (sum of particles divided by full sky area) FIELDNAM: Proton count rate 6 to 8 MeV (omni) LABLAXIS: Omni H+ 6 to 8 MeV DEPEND_0: hit_epoch UNITS: counts per second VALIDMIN: 0 - VALIDMAX: 1000000000 + VALIDMAX: 1000000000.0 VAR_NOTES: Omni indicates the sum of the number of particles divided by the area of the full sky. hit_h_omni_med_en: - <<: *default_uint32 + <<: *default_float32 CATDESC: Count rates from HIT for protons between 12 to 15 MeV, omnidirectional (sum of particles divided by full sky area) FIELDNAM: Proton count rate 12 to 15 MeV (omni) LABLAXIS: Omni H+ 12 to 15 MeV DEPEND_0: hit_epoch UNITS: counts per second VALIDMIN: 0 - VALIDMAX: 1000000000 + VALIDMAX: 1000000000.0 VAR_NOTES: Omni indicates the sum of the number of particles divided by the area of the full sky. hit_h_a_side_high_en: - <<: *default_uint32 + <<: *default_float32 CATDESC: High energy (>70 MeV) proton count rate (A-side, anti-sunward) FIELDNAM: Proton count rate >70 MeV (A-side) LABLAXIS: A-side H >70 MeV DEPEND_0: hit_epoch UNITS: counts per second VALIDMIN: 0 - VALIDMAX: 1000000000 + VALIDMAX: 1000000000.0 VAR_NOTES: A-side indicates the HIT aperture that is nominally looking in the anti-sunward direction. B-side indicates the aperture looking nominally in the sunward direction. hit_h_b_side_high_en: - <<: *default_uint32 + <<: *default_float32 CATDESC: High energy (>70 MeV) proton count rate (B-side, sunward) FIELDNAM: Proton count rate >70 MeV (B-side) LABLAXIS: B-side H >70 MeV DEPEND_0: hit_epoch UNITS: counts per second VALIDMIN: 0 - VALIDMAX: 1000000000 + VALIDMAX: 1000000000.0 VAR_NOTES: A-side indicates the HIT aperture that is nominally looking in the anti-sunward direction. B-side indicates the aperture looking nominally in the sunward direction. hit_he_omni_low_en: - <<: *default_uint32 + <<: *default_float32 CATDESC: Count rates from HIT for He4 between 6 to 8 MeV/nuc, omnidirectional (sum of particles divided by full sky area) FIELDNAM: Helium count rate 6 to 8 MeV/nuc (omni) LABLAXIS: Omni He 6 to 8 MeV/nuc DEPEND_0: hit_epoch UNITS: counts per second VALIDMIN: 0 - VALIDMAX: 1000000000 + VALIDMAX: 1000000000.0 VAR_NOTES: Omni indicates the sum of the number of particles divided by the area of the full sky. hit_he_omni_high_en: - <<: *default_uint32 + <<: *default_float32 CATDESC: Count rates from HIT for He4 between 15 to 70 MeV/nuc, omnidirectional (sum of particles divided by full sky area) FIELDNAM: Helium count rate 15 to 70 MeV/nuc (omni) LABLAXIS: Omni He 15 to 70 MeV/nuc DEPEND_0: hit_epoch UNITS: counts per second VALIDMIN: 0 - VALIDMAX: 1000000000 + VALIDMAX: 1000000000.0 VAR_NOTES: Omni indicates the sum of the number of particles divided by the area of the full sky. mag_B_magnitude: @@ -597,9 +601,10 @@ swe_normalized_counts: FIELDNAM: Normalized electron counts UNITS: normalized counts VALIDMIN: 0 - VALIDMAX: 500000 + VALIDMAX: 5000000000000 DEPEND_1: swe_electron_energy DISPLAY_TYPE: stack_plot + SCALETYP: log LABLAXIS: Electron counts DEPEND_0: swe_epoch VAR_NOTES: The nominal central energies for the 8 i-ALiRT channels are 100.4, 140, 194, 270, 376, 523, 727, and 1011 eV. @@ -638,7 +643,7 @@ sc_velocity_GSE: sc_position_GSM: <<: *default_float32 - CATDESC: Spacecraft position vector in GSM coordinates + CATDESC: Spacecraft position in GSM coordinates FIELDNAM: Spacecraft position in GSM coordinates LABLAXIS: SC position (GSM) UNITS: km diff --git a/imap_processing/ialirt/utils/constants.py b/imap_processing/ialirt/utils/constants.py index cb960aa47..f1830248e 100644 --- a/imap_processing/ialirt/utils/constants.py +++ b/imap_processing/ialirt/utils/constants.py @@ -26,12 +26,8 @@ "codice_lo_o_plus_7_over_o_plus_6": ["codice_lo_epoch"], # Fe low/Fe high charge state ratio "codice_lo_fe_low_over_fe_high": ["codice_lo_epoch"], - # Low energy (>0.5 MeV) electrons (A-side) - "hit_e_a_side_low_en": ["hit_epoch"], # Medium energy (<1 MeV) electrons (A-side) "hit_e_a_side_med_en": ["hit_epoch"], - # Low energy (>0.5 MeV) electrons (B-side) - "hit_e_b_side_low_en": ["hit_epoch"], # Medium energy (<1 MeV) electrons (B-side) "hit_e_b_side_med_en": ["hit_epoch"], # Low energy (6 to 8 MeV) protons (Omnidirectional) @@ -89,16 +85,13 @@ "codice_lo_o_plus_7_over_o_plus_6": np.float32, "codice_lo_fe_low_over_fe_high": np.float32, # HIT scalars - "hit_e_a_side_low_en": np.uint32, - "hit_e_a_side_med_en": np.uint32, - "hit_e_b_side_low_en": np.uint32, - "hit_e_b_side_med_en": np.uint32, - "hit_h_omni_low_en": np.uint32, - "hit_h_omni_med_en": np.uint32, - "hit_he_omni_low_en": np.uint32, - "hit_he_omni_high_en": np.uint32, + "hit_e_a_side_med_en": np.float32, + "hit_e_b_side_med_en": np.float32, + "hit_h_omni_low_en": np.float32, + "hit_h_omni_med_en": np.float32, + "hit_he_omni_low_en": np.float32, + "hit_he_omni_high_en": np.float32, # MAG - "mag_epoch": np.int64, # if you are treating this as a data variable "mag_B_magnitude": np.float32, "mag_B_RTN": np.float32, "mag_B_GSE": np.float32, @@ -126,6 +119,8 @@ "hit_e_b_side_high_en", "hit_h_a_side_high_en", "hit_h_b_side_high_en", + "hit_e_a_side_low_en", + "hit_e_b_side_low_en", } codice_hi_energy_center = [ diff --git a/imap_processing/ialirt/utils/create_xarray.py b/imap_processing/ialirt/utils/create_xarray.py index be8a069d9..d55d22526 100644 --- a/imap_processing/ialirt/utils/create_xarray.py +++ b/imap_processing/ialirt/utils/create_xarray.py @@ -267,22 +267,34 @@ def create_xarray_from_records(records: list[dict]) -> xr.Dataset: # noqa: PLR0 for i, record in enumerate(by_inst.get("codice_lo", [])): for key in IALIRT_DIMS.keys(): - if key.startswith("codice_lo_"): - dataset[key].data[i] = np.float32(record[key]) + val = record.get(key) + if ( + key.startswith("codice_lo_") + and key != "codice_lo_epoch" + and val is not None + ): + dataset[key].data[i] = np.float32(val) for i, record in enumerate(by_inst.get("hit", [])): for key in IALIRT_DIMS.keys(): - if key.startswith("hit_") and key not in hit_restricted_fields: - dataset[key].data[i] = np.uint32(record[key]) + val = record.get(key) + if ( + key.startswith("hit_") + and key != "hit_epoch" + and val is not None + and key not in hit_restricted_fields + ): + dataset[key].data[i] = np.float32(val) for i, record in enumerate(by_inst.get("swapi", [])): for key in IALIRT_DIMS.keys(): - if key.startswith("swapi_"): - dataset[key].data[i] = np.float32(record[key]) + val = record.get(key) + if key.startswith("swapi_") and key != "swapi_epoch" and val is not None: + dataset[key].data[i] = np.float32(val) for i, record in enumerate(by_inst.get("swe", [])): dataset["swe_normalized_counts"].data[i, :] = np.asarray( - record["swe_normalized_counts"], dtype=np.uint32 + record["swe_normalized_counts"], dtype=np.int64 ) dataset["swe_counterstreaming_electrons"].data[i] = np.uint8( record["swe_counterstreaming_electrons"] diff --git a/imap_processing/tests/ialirt/unit/test_create_xarray.py b/imap_processing/tests/ialirt/unit/test_create_xarray.py index 5e8c3d65b..a5876b50d 100644 --- a/imap_processing/tests/ialirt/unit/test_create_xarray.py +++ b/imap_processing/tests/ialirt/unit/test_create_xarray.py @@ -139,10 +139,6 @@ def test_create_dataset(): dataset["swe_normalized_counts"].values[0], np.zeros(8, dtype=np.uint32), ) - np.testing.assert_allclose( - dataset["hit_e_a_side_low_en"].values, - [0.0], - ) np.testing.assert_allclose( dataset["mag_B_GSE"].sel(mag_epoch=123456789000001).values, [5.0, -3.2, 1.1], @@ -165,6 +161,8 @@ def test_create_dataset(): # Tests that you can write to a cdf. dataset.attrs["Data_version"] = "001" dataset.attrs["Start_date"] = "20260114" - test_data_path = write_cdf(dataset, istp=True, compression=None) + test_data_path = write_cdf( + dataset, istp=True, auto_fix_depends=False, compression=None + ) assert test_data_path.exists()