Skip to content

Commit

Permalink
fix psx: Needs integration and doc changes
Browse files Browse the repository at this point in the history
  • Loading branch information
t-b committed Sep 17, 2024
1 parent 36b7c85 commit 50f5169
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 27 deletions.
36 changes: 23 additions & 13 deletions Packages/MIES/MIES_SweepFormula_PSX.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -4316,17 +4316,22 @@ Function/WAVE PSX_OperationKernel(variable jsonId, string jsonPath, string graph
variable riseTau, decayTau, amp, dt, numPoints, numCombos, i, offset
string parameterPath, key

WAVE/WAVE range = SFH_EvaluateRange(jsonId, jsonPath, graph, SF_OP_PSX_KERNEL, 0)
WAVE/WAVE selectDataCompArray = SFH_GetArgumentSelect(jsonID, jsonPath, graph, SF_OP_PSX_KERNEL, 0)

WAVE/WAVE selectData = SFH_GetArgumentSelect(jsonID, jsonPath, graph, SF_OP_PSX_KERNEL, 1)
riseTau = SFH_GetArgumentAsNumeric(jsonID, jsonPath, graph, SF_OP_PSX_KERNEL, 1, defValue = 1, checkFunc = IsStrictlyPositiveAndFinite)
decayTau = SFH_GetArgumentAsNumeric(jsonID, jsonPath, graph, SF_OP_PSX_KERNEL, 2, defValue = 15, checkFunc = IsStrictlyPositiveAndFinite)
amp = SFH_GetArgumentAsNumeric(jsonID, jsonPath, graph, SF_OP_PSX_KERNEL, 3, defValue = -5, checkFunc = IsFinite)

SFH_ASSERT(WaveExists(selectData), "Could not gather sweep data from select statement")
SFH_ASSERT(DimSize(selectDataCompArray, ROWS) == 1, "Only supports a single selection at the moment")

WAVE/WAVE selectDataComp = selectDataCompArray[0]

WAVE/Z selectData = selectDataComp[%SELECTION]
WAVE/WAVE range = selectDataComp[%RANGE]

riseTau = SFH_GetArgumentAsNumeric(jsonID, jsonPath, graph, SF_OP_PSX_KERNEL, 2, defValue = 1, checkFunc = IsStrictlyPositiveAndFinite)
decayTau = SFH_GetArgumentAsNumeric(jsonID, jsonPath, graph, SF_OP_PSX_KERNEL, 3, defValue = 15, checkFunc = IsStrictlyPositiveAndFinite)
amp = SFH_GetArgumentAsNumeric(jsonID, jsonPath, graph, SF_OP_PSX_KERNEL, 4, defValue = -5, checkFunc = IsFinite)
SFH_ASSERT(WaveExists(selectData), "Could not gather sweep data from select statement")

WAVE/WAVE sweepDataRef = SFH_GetSweepsForFormula(graph, selectData, SF_OP_PSX_KERNEL)
WAVE/WAVE sweepDataRef = SFH_GetSweepsForFormula(graph, selectDataCompArray, SF_OP_PSX_KERNEL)

numCombos = DimSize(sweepDataRef, ROWS)
SFH_ASSERT(numCombos > 0, "Could not fetch sweeps")
Expand Down Expand Up @@ -4417,17 +4422,22 @@ Function/WAVE PSX_OperationStats(variable jsonId, string jsonPath, string graph)

id = SFH_GetArgumentAsText(jsonID, jsonPath, graph, SF_OP_PSX, 0, checkFunc = IsValidObjectName)

WAVE/WAVE range = SFH_EvaluateRange(jsonId, jsonPath, graph, SF_OP_PSX_STATS, 1)
WAVE/WAVE/Z selectDataCompArray = SFH_GetArgumentSelect(jsonID, jsonPath, graph, SF_OP_PSX_STATS, 1)
SFH_Assert(WaveExists(selectDataCompArray), "Missing select data")

SFH_ASSERT(DimSize(selectDataCompArray, ROWS) == 1, "Only supports a single selection at the moment")

WAVE/WAVE selectDataComp = selectDataCompArray[0]

WAVE/Z selectData = SFH_GetArgumentSelect(jsonID, jsonPath, graph, SF_OP_PSX_STATS, 2)
SFH_Assert(WaveExists(selectData), "Missing select data")
WAVE/Z selectData = selectDataComp[%SELECTION]
WAVE/WAVE range = selectDataComp[%RANGE]

Make/FREE/T allProps = {"amp", "xpos", "xinterval", "tau", "estate", "fstate", "fitresult", "risetime"}
prop = SFH_GetArgumentAsText(jsonID, jsonPath, graph, SF_OP_PSX_STATS, 3, allowedValues = allProps)
prop = SFH_GetArgumentAsText(jsonID, jsonPath, graph, SF_OP_PSX_STATS, 2, allowedValues = allProps)
Make/FREE/T allStates = {"accept", "reject", "undetermined", "all", "every"}
stateAsStr = SFH_GetArgumentAsText(jsonID, jsonPath, graph, SF_OP_PSX_STATS, 4, allowedValues = allStates)
stateAsStr = SFH_GetArgumentAsText(jsonID, jsonPath, graph, SF_OP_PSX_STATS, 3, allowedValues = allStates)
Make/FREE/T allPostProc = {"nothing", "stats", "count", "hist", "log10", "nonfinite"}
postProc = SFH_GetArgumentAsText(jsonID, jsonPath, graph, SF_OP_PSX_STATS, 5, defValue = "nothing", allowedValues = allPostProc)
postProc = SFH_GetArgumentAsText(jsonID, jsonPath, graph, SF_OP_PSX_STATS, 4, defValue = "nothing", allowedValues = allPostProc)

WAVE/WAVE output = PSX_OperationStatsImpl(graph, id, range, selectData, prop, stateAsStr, postProc)

Expand Down
31 changes: 17 additions & 14 deletions Packages/tests/Basic/UTF_SweepFormula_PSX.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -1052,7 +1052,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(select(selRange([50, 150]), selchannels(AD6), selsweeps([0, 2]), selvis(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 @@ -1088,7 +1088,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(select(selrange([50, 150]), selchannels(AD15), selsweeps(0)), 1, 15, -5)"
try
WAVE/WAVE dataWref = SF_ExecuteFormula(str, win, useVariables = 0)
FAIL()
Expand All @@ -1097,7 +1097,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(select(selRange(ABCD), selchannels(AD6), selsweeps([0, 2]), selvis(all)), 1, 15, -5)"
try
WAVE/WAVE dataWref = SF_ExecuteFormula(str, win, useVariables = 0)
FAIL()
Expand Down Expand Up @@ -1156,7 +1156,7 @@ static Function TestOperationPSX([STRUCT IUTF_mData &m])
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, " + num2str(kernelAmp) + "), 2.5, 100, 0)"
str = "psx(myID, psxKernel(select(selrange([50, 150]), selchannels(AD6), selsweeps([0, 2]), selvis(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 @@ -1187,13 +1187,13 @@ static Function TestOperationPSX([STRUCT IUTF_mData &m])
JSON_Release(jsonID)

// check that plain psx does not error out
str = "psx(id, psxKernel([50, 150], select(channels(AD6), [0, 2], all)))"
str = "psx(id, psxKernel(select(selrange([50, 150]), selchannels(AD6), selsweeps([0, 2]), selvis(all))))"
WAVE/WAVE dataWref = SF_ExecuteFormula(str, win, useVariables = 0)
CHECK_NO_RTE()
CHECK_WAVE(dataWref, WAVE_WAVE)

// complains without events found
str = "psx(myID, psxKernel([50, 150], select(channels(AD6), [0, 2], all), 5000, 15, -5), 25, 100, 0)"
str = "psx(myID, psxKernel(select(selrange([50, 150]), selchannels(AD6), selsweeps([0, 2]), selvis(all)), 5000, 15, -5), 25, 100, 0)"
try
WAVE/WAVE dataWref = SF_ExecuteFormula(str, win, useVariables = 0)
FAIL()
Expand All @@ -1218,7 +1218,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), 10, 100, 0)"
str = "psx(myID, psxKernel(select(selrange([50, 150]),selchannels(AD6), selsweeps([0]), selvis(all)), 1, 15, -5), 10, 100, 0)"
WAVE/WAVE dataWref = SF_ExecuteFormula(str, win, useVariables = 0)
CHECK_WAVE(dataWref, WAVE_WAVE)

