Skip to content

Commit 7e14923

Browse files
author
Menlo Innovations - CAVA Project
committed
Harrison 3029 - PMCL - CoDICE Lo direct events: Pass through spin sector from L2
1 parent 40deb6d commit 7e14923

5 files changed

Lines changed: 30 additions & 23 deletions

File tree

imap_l3_processing/cdf/config/imap_codice_l3a_lo-direct-events_variable_attrs.yaml

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -209,16 +209,6 @@ energy_step:
209209
VAR_TYPE: data
210210
DATA_TYPE: CDF_UINT1
211211

212-
event_spin_angle:
213-
<<: *per_event
214-
<<: *float_data
215-
NAME: event_spin_angle
216-
VAR_TYPE: data
217-
CATDESC: Spin angle when event was observed
218-
FIELDNAM: Spin angle
219-
LABLAXIS: m
220-
UNITS: degrees
221-
222212
gain:
223213
<<: *per_event
224214
NAME: gain
@@ -350,6 +340,22 @@ spin_angle:
350340
SCALEMIN: 0
351341
SCALEMAX: 360
352342

343+
spin_sector:
344+
<<: *per_event
345+
NAME: spin_sector
346+
VAR_TYPE: support_data
347+
CATDESC: Spin sector per event
348+
FIELDNAM: Spin sector
349+
LABLAXIS: Spin sector
350+
DICT_KEY: SPASE>Support>SupportQuantity:Positional
351+
UNITS: ' '
352+
SCALETYP: linear
353+
DATA_TYPE: CDF_UINT1
354+
FORMAT: I2
355+
VALIDMIN: 0
356+
VALIDMAX: 23
357+
FILLVAL: 255
358+
353359
elevation:
354360
<<: *per_event
355361
<<: *float_data

imap_l3_processing/codice/l3/lo/codice_lo_processor.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from imap_l3_processing.codice.l3.lo.codice_lo_l3a_partial_densities_dependencies import \
1010
CodiceLoL3aPartialDensitiesDependencies
1111
from imap_l3_processing.codice.l3.lo.codice_lo_l3a_ratios_dependencies import CodiceLoL3aRatiosDependencies
12-
from imap_l3_processing.codice.l3.lo.constants import CODICE_SPIN_ANGLE_OFFSET_FROM_MAG_BOOM
1312
from imap_l3_processing.codice.l3.lo.direct_events.science.angle_lookup import SpinAngleLookup, \
1413
PositionToElevationLookup
1514
from imap_l3_processing.codice.l3.lo.models import CodiceLoL3aPartialDensityDataProduct, \
@@ -183,8 +182,6 @@ def process_l3a_direct_event_data_product(self, dependencies: CodiceLoL3aDirectE
183182
codice_nsw_priority_counts_l1a_data.p6_hplus_heplusplus
184183
]
185184

186-
spin_angle = np.full((len(codice_direct_events.epoch), len(priority_counts_for_events), event_buffer),
187-
np.nan)
188185
mass_per_charge = np.full((len(codice_direct_events.epoch), len(priority_counts_for_events), event_buffer),
189186
np.nan)
190187
mass = np.full((len(codice_direct_events.epoch), len(priority_counts_for_events), event_buffer), np.nan)
@@ -198,10 +195,9 @@ def process_l3a_direct_event_data_product(self, dependencies: CodiceLoL3aDirectE
198195
codice_direct_events.tof)
199196
mass = calculate_mass(codice_direct_events.apd_energy, codice_direct_events.tof, mass_coefficient_lookup)
200197

