Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add routines for extracting the stimset epoch #1880

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Packages/MIES/MIES_MiesUtilities.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -6310,6 +6310,7 @@ Function GetTotalOnsetDelay(numericalValues, sweepNo)
WAVE numericalValues
variable sweepNo

// present since 778969b0 (DC_PlaceDataInITCDataWave: Document all other settings from the DAQ groupbox, 2015-11-26)
return GetLastSettingIndep(numericalValues, sweepNo, "Delay onset auto", DATA_ACQUISITION_MODE) + \
GetLastSettingIndep(numericalValues, sweepNo, "Delay onset user", DATA_ACQUISITION_MODE)
End
Expand Down
17 changes: 13 additions & 4 deletions Packages/MIES/MIES_SweepFormula.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -4625,7 +4625,7 @@ static Function/WAVE SF_OperationApFrequency(variable jsonId, string jsonPath, s
normValue = NaN
Make/FREE/D/N=0 normMean
WAVE/WAVE output = SFH_CreateSFRefWave(graph, opShort, DimSize(input, ROWS))
output = SF_OperationApFrequencyImpl(input[p], level, method, timeFreq, normalize, xAxisType, normValue, normMean)
output = SF_OperationApFrequencyImpl(graph, input[p], level, method, timeFreq, normalize, xAxisType, normValue, normMean)
if(!CmpStr(normalize, SF_OP_APFREQUENCY_NORMOVERSWEEPSAVG) && DimSize(normMean, ROWS))
normValue = mean(normMean)
SF_OperationApFrequencyNormalizeOverSweeps(output, normValue)
Expand Down Expand Up @@ -4659,9 +4659,9 @@ static Function SF_OperationApFrequencyNormalizeOverSweepsImpl(WAVE/Z data, vari
MultiThread data /= normValue
End

static Function/WAVE SF_OperationApFrequencyImpl(WAVE/Z data, variable level, variable method, string yStr, string normStr, string xAxisTypeStr, variable &normOSValue, WAVE normMean)
static Function/WAVE SF_OperationApFrequencyImpl(string graph, WAVE/Z data, variable level, variable method, string yStr, string normStr, string xAxisTypeStr, variable &normOSValue, WAVE normMean)

variable numPeaks, yModeTime, xAxisCount, normalize, normISValue
variable numPeaks, yModeTime, xAxisCount, normalize, normISValue, dataLengthInS
string yUnit

if(!WaveExists(data))
Expand All @@ -4680,7 +4680,16 @@ static Function/WAVE SF_OperationApFrequencyImpl(WAVE/Z data, variable level, va
switch(method)
case SF_APFREQUENCY_FULL:
// number_of_peaks / sweep_length
Make/FREE/D outD = { numPeaks / (DimDelta(data, ROWS) * DimSize(data, ROWS) * MILLI_TO_ONE) }
[WAVE selectData, WAVE selRange] = SFH_ParseToSelectDataWaveAndRange(data)

if(WaveExists(selRange) && SFH_IsFullRange(selRange))
WAVE stimsetRange = SFH_GetStimsetRange(graph, data, selectData)
dataLengthInS = (stimsetRange[1] - stimsetRange[0]) * MILLI_TO_ONE
else
dataLengthInS = DimDelta(data, ROWS) * DimSize(data, ROWS) * MILLI_TO_ONE
endif

Make/FREE/D outD = { numPeaks / dataLengthInS }
yUnit = SelectString(normalize, "Hz [Full]", "normalized frequency [Full]")
SetScale/P y, DimOffset(outD, ROWS), DimDelta(outD, ROWS), yUnit, outD
break
Expand Down
83 changes: 76 additions & 7 deletions Packages/MIES/MIES_SweepFormula_Helpers.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,14 @@ Function/WAVE SFH_GetFullRange()
return range
End

Function SFH_IsFullRange(WAVE range)

ASSERT(IsNumericWave(range), "Invalid Range wave")
WAVE rangeRef = SFH_GetFullRange()

return EqualWaves(rangeRef, range, EQWAVES_DATA)
End

/// @brief Evaluate range parameter
///
/// Range can be `[100-200]` or implicit as `cursors(A, B)` or a named epoch `E0` or a wildcard expression with epochs `E*`
Expand Down Expand Up @@ -321,12 +329,14 @@ End

/// @brief Returns a range from a epochName
///
/// @param graph name of databrowser graph
/// @param graph name of databrowser graph
/// @param epochName name epoch
/// @param sweep number of sweep
/// @param channel number of DA channel
/// @param sweep number of sweep
/// @param chanType type of channel
/// @param channel number of DA channel
///
/// @returns a 1D wave with two elements, [startTime, endTime] in ms, if no epoch could be resolved [NaN, NaN] is returned
Function/WAVE SFH_GetRangeFromEpoch(string graph, string epochName, variable sweep, variable channel)
Function/WAVE SFH_GetRangeFromEpoch(string graph, string epochName, variable sweep, variable chanType, variable channel)

string regex
variable numEpochs
Expand All @@ -347,7 +357,7 @@ Function/WAVE SFH_GetRangeFromEpoch(string graph, string epochName, variable swe
endif

regex = "^" + epochName + "$"
WAVE/T/Z epochs = EP_GetEpochs(numericalValues, textualValues, sweep, XOP_CHANNEL_TYPE_DAC, channel, regex)
WAVE/T/Z epochs = EP_GetEpochs(numericalValues, textualValues, sweep, chanType, channel, regex)
if(!WaveExists(epochs))
return range
endif
Expand Down Expand Up @@ -951,10 +961,12 @@ Function [WAVE selectData, WAVE range] SFH_ParseToSelectDataWaveAndRange(WAVE sw
WAVE/Z range = JWN_GetTextWaveFromWaveNote(sweepData, SF_META_RANGE)

if(!WaveExists(range))
WAVE range = JWN_GetNumericWaveFromWaveNote(sweepData, SF_META_RANGE)
WAVE/Z range = JWN_GetNumericWaveFromWaveNote(sweepData, SF_META_RANGE)
endif

ASSERT(HasOneValidEntry(range), "Empty range")
if(!WaveExists(range) || !HasOneValidEntry(range))
return [$"", $""]
endif

WAVE selectData = SFH_NewSelectDataWave(1, 1)

Expand Down Expand Up @@ -1238,3 +1250,60 @@ Function SFH_CheckArgumentCount(variable jsonId, string jsonPath, string opShort

return numArgs
End

/// @brief Return a SF range in ms with the stimset range
///
/// Returns the full range if it is not sweep data.
Function/WAVE SFH_GetStimsetRange(string graph, WAVE data, WAVE selectData)

variable sweepNo, channel, chanType, dDAQ, oodDAQ, onsetDelay, terminationDelay, lengthInMS

sweepNo = selectData[0][%SWEEP]
channel = selectData[0][%CHANNELNUMBER]
chanType = selectData[0][%CHANNELTYPE]

// stimset epoch "ST" does not include any onset or termination delay and only the stimset epochs
// and it also works with dDAQ/oodDAQ
WAVE range = SFH_GetRangeFromEpoch(graph, "ST", sweepNo, chanType, channel)

if(!SFH_IsEmptyRange(range))
return range
endif

// data prior to 13b3499d (Add short names for Epochs stored in epoch name, 2021-09-06)
// try the long name instead
WAVE range = SFH_GetRangeFromEpoch(graph, "Stimset;", sweepNo, chanType, channel)

if(!SFH_IsEmptyRange(range))
return range
endif

// data prior to a2172f03 (Added generations of epoch information wave, 2019-05-22)
// remove total onset delay and termination delay iff we have neither dDAQ nor oodDAQ enabled
WAVE/Z numericalValues = BSP_GetLogbookWave(graph, LBT_LABNOTEBOOK, LBN_NUMERICAL_VALUES, sweepNumber = sweepNo)
ASSERT(WaveExists(numericalValues), "Missing numerical labnotebook")

// 778969b0 (DC_PlaceDataInITCDataWave: Document all other settings from the DAQ groupbox, 2015-11-26)
dDAQ = GetLastSettingIndep(numericalValues, sweepNo, "Distributed DAQ", DATA_ACQUISITION_MODE)
SFH_ASSERT(dDAQ != 1, "Can not gather stimset range with dDAQ data")

// d102c07d (Add new data acquisition mode: Optimized overlap distributed acquisition, 2016-08-10)
oodDAQ = GetLastSettingIndep(numericalValues, sweepNo, "Optimized Overlap dDAQ", DATA_ACQUISITION_MODE)
SFH_ASSERT(oodDAQ != 1, "Can not gather stimset range with oodDAQ data")

onsetDelay = GetTotalOnsetDelay(numericalValues, sweepNo)

// 778969b0 (DC_PlaceDataInITCDataWave: Document all other settings from the DAQ groupbox, 2015-11-26)
terminationDelay = GetLastSettingIndep(numericalValues, sweepNo, "Delay termination", DATA_ACQUISITION_MODE)

lengthInMS = DimDelta(data, ROWS) * DimSize(data, ROWS)

WAVE range = SFH_GetEmptyRange()

range[0] = onsetDelay
range[1] = lengthInMS - onsetDelay - terminationDelay

ASSERT(range[0] < range[1], "Invalid range")

return range
End
2 changes: 2 additions & 0 deletions Packages/MIES/MIES_SweepFormula_PSX.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,7 @@ static Function PSX_OperationSweepGathering(string graph, WAVE/WAVE psxKernelDat
WAVE sweepData = psxKernelDataset[%$key]

[WAVE selectData, WAVE range] = SFH_ParseToSelectDataWaveAndRange(sweepData)
ASSERT(WaveExists(selectData) && WaveExists(range), "Could not recreate select/range wave")
comboKey = PSX_GenerateComboKey(graph, selectData, range)

psxParametersAnalyzePeaks = PSX_GetPSXParameters(parameterJSONID, PSX_CACHE_KEY_ANALYZE_PEAKS)
Expand Down Expand Up @@ -756,6 +757,7 @@ static Function PSX_OperationImpl(string graph, variable parameterJSONID, string
endif

[WAVE selectData, WAVE range] = SFH_ParseToSelectDataWaveAndRange(sweepData)
ASSERT(WaveExists(selectData) && WaveExists(range), "Could not recreate select/range wave")
comboKey = PSX_GenerateComboKey(graph, selectData, range)

psxParametersEvents = PSX_GetPSXParameters(parameterJSONID, PSX_CACHE_KEY_EVENTS)
Expand Down