From ca85ceeda59d80a269aeef12c22e4ad25f6058bd Mon Sep 17 00:00:00 2001 From: Tenzin Choedon <36522642+tech3371@users.noreply.github.com> Date: Mon, 29 Jul 2024 09:56:50 -0600 Subject: [PATCH] Refactor epoch attrs (#718) --- imap_processing/cdf/__init__.py | 5 ---- .../imap_codice_l1a_variable_attrs.yaml | 16 ------------ .../imap_codice_l1b_variable_attrs.yaml | 16 ------------ .../config/imap_glows_l1a_variable_attrs.yaml | 18 ------------- .../config/imap_glows_l1b_variable_attrs.yaml | 16 ------------ .../cdf/config/imap_hi_variable_attrs.yaml | 25 ------------------- .../config/imap_hit_l1a_variable_attrs.yaml | 16 ------------ .../config/imap_hit_l1b_variable_attrs.yaml | 16 ------------ .../config/imap_idex_l1_variable_attrs.yaml | 17 ------------- .../config/imap_lo_l1a_variable_attrs.yaml | 16 ------------ .../config/imap_lo_l1b_variable_attrs.yaml | 16 ------------ .../config/imap_lo_l1c_variable_attrs.yaml | 16 ------------ .../config/imap_mag_l1_variable_attrs.yaml | 16 ------------ .../config/imap_swe_l1a_variable_attrs.yaml | 17 ------------- .../config/imap_swe_l1b_variable_attrs.yaml | 17 ------------- .../config/imap_ultra_l1b_variable_attrs.yaml | 13 ---------- .../config/imap_ultra_l1c_variable_attrs.yaml | 13 ---------- imap_processing/codice/codice_l1a.py | 2 +- imap_processing/codice/utils.py | 3 +-- imap_processing/glows/l1b/glows_l1b.py | 2 +- imap_processing/hi/l1a/histogram.py | 2 +- .../hi/l1a/science_direct_event.py | 7 +++++- imap_processing/hi/l1c/hi_l1c.py | 8 +++--- imap_processing/lo/l1a/lo_l1a_write_cdfs.py | 3 +-- imap_processing/mag/l0/decom_mag.py | 3 +-- imap_processing/mag/l1a/mag_l1a.py | 3 +-- imap_processing/swapi/l1/swapi_l1.py | 3 +-- imap_processing/tests/cdf/test_utils.py | 3 +-- imap_processing/tests/glows/test_glows_l1b.py | 4 +-- imap_processing/tests/hi/test_hi_l1c.py | 5 ++-- imap_processing/ultra/utils/ultra_l1_utils.py | 12 +++------ imap_processing/utils.py | 3 +-- 32 files changed, 27 insertions(+), 305 deletions(-) diff --git a/imap_processing/cdf/__init__.py b/imap_processing/cdf/__init__.py index f56ecf2d1..e69de29bb 100644 --- a/imap_processing/cdf/__init__.py +++ b/imap_processing/cdf/__init__.py @@ -1,5 +0,0 @@ -from imap_processing.cdf.imap_cdf_manager import ImapCdfAttributes - -# Load Epoch CDF attributes -cdf_manager = ImapCdfAttributes() -epoch_attrs = cdf_manager.get_variable_attributes("epoch") diff --git a/imap_processing/cdf/config/imap_codice_l1a_variable_attrs.yaml b/imap_processing/cdf/config/imap_codice_l1a_variable_attrs.yaml index 20c18384a..2407e77aa 100644 --- a/imap_processing/cdf/config/imap_codice_l1a_variable_attrs.yaml +++ b/imap_processing/cdf/config/imap_codice_l1a_variable_attrs.yaml @@ -26,22 +26,6 @@ energy_attrs: VALIDMAX: 127 VAR_TYPE: support_data -epoch_attrs: - CATDESC: Time, number of nanoseconds since J2000 with leap seconds included - FIELDNAM: epoch - LABLAXIS: epoch - FILLVAL: -9223372036854775808 - FORMAT: " " # Supposedly not required, fails in xarray_to_cdf - VALIDMIN: -9223372036854775808 - VALIDMAX: 9223372036854775807 - UNITS: ns - VAR_TYPE: support_data - SCALETYP: linear - MONOTON: INCREASE - TIME_BASE: J2000 - TIME_SCALE: Terrestrial Time - REFERENCE_POSITION: Rotating Earth Geoid - # <=== Labels ===> energy_label: CATDESC: Energy per charge (E/q) sweeping step diff --git a/imap_processing/cdf/config/imap_codice_l1b_variable_attrs.yaml b/imap_processing/cdf/config/imap_codice_l1b_variable_attrs.yaml index 268a5b848..90c79664f 100644 --- a/imap_processing/cdf/config/imap_codice_l1b_variable_attrs.yaml +++ b/imap_processing/cdf/config/imap_codice_l1b_variable_attrs.yaml @@ -26,22 +26,6 @@ energy_attrs: VALIDMAX: 127 VAR_TYPE: support_data -epoch_attrs: - CATDESC: Time, number of nanoseconds since J2000 with leap seconds included - FIELDNAM: epoch - LABLAXIS: epoch - FILLVAL: -9223372036854775808 - FORMAT: " " # Supposedly not required, fails in xarray_to_cdf - VALIDMIN: -9223372036854775808 - VALIDMAX: 9223372036854775807 - UNITS: ns - VAR_TYPE: support_data - SCALETYP: linear - MONOTON: INCREASE - TIME_BASE: J2000 - TIME_SCALE: Terrestrial Time - REFERENCE_POSITION: Rotating Earth Geoid - # <=== Labels ===> energy_label: CATDESC: Energy per charge (E/q) sweeping step diff --git a/imap_processing/cdf/config/imap_glows_l1a_variable_attrs.yaml b/imap_processing/cdf/config/imap_glows_l1a_variable_attrs.yaml index 28ba730c9..a517748db 100644 --- a/imap_processing/cdf/config/imap_glows_l1a_variable_attrs.yaml +++ b/imap_processing/cdf/config/imap_glows_l1a_variable_attrs.yaml @@ -19,24 +19,6 @@ default_attrs: &default_attrs FILLVAL: *int_fillval VALIDMIN: *min_epoch -# Information found in cdf.config.global_attrs.py EPOCH, and cdf.defaults.py -epoch: - <<: *default_attrs - CATDESC: Time, number of nanoseconds since J2000 with leap seconds included - FIELDNAM: epoch - FILLVAL: *int_fillval # GlobalConstants.INT_FILLVAL, - LABLAXIS: epoch - FORMAT: "" # Supposedly not required, fails in xarray_to_cdf - UNITS: ns - VALIDMIN: *min_epoch # GlobalConstants.MIN_EPOCH - VALIDMAX: *max_epoch # GlobalConstants.MAX_EPOCH - VAR_TYPE: support_data - SCALETYP: linear - MONOTON: INCREASE - TIME_BASE: J2000 - TIME_SCALE: Terrestrial Time - REFERENCE_POSITION: Rotating Earth Geoid - # Information from glows_cdf_attrs.py bins_attrs: <<: *default_attrs diff --git a/imap_processing/cdf/config/imap_glows_l1b_variable_attrs.yaml b/imap_processing/cdf/config/imap_glows_l1b_variable_attrs.yaml index 8e9faa101..ee3b3904e 100644 --- a/imap_processing/cdf/config/imap_glows_l1b_variable_attrs.yaml +++ b/imap_processing/cdf/config/imap_glows_l1b_variable_attrs.yaml @@ -1,22 +1,6 @@ int_fillval: &int_fillval -9223372036854775808 valid_max: &valid_max 3155630469184000000 -epoch_dim: - CATDESC: Time, number of nanoseconds since J2000 with leap seconds included - FIELDNAM: epoch - FILLVAL: *int_fillval - LABLAXIS: epoch - FORMAT: ' ' # Supposedly not required fails in xarray_to_cdf - UNITS: ns - VALIDMIN: -315575942816000000 - VALIDMAX: 3155630469184000000 - VAR_TYPE: support_data - SCALETYP: linear - MONOTON: INCREASE - TIME_BASE: J2000 - TIME_SCALE: Terrestrial Time - REFERENCE_POSITION: Rotating Earth Geoid - default_attrs: &default # Assumed values for all variable attrs unless overwritten DEPEND_0: epoch diff --git a/imap_processing/cdf/config/imap_hi_variable_attrs.yaml b/imap_processing/cdf/config/imap_hi_variable_attrs.yaml index 773993af3..a450acc34 100644 --- a/imap_processing/cdf/config/imap_hi_variable_attrs.yaml +++ b/imap_processing/cdf/config/imap_hi_variable_attrs.yaml @@ -55,23 +55,6 @@ default_float32_attrs: &default_float32 VALIDMAX: 3.4028235e+38 dtype: float32 -default_epoch: &default_epoch - CATDESC: Time, number of nanoseconds since J2000 with leap seconds included - FIELDNAM: epoch - LABLAXIS: epoch - FILLVAL: -9223372036854775808 - FORMAT: " " # Supposedly not required, fails in xarray_to_cdf - VALIDMIN: -9223372036854775808 - VALIDMAX: 9223372036854775807 - UNITS: ns - VAR_TYPE: support_data - SCALETYP: linear - MONOTON: INCREASE - TIME_BASE: J2000 - TIME_SCALE: Terrestrial Time - REFERENCE_POSITION: Rotating Earth Geoid - dtype: int64 - default_ccsds_met: &hi_ccsds_met <<: *default_uint32 CATDESC: CCSDS mission elapsed time (MET). 32-bit integer value that represents the MET in seconds. @@ -104,10 +87,6 @@ hi_de_de_tag: FIELDNAM: Direct Event Time Tag LABLAXIS: DE Time Tag -hi_de_epoch: - <<: *default_epoch - CATDESC: Direct Event time, number of nanoseconds since J2000 with leap seconds included - hi_de_esa_stepping_num: <<: *hi_esa_stepping_num @@ -178,8 +157,6 @@ hi_de_tof_3: the direct event. 1023 is the value used to indicate no event was registered. # ======= L1A HIST Section ======= -hi_hist_epoch: - <<: *default_epoch hi_hist_angle: SCALE_TYPE: linear @@ -317,8 +294,6 @@ hi_de_nominal_bin: VALIDMAX: 89 # ======= L1C PSET Section ======= -hi_pset_epoch: - <<: *default_epoch hi_pset_esa_step: <<: *default_esa_step diff --git a/imap_processing/cdf/config/imap_hit_l1a_variable_attrs.yaml b/imap_processing/cdf/config/imap_hit_l1a_variable_attrs.yaml index 0eaddb2ba..c04599d73 100644 --- a/imap_processing/cdf/config/imap_hit_l1a_variable_attrs.yaml +++ b/imap_processing/cdf/config/imap_hit_l1a_variable_attrs.yaml @@ -20,22 +20,6 @@ hk_support_attrs: &support_default VAR_TYPE: ignore_data # <=== Coordinates ===> -epoch: - CATDESC: Time, number of nanoseconds since J2000 with leap seconds included - FIELDNAM: epoch - LABLAXIS: epoch - FILLVAL: -9223372036854775808 - FORMAT: " " # Supposedly not required, fails in xarray_to_cdf - VALIDMIN: -9223372036854775808 - VALIDMAX: 9223372036854775807 - UNITS: ns - VAR_TYPE: support_data - SCALETYP: linear - MONOTON: INCREASE - TIME_BASE: J2000 - TIME_SCALE: Terrestrial Time - REFERENCE_POSITION: Rotating Earth Geoid - adc_channels: # adc_channels is a dependency for leak_i data variable DISPLAY_TYPE: no_plot FILLVAL: -9223372036854775808 diff --git a/imap_processing/cdf/config/imap_hit_l1b_variable_attrs.yaml b/imap_processing/cdf/config/imap_hit_l1b_variable_attrs.yaml index 0223d9df7..7492a4a63 100644 --- a/imap_processing/cdf/config/imap_hit_l1b_variable_attrs.yaml +++ b/imap_processing/cdf/config/imap_hit_l1b_variable_attrs.yaml @@ -20,22 +20,6 @@ hk_support_attrs: &support_default VAR_TYPE: ignore_data # <=== Coordinates ===> -epoch: - CATDESC: Time, number of nanoseconds since J2000 with leap seconds included - FIELDNAM: epoch - LABLAXIS: epoch - FILLVAL: -9223372036854775808 - FORMAT: " " # Supposedly not required, fails in xarray_to_cdf - VALIDMIN: -9223372036854775808 - VALIDMAX: 9223372036854775807 - UNITS: ns - VAR_TYPE: support_data - SCALETYP: linear - MONOTON: INCREASE - TIME_BASE: J2000 - TIME_SCALE: Terrestrial Time - REFERENCE_POSITION: Rotating Earth Geoid - adc_channels: # adc_channels is a dependency for leak_i data variable DISPLAY_TYPE: no_plot FILLVAL: -9223372036854775808 diff --git a/imap_processing/cdf/config/imap_idex_l1_variable_attrs.yaml b/imap_processing/cdf/config/imap_idex_l1_variable_attrs.yaml index b0e541ef4..5e8774f7f 100644 --- a/imap_processing/cdf/config/imap_idex_l1_variable_attrs.yaml +++ b/imap_processing/cdf/config/imap_idex_l1_variable_attrs.yaml @@ -32,23 +32,6 @@ l1_target_base: &l1_target_base <<: *l1_data_base DEPEND_1: time_low_sr -epoch: - <<: *l1_data_base - CATDESC: Time, number of nanoseconds since J2000 with leap seconds included - FIELDNAM: epoch - FILLVAL: *int_fillval - LABLAXIS: epoch - FORMAT: "" # Supposedly not required, fails in xarray_to_cdf - UNITS: ns - VALIDMIN: *min_epoch - VALIDMAX: *max_epoch - VAR_TYPE: support_data - SCALETYP: linear - MONOTON: INCREASE - TIME_BASE: J2000 - TIME_SCALE: Terrestrial Time - REFERENCE_POSITION: Rotating Earth Geoid - sample_rate_base: &sample_rate_base DISPLAY_TYPE: no_plot CATDESC: "" diff --git a/imap_processing/cdf/config/imap_lo_l1a_variable_attrs.yaml b/imap_processing/cdf/config/imap_lo_l1a_variable_attrs.yaml index a0544983b..2b9d44c2b 100644 --- a/imap_processing/cdf/config/imap_lo_l1a_variable_attrs.yaml +++ b/imap_processing/cdf/config/imap_lo_l1a_variable_attrs.yaml @@ -18,22 +18,6 @@ de_default_attrs: &de_default DEPEND_1: direct_events UNITS: ' ' -epoch: - CATDESC: Time, number of nanoseconds since J2000 with leap seconds included - FIELDNAM: epoch - LABLAXIS: epoch - FILLVAL: -9223372036854775808 - FORMAT: " " # Supposedly not required, fails in xarray_to_cdf - VALIDMIN: -9223372036854775808 - VALIDMAX: 9223372036854775807 - UNITS: ns - VAR_TYPE: support_data - SCALETYP: linear - MONOTON: INCREASE - TIME_BASE: J2000 - TIME_SCALE: Terrestrial Time - REFERENCE_POSITION: Rotating Earth Geoid - # Re-used Coordinate esa_step: <<: *de_default diff --git a/imap_processing/cdf/config/imap_lo_l1b_variable_attrs.yaml b/imap_processing/cdf/config/imap_lo_l1b_variable_attrs.yaml index 4730e411b..0e5745958 100644 --- a/imap_processing/cdf/config/imap_lo_l1b_variable_attrs.yaml +++ b/imap_processing/cdf/config/imap_lo_l1b_variable_attrs.yaml @@ -9,22 +9,6 @@ default_attrs: &default VAR_TYPE: data UNITS: ' ' -epoch: - CATDESC: Time, number of nanoseconds since J2000 with leap seconds included - FIELDNAM: epoch - LABLAXIS: epoch - FILLVAL: -9223372036854775808 - FORMAT: " " # Supposedly not required, fails in xarray_to_cdf - VALIDMIN: -9223372036854775808 - VALIDMAX: 9223372036854775807 - UNITS: ns - VAR_TYPE: support_data - SCALETYP: linear - MONOTON: INCREASE - TIME_BASE: J2000 - TIME_SCALE: Terrestrial Time - REFERENCE_POSITION: Rotating Earth Geoid - direction_vec_label: CATDESC: Directional vector for each direct event FIELDNAM: Direction Vector (X, Y, Z) diff --git a/imap_processing/cdf/config/imap_lo_l1c_variable_attrs.yaml b/imap_processing/cdf/config/imap_lo_l1c_variable_attrs.yaml index 795b2d219..e78cbdb2a 100644 --- a/imap_processing/cdf/config/imap_lo_l1c_variable_attrs.yaml +++ b/imap_processing/cdf/config/imap_lo_l1c_variable_attrs.yaml @@ -9,22 +9,6 @@ default_attrs: &default VAR_TYPE: data UNITS: ' ' -epoch: - CATDESC: Time, number of nanoseconds since J2000 with leap seconds included - FIELDNAM: epoch - LABLAXIS: epoch - FILLVAL: -9223372036854775808 - FORMAT: " " # Supposedly not required, fails in xarray_to_cdf - VALIDMIN: -9223372036854775808 - VALIDMAX: 9223372036854775807 - UNITS: ns - VAR_TYPE: support_data - SCALETYP: linear - MONOTON: INCREASE - TIME_BASE: J2000 - TIME_SCALE: Terrestrial Time - REFERENCE_POSITION: Rotating Earth Geoid - # Non-epoch Coordinates esa_step_label: CATDESC: ESA Steps diff --git a/imap_processing/cdf/config/imap_mag_l1_variable_attrs.yaml b/imap_processing/cdf/config/imap_mag_l1_variable_attrs.yaml index dd7ed75a6..a26d92975 100644 --- a/imap_processing/cdf/config/imap_mag_l1_variable_attrs.yaml +++ b/imap_processing/cdf/config/imap_mag_l1_variable_attrs.yaml @@ -1,19 +1,3 @@ -epoch: - CATDESC: Time, number of nanoseconds since J2000 with leap seconds included - FIELDNAM: epoch - LABLAXIS: epoch - FILLVAL: -9223372036854775808 - FORMAT: " " # Supposedly not required, fails in xarray_to_cdf - VALIDMIN: -9223372036854775808 - VALIDMAX: 9223372036854775807 - UNITS: ns - VAR_TYPE: support_data - SCALETYP: linear - MONOTON: INCREASE - TIME_BASE: J2000 - TIME_SCALE: Terrestrial Time - REFERENCE_POSITION: Rotating Earth Geoid - default_attrs: &default # Assumed values for all variable attrs unless overwritten DEPEND_0: epoch diff --git a/imap_processing/cdf/config/imap_swe_l1a_variable_attrs.yaml b/imap_processing/cdf/config/imap_swe_l1a_variable_attrs.yaml index d4c418474..93375f2ec 100644 --- a/imap_processing/cdf/config/imap_swe_l1a_variable_attrs.yaml +++ b/imap_processing/cdf/config/imap_swe_l1a_variable_attrs.yaml @@ -44,23 +44,6 @@ polar_angle_label: FORMAT: A1 VAR_TYPE: metadata -# TODO: how to avoid repeating this? -epoch: - CATDESC: Time, number of nanoseconds since J2000 with leap seconds included - FIELDNAM: epoch - LABLAXIS: epoch - FILLVAL: -9223372036854775808 - FORMAT: " " # Supposedly not required, fails in xarray_to_cdf - VALIDMIN: -9223372036854775808 - VALIDMAX: 9223372036854775807 - UNITS: ns - VAR_TYPE: support_data - SCALETYP: linear - MONOTON: INCREASE - TIME_BASE: J2000 - TIME_SCALE: Terrestrial Time - REFERENCE_POSITION: Rotating Earth Geoid - # <=== Data Variables ===> # Default Attrs for all data variables unless overridden diff --git a/imap_processing/cdf/config/imap_swe_l1b_variable_attrs.yaml b/imap_processing/cdf/config/imap_swe_l1b_variable_attrs.yaml index 86757761f..962ee8642 100644 --- a/imap_processing/cdf/config/imap_swe_l1b_variable_attrs.yaml +++ b/imap_processing/cdf/config/imap_swe_l1b_variable_attrs.yaml @@ -68,23 +68,6 @@ cem_label: FORMAT: A1 VAR_TYPE: metadata -# TODO: how to avoid repeating this? -epoch: - CATDESC: Time, number of nanoseconds since J2000 with leap seconds included - FIELDNAM: epoch - LABLAXIS: epoch - FILLVAL: -9223372036854775808 - FORMAT: " " # Supposedly not required, fails in xarray_to_cdf - VALIDMIN: -9223372036854775808 - VALIDMAX: 9223372036854775807 - UNITS: ns - VAR_TYPE: support_data - SCALETYP: linear - MONOTON: INCREASE - TIME_BASE: J2000 - TIME_SCALE: Terrestrial Time - REFERENCE_POSITION: Rotating Earth Geoid - # <=== Data Variables ===> # Default Attrs for all data variables unless overridden diff --git a/imap_processing/cdf/config/imap_ultra_l1b_variable_attrs.yaml b/imap_processing/cdf/config/imap_ultra_l1b_variable_attrs.yaml index fdb826007..a33b4d9f0 100644 --- a/imap_processing/cdf/config/imap_ultra_l1b_variable_attrs.yaml +++ b/imap_processing/cdf/config/imap_ultra_l1b_variable_attrs.yaml @@ -8,19 +8,6 @@ default_attrs: &default VALIDMAX: 9223372036854775807 VAR_TYPE: data -epoch: - <<: *default - CATDESC: Time, number of nanoseconds since J2000 with leap seconds included - FIELDNAM: epoch - LABLAXIS: epoch - UNITS: ns - VAR_TYPE: support_data - SCALETYP: linear - MONOTON: INCREASE - TIME_BASE: J2000 - TIME_SCALE: Terrestrial Time - REFERENCE_POSITION: Rotating Earth Geoid - x_front: <<: *default CATDESC: x front position diff --git a/imap_processing/cdf/config/imap_ultra_l1c_variable_attrs.yaml b/imap_processing/cdf/config/imap_ultra_l1c_variable_attrs.yaml index 0667990ac..c49c6a696 100644 --- a/imap_processing/cdf/config/imap_ultra_l1c_variable_attrs.yaml +++ b/imap_processing/cdf/config/imap_ultra_l1c_variable_attrs.yaml @@ -8,19 +8,6 @@ default_attrs: &default VALIDMAX: 9223372036854775807 VAR_TYPE: data -epoch: - <<: *default - CATDESC: Time, number of nanoseconds since J2000 with leap seconds included - FIELDNAM: epoch - LABLAXIS: epoch - UNITS: ns - VAR_TYPE: support_data - SCALETYP: linear - MONOTON: INCREASE - TIME_BASE: J2000 - TIME_SCALE: Terrestrial Time - REFERENCE_POSITION: Rotating Earth Geoid - spin_angle: <<: *default CATDESC: Angular bin defined by central location of the bin diff --git a/imap_processing/codice/codice_l1a.py b/imap_processing/codice/codice_l1a.py index f38e9cc55..9beafa9a5 100644 --- a/imap_processing/codice/codice_l1a.py +++ b/imap_processing/codice/codice_l1a.py @@ -108,7 +108,7 @@ def create_science_dataset(self, met: np.int64, data_version: str) -> xr.Dataset met_to_j2000ns(met), # TODO: Fix after SIT-3 (see note below) name="epoch", dims=["epoch"], - attrs=cdf_attrs.get_variable_attributes("epoch_attrs"), + attrs=cdf_attrs.get_variable_attributes("epoch"), ) energy_steps = xr.DataArray( np.arange(self.num_energy_steps), diff --git a/imap_processing/codice/utils.py b/imap_processing/codice/utils.py index 19dda4f95..a4a7e8560 100644 --- a/imap_processing/codice/utils.py +++ b/imap_processing/codice/utils.py @@ -12,7 +12,6 @@ import space_packet_parser import xarray as xr -from imap_processing.cdf import epoch_attrs from imap_processing.cdf.imap_cdf_manager import ImapCdfAttributes from imap_processing.cdf.utils import met_to_j2000ns @@ -140,7 +139,7 @@ def create_hskp_dataset( # type: ignore[no-untyped-def] ), name="epoch", dims=["epoch"], - attrs=epoch_attrs, + attrs=cdf_attrs.get_variable_attributes("epoch"), ) dataset = xr.Dataset( diff --git a/imap_processing/glows/l1b/glows_l1b.py b/imap_processing/glows/l1b/glows_l1b.py index a9a6dfa6c..482f0b768 100644 --- a/imap_processing/glows/l1b/glows_l1b.py +++ b/imap_processing/glows/l1b/glows_l1b.py @@ -34,7 +34,7 @@ def glows_l1b(input_dataset: xr.Dataset, data_version: str) -> xr.Dataset: input_dataset["epoch"], name="epoch", dims=["epoch"], - attrs=cdf_attrs.get_variable_attributes("epoch_dim"), + attrs=cdf_attrs.get_variable_attributes("epoch"), ) logical_source = ( diff --git a/imap_processing/hi/l1a/histogram.py b/imap_processing/hi/l1a/histogram.py index c1356faeb..285eee272 100644 --- a/imap_processing/hi/l1a/histogram.py +++ b/imap_processing/hi/l1a/histogram.py @@ -99,7 +99,7 @@ def allocate_histogram_dataset(num_packets: int) -> xr.Dataset: np.empty(num_packets, dtype="datetime64[ns]"), name="epoch", dims=["epoch"], - attrs=attr_mgr.get_variable_attributes("hi_hist_epoch"), + attrs=attr_mgr.get_variable_attributes("epoch"), ) # Histogram data is binned in 90, 4-degree bins coords["angle"] = xr.DataArray( diff --git a/imap_processing/hi/l1a/science_direct_event.py b/imap_processing/hi/l1a/science_direct_event.py index e25ab560c..482e21392 100644 --- a/imap_processing/hi/l1a/science_direct_event.py +++ b/imap_processing/hi/l1a/science_direct_event.py @@ -266,11 +266,16 @@ def create_dataset(de_data_list: list, packet_met_time: list) -> xr.Dataset: # uncomment this once Maxine's PR is merged # attr_mgr.add_global_attribute("Data_version", data_version) + epoch_attrs = attr_mgr.get_variable_attributes("epoch") + epoch_attrs["CATDESC"] = ( + "Direct Event time, number of nanoseconds since J2000 with leap " + "seconds included" + ) epoch_time = xr.DataArray( data_dict.pop("epoch"), name="epoch", dims=["epoch"], - attrs=attr_mgr.get_variable_attributes("hi_de_epoch"), + attrs=epoch_attrs, ) de_global_attrs = attr_mgr.get_global_attributes("imap_hi_l1a_de_attrs") diff --git a/imap_processing/hi/l1c/hi_l1c.py b/imap_processing/hi/l1c/hi_l1c.py index 6509eaabe..91317eb93 100644 --- a/imap_processing/hi/l1c/hi_l1c.py +++ b/imap_processing/hi/l1c/hi_l1c.py @@ -99,13 +99,11 @@ def allocate_pset_dataset(n_esa_steps: int, sensor_str: str) -> xr.Dataset: # preallocate coordinates xr.DataArrays coords = dict() # epoch coordinate has only 1 entry for pointing set - attrs = attr_mgr.get_variable_attributes("hi_pset_epoch", check_schema=False).copy() - dtype = attrs.pop("dtype") coords["epoch"] = xr.DataArray( - np.empty(1, dtype=dtype), + np.empty(1, dtype=np.int64), # TODO: get dtype from cdf attrs? name="epoch", dims=["epoch"], - attrs=attrs, + attrs=attr_mgr.get_variable_attributes("epoch"), ) attrs = attr_mgr.get_variable_attributes( "hi_pset_esa_step", check_schema=False @@ -199,7 +197,7 @@ def full_dataarray( name : str Variable name. attrs : dict - CDF variable attributes. Usually retrieved from CdfAttributeManager. + CDF variable attributes. Usually retrieved from ImapCdfAttributes. coords : dict Coordinate variables for the Dataset. shape : int or tuple diff --git a/imap_processing/lo/l1a/lo_l1a_write_cdfs.py b/imap_processing/lo/l1a/lo_l1a_write_cdfs.py index 9608b737b..e845edaee 100644 --- a/imap_processing/lo/l1a/lo_l1a_write_cdfs.py +++ b/imap_processing/lo/l1a/lo_l1a_write_cdfs.py @@ -3,7 +3,6 @@ import numpy as np import xarray as xr -from imap_processing.cdf import epoch_attrs from imap_processing.cdf.imap_cdf_manager import ImapCdfAttributes from imap_processing.cdf.utils import J2000_EPOCH from imap_processing.lo.l0.lo_apid import LoAPID @@ -71,7 +70,7 @@ def create_lo_scide_dataset(sci_de: list) -> xr.Dataset: epoch_times, dims=["epoch"], name="epoch", - attrs=epoch_attrs, + attrs=cdf_manager.get_variable_attributes("epoch"), ) sci_de_energy = xr.DataArray( np.concatenate([sci_de_data.ENERGY for sci_de_data in sci_de]), diff --git a/imap_processing/mag/l0/decom_mag.py b/imap_processing/mag/l0/decom_mag.py index 095358d33..4ea4d8e8f 100644 --- a/imap_processing/mag/l0/decom_mag.py +++ b/imap_processing/mag/l0/decom_mag.py @@ -13,7 +13,6 @@ from imap_processing import imap_module_directory from imap_processing.ccsds.ccsds_data import CcsdsData -from imap_processing.cdf import epoch_attrs from imap_processing.cdf.imap_cdf_manager import ImapCdfAttributes from imap_processing.cdf.utils import met_to_j2000ns from imap_processing.mag.constants import DataMode @@ -139,7 +138,7 @@ def generate_dataset( shcoarse_data, name="epoch", dims=["epoch"], - attrs=epoch_attrs, + attrs=attribute_manager.get_variable_attributes("epoch"), ) # TODO: raw vectors units raw_vectors = xr.DataArray( diff --git a/imap_processing/mag/l1a/mag_l1a.py b/imap_processing/mag/l1a/mag_l1a.py index d27367f3e..1838bf203 100644 --- a/imap_processing/mag/l1a/mag_l1a.py +++ b/imap_processing/mag/l1a/mag_l1a.py @@ -7,7 +7,6 @@ import numpy as np import xarray as xr -from imap_processing.cdf import epoch_attrs from imap_processing.cdf.imap_cdf_manager import ImapCdfAttributes from imap_processing.cdf.utils import J2000_EPOCH, met_to_j2000ns from imap_processing.mag.constants import DataMode, PrimarySensor @@ -301,7 +300,7 @@ def generate_dataset( time_data, name="epoch", dims=["epoch"], - attrs=epoch_attrs, + attrs=attribute_manager.get_variable_attributes("epoch"), ) vectors = xr.DataArray( diff --git a/imap_processing/swapi/l1/swapi_l1.py b/imap_processing/swapi/l1/swapi_l1.py index 4f65f0a05..dcfffbc70 100644 --- a/imap_processing/swapi/l1/swapi_l1.py +++ b/imap_processing/swapi/l1/swapi_l1.py @@ -6,7 +6,6 @@ import xarray as xr from imap_processing import imap_module_directory -from imap_processing.cdf import epoch_attrs from imap_processing.cdf.imap_cdf_manager import ImapCdfAttributes from imap_processing.swapi.swapi_utils import SWAPIAPID, SWAPIMODE from imap_processing.utils import packet_file_to_datasets @@ -470,7 +469,7 @@ def process_swapi_science(sci_dataset: xr.Dataset, data_version: str) -> xr.Data epoch_values, name="epoch", dims=["epoch"], - attrs=epoch_attrs, + attrs=cdf_manager.get_variable_attributes("epoch"), ) # There are 72 energy steps diff --git a/imap_processing/tests/cdf/test_utils.py b/imap_processing/tests/cdf/test_utils.py index 1afaeae45..67c928061 100644 --- a/imap_processing/tests/cdf/test_utils.py +++ b/imap_processing/tests/cdf/test_utils.py @@ -5,7 +5,6 @@ import pytest import xarray as xr -from imap_processing.cdf import epoch_attrs from imap_processing.cdf.imap_cdf_manager import ImapCdfAttributes from imap_processing.cdf.utils import ( IMAP_EPOCH, @@ -42,7 +41,7 @@ def test_dataset(): "Logical_file_id": "imap_swe_l1a_sci_20100101_v001", }, ) - dataset["epoch"].attrs = epoch_attrs + dataset["epoch"].attrs = swe_attrs.get_variable_attributes("epoch") dataset["epoch"].attrs["DEPEND_0"] = "epoch" return dataset diff --git a/imap_processing/tests/glows/test_glows_l1b.py b/imap_processing/tests/glows/test_glows_l1b.py index 61b109237..5d3e75406 100644 --- a/imap_processing/tests/glows/test_glows_l1b.py +++ b/imap_processing/tests/glows/test_glows_l1b.py @@ -45,7 +45,7 @@ def hist_dataset(): np.arange(20), name="epoch", dims=["epoch"], - attrs=cdf_attrs.get_variable_attributes("epoch_dim"), + attrs=cdf_attrs.get_variable_attributes("epoch"), ) bins = xr.DataArray(np.arange(3600), name="bins", dims=["bins"]) @@ -102,7 +102,7 @@ def de_dataset(): np.arange(20), name="epoch", dims=["epoch"], - attrs=cdf_attrs.get_variable_attributes("epoch_dim"), + attrs=cdf_attrs.get_variable_attributes("epoch"), ) per_second = xr.DataArray(np.arange(2295), name="per_second", dims=["per_second"]) diff --git a/imap_processing/tests/hi/test_hi_l1c.py b/imap_processing/tests/hi/test_hi_l1c.py index bb4966be1..2a48d3cfe 100644 --- a/imap_processing/tests/hi/test_hi_l1c.py +++ b/imap_processing/tests/hi/test_hi_l1c.py @@ -4,8 +4,7 @@ import pytest import xarray as xr -from imap_processing import imap_module_directory -from imap_processing.cdf.cdf_attribute_manager import CdfAttributeManager +from imap_processing.cdf.imap_cdf_manager import ImapCdfAttributes from imap_processing.hi.l1a.hi_l1a import hi_l1a from imap_processing.hi.l1b.hi_l1b import hi_l1b from imap_processing.hi.l1c import hi_l1c @@ -61,7 +60,7 @@ def test_full_dataarray(name, shape, expected_shape): "esa_step": xr.DataArray(np.arange(10)), "spin_angle_bin": xr.DataArray(np.arange(360)), } - cdf_manager = CdfAttributeManager(imap_module_directory / "cdf" / "config") + cdf_manager = ImapCdfAttributes() cdf_manager.load_variable_attributes("imap_hi_variable_attrs.yaml") dataarray = hi_l1c.full_dataarray( diff --git a/imap_processing/ultra/utils/ultra_l1_utils.py b/imap_processing/ultra/utils/ultra_l1_utils.py index d435844bb..a5538ed02 100644 --- a/imap_processing/ultra/utils/ultra_l1_utils.py +++ b/imap_processing/ultra/utils/ultra_l1_utils.py @@ -1,10 +1,8 @@ """Create dataset.""" -from pathlib import Path - import xarray as xr -from imap_processing.cdf.cdf_attribute_manager import CdfAttributeManager +from imap_processing.cdf.imap_cdf_manager import ImapCdfAttributes def create_dataset(data_dict: dict, name: str, level: str) -> xr.Dataset: @@ -25,11 +23,9 @@ def create_dataset(data_dict: dict, name: str, level: str) -> xr.Dataset: dataset : xarray.Dataset Data in xarray format. """ - cdf_manager = CdfAttributeManager(Path(__file__).parents[2] / "cdf" / "config") - cdf_manager.load_global_attributes("imap_default_global_cdf_attrs.yaml") - cdf_manager.load_global_attributes("imap_ultra_global_cdf_attrs.yaml") - cdf_manager.load_variable_attributes(f"imap_ultra_{level}_variable_attrs.yaml") - + cdf_manager = ImapCdfAttributes() + cdf_manager.add_instrument_global_attrs("ultra") + cdf_manager.add_instrument_variable_attrs("ultra", level) epoch_time = xr.DataArray( data_dict["epoch"], name="epoch", diff --git a/imap_processing/utils.py b/imap_processing/utils.py index ea24d2bfa..fb52c442d 100644 --- a/imap_processing/utils.py +++ b/imap_processing/utils.py @@ -10,7 +10,6 @@ import xarray as xr from space_packet_parser import parser, xtcedef -from imap_processing.cdf import epoch_attrs from imap_processing.cdf.imap_cdf_manager import ImapCdfAttributes from imap_processing.cdf.utils import met_to_j2000ns @@ -203,7 +202,7 @@ def create_dataset( metadata_arrays[spacecraft_time_key], name="epoch", dims=["epoch"], - attrs=epoch_attrs, + attrs=cdf_manager.get_variable_attributes("epoch"), ) dataset = xr.Dataset(