201-
spin_angle = (codice_direct_events.spin_angle + CODICE_SPIN_ANGLE_OFFSET_FROM_MAG_BOOM) % 360
202198
direct_events_binned_by_energy_and_spin = rebin_counts_by_energy_and_spin_angle(
203199
codice_direct_events.num_events,
204-
spin_angle,
200+
codice_direct_events.spin_angle,
205201
codice_direct_events.energy_step,
206202
spin_angle_lut,
207203
esa_energy_per_charge_lookup)
@@ -225,7 +221,7 @@ def process_l3a_direct_event_data_product(self, dependencies: CodiceLoL3aDirectE
225221
num_events=codice_direct_events.num_events,
226222
tof=codice_direct_events.tof,
227223
data_quality=codice_direct_events.data_quality,
228-
spin_angle=spin_angle,
224+
spin_angle=codice_direct_events.spin_angle,
229225
elevation=codice_direct_events.elevation_angle,
230226
position=codice_direct_events.position,
231227
energy_bin=np.flip(esa_energy_per_charge_lookup.bin_centers),
@@ -239,6 +235,7 @@ def process_l3a_direct_event_data_product(self, dependencies: CodiceLoL3aDirectE
239235
nso_spin_sector=codice_sw_priority_counts_l1a_data.nso_spin_sector,
240236
nso_esa_step=codice_sw_priority_counts_l1a_data.nso_esa_step,
241237
normalization_per_event=1,
238+
spin_sector=codice_direct_events.spin_sector,
242239
)
243240

244241
def process_l3a_3d_distribution_product(self, dependencies: CodiceLoL3a3dDistributionsDependencies):

imap_l3_processing/codice/l3/lo/models.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ def to_data_product_variables(self) -> list[DataProductVariable]:
311311
DATA_QUALITY_VAR_NAME = "data_quality"
312312
TOF_VAR_NAME = "tof"
313313
SPIN_ANGLE_VAR_NAME = "spin_angle"
314+
SPIN_SECTOR_VAR_NAME = "spin_sector"
314315
ELEVATION_VAR_NAME = "elevation"
315316
POSITION_VAR_NAME = "position"
316317
PRIORITY_INDEX_LABEL_VAR_NAME = "priority_index_label"
@@ -383,6 +384,7 @@ class CodiceLoL3aDirectEventDataProduct(CodiceLoDirectEventData, DataProduct):
383384
rgfo_esa_step: np.ndarray
384385
nso_spin_sector: np.ndarray
385386
nso_esa_step: np.ndarray
387+
spin_sector: np.ndarray
386388
normalization_per_event: np.ndarray
387389

388390

@@ -424,6 +426,7 @@ def to_data_product_variables(self) -> list[DataProductVariable]:
424426
DataProductVariable(ELEVATION_VAR_NAME, self.elevation),
425427
DataProductVariable(POSITION_VAR_NAME, self.position),
426428
DataProductVariable(SPIN_ANGLE_VAR_NAME, self.spin_angle),
429+
DataProductVariable(SPIN_SECTOR_VAR_NAME, self.spin_sector),
427430
DataProductVariable(ENERGY_STEP_VAR_NAME, self.energy_step),
428431

429432
DataProductVariable(PRIORITY_INDEX_VAR_NAME, self.priority_index),

tests/codice/l3/lo/test_codice_lo_processor.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,8 @@ def test_process_l3a_direct_events(self, mock_calculate_mass, mock_calculate_mas
567567
expected_data_quality = codice_l2_variables["data_quality"]
568568
expected_num_events = codice_l2_variables["num_events"]
569569
expected_energy_step = codice_l2_variables["energy_step"]
570+
expected_spin_angle = codice_l2_variables["spin_angle"]
571+
expected_spin_sector = codice_l2_variables["spin_sector"]
570572

571573
direct_events = CodiceLoL2DirectEventData(**codice_l2_variables)
572574

@@ -595,10 +597,9 @@ def test_process_l3a_direct_events(self, mock_calculate_mass, mock_calculate_mas
595597
np.testing.assert_equal(mock_calculate_mass_per_charge.call_args.args[0], expected_energy_per_charge)
596598
np.testing.assert_equal(mock_calculate_mass_per_charge.call_args.args[1], expected_tof)
597599

598-
expected_spin_angles = (codice_l2_variables['spin_angle'] + 316) % 360
599600
self.assertEqual(1, mock_rebin_counts_by_energy_and_spin.call_count)
600601
np.testing.assert_equal(mock_rebin_counts_by_energy_and_spin.call_args.args[0], expected_num_events)
601-
np.testing.assert_equal(mock_rebin_counts_by_energy_and_spin.call_args.args[1], expected_spin_angles)
602+
np.testing.assert_equal(mock_rebin_counts_by_energy_and_spin.call_args.args[1], expected_spin_angle)
602603
np.testing.assert_equal(mock_rebin_counts_by_energy_and_spin.call_args.args[2], expected_energy_step)
603604
np.testing.assert_equal(mock_rebin_counts_by_energy_and_spin.call_args.args[3], mock_spin_angle_lookup)
604605
np.testing.assert_equal(mock_rebin_counts_by_energy_and_spin.call_args.args[4], dependencies.energy_lookup)
@@ -628,12 +629,11 @@ def test_process_l3a_direct_events(self, mock_calculate_mass, mock_calculate_mas
628629
expected_numerator[:,:,:,12:] = priority_rates
629630
expected_normalization = expected_numerator / counts_rebinned_by_energy_and_spin
630631

631-
632-
633632
np.testing.assert_array_equal(l3a_direct_event_data_product.normalization,
634633
np.flip(expected_normalization, axis=2))
635634

636-
np.testing.assert_array_equal(expected_spin_angles, l3a_direct_event_data_product.spin_angle)
635+
np.testing.assert_array_equal(expected_spin_angle, l3a_direct_event_data_product.spin_angle)
636+
np.testing.assert_array_equal(expected_spin_sector, l3a_direct_event_data_product.spin_sector)
637637
np.testing.assert_array_equal(expected_elevation, l3a_direct_event_data_product.elevation)
638638
np.testing.assert_array_equal(expected_position, l3a_direct_event_data_product.position)
639639
np.testing.assert_array_equal(expected_apd_energy, l3a_direct_event_data_product.apd_energy)

tests/codice/l3/lo/test_models.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ def test_codice_lo_l3a_direct_event_to_data_product(self):
378378
input_metadata=Mock(),
379379
epoch=epoch,
380380
epoch_delta=epoch_delta,
381-
normalization=rng.random((len(epoch), len(priority), len(spin_angle), len(energy_step))),
381+
normalization=rng.random((len(epoch), len(priority), len(energy_step), len(spin_angle))),
382382
mass_per_charge=rng.random((len(epoch), len(priority), len(event_num))),
383383
mass=rng.random((len(epoch), len(priority), len(event_num))),
384384
apd_energy=rng.random((len(epoch), len(priority), len(event_num))),
@@ -390,6 +390,7 @@ def test_codice_lo_l3a_direct_event_to_data_product(self):
390390
data_quality=rng.random((len(epoch), len(priority))),
391391
tof=rng.random((len(epoch), len(priority), len(event_num))),
392392
spin_angle=rng.random((len(epoch), len(priority), len(event_num))),
393+
spin_sector=rng.random((len(epoch), len(priority), len(event_num))),
393394
elevation=rng.random((len(epoch), len(priority), len(event_num))),
394395
position=rng.random((len(epoch), len(priority), len(event_num))),
395396
spin_angle_bin=rng.random(24),
@@ -402,7 +403,7 @@ def test_codice_lo_l3a_direct_event_to_data_product(self):
402403
rgfo_esa_step=rng.random(len(epoch)),
403404
nso_spin_sector=rng.random(len(epoch)),
404405
nso_esa_step=rng.random(len(epoch)),
405-
normalization_per_event=rng.random((len(epoch), len(priority), len(event_num)))
406+
normalization_per_event=rng.random((len(epoch), len(priority), len(energy_step), len(spin_angle))),
406407
)
407408

408409
np.testing.assert_array_equal(direct_event.event_index, np.arange(len(event_num)))

0 commit comments

Comments
 (0)