Skip to content

Commit

Permalink
MIES_NeuroDataWithoutBorders.ipf: Introduce functions for TTL channel…
Browse files Browse the repository at this point in the history
… suffix generation in NWB

Since 5f0f447 (NWB_AppendSweepLowLevel: Add support for TTL data from NI
hardware, 2018-09-12) we don't use the ttlBit as channelSuffix anymore but
2^ttlBit. It is unclear at this point why this was changed.

Introduce functions to convert between the two representations to avoid
even more confusion in the future.
  • Loading branch information
t-b committed Oct 24, 2023
1 parent 28b2a5f commit 611677f
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Packages/MIES/MIES_AnalysisBrowser.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -1994,7 +1994,7 @@ static Function AB_LoadSweepFromNWBgeneric(h5_groupID, nwbVersion, channelList,
base += loaded
endif

channelName += "_" + num2str(log(p.ttlBit)/log(2))
channelName += "_" + num2str(NWB_ConvertToStandardTTLBit(p.ttlBit))
else
// for non-ITC hardware we don't have multiple bits in one channel
// so we don't need to fake a base wave
Expand Down
22 changes: 21 additions & 1 deletion Packages/MIES/MIES_NeuroDataWithoutBorders.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -1162,7 +1162,7 @@ threadsafe static Function NWB_AppendSweepLowLevel(STRUCT NWBAsyncParameters &s)
params.stimset = stimset

if(IsFinite(guiToHWChannelMap[i][%TTLBITNR]))
params.channelSuffix = num2str(2^guiToHWChannelMap[i][%TTLBITNR])
params.channelSuffix = num2str(NWB_ConvertTTLBitToChannelSuffix(guiToHWChannelMap[i][%TTLBITNR]))
params.channelSuffixDesc = NWB_SOURCE_TTL_BIT
endif

Expand Down Expand Up @@ -1878,3 +1878,23 @@ static Function NWB_AppendIgorHistoryAndLogFile(nwbVersion, locationID)

HDF5CloseGroup/Z groupID
End

/// @brief Convert between `2^x`, this is what we store as channelSuffix for TTL data
/// in NWB, to `x` what we call TTL bit in MIES
threadsafe Function NWB_ConvertToStandardTTLBit(variable value)

variable bit

ASSERT_TS(IsInteger(value) && value > 0, "Expected positive integer value")

bit = FindRightMostHighBit(value)
ASSERT_TS(bit > 0 && bit < NUM_ITC_TTL_BITS_PER_RACK, "Invalid TTL bit")

return bit
End

/// @brief Reverse direction of NWB_ConvertToStandardTTLBit()
threadsafe Function NWB_ConvertTTLBitToChannelSuffix(variable value)

return 2^value
End
4 changes: 2 additions & 2 deletions Packages/tests/UTF_TestNWBExportV1.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ static Function/S GetChannelNameFromChannelType(groupID, device, channel, sweep,
channelName += "_" + num2str(params.channelNumber)

if(IsFinite(params.ttlBit))
channelName += "_" + num2str(log(params.ttlBit)/log(2))
channelName += "_" + num2str(NWB_ConvertToStandardTTLBit(params.ttlBit))
endif

CHECK_EQUAL_VAR(str2num(params.channelSuffix), params.ttlBit)
Expand Down Expand Up @@ -374,7 +374,7 @@ static Function TestTimeSeries(fileID, device, groupID, channel, sweep, pxpSweep
WAVE/Z channelMapHWToGUI = GetActiveChannels(numericalValues, textualValues, sweep, params.channelType, TTLMode = TTL_HWTOGUI_CHANNEL)
CHECK_WAVE(channelMapHWToGUI, NUMERIC_WAVE)

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

GUIchannelNumber = channelMapHWToGUI[params.channelNumber][ttlBit]
Expand Down
4 changes: 2 additions & 2 deletions Packages/tests/UTF_TestNWBExportV2.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ static Function/S GetChannelNameFromChannelType(groupID, device, channel, sweep,
channelName += "_" + num2str(params.channelNumber)

if(IsFinite(params.ttlBit))
channelName += "_" + num2str(log(params.ttlBit)/log(2))
channelName += "_" + num2str(NWB_ConvertToStandardTTLBit(params.ttlBit))
endif

CHECK_EQUAL_VAR(str2num(params.channelSuffix), params.ttlBit)
Expand Down Expand Up @@ -404,7 +404,7 @@ static Function TestTimeSeries(fileID, filepath, device, groupID, channel, sweep
WAVE/Z channelMapHWToGUI = GetActiveChannels(numericalValues, textualValues, sweep, params.channelType, TTLMode = TTL_HWTOGUI_CHANNEL)
CHECK_WAVE(channelMapHWToGUI, NUMERIC_WAVE)

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

GUIchannelNumber = channelMapHWToGUI[params.channelNumber][ttlBit]
Expand Down

0 comments on commit 611677f

Please sign in to comment.