Skip to content

Commit

Permalink
Merge pull request #1990 from AllenInstitute/feature/1990-make_epochs…
Browse files Browse the repository at this point in the history
…_samplepoint_exact

Make epochs sample point exact
  • Loading branch information
t-b authored Mar 22, 2024
2 parents b84e6e3 + 56e908b commit ad735dd
Show file tree
Hide file tree
Showing 24 changed files with 41,209 additions and 498 deletions.
6 changes: 3 additions & 3 deletions Packages/MIES/MIES_BrowserSettingsPanel.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -1686,14 +1686,14 @@ Function BSP_AddTracesForEpochs(string win)

numEpochs = DimSize(epochs, ROWS)

Make/FREE/N=(BSP_EPOCH_LEVELS) currentLevel, indexInLevel
Make/FREE/D/N=(BSP_EPOCH_LEVELS) currentLevel, indexInLevel

sprintf levels_x_name, "levels_x_%s", idpart
Make/O/N=(numEpochs * 3, 5, 2) dfr:$levels_x_name/WAVE=levels_x
Make/O/D/N=(numEpochs * 3, 5, 2) dfr:$levels_x_name/WAVE=levels_x
levels_x = NaN

sprintf levels_y_name, "levels_y_%s", idPart
Make/O/N=(numEpochs * 3, 5, 2) dfr:$levels_y_name/WAVE=levels_y
Make/O/D/N=(numEpochs * 3, 5, 2) dfr:$levels_y_name/WAVE=levels_y
levels_y = NaN
SetStringInWaveNote(levels_y, "EpochInfo", GetWavesDataFolder(epochs, 2))

Expand Down
9 changes: 7 additions & 2 deletions Packages/MIES/MIES_Constants.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Constant WAVEBUILDER_PANEL_VERSION = 14
Constant ANALYSISBROWSER_PANEL_VERSION = 3

/// Version of the stimset wave note
Constant STIMSET_NOTE_VERSION = 9
Constant STIMSET_NOTE_VERSION = 10

/// Version of the epoch information for DA+TTL data
Constant SWEEP_EPOCH_VERSION = 9
Expand Down Expand Up @@ -55,7 +55,7 @@ Constant PSQ_SEAL_EVALUATION_VERSION = 3
Constant PSQ_TRUE_REST_VM_VERSION = 2
Constant MSQ_FAST_RHEO_EST_VERSION = 1
Constant MSQ_DA_SCALE_VERSION = 1
Constant SC_SPIKE_CONTROL_VERSION = 1
Constant SC_SPIKE_CONTROL_VERSION = 2
/// @}

/// Especially interesting for PXP consumers like the analysis browser.
Expand Down Expand Up @@ -970,6 +970,11 @@ StrConstant EPOCHS_ENTRY_KEY = "Epochs"
StrConstant CLAMPMODE_ENTRY_KEY = "Clamp Mode"
StrConstant TP_AMPLITUDE_VC_ENTRY_KEY = "TP Amplitude VC"
StrConstant TP_AMPLITUDE_IC_ENTRY_KEY = "TP Amplitude IC"
StrConstant PULSE_START_INDICES_KEY = "Pulse Train Pulse Start Indices"
StrConstant PULSE_END_INDICES_KEY = "Pulse Train Pulse End Indices"
StrConstant INFLECTION_POINTS_INDEX_KEY = "Inflection Points Indices"
StrConstant EPOCH_LENGTH_INDEX_KEY = "Epoch Length Indices"
StrConstant STIMSET_SIZE_KEY = "Stimset Size"

