Skip to content

Commit

Permalink
Changes select test
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelHuth committed Jul 27, 2023
1 parent 1872640 commit 561a02d
Show file tree
Hide file tree
Showing 2 changed files with 222 additions and 28 deletions.
117 changes: 108 additions & 9 deletions Packages/tests/Basic/UTF_SweepFormula.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ End
/// Add 10 sweeps from various AD/DA channels to the fake databrowser
static Function [variable numSweeps, variable numChannels, WAVE/U/I channels] FillFakeDatabrowserWindow(string win, string device, variable channelTypeNumeric, string lbnTextKey, string lbnTextValue)

variable i, j, channelNumber, sweepNumber
variable i, j, channelNumber, sweepNumber, clampMode
string name, trace

numSweeps = 10
Expand Down Expand Up @@ -99,12 +99,13 @@ static Function [variable numSweeps, variable numChannels, WAVE/U/I channels] Fi
for(j = 0; j < numChannels; j += 1)
name = UniqueName("data", 1, 0)
trace = "trace_" + name
clampMode = mod(sweepNumber, 2) ? V_CLAMP_MODE : I_CLAMP_MODE
Extract input, $name, q == i && r == j
WAVE wv = $name
AppendToGraph/W=$win wv/TN=$trace
channelNumber = channels[i][j]
TUD_SetUserDataFromWaves(win, trace, {"experiment", "fullPath", "traceType", "occurence", "channelType", "channelNumber", "sweepNumber", "GUIChannelNumber"}, \
{"blah", GetWavesDataFolder(wv, 2), "Sweep", "0", channelType, num2str(channelNumber), num2str(sweepNumber), num2istr(channelNumber)})
TUD_SetUserDataFromWaves(win, trace, {"experiment", "fullPath", "traceType", "occurence", "channelType", "channelNumber", "sweepNumber", "GUIChannelNumber", "clampMode"}, \
{"blah", GetWavesDataFolder(wv, 2), "Sweep", "0", channelType, num2str(channelNumber), num2str(sweepNumber), num2istr(channelNumber), num2istr(clampMode)})
values[connections[j]] = channelNumber
config[j][%ChannelType] = XOP_CHANNEL_TYPE_ADC
config[j][%ChannelNumber] = channelNumber
Expand Down Expand Up @@ -2015,6 +2016,8 @@ static Function TestOperationSelect()

CreateFakeSweepData(win, device, sweepNo=sweepNo)
CreateFakeSweepData(win, device, sweepNo=sweepNo + 1)
CreateFakeSweepData(win, device, sweepNo=sweepNo + 2)
CreateFakeSweepData(win, device, sweepNo=sweepNo + 3)

numChannels = 4 // from LBN creation in CreateFakeSweepData->PrepareLBN_IGNORE -> DA2, AD6, DA3, AD7
Make/FREE/N=0 sweepTemplate
Expand Down Expand Up @@ -2047,10 +2050,47 @@ static Function TestOperationSelect()
REQUIRE_EQUAL_WAVES(dataRef, data, mode = WAVE_DATA | DIMENSION_SIZES)

// non-existing sweeps are ignored
str = "select(channels(AD),[" + num2istr(sweepNo) + "," + num2istr(sweepNo + 2) + "],all)"
str = "select(channels(AD),[" + num2istr(sweepNo) + "," + num2istr(sweepNo + 1337) + "],all)"
WAVE data = SF_ExecuteFormula(str, win, singleResult=1, useVariables=0)
REQUIRE_EQUAL_WAVES(dataRef, data, mode = WAVE_DATA | DIMENSION_SIZES)

Make/FREE/N=(1, 3) dataRef
dataRef[][0] = 3
dataRef[][1] = WhichListItem("DA", XOP_CHANNEL_NAMES)
dataRef[][2] = {0} // DA0 (unassoc)
str = "select(channels(DA0),[" + num2istr(3) + "],all)"
WAVE data = SF_ExecuteFormula(str, win, singleResult=1, useVariables=0)
REQUIRE_EQUAL_WAVES(dataRef, data, mode = WAVE_DATA | DIMENSION_SIZES)

