Skip to content

Commit

Permalink
WIP from live testing
Browse files Browse the repository at this point in the history
  • Loading branch information
timjarsky committed Dec 19, 2024
1 parent 2dae507 commit affb29e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 31 deletions.
38 changes: 21 additions & 17 deletions Packages/MIES/MIES_SweepFormula_Helpers.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
28 changes: 14 additions & 14 deletions Packages/MIES/MIES_SweepFormula_PSX.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -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

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

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

0 comments on commit affb29e

Please sign in to comment.