Skip to content

Commit

Permalink
changes
Browse files Browse the repository at this point in the history
  • Loading branch information
t-b committed Nov 20, 2023
1 parent a4d7294 commit e305464
Show file tree
Hide file tree
Showing 2 changed files with 140 additions and 42 deletions.
79 changes: 42 additions & 37 deletions Packages/MIES/MIES_AnalysisFunctions_PatchSeq.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -2278,28 +2278,37 @@ static Function [WAVE futureDAScales, WAVE apfreq] PSQ_DS_GatherFutureDAScalesAn
WAVE/T apfreqFromSupraLBN = GetLastSettingTextSCI(numericalValues, textualValues, sweepNo, key, headstage, UNKNOWN_MODE)
WAVE apfreqFromSupra = ListToNumericWave(apfreqFromSupraLBN[headstage], ";")

WAVE apFreq = apfreqFromSupra
WAVE DAScales = DAScalesFromSupra

key = CreateAnaFuncLBNKey(PSQ_DA_SCALE, PSQ_FMT_LBN_DA_AT_FREQ, query = 1)
WAVE apfreqLastSweepLBN = GetLastSetting(numericalValues, sweepNo, key, UNKNOWN_MODE)
WAVE apfreqCurrentSCI = GetLastSettingEachSCI(numericalValues, sweepNo, key, headstage, UNKNOWN_MODE)

WAVE DAScaleFromLastSweepLBN = GetLastSetting(numericalValues, sweepNo, "Stim Scale Factor", DATA_ACQUISITION_MODE)
WAVE DAScaleCurrentSCI = GetLastSettingEachSCI(numericalValues, sweepNo, "Stim Scale Factor", headstage, DATA_ACQUISITION_MODE)

WAVE apFreq = apfreqFromSupra
WAVE DAScales = DAScalesFromSupra
key = CreateAnaFuncLBNKey(PSQ_DA_SCALE, PSQ_FMT_LBN_SWEEP_PASS, query = 1)
WAVE sweepPassCurrentSCI = GetLastSettingIndepEachSCI(numericalValues, sweepNo, key, headstage, UNKNOWN_MODE)

Make/FREE/D apfreqLastSweep = {apfreqLastSweepLBN[headstage]}
Make/FREE/D DAScaleFromLastSweep = {DAScaleFromLastSweepLBN[headstage]}
apfreqCurrentSCI[] = sweepPassCurrentSCI[p] ? apfreqCurrentSCI[p] : NaN
DAScaleCurrentSCI[] = sweepPassCurrentSCI[p] ? DAScaleCurrentSCI[p] : NaN

Concatenate/NP=(ROWS) {apfreqLastSweep}, apfreq
Concatenate/NP=(ROWS) {DAScaleFromLastSweep}, DAScales
WAVE/Z apfreqCurrentSCIClean = ZapNaNs(apfreqCurrentSCI)
WAVE/Z DAScaleCurrentSCIClean = ZapNaNs(DAScaleCurrentSCI)

WAVE/D/Z futureDAScalesFromLastSweep = PSQ_DS_GatherOvershootCorrection(apfreq, DAScales, maxFrequencyChangePercent)
if(WaveExists(apfreqCurrentSCIClean) && WaveExists(DAScaleCurrentSCIClean))
Concatenate/NP=(ROWS) {apfreqCurrentSCIClean}, apfreq
Concatenate/NP=(ROWS) {DAScaleCurrentSCIClean}, DAScales

if(WaveExists(futureDAScalesFromLastSweep))
Concatenate/FREE/NP=(ROWS) {futureDAScalesFromLastSweep}, futureDAScalesHistoric
endif
// TODO do we need look at if sweepNo is passing here?
WAVE/D/Z futureDAScalesFromLastSweep = PSQ_DS_GatherOvershootCorrection(apfreq, DAScales, maxFrequencyChangePercent)

WAVE futureDAScales = futureDAScalesHistoric
WaveClear futureDAScalesHistoric, futureDAScalesFromLastSweep
if(WaveExists(futureDAScalesFromLastSweep))
Concatenate/FREE/NP=(ROWS) {futureDAScalesFromLastSweep}, futureDAScalesHistoric
endif

WAVE futureDAScales = futureDAScalesHistoric
WaveClear futureDAScalesHistoric, futureDAScalesFromLastSweep
endif

