diff --git a/Packages/MIES/MIES_AnalysisBrowser.ipf b/Packages/MIES/MIES_AnalysisBrowser.ipf index d7c50d32a9..1e2db96cff 100644 --- a/Packages/MIES/MIES_AnalysisBrowser.ipf +++ b/Packages/MIES/MIES_AnalysisBrowser.ipf @@ -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 diff --git a/Packages/MIES/MIES_NeuroDataWithoutBorders.ipf b/Packages/MIES/MIES_NeuroDataWithoutBorders.ipf index 522d851943..7451787fef 100644 --- a/Packages/MIES/MIES_NeuroDataWithoutBorders.ipf +++ b/Packages/MIES/MIES_NeuroDataWithoutBorders.ipf @@ -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 @@ -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 diff --git a/Packages/tests/UTF_TestNWBExportV1.ipf b/Packages/tests/UTF_TestNWBExportV1.ipf index 413c99cc3d..f4b382ffe7 100644 --- a/Packages/tests/UTF_TestNWBExportV1.ipf +++ b/Packages/tests/UTF_TestNWBExportV1.ipf @@ -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) @@ -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] diff --git a/Packages/tests/UTF_TestNWBExportV2.ipf b/Packages/tests/UTF_TestNWBExportV2.ipf index a70adf7f48..7ad7cd999f 100644 --- a/Packages/tests/UTF_TestNWBExportV2.ipf +++ b/Packages/tests/UTF_TestNWBExportV2.ipf @@ -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) @@ -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]