Skip to content

Commit

Permalink
Merge pull request #2293 from AllenInstitute/bugfix/2293-set-da-scale…
Browse files Browse the repository at this point in the history
…-limits-prep

Preparations for detecting out of range SetDaScale
  • Loading branch information
t-b authored Nov 15, 2024
2 parents 2ba0d9f + 7bd2189 commit 74d6ef9
Show file tree
Hide file tree
Showing 11 changed files with 138 additions and 288 deletions.
27 changes: 20 additions & 7 deletions Packages/MIES/MIES_AnalysisFunctionHelpers.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,7 @@ Function/S AFH_GetAnalysisParameter(name, params, [expectedType])
string type, value

if(ParamIsDefault(expectedType))
type = AFH_GetAnalysisParamType(name, params)
type = AFH_GetAnalysisParamType(name, params, typeCheck = 0)
else
type = AFH_GetAnalysisParamType(name, params, expectedType = expectedType)
endif
Expand Down Expand Up @@ -1268,7 +1268,7 @@ End
/// 0 if not and NaN if it is not possible to determine
Function AFH_LastSweepInSet(string device, variable sweepNo, variable headstage, variable eventType)

variable DAC, sweepsInSet, setCount, skipCountExisting, sweepOffset
variable DAC, sweepsInSet, nextStimsetColumn, sweepOffset