Expand Down Expand Up @@ -1324,7 +1324,7 @@ static Function MouseSelectionPSX()

browser = MIES_DB#DB_LockToDevice(browser, device)

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

// combo0 is the current one

Expand Down Expand Up @@ -1677,9 +1677,12 @@ static Function/S GetTestCode(string postProc, [string eventState, string prop])
prop = "xpos"
endif

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


code = "psx(myId, psxKernel(select(selrange([50, 150]), selchannels(AD6), selsweeps([0, 2]), selvis(all))), 1.5, 100, 0)"
code += "\r and \r"
code += "psxStats(myId, [50, 150], select(channels(AD6), [0, 2], all), " + prop + ", " + eventState + ", " + postProc + ")"
code += "psxStats(myId, select(selrange([50, 150]), selchannels(AD6), selsweeps([0, 2]), selvis(all)), " + prop + ", " + eventState + ", " + postProc + ")"

return code
End
Expand All @@ -1694,11 +1697,11 @@ static Function/WAVE GetCodeVariations()
code = ""

// one sweep per operation separated with `with`
code = "psx(myId, psxKernel([50, 150], select(channels(AD6), [0], all)), 10, 100, 0)"
code = "psx(myId, psxKernel(select(selrange([50, 150]), selchannels(AD6), selsweeps([0]), selvis(all))), 10, 100, 0)"
code += "\r with \r"
code += "psx(myId, psxKernel([50, 150], select(channels(AD6), [2], all)), 2.5, 100, 0)"
code += "psx(myId, psxKernel(select(selrange([50, 150]), selchannels(AD6), selsweeps([2]), selvis(all))), 2.5, 100, 0)"
code += "\r and \r"
code += "psxStats(myId, [50, 150], select(channels(AD6), [0, 2], all), xpos, all, nothing)"
code += "psxStats(myId, select(selrange([50, 150]), selchannels(AD6), selsweeps([0, 2]), selvis(all)), xpos, all, nothing)"
wv[1] = code
code = ""

Expand Down Expand Up @@ -2967,7 +2970,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(select(selrange([50, 150]), selchannels(AD6), selsweeps([0, 2]), selvis(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 50f5169

Please sign in to comment.