Skip to content

Commit

Permalink
Merge pull request #2209 from AllenInstitute/bugfix/2209-preparation-…
Browse files Browse the repository at this point in the history
…for-out-of-range-dascale

Various preparations for detecting out of range DAScale values
  • Loading branch information
t-b authored Aug 6, 2024
2 parents 1a0233d + 4de305c commit 6ca0326
Show file tree
Hide file tree
Showing 13 changed files with 155 additions and 91 deletions.
20 changes: 17 additions & 3 deletions Packages/MIES/MIES_AmplifierInteraction.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -948,13 +948,27 @@ Function AI_GetMode(device, headstage)
return MCC_GetMode()
End

/// @brief Return the DA/AD gains and the current clampmode of the selected amplifier
/// @brief Return the DA/AD gains of the given headstage
///
/// Gain is returned in mV/V for #V_CLAMP_MODE and V/mV for #I_CLAMP_MODE/#I_EQUAL_ZERO_MODE
/// Internally we query the External Command Sensitivity of the Amplifier (MCC) GUI.
///
/// =========== ==========================
/// ClampMode MultiClampCommander GUI
/// =========== ==========================
/// VC Off
/// 20 mV/V
/// 100 mV/V
/// =========== ==========================
/// IC Off
/// 400 pA/V
/// 2 nA/V
/// =========== ==========================
///
/// Gain is returned in mV/V for #V_CLAMP_MODE and pA/V for #I_CLAMP_MODE/#I_EQUAL_ZERO_MODE
///
/// @param device device
/// @param headstage headstage [0, NUM_HEADSTAGES[
/// @param[out] clampMode clamp mode (expected)
/// @param clampMode clamp mode
/// @param[out] ADGain ADC gain
/// @param[out] DAGain DAC gain
static Function AI_RetrieveGains(device, headstage, clampMode, ADGain, DAGain)
Expand Down
32 changes: 19 additions & 13 deletions Packages/MIES/MIES_AnalysisFunctionHelpers.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -218,23 +218,29 @@ End

/// @brief Return the stimset for the given channel
///
/// @param device device
/// @param chanNo channel number (0-based)
/// @param channelType one of the type constants from @ref ChannelTypeAndControlConstants
/// @param device device
/// @param chanNo channel number (0-based)
/// @param channelType one of the type constants from @ref ChannelTypeAndControlConstants
///
/// @return an existing stimulus set name for a DA channel
Function/S AFH_GetStimSetName(device, chanNo, channelType)
string device
variable chanNo
variable channelType
Function/S AFH_GetStimSetName(string device, variable chanNo, variable channelType)

string ctrl

ctrl = GetSpecialControlLabel(channelType, CHANNEL_CONTROL_WAVE)

return DAG_GetTextualValue(device, ctrl, index = chanNo)
End

/// @brief Convenience wrapper for AFH_GetStimSetName
Function/S AFH_GetStimSetNameForHeadstage(string device, variable headstage)

string ctrl, stimset
ctrl = GetPanelControl(chanNo, channelType, CHANNEL_CONTROL_WAVE)
ControlInfo/W=$device $ctrl
stimset = S_Value
variable DAC

ASSERT(!isEmpty(stimset), "Empty stimset")
DAC = AFH_GetDACFromHeadstage(device, headstage)
ASSERT(IsFinite(DAC), "Can't work with unassociated channels")

return stimset
return AFH_GetStimSetName(device, DAC, CHANNEL_TYPE_DAC)
End

/// @brief Return a free wave with all sweep numbers (in ascending order) which
Expand Down
6 changes: 2 additions & 4 deletions Packages/MIES/MIES_AnalysisFunctionManagement.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ Function AFM_UpdateAnalysisFunctionWave(device)
string device

variable i, j, DAC
string ctrl, setName, possibleFunctions, func
string setName, possibleFunctions, func

WAVE statusHS = DAG_GetChannelState(device, CHANNEL_TYPE_HEADSTAGE)
WAVE/T analysisFunctions = GetAnalysisFunctionStorage(device)
Expand All @@ -235,9 +235,7 @@ Function AFM_UpdateAnalysisFunctionWave(device)
continue
endif

