Skip to content

Commit 511fbda

Browse files
committed
PSX_FitEventDecay: Support three tau instead of one
1 parent 35b516f commit 511fbda

File tree

3 files changed

+80
-44
lines changed

3 files changed

+80
-44
lines changed

Packages/MIES/MIES_Cache.ipf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ End
442442
/// @param psxParameters JSON dump of the psx/psxKernel operation parameters
443443
Function/S CA_PSXEventsKey(string comboKey, string psxParameters)
444444

445-
return CA_PSXBaseKey(comboKey, psxParameters) + " Events " + ":Version 2"
445+
return CA_PSXBaseKey(comboKey, psxParameters) + " Events " + ":Version 3"
446446
End
447447

448448
Function/S CA_PSXOperationKey(string comboKey, string psxParameters)

Packages/MIES/MIES_SweepFormula_PSX.ipf

Lines changed: 56 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,8 @@ static Function [WAVE/D peakX, WAVE/D peakY] PSX_AnalyzePeaks(WAVE sweepDataOffF
744744
riseTimeParams[%$"Upper Threshold"], \
745745
p)
746746

747-
psxEvent[][%tau] = PSX_FitEventDecay(sweepDataOffFilt, psxEvent, maxTauFactor, eventFit, p)
747+
Make/FREE/N=(DimSize(psxEvent, ROWS)) indexHelper
748+
indexHelper[] = PSX_FitEventDecay(sweepDataOffFilt, psxEvent, maxTauFactor, eventFit, p)
748749

749750
return [peakX, peakY]
750751
End
@@ -855,19 +856,23 @@ End
855856
///
856857
/// \rst
857858
///
858-
/// exp_XOffset: :math:`y = K0 + K1 \cdot exp(-(x - x0)/K2)`
859+
/// dblexp_XOffset: :math:`y = K0 + K1 \cdot exp(-(x - x0) / K2) + K3 * exp(-(x - x0) / K4)`
859860
///
860861
/// \endrst
861862
static Function PSX_FitEventDecay(WAVE sweepDataOffFilt, WAVE psxEvent, variable maxTauFactor, WAVE/WAVE eventFit, variable eventIndex)
862863

863-
variable startTime, endTime, err, decayTau, fitRange, overrideTau
864+
variable startTime, endTime, err, weightedTau, slowTau, fastTau, fitRange, overrideTau
864865
string comboKey
865866

866867
[startTime, endTime] = PSX_GetEventFitRange(sweepDataOffFilt, psxEvent, eventIndex)
867868

868869
if(IsNaN(startTime) && IsNaN(endTime))
869870
psxEvent[eventIndex][%$"Fit manual QC call"] = PSX_REJECT
870871
psxEvent[eventIndex][%$"Fit result"] = PSX_DECAY_FIT_INVALID_RANGE_ERROR
872+
psxEvent[eventIndex][%weightedTau] = NaN
873+
psxEvent[eventIndex][%slowTau] = NaN
874+
psxEvent[eventIndex][%fastTau] = NaN
875+
871876
return NaN
872877
endif
873878

