Skip to content

Commit

Permalink
Bugfix: SF use proper handling of sweepMap for SB
Browse files Browse the repository at this point in the history
problem described in #2151

SF requires to retrieve the correct LNBs and sweepDFR for sweeps.
Through the analysisbrowser sweeps from multiple devices and/or
experiments can be loaded. This must be handled correctly or wrong
data is retrieved/analysed.

Thus, SF functions that retrieve sweep data are adapted to handle that
correctly. For selections a forth column was added to store the mapIndex
of the sweepMap that is unique for a sweepNo, experiment, device combination.

For graphs from SB the mapIndex is used to retrieve the correct LNB, SweepDF.

** THIS BUGFIX IS LIMITED TO SWEEP HANDLING IN SWEEPFORMULA **

Other parts of MIES may be still unaware of multiple experiment/devices in the SB.
  • Loading branch information
MichaelHuth authored and t-b committed Oct 14, 2024
1 parent 01317c5 commit d5b560f
Show file tree
Hide file tree
Showing 3 changed files with 145 additions and 148 deletions.
1 change: 1 addition & 0 deletions Packages/MIES/MIES_Constants.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -2042,6 +2042,7 @@ StrConstant SF_META_SWEEPNO = "/SweepNumber" // number
StrConstant SF_META_RANGE = "/Range" // numeric wave
StrConstant SF_META_CHANNELTYPE = "/ChannelType" // number
StrConstant SF_META_CHANNELNUMBER = "/ChannelNumber" // number
StrConstant SF_META_SWEEPMAPINDEX = "/SweepMapIndex" // number
StrConstant SF_META_ISAVERAGED = "/IsAveraged" // number
StrConstant SF_META_AVERAGED_FIRST_SWEEP = "/AveragedFirstSweep" // number
StrConstant SF_META_XVALUES = "/XValues" // numeric wave
Expand Down
202 changes: 98 additions & 104 deletions Packages/MIES/MIES_SweepFormula.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ static Constant SF_POWERSPECTRUM_RATIO_GAUSS_NUMCOEFS = 4

static Constant SF_VARIABLE_PREFIX = 36

static StrConstant SF_GETSETINTERSECTIONSELECT_FORMAT = "%d_%d_%d"
static StrConstant SF_GETSETINTERSECTIONSELECT_FORMAT = "%d_%d_%d_%f"

