Skip to content

Commit

Permalink
changes
Browse files Browse the repository at this point in the history
  • Loading branch information
t-b committed Oct 18, 2024
1 parent a87be2f commit a707209
Show file tree
Hide file tree
Showing 5 changed files with 155 additions and 53 deletions.
38 changes: 31 additions & 7 deletions Packages/MIES/MIES_AnalysisFunctions.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -1249,9 +1249,9 @@ Function ReachTargetVoltage(string device, STRUCT AnalysisFunction_V3 &s)
DEBUGPRINT(msg)

retCheckDAScale = SetDAScale(device, i, s.sweepNo, absolute = amps)
CheckSetDAScaleReturn(device, retCheckDAScale)

if(retCheckDAScale)
ComplainOutOfRangeDAScale(device, s.sweepNo, INVALID_ANALYSIS_FUNCTION)
break
endif
endfor
Expand Down Expand Up @@ -1294,21 +1294,45 @@ Function ReachTargetVoltage(string device, STRUCT AnalysisFunction_V3 &s)
endswitch
End

Function CheckSetDAScaleReturn(string device, variable retValue)
Function ComplainOutOfRangeDAScale(string device, variable sweepNo, variable anaFuncType)

variable i
string key

if(!retValue)
return NaN
endif

ASSERT(GetHardwareType(device) != HARDWARE_SUTTER_DAC, "Missing support for Sutter amplififer")
ASSERT(GetHardwareType(device) != HARDWARE_SUTTER_DAC, "Missing support for Sutter amplifier")

printf "(%s) The DAScale value could not be set as it is out-of-range.\r", GetRTStackInfo(2)
printf "Please adjust the \"External Command Sensitivity\" in the MultiClamp Commander application and try again.\r"
ControlWindowToFront()

WAVE statusHS = DAG_GetChannelState(device, CHANNEL_TYPE_HEADSTAGE)

switch(anaFuncType)
case PSQ_CHIRP:
case PSQ_RAMP:
case PSQ_DA_SCALE:
case PSQ_SQUARE_PULSE:
case PSQ_RHEOBASE:
WAVE result = LBN_GetNumericWave()
result[0, NUM_HEADSTAGES - 1] = (statusHS[p] == 1)
key = CreateAnaFuncLBNKey(anaFuncType, PSQ_FMT_LBN_DASCALE_OOR)
ED_AddEntryToLabnotebook(device, key, result, overrideSweepNo = sweepNo, unit = LABNOTEBOOK_BINARY_UNIT)
break
case MSQ_FAST_RHEO_EST:
case MSQ_DA_SCALE:
case SC_SPIKE_CONTROL:
WAVE result = LBN_GetNumericWave()
result[0, NUM_HEADSTAGES - 1] = (statusHS[p] == 1)
key = CreateAnaFuncLBNKey(anaFuncType, MSQ_FMT_LBN_DASCALE_OOR)
ED_AddEntryToLabnotebook(device, key, result, overrideSweepNo = sweepNo, unit = LABNOTEBOOK_BINARY_UNIT)
break
case INVALID_ANALYSIS_FUNCTION: // ReachTargetVoltage
// do nothing
break
default:
ASSERT(0, "Unknown analysis function")
endswitch

for(i = 0; i < NUM_HEADSTAGES; i += 1)

if(!statusHS[i])
Expand Down
59 changes: 41 additions & 18 deletions Packages/MIES/MIES_AnalysisFunctions_MultiPatchSeq.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ End
/// Searches in the complete SCI and assumes that the entries are either 0/1/NaN.
///
/// @todo merge with LBN functions once these are reworked.
static Function MSQ_GetLBNEntryForHSSCIBool(numericalValues, sweepNo, type, str, headstage)
Function MSQ_GetLBNEntryForHSSCIBool(numericalValues, sweepNo, type, str, headstage)
WAVE numericalValues
variable sweepNo, type
string str
Expand Down Expand Up @@ -600,7 +600,7 @@ Function MSQ_FastRheoEst(device, s)
string device
STRUCT AnalysisFunction_V3 &s