Make/FREE/N=(1, 3) dataRef
dataRef[][0] = 3
dataRef[][1] = WhichListItem("AD", XOP_CHANNEL_NAMES)
dataRef[][2] = {1} // AD1 (unassoc)
str = "select(channels(AD1),[" + num2istr(3) + "],all)"
WAVE data = SF_ExecuteFormula(str, win, singleResult=1, useVariables=0)
REQUIRE_EQUAL_WAVES(dataRef, data, mode = WAVE_DATA | DIMENSION_SIZES)

Make/FREE/N=(1, 3) dataRef
dataRef[][0] = 3
dataRef[][1] = WhichListItem("TTL", XOP_CHANNEL_NAMES)
dataRef[][2] = {2} // TTL2
str = "select(channels(TTL2),[" + num2istr(3) + "],all)"
WAVE data = SF_ExecuteFormula(str, win, singleResult=1, useVariables=0)
REQUIRE_EQUAL_WAVES(dataRef, data, mode = WAVE_DATA | DIMENSION_SIZES)

// clamp mode set filters has no effect on TTL
str = "select(channels(TTL2),[" + num2istr(3) + "],all,vc)"
WAVE data = SF_ExecuteFormula(str, win, singleResult=1, useVariables=0)
REQUIRE_EQUAL_WAVES(dataRef, data, mode = WAVE_DATA | DIMENSION_SIZES)

// clamp mode set filters on DA/AD
str = "select(channels(AD1),[" + num2istr(3) + "],all,vc)"
WAVE/Z data = SF_ExecuteFormula(str, win, singleResult=1, useVariables=0)
CHECK_WAVE(data, NULL_WAVE)
str = "select(channels(DA0),[" + num2istr(3) + "],all,vc)"
WAVE/Z data = SF_ExecuteFormula(str, win, singleResult=1, useVariables=0)
CHECK_WAVE(data, NULL_WAVE)

Make/FREE/N=(4, 3) dataRef
dataRef[][0] = {sweepNo, sweepNo, sweepNo + 1, sweepNo + 1} // sweep 0, 1 with 2 AD channels each
dataRef[][1] = WhichListItem("AD", XOP_CHANNEL_NAMES)
Expand All @@ -2077,7 +2117,7 @@ static Function TestOperationSelect()
REQUIRE_EQUAL_WAVES(dataRef, data, mode = WAVE_DATA | DIMENSION_SIZES)

// No existing sweeps
str = "select(channels(AD6, DA),[" + num2istr(sweepNo + 2) + "],all)"
str = "select(channels(AD6, DA),[" + num2istr(sweepNo + 1337) + "],all)"
WAVE/Z data = SF_ExecuteFormula(str, win, singleResult=1, useVariables=0)
REQUIRE(!WaveExists(data))

Expand Down Expand Up @@ -2183,7 +2223,7 @@ static Function TestOperationSelect()
REQUIRE_EQUAL_WAVES(dataRef, data, mode = WAVE_DATA | DIMENSION_SIZES)

// No existing sweeps
str = "select(channels(AD6, DA),[" + num2istr(sweepNo + 2) + "])"
str = "select(channels(AD6, DA),[" + num2istr(sweepNo + 1337) + "])"
WAVE/Z data = SF_ExecuteFormula(str, win, singleResult=1, useVariables=0)
REQUIRE(!WaveExists(data))

Expand Down Expand Up @@ -2225,6 +2265,64 @@ static Function TestOperationSelect()
PASS()
endtry

// Setup graph for unassoc DA/AD and TTL
numSweeps = 1
channelTypeList = "DA;AD;TTL;"
channelNumberList = "0;1;2;"

RemoveTracesFromGraph(win)
TUD_Clear(win)

Make/FREE/N=(dataSize, numSweeps, numChannels) input = q + p^r // + gnoise(1)
for(i = 0; i < numSweeps; i += 1)
sweepNo = i
for(j = 0; j < numChannels; j += 1)
name = UniqueName("data", 1, 0)
trace = "trace_" + name
clampMode = NaN
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", "GUIChannelNumber", "AssociatedHeadstage"}, \
{"blah", GetWavesDataFolder(wv, 2), "Sweep", "0", StringFromList(j, channelTypeList), StringFromList(j, channelNumberList), num2istr(sweepNo), num2istr(clampMode), StringFromList(j, channelNumberList), num2istr(0)})
endfor
endfor

