Skip to content

Commit

Permalink
SF: Add TTL channel support to select operation and unassoc DA support
Browse files Browse the repository at this point in the history
- clampMode filter is applied for DA/AD but ignored for TTL channels
  • Loading branch information
MichaelHuth committed Jul 21, 2023
1 parent 6ae4864 commit 1964894
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 79 deletions.
104 changes: 30 additions & 74 deletions Packages/MIES/MIES_SweepFormula.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -1979,12 +1979,12 @@ End
static Function/WAVE SF_GetActiveChannelNumbersForSweeps(string graph, WAVE/Z channels, WAVE/Z sweeps, variable fromDisplayed, variable clampMode)

variable i, j, k, l, channelType, channelNumber, sweepNo, sweepNoT, outIndex
variable numSweeps, numInChannels, numSettings, maxChannels, activeChannel, numActiveChannels
variable numSweeps, numInChannels, numActiveChannels, index
variable isSweepBrowser
variable dimPosSweep, dimPosChannelNumber, dimPosChannelType
variable dimPosTSweep, dimPosTChannelNumber, dimPosTChannelType
variable numTraces
string setting, settingList, msg, device, singleSweepDFStr
string msg, device, singleSweepDFStr

if(!WaveExists(sweeps) || !DimSize(sweeps, ROWS))
return $""
Expand Down Expand Up @@ -2023,7 +2023,7 @@ static Function/WAVE SF_GetActiveChannelNumbersForSweeps(string graph, WAVE/Z ch
dimPosChannelNumber = FindDimLabel(selectDisplayed, COLS, "CHANNELNUMBER")

dimPosTChannelType = FindDimLabel(traces, COLS, "channelType")
dimPosTChannelNumber = FindDimLabel(traces, COLS, "channelNumber")
dimPosTChannelNumber = FindDimLabel(traces, COLS, "GUIChannelNumber")
for(i = 0; i < numSweeps; i += 1)
sweepNo = sweeps[i]
for(j = 0; j < numTraces; j += 1)
Expand Down Expand Up @@ -2096,6 +2096,10 @@ static Function/WAVE SF_GetActiveChannelNumbersForSweeps(string graph, WAVE/Z ch
if(!WaveExists(numericalValues))
continue
endif
WAVE/Z/T textualValues = BSP_GetLogbookWave(graph, LBT_LABNOTEBOOK, LBN_TEXTUAL_VALUES, sweepNumber = sweepNo)
if(!WaveExists(textualValues))
continue
endif
endif

for(j = 0; j < numInChannels; j += 1)
Expand All @@ -2104,94 +2108,46 @@ static Function/WAVE SF_GetActiveChannelNumbersForSweeps(string graph, WAVE/Z ch
channelNumber = channels[j][%channelNumber]

if(IsNaN(channelType))
settingList = "ADC;DAC;"
Make/FREE/D channelTypes = {XOP_CHANNEL_TYPE_DAC, XOP_CHANNEL_TYPE_ADC, XOP_CHANNEL_TYPE_TTL}
else
switch(channelType)
case XOP_CHANNEL_TYPE_DAC:
settingList = "DAC;"
break
case XOP_CHANNEL_TYPE_ADC:
settingList = "ADC;"
break
default:
sprintf msg, "Unhandled channel type %g in channels() at position %d", channelType, j
SFH_ASSERT(0, msg)
endswitch
sprintf msg, "Unhandled channel type %g in channels() at position %d", channelType, j
SFH_ASSERT(channelType == XOP_CHANNEL_TYPE_DAC || channelType == XOP_CHANNEL_TYPE_ADC || channelType == XOP_CHANNEL_TYPE_TTL, msg)
Make/FREE/D channelTypes = {channelType}
endif

numSettings = ItemsInList(settingList)
for(k = 0; k < numSettings; k += 1)
setting = StringFromList(k, settingList)
strswitch(setting)
case "DAC":
channelType = XOP_CHANNEL_TYPE_DAC
maxChannels = NUM_DA_TTL_CHANNELS
break
case "ADC":
channelType = XOP_CHANNEL_TYPE_ADC
maxChannels = NUM_AD_CHANNELS
break
default:
SFH_ASSERT(0, "Unexpected setting entry for channel type resolution.")
break
endswitch
for(channelType : channelTypes)

if(fromDisplayed)
for(l = 0; l < numTraces; l += 1)
if(IsNaN(channelNumber))
if(sweepNo == selectDisplayed[l][dimPosSweep] && channelType == selectDisplayed[l][dimPosChannelType])
activeChannel = selectDisplayed[l][dimPosChannelNumber]
if(activeChannel < maxChannels)
selectData[outIndex][dimPosSweep] = sweepNo
selectData[outIndex][dimPosChannelType] = channelType
selectData[outIndex][dimPosChannelNumber] = selectDisplayed[l][dimPosChannelNumber]
outIndex += 1
endif
endif
else
if(sweepNo == selectDisplayed[l][dimPosSweep] && channelType == selectDisplayed[l][dimPosChannelType] && channelNumber == selectDisplayed[l][dimPosChannelNumber] && channelNumber < maxChannels)
selectData[outIndex][dimPosSweep] = sweepNo
selectData[outIndex][dimPosChannelType] = channelType
selectData[outIndex][dimPosChannelNumber] = channelNumber
outIndex += 1
endif
if(sweepNo == selectDisplayed[l][dimPosSweep] && channelType == selectDisplayed[l][dimPosChannelType] && (IsNaN(channelNumber) || channelNumber == selectDisplayed[l][dimPosChannelNumber]))
selectData[outIndex][dimPosSweep] = sweepNo
selectData[outIndex][dimPosChannelType] = channelType
selectData[outIndex][dimPosChannelNumber] = selectDisplayed[l][dimPosChannelNumber]
outIndex += 1
endif
endfor
else
WAVE/Z activeChannels = GetLastSetting(numericalValues, sweepNo, setting, DATA_ACQUISITION_MODE)
WAVE/Z activeChannels = GetActiveChannels(numericalValues, textualValues, sweepNo, channelType)
if(!WaveExists(activeChannels))
continue
endif
if(clampMode != SF_OP_SELECT_CLAMPCODE_ALL)
WAVE/Z clampModes = GetLastSetting(numericalValues, sweepNo, CLAMPMODE_ENTRY_KEY, DATA_ACQUISITION_MODE)
if(!WaveExists(clampModes))
// faster than ZapNaNs due to no mem alloc
numActiveChannels = DimSize(activeChannels, ROWS)
for(l = 0; l < numActiveChannels; l += 1)
if(IsNan(activeChannels[l]) || (!IsNaN(channelNumber) && channelNumber != l))
continue
endif
endif
if(IsNaN(channelNumber))
// faster than ZapNaNs due to no mem alloc
numActiveChannels = DimSize(activeChannels, ROWS)
for(l = 0; l < numActiveChannels; l += 1)
if(clampMode != SF_OP_SELECT_CLAMPCODE_ALL && clampMode != clampModes[l])
if(clampMode != SF_OP_SELECT_CLAMPCODE_ALL && (channelType == XOP_CHANNEL_TYPE_DAC || channelType == XOP_CHANNEL_TYPE_ADC))
[WAVE setting, index] = GetLastSettingChannel(numericalValues, $"", sweepNo, CLAMPMODE_ENTRY_KEY, l, channelType, DATA_ACQUISITION_MODE)
if(!WaveExists(setting) || (WaveExists(setting) && clampMode != setting[index]))
continue
endif
activeChannel = activeChannels[l]
if(!IsNaN(activeChannel) && activeChannel < maxChannels)
selectData[outIndex][dimPosSweep] = sweepNo
selectData[outIndex][dimPosChannelType] = channelType
selectData[outIndex][dimPosChannelNumber] = activeChannel
outIndex += 1
endif
endfor
elseif(channelNumber < maxChannels)
FindValue/V=(channelNumber) activeChannels
if(V_Value >= 0 && (clampMode == SF_OP_SELECT_CLAMPCODE_ALL || clampMode == clampModes[V_Value]))
selectData[outIndex][dimPosSweep] = sweepNo
selectData[outIndex][dimPosChannelType] = channelType
selectData[outIndex][dimPosChannelNumber] = channelNumber
outIndex += 1
endif
endif
selectData[outIndex][dimPosSweep] = sweepNo
selectData[outIndex][dimPosChannelType] = channelType
selectData[outIndex][dimPosChannelNumber] = l
outIndex += 1
endfor
endif

endfor
Expand Down
6 changes: 3 additions & 3 deletions Packages/doc/SweepFormula.rst
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,7 @@ It is intended to be used with operations like `data`, `labnotebook`, `epochs` a
The function accepts none, two, three or four arguments.
channels
array with channel specification from `channels` operation. When channels is not specified, it defaults to `channels()`.
array with channel specification from `channels` operation. When channels is not specified, it defaults to `channels()`. The input channel numbers are treated as GUI channel numbers.
sweeps
array with sweep number, typically from `sweeps` operation. When sweeps is not specified, it defaults to `sweeps()`.
Expand All @@ -909,13 +909,13 @@ mode
string specifying which sweeps are selected. Possible strings are `displayed` and `all` that refer to the currently displayed sweeps or all acquired sweeps. When mode is not specified it defaults to `displayed`.
clampMode
string specifying which clamp mode is selected. Possible strings are `all`, `vc`, `ic` and `izero`. When clampMode is not specified it defaults to `all`.
string specifying which clamp mode is selected. Possible strings are `all`, `vc`, `ic` and `izero`. When clampMode is not specified it defaults to `all`. The clampMode selection is only applied for AD/DA channels.
To retrieve a correct array of channels the `channels` function must be used.
If a given channel/sweep combination does not exist it is omitted in the output.
The output is a N x 3 array where the columns are sweep number, channel type, channel number.
The output is a N x 3 array where the columns are sweep number, channel type, GUI channel number.
The output is sorted. The order is sweep -> channel type -> channel number.
e.g. for two sweeps numbered 0, 1 that have channels AD0, AD1, DA6, DA7:
Expand Down
4 changes: 2 additions & 2 deletions Packages/tests/Basic/UTF_SweepFormula.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -2108,8 +2108,8 @@ static Function TestOperationSelect()
Extract input, $name, q == i && r == j
WAVE wv = $name
AppendToGraph/W=$win wv/TN=$trace
TUD_SetUserDataFromWaves(win, trace, {"experiment", "fullPath", "traceType", "occurence", "channelType", "channelNumber", "sweepNumber", "clampMode"}, \
{"blah", GetWavesDataFolder(wv, 2), "Sweep", "0", StringFromList(j, channelTypeList), StringFromList(j, channelNumberList), num2istr(sweepNo), num2istr(clampMode)})
TUD_SetUserDataFromWaves(win, trace, {"experiment", "fullPath", "traceType", "occurence", "channelType", "channelNumber", "sweepNumber", "clampMode", "GUIChannelNumber"}, \
{"blah", GetWavesDataFolder(wv, 2), "Sweep", "0", StringFromList(j, channelTypeList), StringFromList(j, channelNumberList), num2istr(sweepNo), num2istr(clampMode), StringFromList(j, channelNumberList)})
endfor
endfor

Expand Down

0 comments on commit 1964894

Please sign in to comment.