Skip to content

Commit

Permalink
EP: Move AD to DA channel conversion into EP_FetchEpochs
Browse files Browse the repository at this point in the history
- When epochs are retrieved AD channels are converted to the associated
  DA channels, as only DA channels carry epoch information.
  This was done in SFH_GetSweepsForFormula and in BSP_AddTracesForEpochs in
  the same way.
- This conversion was moved into EP_FetchEpochs and is done automatically now.
  The conversion in the other functions was removed.
- The utility function SFH_GetDAChannel was removed as it is now unused
  • Loading branch information
MichaelHuth committed Jul 28, 2023
1 parent 692c7a5 commit 5d33d71
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 33 deletions.
7 changes: 2 additions & 5 deletions Packages/MIES/MIES_BrowserSettingsPanel.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -1608,7 +1608,7 @@ Function BSP_AddTracesForEpochs(string win)

variable i, j, start_x, start_y, end_x, end_y, yOffset
variable headstage, yLevelOffset, level, idx, numTraces, numEpochs
variable sweepNumber, traceIndex, channelType, channelNumber, fetchEpChanType, fetchEpChannelNumber
variable sweepNumber, traceIndex, channelType, channelNumber
STRUCT RGBColor c
string xaxis, yaxis, axes, axis, levels_x_name, levels_y_name, name, idPart, level_x_trace

Expand Down Expand Up @@ -1670,11 +1670,8 @@ Function BSP_AddTracesForEpochs(string win)
WAVE/Z/T textualValues = BSP_GetLogbookWave(win, LBT_LABNOTEBOOK, LBN_TEXTUAL_VALUES, sweepNumber = sweepNumber)
ASSERT(WaveExists(textualValues), "Textual LabNotebook not found.")

fetchEpChanType = channelType == XOP_CHANNEL_TYPE_ADC ? XOP_CHANNEL_TYPE_DAC : channelType
fetchEpChannelNumber = channelType == XOP_CHANNEL_TYPE_ADC ? SFH_GetDAChannel(win, sweepNumber, channelType, channelNumber) : channelNumber

// present since a2172f03 (Added generations of epoch information wave, 2019-05-22)
WAVE/T/Z epochsFromLBN = EP_FetchEpochs(numericalValues, textualValues, sweepNumber, fetchEpChannelNumber, fetchEpChanType)
WAVE/T/Z epochsFromLBN = EP_FetchEpochs(numericalValues, textualValues, sweepNumber, channelNumber, channelType)
if(!WaveExists(epochsFromLBN))
continue
endif
Expand Down
16 changes: 13 additions & 3 deletions Packages/MIES/MIES_Epochs.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,7 @@ Function/WAVE EP_GetEpochs(WAVE numericalValues, WAVE textualValues, variable sw
variable index, epochCnt, midSweep
string regexp

ASSERT(channelType == XOP_CHANNEL_TYPE_DAC || channelType == XOP_CHANNEL_TYPE_TTL, "Only channelType XOP_CHANNEL_TYPE_DAC and XOP_CHANNEL_TYPE_TTL is supported")
ASSERT(channelType == XOP_CHANNEL_TYPE_DAC || channelType == XOP_CHANNEL_TYPE_ADC || channelType == XOP_CHANNEL_TYPE_TTL, "Unsupported channel type")
treelevel = ParamIsDefault(treelevel) ? NaN : treelevel

if(ParamIsDefault(epochsWave) || !WaveExists(epochsWave))
Expand Down Expand Up @@ -990,10 +990,20 @@ End
///
/// See GetEpochsWave() for the wave layout.
threadsafe Function/WAVE EP_FetchEpochs(WAVE numericalValues, WAVE/T/Z textualValues, variable sweep, variable channelNumber, variable channelType)

variable index

if(channelType != XOP_CHANNEL_TYPE_DAC && channelType != XOP_CHANNEL_TYPE_TTL)
return $""
ASSERT_TS(channelType == XOP_CHANNEL_TYPE_DAC || channelType == XOP_CHANNEL_TYPE_ADC || channelType == XOP_CHANNEL_TYPE_TTL, "Unsupported channel type")
if(channelType == XOP_CHANNEL_TYPE_ADC)
[WAVE setting, index] = GetLastSettingChannel(numericalValues, $"", sweep, "DAC", channelNumber, XOP_CHANNEL_TYPE_ADC, DATA_ACQUISITION_MODE)
if(!WaveExists(setting))
return $""
endif
channelType = XOP_CHANNEL_TYPE_DAC
channelNumber = setting[index]
if(!(IsFinite(channelNumber) && index < NUM_HEADSTAGES))
return $""
endif
endif

[WAVE setting, index] = GetLastSettingChannel(numericalValues, textualValues, sweep, EPOCHS_ENTRY_KEY, channelNumber, channelType, DATA_ACQUISITION_MODE)
Expand Down
27 changes: 2 additions & 25 deletions Packages/MIES/MIES_SweepFormula_Helpers.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -363,24 +363,6 @@ Function/WAVE SFH_GetRangeFromEpoch(string graph, string epochName, variable swe
return range
End

Function SFH_GetDAChannel(string graph, variable sweep, variable channelType, variable channelNumber)

variable DAC, index

WAVE/Z numericalValues = BSP_GetLogbookWave(graph, LBT_LABNOTEBOOK, LBN_NUMERICAL_VALUES, sweepNumber = sweep)
if(!WaveExists(numericalValues))
return NaN
endif
[WAVE settings, index] = GetLastSettingChannel(numericalValues, $"", sweep, "DAC", channelNumber, channelType, DATA_ACQUISITION_MODE)
if(WaveExists(settings))
DAC = settings[index]
ASSERT(IsFinite(DAC) && index < NUM_HEADSTAGES, "Only associated channels are supported.")
return DAC
endif

return NaN
End

/// @brief Return a wave reference wave with the requested sweep data
///
/// All wave input parameters should are treated as const and are thus *not* modified.
Expand All @@ -393,7 +375,7 @@ End
Function/WAVE SFH_GetSweepsForFormula(string graph, WAVE range, WAVE/Z selectData, string opShort)

variable i, j, rangeStart, rangeEnd, sweepNo
variable chanNr, chanType, cIndex, isSweepBrowser, fetchEpChanType, fetchEpChannelNumber
variable chanNr, chanType, cIndex, isSweepBrowser
variable numSelected, index, numEpochPatterns, numRanges, numEpochs, epIndex, lastx
string dimLabel, device, dataFolder
string allEpochsRegex = "^.*$"
Expand Down Expand Up @@ -461,12 +443,7 @@ Function/WAVE SFH_GetSweepsForFormula(string graph, WAVE range, WAVE/Z selectDat

if(WaveExists(epochNames))

fetchEpChanType = chanType == XOP_CHANNEL_TYPE_ADC ? XOP_CHANNEL_TYPE_DAC : chanType
fetchEpChannelNumber = chanType == XOP_CHANNEL_TYPE_ADC ? SFH_GetDAChannel(graph, sweepNo, chanType, chanNr) : chanNr
if(IsNaN(fetchEpChannelNumber))
continue
endif
WAVE/T/Z epochInfo = EP_GetEpochs(numericalValues, textualValues, sweepNo, fetchEpChanType, fetchEpChannelNumber, allEpochsRegex)
WAVE/T/Z epochInfo = EP_GetEpochs(numericalValues, textualValues, sweepNo, chanType, chanNr, allEpochsRegex)
if(!WaveExists(epochInfo))
continue
endif
Expand Down

0 comments on commit 5d33d71

Please sign in to comment.