Make/FREE/N=(1, 3) dataRef
dataRef[][0] = {0}
dataRef[][1] = WhichListItem("DA", XOP_CHANNEL_NAMES)
dataRef[][2] = {0}
str = "select(channels(DA0),sweeps(),displayed)"
WAVE data = SF_ExecuteFormula(str, win, singleResult=1, useVariables=0)
REQUIRE_EQUAL_WAVES(dataRef, data, mode = WAVE_DATA | DIMENSION_SIZES)

Make/FREE/N=(1, 3) dataRef
dataRef[][0] = {0}
dataRef[][1] = WhichListItem("AD", XOP_CHANNEL_NAMES)
dataRef[][2] = {1}
str = "select(channels(AD1),sweeps(),displayed)"
WAVE data = SF_ExecuteFormula(str, win, singleResult=1, useVariables=0)
REQUIRE_EQUAL_WAVES(dataRef, data, mode = WAVE_DATA | DIMENSION_SIZES)

Make/FREE/N=(1, 3) dataRef
dataRef[][0] = {0}
dataRef[][1] = WhichListItem("TTL", XOP_CHANNEL_NAMES)
dataRef[][2] = {2}
str = "select(channels(TTL2),sweeps(),displayed)"
WAVE data = SF_ExecuteFormula(str, win, singleResult=1, useVariables=0)
REQUIRE_EQUAL_WAVES(dataRef, data, mode = WAVE_DATA | DIMENSION_SIZES)
// clamp mode set filters has no effect on TTL
str = "select(channels(TTL2),sweeps(),displayed,vc)"
WAVE data = SF_ExecuteFormula(str, win, singleResult=1, useVariables=0)
REQUIRE_EQUAL_WAVES(dataRef, data, mode = WAVE_DATA | DIMENSION_SIZES)

// clamp mode set filters on DA/AD
str = "select(channels(AD1),sweeps(),displayed,vc)"
WAVE/Z data = SF_ExecuteFormula(str, win, singleResult=1, useVariables=0)
CHECK_WAVE(data, NULL_WAVE)
str = "select(channels(DA0),sweeps(),displayed,vc)"
WAVE/Z data = SF_ExecuteFormula(str, win, singleResult=1, useVariables=0)
CHECK_WAVE(data, NULL_WAVE)
End

static Function CheckSweepsFromData(WAVE/WAVE dataWref, WAVE sweepRef, variable numResults, WAVE chanIndex[, WAVE ranges])
Expand Down Expand Up @@ -2339,7 +2437,7 @@ End

static Function TestOperationData()

variable i, j, numChannels, sweepNo, sweepCnt, numResultsRef
variable i, j, numChannels, sweepNo, sweepCnt, numResultsRef, clampMode
string str, epochStr, name, trace
string win, device
variable mode = DATA_ACQUISITION_MODE
Expand Down Expand Up @@ -2514,11 +2612,12 @@ static Function TestOperationData()
for(j = 0; j < numChannels; j += 1)
name = UniqueName("data", 1, 0)
trace = "trace_" + name
clampMode = mod(sweepNo, 2) ? V_CLAMP_MODE : I_CLAMP_MODE
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", "GUIChannelNumber"}, \
{"blah", GetWavesDataFolder(wv, 2), "Sweep", "0", StringFromList(j, channelTypeList), StringFromList(j, channelNumberList), num2istr(sweepNo), StringFromList(j, channelNumberList)})
TUD_SetUserDataFromWaves(win, trace, {"experiment", "fullPath", "traceType", "occurence", "channelType", "channelNumber", "sweepNumber", "GUIChannelNumber", "clampMode"}, \
{"blah", GetWavesDataFolder(wv, 2), "Sweep", "0", StringFromList(j, channelTypeList), StringFromList(j, channelNumberList), num2istr(sweepNo), StringFromList(j, channelNumberList), num2istr(clampMode)})
endfor
endfor