variable totalOnsetDelay, setPassed, sweepPassed, multiplier, newDAScaleValue, found, val
variable totalOnsetDelay, setPassed, sweepPassed, multiplier, newDAScaleValue, found, val, retCheckDAScale
variable i, postDAQDAScale, postDAQDAScaleFactor, DAC, maxDAScale, allHeadstagesExceeded, minRheoOffset
string key, msg, ctrl
string stimsets = ""
Expand Down Expand Up @@ -663,7 +663,7 @@ Function MSQ_FastRheoEst(device, s)
continue
endif

SetDAScale(device, i, s.sweepNo, absolute = MSQ_FRE_INIT_AMP_p100)
SetDAScale(device, i, s.sweepNo, absolute = MSQ_FRE_INIT_AMP_p100, limitCheck = 0)
endfor

PGC_SetAndActivateControl(device, "Check_DataAcq1_DistribDaq", val = 0)
Expand Down Expand Up @@ -789,7 +789,12 @@ Function MSQ_FastRheoEst(device, s)
ASSERT(headstagePassed[i] != 1, "Unexpected headstage passing")
headstagePassed[i] = 0
else
SetDAScale(device, i, s.sweepNo, absolute = newDAScaleValue)
retCheckDAScale = SetDAScale(device, i, s.sweepNo, absolute = newDAScaleValue)

if(retCheckDAScale)
ComplainOutOfRangeDAScale(device, s.sweepNo, INVALID_ANALYSIS_FUNCTION)
break
endif
endif
endfor

Expand Down Expand Up @@ -855,16 +860,6 @@ Function MSQ_FastRheoEst(device, s)
PGC_SetAndActivateControl(device, "Check_Settings_InsertTP", val = 1)

WAVE numericalValues = GetLBNumericalValues(device)
// assuming that all headstages have the same sweeps in their SCI
setPassed = MSQ_NumPassesInSet(numericalValues, MSQ_FAST_RHEO_EST, s.sweepNo, s.headstage) >= 1

sprintf msg, "Set has %s\r", ToPassFail(setPassed)
DEBUGPRINT(msg)

WAVE result = LBN_GetNumericWave()
result[INDEP_HEADSTAGE] = setPassed
key = CreateAnaFuncLBNKey(MSQ_FAST_RHEO_EST, MSQ_FMT_LBN_SET_PASS)
ED_AddEntryToLabnotebook(device, key, result, unit = LABNOTEBOOK_BINARY_UNIT)

postDAQDAScale = AFH_GetAnalysisParamNumerical("PostDAQDAScale", s.params)

Expand All @@ -891,10 +886,26 @@ Function MSQ_FastRheoEst(device, s)
val = AFH_GetAnalysisParamNumerical("PostDAQDAScaleForFailedHS", s.params) * PICO_TO_ONE
endif

SetDAScale(device, i, s.sweepNo, absolute = val)
retCheckDAScale = SetDAScale(device, i, s.sweepNo, absolute = val)

if(retCheckDAScale)
ComplainOutOfRangeDAScale(device, s.sweepNo, INVALID_ANALYSIS_FUNCTION)
break
endif
endfor
endif

// assuming that all headstages have the same sweeps in their SCI
setPassed = !retCheckDAScale && (MSQ_NumPassesInSet(numericalValues, MSQ_FAST_RHEO_EST, s.sweepNo, s.headstage) >= 1)

sprintf msg, "Set has %s\r", ToPassFail(setPassed)
DEBUGPRINT(msg)

WAVE result = LBN_GetNumericWave()
result[INDEP_HEADSTAGE] = setPassed
key = CreateAnaFuncLBNKey(MSQ_FAST_RHEO_EST, MSQ_FMT_LBN_SET_PASS)
ED_AddEntryToLabnotebook(device, key, result, unit = LABNOTEBOOK_BINARY_UNIT)

WAVE statusHS = DAG_GetChannelState(device, CHANNEL_TYPE_HEADSTAGE)

