Skip to content

Commit b57060e

Browse files
committed
PSX_CalculateRiseTime: Factor it out
And rename the original function to PSX_CalculateRiseTimeWrapper.
1 parent 47f1425 commit b57060e

File tree

1 file changed

+33
-26
lines changed

1 file changed

+33
-26
lines changed

Packages/MIES/MIES_SweepFormula_PSX.ipf

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -702,10 +702,10 @@ static Function [WAVE/D peakX, WAVE/D peakY] PSX_AnalyzePeaks(WAVE sweepDataOffF
702702
riseTimeParams[%$"Differentiate Threshold"], \
703703
p)
704704

705-
Multithread psxEvent[][%$"Rise Time"] = PSX_CalculateRiseTime(sweepDataOffFilt, psxEvent, kernelAmp, \
706-
riseTimeParams[%$"Lower Threshold"], \
707-
riseTimeParams[%$"Upper Threshold"], \
708-
p)
705+
Multithread psxEvent[][%$"Rise Time"] = PSX_CalculateRiseTimeWrapper(sweepDataOffFilt, psxEvent, kernelAmp, \
706+
riseTimeParams[%$"Lower Threshold"], \
707+
riseTimeParams[%$"Upper Threshold"], \
708+
p)
709709

710710
psxEvent[][%tau] = PSX_FitEventDecay(sweepDataOffFilt, psxEvent, maxTauFactor, eventFit, p)
711711

@@ -1739,25 +1739,40 @@ static Function/WAVE PSX_OperationStatsImpl(string graph, string id, WAVE/WAVE s
17391739
return output
17401740
End
17411741

1742-
threadsafe static Function PSX_CalculateRiseTime(WAVE sweepDataOffFilt, WAVE psxEvent, variable kernelAmp, variable lowerThreshold, variable upperThreshold, variable index)
1742+
threadsafe static Function PSX_CalculateRiseTimeWrapper(WAVE sweepDataOffFilt, WAVE psxEvent, variable kernelAmp, variable lowerThreshold, variable upperThreshold, variable index)
17431743

1744-
variable dY, xStart, xEnd, yStart, yEnd, xlt, xupt, lowerLevel, upperLevel, riseTime
1745-
variable printDebug
1746-
string comboKey
1744+
variable error, xStart, xEnd, yStart, yEnd, riseTime
1745+
string comboKey
17471746

17481747
// deconvPeak is defined in the deconvoluted wave,
17491748
// so we can't use %deconvPeak as y-value
17501749
xStart = psxEvent[index][%$"Onset Time"]
1751-
1752-
if(IsNaN(xStart))
1753-
return NaN
1754-
endif
1755-
17561750
yStart = sweepDataOffFilt(xStart)
17571751

17581752
xEnd = psxEvent[index][%peak_t]
17591753
yEnd = psxEvent[index][%peak]
17601754

1755+
[riseTime, error] = PSX_CalculateRiseTime(sweepDataOffFilt, xStart, xEnd, yStart, yEnd, lowerThreshold, upperThreshold, kernelAmp)
1756+
1757+
#ifdef DEBUGGING_ENABLED
1758+
if(error)
1759+
comboKey = JWN_GetStringFromWaveNote(psxEvent, PSX_EVENTS_COMBO_KEY_WAVE_NOTE)
1760+
1761+
printf "comboKey: %s, x: [%g, %g], y: [%g, %g], index: %d, dY: %g, thresholds: [%g, %g], levels: [%g, %g], risetime: %g, xlt: %g, xupt: %g\r", comboKey, xStart, xEnd, yStart, yEnd, index, dY, lowerThreshold, upperThreshold, lowerLevel, upperLevel, risetime, xlt, xupt
1762+
endif
1763+
#endif // DEBUGGING_ENABLED
1764+
1765+
return riseTime
1766+
End
1767+
1768+
threadsafe static Function [variable riseTime, variable error] PSX_CalculateRiseTime(WAVE data, variable xStart, variable xEnd, variable yStart, variable yEnd, variable lowerThreshold, variable upperThreshold, variable kernelAmp)
1769+
1770+
variable dY, xlt, xupt, lowerLevel, upperLevel
1771+
1772+
if(IsNaN(xStart))
1773+
return [NaN, 0]
1774+
endif
1775+
17611776
dY = abs(yStart - yEnd)
17621777

17631778
lowerLevel = min(yStart, yEnd) + lowerThreshold * dY
@@ -1767,34 +1782,26 @@ threadsafe static Function PSX_CalculateRiseTime(WAVE sweepDataOffFilt, WAVE psx
17671782
xlt = NaN
17681783
xupt = NaN
17691784

1770-
FindLevel/R=(xStart, xEnd)/Q sweepDataOffFilt, lowerLevel
1785+
FindLevel/R=(xStart, xEnd)/Q data, lowerLevel
17711786

17721787
if(!V_flag)
17731788
xlt = V_levelX
17741789
else
1775-
printDebug = 1
1790+
error = 1
17761791
endif
17771792

1778-
FindLevel/R=(xStart, xEnd)/Q sweepDataOffFilt, upperLevel
1793+
FindLevel/R=(xStart, xEnd)/Q data, upperLevel
17791794

17801795
if(!V_flag)
17811796
xupt = V_levelX
17821797
else
1783-
printDebug = 1
1798+
error = 1
17841799
endif
17851800

17861801
ASSERT_TS(kernelAmp != 0 && IsFinite(kernelAmp), "kernelAmp must be finite and not zero")
17871802
riseTime = (xlt - xupt) * sign(kernelAmp) * (-1)
17881803

1789-
#ifdef DEBUGGING_ENABLED
1790-
if(printDebug)
1791-
comboKey = JWN_GetStringFromWaveNote(psxEvent, PSX_EVENTS_COMBO_KEY_WAVE_NOTE)
1792-
1793-
printf "comboKey: %s, x: [%g, %g], y: [%g, %g], index: %d, dY: %g, thresholds: [%g, %g], levels: [%g, %g], risetime: %g, xlt: %g, xupt: %g\r", comboKey, xStart, xEnd, yStart, yEnd, index, dY, lowerThreshold, upperThreshold, lowerLevel, upperLevel, risetime, xlt, xupt
1794-
endif
1795-
#endif // DEBUGGING_ENABLED
1796-
1797-
return riseTime
1804+
return [riseTime, error]
17981805
End
17991806

18001807
threadsafe static Function PSX_CalculateOnsetTime(WAVE sweepDataDiff, WAVE psxEvent, variable kernelAmp, variable diffThreshPerc, variable index)

0 commit comments

Comments
 (0)