Skip to content

Commit

Permalink
Merge pull request #2004 from AllenInstitute/bugfix/2004-adapt-psx-ti…
Browse files Browse the repository at this point in the history
…me-time-to-kernel-amp-sign

Make psx rise time sign dependent on kernel amp sign
  • Loading branch information
t-b authored Feb 14, 2024
2 parents 925bf75 + 9e506bb commit 5522624
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
11 changes: 6 additions & 5 deletions Packages/MIES/MIES_SweepFormula_PSX.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,7 @@ static Function PSX_OperationImpl(string graph, variable parameterJSONID, string

UpgradePSXEventWave(psxEvent)

WAVE riseTime = PSX_CalculateRiseTime(psxEvent, sweepDataFiltOff, parameterJsonID, riseTimeParams[%$"Lower Threshold"], riseTimeParams[%$"Upper Threshold"])
WAVE riseTime = PSX_CalculateRiseTime(psxEvent, sweepDataFiltOff, parameterJsonID, kernelAmp, riseTimeParams[%$"Lower Threshold"], riseTimeParams[%$"Upper Threshold"])
ASSERT(DimSize(riseTime, ROWS) == DimSize(psxEvent, ROWS), "Unmatched number of rows for rise time")
psxEvent[][%$"Rise Time"] = riseTime[p]
WaveClear riseTime
Expand Down Expand Up @@ -1403,7 +1403,7 @@ static Function/WAVE PSX_OperationStatsImpl(string graph, string id, WAVE rangeP
return output
End
static Function/WAVE PSX_CalculateRiseTime(WAVE psxEvent, WAVE sweepDataFiltOff, variable parameterJsonID, variable lowerThreshold, variable upperThreshold)
static Function/WAVE PSX_CalculateRiseTime(WAVE psxEvent, WAVE sweepDataFiltOff, variable parameterJsonID, variable kernelAmp, variable lowerThreshold, variable upperThreshold)
string psxParameters, comboKey, cacheKey
variable numEvents
Expand All @@ -1422,14 +1422,14 @@ static Function/WAVE PSX_CalculateRiseTime(WAVE psxEvent, WAVE sweepDataFiltOff,
Make/D/FREE/N=(numEvents) riseTime
riseTime[] = PSX_CalculateRiseTimeImpl(psxEvent, sweepDataFiltOff, psxEvent[p][%index], lowerThreshold, upperThreshold)
riseTime[] = PSX_CalculateRiseTimeImpl(psxEvent, sweepDataFiltOff, kernelAmp, psxEvent[p][%index], lowerThreshold, upperThreshold)
CA_StoreEntryIntoCache(cacheKey, riseTime)
return riseTime
End
static Function PSX_CalculateRiseTimeImpl(WAVE psxEvent, WAVE sweepDataFiltOff, variable index, variable lowerThreshold, variable upperThreshold)
static Function PSX_CalculateRiseTimeImpl(WAVE psxEvent, WAVE sweepDataFiltOff, variable kernelAmp, variable index, variable lowerThreshold, variable upperThreshold)
variable dY, xStart, xEnd, yStart, yEnd, xlt, xupt, lowerLevel, upperLevel, riseTime
variable printDebug
Expand Down Expand Up @@ -1466,7 +1466,8 @@ static Function PSX_CalculateRiseTimeImpl(WAVE psxEvent, WAVE sweepDataFiltOff,
printDebug = 1
endif
riseTime = xlt - xupt
ASSERT(kernelAmp != 0 && IsFinite(kernelAmp), "kernelAmp must be finite and not zero")
riseTime = (xlt - xupt) * sign(kernelAmp) * (-1)
#ifdef DEBUGGING_ENABLED
if(printDebug)
Expand Down
31 changes: 22 additions & 9 deletions Packages/tests/Basic/UTF_SweepFormula_PSX.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -1012,7 +1012,7 @@ static Function TestOperationPSXKernel()
win = CreateFakeSweepData(win, device, sweepNo = 0, sweepGen=FakeSweepDataGeneratorPSXKernel)
win = CreateFakeSweepData(win, device, sweepNo = 2, sweepGen=FakeSweepDataGeneratorPSXKernel)

str = "psxKernel([50, 150], select(channels(AD6), [0, 2], all), 1, 15, (-5))"
str = "psxKernel([50, 150], select(channels(AD6), [0, 2], all), 1, 15, -5)"
WAVE/WAVE dataWref = SF_ExecuteFormula(str, win, useVariables = 0)
CHECK_WAVE(dataWref, WAVE_WAVE)
CHECK_EQUAL_VAR(DimSize(dataWref, ROWS), 6)
Expand Down Expand Up @@ -1042,7 +1042,7 @@ static Function TestOperationPSXKernel()
CheckDimensionScaleHelper(dataWref[5], 50, 0.2)

// no data from select statement
str = "psxKernel([50, 150], select(channels(AD15), [0]), 1, 15, (-5))"
str = "psxKernel([50, 150], select(channels(AD15), [0]), 1, 15, -5)"
try
WAVE/WAVE dataWref = SF_ExecuteFormula(str, win, useVariables = 0)
FAIL()
Expand All @@ -1051,7 +1051,7 @@ static Function TestOperationPSXKernel()
endtry

// no data from this sweep statement
str = "psxKernel(ABCD, select(channels(AD6), [0, 2], all), 1, 15, (-5))"
str = "psxKernel(ABCD, select(channels(AD6), [0, 2], all), 1, 15, -5)"
try
WAVE/WAVE dataWref = SF_ExecuteFormula(str, win, useVariables = 0)
FAIL()
Expand Down Expand Up @@ -1084,9 +1084,19 @@ Function/WAVE FakeSweepDataGeneratorPSX(WAVE sweep, variable numChannels)
return sweep
End

static Function TestOperationPSX()
static Function/WAVE GetKernelAmplitude()

Make/D/FREE wv = {5, -5}

return wv
End

/// IUTF_TD_GENERATOR v0:GetKernelAmplitude
static Function TestOperationPSX([STRUCT IUTF_mData &m])
string win, device, str
variable jsonID
variable jsonID, kernelAmp

kernelAmp = m.v0

Make/FREE/T combos = {"Range[50, 150], Sweep [0], Channel [AD6], Device [ITC16_Dev_0]", \
"Range[50, 150], Sweep [2], Channel [AD6], Device [ITC16_Dev_0]"}
Expand All @@ -1100,7 +1110,7 @@ static Function TestOperationPSX()
win = CreateFakeSweepData(win, device, sweepNo = 0, sweepGen=FakeSweepDataGeneratorPSX)
win = CreateFakeSweepData(win, device, sweepNo = 2, sweepGen=FakeSweepDataGeneratorPSX)

str = "psx(myID, psxKernel([50, 150], select(channels(AD6), [0, 2], all), 1, 15, (-5)), 2.5, 100, 0)"
str = "psx(myID, psxKernel([50, 150], select(channels(AD6), [0, 2], all), 1, 15, " + num2str(kernelAmp) + "), 2.5, 100, 0)"
WAVE/WAVE dataWref = SF_ExecuteFormula(str, win, useVariables = 0)
CHECK_WAVE(dataWref, WAVE_WAVE)
CHECK_EQUAL_VAR(DimSize(dataWref, ROWS), 2 * 7)
Expand Down Expand Up @@ -1137,7 +1147,7 @@ static Function TestOperationPSX()
CHECK_WAVE(dataWref, WAVE_WAVE)

// complains without events found
str = "psx(myID, psxKernel([50, 150], select(channels(AD6), [0, 2], all), 5000, 15, (-5)), 2.5, 100, 0)"
str = "psx(myID, psxKernel([50, 150], select(channels(AD6), [0, 2], all), 5000, 15, -5), 2.5, 100, 0)"
try
WAVE/WAVE dataWref = SF_ExecuteFormula(str, win, useVariables = 0)
FAIL()
Expand All @@ -1162,7 +1172,7 @@ static Function TestOperationPSXTooLargeDecayTau()
win = CreateFakeSweepData(win, device, sweepNo = 0, sweepGen=FakeSweepDataGeneratorPSX)
win = CreateFakeSweepData(win, device, sweepNo = 2, sweepGen=FakeSweepDataGeneratorPSX)

str = "psx(myID, psxKernel([50, 150], select(channels(AD6), [0], all), 1, 15, (-5)), 1.5, 100, 0)"
str = "psx(myID, psxKernel([50, 150], select(channels(AD6), [0], all), 1, 15, -5), 1.5, 100, 0)"
WAVE/WAVE dataWref = SF_ExecuteFormula(str, win, useVariables = 0)
CHECK_WAVE(dataWref, WAVE_WAVE)

Expand Down Expand Up @@ -1200,6 +1210,9 @@ static Function CheckEventDataHelper(WAVE/WAVE/Z dataWref, variable index)
comp = psxEvent[p][%$"Event manual QC call"] == PSX_UNDET
CHECK_EQUAL_VAR(Sum(comp), numEvents)

comp = sign(psxEvent[p][%$"Rise Time"])
CHECK_EQUAL_VAR(Sum(comp), numEvents)

// 1 NaN for the first event only
WaveStats/M=0/Q psxEvent
CHECK_EQUAL_VAR(V_numNaNs, 1)
Expand Down Expand Up @@ -2900,7 +2913,7 @@ static Function TestOperationPrep()

win = CreateFakeSweepData(win, device, sweepNo = 0, sweepGen=FakeSweepDataGeneratorPSX)

psxCode = "psx(myID, psxKernel([50, 150], select(channels(AD6), [0, 2], all), 1, 15, (-5)), 2.5, 100, 0)"
psxCode = "psx(myID, psxKernel([50, 150], select(channels(AD6), [0, 2], all), 1, 15, -5), 2.5, 100, 0)"
sprintf code, "psxPrep(%s)", psxCode

WAVE/WAVE dataWref = SF_ExecuteFormula(code, win, useVariables = 0)
Expand Down

0 comments on commit 5522624

Please sign in to comment.