Skip to content

Commit b726929

Browse files
author
Menlo Innovations - CAVA Project
committed
Harrison 2381 - PMCL/TLAY - Add explicit CDF data types to SweL3Data
Starting out with CDF_REAL4 for float variables; this may change after discussion
1 parent 20b0b3a commit b726929

2 files changed

Lines changed: 47 additions & 24 deletions

File tree

imap_processing/swe/l3/models.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from typing import TypedDict
33

44
import numpy as np
5+
from spacepy import pycdf
56

67
from imap_processing.models import DataProduct, DataProductVariable
78

@@ -57,23 +58,30 @@ class SweL3Data(DataProduct):
5758

5859
def to_data_product_variables(self) -> list[DataProductVariable]:
5960
return [
60-
DataProductVariable(EPOCH_CDF_VAR_NAME, value=self.epoch),
61+
DataProductVariable(EPOCH_CDF_VAR_NAME, value=self.epoch, cdf_data_type=pycdf.const.CDF_TIME_TT2000),
6162
DataProductVariable(EPOCH_DELTA_CDF_VAR_NAME,
62-
value=[delta.total_seconds() * 1e9 for delta in self.epoch_delta]),
63-
DataProductVariable(ENERGY_CDF_VAR_NAME, value=self.energy, record_varying=False),
64-
DataProductVariable(ENERGY_DELTA_PLUS_CDF_VAR_NAME, value=self.energy_delta_plus, record_varying=False),
65-
DataProductVariable(ENERGY_DELTA_MINUS_CDF_VAR_NAME, value=self.energy_delta_minus, record_varying=False),
66-
DataProductVariable(PITCH_ANGLE_CDF_VAR_NAME, value=self.pitch_angle, record_varying=False),
67-
DataProductVariable(PITCH_ANGLE_DELTA_CDF_VAR_NAME, value=self.pitch_angle_delta, record_varying=False),
68-
DataProductVariable(FLUX_BY_PITCH_ANGLE_CDF_VAR_NAME, value=self.flux_by_pitch_angle),
63+
value=[delta.total_seconds() * 1e9 for delta in self.epoch_delta],
64+
cdf_data_type=pycdf.const.CDF_INT8),
65+
DataProductVariable(ENERGY_CDF_VAR_NAME, value=self.energy, cdf_data_type=pycdf.const.CDF_REAL4,
66+
record_varying=False),
67+
DataProductVariable(ENERGY_DELTA_PLUS_CDF_VAR_NAME, value=self.energy_delta_plus,
68+
cdf_data_type=pycdf.const.CDF_REAL4, record_varying=False),
69+
DataProductVariable(ENERGY_DELTA_MINUS_CDF_VAR_NAME, value=self.energy_delta_minus,
70+
cdf_data_type=pycdf.const.CDF_REAL4, record_varying=False),
71+
DataProductVariable(PITCH_ANGLE_CDF_VAR_NAME, value=self.pitch_angle, cdf_data_type=pycdf.const.CDF_REAL4,
72+
record_varying=False),
73+
DataProductVariable(PITCH_ANGLE_DELTA_CDF_VAR_NAME, value=self.pitch_angle_delta,
74+
cdf_data_type=pycdf.const.CDF_REAL4, record_varying=False),
75+
DataProductVariable(FLUX_BY_PITCH_ANGLE_CDF_VAR_NAME, value=self.flux_by_pitch_angle,
76+
cdf_data_type=pycdf.const.CDF_REAL4),
6977
DataProductVariable(PHASE_SPACE_DENSITY_BY_PITCH_ANGLE_CDF_VAR_NAME,
70-
value=self.phase_space_density_by_pitch_angle),
78+
value=self.phase_space_density_by_pitch_angle, cdf_data_type=pycdf.const.CDF_REAL4),
7179
DataProductVariable(ENERGY_SPECTRUM_CDF_VAR_NAME,
72-
value=self.energy_spectrum),
80+
value=self.energy_spectrum, cdf_data_type=pycdf.const.CDF_REAL4),
7381
DataProductVariable(ENERGY_SPECTRUM_INBOUND_CDF_VAR_NAME,
74-
value=self.energy_spectrum_inbound),
82+
value=self.energy_spectrum_inbound, cdf_data_type=pycdf.const.CDF_REAL4),
7583
DataProductVariable(ENERGY_SPECTRUM_OUTBOUND_CDF_VAR_NAME,
76-
value=self.energy_spectrum_outbound),
84+
value=self.energy_spectrum_outbound, cdf_data_type=pycdf.const.CDF_REAL4),
7785
]
7886

7987

tests/swe/l3/science/test_models.py

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
from datetime import timedelta
33
from unittest.mock import Mock
44