key = CreateAnaFuncLBNKey(MSQ_FAST_RHEO_EST, MSQ_FMT_LBN_ACTIVE_HS, query = 1)
Expand Down Expand Up @@ -1096,7 +1107,7 @@ Function MSQ_DAScale(device, s)
string device
STRUCT AnalysisFunction_V3 &s

variable i, index, ret, headstagePassed, val, sweepNo
variable i, index, ret, headstagePassed, val, sweepNo, limitCheck, retCheckDAScale
string msg, key, ctrl

switch(s.eventType)
Expand Down Expand Up @@ -1204,8 +1215,12 @@ Function MSQ_DAScale(device, s)
return NaN
endif

key = CreateAnaFuncLBNKey(MSQ_DA_SCALE, MSQ_FMT_LBN_DASCALE_OOR, query = 1)
Make/N=(NUM_HEADSTAGES)/FREE DAScaleOOR = MSQ_GetLBNEntryForHSSCIBool(numericalValues, s.sweepNo, \
MSQ_FAST_RHEO_EST, MSQ_FMT_LBN_DASCALE_OOR, p)

WAVE values = LBN_GetNumericWave()
values[INDEP_HEADSTAGE] = 1
values[INDEP_HEADSTAGE] = Sum(DAScaleOOR) == 0
key = CreateAnaFuncLBNKey(MSQ_DA_SCALE, MSQ_FMT_LBN_SET_PASS)
ED_AddEntryToLabnotebook(device, key, values, unit = LABNOTEBOOK_BINARY_UNIT)

Expand Down Expand Up @@ -1255,9 +1270,17 @@ Function MSQ_DAScale(device, s)

index = mod(DAScalesIndex[i], DimSize(DAScales, ROWS))

limitCheck = (s.eventType == POST_SWEEP_EVENT)
retCheckDAScale = 0

ASSERT(isFinite(daScaleOffset[i]), "DAScale offset is non-finite")
SetDAScale(device, i, s.sweepNo, absolute = (DAScales[index] + daScaleOffset[i]) * PICO_TO_ONE)
retCheckDAScale = SetDAScale(device, i, s.sweepNo, absolute = (DAScales[index] + daScaleOffset[i]) * PICO_TO_ONE, limitCheck = limitCheck)
DAScalesIndex[i] += 1

if(limitCheck && retCheckDAScale)
ComplainOutOfRangeDAScale(device, s.sweepNo, MSQ_DA_SCALE)
break
endif
endfor
endif
End
30 changes: 20 additions & 10 deletions Packages/MIES/MIES_AnalysisFunctions_MultiPatchSeq_SpikeControl.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -151,19 +151,24 @@ End

/// @brief Return pass/fail state of the sweep
///
/// This is true iff we have for the current stimulus set sweep count a passing headstage
/// This is true iff we have for the current stimulus set sweep count a passing
/// headstage and did not have a SetDAScale/SetDAScaleModOp out-of-range condition.
static Function SC_GetSweepPassed(string device, variable sweepNo)

variable setSweepCount
variable setSweepCount, setSweepQC

WAVE headstageQCTotalPerSweepCount = SC_GetHeadstageQCForSetCount(device, sweepNo)

WAVE numericalValues = GetLBNumericalValues(device)
setSweepCount = SC_GetSetSweepCount(numericalValues, sweepNo)

FindValue/RMD=[][setSweepCount]/V=(0.0) headstageQCTotalPerSweepCount
setSweepQC = (V_Value == -1)

return V_Value == -1
Make/N=(NUM_HEADSTAGES)/FREE DAScaleOOR = MSQ_GetLBNEntryForHSSCIBool(numericalValues, sweepNo, \
MSQ_FAST_RHEO_EST, MSQ_FMT_LBN_DASCALE_OOR, p)

return setSweepQC && Sum(DAScaleOOR) == 0
End