@@ -886,7 +891,9 @@ static Function PSX_FitEventDecay(WAVE sweepDataOffFilt, WAVE psxEvent, variable
886891

887892
SetDataFolder currDFR
888893
// weighted tau computed from double exponential fit
889-
decayTau = ((coefWave[1] * coefWave[2] + coefWave[3] * coefWave[4]) / (coefWave[1] + coefWave[3]))
894+
slowTau = coefWave[2]
895+
fastTau = coefWave[4]
896+
weightedTau = ((coefWave[1] * slowTau + coefWave[3] * fastTau) / (coefWave[1] + coefWave[3]))
890897

891898
#ifdef AUTOMATED_TESTING
892899
WAVE/Z overrideResults = GetOverrideResults()
@@ -900,22 +907,30 @@ static Function PSX_FitEventDecay(WAVE sweepDataOffFilt, WAVE psxEvent, variable
900907
overrideTau = overrideResults[eventIndex][%$comboKey][%Tau]
901908

902909
if(!IsNaN(overrideTau))
903-
decayTau = overrideTau
910+
weightedTau = overrideTau
904911
endif
905912
endif
906913
#endif // AUTOMATED_TESTING
907914

908915
if(err)
909916
psxEvent[eventIndex][%$"Fit manual QC call"] = PSX_REJECT
910917
psxEvent[eventIndex][%$"Fit result"] = -err
918+
psxEvent[eventIndex][%weightedTau] = NaN
919+
psxEvent[eventIndex][%slowTau] = NaN
920+
psxEvent[eventIndex][%fastTau] = NaN
921+
911922
return NaN
912923
endif
913924

914925
fitRange = endTime - startTime
915926

916-
if(IsFinite(decayTau) && decayTau > (maxTauFactor * fitRange))
927+
if(IsFinite(weightedTau) && weightedTau > (maxTauFactor * fitRange))
917928
psxEvent[eventIndex][%$"Fit manual QC call"] = PSX_REJECT
918929
psxEvent[eventIndex][%$"Fit result"] = PSX_DECAY_FIT_ERROR
930+
psxEvent[eventIndex][%weightedTau] = NaN
931+
psxEvent[eventIndex][%slowTau] = NaN
932+
psxEvent[eventIndex][%fastTau] = NaN
933+
919934
return NaN
920935
endif
921936

@@ -925,8 +940,9 @@ static Function PSX_FitEventDecay(WAVE sweepDataOffFilt, WAVE psxEvent, variable
925940
eventFit[eventIndex] = fit
926941
psxEvent[eventIndex][%$"Fit result"] = 1
927942
psxEvent[eventIndex][%$"Fit manual QC call"] = PSX_UNDET
928-
929-
return decayTau
943+
psxEvent[eventIndex][%weightedTau] = weightedTau
944+
psxEvent[eventIndex][%slowTau] = slowTau
945+
psxEvent[eventIndex][%fastTau] = fastTau
930946
End
931947

932948
/// @brief Create the override results 2D wave
@@ -1216,8 +1232,14 @@ static Function [WAVE/D results, WAVE eventIndex, WAVE marker, WAVE/T comboKeys]
12161232
case "xinterval":
12171233
propLabel = "iei"
12181234
break
1219-
case "tau":
1220-
propLabel = "tau"
1235+
case "slowtau":
1236+
propLabel = "slowTau"
1237+
break
1238+
case "fasttau":
1239+
propLabel = "fastTau"
1240+
break
1241+
case "weightedtau":
1242+
propLabel = "weightedTau"
12211243
break
12221244
case "estate":
12231245
propLabel = "Event manual QC call"
@@ -1262,7 +1284,9 @@ static Function [WAVE/D results, WAVE eventIndex, WAVE marker, WAVE/T comboKeys]
12621284
stateType = "Event manual QC call"
12631285
break
12641286
case "Fit result":
1265-
case "tau":
1287+
case "slowtau":
1288+
case "fasttau":
1289+
case "weightedtau":
12661290
case "Fit manual QC call":
12671291
stateType = "Fit manual QC call"
12681292
break
@@ -1556,8 +1580,14 @@ static Function/WAVE PSX_OperationStatsImpl(string graph, string id, WAVE/WAVE s
15561580
case "xinterval":
15571581
propLabelAxis = "Event interval" + " (" + JWN_GetStringFromWaveNote(allEvents[0], PSX_X_DATA_UNIT) + ")"
15581582
break
1559-
case "tau":
1560-
propLabelAxis = "Decay tau" + " (" + JWN_GetStringFromWaveNote(allEvents[0], PSX_X_DATA_UNIT) + ")"
1583+
case "slowtau":
1584+
propLabelAxis = "Slow tau" + " (" + JWN_GetStringFromWaveNote(allEvents[0], PSX_X_DATA_UNIT) + ")"
1585+
break
1586+
case "fasttau":
1587+
propLabelAxis = "Fast tau" + " (" + JWN_GetStringFromWaveNote(allEvents[0], PSX_X_DATA_UNIT) + ")"
1588+
break
1589+
case "weightedtau":
1590+
propLabelAxis = "Weighted tau" + " (" + JWN_GetStringFromWaveNote(allEvents[0], PSX_X_DATA_UNIT) + ")"
15611591
break
15621592
case "estate":
15631593
propLabelAxis = "Event manual QC" + " (enum)"
@@ -3002,9 +3032,9 @@ static Function PSX_UpdateSingleEventTextbox(string win, [variable eventIndex])
30023032
DFREF comboDFR = PSX_GetCurrentComboFolder(win)
30033033
WAVE psxEvent = GetPSXEventWaveFromDFR(comboDFR)
30043034

3005-
Make/FREE/T/N=(8, 2) input
3035+
Make/FREE/T/N=(10, 2) input
30063036

3007-
input[0][0] = {"Event State:", "Fit State:", "Fit Result:", "Event:", "Deconv Peak:", "Peak:", "Baseline:", "IeI:", "Amp (rel.):", "Tau:", "Onset time:", "Rise time:"}
3037+
input[0][0] = {"Event State:", "Fit State:", "Fit Result:", "Event:", "Deconv Peak:", "Peak:", "Baseline:", "IeI:", "Amp (rel.):", "Slow tau:", "Fast tau:", "Weighted tau:", "Onset time:", "Rise time:"}
30083038
input[0][1] = {PSX_StateToString(psxEvent[eventIndex][%$"Event manual QC call"]), \
30093039
PSX_StateToString(psxEvent[eventIndex][%$"Fit manual QC call"]), \
30103040
PSX_FitResultToString(psxEvent[eventIndex][%$"Fit Result"]), \
@@ -3014,7 +3044,9 @@ static Function PSX_UpdateSingleEventTextbox(string win, [variable eventIndex])
30143044
num2str(psxEvent[eventIndex][%baseline_t], "%8.02f") + " [ms]", \
30153045
num2str(psxEvent[eventIndex][%iei], "%8.02f") + " [ms]", \
30163046
num2str(psxEvent[eventIndex][%amplitude], "%8.02f") + " [" + yUnit + "]", \
3017-
num2str(psxEvent[eventIndex][%tau], "%8.02f") + " [ms]", \
3047+
num2str(psxEvent[eventIndex][%slowTau], "%8.02f") + " [ms]", \
3048+
num2str(psxEvent[eventIndex][%fastTau], "%8.02f") + " [ms]", \
3049+
num2str(psxEvent[eventIndex][%weightedTau], "%8.02f") + " [ms]", \
30183050
num2str(psxEvent[eventIndex][%$"Onset Time"], "%8.02f") + " [ms]", \
30193051
num2str(psxEvent[eventIndex][%$"Rise Time"], "%8.02f") + " [ms]"}
30203052

@@ -5155,14 +5187,14 @@ End
51555187

51565188
static Function/WAVE PSX_GetAllStatsProperties()
51575189

5158-
Make/FREE/T allProps = {"amp", \
5159-
"peak", "peaktime", \
5160-
"deconvpeak", "deconvpeaktime", \
5161-
"baseline", "baselinetime", \
5162-
"xinterval", \
5163-
"tau", \
5164-
"estate", "fstate", "fitresult", \
5165-
"slewrate", "slewratetime", \
5190+
Make/FREE/T allProps = {"amp", \
5191+
"peak", "peaktime", \
5192+
"deconvpeak", "deconvpeaktime", \
5193+
"baseline", "baselinetime", \
5194+
"xinterval", \
5195+
"slowtau", "fasttau", "weightedtau", \
5196+
"estate", "fstate", "fitresult", \
5197+
"slewrate", "slewratetime", \
51665198
"risetime", "onsettime"}
51675199

51685200
return allProps

Packages/MIES/MIES_WaveDataFolderGetters.ipf

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8342,15 +8342,15 @@ End
83428342
/// @name SweepFormula PSX
83438343
///@{
83448344

8345-
static Constant PSX_WAVE_VERSION = 3
8346-
static Constant PSX_EVENT_WAVE_COLUMNS = 17
8345+
static Constant PSX_WAVE_VERSION = 4
8346+
static Constant PSX_EVENT_WAVE_COLUMNS = 19
83478347

83488348
/// @brief Return the upgraded psxEvent wave
83498349
Function/WAVE UpgradePSXEventWave(WAVE psxEvent)
83508350

83518351
if(WaveVersionIsAtLeast(psxEvent, PSX_WAVE_VERSION))
83528352
return psxEvent
8353-
elseif(WaveVersionIsAtLeast(psxEvent, 2))
8353+
elseif(WaveVersionIsAtLeast(psxEvent, 2)) // Version 2 and 3
83548354

83558355
if(!AlreadyCalledOnce(CO_PSX_UPGRADE_EVENT))
83568356
print "The algorithm for psp/psc event detection was heavily overhauled, therefore we are very sorry " \
@@ -8388,16 +8388,18 @@ End
83888388
/// - 6/baseline_t: baseline time
83898389
/// - 7/amplitude: Relative amplitude: [3] - [5]
83908390
/// - 8/iei: Time difference to previous event (inter event interval) [ms]
8391-
/// - 9/tau: Decay constant tau of exponential fit
8392-
/// - 10/Fit manual QC call: One of @ref PSXStates
8393-
/// - 11/Fit result: 1 for success, everything smaller than 0 is failure:
8391+
/// - 9/weightedTau: Weighted tau of the double exponential fit
8392+
/// - 10/fastTau: Fast tau of the double exponential fit
8393+
/// - 11/slowTau: Slow tau of the double exponential fit
8394+
/// - 12/Fit manual QC call: One of @ref PSXStates
8395+
/// - 13/Fit result: 1 for success, everything smaller than 0 is failure:
83948396
/// - `]-10000, 0[`: CurveFit error codes
83958397
/// - `]-inf, -10000]`: Custom error codes, one of @ref FitEventDecayCustomErrors
8396-
/// - 12/Event manual QC call: One of @ref PSXStates
8397-
/// - 13/Onset time as calculated by PSX_CalculateOnsetTime
8398-
/// - 14/Rise Time as calculated by PSX_CalculateRiseTime
8399-
/// - 15/Slew Rate
8400-
/// - 16/Slew Rate Time
8398+
/// - 14/Event manual QC call: One of @ref PSXStates
8399+
/// - 15/Onset time as calculated by PSX_CalculateOnsetTime
8400+
/// - 16/Rise Time as calculated by PSX_CalculateRiseTime
8401+
/// - 17/Slew Rate
8402+
/// - 18/Slew Rate Time
84018403
Function/WAVE GetPSXEventWaveAsFree()
84028404

84038405
variable versionOfWave = PSX_WAVE_VERSION
@@ -8422,14 +8424,16 @@ static Function SetPSXEventDimensionLabels(WAVE wv)
84228424
SetDimLabel COLS, 6, baseline_t, wv
84238425
SetDimLabel COLS, 7, amplitude, wv
84248426
SetDimLabel COLS, 8, iei, wv
8425-
SetDimLabel COLS, 9, tau, wv
8426-
SetDimLabel COLS, 10, $"Fit manual QC call", wv
8427-
SetDimLabel COLS, 11, $"Fit result", wv
8428-
SetDimLabel COLS, 12, $"Event manual QC call", wv
8429-
SetDimLabel COLS, 13, $"Onset Time", wv
8430-
SetDimLabel COLS, 14, $"Rise Time", wv
8431-
SetDimLabel COLS, 15, $"Slew Rate", wv
8432-
SetDimLabel COLS, 16, $"Slew Rate Time", wv
8427+
SetDimLabel COLS, 9, weightedTau, wv
8428+
SetDimLabel COLS, 10, slowTau, wv
8429+
SetDimLabel COLS, 11, fastTau, wv
8430+
SetDimLabel COLS, 12, $"Fit manual QC call", wv
8431+
SetDimLabel COLS, 13, $"Fit result", wv
8432+
SetDimLabel COLS, 14, $"Event manual QC call", wv
8433+
SetDimLabel COLS, 15, $"Onset Time", wv
8434+
SetDimLabel COLS, 16, $"Rise Time", wv
8435+
SetDimLabel COLS, 17, $"Slew Rate", wv
8436+
SetDimLabel COLS, 18, $"Slew Rate Time", wv
84338437
End
84348438

84358439
Function/WAVE GetPSXSingleEventFitWaveFromDFR(DFREF dfr)

0 commit comments

Comments
 (0)