Skip to content

Commit

Permalink
Glows L2 initial setup (#1156)
Browse files Browse the repository at this point in the history
* Setting up

* first pass at making histl2 dataclass

* L2 processing updates

* Renaming variance variables to std_dev

* fixing flag dimensions

* WIP L2

* Removing unneeded files

* Updating docs

* Updating docs

* mypy ignore

* Fixing docs
  • Loading branch information
maxinelasp authored Nov 20, 2024
1 parent 032ef2b commit b88e2c7
Show file tree
Hide file tree
Showing 9 changed files with 245 additions and 95 deletions.
72 changes: 36 additions & 36 deletions imap_processing/cdf/config/imap_glows_l1b_variable_attrs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -251,13 +251,13 @@ filter_temperature_average:
LABLAXIS: Avgd Temperature
VALIDMAX: 255

filter_temperature_variance:
filter_temperature_std_dev:
<<: *support_data_defaults
CATDESC: spin-block-averaged variance of filter temperature
FIELDNAM: Variance of filter temperature
CATDESC: spin-block-averaged std_dev of filter temperature
FIELDNAM: std_dev of filter temperature
FILLVAL: *max_uint32
FORMAT: I6
LABLAXIS: Variance
LABLAXIS: std_dev
VALIDMAX: *max_uint16

hv_voltage_average:
Expand All @@ -269,12 +269,12 @@ hv_voltage_average:
LABLAXIS: Avg voltage
VALIDMAX: *max_uint16

hv_voltage_variance:
hv_voltage_std_dev:
<<: *support_data_defaults
CATDESC: variance of HV voltage on the CEM, uint encoded
FIELDNAM: HV voltage variance
CATDESC: std_dev of HV voltage on the CEM, uint encoded
FIELDNAM: HV voltage std_dev
FILLVAL: *int_fillval
LABLAXIS: Variance
LABLAXIS: std_dev
VALIDMAX: *max_uint32

spin_period_average:
Expand All @@ -291,13 +291,13 @@ spin_period_average:
VALIDMIN: 45000 # TBC 14.63 s where 20.9712 s = 65535, rounded down
VAR_TYPE: support_data

spin_period_variance:
spin_period_std_dev:
<<: *support_data_defaults
CATDESC: spin-block-averaged variance of spin period
FIELDNAM: variance of spin period
CATDESC: spin-block-averaged std_dev of spin period
FIELDNAM: std_dev of spin period
FILLVAL: *int_fillval
FORMAT: I10
LABLAXIS: Variance
LABLAXIS: std_dev
VALIDMAX: *max_uint32

# TODO review these
Expand All @@ -315,13 +315,13 @@ spin_period_ground_average:
VALIDMIN: 45000 # TBC 14.63 s where 20.9712 s = 65535, rounded down
VAR_TYPE: support_data

spin_period_ground_variance:
spin_period_ground_std_dev:
<<: *support_data_defaults
CATDESC: spin-block-averaged variance of spin period on ground
FIELDNAM: ground variance of spin period
CATDESC: spin-block-averaged std_dev of spin period on ground
FIELDNAM: ground std_dev of spin period
FILLVAL: *int_fillval
FORMAT: I10
LABLAXIS: Variance
LABLAXIS: std_dev
VALIDMAX: *max_uint32

pulse_length_average:
Expand All @@ -333,13 +333,13 @@ pulse_length_average:
LABLAXIS: Avg pulse len
VALIDMAX: 255

pulse_length_variance:
pulse_length_std_dev:
<<: *support_data_defaults
CATDESC: spin-block-averaged variance of pulse length
FIELDNAM: Variance of pulse length
CATDESC: spin-block-averaged std_dev of pulse length
FIELDNAM: std_dev of pulse length
FILLVAL: *max_uint32
FORMAT: I10
LABLAXIS: Variance
LABLAXIS: std_dev
VALIDMAX: *max_uint16

position_angle_offset_average:
Expand All @@ -350,21 +350,21 @@ position_angle_offset_average:
FORMAT: I4
LABLAXIS: Avg pos angle

position_angle_offset_variance:
position_angle_offset_std_dev:
<<: *support_data_defaults
CATDESC: spin-block averaged variance of position angle offset
FIELDNAM: Variance of position angle offset
CATDESC: spin-block averaged std_dev of position angle offset
FIELDNAM: std_dev of position angle offset
FILLVAL: *max_uint16
FORMAT: I4
LABLAXIS: Variance
LABLAXIS: std_dev

spin_axis_orientation_variance:
spin_axis_orientation_std_dev:
<<: *support_data_defaults
CATDESC: spin-block averaged variance of spin axis orientation
FIELDNAM: Variance of spin axis orientation
CATDESC: spin-block averaged std_dev of spin axis orientation
FIELDNAM: std_dev of spin axis orientation
FILLVAL: *max_uint16
FORMAT: I4
LABLAXIS: Variance
LABLAXIS: std_dev

spin_axis_orientation_average:
<<: *support_data_defaults
Expand All @@ -383,14 +383,14 @@ spacecraft_location_average:
FORMAT: I4
LABLAXIS: Avg spacecraft location

spacecraft_location_variance:
spacecraft_location_std_dev:
<<: *support_data_defaults
DEPEND_1: ecliptic
CATDESC: spin-block averaged variance of spacecraft location
FIELDNAM: Variance of spacecraft location
CATDESC: spin-block averaged std_dev of spacecraft location
FIELDNAM: std_dev of spacecraft location
FILLVAL: *max_uint16
FORMAT: I4
LABLAXIS: Variance
LABLAXIS: std_dev

spacecraft_velocity_average:
<<: *support_data_defaults
Expand All @@ -401,14 +401,14 @@ spacecraft_velocity_average:
FORMAT: I4
LABLAXIS: Avg spacecraft velocity

spacecraft_velocity_variance:
spacecraft_velocity_std_dev:
<<: *support_data_defaults
DEPEND_1: ecliptic
CATDESC: spin-block averaged variance of spacecraft velocity
FIELDNAM: Variance of spacecraft velocity
CATDESC: spin-block averaged std_dev of spacecraft velocity
FIELDNAM: std_dev of spacecraft velocity
FILLVAL: *max_uint16
FORMAT: I4
LABLAXIS: Variance
LABLAXIS: std_dev

# End of not-in--dicts in generate_de_dataset

Expand Down
6 changes: 3 additions & 3 deletions imap_processing/glows/l1b/glows_l1b.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,10 @@ def process_histogram(l1a: xr.Dataset) -> xr.Dataset:
"imap_spin_angle_bin_cntr": ["bins"],
"histogram_flag_array": ["bad_angle_flags", "bins"],
"spacecraft_location_average": ["ecliptic"],
"spacecraft_location_variance": ["ecliptic"],
"spacecraft_location_std_dev": ["ecliptic"],
"spacecraft_velocity_average": ["ecliptic"],
"spacecraft_velocity_variance": ["ecliptic"],
"flags": ["flag_dim", "bins"],
"spacecraft_velocity_std_dev": ["ecliptic"],
"flags": ["flag_dim"],
}

