From affb29e12d7b8f7473dd3c47c93f23470a21dcfd Mon Sep 17 00:00:00 2001 From: Tim Jarsky Date: Wed, 18 Dec 2024 16:28:08 -0800 Subject: [PATCH] WIP from live testing --- Packages/MIES/MIES_SweepFormula_Helpers.ipf | 38 ++++++++++++--------- Packages/MIES/MIES_SweepFormula_PSX.ipf | 28 +++++++-------- 2 files changed, 35 insertions(+), 31 deletions(-) diff --git a/Packages/MIES/MIES_SweepFormula_Helpers.ipf b/Packages/MIES/MIES_SweepFormula_Helpers.ipf index 26543e885c..5ff845e287 100644 --- a/Packages/MIES/MIES_SweepFormula_Helpers.ipf +++ b/Packages/MIES/MIES_SweepFormula_Helpers.ipf @@ -128,7 +128,7 @@ End Function/S SFH_GetArgumentAsText(variable jsonId, string jsonPath, string graph, string opShort, variable argNum, [string defValue, WAVE/Z/T allowedValues, FUNCREF SFH_StringChecker_Prototype checkFunc, variable checkDefault]) string msg, result, sep, allowedValuesAsStr - variable checkExist, numArgs, idx, ret + variable checkExist, numArgs, idx, ret, matchIndex if(ParamIsDefault(checkDefault)) checkDefault = 1 @@ -178,22 +178,26 @@ Function/S SFH_GetArgumentAsText(variable jsonId, string jsonPath, string graph, if(!ParamIsDefault(allowedValues)) ASSERT(WaveExists(allowedValues) && IsTextWave(allowedValues), "allowedValues must be a text wave") - // search are allowed entries and try to match a unique abbreviation - WAVE/Z/T matches = GrepTextWave(allowedValues, "(?i)^\\Q" + result + "\\E.*$") - if(!WaveExists(matches)) - sep = ", " - allowedValuesAsStr = TextWaveToList(allowedValues, sep, trailSep = 0) - sprintf msg, "Argument #%d of operation %s: The text argument \"%s\" is not one of the allowed values (%s)", argNum, opShort, result, allowedValuesAsStr - SFH_ASSERT(0, msg) - elseif(DimSize(matches, ROWS) > 1) - sep = ", " - allowedValuesAsStr = TextWaveToList(matches, sep, trailSep = 0) - sprintf msg, "Argument #%d of operation %s: The abbreviated text argument \"%s\" is not unique and could be (%s)", argNum, opShort, result, allowedValuesAsStr - SFH_ASSERT(0, msg) - else - ASSERT(DimSize(matches, ROWS) == 1, "Unexpected match") - // replace possibly abbreviated argument with its full name - result = matches[0] + matchIndex = GetRowIndex(allowedValues, str = result) + + if(IsNaN(matchIndex)) + // search are allowed entries and try to match a unique abbreviation + WAVE/Z/T matches = GrepTextWave(allowedValues, "(?i)^\\Q" + result + "\\E.*$") + if(!WaveExists(matches)) + sep = ", " + allowedValuesAsStr = TextWaveToList(allowedValues, sep, trailSep = 0) + sprintf msg, "Argument #%d of operation %s: The text argument \"%s\" is not one of the allowed values (%s)", argNum, opShort, result, allowedValuesAsStr + SFH_ASSERT(0, msg) + elseif(DimSize(matches, ROWS) > 1) + sep = ", " + allowedValuesAsStr = TextWaveToList(matches, sep, trailSep = 0) + sprintf msg, "Argument #%d of operation %s: The abbreviated text argument \"%s\" is not unique and could be (%s)", argNum, opShort, result, allowedValuesAsStr + SFH_ASSERT(0, msg) + else + ASSERT(DimSize(matches, ROWS) == 1, "Unexpected match") + // replace possibly abbreviated argument with its full name + result = matches[0] + endif endif endif diff --git a/Packages/MIES/MIES_SweepFormula_PSX.ipf b/Packages/MIES/MIES_SweepFormula_PSX.ipf index bcd49b0281..beeec23cb2 100644 --- a/Packages/MIES/MIES_SweepFormula_PSX.ipf +++ b/Packages/MIES/MIES_SweepFormula_PSX.ipf @@ -610,13 +610,8 @@ End static Function [variable peak, variable peak_t, variable baseline, variable baseline_t, variable amplitude] PSX_CalculateEventProperties(WAVE peakX, WAVE peakY, WAVE sweepDataOffFilt, variable kernelAmp, variable kernelRiseTau, variable kernelDecayTau, variable index) - variable deconvPeak, deconvPeak_t - - deconvPeak_t = peakX[index] - deconvPeak = peakY[index] - [peak_t, peak] = PSX_CalculateEventPeak(peakX, peakY, sweepDataOffFilt, kernelAmp, kernelRiseTau, kernelDecayTau, index) - [baseline_t, baseline] = PSX_CalculateEventBaseline(sweepDataOffFilt, deconvPeak_t, kernelAmp, kernelRiseTau) + [baseline_t, baseline] = PSX_CalculateEventBaseline(sweepDataOffFilt, peak_t, kernelAmp, kernelRiseTau) amplitude = peak - baseline @@ -654,7 +649,7 @@ static Function [WAVE/D peakX, WAVE/D peakY] PSX_AnalyzePeaks(WAVE sweepDataOffF if(i == 0) iei = NaN else - iei = deconvPeak_t - psxEvent[i - 1][%deconvPeak_t] + iei = peak_t - psxEvent[i - 1][%peak_t] endif psxEvent[i][%index] = i @@ -673,11 +668,6 @@ static Function [WAVE/D peakX, WAVE/D peakY] PSX_AnalyzePeaks(WAVE sweepDataOffF psxEvent[][%$"Fit manual QC call"] = PSX_UNDET psxEvent[][%$"Fit result"] = 0 - Multithread psxEvent[][%$"Rise Time"] = PSX_CalculateRiseTime(sweepDataOffFilt, psxEvent, kernelAmp, \ - riseTimeParams[%$"Lower Threshold"], \ - riseTimeParams[%$"Upper Threshold"], \ - p) - Make/FREE/D/N=0 sweepDataDiff Differentiate/EP=1 sweepDataOffFilt/D=sweepDataDiff @@ -688,6 +678,11 @@ static Function [WAVE/D peakX, WAVE/D peakY] PSX_AnalyzePeaks(WAVE sweepDataOffF riseTimeParams[%$"Differentiate Threshold"], \ p) + Multithread psxEvent[][%$"Rise Time"] = PSX_CalculateRiseTime(sweepDataOffFilt, psxEvent, kernelAmp, \ + riseTimeParams[%$"Lower Threshold"], \ + riseTimeParams[%$"Upper Threshold"], \ + p) + psxEvent[][%tau] = PSX_FitEventDecay(sweepDataOffFilt, psxEvent, maxTauFactor, eventFit, p) return [peakX, peakY] @@ -1261,7 +1256,7 @@ static Function [WAVE/D results, WAVE eventIndex, WAVE marker, WAVE/T comboKeys] if(!cmpstr(propLabel, "iei") && numEntries >= 2) // recalculate the iei as that might have changed due to in-between events being not selected - Multithread results[0, numEntries - 1] = events[indizes[p]][%deconvPeak_t] - (p >= 1 ? events[indizes[p - 1]][%deconvPeak_t] : NaN) + Multithread results[0, numEntries - 1] = events[indizes[p]][%peak_t] - (p >= 1 ? events[indizes[p - 1]][%peak_t] : NaN) else Multithread results[] = events[indizes[p]][%$propLabel] endif @@ -1738,7 +1733,12 @@ threadsafe static Function PSX_CalculateRiseTime(WAVE sweepDataOffFilt, WAVE psx // deconvPeak is defined in the deconvoluted wave, // so we can't use %deconvPeak as y-value - xStart = psxEvent[index][%deconvPeak_t] + xStart = psxEvent[index][%$"Onset Time"] + + if(IsNaN(xStart)) + return NaN + endif + yStart = sweepDataOffFilt(xStart) xEnd = psxEvent[index][%peak_t]