From f95e218245d724a78510b6785be0a2eac3f81dfd Mon Sep 17 00:00:00 2001 From: John Backman Date: Wed, 3 Apr 2024 17:55:57 +0300 Subject: [PATCH 1/5] typo --- tests/test_gfit.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_gfit.py b/tests/test_gfit.py index 3a29148..e179441 100644 --- a/tests/test_gfit.py +++ b/tests/test_gfit.py @@ -11,7 +11,7 @@ def test_gaussian_fit(): np.nanmax(my_binary.PkHt_ch0.values), 98708.92915295, decimal=1) np.testing.assert_almost_equal( np.nanmax(my_binary.PkHt_ch4.values), 65088.3959945008, decimal=1) - # check that there are requal amounts of successful fits for low gain and + # check that there are equal amounts of successful fits for low gain and # high gain scattering when the peak heighs are large enough bl_hg = np.logical_and(my_binary['FtAmp_ch0'] > 30000, my_binary['FtAmp_ch0'] < 50000) From 023e3316646df5be4aad82dec60b2a572cccc181 Mon Sep 17 00:00:00 2001 From: John Backman Date: Wed, 3 Apr 2024 18:01:48 +0300 Subject: [PATCH 2/5] FIX: gaussian width is FWHM/2.35482 and not width/2. and changed split point marker symbols so that they are visible when they are on top of each other. --- pysp2/vis/plot_wave.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pysp2/vis/plot_wave.py b/pysp2/vis/plot_wave.py index b753ea5..e466f30 100644 --- a/pysp2/vis/plot_wave.py +++ b/pysp2/vis/plot_wave.py @@ -71,7 +71,7 @@ def plot_wave(ds, record_no, chn, plot_fit=True, pos = spectra['FtPos_ch' + str(chn)].values base = spectra['Base_ch' + str(chn)].values width = spectra['PkFWHM_ch' + str(chn)].values - Y = _gaus(xspace, amplitude, pos, width/2., base) + Y = _gaus(xspace, amplitude, pos, width/2.35482, base) ax.plot(xspace, Y) ax.text(0.7, 0.5, 'Fit Pos = %3.2f' % pos, transform=ax.transAxes) @@ -140,6 +140,6 @@ def plot_waves(ds, record_no, plot_fit=True): ax.legend(legends[i]) if i==2: lines=ax.get_lines() - ax.plot(ds['PkSplitPos_ch3'].isel(event_index=record_no),0,'*',markersize=10,color=lines[0].get_color()) - ax.plot(ds['PkSplitPos_ch7'].isel(event_index=record_no),0,'*',markersize=10,color=lines[1].get_color()) + ax.plot(ds['PkSplitPos_ch3'].isel(event_index=record_no),0,'1',markersize=10,color=lines[0].get_color()) + ax.plot(ds['PkSplitPos_ch7'].isel(event_index=record_no),0,'2',markersize=10,color=lines[1].get_color()) return display From 78e1485a80d6d1da83e1e6872a63b4906e307be8 Mon Sep 17 00:00:00 2001 From: John Backman Date: Wed, 3 Apr 2024 18:04:10 +0300 Subject: [PATCH 3/5] split point algorithms is more reliable when it is hard coded which channel is inverted and which one is not. In the future, we could add this to the conifguration file but I believe that this is standard and always the same. --- pysp2/util/peak_fit.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pysp2/util/peak_fit.py b/pysp2/util/peak_fit.py index eceb842..9c75d2d 100644 --- a/pysp2/util/peak_fit.py +++ b/pysp2/util/peak_fit.py @@ -509,9 +509,10 @@ def _split_scatter_fit(my_ds, channel): num_base_pts_2_avg = 20 data = my_ds['Data_ch' + str(channel)].values V_maxloc = np.argmax(data, axis=1) - V_minloc = np.argmin(data, axis=1) - invert = V_maxloc < V_minloc - data[invert, :] = -data[invert, :] + #V_minloc = np.argmin(data, axis=1) + #invert = V_maxloc < V_minloc + if channel==3: + data = -data base = np.nanmean(data[:, 0:num_base_pts_2_avg], axis=1) V_max = data.max(axis=1) conditions = np.logical_and.reduce(((V_max - base) > 1, V_maxloc < len(data), V_maxloc > 0)) @@ -526,7 +527,7 @@ def _split_scatter_fit(my_ds, channel): pos_tile = np.tile(pos, (data.shape[1], 1)).T counting_up = np.where(np.logical_and(data < 5, counting_up <= pos_tile), counting_up, -1) start = counting_up.max(axis=1) - fit_coeffs = {'base': base, 'height': height, 'pos': pos, 'start': start, 'inverted': invert} + fit_coeffs = {'base': base, 'height': height, 'pos': pos, 'start': start} return fit_coeffs From c477190defcc722c711ea47640cedd563473afef Mon Sep 17 00:00:00 2001 From: John Backman Date: Wed, 3 Apr 2024 18:07:15 +0300 Subject: [PATCH 4/5] FIX: when ch1 is saturated, the peak width should be taken from Ch5. Otherwise we loose the largest particles and the rBC size distribution is wrong. Large particles will be missing since PkEnd_ch1 will become nan --> width = nan --> accepted_incand will become False. --- pysp2/util/particle_properties.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pysp2/util/particle_properties.py b/pysp2/util/particle_properties.py index 125a6ed..4fc6d2e 100644 --- a/pysp2/util/particle_properties.py +++ b/pysp2/util/particle_properties.py @@ -61,7 +61,9 @@ def calc_diams_masses(input_ds, debug=True, factor=1.0, Globals=None): PkHt_ch1 = input_ds['PkHt_ch1'].values PkHt_ch5 = input_ds['PkHt_ch5'].values - width = input_ds['PkEnd_ch1'].values - input_ds['PkStart_ch1'].values + width_ch1 = input_ds['PkEnd_ch1'].values - input_ds['PkStart_ch1'].values + width_ch5 = input_ds['PkEnd_ch5'].values - input_ds['PkStart_ch5'].values + width = np.where(np.isnan(width_ch1),width_ch5,width_ch1) accepted_incand = width >= Globals.IncanMinWidth accepted_incand = np.logical_and(accepted_incand, input_ds['PkHt_ch2'].values >= Globals.IncanMinPeakHt1) From 83613edee616909bbe79fa7c809e13f7b98ab6b9 Mon Sep 17 00:00:00 2001 From: John Backman Date: Wed, 3 Apr 2024 18:35:29 +0300 Subject: [PATCH 5/5] forgot to update the tests --- tests/test_gfit.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_gfit.py b/tests/test_gfit.py index e179441..4908813 100644 --- a/tests/test_gfit.py +++ b/tests/test_gfit.py @@ -30,9 +30,9 @@ def test_psds(): my_psds = pysp2.util.process_psds(my_binary, my_hk, my_ini) np.testing.assert_almost_equal(my_psds['NumConcIncan'].max(), 0.95805343) np.testing.assert_almost_equal(my_psds['ScatNumEnsemble'].sum(), 254.773995310) - np.testing.assert_almost_equal(my_psds['IncanNumEnsemble'].sum(), 32.22939087) + np.testing.assert_almost_equal(my_psds['IncanNumEnsemble'].sum(), 32.61006871) np.testing.assert_almost_equal(my_psds['ScatMassEnsemble'].sum(), 3.15026266) - np.testing.assert_almost_equal(my_psds['IncanMassEnsemble'].sum(), 0.08177226) + np.testing.assert_almost_equal(my_psds['IncanMassEnsemble'].sum(), 0.08280955) np.testing.assert_almost_equal(my_binary['DeadtimeRelativeBias'].mean(), -0.00023515) coeff, beam_profile = pysp2.util.beam_shape( my_binary, beam_position_from='peak maximum', Globals=pysp2.util.DMTGlobals())