Skip to content

Commit

Permalink
WIP: AnaFuncParam
Browse files Browse the repository at this point in the history
  • Loading branch information
t-b committed Sep 10, 2024
1 parent af62c0a commit 6c0b1d1
Show file tree
Hide file tree
Showing 2 changed files with 157 additions and 1 deletion.
1 change: 1 addition & 0 deletions Packages/MIES/MIES_Constants.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -2093,6 +2093,7 @@ StrConstant SF_DATATYPE_TPBASE = "TestPulseMode_Baseline"
StrConstant SF_DATATYPE_TPFIT = "TestPulseMode_Fit"
StrConstant SF_DATATYPE_POWERSPECTRUM = "Powerspectrum"
StrConstant SF_DATATYPE_PSX = "PSX"
StrConstant SF_DATATYPE_ANAFUNCPARAM = "AnaFunc"

StrConstant SF_WREF_MARKER = "\"WREF@\":"
StrConstant SF_VARIABLE_MARKER = "/SF_IsVariable" // numeric
Expand Down
157 changes: 156 additions & 1 deletion Packages/MIES/MIES_SweepFormula.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ static StrConstant SF_OP_BUTTERWORTH = "butterworth"
static StrConstant SF_OP_CHANNELS = "channels"
static StrConstant SF_OP_DATA = "data"
static StrConstant SF_OP_LABNOTEBOOK = "labnotebook"
static StrConstant SF_OP_ANAFUNCPARAM = "anaFuncParam"
static StrConstant SF_OP_WAVE = "wave"
static StrConstant SF_OP_FINDLEVEL = "findlevel"
static StrConstant SF_OP_EPOCHS = "epochs"
Expand Down Expand Up @@ -208,7 +209,7 @@ Function/WAVE SF_GetNamedOperations()
SF_OP_CHANNELS, SF_OP_DATA, SF_OP_LABNOTEBOOK, SF_OP_WAVE, SF_OP_FINDLEVEL, SF_OP_EPOCHS, SF_OP_TP, \
SF_OP_STORE, SF_OP_SELECT, SF_OP_POWERSPECTRUM, SF_OP_TPSS, SF_OP_TPBASE, SF_OP_TPINST, SF_OP_TPFIT, \
SF_OP_PSX, SF_OP_PSX_KERNEL, SF_OP_PSX_STATS, SF_OP_PSX_RISETIME, SF_OP_PSX_PREP, SF_OP_PSX_DECONV_FILTER, \
SF_OP_MERGE, SF_OP_FIT, SF_OP_FITLINE, SF_OP_DATASET}
SF_OP_MERGE, SF_OP_FIT, SF_OP_FITLINE, SF_OP_DATASET, SF_OP_ANAFUNCPARAM}