/// DA_Ephys controls which should be disabled during DAQ
StrConstant CONTROLS_DISABLE_DURING_DAQ = "Check_DataAcqHS_All;Radio_ClampMode_AllIClamp;Radio_ClampMode_AllVClamp;Radio_ClampMode_AllIZero;SetVar_Sweep;Check_DataAcq_Indexing;check_DataAcq_IndexRandom;Check_DataAcq1_IndexingLocked;check_DataAcq_RepAcqRandom;Check_DataAcq1_RepeatAcq;Check_Settings_SkipAnalysFuncs;check_Settings_MD"
Expand Down
28 changes: 20 additions & 8 deletions Packages/MIES/MIES_DataConfigurator.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,7 @@ End
/// @param stimSet stimset wave
/// @param device device
/// @param dataAcqOrTP one of #DATA_ACQUISITION_MODE or #TEST_PULSE_MODE
static Function DC_CalculateStimsetLength(stimSet, device, dataAcqOrTP)
Function DC_CalculateStimsetLength(stimSet, device, dataAcqOrTP)
WAVE stimSet
string device
variable dataAcqOrTP
Expand All @@ -891,14 +891,16 @@ static Function DC_CalculateGeneratedDataSize(device, dataAcqOrTP, genLength)
string device
variable dataAcqOrTP, genLength

variable decimationFactor = DC_GetDecimationFactor(device, dataAcqOrTP)

