Skip to content

Commit 5e60339

Browse files
committed
SF: Add operation ivscc_apfrequency
- Add plot property support for axisOffsets and axisPercent An operation can set these through SF_META_XAXISOFFSET, SF_META_YAXISOFFSET, SF_META_XAXISPERCENT and SF_META_YAXISPERCENT in the JSON wave note of the result wave. The plotter uses the settings from the last result in a "with" block. e.g. op_that_sets_axisoffet() with 1 would ignore the plot properties set by the first operation, whereas 1 with op_that_sets_axisoffet() would apply it.
1 parent 6244d67 commit 5e60339

File tree

6 files changed

+222
-3
lines changed

6 files changed

+222
-3
lines changed

Packages/MIES/MIES_Constants.ipf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2141,6 +2141,11 @@ StrConstant SF_META_TRACETOFRONT = "/TraceToFront" // number, boolean,
21412141
StrConstant SF_META_DONOTPLOT = "/DoNotPlot" // number, boolean, defaults to false (0)
21422142
StrConstant SF_META_WINDOW_HOOK = "/WindowHook" // string
21432143
StrConstant SF_META_FORMULA = "/Formula" // string
2144+
StrConstant SF_META_PLOT = "/Plot" // number, boolean, defaults to false (0)
2145+
StrConstant SF_META_XAXISOFFSET = "/XAxisOffset" // number
2146+
StrConstant SF_META_YAXISOFFSET = "/YAxisOffset" // number
2147+
StrConstant SF_META_XAXISPERCENT = "/XAxisPercent" // number
2148+
StrConstant SF_META_YAXISPERCENT = "/YAxisPercent" // number
21442149

21452150
/// A color group allows to have matching colors for sweep data with the same channel type/number and sweep.
21462151
/// It is applied before the matching headstage/average colors in #SF_GetTraceColor().
@@ -2542,6 +2547,7 @@ StrConstant SF_OP_TPBASE = "tpbase"
25422547
StrConstant SF_OP_TPFIT = "tpfit"
25432548
StrConstant SF_OP_EXTRACT = "extract"
25442549
StrConstant SF_OP_FLATTEN = "flatten"
2550+
StrConstant SF_OP_IVSCCAPFREQUENCY = "ivscc_apfrequency"
25452551
///@}
25462552

25472553
StrConstant SF_PROPERTY_TABLE = "Table"

Packages/MIES/MIES_SweepFormula.ipf

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ Function/WAVE SF_GetNamedOperations()
9797
SF_OP_SELECTIVSCCSWEEPQC, SF_OP_SELECTIVSCCSETQC, SF_OP_SELECTRANGE, SF_OP_SELECTEXP, SF_OP_SELECTDEV, \
9898
SF_OP_SELECTEXPANDSCI, SF_OP_SELECTEXPANDRAC, SF_OP_SELECTSETCYCLECOUNT, SF_OP_SELECTSETSWEEPCOUNT, \
9999
SF_OP_SELECTSCIINDEX, SF_OP_SELECTRACINDEX, SF_OP_ANAFUNCPARAM, SF_OP_CONCAT, SF_OP_TABLE, SF_OP_EXTRACT, \
100-
SF_OP_FLATTEN}
100+
SF_OP_FLATTEN, SF_OP_IVSCCAPFREQUENCY}
101101