/// @brief Return 1 if we are currently acquiring the last sweep in the stimulus set, 0 otherwise
Expand Down Expand Up @@ -692,6 +697,7 @@ End
/// @brief Perform various actions on QC failures
static Function SC_ReactToQCFailures(string device, variable sweepNo, string params)
variable daScaleSpikePositionModifier, daScaleModifier, daScaleTooManySpikesModifier, i, autoBiasV, autobiasModifier, prevSliderPos
variable retCheckDAScale
string daScaleOperator, daScaleSpikePositionOperator, daScaleTooManySpikesOperator
string key, msg

Expand Down Expand Up @@ -731,7 +737,7 @@ static Function SC_ReactToQCFailures(string device, variable sweepNo, string par
if(!spikePositionsQCLBN[i])
sprintf msg, "spike position QC failed on HS%d, adapting DAScale", i
DebugPrint(msg)
SetDAScaleModOp(device, i, sweepNo, daScaleSpikePositionModifier, daScaleSpikePositionOperator)
retCheckDAScale = SetDAScaleModOp(device, i, sweepNo, daScaleSpikePositionModifier, daScaleSpikePositionOperator)
endif

continue
Expand All @@ -755,7 +761,7 @@ static Function SC_ReactToQCFailures(string device, variable sweepNo, string par

strswitch(spikeCountStateLBN[i])
case SC_SPIKE_COUNT_STATE_STR_TOO_MANY:
SetDAScaleModOp(device, i, sweepNo, daScaleTooManySpikesModifier, daScaleTooManySpikesOperator)
retCheckDAScale = SetDAScaleModOp(device, i, sweepNo, daScaleTooManySpikesModifier, daScaleTooManySpikesOperator)
break
case SC_SPIKE_COUNT_STATE_STR_MIXED:
printf "The spike count on headstage %d in sweep %d is mixed (some pulses have too few, others too many)\n", i, sweepNo
Expand All @@ -769,7 +775,7 @@ static Function SC_ReactToQCFailures(string device, variable sweepNo, string par
ControlWindowToFront()
endif
case SC_SPIKE_COUNT_STATE_STR_TOO_FEW: // fallthrough-by-design
SetDAScaleModOp(device, i, sweepNo, daScaleModifier, daScaleOperator)
retCheckDAScale = SetDAScaleModOp(device, i, sweepNo, daScaleModifier, daScaleOperator)
break
case SC_SPIKE_COUNT_STATE_STR_GOOD:
// nothing to do
Expand All @@ -783,6 +789,10 @@ static Function SC_ReactToQCFailures(string device, variable sweepNo, string par
if(prevSliderPos != GetSliderPositionIndex(device, "slider_DataAcq_ActiveHeadstage"))
PGC_SetAndActivateControl(device, "slider_DataAcq_ActiveHeadstage", val = prevSliderPos)
endif

if(retCheckDAScale)
ComplainOutOfRangeDAScale(device, sweepNo, SC_SPIKE_CONTROL)
endif
End

Function/S SC_SpikeControl_GetParams()
Expand Down Expand Up @@ -1101,6 +1111,10 @@ Function SC_SpikeControl(device, s)

SC_ProcessPulses(device, s.sweepNo, minimumSpikePosition, idealNumberOfSpikes)

[minTrials, maxTrials] = SC_GetTrials(device, s.sweepNo, s.headstage)

SC_ReactToQCFailures(device, s.sweepNo, s.params)

// sweep QC
sweepPassed = SC_GetSweepPassed(device, s.sweepNo)

Expand All @@ -1109,10 +1123,6 @@ Function SC_SpikeControl(device, s)
key = CreateAnaFuncLBNKey(SC_SPIKE_CONTROL, MSQ_FMT_LBN_SWEEP_PASS)
ED_AddEntryToLabnotebook(device, key, sweepQCLBN, unit = LABNOTEBOOK_BINARY_UNIT)

[minTrials, maxTrials] = SC_GetTrials(device, s.sweepNo, s.headstage)

SC_ReactToQCFailures(device, s.sweepNo, s.params)

if(!sweepPassed)
if(SC_CanStillSkip(maxTrials, s.params))
skippedBack = 1
Expand Down
Loading

0 comments on commit a707209

Please sign in to comment.