Skip to content

Commit

Permalink
Generalize PSQ_TestOverrideActive and MSQ_TestOverrideActive
Browse files Browse the repository at this point in the history
For testing Auto TP we want to also use the override results wave
approach. Therefore it makes sense to have one function which does that
instead of creating yet another identical one.
  • Loading branch information
t-b committed Nov 13, 2021
1 parent ec4576b commit 627725e
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 60 deletions.
30 changes: 6 additions & 24 deletions Packages/MIES/MIES_AnalysisFunctions_MultiPatchSeq.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ static Function MSQ_EvaluateBaselineProperties(panelTitle, scaledDACWave, type,
chunkPassed = rmsShortPassedAll && rmsLongPassedAll && targetVPassedAll

// BEGIN TEST
if(MSQ_TestOverrideActive())
if(TestOverrideActive())
WAVE overrideResults = GetOverrideResults()
NVAR count = $GetCount(panelTitle)
chunkPassed = overrideResults[chunk][count][0]
Expand All @@ -399,7 +399,7 @@ static Function MSQ_EvaluateBaselineProperties(panelTitle, scaledDACWave, type,
key = CreateAnaFuncLBNKey(type, MSQ_FMT_LBN_CHUNK_PASS, chunk = chunk)
ED_AddEntryToLabnotebook(panelTitle, key, result, unit = LABNOTEBOOK_BINARY_UNIT, overrideSweepNo = sweepNo)

if(MSQ_TestOverrideActive())
if(TestOverrideActive())
if(baselineType == MSQ_BL_PRE_PULSE)
if(!chunkPassed)
return ANALYSIS_FUNC_RET_EARLY_STOP
Expand Down Expand Up @@ -688,7 +688,7 @@ static Function/WAVE MSQ_SearchForSpikes(panelTitle, type, sweepWave, headstage,
WAVE singleAD = AFH_ExtractOneDimDataFromSweep(panelTitle, sweepWave, headstage, XOP_CHANNEL_TYPE_ADC, config = config)
ASSERT(!cmpstr(WaveUnits(singleAD, -1), "mV"), "Unexpected AD Unit")

if(MSQ_TestOverrideActive())
if(TestOverrideActive())
WAVE overrideResults = GetOverrideResults()
NVAR count = $GetCount(panelTitle)

Expand Down Expand Up @@ -748,24 +748,6 @@ static Function/WAVE MSQ_SearchForSpikes(panelTitle, type, sweepWave, headstage,
return DEBUGPRINTw(spikeDetection)
End

/// @brief Return if the analysis function results are overriden for testing purposes
Function MSQ_TestOverrideActive()
variable numberOfOverrideWarnings

WAVE/Z overrideResults = GetOverrideResults()

if(WaveExists(overrideResults))
numberOfOverrideWarnings = GetNumberFromWaveNote(overrideResults, "OverrideWarningIssued")
if(IsNaN(numberOfOverrideWarnings))
print "TEST OVERRIDE ACTIVE"
SetNumberInWaveNote(overrideResults, "OverrideWarningIssued", 1)
endif
return 1
endif

return 0
End

/// @brief Return true if one of the entries is true for the given headstage. False otherwise.
/// Searches in the complete SCI and assumes that the entries are either 0/1/NaN.
///
Expand Down Expand Up @@ -1270,7 +1252,7 @@ static Function/WAVE MSQ_DS_GetDAScaleOffset(panelTitle, headstage)

Make/D/FREE/N=(LABNOTEBOOK_LAYER_COUNT) values = NaN

if(MSQ_TestOverrideActive())
if(TestOverrideActive())
values[] = MSQ_DS_OFFSETSCALE_FAKE
return values
endif
Expand Down Expand Up @@ -1303,7 +1285,7 @@ static Function MSQ_GetLastPassingLongRHSweep(panelTitle, headstage)
string key
variable i, numEntries, sweepNo, sweepCol

if(MSQ_TestOverrideActive())
if(TestOverrideActive())
return MSQ_DS_SWEEP_FAKE
endif

Expand Down Expand Up @@ -1460,7 +1442,7 @@ Function MSQ_DAScale(panelTitle, s)

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

if(MSQ_TestOverrideActive())
if(TestOverrideActive())
headstagePassed = 1
else
headstagePassed = MSQ_GetLBNEntryForHSSCIBool(numericalValues, sweepNo, MSQ_DA_SCALE, MSQ_FMT_LBN_HEADSTAGE_PASS, i)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ static Function [WAVE/T spikeNumbersLBN, WAVE/T spikePositionsLBN] SC_GetSpikeNu

WAVE noteWave = propertiesWaves[idx][PA_PROPERTIESWAVES_INDEX_PULSENOTE]

if(MSQ_TestOverrideActive())
if(TestOverrideActive())
WAVE/T overrideResults = GetOverrideResults()
entry = overrideResults[sweepNoProp][headstageProp][pulseIndex][region]
WAVE spikePositions = ListToNumericWave(StringByKey("SpikePosition_ms", entry), ",")
Expand Down Expand Up @@ -609,7 +609,7 @@ static Function/WAVE SC_SpontaneousSpikingCheckQC(string panelTitle, variable sw
SC_RegionBlanked(singleAD, totalOnsetDelay, oodDAQRegion)

// check that the max of the data is below failedPulseLevel
if(MSQ_TestOverrideActive())
if(TestOverrideActive())
WAVE/T overrideResults = GetOverrideResults()

entry = overrideResults[sweepNo][i][0][0]
Expand Down
45 changes: 13 additions & 32 deletions Packages/MIES/MIES_AnalysisFunctions_PatchSeq.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ static Function PSQ_EvaluateBaselineProperties(string panelTitle, STRUCT Analysi
targetV = DAG_GetNumericalValue(panelTitle, "setvar_DataAcq_AutoBiasV")

// BEGIN TEST
if(PSQ_TestOverrideActive())
if(TestOverrideActive())
WAVE overrideResults = GetOverrideResults()
NVAR count = $GetCount(panelTitle)
chunkPassedTestOverride = overrideResults[chunk][count][0]
Expand Down Expand Up @@ -453,7 +453,7 @@ static Function PSQ_EvaluateBaselineProperties(string panelTitle, STRUCT Analysi
// check 1: RMS of the last 1.5ms of the baseline should be below 0.07mV
rmsShort[i] = PSQ_Calculate(s.scaledDACWave, ADCol, evalStartTime, evalRangeTime, PSQ_CALC_METHOD_RMS)

if(PSQ_TestOverrideActive())
if(TestOverrideActive())
rmsShortPassed[i] = chunkPassedTestOverride
else
rmsShortPassed[i] = rmsShort[i] < rmsShortThreshold
Expand All @@ -479,7 +479,7 @@ static Function PSQ_EvaluateBaselineProperties(string panelTitle, STRUCT Analysi
// check 2: RMS of the last 500ms of the baseline should be below 0.50mV
rmsLong[i] = PSQ_Calculate(s.scaledDACWave, ADCol, evalStartTime, evalRangeTime, PSQ_CALC_METHOD_RMS)

if(PSQ_TestOverrideActive())
if(TestOverrideActive())
rmsLongPassed[i] = chunkPassedTestOverride
else
rmsLongPassed[i] = rmsLong[i] < rmsLongThreshold
Expand All @@ -505,7 +505,7 @@ static Function PSQ_EvaluateBaselineProperties(string panelTitle, STRUCT Analysi
// check 3: Average voltage within 1mV of auto bias target voltage
avgVoltage[i] = PSQ_Calculate(s.scaledDACWave, ADCol, evalStartTime, evalRangeTime, PSQ_CALC_METHOD_AVG)

if(PSQ_TestOverrideActive())
if(TestOverrideActive())
targetVPassed[i] = chunkPassedTestOverride
else
targetVPassed[i] = abs(avgVoltage[i] - targetV) <= PSQ_TARGETV_THRESHOLD
Expand Down Expand Up @@ -947,7 +947,7 @@ static Function/WAVE PSQ_SearchForSpikes(panelTitle, type, sweepWave, headstage,
endif
endif

if(PSQ_TestOverrideActive())
if(TestOverrideActive())
WAVE overrideResults = GetOverrideResults()
NVAR count = $GetCount(panelTitle)

Expand Down Expand Up @@ -1059,25 +1059,6 @@ static Function/WAVE PSQ_SearchForSpikes(panelTitle, type, sweepWave, headstage,
return DEBUGPRINTw(spikeDetection)
End

/// @brief Return if the analysis function results are overriden for testing purposes
static Function PSQ_TestOverrideActive()

variable numberOfOverrideWarnings

WAVE/Z/SDFR=root: overrideResults

if(WaveExists(overrideResults))
numberOfOverrideWarnings = GetNumberFromWaveNote(overrideResults, "OverrideWarningIssued")
if(IsNaN(numberOfOverrideWarnings))
print "TEST OVERRIDE ACTIVE"
SetNumberInWaveNote(overrideResults, "OverrideWarningIssued", 1)
endif
return 1
endif

return 0
End

/// @brief Return a sweep number of an existing sweep matching the following conditions
///
/// - Acquired with Rheobase analysis function
Expand Down Expand Up @@ -1195,7 +1176,7 @@ Function PSQ_DS_GetDAScaleOffset(panelTitle, headstage, opMode)
variable sweepNo

if(!cmpstr(opMode, PSQ_DS_SUPRA))
if(PSQ_TestOverrideActive())
if(TestOverrideActive())
return PSQ_DS_OFFSETSCALE_FAKE
endif

Expand Down Expand Up @@ -2336,7 +2317,7 @@ Function PSQ_Rheobase(panelTitle, s)

if(!IsFinite(finalDAScale) || CheckIfSmall(finalDAScale, tol = 1e-14) || !IsValidSweepNumber(sweepNoFound))
printf "(%s): Could not find final DAScale value from one of the previous analysis functions.\r", panelTitle
if(PSQ_TestOverrideActive())
if(TestOverrideActive())
finalDASCale = PSQ_GetFinalDAScaleFake()
else
ControlWindowToFront()
Expand All @@ -2359,7 +2340,7 @@ Function PSQ_Rheobase(panelTitle, s)
// query the initial DA scale from the previous sweep (which is from a different RAC)
key = CreateAnaFuncLBNKey(PSQ_SQUARE_PULSE, PSQ_FMT_LBN_FINAL_SCALE, query = 1)
finalDAScale = GetLastSweepWithSettingIndep(numericalValues, key, sweepNoFound)
if(PSQ_TestOverrideActive())
if(TestOverrideActive())
finalDAScale = PSQ_GetFinalDAScaleFake()
else
ASSERT(IsFinite(finalDAScale) && IsValidSweepNumber(sweepNoFound), "Could not find final DAScale value from previous analysis function")
Expand Down Expand Up @@ -2595,7 +2576,7 @@ Function PSQ_GetFinalDAScaleFake()

variable daScale

ASSERT(PSQ_TestOverrideActive(), "Should not be called in production.")
ASSERT(TestOverrideActive(), "Should not be called in production.")

WAVE overrideResults = GetOverrideResults()
ASSERT(WaveExists(overrideResults), "overrideResults wave must exist")
Expand Down Expand Up @@ -2892,7 +2873,7 @@ Function PSQ_Ramp(panelTitle, s)
totalOnsetDelay, PSQ_SPIKE_LEVEL, spikePositions = spikePos, numberOfSpikesReq = numberOfSpikes)

if(spikeDetection[s.headstage] \
&& ((PSQ_TestOverrideActive() && (fifoInStimsetTime > WaveMax(spikePos))) || !PSQ_TestOverrideActive()))
&& ((TestOverrideActive() && (fifoInStimsetTime > WaveMax(spikePos))) || !TestOverrideActive()))

enoughSpikesFound = 1

Expand Down Expand Up @@ -3183,7 +3164,7 @@ static Function [variable boundsAction, variable scalingFactorDAScale] PSQ_CR_De

[lowerValue, upperValue] = WaveMinAndMaxWrapper(singleAD, x1 = chirpStart, x2 = cycleEnd)

if(PSQ_TestOverrideActive())
if(TestOverrideActive())
WAVE/SDFR=root: overrideResults
NVAR count = $GetCount(panelTitle)
upperValueOverride = overrideResults[0][count][1]
Expand All @@ -3200,7 +3181,7 @@ static Function [variable boundsAction, variable scalingFactorDAScale] PSQ_CR_De
totalOnsetDelay = DAG_GetNumericalValue(panelTitle, "setvar_DataAcq_OnsetDelayUser") \
+ GetValDisplayAsNum(panelTitle, "valdisp_DataAcq_OnsetDelayAuto")

if(PSQ_TestOverrideActive())
if(TestOverrideActive())
baselineVoltage = PSQ_CR_BASELINE_V_FAKE
else
key = CreateAnaFuncLBNKey(PSQ_CHIRP, PSQ_FMT_LBN_TARGETV, chunk = 0, query = 1)
Expand Down Expand Up @@ -3621,7 +3602,7 @@ Function PSQ_Chirp(panelTitle, s)
key = CreateAnaFuncLBNKey(PSQ_CHIRP, PSQ_FMT_LBN_CR_SPIKE_CHECK)
ED_AddEntryToLabnotebook(panelTitle, key, values, overrideSweepNo = s.sweepNo, unit = LABNOTEBOOK_BINARY_UNIT)

if(PSQ_TestOverrideActive())
if(TestOverrideActive())
resistance = PSQ_CR_RESISTANCE_FAKE * 1e9
else
passingDaScaleSweep = PSQ_GetLastPassingDAScaleSub(panelTitle, s.headstage)
Expand Down
19 changes: 19 additions & 0 deletions Packages/MIES/MIES_MiesUtilities.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -7464,3 +7464,22 @@ static Function AddToSweepWave(WAVE/WAVE channelWaves, Wave channelNumbers, WAVE
Concatenate {wv}, sweepWave
endfor
End

/// @brief Return if the function results are overriden for testing purposes
Function TestOverrideActive()
variable numberOfOverrideWarnings

WAVE/Z overrideResults = GetOverrideResults()

if(WaveExists(overrideResults))
numberOfOverrideWarnings = GetNumberFromWaveNote(overrideResults, "OverrideWarningIssued")
if(IsNaN(numberOfOverrideWarnings))
print "TEST OVERRIDE ACTIVE"
SetNumberInWaveNote(overrideResults, "OverrideWarningIssued", 1)
endif

return 1
endif

return 0
End
5 changes: 3 additions & 2 deletions Packages/MIES/MIES_WaveDataFolderGetters.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -6577,8 +6577,9 @@ End

/// @brief Return the wave used for storing mock data for the analysis function tests
///
/// This wave is created by MSQ_CreateOverrideResults() or PSQ_CreateOverrideResults() and does also not
/// folow our usual rules so it might not exist.
/// This wave is created by MSQ_CreateOverrideResults(),
/// PSQ_CreateOverrideResults() or TP_CreateOverrideResults() and does also not
/// follow our usual rules so it might not exist.
Function/WAVE GetOverrideResults()

WAVE/Z/SDFR=root: overrideResults
Expand Down

0 comments on commit 627725e

Please sign in to comment.