Skip to content

Commit

Permalink
changes
Browse files Browse the repository at this point in the history
  • Loading branch information
t-b committed Aug 6, 2024
1 parent c198491 commit f745847
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 32 deletions.
6 changes: 5 additions & 1 deletion Packages/MIES/MIES_AnalysisFunctions.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -1310,19 +1310,23 @@ Function ComplainOutOfRangeDAScale(string device, variable sweepNo, variable ana
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:
case INVALID_ANALYSIS_FUNCTION: // ReachTargetVoltage
// do nothing
break
default:
Expand Down
9 changes: 5 additions & 4 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 @@ -1216,7 +1216,8 @@ Function MSQ_DAScale(device, s)
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)
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] = Sum(DAScaleOOR) == 0
Expand Down Expand Up @@ -1269,11 +1270,11 @@ Function MSQ_DAScale(device, s)

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

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

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

if(limitsCheck && retCheckDAScale)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,22 +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)

// TODO
key = CreateAnaFuncLBNKey(SC_SPIKE_CONTROL, PSQ_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)

return V_Value == -1
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 @@ -789,7 +791,7 @@ static Function SC_ReactToQCFailures(string device, variable sweepNo, string par
endif

if(retCheckDAScale)
ComplainOutOfRangeDAScale(device, s.sweepNo, PSQ_RAMP)
ComplainOutOfRangeDAScale(device, s.sweepNo, SC_SPIKE_CONTROL)
endif
End

Expand Down
69 changes: 49 additions & 20 deletions Packages/MIES/MIES_AnalysisFunctions_PatchSeq.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -2911,6 +2911,13 @@ static Function PSQ_DS_AdaptiveIsFinished(string device, variable sweepNo, varia
endif
endif

key = CreateAnaFuncLBNKey(PSQ_DA_SCALE, PSQ_FMT_LBN_DASCALE_OOR, query = 1)
WAVE/Z DAScaleOOR = GetLastSetting(numericalValues, sweepNo, key, UNKNOWN_MODE)

if(WaveExists(DAScaleOOR) && DAScaleOOR[headstage])
return 1
endif

[WAVE sweepPassed, emptySCI] = PSQ_DS_GetLabnotebookData(device, sweepNo, headstage, PSQ_DS_SWEEP_PASS, fromRhSuAd = fromRhSuAd)

if(DimSize(sweepPassed, ROWS) < numSweepsWithSaturation)
Expand Down Expand Up @@ -3677,7 +3684,7 @@ Function PSQ_DAScale(device, s)
variable sweepPassed, setPassed, length, minLength, reachedFinalSlope, fitOffset, fitSlope, apfreq, enoughFIPointsPassedQC
variable minimumSpikeCount, maximumSpikeCount, daScaleModifierParam, measuredAllFutureDAScales, fallbackDAScaleRangeFac
variable sweepsInSet, passesInSet, acquiredSweepsInSet, multiplier, asyncAlarmPassed, supraStimsetCycle
variable daScaleStepMinNorm, daScaleStepMaxNorm, maxSlope, validFit
variable daScaleStepMinNorm, daScaleStepMaxNorm
string msg, stimset, key, opMode, offsetOp, textboxString, str, errMsg
variable daScaleOffset
variable finalSlopePercent = NaN
Expand Down Expand Up @@ -4183,22 +4190,26 @@ Function PSQ_DAScale(device, s)

enoughSweepsPassed = PSQ_NumPassesInSet(numericalValues, PSQ_DA_SCALE, s.sweepNo, s.headstage) >= numSweepsPass

key = CreateAnaFuncLBNKey(PSQ_DA_SCALE, PSQ_FMT_LBN_DASCALE_OOR, query = 1)
WAVE/Z DAScaleOOR = GetLastSetting(numericalValues, s.sweepNo, key, UNKNOWN_MODE)
DAScaleOORQC = !WaveExists(DAScaleOOR)

strswitch(opMode)
case PSQ_DS_SUB:
setPassed = enoughSweepsPassed
setPassed = enoughSweepsPassed && DAScaleOORQC
break
case PSQ_DS_SUPRA:
if(IsFinite(finalSlopePercent))
key = CreateAnaFuncLBNKey(PSQ_DA_SCALE, PSQ_FMT_LBN_DA_fI_SLOPE_REACHED_PASS, query = 1)
WAVE fISlopeReached = GetLastSettingIndepEachSCI(numericalValues, s.sweepNo, key, s.headstage, UNKNOWN_MODE)
ASSERT(WaveExists(fISlopeReached), "Missing fiSlopeReached LBN entry")

setPassed = enoughSweepsPassed && Sum(fISlopeReached) > 0
setPassed = enoughSweepsPassed && Sum(fISlopeReached) > 0 && DAScaleOORQC
else
sprintf msg, "Final slope percentage not present\r"
DEBUGPRINT(msg)

setPassed = enoughSweepsPassed
setPassed = enoughSweepsPassed && DAScaleOORQC
endif
break
case PSQ_DS_ADAPT:
Expand Down Expand Up @@ -4265,7 +4276,16 @@ Function PSQ_DAScale(device, s)
ASSERT(0, "Invalid case")
break
endswitch
SetDAScale(device, i, s.sweepNo, absolute = DAScale * PICO_TO_ONE)

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

retCheckDAScale = SetDAScale(device, i, s.sweepNo, absolute = DAScale * PICO_TO_ONE, limitCheck = limitCheck)

if(limitCheck && retCheckDAScale)
ComplainOutOfRangeDAScale(device, s.sweepNo, MSQ_DA_SCALE)
break
endif
endif
endfor
endif
Expand Down Expand Up @@ -4363,7 +4383,7 @@ Function PSQ_SquarePulse(device, s)
STRUCT AnalysisFunction_V3 &s

variable stepsize, DAScale, totalOnsetDelay, setPassed, sweepPassed, multiplier
variable val, samplingFrequencyPassed, asyncAlarmPassed, ret
variable val, samplingFrequencyPassed, asyncAlarmPassed, ret, retCheckDAScale
string key, msg

multiplier = AFH_GetAnalysisParamNumerical("SamplingMultiplier", s.params)
Expand Down Expand Up @@ -4407,7 +4427,7 @@ Function PSQ_SquarePulse(device, s)
PGC_SetAndActivateControl(device, "check_Settings_ITITP", val = 0)

PSQ_StoreStepSizeInLBN(device, PSQ_SQUARE_PULSE, s.sweepNo, PSQ_SP_INIT_AMP_p100)
SetDAScale(device, s.headstage, s.sweepNo, absolute = PSQ_SP_INIT_AMP_p100)
SetDAScale(device, s.headstage, s.sweepNo, absolute = PSQ_SP_INIT_AMP_p100, limitCheck = 0)

return 0

Expand Down Expand Up @@ -4460,7 +4480,7 @@ Function PSQ_SquarePulse(device, s)
RA_SkipSweeps(device, Inf, SWEEP_SKIP_AUTO, limitToSetBorder = 1)
endif
elseif(CheckIfClose(stepSize, PSQ_SP_INIT_AMP_m50))
SetDAScale(device, s.headstage, s.sweepNo, absolute = DAScale + stepsize)
retCheckDAScale = SetDAScale(device, s.headstage, s.sweepNo, absolute = DAScale + stepsize)
elseif(CheckIfClose(stepSize, PSQ_SP_INIT_AMP_p10))
WAVE value = LBN_GetNumericWave()
value[INDEP_HEADSTAGE] = DAScale
Expand All @@ -4475,8 +4495,8 @@ Function PSQ_SquarePulse(device, s)
endif
elseif(CheckIfClose(stepSize, PSQ_SP_INIT_AMP_p100))
PSQ_StoreStepSizeInLBN(device, PSQ_SQUARE_PULSE, s.sweepNo, PSQ_SP_INIT_AMP_m50)
stepsize = PSQ_SP_INIT_AMP_m50
SetDAScale(device, s.headstage, s.sweepNo, absolute = DAScale + stepsize)
stepsize = PSQ_SP_INIT_AMP_m50
retCheckDAScale = SetDAScale(device, s.headstage, s.sweepNo, absolute = DAScale + stepsize)
else
ASSERT(0, "Unknown stepsize")
endif
Expand All @@ -4492,7 +4512,12 @@ Function PSQ_SquarePulse(device, s)
ASSERT(0, "Unknown stepsize")
endif

SetDAScale(device, s.headstage, s.sweepNo, absolute = DAScale + stepsize)
retCheckDAScale = SetDAScale(device, s.headstage, s.sweepNo, absolute = DAScale + stepsize)
endif

if(retCheckDAScale)
ComplainOutOfRangeDAScale(device, s.sweepNo, PSQ_RAMP)
sweepPassed = 0
endif

sprintf msg, "Sweep has %s\r", ToPassFail(sweepPassed)
Expand Down Expand Up @@ -4626,7 +4651,7 @@ Function PSQ_Rheobase(device, s)

variable DAScale, val, numSweeps, currentSweepHasSpike, lastSweepHasSpike, setPassed, diff
variable baselineQCPassed, finalDAScale, initialDAScale, stepSize, previousStepSize, samplingFrequencyPassed
variable totalOnsetDelay, asyncAlarmPassed
variable totalOnsetDelay, asyncAlarmPassed, retCheckDAScale
variable i, ret, numSweepsWithSpikeDetection, sweepNoFound, length, minLength, multiplier, chunk
string key, msg

Expand Down Expand Up @@ -4702,7 +4727,7 @@ Function PSQ_Rheobase(device, s)
endif
endif

SetDAScale(device, s.headstage, s.sweepNo, absolute = finalDAScale)
SetDAScale(device, s.headstage, s.sweepNo, absolute = finalDAScale, limitCheck = 0)

return 0

Expand Down Expand Up @@ -4891,7 +4916,16 @@ Function PSQ_Rheobase(device, s)
break
endif

SetDAScale(device, s.headstage, s.sweepNo, absolute = DAScale)
retCheckDAScale = SetDAScale(device, s.headstage, s.sweepNo, absolute = DAScale)

if(retCheckDAScale)
ComplainOutOfRangeDAScale(device, s.sweepNo, PSQ_RHEOBASE)

WAVE result = LBN_GetNumericWave()
key = CreateAnaFuncLBNKey(PSQ_RHEOBASE, PSQ_FMT_LBN_SET_PASS)
result[INDEP_HEADSTAGE] = 0
ED_AddEntryToLabnotebook(device, key, result, unit = LABNOTEBOOK_BINARY_UNIT)
endif
break
case POST_SET_EVENT:
WAVE numericalValues = GetLBNumericalValues(device)
Expand Down Expand Up @@ -5143,12 +5177,7 @@ Function PSQ_Ramp(device, s)
PGC_SetAndActivateControl(device, "check_Settings_ITITP", val = 1)
PGC_SetAndActivateControl(device, "Check_Settings_InsertTP", val = 1)

retCheckDAScale = SetDAScale(device, s.headstage, s.sweepNo, absolute = PSQ_RA_DASCALE_DEFAULT * PICO_TO_ONE)

if(retCheckDAScale)
ComplainOutOfRangeDAScale(device, s.sweepNo, PSQ_RAMP)
return 1
endif
SetDAScale(device, s.headstage, s.sweepNo, absolute = PSQ_RA_DASCALE_DEFAULT * PICO_TO_ONE, limitCheck = 0)

return 0

Expand Down
2 changes: 1 addition & 1 deletion Packages/MIES/MIES_Constants.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -1419,7 +1419,7 @@ StrConstant MSQ_FMT_LBN_SPIKE_COUNTS_STATE = "%s Spike counts state"
StrConstant MSQ_FMT_LBN_IDEAL_SPIKE_COUNTS = "%s Ideal spike counts"
StrConstant MSQ_FMT_LBN_RERUN_TRIAL = "%s Rerun Trials"
StrConstant MSQ_FMT_LBN_RERUN_TRIAL_EXC = "%s Rerun Trials exceeded"
StrConstant PSQ_FMT_LBN_DASCALE_OOR = "%s DAScale out of range"
StrConstant MSQ_FMT_LBN_DASCALE_OOR = "%s DAScale out of range"
/// @}

/// @name Workaround flags for CreateAnaFuncLBNKey()
Expand Down

0 comments on commit f745847

Please sign in to comment.