Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
timjarsky committed Dec 16, 2024
1 parent e76868b commit 7c1b18a
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 6 deletions.
18 changes: 12 additions & 6 deletions Packages/MIES/MIES_SweepFormula_PSX.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -1128,9 +1128,8 @@ static Function [WAVE/D results, WAVE eventIndex, WAVE marker, WAVE/T comboKeys]
case "amp":
propLabel = "amplitude"
break
case "xpos":
propLabel = "onset_t"
break
// add peak, peak_t, deconvPeak, deconvPeak_t, baseline_t, baseline
// add slew rate and slew rate time
case "xinterval":
propLabel = "iei"
break
Expand All @@ -1146,6 +1145,7 @@ static Function [WAVE/D results, WAVE eventIndex, WAVE marker, WAVE/T comboKeys]
case "fitresult":
propLabel = "Fit result"
break
// add onset time
case "risetime":
propLabel = "Rise Time"
break
Expand Down Expand Up @@ -1937,12 +1937,16 @@ static Function PSX_UpdateOffsetInAllEventGraph(string win)
switch(offsetMode)
case PSX_HORIZ_OFFSET_ONSET:
xOffset = 0
yOffset = sweepDataOffFilt(psxEvent[i][%onset_t])
yOffset = sweepDataOffFilt(psxEvent[i][%$"Onset Time"])
break
case PSX_HORIZ_OFFSET_PEAK:
xOffset = first - psxEvent[i][%onset_t]
xOffset = first - psxEvent[i][%peak_t]
yOffset = 0
break
// case PSX_HORIZ_OFFSET_SLEW: // call it Slew Rate
// xOffset = first - psxEvent[i][%$"Slew Rate Time"]
// yOffset = 0
// break
default:
ASSERT(0, "Invalid offset mode")
endswitch
Expand Down Expand Up @@ -2740,7 +2744,7 @@ static Function PSX_UpdateSingleEventTextbox(string win, [variable eventIndex])

Make/FREE/T/N=(8, 2) input

input[0][0] = {"Event State:", "Fit State:", "Fit Result:", "Event:", "Onset:", "IeI:", "Amp (rel.):", "Tau:", "Rise time:"}
input[0][0] = {"Event State:", "Fit State:", "Fit Result:", "Event:", "Deconv Peak:", "IeI:", "Amp (rel.):", "Tau:", "Rise time:"}
input[0][1] = {PSX_StateToString(psxEvent[eventIndex][%$"Event manual QC call"]), \
PSX_StateToString(psxEvent[eventIndex][%$"Fit manual QC call"]), \
PSX_FitResultToString(psxEvent[eventIndex][%$"Fit Result"]), \
Expand All @@ -2750,6 +2754,7 @@ static Function PSX_UpdateSingleEventTextbox(string win, [variable eventIndex])
num2str(psxEvent[eventIndex][%amplitude], "%8.02f") + " [" + yUnit + "]", \
num2str(psxEvent[eventIndex][%tau], "%8.02f") + " [ms]", \
num2str(psxEvent[eventIndex][%$"Rise Time"], "%8.02f") + " [ms]"}
// TODO add onset time before rise time

str = "\F'Consolas'" + FormatTextWaveForLegend(input)

Expand Down Expand Up @@ -4698,6 +4703,7 @@ Function/WAVE PSX_OperationStats(variable jsonId, string jsonPath, string graph)
WAVE/Z selectData = selectDataComp[%SELECTION]
WAVE/WAVE range = selectDataComp[%RANGE]

// TODO add onsetTime and slew rate, slew
Make/FREE/T allProps = {"amp", "xpos", "xinterval", "tau", "estate", "fstate", "fitresult", "risetime"}
prop = SFH_GetArgumentAsText(jsonID, jsonPath, graph, SF_OP_PSX_STATS, 2, allowedValues = allProps)
Make/FREE/T allStates = {"accept", "reject", "undetermined", "all", "every"}
Expand Down
58 changes: 58 additions & 0 deletions Packages/MIES/MIES_WaveDataFolderGetters.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -8212,6 +8212,64 @@ Function UpgradePSXEventWave(WAVE psxEvent)
endif
End

+static Function/WAVE PSX_CalculateOnsetTimeImpl(WAVE psxEvent, WAVE sweepData, variable kernelAmp, variable diffThreshPerc)
+
+ variable numEvents
+
+ Make/FREE/D/N=0 diff
+ Differentiate/EP=1 sweepData/D=diff
+
+ numEvents = DimSize(psxEvent, ROWS)
+ Make/FREE/D/N=(numEvents) onset
+
+ Multithread onset[] = PSX_CalculateOnsetTimeImplEvent(diff, psxEvent[p][%peak_t], psxEvent[p][%baseline_t], kernelAmp, diffThreshPerc)
+
+ return onset
+End
+
+threadsafe static Function PSX_CalculateOnsetTimeImplEvent(WAVE diff, variable peak_t, variable baseline_t, variable kernelAmp, variable diffThreshPerc)
+
+ variable diffPeak, diffPeak_t, level
+
+ ASSERT_TS(peak_t < baseline_t, "Unexpected ordering of peak_t and baseline_t")
+
+ WaveStats/Q/M=1/R=(peak_t, baseline_t) diff
+ if(kernelAmp > 0)
+ diffPeak = V_max
+ diffPeak_t = V_maxLoc
+ elseif(kernelAmp < 0)
+ diffPeak = V_min
+ diffPeak_t = V_minLoc
+ else
+ ASSERT_TS(0, "Unsupported case: kernelAmp being zero")
+ endif
+ // TODO store diffPeak, diffPeak_t in psxEvent
+ // Names: "Slew Rate" and "Slew Rate Time"
+
+ // TODO check sign
+ level = diffThreshPerc * (diffPeak - diff(baseline_t))
+
+ // search backwards in time
+ FindLevel/R=(diffPeak_t, baseline_t) diff, level
+
+ if(V_flag)
return NaN
endif

return V_levelX
+End
+
+// New function:
+// PSX_OnsetTime(peak_t, baseline_t, DiffV)
+/// onset_t = time of the percentDiffThresh amplitude of the 1st differential of the event
+/// percentDiffThresh taken from psxRiseTime user input, default to 5%
+// Order of operations:
+// 1. DiffV = Differentiated sweep trace
+// 2. DiffPeak = the peak of the differentiated trace between [peak_t - baseline_t], peak = min for (–) kernel sign, max for (+) kernel sign
+// 3. DiffPeak_t = time of DiffPeak
+// 4. onset_t = findlevel/R= (DiffPeak_t, baseline_t) wave = DiffV, level=(percentDiffThresh * DiffPeak)
+// 5. Return onset_t
+
/// @brief Return a 2D events wave as free wave
///
/// Rows:
Expand Down

0 comments on commit 7c1b18a

Please sign in to comment.