Menu "GraphPopup"
"Bring browser to front", /Q, SF_BringBrowserToFront()
Expand Down Expand Up @@ -2253,10 +2253,12 @@ static Function/WAVE SF_GetSelectData(string graph, STRUCT SF_SelectParameters &
variable i, j, k, l, channelType, channelNumber, sweepNo, sweepNoT, outIndex
variable numSweeps, numInChannels, numActiveChannels, index
variable isSweepBrowser
variable dimPosSweep, dimPosChannelNumber, dimPosChannelType
variable dimPosTSweep, dimPosTChannelNumber, dimPosTChannelType, dimPosTClampMode
variable numTraces, fromDisplayed, clampCode
string msg, device, singleSweepDFStr
variable dimPosSweep, dimPosChannelNumber, dimPosChannelType, dimPosSweepMapIndex
variable dimPosTSweep, dimPosTChannelNumber, dimPosTChannelType, dimPosTClampMode, dimPosTSweepMapIndex
variable numTraces, fromDisplayed, clampCode, smIndexCounter, mapIndex
string msg, device, singleSweepDFStr, expName, dataFolder
variable mapSize = 1
DFREF deviceDFR = $""

WAVE/Z sweeps = filter.sweeps
WAVE/Z channels = filter.channels
Expand All @@ -2265,7 +2267,8 @@ static Function/WAVE SF_GetSelectData(string graph, STRUCT SF_SelectParameters &
return $""
endif

fromDisplayed = !CmpStr(filter.vis, SF_OP_SELECTVIS_DISPLAYED)
fromDisplayed = !CmpStr(filter.vis, SF_OP_SELECTVIS_DISPLAYED)
isSweepBrowser = BSP_IsSweepBrowser(graph)

if(fromDisplayed)
WAVE/T/Z traces = GetTraceInfos(graph)
Expand All @@ -2289,10 +2292,12 @@ static Function/WAVE SF_GetSelectData(string graph, STRUCT SF_SelectParameters &
dimPosSweep = FindDimLabel(selectDisplayed, COLS, "SWEEP")
dimPosChannelType = FindDimLabel(selectDisplayed, COLS, "CHANNELTYPE")
dimPosChannelNumber = FindDimLabel(selectDisplayed, COLS, "CHANNELNUMBER")
dimPosSweepMapIndex = FindDimLabel(selectDisplayed, COLS, "SWEEPMAPINDEX")

dimPosTChannelType = FindDimLabel(traces, COLS, "channelType")
dimPosTChannelNumber = FindDimLabel(traces, COLS, "GUIChannelNumber")
dimPosTClampMode = FindDimLabel(traces, COLS, "clampMode")
dimPosTSweepMapIndex = FindDimLabel(traces, COLS, "SweepMapIndex")
for(i = 0; i < numSweeps; i += 1)
sweepNo = sweeps[i]
for(j = 0; j < numTraces; j += 1)
Expand All @@ -2301,6 +2306,7 @@ static Function/WAVE SF_GetSelectData(string graph, STRUCT SF_SelectParameters &
selectDisplayed[outIndex][dimPosSweep] = sweepNo
selectDisplayed[outIndex][dimPosChannelType] = WhichListItem(traces[j][dimPosTChannelType], XOP_CHANNEL_NAMES)
selectDisplayed[outIndex][dimPosChannelNumber] = str2num(traces[j][dimPosTChannelNumber])
selectDisplayed[outIndex][dimPosSweepMapIndex] = str2num(traces[j][dimPosTSweepMapIndex])
clampModeDisplayed[outIndex] = str2num(traces[j][dimPosTClampMode])
outIndex += 1
endif
Expand All @@ -2317,16 +2323,10 @@ static Function/WAVE SF_GetSelectData(string graph, STRUCT SF_SelectParameters &
numTraces = outIndex

outIndex = 0
elseif(isSweepBrowser)
WAVE/T sweepMap = SB_GetSweepMap(graph)
else
isSweepBrowser = BSP_IsSweepBrowser(graph)
if(isSweepBrowser)
DFREF sweepBrowserDFR = SB_GetSweepBrowserFolder(graph)
WAVE/T sweepMap = GetSweepBrowserMap(sweepBrowserDFR)
else
SFH_ASSERT(BSP_HasBoundDevice(graph), "No device bound.")
device = BSP_GetDevice(graph)
DFREF deviceDFR = GetDeviceDataPath(device)
endif
DFREF deviceDFR = DB_GetDeviceDF(graph)
endif

// search sweeps for active channels
Expand All @@ -2338,6 +2338,7 @@ static Function/WAVE SF_GetSelectData(string graph, STRUCT SF_SelectParameters &
dimPosSweep = FindDimLabel(selectData, COLS, "SWEEP")
dimPosChannelType = FindDimLabel(selectData, COLS, "CHANNELTYPE")
dimPosChannelNumber = FindDimLabel(selectData, COLS, "CHANNELNUMBER")
dimPosSweepMapIndex = FindDimLabel(selectData, COLS, "SWEEPMAPINDEX")
endif

for(i = 0; i < numSweeps; i += 1)
Expand All @@ -2349,86 +2350,85 @@ static Function/WAVE SF_GetSelectData(string graph, STRUCT SF_SelectParameters &

if(!fromDisplayed)
if(isSweepBrowser)
DFREF deviceDFR = SB_GetSweepDataFolder(sweepMap, sweepNo = sweepNo)
if(!DataFolderExistsDFR(deviceDFR))
continue
endif
else
if(DB_SplitSweepsIfReq(graph, sweepNo))
WAVE/Z mapIndices = SF_GetSweepMapIndices(sweepMap, sweepNo, "", "")
if(!WaveExists(mapIndices))
continue
endif
endif
singleSweepDFStr = GetSingleSweepFolderAsString(deviceDFR, sweepNo)
if(!DataFolderExists(singleSweepDFStr))
continue
endif
DFREF sweepDFR = $singleSweepDFStr
WAVE/Z numericalValues = BSP_GetLogbookWave(graph, LBT_LABNOTEBOOK, LBN_NUMERICAL_VALUES, sweepNumber = sweepNo)
if(!WaveExists(numericalValues))
continue
endif
WAVE/Z/T textualValues = BSP_GetLogbookWave(graph, LBT_LABNOTEBOOK, LBN_TEXTUAL_VALUES, sweepNumber = sweepNo)
if(!WaveExists(textualValues))
mapSize = DimSize(mapIndices, ROWS)
elseif(DB_SplitSweepsIfReq(graph, sweepNo))
continue
endif
endif

for(j = 0; j < numInChannels; j += 1)
for(smIndexCounter = 0; smIndexCounter < mapSize; smIndexCounter += 1)
if(!fromDisplayed)
mapIndex = isSweepBrowser ? mapIndices[smIndexCounter] : NaN
DFREF sweepDFR
[WAVE numericalValues, WAVE textualValues, sweepDFR] = SFH_GetLabNoteBooksAndDFForSweep(graph, sweepNo, mapIndex)
if(!WaveExists(numericalValues) || !WaveExists(textualValues) || !DataFolderExistsDFR(sweepDFR))
continue
endif
endif

channelType = channels[j][%channelType]
channelNumber = channels[j][%channelNumber]
for(j = 0; j < numInChannels; j += 1)

if(IsNaN(channelType))
Make/FREE/D channelTypes = {XOP_CHANNEL_TYPE_DAC, XOP_CHANNEL_TYPE_ADC, XOP_CHANNEL_TYPE_TTL}
else
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
channelType = channels[j][%channelType]
channelNumber = channels[j][%channelNumber]

for(channelType : channelTypes)
if(IsNaN(channelType))
Make/FREE/D channelTypes = {XOP_CHANNEL_TYPE_DAC, XOP_CHANNEL_TYPE_ADC, XOP_CHANNEL_TYPE_TTL}
else
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

if(fromDisplayed)
for(l = 0; l < numTraces; l += 1)
for(channelType : channelTypes)

clampCode = SF_MapClampModeToSelectCM(clampModeDisplayed[l])
if(!SF_IsValidSingleSelection(graph, filter, sweepNo, channelNumber, channelType, selectDisplayed[l][dimPosSweep], selectDisplayed[l][dimPosChannelNumber], selectDisplayed[l][dimPosChannelType], clampCode))
continue
endif
if(fromDisplayed)
for(l = 0; l < numTraces; l += 1)

selectData[outIndex][dimPosSweep] = sweepNo
selectData[outIndex][dimPosChannelType] = channelType
selectData[outIndex][dimPosChannelNumber] = selectDisplayed[l][dimPosChannelNumber]
outIndex += 1
endfor
else
WAVE/Z activeChannels = GetActiveChannels(numericalValues, textualValues, sweepNo, channelType)
if(!WaveExists(activeChannels))
continue
endif
// faster than ZapNaNs due to no mem alloc
numActiveChannels = DimSize(activeChannels, ROWS)
for(l = 0; l < numActiveChannels; l += 1)
if(IsNan(activeChannels[l]))
clampCode = SF_MapClampModeToSelectCM(clampModeDisplayed[l])
if(!SF_IsValidSingleSelection(graph, filter, sweepNo, channelNumber, channelType, selectDisplayed[l][dimPosSweep], selectDisplayed[l][dimPosChannelNumber], selectDisplayed[l][dimPosChannelType], clampCode))
continue
endif

selectData[outIndex][dimPosSweep] = sweepNo
selectData[outIndex][dimPosChannelType] = channelType
selectData[outIndex][dimPosChannelNumber] = selectDisplayed[l][dimPosChannelNumber]
selectData[outIndex][dimPosSweepMapIndex] = selectDisplayed[l][dimPosSweepMapIndex]
outIndex += 1
endfor
else
WAVE/Z activeChannels = GetActiveChannels(numericalValues, textualValues, sweepNo, channelType)
if(!WaveExists(activeChannels))
continue
endif
// faster than ZapNaNs due to no mem alloc
numActiveChannels = DimSize(activeChannels, ROWS)
for(l = 0; l < numActiveChannels; l += 1)
if(IsNan(activeChannels[l]))
continue
endif

if(SF_FilterByClampModeEnabled(filter.clampMode, channelType))
[WAVE setting, index] = GetLastSettingChannel(numericalValues, $"", sweepNo, CLAMPMODE_ENTRY_KEY, l, channelType, DATA_ACQUISITION_MODE)
clampCode = WaveExists(setting) ? SF_MapClampModeToSelectCM(setting[index]) : SF_OP_SELECT_CLAMPCODE_NONE
endif
if(SF_FilterByClampModeEnabled(filter.clampMode, channelType))
[WAVE setting, index] = GetLastSettingChannel(numericalValues, $"", sweepNo, CLAMPMODE_ENTRY_KEY, l, channelType, DATA_ACQUISITION_MODE)
clampCode = WaveExists(setting) ? SF_MapClampModeToSelectCM(setting[index]) : SF_OP_SELECT_CLAMPCODE_NONE
endif

if(!SF_IsValidSingleSelection(graph, filter, sweepNo, channelNumber, channelType, sweepNo, l, channelType, clampCode))
continue
endif
if(!SF_IsValidSingleSelection(graph, filter, sweepNo, channelNumber, channelType, sweepNo, l, channelType, clampCode))
continue
endif

selectData[outIndex][dimPosSweep] = sweepNo
selectData[outIndex][dimPosChannelType] = channelType
selectData[outIndex][dimPosChannelNumber] = l
outIndex += 1
endfor
endif
selectData[outIndex][dimPosSweep] = sweepNo
selectData[outIndex][dimPosChannelType] = channelType
selectData[outIndex][dimPosChannelNumber] = l
selectData[outIndex][dimPosSweepMapIndex] = mapIndex
outIndex += 1
endfor
endif

endfor
endfor
endfor
endfor
Expand Down Expand Up @@ -2975,7 +2975,7 @@ static Function/WAVE SF_OperationTPImpl(string graph, WAVE/WAVE mode, WAVE/Z sel
string fitFunc, retWhat, epBaselineTrail, allowedReturns

variable numTPs, beginTrail, endTrail, endTrailZero, endTrailIndex, beginTrailIndex, fitResult
variable debugMode
variable debugMode, mapIndex

STRUCT TPAnalysisInput tpInput
string epochTPRegExp = "^(U_)?TP[[:digit:]]*$"
Expand Down Expand Up @@ -3013,21 +3013,21 @@ static Function/WAVE SF_OperationTPImpl(string graph, WAVE/WAVE mode, WAVE/Z sel
WAVE/Z settings
for(i = 0; i < numSelected; i += 1)

sweepNo = selectData[i][%SWEEP]
chanNr = selectData[i][%CHANNELNUMBER]
chanType = selectData[i][%CHANNELTYPE]

sweepNo = selectData[i][%SWEEP]
if(!IsValidSweepNumber(sweepNo))
continue
endif

WAVE/Z numericalValues = BSP_GetLogbookWave(graph, LBT_LABNOTEBOOK, LBN_NUMERICAL_VALUES, sweepNumber = sweepNo)
WAVE/Z textualValues = BSP_GetLogbookWave(graph, LBT_LABNOTEBOOK, LBN_TEXTUAL_VALUES, sweepNumber = sweepNo)
chanNr = selectData[i][%CHANNELNUMBER]
chanType = selectData[i][%CHANNELTYPE]
mapIndex = selectData[i][%SWEEPMAPINDEX]
DFREF sweepDFR
[WAVE numericalValues, WAVE textualValues, sweepDFR] = SFH_GetLabNoteBooksAndDFForSweep(graph, sweepNo, mapIndex)
if(!WaveExists(numericalValues) || !WaveExists(textualValues))
continue
endif
SFH_ASSERT(DataFolderExistsDFR(sweepDFR), "Could not determine sweepDFR")

WAVE/WAVE singleSelect = SFH_GetSingleSelect(graph, opShort, sweepNo, chanType, chanNr)
WAVE/WAVE singleSelect = SFH_GetSingleSelect(graph, opShort, sweepNo, chanType, chanNr, mapIndex)
WAVE/WAVE sweepDataRef = SFH_GetSweepsForFormula(graph, singleSelect, SF_OP_TP)
SFH_ASSERT(DimSize(sweepDataRef, ROWS) == 1, "Could not retrieve sweep data for " + num2istr(sweepNo))
WAVE/Z sweepData = sweepDataRef[0]
Expand All @@ -3054,8 +3054,6 @@ static Function/WAVE SF_OperationTPImpl(string graph, WAVE/WAVE mode, WAVE/Z sel
dacChannelNr = settings[headstage]
SFH_ASSERT(IsFinite(dacChannelNr), "DAC channel number must be finite")

DFREF sweepDFR = BSP_GetSweepDF(graph, sweepNo)
SFH_ASSERT(DataFolderExistsDFR(sweepDFR), "Could not determine sweepDFR")
WAVE/Z epochMatchesAll = EP_GetEpochs(numericalValues, textualValues, sweepNo, XOP_CHANNEL_TYPE_DAC, dacChannelNr, epochTPRegExp, sweepDFR = sweepDFR)

// drop TPs which should be ignored
Expand Down Expand Up @@ -3393,22 +3391,20 @@ static Function/WAVE SF_OperationEpochsImpl(string graph, WAVE/T epochPatterns,
numPatterns = DimSize(epochPatterns, ROWS)
for(i = 0; i < numSelected; i += 1)

sweepNo = selectData[i][%SWEEP]
chanNr = selectData[i][%CHANNELNUMBER]
chanType = selectData[i][%CHANNELTYPE]

sweepNo = selectData[i][%SWEEP]
if(!IsValidSweepNumber(sweepNo))
continue
endif
chanNr = selectData[i][%CHANNELNUMBER]
chanType = selectData[i][%CHANNELTYPE]

WAVE/Z numericalValues = BSP_GetLogbookWave(graph, LBT_LABNOTEBOOK, LBN_NUMERICAL_VALUES, sweepNumber = sweepNo)
WAVE/Z textualValues = BSP_GetLogbookWave(graph, LBT_LABNOTEBOOK, LBN_TEXTUAL_VALUES, sweepNumber = sweepNo)
DFREF sweepDFR
[WAVE numericalValues, WAVE textualValues, sweepDFR] = SFH_GetLabNoteBooksAndDFForSweep(graph, sweepNo, selectData[i][%SWEEPMAPINDEX])
if(!WaveExists(numericalValues) || !WaveExists(textualValues))
continue
endif

DFREF sweepDFR = BSP_GetSweepDF(graph, sweepNo)
SFH_ASSERT(DataFolderExistsDFR(sweepDFR), "Could not determine sweepDFR")

WAVE/Z/T epochInfo = EP_FetchEpochs(numericalValues, textualValues, sweepNo, sweepDFR, chanNr, chanType)
if(!WaveExists(epochInfo))
continue
Expand Down Expand Up @@ -4367,7 +4363,7 @@ static Function/WAVE SF_OperationSelectSweeps(variable jsonId, string jsonPath,
WAVE/ZZ uniqueSweeps
endif

return SFH_GetOutputForExecutorSingle(sweeps, graph, SF_OP_SELECTSWEEPS, discardOpStack = 1, dataType = SF_DATATYPE_SWEEPNO)
return SFH_GetOutputForExecutorSingle(uniqueSweeps, graph, SF_OP_SELECTSWEEPS, discardOpStack = 1, dataType = SF_DATATYPE_SWEEPNO)
End

static Function/WAVE SF_OperationPowerSpectrum(variable jsonId, string jsonPath, string graph)
Expand Down Expand Up @@ -5047,16 +5043,14 @@ static Function/WAVE SF_OperationLabnotebookImpl(string graph, string lbnKey, WA

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

sweepNo = selectData[i][%SWEEP]
chanNr = selectData[i][%CHANNELNUMBER]
chanType = selectData[i][%CHANNELTYPE]

sweepNo = selectData[i][%SWEEP]
if(!IsValidSweepNumber(sweepNo))
continue
endif
chanNr = selectData[i][%CHANNELNUMBER]
chanType = selectData[i][%CHANNELTYPE]

WAVE/Z numericalValues = BSP_GetLogbookWave(graph, LBT_LABNOTEBOOK, LBN_NUMERICAL_VALUES, sweepNumber = sweepNo)
WAVE/Z textualValues = BSP_GetLogbookWave(graph, LBT_LABNOTEBOOK, LBN_TEXTUAL_VALUES, sweepNumber = sweepNo)
[WAVE numericalValues, WAVE textualValues] = SFH_GetLabNoteBooksForSweep(graph, sweepNo, selectData[i][%SWEEPMAPINDEX])
if(!WaveExists(numericalValues) || !WaveExists(textualValues))
continue
endif
Expand Down Expand Up @@ -6229,7 +6223,7 @@ threadsafe static Function/S SF_GetSelectRowId(WAVE select, variable row)

string str

sprintf str, SF_GETSETINTERSECTIONSELECT_FORMAT, select[row][%SWEEP], select[row][%CHANNELTYPE], select[row][%CHANNELNUMBER]
sprintf str, SF_GETSETINTERSECTIONSELECT_FORMAT, select[row][%SWEEP], select[row][%CHANNELTYPE], select[row][%CHANNELNUMBER], select[row][%SWEEPMAPINDEX]
return str
End

Expand Down
Loading

0 comments on commit d5b560f

Please sign in to comment.