Expand Down
133 changes: 114 additions & 19 deletions Packages/tests/UTF_HelperFunctions.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -238,13 +238,15 @@ End

Function [string key, string keyTxt] PrepareLBN_IGNORE(string device)

variable sweepNo
variable sweepNo, hwType
string strVal

key = LABNOTEBOOK_USER_PREFIX + "some key"
keyTxt = LABNOTEBOOK_USER_PREFIX + "other key"

WAVE numericalValues = GetLBNumericalValues(device)
WAVE textualValues = GetLBTextualValues(device)
hwType = GetHardwareType(device)

// prepare the LBN
Make/FREE/N=(1, 1, LABNOTEBOOK_LAYER_COUNT) values, valuesDAC, valuesADC
Expand Down Expand Up @@ -430,6 +432,66 @@ Function [string key, string keyTxt] PrepareLBN_IGNORE(string device)
keys[0][0][0] = keyTxt
ED_AddEntriesToLabnotebook(valuesTxt, keys, sweepNo, device, DATA_ACQUISITION_MODE)

sweepNo = 3

valuesDAC[] = NaN
valuesDAC[0][0][0] = 1
valuesDAC[0][0][1] = 0
keys[0][0][0] = "DAC"
ED_AddEntriesToLabnotebook(valuesDAC, keys, sweepNo, device, DATA_ACQUISITION_MODE)

valuesADC[] = NaN
valuesADC[0][0][0] = 0
valuesADC[0][0][1] = 1
keys[0][0][0] = "ADC"
ED_AddEntriesToLabnotebook(valuesADC, keys, sweepNo, device, DATA_ACQUISITION_MODE)

values[] = 0
values[0][0][0] = 1
values[0][0][1] = 0
keys[0][0][0] = "Headstage Active"
ED_AddEntriesToLabnotebook(valuesDAC, keys, sweepNo, device, DATA_ACQUISITION_MODE)

values[] = NaN
values[0][0][0] = V_CLAMP_MODE
keys[0][0][0] = CLAMPMODE_ENTRY_KEY
ED_AddEntriesToLabnotebook(values, keys, sweepNo, device, DATA_ACQUISITION_MODE)

// indep headstage
values[] = NaN
values[0][0][INDEP_HEADSTAGE] = hwType
keys[0][0][0] = "Digitizer Hardware Type"
keys[2][0][0] = "1"
ED_AddEntriesToLabnotebook(values, keys, sweepNo, device, DATA_ACQUISITION_MODE)

if(hwType == HARDWARE_NI_DAC)
Make/FREE/T/N=(NUM_DA_TTL_CHANNELS) ttlChannels
ttlChannels[2] = "2"
strVal = TextWaveToList(ttlChannels, ";")
valuesTxt[] = ""
valuesTxt[0][0][INDEP_HEADSTAGE] = strVal
keys[0][0][0] = "TTL channels"
keys[2][0][0] = LABNOTEBOOK_NO_TOLERANCE
ED_AddEntriesToLabnotebook(valuesTxt, keys, sweepNo, device, DATA_ACQUISITION_MODE)

elseif(hwType == HARDWARE_ITC_DAC)

values[] = NaN
keys = ""
values[0][0][INDEP_HEADSTAGE] = IsITC1600(device) ? HARDWARE_ITC_TTL_1600_RACK_ZERO : HARDWARE_ITC_TTL_DEF_RACK_ZERO
keys[0][0][0] = "TTL rack zero channel"
keys[2][0][0] = LABNOTEBOOK_NO_TOLERANCE
ED_AddEntriesToLabnotebook(values, keys, sweepNo, device, DATA_ACQUISITION_MODE)

values[] = NaN
keys = ""
values[0][0][INDEP_HEADSTAGE] = 1 << 2
keys[0][0][0] = "TTL rack zero bits"
keys[1][0][0] = "bit mask"
keys[2][0][0] = LABNOTEBOOK_NO_TOLERANCE
ED_AddEntriesToLabnotebook(values, keys, sweepNo, device, DATA_ACQUISITION_MODE)
endif

