Skip to content

Commit

Permalink
Merge pull request #2291 from AllenInstitute/feature/2291-make-last-s…
Browse files Browse the repository at this point in the history
…weep-in-set-available-for-all

AFH_LastSweepInSet: Make it available for all and fix it
  • Loading branch information
t-b authored Oct 27, 2024
2 parents dc4b21e + 2de3732 commit e9960db
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 15 deletions.
38 changes: 38 additions & 0 deletions Packages/MIES/MIES_AnalysisFunctionHelpers.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -1263,3 +1263,41 @@ Function [WAVE passingSweeps, WAVE failingSweeps] AFH_GetRheobaseSweepsSCISweepQ

return [passingSweeps, failingSweeps]
End

/// @brief Return 1 if we are currently acquiring the last sweep in the stimulus set,
/// 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

switch(eventType)
case PRE_DAQ_EVENT:
case PRE_SWEEP_CONFIG_EVENT:
// no valid setup yet
return NaN
case PRE_SET_EVENT:
case MID_SWEEP_EVENT:
// we need to look at the last acquired sweep
sweepNo -= 1
sweepOffset = 2
break
default:
sweepOffset = 1
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)

if(!WaveExists(sweepSetCount))
setCount = 0
else
setCount = sweepSetCount[headstage]
endif

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

return (setCount + sweepOffset + skipCountExisting) >= sweepsInSet
End
Original file line number Diff line number Diff line change
Expand Up @@ -166,20 +166,6 @@ static Function SC_GetSweepPassed(string device, variable sweepNo)
return V_Value == -1
End

/// @brief Return 1 if we are currently acquiring the last sweep in the stimulus set, 0 otherwise
static Function SC_LastSweepInSet(string device, variable sweepNo, variable headstage)

variable DAC, sweepsInSet

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

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

return (sweepSetCount[headstage] + 1) == sweepsInSet
End

/// @brief Given a list of pulses by their indizes, this function return only the diagonal
/// ones which are matching the given sweep
static Function/WAVE SC_FilterPulses(WAVE/WAVE propertiesWaves, WAVE/Z indizesAll, WAVE/Z indizesSweep)
Expand Down Expand Up @@ -1136,7 +1122,7 @@ Function SC_SpikeControl(device, s)
if(SC_SkipsExhausted(minTrials, s.params))
// if the minimum trials value has already reached the maximum
// allowed trials, we are done and the set has not passed
elseif(SC_LastSweepInSet(device, s.sweepNo, s.headstage) && !skippedBack)
elseif(AFH_LastSweepInSet(device, s.sweepNo, s.headstage, s.eventType) && !skippedBack)
// work around broken XXX_SET_EVENT
// we are done and were not successful
else
Expand Down
5 changes: 5 additions & 0 deletions Packages/MIES/MIES_DAEphys_GuiState.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,11 @@ Function/S DAG_GetTextualValue(device, ctrl, [index])
ControlInfo/W=$device $fullCtrl
endif

if(V_flag == 0)
sprintf msg, "Control %s does not exist in window %s.\r", ctrl, device
BUG(msg)
endif

ctrlDim = FindDimLabel(GUIState, COLS, ctrl)
if(ctrlDim < 0)
sprintf msg, "Control entry not found in textual GUI state wave: %s\r", ctrl
Expand Down
90 changes: 90 additions & 0 deletions Packages/tests/HardwareBasic/UTF_AnalysisFunctionManagement.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -2057,3 +2057,93 @@ static Function CanModifyStimsetInPreSweepConfig_REENTRY([str])
WAVE/Z settingsUnique = GetUniqueEntries(settings)
CHECK_EQUAL_WAVES(settings, settingsUnique)
End

static Function [WAVE entryHS1, WAVE entryHS2] GetLastSweepLBNEntries(WAVE numericalValues, variable sweepNo, variable eventType)

string key

// SCI is only one sweep for HS2, so let's gather the entries from the full RAC instead

sprintf key, "USER_LastSweepInSet_Event_%s_HS_%d", StringFromList(eventType, EVENT_NAME_LIST), 1
WAVE/Z entriesHS1 = GetLastSettingIndepEachRAC(numericalValues, sweepNo, key, UNKNOWN_MODE)

sprintf key, "USER_LastSweepInSet_Event_%s_HS_%d", StringFromList(eventType, EVENT_NAME_LIST), 2
WAVE/Z entriesHS2 = GetLastSettingIndepEachRAC(numericalValues, sweepNo, key, UNKNOWN_MODE)

return [entriesHS1, entriesHS2]
End

// UTF_TD_GENERATOR DeviceNameGeneratorMD1
static Function CheckLastSweepInSetWithoutSkipping([str])
string str