# For each attribute, retrieve the dims from output_dimension_mapping or use an
Expand Down
96 changes: 59 additions & 37 deletions imap_processing/glows/l1b/glows_l1b_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,19 +417,19 @@ class HistogramL1B:
IMAP spin angle ψ for bin centers
filter_temperature_average
block-averaged value, decoded to Celsius degrees using Eq. (47)
filter_temperature_variance
filter_temperature_std_dev
standard deviation (1 sigma), decoded to Celsius degrees using Eq. (51)
hv_voltage_average
block-averaged value, decoded to volts using Eq. (47)
hv_voltage_variance
hv_voltage_std_dev
standard deviation (1 sigma), decoded to volts using Eq. (51)
spin_period_average
block-averaged onboard value, decoded to seconds using Eq. (47)
spin_period_variance
spin_period_std_dev
standard deviation (1 sigma), decoded to seconds using Eq. (51)
pulse_length_average
block-averaged value, decoded to μs using Eq. (47)
pulse_length_variance
pulse_length_std_dev
standard deviation (1 sigma), decoded to μs using Eq. (51)
glows_start_time
GLOWS clock, subseconds as decimal part of float
Expand All @@ -444,24 +444,24 @@ class HistogramL1B:
is_inside_excluded_region, is_excluded_by_instr_team, is_suspected_transient]
spin_period_ground_average
block-averaged value computed on ground
spin_period_ground_variance
spin_period_ground_std_dev
standard deviation (1 sigma)
position_angle_offset_average
block-averaged value in degrees
position_angle_offset_variance
position_angle_offset_std_dev
standard deviation (1 sigma)
spin_axis_orientation_variance
spin_axis_orientation_std_dev
standard deviation( 1 sigma): ∆λ, ∆φ for ⟨λ⟩, ⟨φ⟩
spin_axis_orientation_average
block-averaged spin-axis ecliptic longitude ⟨λ⟩ and latitude ⟨φ⟩ in degrees
spacecraft_location_average
block-averaged Cartesian ecliptic coordinates ⟨X⟩, ⟨Y ⟩, ⟨Z⟩ [km] of IMAP
spacecraft_location_variance
spacecraft_location_std_dev
standard deviations (1 sigma) ∆X, ∆Y , ∆Z for ⟨X⟩, ⟨Y ⟩, ⟨Z⟩
spacecraft_velocity_average
block-averaged values ⟨VX⟩, ⟨VY⟩, ⟨VZ⟩ [km/s] of IMAP velocity components
(Cartesian ecliptic frame)
spacecraft_velocity_variance
spacecraft_velocity_std_dev
standard deviations (1 sigma) ∆VX , ∆VY , ∆VZ for ⟨VX ⟩, ⟨VY ⟩, ⟨VZ ⟩
flags
flags for extra information, per histogram. This should be a human-readable
Expand All @@ -470,9 +470,7 @@ class HistogramL1B:

