Skip to content

Commit

Permalink
changes
Browse files Browse the repository at this point in the history
  • Loading branch information
t-b committed Jan 3, 2023
1 parent 2470605 commit de5a0a6
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Packages/MIES/MIES_Constants.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -1995,5 +1995,5 @@ StrConstant SF_OP_EPSP_STATS = "epspStats"
/// @{
Constant ES_EVENT_ACCEPT = 0x01
Constant ES_EVENT_REJECT = 0x02
Constant ES_EVENT_UNDET = 0x03
Constant ES_EVENT_UNDET = 0x04
/// @}
101 changes: 95 additions & 6 deletions Packages/MIES/MIES_SweepFormula_EPSP.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,8 @@ Function/WAVE ES_Operation(variable jsonId, string jsonPath, string graph)

resultsKey = ES_GenerateResultsKey(graph, selectData)
SetStringInWaveNote(epspEvent, ES_EVENTS_RESULTS_WAVE_NOTE, resultsKey)
SetStringInWaveNote(epspEvent, "Y_DATA_UNIT", WaveUnits(sweepData, -1))
SetStringInWaveNote(epspEvent, "X_DATA_UNIT", WaveUnits(sweepData, ROWS))

WAVE/WAVE output = SFH_CreateSFRefWave(graph, SF_OP_EPSP, 7)
SetDimensionLabels(output, "sweepData;sweepDataFiltOff;sweepDataFiltOffDeconv;peakX;peakY;epspAnalysis;epspEvent", ROWS)
Expand All @@ -523,8 +525,8 @@ Function/WAVE ES_Operation(variable jsonId, string jsonPath, string graph)
output[%sweepDataFiltOffDeconv] = sweepDataFiltOffDeconv
output[%peakX] = peakX
output[%peakY] = peakY
output[%epspAnalysis] = epspAnalysis
output[%epspEvent] = epspEvent
output[%epspAnalysis] = epspAnalysis
output[%epspEvent] = epspEvent

