@@ -58,33 +58,60 @@ def calculate_moment_products(self, dependencies: SweL3Dependencies):
5858
5959 weights : np .ndarray [float ] = compute_maxwellian_weight_factors (ccounts )
6060
61- halo_core_breakpoint_index : int = next (
62- i - 1 for i , energy in enumerate (swe_l2_data .energy ) if energy > halo_core )
6361 spacecraft_potential_core_breakpoint_index : int = next (
6462 i for i , energy in enumerate (swe_l2_data .energy ) if energy >= spacecraft_potential )
63+ halo_core_breakpoint_index : int = next (
64+ i - 1 for i , energy in enumerate (swe_l2_data .energy ) if energy > halo_core )
65+
66+ core_end_index = halo_core_breakpoint_index
67+ while True :
68+ filtered_velocity_vectors , filtered_weights , filtered_yreg = filter_and_flatten_regress_parameters (
69+ corrected_energy_bins ,
70+ velocity_vectors ,
71+ swe_l2_data .phase_space_density [i ],
72+ weights ,
73+ spacecraft_potential_core_breakpoint_index , core_end_index )
74+
75+ fit_function , chisq = regress (filtered_velocity_vectors ,
76+ filtered_weights , filtered_yreg )
77+ core_moments = calculate_fit_temperature_density_velocity (fit_function )
78+
79+ if 0 < core_moments .density < 185 or (
80+ core_end_index - spacecraft_potential_core_breakpoint_index ) <= 3 :
81+ break
82+ else :
83+ core_end_index -= 1
84+
85+ rtn_velocity = rotate_dps_vector_to_rtn (swe_epoch [i ],
86+ np .array (
87+ [core_moments .velocity_x , core_moments .velocity_y ,
88+ core_moments .velocity_z ]))
89+ rotate_temperature (swe_epoch [i ], core_moments .alpha , core_moments .beta )
6590
91+ halo_end_index = len (swe_l2_data .energy )
6692 while True :
6793 filtered_velocity_vectors , filtered_weights , filtered_yreg = filter_and_flatten_regress_parameters (
6894 corrected_energy_bins ,
6995 velocity_vectors ,
7096 swe_l2_data .phase_space_density [i ],
7197 weights ,
72- spacecraft_potential_core_breakpoint_index , halo_core_breakpoint_index )
98+ halo_core_breakpoint_index , halo_end_index )
7399
74100 fit_function , chisq = regress (filtered_velocity_vectors ,
75101 filtered_weights , filtered_yreg )
76- moments = calculate_fit_temperature_density_velocity (fit_function )
102+ halo_moments = calculate_fit_temperature_density_velocity (fit_function )
77103
78- if 0 < moments .density < 185 or (
79- halo_core_breakpoint_index - spacecraft_potential_core_breakpoint_index ) <= 3 :
104+ if 0 < halo_moments .density < 185 or (
105+ halo_end_index - halo_core_breakpoint_index ) <= 3 :
80106 break
81107 else :
82- halo_core_breakpoint_index -= 1
108+ halo_end_index -= 1
83109
84110 rtn_velocity = rotate_dps_vector_to_rtn (swe_epoch [i ],
85111 np .array (
86- [moments .velocity_x , moments .velocity_y , moments .velocity_z ]))
87- rotate_temperature (swe_epoch [i ], moments .alpha , moments .beta )
112+ [halo_moments .velocity_x , halo_moments .velocity_y ,
113+ halo_moments .velocity_z ]))
114+ rotate_temperature (swe_epoch [i ], halo_moments .alpha , halo_moments .beta )
88115
89116 def calculate_pitch_angle_products (self , dependencies : SweL3Dependencies ) -> SweL3Data :
90117 swe_l2_data = dependencies .swe_l2_data
0 commit comments