switch(eventType)
case PRE_DAQ_EVENT:
Expand All @@ -1279,17 +1279,30 @@ Function AFH_LastSweepInSet(string device, variable sweepNo, variable headstage,
case MID_SWEEP_EVENT:
// we need to look at the last acquired sweep
sweepNo -= 1
sweepOffset = 2
sweepOffset = 1
break
default:
sweepOffset = 1
// do nothing
endswitch

DAC = AFH_GetDACFromHeadstage(device, headstage)
sweepsInSet = IDX_NumberOfSweepsInSet(AFH_GetStimSetName(device, DAC, CHANNEL_TYPE_DAC))

WAVE numericalValues = GetLBNumericalValues(device)
WAVE/Z sweepSetCount = GetLastSetting(numericalValues, sweepNo, "Set Sweep Count", DATA_ACQUISITION_MODE)
WAVE numericalValues = GetLBNumericalValues(device)

nextStimsetColumn = AFH_GetNextSweepSetCount(numericalValues, sweepNo, headstage)

return (nextStimsetColumn + sweepOffset) >= sweepsInSet
End

/// @brief Return the set count of the next sweep
///
/// No checking is done on the number of sweeps in the stimulus set
Function AFH_GetNextSweepSetCount(WAVE numericalValues, variable sweepNo, variable headstage)

variable setCount, skipCountExisting

WAVE/Z sweepSetCount = GetLastSetting(numericalValues, sweepNo, "Set Sweep Count", DATA_ACQUISITION_MODE)

if(!WaveExists(sweepSetCount))
setCount = 0
Expand All @@ -1299,5 +1312,5 @@ Function AFH_LastSweepInSet(string device, variable sweepNo, variable headstage,

skipCountExisting = GetLastSettingIndep(numericalValues, sweepNo, SKIP_SWEEPS_KEY, UNKNOWN_MODE, defValue = 0)

return (setCount + sweepOffset + skipCountExisting) >= sweepsInSet
return setCount + skipCountExisting + 1
End
2 changes: 1 addition & 1 deletion Packages/MIES/MIES_AnalysisFunctions.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
/// analysis parameters are validated if present. With Indexing ON,
/// only the analysis function of the first stimset will receive
/// that event.
/// Pre Sweep Config Before the sweep is configured None Write
/// Pre Set Before a new set starts None Write
/// Pre Sweep Config Before the sweep is configured None Write
/// Mid Sweep Each time when new data is polled Available for background DAQ only. Write
/// Will always be called at least once and
/// also with the full stimset acquired.
Expand Down
8 changes: 3 additions & 5 deletions Packages/MIES/MIES_PulseAveraging.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -2493,7 +2493,7 @@ End
threadsafe Function/WAVE PA_SpikePositionsForNonVC(WAVE wv, variable failedPulsesLevel)

variable numLevels, maxNumLevels, numSpikes
variable first, last, i, err, idx
variable first, last, i, idx

// allow at most 1 pulse per ms, but at least 1
maxNumLevels = max(1, round(DimSize(wv, ROWS) * DimDelta(wv, ROWS)) * 2)
Expand Down Expand Up @@ -2525,11 +2525,9 @@ threadsafe Function/WAVE PA_SpikePositionsForNonVC(WAVE wv, variable failedPulse
continue
endif

AssertOnAndClearRTError()
FindPeak/B=(PA_PEAK_BOX_AVERAGE)/M=(failedPulsesLevel)/R=(first, last)/Q wv; err = GetRTError(1) // see developer docu section Preventing Debugger Popup
FindPeak/B=(PA_PEAK_BOX_AVERAGE)/M=(failedPulsesLevel)/R=(first, last)/Q wv

if(!err)
ASSERT_TS(!V_Flag, "Could not find peak but FindLevelWrapper was successfull, this is unexpected.")
if(!V_Flag)
spikePositions[idx++] = V_PeakLoc
endif
endfor
Expand Down
65 changes: 36 additions & 29 deletions Packages/doc/svg/analysis-functions-calls-during-RA-stages.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
44 changes: 44 additions & 0 deletions Packages/tests/Basic/UTF_AnalysisFunctionParameters.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -1023,3 +1023,47 @@ Function GAPasT_Works([WAVE/T wv])
CHECK_EQUAL_STR(result, wv[1])
End
/// @}

/// @name AFH_GetAnalysisParameter
/// @{
static Function GAP_Works()

string result
string params = "var:variable=123,str:string=456"

result = AFH_GetAnalysisParameter("var", params)
CHECK_EQUAL_STR(result, "123")

result = AFH_GetAnalysisParameter("str", params, expectedType = "string")
CHECK_EQUAL_STR(result, "456")

// wrong type
try
AFH_GetAnalysisParameter("var1", params, expectedType = "string")
FAIL()
catch
CHECK_NO_RTE()
endtry

// invalid type
try
AFH_GetAnalysisParameter("var1", params, expectedType = "abcd")
FAIL()
catch
CHECK_NO_RTE()
endtry

// non-existent parameter but type was given
try
AFH_GetAnalysisParameter("I_DONT_EXIST", params, expectedType = "variable")
FAIL()
catch
CHECK_NO_RTE()
endtry

// empty return without type
result = AFH_GetAnalysisParameter("I_DONT_EXIST", params)
CHECK_EMPTY_STR(result)
End

/// @}
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,6 @@ static Function PS_DS_Sub1_REENTRY([str])
WAVE/Z resistanceErr = GetLBNEntries_IGNORE(str, sweepNo, LBN_RESISTANCE_FIT_ERR)
CHECK_WAVE(resistanceErr, NULL_WAVE)

WAVE/Z sweeps = AFH_GetSweepsFromSameRACycle(numericalValues, sweepNo)
CHECK_WAVE(sweeps, NUMERIC_WAVE)
numEntries = DimSize(sweeps, ROWS)
CHECK_EQUAL_VAR(numEntries, 5)

numEntries = DimSize(sweepPassed, ROWS)
WAVE/Z stimScale = GetLBNEntries_IGNORE(str, sweepNo, STIMSET_SCALE_FACTOR_KEY)
Make/FREE/D/N=(numEntries) stimScaleRef = -30
Expand Down Expand Up @@ -432,11 +427,6 @@ static Function PS_DS_Sub2_REENTRY([str])
WAVE/T/Z opMode = GetLBNEntries_IGNORE(str, sweepNo, PSQ_FMT_LBN_DA_OPMODE)
CHECK_EQUAL_TEXTWAVES(opMode, {PSQ_DS_SUB, PSQ_DS_SUB, PSQ_DS_SUB, PSQ_DS_SUB, PSQ_DS_SUB}, mode = WAVE_DATA)

WAVE/Z sweeps = AFH_GetSweepsFromSameRACycle(numericalValues, sweepNo)
CHECK_WAVE(sweeps, NUMERIC_WAVE)
numEntries = DimSize(sweeps, ROWS)
CHECK_EQUAL_VAR(numEntries, 5)

numEntries = DimSize(sweepPassed, ROWS)
WAVE/Z stimScale = GetLBNEntries_IGNORE(str, sweepNo, STIMSET_SCALE_FACTOR_KEY)
Make/FREE/D/N=(numEntries) stimScaleRef = -30
Expand Down Expand Up @@ -607,11 +597,6 @@ static Function PS_DS_Sub3_REENTRY([str])
WAVE/Z resistanceErr = GetLBNEntries_IGNORE(str, sweepNo, LBN_RESISTANCE_FIT_ERR)
CHECK_WAVE(resistanceErr, NUMERIC_WAVE)

WAVE/Z sweeps = AFH_GetSweepsFromSameRACycle(numericalValues, sweepNo)
CHECK_WAVE(sweeps, NUMERIC_WAVE)
numEntries = DimSize(sweeps, ROWS)
CHECK_EQUAL_VAR(numEntries, 5)

numEntries = DimSize(sweepPassed, ROWS)
WAVE/Z stimScale = GetLBNEntries_IGNORE(str, sweepNo, STIMSET_SCALE_FACTOR_KEY)
Make/FREE/D/N=(numEntries) stimScaleRef = {-30, -50, -70, -110, -130}
Expand Down Expand Up @@ -827,11 +812,6 @@ static Function PS_DS_Sub4_REENTRY([str])
WAVE/Z resistanceErr = GetLBNEntries_IGNORE(str, sweepNo, LBN_RESISTANCE_FIT_ERR)
CHECK_WAVE(resistanceErr, NUMERIC_WAVE)

WAVE/Z sweeps = AFH_GetSweepsFromSameRACycle(numericalValues, sweepNo)
CHECK_WAVE(sweeps, NUMERIC_WAVE)
numEntries = DimSize(sweeps, ROWS)
CHECK_EQUAL_VAR(numEntries, 5)

numEntries = DimSize(sweepPassed, ROWS)
WAVE/Z stimScale = GetLBNEntries_IGNORE(str, sweepNo, STIMSET_SCALE_FACTOR_KEY)
Make/FREE/D/N=(numEntries) stimScaleRef = {-30, -50, -70, -110, -130}
Expand Down Expand Up @@ -980,11 +960,6 @@ static Function PS_DS_Sub5_REENTRY([str])
WAVE/Z resistanceErr = GetLBNEntries_IGNORE(str, sweepNo, LBN_RESISTANCE_FIT_ERR)
CHECK_WAVE(resistanceErr, NULL_WAVE)

WAVE/Z sweeps = AFH_GetSweepsFromSameRACycle(numericalValues, sweepNo)
CHECK_WAVE(sweeps, NUMERIC_WAVE)
numEntries = DimSize(sweeps, ROWS)
CHECK_EQUAL_VAR(numEntries, 5)

numEntries = DimSize(sweepPassed, ROWS)
WAVE/Z stimScale = GetLBNEntries_IGNORE(str, sweepNo, STIMSET_SCALE_FACTOR_KEY)
Make/FREE/D/N=(numEntries) stimScaleRef = -30
Expand Down Expand Up @@ -1133,11 +1108,6 @@ static Function PS_DS_Sub5a_REENTRY([str])
WAVE/Z resistanceErr = GetLBNEntries_IGNORE(str, sweepNo, LBN_RESISTANCE_FIT_ERR)
CHECK_WAVE(resistanceErr, NULL_WAVE)

WAVE/Z sweeps = AFH_GetSweepsFromSameRACycle(numericalValues, sweepNo)
CHECK_WAVE(sweeps, NUMERIC_WAVE)
numEntries = DimSize(sweeps, ROWS)
CHECK_EQUAL_VAR(numEntries, 5)

numEntries = DimSize(sweepPassed, ROWS)
WAVE/Z stimScale = GetLBNEntries_IGNORE(str, sweepNo, STIMSET_SCALE_FACTOR_KEY)
Make/FREE/D/N=(numEntries) stimScaleRef = -30
Expand Down Expand Up @@ -1354,11 +1324,6 @@ static Function PS_DS_Sub6_REENTRY([str])
WAVE/Z resistanceErr = GetLBNEntries_IGNORE(str, sweepNo, LBN_RESISTANCE_FIT_ERR)
CHECK_WAVE(resistanceErr, NUMERIC_WAVE)

WAVE/Z sweeps = AFH_GetSweepsFromSameRACycle(numericalValues, sweepNo)
CHECK_WAVE(sweeps, NUMERIC_WAVE)
numEntries = DimSize(sweeps, ROWS)
CHECK_EQUAL_VAR(numEntries, 5)

numEntries = DimSize(sweepPassed, ROWS)
WAVE/Z stimScale = GetLBNEntries_IGNORE(str, sweepNo, STIMSET_SCALE_FACTOR_KEY)
Make/FREE/D/N=(numEntries) stimScaleRef = {-30, -50, -70, -110, -130}
Expand Down Expand Up @@ -1531,11 +1496,6 @@ static Function PS_DS_Sub7_REENTRY([str])
WAVE/Z resistanceErr = GetLBNEntries_IGNORE(str, sweepNo, LBN_RESISTANCE_FIT_ERR)
CHECK_WAVE(resistanceErr, NUMERIC_WAVE)

WAVE/Z sweeps = AFH_GetSweepsFromSameRACycle(numericalValues, sweepNo)
CHECK_WAVE(sweeps, NUMERIC_WAVE)
numEntries = DimSize(sweeps, ROWS)
CHECK_EQUAL_VAR(numEntries, 7)

numEntries = DimSize(sweepPassed, ROWS)
WAVE/Z stimScale = GetLBNEntries_IGNORE(str, sweepNo, STIMSET_SCALE_FACTOR_KEY)
Make/FREE/D/N=(numEntries) stimScaleRef = {-30, -30, -30, -50, -70, -110, -130}
Expand Down Expand Up @@ -1721,11 +1681,6 @@ static Function PS_DS_Sub8_REENTRY([str])
WAVE/Z resistanceErr = GetLBNEntries_IGNORE(str, sweepNo, LBN_RESISTANCE_FIT_ERR)
CHECK_WAVE(resistanceErr, NUMERIC_WAVE)

WAVE/Z sweeps = AFH_GetSweepsFromSameRACycle(numericalValues, sweepNo)
CHECK_WAVE(sweeps, NUMERIC_WAVE)
numEntries = DimSize(sweeps, ROWS)
CHECK_EQUAL_VAR(numEntries, 9)

numEntries = DimSize(sweepPassed, ROWS)
WAVE/Z stimScale = GetLBNEntries_IGNORE(str, sweepNo, STIMSET_SCALE_FACTOR_KEY)
Make/FREE/D/N=(numEntries) stimScaleRef = {-30, -50, -50, -50, -70, -70, -70, -110, -130}
Expand Down Expand Up @@ -1885,11 +1840,6 @@ static Function PS_DS_Sub9_REENTRY([str])
WAVE/Z resistanceErr = GetLBNEntries_IGNORE(str, sweepNo, LBN_RESISTANCE_FIT_ERR)
CHECK_WAVE(resistanceErr, NULL_WAVE)

WAVE/Z sweeps = AFH_GetSweepsFromSameRACycle(numericalValues, sweepNo)
CHECK_WAVE(sweeps, NUMERIC_WAVE)
numEntries = DimSize(sweeps, ROWS)
CHECK_EQUAL_VAR(numEntries, 5)

numEntries = DimSize(sweepPassed, ROWS)
WAVE/Z stimScale = GetLBNEntries_IGNORE(str, sweepNo, STIMSET_SCALE_FACTOR_KEY)
Make/FREE/D/N=(numEntries) stimScaleRef = -30
Expand Down Expand Up @@ -2064,11 +2014,6 @@ static Function PS_DS_Sub10_REENTRY([str])
WAVE/Z resistanceErr = GetLBNEntries_IGNORE(str, sweepNo, LBN_RESISTANCE_FIT_ERR)
CHECK_WAVE(resistanceErr, NULL_WAVE)

WAVE/Z sweeps = AFH_GetSweepsFromSameRACycle(numericalValues, sweepNo)
CHECK_WAVE(sweeps, NUMERIC_WAVE)
numEntries = DimSize(sweeps, ROWS)
CHECK_EQUAL_VAR(numEntries, 1)

numEntries = DimSize(sweepPassed, ROWS)
WAVE/Z stimScale = GetLBNEntries_IGNORE(str, sweepNo, STIMSET_SCALE_FACTOR_KEY)
Make/FREE/D/N=(numEntries) stimScaleRef = {-30}
Expand Down
Loading

0 comments on commit 74d6ef9

Please sign in to comment.