From 567980b6a8466f5461a65809ddf9c9a5f057d5d9 Mon Sep 17 00:00:00 2001 From: Thomas Braun Date: Wed, 17 Jan 2024 23:01:52 +0100 Subject: [PATCH] PSX_CreateHistogramOfDeconvSweepData: Rework it completely The old method was not very robust. Close #1980 --- Packages/MIES/MIES_SweepFormula_PSX.ipf | 39 ++++++------------- Packages/tests/Basic/UTF_SweepFormula_PSX.ipf | 10 ++--- 2 files changed, 16 insertions(+), 33 deletions(-) diff --git a/Packages/MIES/MIES_SweepFormula_PSX.ipf b/Packages/MIES/MIES_SweepFormula_PSX.ipf index 2b7b556d4c..ea31d4482a 100644 --- a/Packages/MIES/MIES_SweepFormula_PSX.ipf +++ b/Packages/MIES/MIES_SweepFormula_PSX.ipf @@ -369,38 +369,21 @@ static Function/WAVE PSX_DeconvoluteSweepData(WAVE sweepData, WAVE/C psxKernelFF end /// @brief Creates a histogram of the deconvoluted sweep data -static Function/WAVE PSX_CreateHistogramOfDeconvSweepData(WAVE deconvSweepData, [variable bin_start, variable bin_end, variable bin_width]) +static Function/WAVE PSX_CreateHistogramOfDeconvSweepData(WAVE deconvSweepData) - variable n_bins, tmp + variable n_bins, start, binWidth, range - StatsQuantiles/Q deconvSweepData + // we take +/- 80% of the average deviation around the average value + WaveStats/Q deconvSweepData + binWidth = 0.0001 + range = V_adev * 0.8 + start = V_avg - range + n_bins = 2 * range /binWidth - variable q75 = V_Q75 + SFH_ASSERT(n_bins > 10, "Histogram creation failed due to too few data points") - if(ParamIsDefault(bin_start)) - bin_start = q75 * -3 - endif - - if(ParamIsDefault(bin_end)) - bin_end = q75 * 3 - endif - - if(ParamIsDefault(bin_width)) - bin_width = 0.0005 - endif - - if(bin_start > bin_end) - tmp = bin_end - bin_end = bin_start - bin_start = tmp - endif - - n_bins = ceil((bin_end - bin_start) / bin_width) - - SFH_ASSERT(n_bins > 1, "Histogram creation failed due to too few data points") - - Make/FREE/N=0 hist - Histogram/B={bin_start, bin_width, n_bins}/DEST=hist deconvSweepData + Make/D/FREE/N=0 hist + Histogram/B={start, binWidth, n_bins}/DEST=hist deconvSweepData return hist end diff --git a/Packages/tests/Basic/UTF_SweepFormula_PSX.ipf b/Packages/tests/Basic/UTF_SweepFormula_PSX.ipf index 73bbb25b34..e1c07a60dc 100644 --- a/Packages/tests/Basic/UTF_SweepFormula_PSX.ipf +++ b/Packages/tests/Basic/UTF_SweepFormula_PSX.ipf @@ -1137,7 +1137,7 @@ static Function TestOperationPSX() CHECK_WAVE(dataWref, WAVE_WAVE) // complains without events found - str = "psx(myID, psxKernel([50, 150], select(channels(AD6), [0, 2], all), 5000, 15, (-5)), 2.5, 100, 0)" + str = "psx(myID, psxKernel([50, 150], select(channels(AD6), [0, 2], all), 5000, 15, (-5)), 25, 100, 0)" try WAVE/WAVE dataWref = SF_ExecuteFormula(str, win, useVariables = 0) FAIL() @@ -1162,7 +1162,7 @@ static Function TestOperationPSXTooLargeDecayTau() win = CreateFakeSweepData(win, device, sweepNo = 0, sweepGen=FakeSweepDataGeneratorPSX) win = CreateFakeSweepData(win, device, sweepNo = 2, sweepGen=FakeSweepDataGeneratorPSX) - str = "psx(myID, psxKernel([50, 150], select(channels(AD6), [0], all), 1, 15, (-5)), 1.5, 100, 0)" + str = "psx(myID, psxKernel([50, 150], select(channels(AD6), [0], all), 1, 15, (-5)), 5, 100, 0)" WAVE/WAVE dataWref = SF_ExecuteFormula(str, win, useVariables = 0) CHECK_WAVE(dataWref, WAVE_WAVE) @@ -1265,7 +1265,7 @@ static Function MouseSelectionPSX() browser = MIES_DB#DB_LockToDevice(browser, device) - code = "psx(myId, psxKernel([50, 150], select(channels(AD6), [0, 2], all)), 1.5, 100, 0)" + code = "psx(myId, psxKernel([50, 150], select(channels(AD6), [0, 2], all)), 5, 100, 0)" // combo0 is the current one @@ -1627,9 +1627,9 @@ static Function/WAVE GetCodeVariations() code = "" // one sweep per operation separated with `with` - code = "psx(myId, psxKernel([50, 150], select(channels(AD6), [0], all)), 1.8, 100, 0)" + code = "psx(myId, psxKernel([50, 150], select(channels(AD6), [0], all)), 10, 100, 0)" code += "\r with \r" - code += "psx(myId, psxKernel([50, 150], select(channels(AD6), [2], all)), 8, 100, 0)" + code += "psx(myId, psxKernel([50, 150], select(channels(AD6), [2], all)), 2.5, 100, 0)" code += "\r and \r" code += "psxStats(myId, [50, 150], select(channels(AD6), [0, 2], all), xpos, all, nothing)" wv[1] = code