Skip to content

Commit

Permalink
PSX_CreateHistogramOfDeconvSweepData: Rework it completely
Browse files Browse the repository at this point in the history
The old method was not very robust.

Close #1980
  • Loading branch information
t-b committed Feb 6, 2024
1 parent a98dc05 commit 567980b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 33 deletions.
39 changes: 11 additions & 28 deletions Packages/MIES/MIES_SweepFormula_PSX.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions Packages/tests/Basic/UTF_SweepFormula_PSX.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 567980b

Please sign in to comment.