102102
return wt
103103
End
@@ -172,6 +172,10 @@ static Function/WAVE SF_FillPlotMetaData(WAVE wvYRef, variable useXLabel, string
172172
plotMetaData[%ARGSETUPSTACK] = JWN_GetStringFromWaveNote(wvYRef, SF_META_ARGSETUPSTACK)
173173
plotMetaData[%XAXISLABEL] = SelectString(useXLabel, SF_XLABEL_USER, JWN_GetStringFromWaveNote(wvYRef, SF_META_XAXISLABEL))
174174
plotMetaData[%YAXISLABEL] = JWN_GetStringFromWaveNote(wvYRef, SF_META_YAXISLABEL) + dataUnits
175+
plotMetaData[%XAXISOFFSET] = num2str(JWN_GetNumberFromWaveNote(wvYRef, SF_META_XAXISOFFSET), "%f")
176+
plotMetaData[%YAXISOFFSET] = num2str(JWN_GetNumberFromWaveNote(wvYRef, SF_META_YAXISOFFSET), "%f")
177+
plotMetaData[%XAXISPERCENT] = num2str(JWN_GetNumberFromWaveNote(wvYRef, SF_META_XAXISPERCENT), "%f")
178+
plotMetaData[%YAXISPERCENT] = num2str(JWN_GetNumberFromWaveNote(wvYRef, SF_META_YAXISPERCENT), "%f")
175179

176180
return plotMetaData
177181
End
@@ -1478,6 +1482,29 @@ static Function SF_FormulaPlotter(string graph, string formula, [variable dmMode
14781482
SF_KillOldDataDisplayWindows(graph, winDisplayMode, wList, outputWindows)
14791483
End
14801484

1485+
/// @brief Sets axis properties for plots of the SF formula plotter. The properties are stored in the plotMetaData wave.
1486+
static Function [STRUCT SF_PlotterGraphStruct pg] SF_SetAxisProperties()
1487+
1488+
variable xaxisOffset, yaxisOffset, xaxisPercent, yaxisPercent
1489+
1490+
xaxisOffset = str2num(pg.plotMetaData[%XAXISOFFSET])
1491+
if(!IsNaN(xaxisOffset))
1492+
ModifyGraph/W=$pg.win axOffset(bottom)=xaxisOffset
1493+
endif
1494+
yaxisOffset = str2num(pg.plotMetaData[%YAXISOFFSET])
1495+
if(!IsNaN(yaxisOffset))
1496+
ModifyGraph/W=$pg.win axOffset(left)=yaxisOffset
1497+
endif
1498+
xaxisPercent = str2num(pg.plotMetaData[%XAXISPERCENT])
1499+
if(!IsNaN(xaxisPercent))
1500+
ModifyGraph/W=$pg.win axisEnab(bottom)={0, xaxisPercent * PERCENT_TO_ONE}
1501+
endif
1502+
yaxisPercent = str2num(pg.plotMetaData[%YAXISPERCENT])
1503+
if(!IsNaN(yaxisPercent))
1504+
ModifyGraph/W=$pg.win axisEnab(left)={0, yaxisPercent * PERCENT_TO_ONE}
1505+
endif
1506+
End
1507+
14811508
static Function [STRUCT SF_PlotterGraphStruct pg] SF_FinishPlotWindow(WAVE/T winGraphs)
14821509

14831510
variable formulasAreDifferent, numTableFormulas
@@ -1490,6 +1517,9 @@ static Function [STRUCT SF_PlotterGraphStruct pg] SF_FinishPlotWindow(WAVE/T win
14901517
endif
14911518

14921519
if(pg.panelsCreated[%GRAPH])
1520+
1521+
[pg] = SF_SetAxisProperties()
1522+
14931523
pg.win = winGraphs[GetNumberFromWaveNote(winGraphs, NOTE_INDEX) - 1]
14941524
if(pg.showLegend)
14951525
[formulasAreDifferent, pg] = SF_AddPlotLegend()
@@ -2804,3 +2834,9 @@ Function SF_TableWindowHook(STRUCT WMWinHookStruct &s)
28042834

28052835
return 0
28062836
End
2837+
2838+
/// @brief Adds an expression to a formula string with the proper termination character
2839+
Function/S SF_AddExpressionToFormula(string formula, string expr)
2840+
2841+
return formula + expr + SF_CHAR_CR
2842+
End

Packages/MIES/MIES_SweepFormula_Executor.ipf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,9 @@ Function/WAVE SFE_FormulaExecutor(STRUCT SF_ExecutionData &exd, [variable srcLoc
520520
case SF_OP_FLATTEN:
521521
WAVE out = SFO_OperationFlatten(exdop)
522522
break
523+
case SF_OP_IVSCCAPFREQUENCY:
524+
WAVE out = SFO_OperationIVSCCApFrequency(exdop)
525+
break
523526
default:
524527
SFH_FATAL_ERROR("Undefined Operation", jsonId = exdop.jsonId)
525528
endswitch

Packages/MIES/MIES_SweepFormula_Helpers.ipf

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2173,3 +2173,40 @@ Function/WAVE SFH_GetDatasetArrayAsResolvedWaverefs(STRUCT SF_ExecutionData &exd
21732173

21742174
return dataFromEachGroup
21752175
End
2176+
2177+
/// @brief Executes a formula from within an operation with low overhead
2178+
/// - the currently active variable storage is used
2179+
/// - the formula string is not preprocessed
2180+
Function/WAVE SFH_ExecuteFormulaInternal(string graph, string formula)
2181+
2182+
STRUCT SF_ExecutionData exd
2183+
variable jsonId, srcLocId
2184+
2185+
exd.graph = graph
2186+
[jsonId, srcLocId] = SFP_ParseFormulaToJSON(formula)
2187+
exd.jsonId = jsonId
2188+
WAVE dataRef = SFE_FormulaExecutor(exd, srcLocId = srcLocId)
2189+
2190+
JSON_Release(exd.jsonId)
2191+
JSON_Release(srcLocId)
2192+
2193+
WAVE resolved = SF_ResolveDataset(dataRef)
2194+
2195+
return resolved
2196+
End
2197+
2198+
/// @brief Adds a variable to the variable storage. If the variable already exists it is overwritten.
2199+
Function SFH_AddVariableToStorage(string graph, string name, WAVE result)
2200+
2201+
variable size, idx
2202+
2203+
WAVE/WAVE varStorage = GetSFVarStorage(graph)
2204+
idx = FindDimLabel(varStorage, ROWS, name)
2205+
if(idx == -2)
2206+
size = DimSize(varStorage, ROWS)
2207+
Redimension/N=(size + 1) varStorage
2208+
idx = size
2209+
endif
2210+
varStorage[idx] = result
2211+
SetDimLabel ROWS, idx, $name, varStorage
2212+
End

Packages/MIES/MIES_SweepFormula_Operations.ipf

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ static StrConstant SF_OP_APFREQUENCY_NONORM = "nonorm"
3030
static StrConstant SF_OP_APFREQUENCY_X_COUNT = "count"
3131
static StrConstant SF_OP_APFREQUENCY_X_TIME = "time"
3232

33+
static StrConstant SF_OP_IVSCCAPFREQUENCY_MIN = "min"
34+
static StrConstant SF_OP_IVSCCAPFREQUENCY_MAX = "max"
35+
static StrConstant SF_OP_IVSCCAPFREQUENCY_NONE = "none"
36+
3337
static StrConstant SF_OP_AVG_INSWEEPS = "in"
3438
static StrConstant SF_OP_AVG_OVERSWEEPS = "over"
3539
static StrConstant SF_OP_AVG_GROUPS = "group"
@@ -2503,3 +2507,136 @@ Function/WAVE SFO_OperationTable(STRUCT SF_ExecutionData &exd)
25032507

25042508
return SFH_GetOutputForExecutor(output, exd.graph, SF_OP_TABLE)
25052509
End
2510+
2511+
/// @brief Sets the plot meta data for the ivscc_apfrequency operation
2512+
static Function SFO_OperationIVSCCApFrequencySetPlotProperties(WAVE wvY, variable xAxisPercentage, variable yAxisPercentage)
2513+
2514+
JWN_SetNumberInWaveNote(wvY, SF_META_XAXISPERCENT, xAxisPercentage)
2515+
JWN_SetNumberInWaveNote(wvY, SF_META_YAXISPERCENT, yAxisPercentage)
2516+
End
2517+
2518+
// ivscc_apfrequency([xaxisOffset, yaxisOffset, xAxisPercentage, yAxisPercentage])
2519+
Function/WAVE SFO_OperationIVSCCApFrequency(STRUCT SF_ExecutionData &exd)
2520+
2521+
string opShort = SF_OP_IVSCCAPFREQUENCY
2522+
variable numArgsMin = 0
2523+
variable numArgsMax = 4
2524+
string formula, expr, exprPart
2525+
variable i, numArgs, col, size, numExp
2526+
variable xAxisPercentage, yAxisPercentage
2527+
string xaxisOffset, yaxisOffset
2528+
2529+
SFH_ASSERT(BSP_IsSweepBrowser(exd.graph), "ivscc_apfrequency only works with sweepbrowser")
2530+
2531+
numArgs = SFH_GetNumberOfArguments(exd)
2532+
SFH_ASSERT(numArgs <= numArgsMax, "ivscc_apfrequency has " + num2istr(numArgsMax) + " arguments at most.")
2533+
SFH_ASSERT(numArgs >= numArgsMin, "ivscc_apfrequency needs at least " + num2istr(numArgsMin) + " argument(s).")
2534+
2535+
xaxisOffset = SFH_GetArgumentAsText(exd, opShort, 0, defValue = SF_OP_IVSCCAPFREQUENCY_MIN, allowedValues = {SF_OP_IVSCCAPFREQUENCY_MIN, SF_OP_IVSCCAPFREQUENCY_MAX, SF_OP_IVSCCAPFREQUENCY_NONE})
2536+
yaxisOffset = SFH_GetArgumentAsText(exd, opShort, 1, defValue = SF_OP_IVSCCAPFREQUENCY_MIN, allowedValues = {SF_OP_IVSCCAPFREQUENCY_MIN, SF_OP_IVSCCAPFREQUENCY_MAX, SF_OP_IVSCCAPFREQUENCY_NONE})
2537+
xAxisPercentage = SFH_GetArgumentAsNumeric(exd, opShort, 2, defValue = 100, checkFunc = BetweenZeroAndOneHoundred)
2538+
yAxisPercentage = SFH_GetArgumentAsNumeric(exd, opShort, 3, defValue = 100, checkFunc = BetweenZeroAndOneHoundred)
2539+
2540+
WAVE/T sweepMap = SB_GetSweepMap(exd.graph)
2541+
col = FindDimlabel(sweepMap, COLS, "FileName")
2542+
size = GetNumberFromWaveNote(sweepMap, NOTE_INDEX)
2543+
Duplicate/FREE/RMD=[0, size - 1][col] sweepMap, fileNames
2544+
WAVE/T uniqueFiles = GetUniqueEntries(fileNames, dontDuplicate = 1)
2545+
numExp = DimSize(uniqueFiles, ROWS)
2546+
SFH_ASSERT(numExp > 0, "ivscc_apfrequency: data from at least one experiment has to be loaded")
2547+
2548+
Make/FREE/T/N=(numExp) elems
2549+
2550+
formula = "sel = select(selsweeps(), selstimset(\"*rheo*\", \"*supra*\"), selvis(all))\r"
2551+
for(i = 0; i < numExp; i += 1)
2552+
sprintf expr, "selexpAD%d = select(selexp(\"%s\"), $sel, selchannels(AD0), selrange(E1))", i, uniqueFiles[i]
2553+
formula = SF_AddExpressionToFormula(formula, expr)
2554+
sprintf expr, "selexpDA%d = select(selexp(\"%s\"), $sel, selchannels(DA0), selrange(E1))", i, uniqueFiles[i]
2555+
formula = SF_AddExpressionToFormula(formula, expr)
2556+
sprintf expr, "freq%d = apfrequency(data($selexpAD%d))", i, i
2557+
formula = SF_AddExpressionToFormula(formula, expr)
2558+
sprintf expr, "current%d = max(data($selexpDA%d))", i, i
2559+
formula = SF_AddExpressionToFormula(formula, expr)
2560+
if(!CmpStr(xaxisOffset, SF_OP_IVSCCAPFREQUENCY_MIN))
2561+
sprintf expr, "currentNorm%d = $current%d - extract($current%d, 0)", i, i, i
2562+
elseif(!CmpStr(xaxisOffset, SF_OP_IVSCCAPFREQUENCY_MAX))
2563+
sprintf expr, "currentNorm%d = $current%d - max(flatten($current%d))", i, i, i
2564+
elseif(!CmpStr(xaxisOffset, SF_OP_IVSCCAPFREQUENCY_NONE))
2565+
sprintf expr, "currentNorm%d = $current%d", i, i
2566+
else
2567+
FATAL_ERROR("Unknown xaxisOffset specification")
2568+
endif
2569+
formula = SF_AddExpressionToFormula(formula, expr)
2570+
endfor
2571+
2572+
elems[] = "$freq" + num2istr(p)
2573+
expr = "ivsccavg = avg([" + TextWaveToList(elems, ",", trailSep = 0) + "], group)"
2574+
formula = SF_AddExpressionToFormula(formula, expr)
2575+
2576+
elems[] = "$currentNorm" + num2istr(p)
2577+
expr = "ivscccurrentavg = avg([" + TextWaveToList(elems, ",", trailSep = 0) + "], group)"
2578+
formula = SF_AddExpressionToFormula(formula, expr)
2579+
2580+
elems[] = "\"" + uniqueFiles[p] + "\""
2581+
expr = "ivscc_apfrequency_explist = [" + TextWaveToList(elems, ",", trailSep = 0) + "]"
2582+
formula = SF_AddExpressionToFormula(formula, expr)
2583+
2584+
WAVE/WAVE varStorage = GetSFVarStorage(exd.graph)
2585+
Duplicate/FREE varStorage, varBackup
2586+
SFE_ExecuteVariableAssignments(exd.graph, formula)
2587+
2588+
WAVE/WAVE varStorageOp = GetSFVarStorage(exd.graph)
2589+
WAVE wvResult = varStorageOp[%ivscc_apfrequency_explist]
2590+
2591+
WAVE/WAVE plotAND = SFH_CreateSFRefWave(exd.graph, opShort, 1)
2592+
Make/FREE/WAVE/N=(numExp + 1, 2) plotWITH
2593+
SetDimlabel COLS, 0, FORMULAX, plotWITH
2594+
SetDimlabel COLS, 1, FORMULAY, plotWITH
2595+
plotAND[0] = plotWITH
2596+
2597+
for(i = 0; i < numExp; i += 1)
2598+
if(!CmpStr(yaxisOffset, SF_OP_IVSCCAPFREQUENCY_MIN))
2599+
sprintf formula, "$freq%d - extract($freq%d, 0)", i, i
2600+
elseif(!CmpStr(yaxisOffset, SF_OP_IVSCCAPFREQUENCY_MAX))
2601+
sprintf formula, "$freq%d - max(flatten($freq%d))", i, i
2602+
elseif(!CmpStr(yaxisOffset, SF_OP_IVSCCAPFREQUENCY_NONE))
2603+
sprintf formula, "$freq%d", i
2604+
else
2605+
FATAL_ERROR("Unknown xaxisOffset specification")
2606+
endif
2607+
plotWITH[i][%FORMULAY] = SFH_ExecuteFormulaInternal(exd.graph, formula)
2608+
SFO_OperationIVSCCApFrequencySetPlotProperties(plotWITH[i][%FORMULAY], xAxisPercentage, yAxisPercentage)
2609+
sprintf formula, "$currentNorm%d", i
2610+
plotWITH[i][%FORMULAX] = SFH_ExecuteFormulaInternal(exd.graph, formula)
2611+
endfor
2612+
2613+
if(!CmpStr(yaxisOffset, SF_OP_IVSCCAPFREQUENCY_MIN))
2614+
formula = "$ivsccavg - extract($ivsccavg, 0)"
2615+
elseif(!CmpStr(yaxisOffset, SF_OP_IVSCCAPFREQUENCY_MAX))
2616+
formula = "$ivsccavg - max(flatten($ivsccavg))"
2617+
elseif(!CmpStr(yaxisOffset, SF_OP_IVSCCAPFREQUENCY_NONE))
2618+
formula = "$ivsccavg"
2619+
else
2620+
FATAL_ERROR("Unknown yaxisOffset specification")
2621+
endif
2622+
plotWITH[i][%FORMULAY] = SFH_ExecuteFormulaInternal(exd.graph, formula)
2623+
SFO_OperationIVSCCApFrequencySetPlotProperties(plotWITH[i][%FORMULAY], xAxisPercentage, yAxisPercentage)
2624+
2625+
if(!CmpStr(xaxisOffset, SF_OP_IVSCCAPFREQUENCY_MIN))
2626+
formula = "$ivscccurrentavg - extract($ivscccurrentavg, 0)"
2627+
elseif(!CmpStr(xaxisOffset, SF_OP_IVSCCAPFREQUENCY_MAX))
2628+
formula = "$ivscccurrentavg - max(flatten($ivscccurrentavg))"
2629+
elseif(!CmpStr(xaxisOffset, SF_OP_IVSCCAPFREQUENCY_NONE))
2630+
formula = "$ivscccurrentavg"
2631+
else
2632+
FATAL_ERROR("Unknown xaxisOffset specification")
2633+
endif
2634+
plotWITH[i][%FORMULAX] = SFH_ExecuteFormulaInternal(exd.graph, formula)
2635+
2636+
Duplicate/O varBackup, varStorage
2637+
SFH_AddVariableToStorage(exd.graph, "ivscc_apfrequency_explist", wvResult)
2638+
2639+
JWN_SetNumberInWaveNote(plotAND, SF_META_PLOT, 1)
2640+
2641+
return SFH_GetOutputForExecutor(plotAND, exd.graph, opShort)
2642+
End

Packages/MIES/MIES_WaveDataFolderGetters.ipf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9284,8 +9284,8 @@ End
92849284
/// @brief Wave storing sf plot meta information per formularesult, filled in SF_GatherFormulaResults
92859285
Function/WAVE GetSFPlotMetaData()
92869286

9287-
Make/FREE/T/N=(5) wv
9288-
SetDimensionLabels(wv, "DATATYPE;OPSTACK;ARGSETUPSTACK;XAXISLABEL;YAXISLABEL;", ROWS)
9287+
Make/FREE/T/N=(9) wv
9288+
SetDimensionLabels(wv, "DATATYPE;OPSTACK;ARGSETUPSTACK;XAXISLABEL;YAXISLABEL;XAXISOFFSET;YAXISOFFSET;XAXISPERCENT;YAXISPERCENT;", ROWS)
92899289

92909290
return wv
92919291
End

0 commit comments

Comments
 (0)