5+
from spacepy import pycdf
6+
from spacepy.pycdf.const import CDF_TIME_TT2000, CDF_INT8
7+
58
from imap_processing.swe.l3.models import SweL3Data, EPOCH_CDF_VAR_NAME, EPOCH_DELTA_CDF_VAR_NAME, ENERGY_CDF_VAR_NAME, \
69
ENERGY_DELTA_PLUS_CDF_VAR_NAME, ENERGY_DELTA_MINUS_CDF_VAR_NAME, PITCH_ANGLE_CDF_VAR_NAME, \
710
PITCH_ANGLE_DELTA_CDF_VAR_NAME, FLUX_BY_PITCH_ANGLE_CDF_VAR_NAME, PHASE_SPACE_DENSITY_BY_PITCH_ANGLE_CDF_VAR_NAME, \
@@ -43,18 +46,30 @@ def test_data_to_product_variables(self):
4346

4447
variables = iter(variables)
4548
# @formatter:off
46-
self.assert_variable_attributes(next(variables), epoch, EPOCH_CDF_VAR_NAME)
47-
self.assert_variable_attributes(next(variables), [86400*1e9, 40*1e9], EPOCH_DELTA_CDF_VAR_NAME)
48-
self.assert_variable_attributes(next(variables), energy, ENERGY_CDF_VAR_NAME, expected_record_varying=False)
49-
self.assert_variable_attributes(next(variables), energy_delta_plus, ENERGY_DELTA_PLUS_CDF_VAR_NAME, expected_record_varying=False)
50-
self.assert_variable_attributes(next(variables), energy_delta_minus, ENERGY_DELTA_MINUS_CDF_VAR_NAME, expected_record_varying=False)
51-
self.assert_variable_attributes(next(variables), pitch_angle, PITCH_ANGLE_CDF_VAR_NAME, expected_record_varying=False)
52-
self.assert_variable_attributes(next(variables), pitch_angle_delta, PITCH_ANGLE_DELTA_CDF_VAR_NAME, expected_record_varying=False)
53-
self.assert_variable_attributes(next(variables), flux_by_pitch_angle, FLUX_BY_PITCH_ANGLE_CDF_VAR_NAME)
54-
self.assert_variable_attributes(next(variables), psd_by_pitch_angle, PHASE_SPACE_DENSITY_BY_PITCH_ANGLE_CDF_VAR_NAME)
55-
self.assert_variable_attributes(next(variables), energy_spectrum, ENERGY_SPECTRUM_CDF_VAR_NAME)
56-
self.assert_variable_attributes(next(variables), energy_spectrum_inbound, ENERGY_SPECTRUM_INBOUND_CDF_VAR_NAME)
57-
self.assert_variable_attributes(next(variables), energy_spectrum_outbound, ENERGY_SPECTRUM_OUTBOUND_CDF_VAR_NAME)
49+
self.assert_variable_attributes(
50+
next(variables), epoch, EPOCH_CDF_VAR_NAME, pycdf.const.CDF_TIME_TT2000)
51+
self.assert_variable_attributes(
52+
next(variables), [86400 * 1e9, 40 * 1e9], EPOCH_DELTA_CDF_VAR_NAME, pycdf.const.CDF_INT8)
53+
self.assert_variable_attributes(
54+
next(variables), energy, ENERGY_CDF_VAR_NAME, pycdf.const.CDF_REAL4, expected_record_varying=False)
55+
self.assert_variable_attributes(
56+
next(variables), energy_delta_plus, ENERGY_DELTA_PLUS_CDF_VAR_NAME, pycdf.const.CDF_REAL4, expected_record_varying=False)
57+
self.assert_variable_attributes(
58+
next(variables), energy_delta_minus, ENERGY_DELTA_MINUS_CDF_VAR_NAME, pycdf.const.CDF_REAL4, expected_record_varying=False)
59+
self.assert_variable_attributes(
60+
next(variables), pitch_angle, PITCH_ANGLE_CDF_VAR_NAME, pycdf.const.CDF_REAL4, expected_record_varying=False)
61+
self.assert_variable_attributes(
62+
next(variables), pitch_angle_delta, PITCH_ANGLE_DELTA_CDF_VAR_NAME, pycdf.const.CDF_REAL4, expected_record_varying=False)
63+
self.assert_variable_attributes(
64+
next(variables), flux_by_pitch_angle, FLUX_BY_PITCH_ANGLE_CDF_VAR_NAME, pycdf.const.CDF_REAL4)
65+
self.assert_variable_attributes(
66+
next(variables), psd_by_pitch_angle, PHASE_SPACE_DENSITY_BY_PITCH_ANGLE_CDF_VAR_NAME, pycdf.const.CDF_REAL4)
67+
self.assert_variable_attributes(
68+
next(variables), energy_spectrum, ENERGY_SPECTRUM_CDF_VAR_NAME, pycdf.const.CDF_REAL4)
69+
self.assert_variable_attributes(
70+
next(variables), energy_spectrum_inbound, ENERGY_SPECTRUM_INBOUND_CDF_VAR_NAME, pycdf.const.CDF_REAL4)
71+
self.assert_variable_attributes(
72+
next(variables), energy_spectrum_outbound, ENERGY_SPECTRUM_OUTBOUND_CDF_VAR_NAME, pycdf.const.CDF_REAL4)
5873

5974

6075
if __name__ == '__main__':

0 commit comments

Comments
 (0)