STRUCT DAQSettings s
InitDAQSettingsFromString(s, "MD1_RA1_I0_L0_BKG1" + \
"__HS1_DA2_AD3_CM:IC:_ST:StimulusSetA_DA_0:_AF:LastSweepInSetWithoutSkip:" + \
"__HS2_DA1_AD0_CM:IC:_ST:StimulusSetB_DA_0:_AF:LastSweepInSetWithoutSkip:")

AcquireData_NG(s, str)
End

static Function CheckLastSweepInSetWithoutSkipping_REENTRY([str])
string str

variable sweepNo, entry
string key

WAVE numericalValues = GetLBNumericalValues(str)
WAVE textualValues = GetLBNumericalValues(str)

sweepNo = 2
CHECK_EQUAL_VAR(AFH_GetLastSweepAcquired(str), sweepNo)

// PRE_DAQ_EVENT

key = "USER_LastSweepInSet_Event_Pre DAQ_HS_1"
entry = GetLastSettingIndep(numericalValues, NaN, key, UNKNOWN_MODE)
CHECK_EQUAL_VAR(entry, NaN)

key = "USER_LastSweepInSet_Event_Pre DAQ_HS_2"
entry = GetLastSettingIndep(numericalValues, NaN, key, UNKNOWN_MODE)
CHECK_EQUAL_VAR(entry, NaN)

[WAVE entriesHS1, WAVE entriesHS2] = GetLastSweepLBNEntries(numericalValues, sweepNo, PRE_DAQ_EVENT)
CHECK_WAVE(entriesHS1, NULL_WAVE)
CHECK_WAVE(entriesHS2, NULL_WAVE)

// PRE_SWEEP_CONFIG_EVENT

[WAVE entriesHS1, WAVE entriesHS2] = GetLastSweepLBNEntries(numericalValues, sweepNo, PRE_SWEEP_CONFIG_EVENT)
CHECK_WAVE(entriesHS1, NULL_WAVE)
CHECK_WAVE(entriesHS2, NULL_WAVE)

// PRE_SET_EVENT

[WAVE entriesHS1, WAVE entriesHS2] = GetLastSweepLBNEntries(numericalValues, sweepNo, PRE_SET_EVENT)
CHECK_EQUAL_WAVES(entriesHS1, {0, NaN, NaN}, mode = WAVE_DATA)
CHECK_EQUAL_WAVES(entriesHS2, {1, 1, 1}, mode = WAVE_DATA)

// MID_SWEEP_EVENT

[WAVE entriesHS1, WAVE entriesHS2] = GetLastSweepLBNEntries(numericalValues, sweepNo, MID_SWEEP_EVENT)
CHECK_EQUAL_WAVES(entriesHS1, {0, 0, 1}, mode = WAVE_DATA)
CHECK_EQUAL_WAVES(entriesHS2, {1, 1, 1}, mode = WAVE_DATA)

// POST_SWEEP_EVENT

[WAVE entriesHS1, WAVE entriesHS2] = GetLastSweepLBNEntries(numericalValues, sweepNo, POST_SWEEP_EVENT)
CHECK_EQUAL_WAVES(entriesHS1, {0, 0, 1}, mode = WAVE_DATA)
CHECK_EQUAL_WAVES(entriesHS2, {1, 1, 1}, mode = WAVE_DATA)

// POST_SET_EVENT

[WAVE entriesHS1, WAVE entriesHS2] = GetLastSweepLBNEntries(numericalValues, sweepNo, POST_SET_EVENT)
CHECK_EQUAL_WAVES(entriesHS1, {NaN, NaN, 1}, mode = WAVE_DATA)
CHECK_EQUAL_WAVES(entriesHS2, {1, 1, 1}, mode = WAVE_DATA)

// POST_DAQ_EVENT

[WAVE entriesHS1, WAVE entriesHS2] = GetLastSweepLBNEntries(numericalValues, sweepNo, POST_DAQ_EVENT)
CHECK_EQUAL_WAVES(entriesHS1, {NaN, NaN, 1}, mode = WAVE_DATA)
CHECK_EQUAL_WAVES(entriesHS2, {NaN, NaN, 1}, mode = WAVE_DATA)
End
11 changes: 11 additions & 0 deletions Packages/tests/UserAnalysisFunctions.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -1195,3 +1195,14 @@ static Function ILCUCheck_IGNORE(string device, STRUCT AnalysisFunction_V3 &s)
CHECK_EQUAL_VAR(s.sweepNo, 1)
endif
End

Function LastSweepInSetWithoutSkip(string device, STRUCT AnalysisFunction_V3 &s)

string key

sprintf key, "LastSweepInSet_Event_%s_HS_%d", StringFromList(s.eventType, EVENT_NAME_LIST), s.headstage

WAVE values = LBN_GetNumericWave()
values[INDEP_HEADSTAGE] = AFH_LastSweepInSet(device, s.sweepNo, s.headstage, s.eventType)
ED_AddEntryToLabnotebook(device, key, values, overrideSweepNo = s.sweepNo)
End

0 comments on commit e9960db

Please sign in to comment.