Skip to content

Commit

Permalink
changes
Browse files Browse the repository at this point in the history
  • Loading branch information
t-b committed Dec 18, 2024
1 parent cfcafbb commit 86fbbbf
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 20 deletions.
16 changes: 10 additions & 6 deletions Packages/MIES/MIES_SweepFormula_PSX.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -244,18 +244,22 @@ End

/// @brief Filter the sweep data
///
/// @param sweepData data from a single sweep and channel *without* inserted TP
/// @param high high cutoff [Hz]
/// @param low low cutoff [Hz]
static Function/WAVE PSX_FilterSweepData(WAVE sweepData, variable low, variable high)
/// @param sweepDataOff data from a single sweep and channel *without* inserted TP already offsetted
/// @param high high cutoff [Hz]
/// @param low low cutoff [Hz]
static Function/WAVE PSX_FilterSweepData(WAVE/Z sweepDataOff, variable low, variable high)

variable samp, err

samp = 1 / (deltax(sweepData) * MILLI_TO_ONE)
if(!WaveExists(sweepDataOff))
return $""
endif

samp = 1 / (deltax(sweepDataOff) * MILLI_TO_ONE)

ASSERT(low > high, "Expected a band pass filter with low > high")

Duplicate/FREE sweepData, filtered
Duplicate/FREE sweepDataOff, filtered

FilterIIR/LO=(low / samp)/HI=(high / samp)/DIM=(ROWS)/ORD=6 filtered; err = GetRTError(1)
SFH_ASSERT(!err, "Error filtering the data, msg: " + GetErrMessage(err))
Expand Down
39 changes: 25 additions & 14 deletions Packages/tests/Basic/UTF_SweepFormula_PSX.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,7 @@ Function/WAVE StatsTest_GetInput()
Duplicate/FREE/T template, wv6
WAVE/T input = wv6

input[%prop] = "xpos"
input[%prop] = "peaktime"
input[%state] = "undetermined"
input[%postProc] = "hist"

Expand Down Expand Up @@ -820,7 +820,7 @@ Function/WAVE StatsTest_GetInput()
Duplicate/FREE/T template, wv10
WAVE/T input = wv10

input[%prop] = "xpos"
input[%prop] = "peaktime"
input[%state] = "all"
input[%postProc] = "nonfinite"

Expand Down Expand Up @@ -1402,9 +1402,10 @@ End
static Function TestOperationPSX([STRUCT IUTF_mData &m])

string win, device, str, comboKey
variable jsonID, kernelAmp
variable jsonID, kernelAmp, kernelAmpSign

kernelAmp = m.v0
kernelAmp = m.v0
kernelAmpSign = sign(kernelAmp)

Make/FREE/T/N=2 combos

Expand All @@ -1418,6 +1419,7 @@ static Function TestOperationPSX([STRUCT IUTF_mData &m])

// all decay fits are successfull
overrideResults[][][%$"Fit Result"] = 1
overrideResults[][][%$"Tau"] = 1
overrideResults[][][%$"KernelAmpSignQC"] = 1

[win, device] = CreateEmptyUnlockedDataBrowserWindow()
Expand All @@ -1435,8 +1437,8 @@ static Function TestOperationPSX([STRUCT IUTF_mData &m])
CHECK_EQUAL_TEXTWAVES(dimlabels, {"sweepData_0", "sweepDataOffFilt_0", "sweepDataOffFiltDeconv_0", "peakX_0", "peakY_0", "psxEvent_0", "eventFit_0", \
"sweepData_1", "sweepDataOffFilt_1", "sweepDataOffFiltDeconv_1", "peakX_1", "peakY_1", "psxEvent_1", "eventFit_1"})

CheckEventDataHelper(dataWref, 0)
CheckEventDataHelper(dataWref, 1)
CheckEventDataHelper(dataWref, 0, kernelAmpSign)
CheckEventDataHelper(dataWref, 1, kernelAmpSign)

// check that we have parameters in the JSON wave note
jsonID = JWN_GetWaveNoteAsJSON(dataWref)
Expand All @@ -1451,7 +1453,7 @@ static Function TestOperationPSX([STRUCT IUTF_mData &m])