// note: the decimationFactor is the factor between the hardware sample rate and the sample rate of the generated waveform in singleStimSet
// The ratio of the source to target wave sizes is however limited by the integer size of both waves
// While ideally srcLength == tgtLength the floor(...) limits the real data wave length such that
// when decimationFactor * index of real data wave is applied as index of the generated data wave it never exceeds its size
// Also if decimationFactor >= 2 the last point of the generated data wave is never transferred
// e.g. generated data with 10 points and decimationFactor == 2 copies index 0, 2, 4, 6, 8 to the real data wave of size 5
if(dataAcqOrTP == DATA_ACQUISITION_MODE)
return floor(genLength / DC_GetDecimationFactor(device, dataAcqOrTP))
return floor(genLength / decimationFactor) + IndexAfterDecimation(0, decimationFactor)
elseif(dataAcqOrTP == TEST_PULSE_MODE)
return genLength
else
Expand All @@ -920,11 +922,14 @@ static Function DC_PlaceDataInDAQDataWave(device, numActiveChannels, dataAcqOrTP

variable ret, row, column

WAVE/T epochWave = GetEpochsWave(device)

STRUCT DataConfigurationResult s
[s] = DC_GetConfiguration(device, numActiveChannels, dataAcqOrTP, multiDevice)

NVAR stopCollectionPoint = $GetStopCollectionPoint(device)
stopCollectionPoint = DC_GetStopCollectionPoint(device, s)
s.stopCollectionPoint = stopCollectionPoint

AssertOnAndClearRTError()

Expand All @@ -934,7 +939,7 @@ static Function DC_PlaceDataInDAQDataWave(device, numActiveChannels, dataAcqOrTP
DC_FillDAQDataWaveForDAQ(device, s)
endif

EP_CollectEpochInfo(device, s)
EP_CollectEpochInfo(epochWave, s)
DC_PrepareLBNEntries(device, s)

if(dataAcqOrTP == DATA_ACQUISITION_MODE)
Expand Down Expand Up @@ -994,7 +999,7 @@ static Function DC_WriteTTLIntoDAQDataWave(string device, STRUCT DataConfigurati
singleSetLength = DC_CalculateStimsetLength(TTLWaveSingle, device, DATA_ACQUISITION_MODE)
WAVE NIChannel = NIDataWave[i + ttlOffset]
MultiThread NIChannel[startOffset, startOffset + singleSetLength - 1] = \
limit(TTLWaveSingle[trunc(s.decimationFactor * (p - startOffset))], 0, 1); AbortOnRTE
limit(TTLWaveSingle[round(s.decimationFactor * (p - startOffset))], 0, 1); AbortOnRTE
endfor
break
case HARDWARE_ITC_DAC:
Expand All @@ -1007,12 +1012,12 @@ static Function DC_WriteTTLIntoDAQDataWave(string device, STRUCT DataConfigurati
bitMask = 1 << NUM_ITC_TTL_BITS_PER_RACK - 1
if(ITCRackZeroChecked)
MultiThread ITCDataWave[startOffset, startOffset + singleSetLength - 1][ttlOffset] = \
limit(TTLWaveITC[trunc(s.decimationFactor * (p - startOffset))] & bitMask, SIGNED_INT_16BIT_MIN, SIGNED_INT_16BIT_MAX); AbortOnRTE
limit(TTLWaveITC[round(s.decimationFactor * (p - startOffset))] & bitMask, SIGNED_INT_16BIT_MIN, SIGNED_INT_16BIT_MAX); AbortOnRTE
endif

if(DC_AreTTLsInRackChecked(device, RACK_ONE))
MultiThread ITCDataWave[startOffset, startOffset + singleSetLength - 1][ttlOffset + ITCRackZeroChecked] = \
limit(TTLWaveITC[trunc(s.decimationFactor * (p - startOffset))] >> NUM_ITC_TTL_BITS_PER_RACK & bitMask, SIGNED_INT_16BIT_MIN, SIGNED_INT_16BIT_MAX); AbortOnRTE
limit(TTLWaveITC[round(s.decimationFactor * (p - startOffset))] >> NUM_ITC_TTL_BITS_PER_RACK & bitMask, SIGNED_INT_16BIT_MIN, SIGNED_INT_16BIT_MAX); AbortOnRTE
endif
break
endswitch
Expand Down Expand Up @@ -1430,6 +1435,7 @@ static Function [STRUCT DataConfigurationResult s] DC_GetConfiguration(string de
variable channel, headstage, channelMode
variable scalingZero, indexingLocked, indexing
variable i, j, ret, setCycleCountLocal
variable testPulseLength, tpPulseStartPoint, tpPulseLengthPoints
string ctrl

// pass parameters into returned struct
Expand Down Expand Up @@ -1484,8 +1490,11 @@ static Function [STRUCT DataConfigurationResult s] DC_GetConfiguration(string de

WAVE s.testPulse = GetTestPulse()

// test pulse length is calculated for dataAcqOrTP
s.testPulseLength = DimSize(s.testPulse, ROWS)
// test pulse length is calculated for dataAcqOrTP @ref TP_CreateTestPulseWave
[testPulseLength, tpPulseStartPoint, tpPulseLengthPoints] = TP_GetCreationPropertiesInPoints(device, dataAcqOrTP)
s.testPulseLength = testPulseLength
s.tpPulseStartPoint = tpPulseStartPoint
s.tpPulseLengthPoints = tpPulseLengthPoints

s.headstageDAC[] = channelClampMode[s.DACList[p]][%DAC][%Headstage]
s.headstageADC[] = channelClampMode[s.ADCList[p]][%ADC][%Headstage]
Expand Down Expand Up @@ -1671,6 +1680,7 @@ static Function DC_SetupConfigurationTTLstimSets(string device, STRUCT DataConfi

WAVE/T allSetNames = DAG_GetChannelTextual(device, CHANNEL_TYPE_TTL, CHANNEL_CONTROL_WAVE)
WAVE statusTTLFiltered = DC_GetFilteredChannelState(device, s.dataAcqOrTP, CHANNEL_TYPE_TTL)
WAVE s.statusTTLFiltered = statusTTLFiltered

for(i = 0; i < NUM_DA_TTL_CHANNELS; i += 1)
if(!statusTTLFiltered[i])
Expand Down Expand Up @@ -1997,6 +2007,7 @@ static Function DC_ITC_MakeTTLWave(string device, STRUCT DataConfigurationResult
endfor
endif
endfor
s.joinedTTLStimsetSize = DC_CalculateStimsetLength(TTLWave, device, DATA_ACQUISITION_MODE)
End

static Function DC_NI_MakeTTLWave(string device, STRUCT DataConfigurationResult &s)
Expand Down Expand Up @@ -2027,6 +2038,7 @@ static Function DC_NI_MakeTTLWave(string device, STRUCT DataConfigurationResult
MultiThread TTLWaveSingle[] = TTLStimSet[p][s.TTLsetColumn[i]]
TTLWave[i] = TTLWaveSingle
endfor
s.joinedTTLStimsetSize = NaN

DC_DocumentChannelProperty(device, "Stim set length", INDEP_HEADSTAGE, NaN, XOP_CHANNEL_TYPE_TTL, str=TextWaveToList(setLength, ";"))
DC_DocumentChannelProperty(device, "channels", INDEP_HEADSTAGE, NaN, XOP_CHANNEL_TYPE_TTL, str=TextWaveToList(channels, ";"))
Expand Down
Loading

0 comments on commit ad735dd

Please sign in to comment.