return [futureDAScales, apfreq]
End
Expand Down Expand Up @@ -3149,32 +3158,28 @@ Function PSQ_DAScale(device, s)
break
elseif(sweepPassed && ret == PSQ_RESULTS_CONT)
DAScalesIndex[s.headstage] += 1
endif

[WAVE futureDAScales, WAVE apfreq] = PSQ_DS_GatherFutureDAScalesAndFrequency(device, s.sweepNo, s.headstage, maxFrequencyChangePercent)

key = CreateAnaFuncLBNKey(PSQ_DA_SCALE, PSQ_FMT_LBN_DA_FI_SLOPE, query = 1)
WAVE/Z fitSlope = GetLastSetting(numericalValues, s.sweepNo, key, UNKNOWN_MODE)

key = CreateAnaFuncLBNKey(PSQ_DA_SCALE, PSQ_FMT_LBN_DA_AT_FI_OFFSET, query = 1)
WAVE/Z fitOffset = GetLastSetting(numericalValues, s.sweepNo, key, UNKNOWN_MODE)

if(WaveExists(fitSlope) && WaveExists(fitOffset))
dascale = PSQ_DS_CalculateDAScale(fitOffset[s.headstage], fitSlope[s.headstage], apfreq[inf], maxFrequencyChangePercent)

Make/FREE/D DAScaleNew = {dascale}

Concatenate/NP=(ROWS) {DAScaleNew}, futureDAScales
endif

WAVE/T futureDAScalesLBN = LBN_GetTextWave()
futureDAScalesLBN[s.headstage] = NumericWaveToList(futureDAScales, ";", format = "%.15g")
key = CreateAnaFuncLBNKey(PSQ_DA_SCALE, PSQ_FMT_LBN_DA_AT_FUTURE_DASCALES)
ED_AddEntryToLabnotebook(device, key, futureDAScalesLBN, overrideSweepNo = s.sweepNo)
[WAVE futureDAScales, WAVE apfreq] = PSQ_DS_GatherFutureDAScalesAndFrequency(device, s.sweepNo, s.headstage, maxFrequencyChangePercent)

key = CreateAnaFuncLBNKey(PSQ_DA_SCALE, PSQ_FMT_LBN_DA_FI_SLOPE, query = 1)
WAVE/Z fitSlope = GetLastSetting(numericalValues, s.sweepNo, key, UNKNOWN_MODE)

key = CreateAnaFuncLBNKey(PSQ_DA_SCALE, PSQ_FMT_LBN_DA_AT_FI_OFFSET, query = 1)
WAVE/Z fitOffset = GetLastSetting(numericalValues, s.sweepNo, key, UNKNOWN_MODE)

if(WaveExists(fitSlope) && WaveExists(fitOffset))
dascale = PSQ_DS_CalculateDAScale(fitOffset[s.headstage], fitSlope[s.headstage], apfreq[inf], maxFrequencyChangePercent)

Make/FREE/D DAScaleNew = {dascale}

Concatenate/NP=(ROWS) {DAScaleNew}, futureDAScales
endif

key = CreateAnaFuncLBNKey(PSQ_DA_SCALE, PSQ_FMT_LBN_DA_AT_FUTURE_DASCALES, query = 1)
WAVE/T futureDAScalesLBN = GetLastSettingTextSCI(numericalValues, textualValues, s.sweepNo, key, s.headstage, UNKNOWN_MODE)
WAVE futureDAScales = ListToNumericWave(futureDAScalesLBN[s.headstage], ";")
WAVE/T futureDAScalesLBN = LBN_GetTextWave()
futureDAScalesLBN[s.headstage] = NumericWaveToList(futureDAScales, ";", format = "%.15g")
key = CreateAnaFuncLBNKey(PSQ_DA_SCALE, PSQ_FMT_LBN_DA_AT_FUTURE_DASCALES)
ED_AddEntryToLabnotebook(device, key, futureDAScalesLBN, overrideSweepNo = s.sweepNo)

// prepare wave for setting DAScale; DAScalesIndex is incremented above if required
WAVE/ZZ DAScales = futureDAScales
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,8 @@ static Function PS_DA_AD1_REENTRY([string str])
CHECK_EQUAL_WAVES(entries[%asyncPass], {0, 0, 0}, mode = WAVE_DATA)
CHECK_EQUAL_WAVES(entries[%samplingPass], {1, 1, 1}, mode = WAVE_DATA)