return wt
End
Expand Down Expand Up @@ -1057,6 +1058,9 @@ static Function/WAVE SF_FormulaExecutor(string graph, variable jsonID, [string j
case SF_OP_LABNOTEBOOK:
WAVE out = SF_OperationLabnotebook(jsonId, jsonPath, graph)
break
case SF_OP_ANAFUNCPARAM:
WAVE out = SF_OperationAnaFuncParam(jsonId, jsonPath, graph)
break
case SF_OP_LOG: // JSON logic debug operation
WAVE out = SF_OperationLog(jsonId, jsonPath, graph)
break
Expand Down Expand Up @@ -1230,6 +1234,8 @@ static Function/S SF_GetAnnotationPrefix(string dataType)
return "TP "
case SF_DATATYPE_LABNOTEBOOK:
return "LB "
case SF_DATATYPE_ANAFUNCPARAM:
return "AFP "
default:
ASSERT(0, "Invalid dataType")
endswitch
Expand All @@ -1247,6 +1253,7 @@ static Function/S SF_GetTraceAnnotationText(STRUCT SF_PlotMetaData &plotMetaData
case SF_DATATYPE_EPOCHS: // fallthrough
case SF_DATATYPE_SWEEP: // fallthrough
case SF_DATATYPE_LABNOTEBOOK: // fallthrough
case SF_DATATYPE_ANAFUNCPARAM: // fallthrough
case SF_DATATYPE_TP:
sweepNo = JWN_GetNumberFromWaveNote(data, SF_META_SWEEPNO)
legendPrefix = JWN_GetStringFromWaveNote(data, SF_META_LEGEND_LINE_PREFIX)
Expand Down Expand Up @@ -4628,6 +4635,154 @@ static Function/WAVE SF_OperationData(variable jsonId, string jsonPath, string g
return SFH_GetOutputForExecutor(output, graph, SF_OP_DATA)
End

static Function/WAVE SF_OperationAnaFuncParam(variable jsonId, string jsonPath, string graph)

SFH_CheckArgumentCount(jsonID, jsonPath, SF_OP_ANAFUNCPARAM, 0, maxArgs = 2)

WAVE/T names = SFH_GetArgumentAsWave(jsonId, jsonPath, graph, SF_OP_ANAFUNCPARAM, 0, singleResult = 1)
WAVE/Z selectData = SFH_GetArgumentSelect(jsonID, jsonPath, graph, SF_OP_DATA, 1)

WAVE/WAVE output = SF_OperationAnaFuncParamImpl(graph, names, selectData, SF_OP_ANAFUNCPARAM)

JWN_SetStringInWaveNote(output, SF_META_OPSTACK, AddListItem(SF_OP_ANAFUNCPARAM, ""))

SF_SetSweepXAxisTickLabels(output, selectData)

return SFH_GetOutputForExecutor(output, graph, SF_OP_ANAFUNCPARAM)
End

static Function/WAVE SF_OperationAnaFuncParamImplAllNames(WAVE/T names, WAVE/WAVE allParams)

variable i, numParams, gatherAllNames, j, numNames
string params, name, gatheredNames, namesPerParam

numParams = DimSize(allParams, ROWS)
numNames = DimSize(names, ROWS)

Make/FREE/N=0/T allNames

for(i = 0; i < numParams; i += 1)

WAVE/T paramsSingle = allParams[i]
params = JWN_GetStringFromWaveNote(paramsSingle, SF_META_TAG_TEXT)

gatheredNames = AFH_GetListOfAnalysisParamNames(params)

for(j = 0; j < numNames; j += 1)
name = names[j]

namesPerParam = ListMatch(gatheredNames, name)

if(IsEmpty(namesPerParam))
continue
endif

WAVE wv = ListToTextWave(namesPerParam, ";")

Concatenate/NP=(ROWS)/T {wv}, allNames
endfor
endfor

if(DimSize(allNames, ROWS) == 0)
return $""
endif

WAVE allNamesUnique = GetUniqueEntries(allNames)

return allNamesUnique
End

static Function/WAVE SF_OperationAnaFuncParamImpl(string graph, WAVE/T names, WAVE/Z selectData, string opType)

variable numNames, numParams, i, j, idx, sweepNo, chanType, chanNr, colorGroup, colorGroupFound, nextFreeIndex, marker
string params, name, type

if(!WaveExists(selectData))
WAVE/WAVE output = SFH_CreateSFRefWave(graph, SF_OP_ANAFUNCPARAM, 0)
JWN_SetStringInWaveNote(output, SF_META_DATATYPE, SF_DATATYPE_ANAFUNCPARAM)
return SFH_GetOutputForExecutor(output, graph, SF_OP_ANAFUNCPARAM)
endif

WAVE/WAVE allParams = SF_OperationLabnotebookImpl(graph, {"Function params (encoded)"}, selectData, DATA_ACQUISITION_MODE, SF_OP_ANAFUNCPARAM)

numParams = DimSize(allParams, ROWS)

if(numParams == 0)
WAVE/WAVE output = SFH_CreateSFRefWave(graph, opType, 0)
return SFH_GetOutputForExecutor(output, graph, opType)
endif

WAVE/T/Z allNamesUnique = SF_OperationAnaFuncParamImplAllNames(names, allParams)

if(!WaveExists(allNamesUnique))
WAVE/WAVE output = SFH_CreateSFRefWave(graph, opType, 0)
return SFH_GetOutputForExecutor(output, graph, opType)
endif

numNames = DimSize(allNamesUnique, ROWS)

Make/FREE/N=(MINIMUM_WAVE_SIZE)/D colorGroups
SetNumberInWaveNote(colorGroups, NOTE_INDEX, 0)

WAVE/WAVE output = SFH_CreateSFRefWave(graph, opType, MINIMUM_WAVE_SIZE)

for(i = 0; i < numNames; i += 1)
name = allNamesUnique[i]
colorGroup = GetUniqueInteger()

marker = SFH_GetPlotMarkerCodeSelection(i)

for(j = 0; j < numParams; j += 1)
WAVE/T paramsSingle = allParams[j]
params = JWN_GetStringFromWaveNote(paramsSingle, SF_META_TAG_TEXT)
type = AFH_GetAnalysisParamType(name, params, typeCheck = 0)

strswitch(type)
case "variable":
Make/FREE/D out = {AFH_GetAnalysisParamNumerical(name, params)}
break
case "string":
case "wave":
case "textwave":
Make/FREE/D out = {0.0}
JWN_SetWaveInWaveNote(out, SF_META_TRACECOLOR, {0, 0, 0, 0})
JWN_SetStringInWaveNote(out, SF_META_TAG_TEXT, AFH_GetAnalysisParameterAsText(name, params))
break
case "":
Make/FREE/D out = {NaN}
break
default:
ASSERT(0, "Unsupported parameter type: " + type)
endswitch

sweepNo = JWN_GetNumberFromWaveNote(paramsSingle, SF_META_SWEEPNO)
chanType = JWN_GetNumberFromWaveNote(paramsSingle, SF_META_CHANNELTYPE)
chanNr = JWN_GetNumberFromWaveNote(paramsSingle, SF_META_CHANNELNUMBER)

JWN_SetNumberInWaveNote(out, SF_META_SWEEPNO, sweepNo)
JWN_SetNumberInWaveNote(out, SF_META_CHANNELTYPE, chanType)
JWN_SetNumberInWaveNote(out, SF_META_CHANNELNUMBER, chanNr)
JWN_SetWaveInWaveNote(out, SF_META_XVALUES, {sweepNo})

JWN_SetStringInWaveNote(out, SF_META_LEGEND_LINE_PREFIX, name)
JWN_SetNumberInWaveNote(out, SF_META_COLOR_GROUP, colorGroup)
JWN_SetNumberInWaveNote(out, SF_META_MOD_MARKER, marker)

EnsureLargeEnoughWave(output, dimension = ROWS, indexShouldExist = idx)
output[idx] = out
idx += 1
endfor
endfor

Redimension/N=(idx) output

JWN_SetStringInWaveNote(output, SF_META_YAXISLABEL, "Analysis function parameters")
JWN_SetStringInWaveNote(output, SF_META_XAXISLABEL, "Sweeps")
JWN_SetStringInWaveNote(output, SF_META_DATATYPE, SF_DATATYPE_ANAFUNCPARAM)

return output
End

/// `labnotebook(array keys[, array selectData [, string entrySourceType]])`
///
/// return lab notebook @p key for all @p sweeps that belong to the channels @p channels
Expand Down

0 comments on commit 6c0b1d1

Please sign in to comment.