histogram: np.ndarray
flight_software_version: str
# pkts_file_name: str TODO: add this in L0
seq_count_in_pkts_file: int
# l1a_file_name: str TODO: add this
# ancillary_data_files: np.ndarray TODO Add this
first_spin_id: int
last_spin_id: int
Expand All @@ -482,13 +480,17 @@ class HistogramL1B:
number_of_bins_per_histogram: int
number_of_events: int
filter_temperature_average: np.double
filter_temperature_variance: np.double
filter_temperature_variance: InitVar[np.double]
filter_temperature_std_dev: np.double = field(init=False)
hv_voltage_average: np.double
hv_voltage_variance: np.double
hv_voltage_variance: InitVar[np.double]
hv_voltage_std_dev: np.double = field(init=False)
spin_period_average: np.double
spin_period_variance: np.double
spin_period_variance: InitVar[np.double]
spin_period_std_dev: np.double = field(init=False)
pulse_length_average: np.double
pulse_length_variance: np.double
pulse_length_variance: InitVar[np.double]
pulse_length_std_dev: np.double = field(init=False)
imap_start_time: np.double # No conversion needed from l1a->l1b
imap_time_offset: np.double # No conversion needed from l1a->l1b
glows_start_time: np.double # No conversion needed from l1a->l1b
Expand All @@ -499,40 +501,60 @@ class HistogramL1B:
imap_spin_angle_bin_cntr: np.ndarray = field(init=False) # Same size as bins
histogram_flag_array: np.ndarray = field(init=False)
spin_period_ground_average: np.double = field(init=False) # retrieved from SPICE?
spin_period_ground_variance: np.double = field(init=False) # retrieved from SPICE?
spin_period_ground_std_dev: np.double = field(init=False) # retrieved from SPICE?
position_angle_offset_average: np.double = field(init=False) # retrieved from SPICE
position_angle_offset_variance: np.double = field(init=False) # from SPICE
spin_axis_orientation_variance: np.double = field(init=False) # from SPICE
position_angle_offset_std_dev: np.double = field(init=False) # from SPICE
spin_axis_orientation_std_dev: np.double = field(init=False) # from SPICE
spin_axis_orientation_average: np.double = field(init=False) # retrieved from SPICE
spacecraft_location_average: np.ndarray = field(init=False) # retrieved from SPIC
spacecraft_location_variance: np.ndarray = field(init=False) # retrieved from SPIC
spacecraft_location_std_dev: np.ndarray = field(init=False) # retrieved from SPIC
spacecraft_velocity_average: np.ndarray = field(init=False) # retrieved from SPIC
spacecraft_velocity_variance: np.ndarray = field(init=False) # retrieved from SPIC
spacecraft_velocity_std_dev: np.ndarray = field(init=False) # retrieved from SPIC
flags: np.ndarray = field(init=False)
# TODO:
# - Determine a good way to output flags as "human readable"
# - Add spice pieces
# - add in the filenames for the input files - should they be global attributes?
# - also unique identifiers
# - Bad angle algorithm using SPICE locations
# - Move ancillary file to AWS

