1515 rebin_to_counts_by_species_elevation_and_spin_sector , rebin_direct_events_by_energy_and_spin_sector , \
1616 CODICE_LO_NUM_AZIMUTH_BINS , normalize_counts , combine_priorities_and_convert_to_rate , \
1717 rebin_3d_distribution_azimuth_to_elevation , convert_count_rate_to_intensity , rebin_direct_events_for_normalization , \
18- calculate_normalization_factor
18+ calculate_normalization_factor , lookup_normalization_per_event
1919from imap_l3_processing .constants import ONE_SECOND_IN_MICROSECONDS
2020
2121
@@ -336,7 +336,7 @@ def test_calculate_normalization_factor(self):
336336 spin_sectors [0 , 0 , :3 ] = [0 , 2 , 12 ]
337337 energy_steps [0 , 0 , :3 ] = [0 , 0 , 0 ]
338338
339- result = calculate_normalization_factor (priority_counts , num_events , spin_sectors , energy_steps )
339+ result = calculate_normalization_factor (priority_counts , num_events , energy_steps , spin_sectors )
340340
341341 expected_shape = (num_epochs , num_priorities , num_esa_steps , num_l2_spin_sectors )
342342 expected = np .full (expected_shape , 0.0 )
@@ -367,7 +367,7 @@ def test_calculate_normalization_factor_floor_is_one(self):
367367 spin_sectors [0 , 0 , :3 ] = [0 , 12 , 2 ]
368368 energy_steps [0 , 0 , :3 ] = [0 , 0 , 0 ]
369369
370- result = calculate_normalization_factor (priority_counts , num_events , spin_sectors , energy_steps )
370+ result = calculate_normalization_factor (priority_counts , num_events , energy_steps , spin_sectors )
371371
372372 expected_shape = (num_epochs , num_priorities , num_esa_steps , num_l2_spin_sectors )
373373 expected = np .full (expected_shape , 0.0 )
@@ -395,7 +395,7 @@ def test_normalization_factor_is_fill_when_priority_nonzero_and_direct_zero(self
395395 spin_sectors = np .zeros ((num_epochs , num_priorities , event_buffer_len ), dtype = int )
396396 energy_steps = np .zeros ((num_epochs , num_priorities , event_buffer_len ), dtype = int )
397397
398- result = calculate_normalization_factor (priority_counts , num_events , spin_sectors , energy_steps )
398+ result = calculate_normalization_factor (priority_counts , num_events , energy_steps , spin_sectors )
399399
400400 expected_shape = (num_epochs , num_priorities , num_esa_steps , num_l2_spin_sectors )
401401 expected = np .full (expected_shape , 0.0 )
@@ -407,6 +407,59 @@ def test_normalization_factor_is_fill_when_priority_nonzero_and_direct_zero(self
407407 expected [0 , 0 , 0 , (0 , 2 , 12 , 14 )] = np .nan
408408 np .testing .assert_equal (result , expected )
409409
410+ def test_lookup_normalization_per_event (self ):
411+ num_epochs = 2
412+ num_priorities = 7
413+ num_esa_steps = 128
414+ num_l1_spin_sectors = 12
415+ num_l2_spin_sectors = 2 * num_l1_spin_sectors
416+
417+ normalization = np .zeros ((num_epochs , num_priorities , num_esa_steps , num_l2_spin_sectors ))
418+ normalization [0 ,0 ,0 ,0 ] = 123.
419+ normalization [0 ,0 ,0 ,12 ] = 456.
420+ normalization [0 ,0 ,1 ,2 ] = 789.
421+
422+ event_buffer_len = 15
423+ num_events = np .zeros ((num_epochs , num_priorities ), dtype = int )
424+ spin_sectors = np .ma .array (np .full ((num_epochs , num_priorities , event_buffer_len ), 255 , dtype = int ), mask = True )
425+ energy_steps = np .ma .array (np .full ((num_epochs , num_priorities , event_buffer_len ), 255 , dtype = int ), mask = True )
426+
427+ num_events [0 , 0 ] = 3
428+ spin_sectors [0 , 0 , :3 ] = [0 , 12 , 2 ]
429+ energy_steps [0 , 0 , :3 ] = [0 , 0 , 1 ]
430+
431+ normalization_per_event = lookup_normalization_per_event (normalization , num_events , energy_steps , spin_sectors )
432+
433+ np .testing .assert_array_equal (normalization_per_event [0 , 0 , :3 ], [123 , 456 , 789 ])
434+
435+ expected_normalization_per_event = np .full ((num_epochs , num_priorities , event_buffer_len ), np .nan )
436+ expected_normalization_per_event [0 , 0 , :3 ] = [123 , 456 , 789 ]
437+
438+ np .testing .assert_array_equal (normalization_per_event , expected_normalization_per_event )
439+
440+
441+ def test_lookup_normalization_per_event_skips_masked_num_events (self ):
442+ num_epochs = 2
443+ num_priorities = 7
444+ num_esa_steps = 128
445+ num_l1_spin_sectors = 12
446+ num_l2_spin_sectors = 2 * num_l1_spin_sectors
447+
448+ normalization = np .zeros ((num_epochs , num_priorities , num_esa_steps , num_l2_spin_sectors ))
449+ normalization [0 ,0 ,0 ,0 ] = 123.
450+ normalization [0 ,0 ,0 ,12 ] = 456.
451+ normalization [0 ,0 ,1 ,2 ] = 789.
452+
453+ event_buffer_len = 15
454+ num_events = np .ma .array (np .full ((num_epochs , num_priorities ),65535 ), mask = True )
455+ spin_sectors = np .ma .array (np .full ((num_epochs , num_priorities , event_buffer_len ), 255 , dtype = int ), mask = True )
456+ energy_steps = np .ma .array (np .full ((num_epochs , num_priorities , event_buffer_len ), 255 , dtype = int ), mask = True )
457+
458+ normalization_per_event = lookup_normalization_per_event (normalization , num_events , energy_steps , spin_sectors )
459+
460+ expected_normalization_per_event = np .full ((num_epochs , num_priorities , event_buffer_len ), np .nan )
461+ np .testing .assert_array_equal (normalization_per_event , expected_normalization_per_event )
462+
410463 def test_normalize_counts (self ):
411464 num_epochs = 2
412465 num_priorities = 3
0 commit comments