Skip to content

Commit c3dc12d

Browse files
author
Menlo Innovations - CAVA Project
committed
Harrison 2382 - SWYN/PSCH - Now performing the main fitting logic on halo electrons, regress, find_density_temp
1 parent 66a82bd commit c3dc12d

3 files changed

Lines changed: 239 additions & 89 deletions

File tree

imap_processing/swe/swe_processor.py

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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

run_local.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -298,9 +298,9 @@ def create_hit_direct_event_cdf():
298298

299299
if "swe_moments" in sys.argv:
300300
dependencies = SweL3Dependencies.from_file_paths(
301-
get_test_data_path("swe/imap_swe_l2_sci-with-ace-data_19990609_v002.cdf"),
302-
get_test_data_path("swe/imap_mag_l1d_mago-normal_19990609_v001.cdf"),
303-
get_test_data_path("swe/imap_swapi_l3a_proton-sw_19990609_v001.cdf"),
301+
get_test_data_path("swe/imap_swe_l2_sci-with-ace-data_19990906_v002.cdf"),
302+
get_test_data_path("swe/imap_mag_l1d_mago-normal_19990906_v001.cdf"),
303+
get_test_data_path("swe/imap_swapi_l3a_proton-sw_19990906_v001.cdf"),
304304
get_test_data_path("swe/example_swe_config.json"),
305305
)
306306
print(create_swe_moments_cdf(dependencies))

0 commit comments

Comments
 (0)