return [key, keyTxt]
End

Expand All @@ -449,7 +511,7 @@ End
Function CreateFakeSweepData(string win, string device, [variable sweepNo, FUNCREF FakeSweepDataGeneratorProto sweepGen])

string list, key, keyTxt
variable numChannels
variable numChannels, hwType

sweepNo = ParamIsDefault(sweepNo) ? 0: sweepNo
if(ParamIsDefault(sweepGen))
Expand All @@ -459,26 +521,59 @@ Function CreateFakeSweepData(string win, string device, [variable sweepNo, FUNCR
GetDAQDeviceID(device)

[key, keyTxt] = PrepareLBN_IGNORE(device)
numChannels = 4 // from LBN creation in PrepareLBN_IGNORE -> DA2, AD6, DA3, AD7

WAVE sweepTemplate = GetDAQDataWave(device, DATA_ACQUISITION_MODE)
WAVE sweep = sweepGen(sweepTemplate, numChannels)

WAVE config = GetDAQConfigWave(device)
Redimension/N=(4, -1) config
// creates HS 0 with DAC 2 and ADC 6
config[0][%ChannelType] = XOP_CHANNEL_TYPE_DAC
config[0][%ChannelNumber] = 2

config[1][%ChannelType] = XOP_CHANNEL_TYPE_ADC
config[1][%ChannelNumber] = 6

// creates HS 1 with DAC 3 and ADC 7
config[2][%ChannelType] = XOP_CHANNEL_TYPE_DAC
config[2][%ChannelNumber] = 3

config[3][%ChannelType] = XOP_CHANNEL_TYPE_ADC
config[3][%ChannelNumber] = 7
hwType = GetHardwareType(device)
switch(sweepNo)
case 0: // intended drop through
case 1:
case 2:
numChannels = 4 // from LBN creation in PrepareLBN_IGNORE -> DA2, AD6, DA3, AD7
WAVE sweep = sweepGen(sweepTemplate, numChannels)

Redimension/N=(numChannels, -1) config
// creates HS 0 with DAC 2 and ADC 6
config[0][%ChannelType] = XOP_CHANNEL_TYPE_DAC
config[0][%ChannelNumber] = 2

config[1][%ChannelType] = XOP_CHANNEL_TYPE_ADC
config[1][%ChannelNumber] = 6

// creates HS 1 with DAC 3 and ADC 7
config[2][%ChannelType] = XOP_CHANNEL_TYPE_DAC
config[2][%ChannelNumber] = 3

config[3][%ChannelType] = XOP_CHANNEL_TYPE_ADC
config[3][%ChannelNumber] = 7
break
case 3:
numChannels = 5 // from LBN creation in PrepareLBN_IGNORE -> DA2, AD6, DA3, AD7
WAVE sweep = sweepGen(sweepTemplate, numChannels)

Redimension/N=(numChannels, -1) config
// creates HS 0 with DAC 1 and ADC 0
config[0][%ChannelType] = XOP_CHANNEL_TYPE_DAC
config[0][%ChannelNumber] = 1

config[1][%ChannelType] = XOP_CHANNEL_TYPE_ADC
config[1][%ChannelNumber] = 0

// DAC 0 unassoc
config[2][%ChannelType] = XOP_CHANNEL_TYPE_DAC
config[2][%ChannelNumber] = 0
// ADC 1 unassoc
config[3][%ChannelType] = XOP_CHANNEL_TYPE_ADC
config[3][%ChannelNumber] = 1
// TTL 2
config[4][%ChannelType] = XOP_CHANNEL_TYPE_TTL
config[4][%ChannelNumber] = hwType == HARDWARE_NI_DAC ? 2 : IsITC1600(device) ? HARDWARE_ITC_TTL_1600_RACK_ZERO : HARDWARE_ITC_TTL_DEF_RACK_ZERO
break
default:
INFO("Unsupported sweep number in test setup")
FAIL()
return NaN
endswitch

DFREF dfr = GetDeviceDataPath(device)
MoveWave sweep, dfr:$GetSweepWaveName(sweepNo)
Expand Down

0 comments on commit 561a02d

Please sign in to comment.