ctrl = GetPanelControl(DAC, CHANNEL_TYPE_DAC, CHANNEL_CONTROL_WAVE)
// deliberately not using the GUI state wave
setName = GetPopupMenuString(device, ctrl)
setName = AFH_GetStimSetNameForHeadstage(device, i)

WAVE/Z stimSet = WB_CreateAndGetStimSet(setName)

Expand Down
2 changes: 1 addition & 1 deletion Packages/MIES/MIES_AnalysisFunctions.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,7 @@ Function SetDAScale(device, headstage, [absolute, relative, offset, roundTopA])
endif

DAC = AFH_GetDACFromHeadstage(device, headstage)
ASSERT(IsFinite(DAC), "This analysis function does not work with unassociated DA channels")
ASSERT(IsFinite(DAC), "Does not work with unassociated DA channels")

DAUnit = DAG_GetTextualValue(device, GetSpecialControlLabel(CHANNEL_TYPE_DAC, CHANNEL_CONTROL_UNIT), index = DAC)

Expand Down
21 changes: 9 additions & 12 deletions Packages/MIES/MIES_AnalysisFunctions_PatchSeq.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -1950,12 +1950,10 @@ End

static Function [variable start, variable stop] PSQ_DS_GetFrequencyEvalRangeForRhSuAd(string device, variable headstage, variable sweepNo)

variable DAC, supraEpochLength, adaptiveEpochLength
string ctrl, setName
variable supraEpochLength, adaptiveEpochLength
string setName

DAC = AFH_GetDACFromHeadstage(device, headstage)
ctrl = GetSpecialControlLabel(CHANNEL_TYPE_DAC, CHANNEL_CONTROL_WAVE)
setName = DAG_GetTextualValue(device, ctrl, index = DAC)
setName = AFH_GetStimSetNameForHeadstage(device, headstage)