def __post_init__(self) -> None:
"""Will process data."""
def __post_init__(
self,
filter_temperature_variance: np.double,
hv_voltage_variance: np.double,
spin_period_variance: np.double,
pulse_length_variance: np.double,
) -> None:
"""
Will process data.
The input variance values are used to calculate the output standard deviation.
Parameters
----------
filter_temperature_variance : numpy.double
Encoded filter temperature variance.
hv_voltage_variance : numpy.double
Encoded HV voltage variance.
spin_period_variance : numpy.double
Encoded spin period variance.
pulse_length_variance : numpy.double
Encoded pulse length variance.
"""
# self.histogram_flag_array = np.zeros((2,))

# TODO: These pieces will need to be filled in from SPICE kernels. For now,
# they are placeholders. GLOWS example code has better placeholders if needed.
self.spin_period_ground_average = np.double(-999.9)
self.spin_period_ground_variance = np.double(-999.9)
self.spin_period_ground_std_dev = np.double(-999.9)
self.position_angle_offset_average = np.double(-999.9)
self.position_angle_offset_variance = np.double(-999.9)
self.spin_axis_orientation_variance = np.double(-999.9)
self.position_angle_offset_std_dev = np.double(-999.9)
self.spin_axis_orientation_std_dev = np.double(-999.9)
self.spin_axis_orientation_average = np.double(-999.9)
self.spacecraft_location_average = np.array([-999.9, -999.9, -999.9])
self.spacecraft_location_variance = np.array([-999.9, -999.9, -999.9])
self.spacecraft_location_std_dev = np.array([-999.9, -999.9, -999.9])
self.spacecraft_velocity_average = np.array([-999.9, -999.9, -999.9])
self.spacecraft_velocity_variance = np.array([-999.9, -999.9, -999.9])
self.spacecraft_velocity_std_dev = np.array([-999.9, -999.9, -999.9])
# Will require some additional inputs
self.imap_spin_angle_bin_cntr = np.zeros((3600,))

Expand All @@ -546,34 +568,34 @@ def __post_init__(self) -> None:
self.filter_temperature_average = self.ancillary_parameters.decode(
"filter_temperature", self.filter_temperature_average
)
self.filter_temperature_variance = self.ancillary_parameters.decode_std_dev(
"filter_temperature", self.filter_temperature_variance
self.filter_temperature_std_dev = self.ancillary_parameters.decode_std_dev(
"filter_temperature", filter_temperature_variance
)

self.hv_voltage_average = self.ancillary_parameters.decode(
"hv_voltage", self.hv_voltage_average
)
self.hv_voltage_variance = self.ancillary_parameters.decode_std_dev(
"hv_voltage", self.hv_voltage_variance
self.hv_voltage_std_dev = self.ancillary_parameters.decode_std_dev(
"hv_voltage", hv_voltage_variance
)
self.spin_period_average = self.ancillary_parameters.decode(
"spin_period", self.spin_period_average
)
self.spin_period_variance = self.ancillary_parameters.decode_std_dev(
"spin_period", self.spin_period_variance
self.spin_period_std_dev = self.ancillary_parameters.decode_std_dev(
"spin_period", spin_period_variance
)
self.pulse_length_average = self.ancillary_parameters.decode(
"pulse_length", self.pulse_length_average
)
self.pulse_length_variance = self.ancillary_parameters.decode_std_dev(
"pulse_length", self.pulse_length_variance
self.pulse_length_std_dev = self.ancillary_parameters.decode_std_dev(
"pulse_length", pulse_length_variance
)

self.histogram_flag_array = np.zeros((4, 3600), dtype=np.uint8)
# self.unique_block_identifier = np.datetime_as_string(
# np.datetime64(int(self.imap_start_time), "ns"), "s"
# )
self.flags = np.zeros((17, 3600), dtype=np.uint8)
self.flags = np.ones((17,), dtype=np.uint8)

def output_data(self) -> tuple:
"""
Expand Down
Loading

0 comments on commit b88e2c7

Please sign in to comment.