Skip to content

Commit

Permalink
NWB_AppendSweepLowLevel: Fix exporting TTL epoch information for ITC …
Browse files Browse the repository at this point in the history
…hardware

Since 2637e08 (Add channel types support to EpochsWave as chunk index,
2023-07-07) we have support for exporting epoch information of TTL
channels into NWBv2.

Unfortunately that commit failed to realize that we have to export TTL
information per ttlBit for ITC hardware. As the tests were also wrong,
this was found until now with the ITC1600 tests.
  • Loading branch information
t-b committed Oct 9, 2023
1 parent 8f6dfb7 commit 5204b4d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
14 changes: 8 additions & 6 deletions Packages/MIES/MIES_NeuroDataWithoutBorders.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -1170,8 +1170,6 @@ threadsafe static Function NWB_AppendSweepLowLevel(STRUCT NWBAsyncParameters &s)
col = AFH_GetDAQDataColumn(s.DAQConfigWave, params.channelNumber, params.channelType)
writtenDataColumns[col] = 1

WAVE/T/Z params.epochs = EP_FetchEpochs(s.numericalValues, s.textualValues, s.sweep, params.channelNumber, params.channelType)

WAVE data = ExtractOneDimDataFromSweep(s.DAQConfigWave, s.DAQDataWave, col)

if(hardwareType == HARDWARE_ITC_DAC)
Expand All @@ -1190,13 +1188,17 @@ threadsafe static Function NWB_AppendSweepLowLevel(STRUCT NWBAsyncParameters &s)
params.channelSuffixDesc = NWB_SOURCE_TTL_BIT
params.stimset = ttlStimsets[log(ttlBit)/log(2)]
NWB_GetTimeSeriesProperties(s.nwbVersion, s.numericalKeys, s.numericalValues, params, tsp)
params.groupIndex = IsFinite(params.groupIndex) ? params.groupIndex : GetNextFreeGroupIndex(s.locationID, path)
params.groupIndex = IsFinite(params.groupIndex) ? params.groupIndex : GetNextFreeGroupIndex(s.locationID, path)
WAVE/T/Z params.epochs = EP_FetchEpochs(s.numericalValues, s.textualValues, s.sweep, log(ttlBit)/log(2), params.channelType)

s.locationID = WriteSingleChannel(s.locationID, path, s.nwbVersion, params, tsp, compressionMode = s.compressionMode, nwbFilePath = s.nwbFilePath)
endfor
elseif(hardwareType == HARDWARE_NI_DAC)
WAVE params.data = data
path = "/stimulus/presentation"
params.stimset = stimset
WAVE params.data = data
path = "/stimulus/presentation"
params.stimset = stimset
WAVE/T/Z params.epochs = EP_FetchEpochs(s.numericalValues, s.textualValues, s.sweep, params.channelNumber, params.channelType)

NWB_GetTimeSeriesProperties(s.nwbVersion, s.numericalKeys, s.numericalValues, params, tsp)
params.groupIndex = IsFinite(params.groupIndex) ? params.groupIndex : GetNextFreeGroupIndex(s.locationID, path)
s.locationID = WriteSingleChannel(s.locationID, path, s.nwbVersion, params, tsp, compressionMode = s.compressionMode, nwbFilePath = s.nwbFilePath)
Expand Down
19 changes: 17 additions & 2 deletions Packages/tests/UTF_TestNWBExportV2.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ static Function TestTimeSeries(fileID, filepath, device, groupID, channel, sweep
DFREF pxpSweepsDFR
WAVE/Z epochs

variable channelGroupID, starting_time, session_start_time, actual, idx, index
variable channelGroupID, starting_time, session_start_time, actual, idx, index, channelNumber, ttlBit
variable clampMode, gain, gain_ref, resolution, conversion, headstage, rate_ref, rate, samplingInterval, samplingInterval_ref
string stimulus, stimulus_expected, channelName, str, path, neurodata_type
string electrode_name, electrode_name_ref, key, unit_ref, unit, base_unit_ref
Expand Down Expand Up @@ -536,8 +536,23 @@ static Function TestTimeSeries(fileID, filepath, device, groupID, channel, sweep
WAVE/T/Z epochsSingleChannel = WaveRef(epochs, row=idx)
CHECK_WAVE(epochsSingleChannel, TEXT_WAVE)

WAVE/Z epochsLBN = EP_FetchEpochs(numericalValues, textualValues, sweep, params.channelNumber, params.channelType)
channelNumber = params.channelNumber
ttlBit = NaN

if(params.channelType == XOP_CHANNEL_TYPE_TTL)
WAVE/Z channelMapHWToGUI = GetActiveChannels(numericalValues, textualValues, sweep, params.channelType, TTLMode = TTL_HWTOGUI_CHANNEL)
CHECK_WAVE(channelMapHWToGUI, NUMERIC_WAVE)

ttlBit = log(params.ttlBit)/log(2)
CHECK_GE_VAR(ttlBit, 0)

channelNumber = channelMapHWToGUI[params.channelNumber][ttlBit]
CHECK_GE_VAR(channelNumber, 0)
endif

WAVE/Z epochsLBN = EP_FetchEpochs(numericalValues, textualValues, sweep, channelNumber, params.channelType)
CHECK_WAVE(epochsLBN, TEXT_WAVE)
INFO("Channeltype: %s, GUI channel number %d, hardware channel number %d, TTL bit %d", s0 = StringFromList(params.channelType, CHANNEL_NAMES), n0 = channelNumber, n1 = params.channelNumber, n2 = ttlBit)
CHECK_EQUAL_TEXTWAVES(epochsLBN, epochsSingleChannel)
endif
End
Expand Down

0 comments on commit 5204b4d

Please sign in to comment.