WAVE numericalValues = GetLBNumericalValues(device)
WAVE textualValues = GetLBTextualValues(device)
Expand Down Expand Up @@ -7017,11 +7015,10 @@ static Function PSQ_GetSweepFormulaResult(WAVE/T textualResultsValues, string ke
End

static Function PSQ_PB_GetPrePulseBaselineDuration(string device, variable headstage)
variable DAC
string setName

DAC = AFH_GetDACFromHeadstage(device, headstage)
setName = DAG_GetTextualValue(device, GetSpecialControlLabel(CHANNEL_TYPE_DAC, CHANNEL_CONTROL_WAVE), index = DAC)
string setName

setName = AFH_GetStimSetNameForHeadstage(device, headstage)

return ST_GetStimsetParameterAsVariable(setName, "Duration", epochIndex = 0)
End
Expand All @@ -7037,7 +7034,7 @@ static Function PSQ_CreateTestpulseEpochs(string device, variable headstage, var
string setName

DAC = AFH_GetDACFromHeadstage(device, headstage)
setName = DAG_GetTextualValue(device, GetSpecialControlLabel(CHANNEL_TYPE_DAC, CHANNEL_CONTROL_WAVE), index = DAC)
setName = AFH_GetStimSetName(device, DAC, CHANNEL_TYPE_DAC)
totalOnsetDelay = GetTotalOnsetDelayFromDevice(device)
DAScale = DAG_GetNumericalValue(device, GetSpecialControlLabel(CHANNEL_TYPE_DAC, CHANNEL_CONTROL_SCALE), index = DAC)
WAVE/T epochWave = GetEpochsWave(device)
Expand Down Expand Up @@ -7537,8 +7534,7 @@ static Function PSQ_SE_CreateEpochs(string device, variable headstage, string pa
variable amplitude, numEpochs, i, epBegin, epEnd, totalOnsetDelay, duration, DAScale, wbBegin, wbEnd
string setName, shortName, tags

DAC = AFH_GetDACFromHeadstage(device, headstage)
setName = DAG_GetTextualValue(device, GetSpecialControlLabel(CHANNEL_TYPE_DAC, CHANNEL_CONTROL_WAVE), index = DAC)
setName = AFH_GetStimSetNameForHeadstage(device, headstage)

numEpochs = ST_GetStimsetParameterAsVariable(setName, "Total number of epochs")

Expand All @@ -7550,6 +7546,7 @@ static Function PSQ_SE_CreateEpochs(string device, variable headstage, string pa

testpulseGroupSel = PSQ_SE_GetTestpulseGroupSelection(params)

DAC = AFH_GetDACFromHeadstage(device, headstage)
DAScale = DAG_GetNumericalValue(device, GetSpecialControlLabel(CHANNEL_TYPE_DAC, CHANNEL_CONTROL_SCALE), index = DAC)

totalOnsetDelay = GetTotalOnsetDelayFromDevice(device)
Expand Down
4 changes: 4 additions & 0 deletions Packages/MIES/MIES_Constants.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -1029,6 +1029,8 @@ Constant NI_DAC_MIN = -10
Constant NI_DAC_MAX = 10
Constant NI_ADC_MIN = -10
Constant NI_ADC_MAX = 10
Constant NI_TTL_MIN = 0
Constant NI_TTL_MAX = 1
/// @}

/// @name Ranges for Sutter DAQ analog output in volts
Expand All @@ -1045,6 +1047,8 @@ Constant SU_ADC_MIN = -10 // V
Constant SU_ADC_MAX = 10 // V
Constant SU_HS_OUT_MIN = -1 // V
Constant SU_HS_OUT_MAX = 1 // V
Constant SU_TTL_MIN = 0 // V
Constant SU_TTL_MAX = 1 // V
/// @}

/// Maximum length of a valid object name in bytes in Igor Pro >= 8
Expand Down
42 changes: 42 additions & 0 deletions Packages/MIES/MIES_DAC-Hardware.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -863,6 +863,48 @@ Function HW_GetDAFifoPosition(string device, variable dataAcqOrTP)
endswitch
End

/// @brief Return the minimum/maximum voltage ranges for the given hardware and channel type
///
/// @param hardwareType One of @ref HardwareDACTypeConstants
/// @param channelType One of @ref XopChannelConstants
/// @param isAssociated For Sutter hardware the voltage range differs for associated channels or unassociated ones
Function [variable minimum, variable maximum] HW_GetVoltageRange(variable hardwareType, variable channelType, variable isAssociated)

switch(hardwareType)
case HARDWARE_NI_DAC:
switch(channelType)
case XOP_CHANNEL_TYPE_DAC:
return [NI_DAC_MIN, NI_DAC_MAX]
case XOP_CHANNEL_TYPE_ADC:
return [NI_ADC_MIN, NI_ADC_MAX]
case XOP_CHANNEL_TYPE_TTL:
return [NI_TTL_MIN, NI_TTL_MAX]
default:
ASSERT(0, "Not implemented")
endswitch
case HARDWARE_ITC_DAC:
return [SIGNED_INT_16BIT_MIN, SIGNED_INT_16BIT_MAX]
case HARDWARE_SUTTER_DAC:
if(isAssociated)
ASSERT(channelType != XOP_CHANNEL_TYPE_TTL, "Associated must be 0 for TTL")
return [SU_HS_OUT_MIN, SU_HS_OUT_MAX]
endif

switch(channelType)
case XOP_CHANNEL_TYPE_DAC:
return [SU_DAC_MIN, SU_DAC_MAX]
case XOP_CHANNEL_TYPE_ADC:
return [SU_ADC_MIN, SU_ADC_MAX]
case XOP_CHANNEL_TYPE_TTL:
return [SU_TTL_MIN, SU_TTL_MAX]
default:
ASSERT(0, "Not implemented")
endswitch
default:
ASSERT(0, "Unsupported hardware type")
endswitch
End

/// @}

/// @name ITC
Expand Down
2 changes: 1 addition & 1 deletion Packages/MIES/MIES_DAEphys.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -2868,7 +2868,7 @@ static Function DAP_CheckStimset(device, channelType, channel, headstage)

channelTypeStr = ChannelTypeToString(channelType)

setName = DAG_GetTextualValue(device, GetSpecialControlLabel(channelType, CHANNEL_CONTROL_WAVE), index = channel)
setName = AFH_GetStimSetName(device, channel, channelType)
if(!CmpStr(setName, NONE))
printf "(%s) Please select a stimulus set for %s channel %d referenced by headstage %g\r", device, channelTypeStr, channel, headStage
ControlWindowToFront()
Expand Down
Loading

0 comments on commit 6ca0326

Please sign in to comment.