CHECK_EQUAL_WAVES(entries[%futureDAScalesPass], {1, 1, 1}, mode = WAVE_DATA)
// TODO is that really correct?
CHECK_EQUAL_WAVES(entries[%futureDAScalesPass], {1, 1, 0}, mode = WAVE_DATA)
CHECK_EQUAL_WAVES(entries[%fiSlopeReachedPass], {0, 0, 0}, mode = WAVE_DATA)
CHECK_EQUAL_WAVES(entries[%enoughFIPointsPass], {1, 1, 1}, mode = WAVE_DATA)
CHECK_EQUAL_WAVES(entries[%validSlopePass], {1, 0, 0}, mode = WAVE_DATA)
Expand All @@ -308,13 +309,13 @@ static Function PS_DA_AD1_REENTRY([string str])
Make/FREE/D maxSlopeRef = {9.37500146847015e-07 ,NaN, NaN}
Make/FREE/D fiSlopeRef = {9.37500146847015e-07, NaN, NaN}
Make/FREE/D fiOffsetRef = {-21.5000076293945, NaN, NaN}
Make/FREE/T futureDAScalesRef = {"0.00495999982456056;", \
"", \
""}
Make/FREE/T futureDAScalesRef = {"0.00495999982456056;0.00430720013913597;", \
"0.00495999982456056;0.00430720013913597;", \
"0.00495999982456056;0.00430720013913597;"}

Make/FREE/D fiSlopesFromSupraRef = {1e-07, 2e-07, 3e-07}
Make/FREE/D fiOffsetsFromSupraRef = {9, 7, 4}
Make/FREE/D DAScalesRef = {0.00495999982456056, 0.00495999982456056, 0.00495999982456056}
Make/FREE/D DAScalesRef = {0.004959999824560564, 0.004307200139135969, 0.004307200139135969}

CHECK_EQUAL_WAVES(entries[%maxSlope], maxSlopeRef, mode = WAVE_DATA, tol = 1e-12)
CHECK_EQUAL_WAVES(entries[%fiSlope], fiSlopeRef, mode = WAVE_DATA, tol = 1e-12)
Expand Down Expand Up @@ -416,3 +417,95 @@ static Function PS_DA_AD2_REENTRY([string str])

CommonAnalysisFunctionChecks(str, sweepNo, entries[%setPass])
End

static Function PS_DA_AD3_preAcq(string device)

AFH_AddAnalysisParameter("PSQ_DaScale_Adapt_DA_0", "BaselineRMSLongThreshold", var=0.5)
AFH_AddAnalysisParameter("PSQ_DaScale_Adapt_DA_0", "BaselineRMSShortThreshold", var=0.07)

// SamplingMultiplier, SamplingFrequency use defaults

// use defaults for the rest

Make/FREE asyncChannels = {2, 4}
AFH_AddAnalysisParameter("PSQ_DaScale_Adapt_DA_0", "AsyncQCChannels", wv = asyncChannels)

SetAsyncChannelProperties(device, asyncChannels, -1e6, +1e6)

WAVE/Z overrideResults = GetOverrideResults()
CHECK_WAVE(overrideResults, NUMERIC_WAVE)
JWN_SetWaveInWaveNote(overrideResults, "PassingSupraSweep", {7})
JWN_SetWaveInWaveNote(overrideResults, "PassingSupraSweeps", {4, 5, 6, 7})

Make/FREE/D daScalesFromSupra = {1e-3, 2e-3, 3e-3, 4e-3}
JWN_SetWaveInWaveNote(overrideResults, "DAScalesSupra", daScalesFromSupra)

Make/FREE/D apFrequenciesFromSupra = {10, 11, 13, 16}
JWN_SetWaveInWaveNote(overrideResults, "APFrequenciesSupra", apFrequenciesFromSupra)
End

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

[STRUCT DAQSettings s] = PS_GetDAQSettings(str)
AcquireData_NG(s, str)

WAVE wv = PSQ_CreateOverrideResults(str, PSQ_TEST_HEADSTAGE, PSQ_DA_SCALE, opMode = PSQ_DS_ADAPT)