WAVE/Z params = JSON_GetKeys(jsonID, SF_META_USER_GROUP + "Parameters/" + SF_OP_PSX_RISETIME)
CHECK_WAVE(params, TEXT_WAVE)
CHECK_EQUAL_VAR(DimSize(params, ROWS), 2)
CHECK_EQUAL_VAR(DimSize(params, ROWS), 3)

JSON_Release(jsonID)

Expand All @@ -1462,7 +1464,7 @@ static Function TestOperationPSX([STRUCT IUTF_mData &m])
CHECK_WAVE(dataWref, WAVE_WAVE)

// without events found we get empty waves
str = "psx(myID, psxKernel(select(selrange([50, 150]), selchannels(AD6), selsweeps([0, 2]), selvis(all)), 5000, 15, -5), 25, 100, 0)"
str = "psx(myID, psxKernel(select(selrange([50, 150]), selchannels(AD6), selsweeps([0, 2]), selvis(all)), 10, 15, -5), 250, 10, 0)"
WAVE/WAVE dataWref = SF_ExecuteFormula(str, win, useVariables = 0)
CHECK_WAVE(dataWref, WAVE_WAVE)
Make/FREE/N=(DimSize(dataWref, ROWS)) sizes = WaveExists(dataWref[p]) ? DimSize(dataWref[p], ROWS) : NaN
Expand All @@ -1479,7 +1481,7 @@ static Function TestOperationPSX([STRUCT IUTF_mData &m])

// returns empty waves without events found due to kernelAmp sign
overrideResults[][][%$"KernelAmpSignQC"] = 0
str = "psx(id, psxKernel([50, 150], select(channels(AD6), [0, 2], all), 1, 15, -4))"
str = "psx(id, psxKernel(select(selrange([50, 150]), selchannels(AD6), selvis(all), selsweeps([0, 2])), 1, 15, -4))"
WAVE/WAVE dataWref = SF_ExecuteFormula(str, win, useVariables = 0)
CHECK_WAVE(dataWref, WAVE_WAVE)
Make/FREE/N=(DimSize(dataWref, ROWS)) sizes = WaveExists(dataWref[p]) ? DimSize(dataWref[p], ROWS) : NaN
Expand Down Expand Up @@ -1544,7 +1546,7 @@ static Function TestOperationPSXTooLargeDecayTau()
CHECK_EQUAL_WAVES(fitResult, {PSX_DECAY_FIT_ERROR, PSX_DECAY_FIT_ERROR}, mode = WAVE_DATA)
End

static Function CheckEventDataHelper(WAVE/Z/WAVE dataWref, variable index)
static Function CheckEventDataHelper(WAVE/Z/WAVE dataWref, variable index, variable kernelAmpSign)

variable numEvents

Expand All @@ -1571,12 +1573,21 @@ static Function CheckEventDataHelper(WAVE/Z/WAVE dataWref, variable index)
CHECK_EQUAL_VAR(Sum(comp), numEvents)

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

// 1 NaN for the first event only
WaveStats/M=0/Q psxEvent
CHECK_EQUAL_VAR(V_numNaNs, 1)
CHECK_EQUAL_VAR(V_numInfs, 0)

INFO("index = %d, V_numNaNs = %d, kernelAmpSign = %d", n0 = index, n1 = V_numNans, n2 = kernelAmpSign)

// 1 NaN for the first event only, the rest is onset Time
if(kernelAmpSign == 1)
CHECK_EQUAL_VAR(V_numNaNs, 3)
elseif(kernelAmpSign == -1)
CHECK_EQUAL_VAR(V_numNaNs, 5)
else
FAIL()
endif
End

static Function CheckPSXEventField(WAVE/WAVE psxEventWaves, WAVE/T colLabels, WAVE indices, variable val)
Expand Down Expand Up @@ -1989,7 +2000,7 @@ static Function/S GetTestCode(string postProc, [string eventState, string prop])
endif

if(ParamIsDefault(prop))
prop = "xpos"
prop = "peaktime"
endif

code = "psx(myId, psxKernel(select(selrange([50, 150]), selchannels(AD6), selsweeps([0, 2]), selvis(all))), 5, 100, 0)"
Expand Down

0 comments on commit 86fbbbf

Please sign in to comment.