// TODO Implement the following steps properly
// - RunAll
Expand Down Expand Up @@ -656,21 +658,108 @@ static Function [WAVE kernel, WAVE kernelFFT] ES_CreatePSCKernel(variable tau1,
return [kernel, kernelFFT]
end

// epspStats(select(channels(AD),sweeps()), state, source, mode)
static Function [WAVE/D results, WAVE/D xValues] ES_GetStatsResults(WAVE events, variable state, string prop)

Make/D/FREE/N=(DimSize(events, ROWS)) xValues, results

Multithread results[] = (events[p][%state] & state) ? events[p][%$prop] : NaN
Multithread xValues[] = results[p] >= 0 ? p : NaN

WAVE/Z resultsClean = ZapNaNs(results)

if(!WaveExists(resultsClean))
return [$"", $""]
endif

WAVE xValuesClean = ZapNaNs(xValues)

return [resultsClean, xValuesClean]
End

// epspStats(select(channels(AD),sweeps()), prop, state, [postProc])
//
// # state: accepted/rejected/all
// # source: totalEventCount/amplitude/x-position
// # mode: nothing/avg
// # prop: amp/x-pos/x-interval
// # state: accepted/rejected/all
// # postProc: nothing/avg/count/hist
Function/WAVE ES_OperationStats(variable jsonId, string jsonPath, string graph)

string stateAsStr, prop, postProc, propLabel, yLabel
variable state, err

WAVE/Z selectData = SFH_GetArgumentSelect(jsonID, jsonPath, graph, SF_OP_EPSP_STATS, 0)
SFH_Assert(WaveExists(selectData), "Missing select operation")

prop = SFH_GetArgumentAsText(jsonID, jsonPath, graph, SF_OP_EPSP_STATS, 1, allowedValues = {"amp", "x-pos", "x-interval"})
stateAsStr = SFH_GetArgumentAsText(jsonID, jsonPath, graph, SF_OP_EPSP_STATS, 2, allowedValues = {"accepted", "rejected", "all"})
postProc = SFH_GetArgumentAsText(jsonID, jsonPath, graph, SF_OP_EPSP_STATS, 3, defValue = "nothing", allowedValues = {"nothing", "avg", "count", "hist"})

WAVE/Z events = ES_GetEventsFromResults(graph, selectData)
SFH_ASSERT(WaveExists(events), "Could not find any EPSP events in the results wave")

strswitch(prop)
case "amp":
propLabel = "i_amp"
yLabel = "Amplitude " + " (" + GetStringFromWaveNote(events, "Y_DATA_UNIT") + ")"
break
case "x-pos":
propLabel = "dc_peak_time"
yLabel = "Event time " + " (" + GetStringFromWaveNote(events, "X_DATA_UNIT") + ")"
break
case "x-interval":
propLabel = "isi"
yLabel = "Event interval " + " (" + GetStringFromWaveNote(events, "X_DATA_UNIT") + ")"
break
default:
ASSERT(0, "Impossible prop")
endswitch

strswitch(stateAsStr)
case "accepted":
state = ES_EVENT_ACCEPT
break
case "rejected":
state = ES_EVENT_REJECT
break
case "all":
state = ES_EVENT_ACCEPT | ES_EVENT_REJECT
break
default:
ASSERT(0, "Impossible state")
endswitch

[WAVE resultsRaw, WAVE xValues] = ES_GetStatsResults(events, state, propLabel)

WAVE/WAVE output = SFH_CreateSFRefWave(graph, SF_OP_EPSP_STATS, 1)

if(WaveExists(resultsRaw))
strswitch(postProc)
case "nothing":
WAVE/D results = resultsRaw

JWN_SetWaveInWaveNote(results, SF_META_XVALUES, xValues)

JWN_SetStringInWaveNote(output, SF_META_XAXISLABEL, "Event")
JWN_SetStringInWaveNote(output, SF_META_YAXISLABEL, yLabel)

break
case "avg":
MatrixOP/FREE results = mean(resultsRaw)
break
case "count":
MatrixOP/FREE results = numRows(resultsRaw)
break
case "hist":
Make/FREE/N=0/D results
Histogram/B=5/DEST=results resultsRaw; err = GetRTError(1)
if(err)
WaveClear results
endif
break
endswitch

output[0] = results
endif

return SFH_GetOutputForExecutor(output, graph, SF_OP_EPSP_STATS)
End

Expand Down
52 changes: 39 additions & 13 deletions Packages/MIES/MIES_SweepFormula_Helpers.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ static StrConstant SFH_WORKING_DF = "FormulaData"
/// Here `numBottles` is argument number 0 and mandatory as `defValue` is not present.
///
/// The second argument `size` is optional with 0.5 as default.
Function SFH_GetArgumentAsNumeric(variable jsonId, string jsonPath, string graph, string opShort, variable argNum, [variable defValue])
///
/// The parameter `allowedValues` allows to check the argument against a list of valid values.
Function SFH_GetArgumentAsNumeric(variable jsonId, string jsonPath, string graph, string opShort, variable argNum, [variable defValue, WAVE/Z allowedValues])

string msg
variable checkExist, numArgs
string msg, sep, allowedValuesAsStr
variable checkExist, numArgs, result

if(ParamIsDefault(defValue))
checkExist = 1
Expand All @@ -52,13 +54,24 @@ Function SFH_GetArgumentAsNumeric(variable jsonId, string jsonPath, string graph
sprintf msg, "Argument #%d of operation %s: Too many input values", argNum, opShort
SFH_ASSERT(DimSize(data, ROWS) == 1 && DimSize(data, COLS) == 0, msg)

return data[0]
result = data[0]
else
sprintf msg, "Argument #%d of operation %s is mandatory", argNum, opShort
SFH_ASSERT(!checkExist, msg)

result = defValue
endif

sprintf msg, "Argument #%d of operation %s is mandatory", argNum, opShort
SFH_ASSERT(!checkExist, msg)
if(!ParamIsDefault(allowedValues))
ASSERT(WaveExists(allowedValues) && IsNumericWave(allowedValues), "allowedValues must be a numeric wave")

sep = ", "
allowedValuesAsStr = RemoveEnding(NumericWaveToList(allowedValues, sep), sep)
sprintf msg, "Argument #%d of operation %s: The text argument \"%s\" is not one of the allowed values (%s)", argNum, opShort, result, allowedValuesAsStr
SFH_ASSERT(GetRowIndex(allowedValues, val = result) >= 0, msg)
endif

return defValue
return result
End

/// @brief Convenience helper function to get a textual SweepFormula operation argument
Expand All @@ -77,9 +90,11 @@ End
/// Here `date` is argument number 0 and mandatory as `defValue` is not present.
///
/// The second argument `type` is optional with `steam train` as default.
Function/S SFH_GetArgumentAsText(variable jsonId, string jsonPath, string graph, string opShort, variable argNum, [string defValue])
///
/// The parameter `allowedValues` allows to check the argument against a list of valid values.
Function/S SFH_GetArgumentAsText(variable jsonId, string jsonPath, string graph, string opShort, variable argNum, [string defValue, WAVE/T/Z allowedValues])

string msg
string msg, result, sep, allowedValuesAsStr
variable checkExist, numArgs

if(ParamIsDefault(defValue))
Expand All @@ -101,13 +116,24 @@ Function/S SFH_GetArgumentAsText(variable jsonId, string jsonPath, string graph,
sprintf msg, "Argument #%d of operation %s: Too many input values", argNum, opShort
SFH_ASSERT(DimSize(data, ROWS) == 1 && DimSize(data, COLS) == 0, msg)

return data[0]
result = data[0]
else
sprintf msg, "Argument #%d of operation %s is mandatory", argNum, opShort
SFH_ASSERT(!checkExist, msg)

result = defValue
endif

sprintf msg, "Argument #%d of operation %s is mandatory", argNum, opShort
SFH_ASSERT(!checkExist, msg)
if(!ParamIsDefault(allowedValues))
ASSERT(WaveExists(allowedValues) && IsTextWave(allowedValues), "allowedValues must be a text wave")

sep = ", "
allowedValuesAsStr = RemoveEnding(TextWaveToList(allowedValues, sep), sep)
sprintf msg, "Argument #%d of operation %s: The text argument \"%s\" is not one of the allowed values (%s)", argNum, opShort, result, allowedValuesAsStr
SFH_ASSERT(GetRowIndex(allowedValues, str = result) >= 0, msg)
endif

return defValue
return result
End

/// @brief Convenience helper function to get a wave SweepFormula operation argument
Expand Down

0 comments on commit de5a0a6

Please sign in to comment.