// 0: BL fails
// 1: sweep QC passes and fiSlope reached
wv[][0][%APFrequency] = 20
wv[][1,][%APFrequency] = 20.1 - 5 * (q - 1)
wv[][][%AsyncQC] = 1
wv[][1][%BaselineQC] = 1
End

static Function PS_DA_AD3_REENTRY([string str])
variable sweepNo

sweepNo = 1

WAVE/WAVE entries = GetEntries_IGNORE(str, sweepNo)

CHECK_EQUAL_TEXTWAVES(entries[%opMode], {PSQ_DS_ADAPT}, mode = WAVE_DATA)

CHECK_EQUAL_WAVES(entries[%setPass], {1}, mode = WAVE_DATA)
CHECK_EQUAL_WAVES(entries[%sweepPass], {1}, mode = WAVE_DATA)

CHECK_EQUAL_WAVES(entries[%rmsShortPass], {1}, mode = WAVE_DATA)
CHECK_EQUAL_WAVES(entries[%rmsLongPass], {1}, mode = WAVE_DATA)
CHECK_EQUAL_WAVES(entries[%baselinePass], {1}, mode = WAVE_DATA)
CHECK_EQUAL_WAVES(entries[%asyncPass], {1}, mode = WAVE_DATA)
CHECK_EQUAL_WAVES(entries[%samplingPass], {1}, mode = WAVE_DATA)

CHECK_EQUAL_WAVES(entries[%futureDAScalesPass], {1}, mode = WAVE_DATA)
CHECK_EQUAL_WAVES(entries[%fiSlopeReachedPass], {1}, mode = WAVE_DATA)
CHECK_EQUAL_WAVES(entries[%enoughFIPointsPass], {1}, mode = WAVE_DATA)
CHECK_EQUAL_WAVES(entries[%validSlopePass], {1}, mode = WAVE_DATA)
CHECK_EQUAL_WAVES(entries[%initialValidSlopePass], {1}, mode = WAVE_DATA)

[WAVE apFreqRef, WAVE apFreqFromSupra, WAVE DAScalesFromSupra] = ExtractRefValuesFromOverride(sweepNo)

CHECK_EQUAL_WAVES(entries[%apfreq], apFreqRef, mode = WAVE_DATA)
CHECK_EQUAL_WAVES(entries[%apfreqFromSupra], apFreqFromSupra, mode = WAVE_DATA)
CHECK_EQUAL_WAVES(entries[%dascaleFromSupra], DAScalesFromSupra, mode = WAVE_DATA)

Make/FREE/D maxSlopeRef = {9.37500146847015e-07}
Make/FREE/D fiSlopeRef = {9.37500146847015e-07}
Make/FREE/D fiOffsetRef = {15.58333301544189}
Make/FREE/T futureDAScalesRef = {"0.00495999982456056;"}

Make/FREE/D fiSlopesFromSupraRef = {1e-07, 2e-07, 3e-07}
Make/FREE/D fiOffsetsFromSupraRef = {9, 7, 4}
Make/FREE/D DAScalesRef = {0.00495999982456056}

CHECK_EQUAL_WAVES(entries[%maxSlope], maxSlopeRef, mode = WAVE_DATA, tol = 1e-12)
CHECK_EQUAL_WAVES(entries[%fiSlope], fiSlopeRef, mode = WAVE_DATA, tol = 1e-12)
CHECK_EQUAL_WAVES(entries[%fiOffset], fiOffsetRef, mode = WAVE_DATA, tol = 1e-12)
CHECK_EQUAL_TEXTWAVES(entries[%futureDAScales], futureDAScalesRef, mode = WAVE_DATA)
CHECK_EQUAL_WAVES(entries[%fiSlopesFromSupra], fiSlopesFromSupraRef, mode = WAVE_DATA, tol = 1e-12)
CHECK_EQUAL_WAVES(entries[%fiOffsetsFromSupra], fiOffsetsFromSupraRef, mode = WAVE_DATA, tol = 1e-12)
CHECK_EQUAL_WAVES(entries[%dascale], DAScalesRef, mode = WAVE_DATA, tol = 1e-12)

CommonAnalysisFunctionChecks(str, sweepNo, entries[%setPass])
End

0 comments on commit e305464

Please sign in to comment.