From 2cce987e9d851e32512d65ae1886894d0b044630 Mon Sep 17 00:00:00 2001 From: John Backman Date: Fri, 27 Mar 2026 17:14:22 +0200 Subject: [PATCH 1/6] check that the max position is roughly in the place --- pysp2/util/leo_fit.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pysp2/util/leo_fit.py b/pysp2/util/leo_fit.py index c636733..55bdc33 100644 --- a/pysp2/util/leo_fit.py +++ b/pysp2/util/leo_fit.py @@ -199,6 +199,8 @@ def beam_shape(my_binary, beam_position_from='split point', Globals=None, for i in range(moving_avg_ch0_profiles_.shape[0]): i_profile = moving_avg_ch0_profiles_[i,:] i_max = np.nanargmax(i_profile) + if i_max < num_base_pts_2_avg: + continue i_range = i_profile[i_max] - np.nanmin(i_profile[:i_max]) moving_avg_ch0_profiles[i,:] = (i_profile - np.nanmin(i_profile[:i_max])) / i_range #interpolate here to get the exact position in fraction (not integer) :: which posiiton (float) is the 0.03 cross in @@ -212,6 +214,8 @@ def beam_shape(my_binary, beam_position_from='split point', Globals=None, for i in range(moving_avg_ch4_profiles_.shape[0]): i_profile = moving_avg_ch4_profiles_[i,:] i_max = np.nanargmax(i_profile) + if i_max < num_base_pts_2_avg: + continue i_range = i_profile[i_max] - np.nanmin(i_profile[:i_max]) moving_avg_ch4_profiles[i,:] = (i_profile - np.nanmin(i_profile[:i_max])) / i_range #interpolate here to get the exact position in fraction (not integer) :: which posiiton (float) is the 0.03 cross in From 92d36e452a2ec7dcf2f3f01d08d721e8a37300a2 Mon Sep 17 00:00:00 2001 From: John Backman Date: Fri, 27 Mar 2026 20:04:23 +0200 Subject: [PATCH 2/6] boundary for leo_EndPos_ch0 --- pysp2/util/leo_fit.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pysp2/util/leo_fit.py b/pysp2/util/leo_fit.py index 55bdc33..3bf2d4c 100644 --- a/pysp2/util/leo_fit.py +++ b/pysp2/util/leo_fit.py @@ -321,6 +321,10 @@ def beam_shape(my_binary, beam_position_from='split point', Globals=None, np.nan, output_ds['leo_EndPos_ch0'].values) output_ds['leo_EndPos_ch4'].values = np.where(output_ds['leo_EndPos_ch4'].values < num_base_pts_2_avg, np.nan, output_ds['leo_EndPos_ch4'].values) + output_ds['leo_EndPos_ch0'].values = np.where(output_ds['leo_EndPos_ch0'].values > Globals.ScatMaxPeakPos, + np.nan, output_ds['leo_EndPos_ch0'].values) + output_ds['leo_EndPos_ch4'].values = np.where(output_ds['leo_EndPos_ch4'].values > Globals.ScatMaxPeakPos, + np.nan, output_ds['leo_EndPos_ch4'].values) output_ds['leo_PkFWHM_ch0'] = output_ds['leo_PkFWHM_ch0'].interpolate_na(dim="event_index", method="nearest", fill_value="extrapolate") From 07ca3c2d8f91bd1bfe28c482802f618c35a92a60 Mon Sep 17 00:00:00 2001 From: John Backman Date: Fri, 27 Mar 2026 21:47:20 +0200 Subject: [PATCH 3/6] more restraints for all possible errors --- pysp2/util/leo_fit.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pysp2/util/leo_fit.py b/pysp2/util/leo_fit.py index 3bf2d4c..856a1f2 100644 --- a/pysp2/util/leo_fit.py +++ b/pysp2/util/leo_fit.py @@ -179,10 +179,14 @@ def beam_shape(my_binary, beam_position_from='split point', Globals=None, #moving average of the beam shape with a window of moving_average_window moving_ch0_profile_window = np.lib.stride_tricks.sliding_window_view(my_ch0_profiles, - moving_average_window, axis=0) + min(moving_average_window, + np.sum(only_scattering_ch0)), + axis=0) moving_avg_ch0_profiles_ = np.nanmedian(moving_ch0_profile_window,axis=2) moving_ch4_profile_window = np.lib.stride_tricks.sliding_window_view(my_ch4_profiles, - moving_average_window, axis=0) + min(moving_average_window, + np.sum(only_scattering_ch4)), + axis=0) moving_avg_ch4_profiles_ = np.nanmedian(moving_ch4_profile_window,axis=2) moving_avg_ch0_profiles = np.zeros_like(moving_avg_ch0_profiles_) * np.nan From b356c1ed47b8ac763075cc55d7528f4ba904522f Mon Sep 17 00:00:00 2001 From: John Backman Date: Mon, 30 Mar 2026 14:34:24 +0300 Subject: [PATCH 4/6] no sliding window beyond the amount of data --- pysp2/util/leo_fit.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pysp2/util/leo_fit.py b/pysp2/util/leo_fit.py index 856a1f2..f02060f 100644 --- a/pysp2/util/leo_fit.py +++ b/pysp2/util/leo_fit.py @@ -247,9 +247,11 @@ def beam_shape(my_binary, beam_position_from='split point', Globals=None, #moving average of beam width moving_ch0_beam_width = np.lib.stride_tricks.sliding_window_view(my_ch0_scatterers['PkFWHM_ch0'].values, - moving_average_window, axis=0) + min(moving_average_window, + np.sum(only_scattering_ch0)), axis=0) moving_ch4_beam_width = np.lib.stride_tricks.sliding_window_view(my_ch4_scatterers['PkFWHM_ch4'].values, - moving_average_window, axis=0) + min(moving_average_window, + np.sum(only_scattering_ch4)), axis=0) moving_median_ch0_beam_width = np.nanmedian(moving_ch0_beam_width,axis=1) moving_median_ch4_beam_width = np.nanmedian(moving_ch4_beam_width,axis=1) From 88eeaffd3189af4fd97299c5b54caf0dadb95680 Mon Sep 17 00:00:00 2001 From: John Backman Date: Mon, 30 Mar 2026 19:13:13 +0300 Subject: [PATCH 5/6] no sliding window beyond the amount of data --- pysp2/util/leo_fit.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pysp2/util/leo_fit.py b/pysp2/util/leo_fit.py index f02060f..5932bc6 100644 --- a/pysp2/util/leo_fit.py +++ b/pysp2/util/leo_fit.py @@ -257,9 +257,11 @@ def beam_shape(my_binary, beam_position_from='split point', Globals=None, #Moving cross to centre (c2c) moving_ch0_c2c = np.lib.stride_tricks.sliding_window_view(ch0_c2c, - moving_average_window, axis=0) + min(moving_average_window, + np.sum(only_scattering_ch0)), axis=0) moving_ch4_c2c = np.lib.stride_tricks.sliding_window_view(ch4_c2c, - moving_average_window, axis=0) + min(moving_average_window, + np.sum(only_scattering_ch4)), axis=0) moving_median_ch0_c2c = np.nanmedian(moving_ch0_c2c,axis=1) moving_median_ch4_c2c = np.nanmedian(moving_ch4_c2c,axis=1) From 4f3def110790d3f9521f11b0c280c2a0ed23c980 Mon Sep 17 00:00:00 2001 From: John Backman Date: Wed, 1 Apr 2026 14:40:37 +0300 Subject: [PATCH 6/6] forgot log scale bin adjustment for leo fits --- pysp2/util/particle_properties.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pysp2/util/particle_properties.py b/pysp2/util/particle_properties.py index 679552b..84fe3b9 100644 --- a/pysp2/util/particle_properties.py +++ b/pysp2/util/particle_properties.py @@ -361,7 +361,10 @@ def process_psds(particle_ds, hk_ds, config, deltaSize=0.005, num_bins=199, SizeIncandOnly[the_particles], side='right') #axis 0 = time, axis 1 incandesence, axis 2 leo size - np.add.at(leo_IncandScatNumEnsemble[t,:,:], (ind_incan,ind_leo), OneOfEvery[the_particles]) + if deltaSize==0: + np.add.at(leo_IncandScatNumEnsemble[t,:,:], (ind_incan - 1,ind_leo - 1), OneOfEvery[the_particles]) + else: + np.add.at(leo_IncandScatNumEnsemble[t,:,:], (ind_incan, ind_leo), OneOfEvery[the_particles]) scat_parts = np.logical_and(scatter_accept, parts_time) incan_parts = np.logical_and(incand_accept, parts_time)