Skip to content

Commit

Permalink
changes
Browse files Browse the repository at this point in the history
  • Loading branch information
t-b committed Nov 23, 2023
1 parent a5e25ed commit 25aa831
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 11 deletions.
21 changes: 11 additions & 10 deletions Packages/MIES/MIES_AnalysisFunctions_PatchSeq.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -1845,7 +1845,8 @@ End
///
/// @retval fitOffset offsets of all line fits
/// @retval fitSlope slopes of all line fits
static Function [WAVE/D fitOffset, WAVE/D fitSlope] PSQ_DS_FitFrequencyCurrentData(string device, variable sweepNo, WAVE apfreq, WAVE DAScales, variable numPointsForLineFit)
/// @retval errMsg error message if both `fitOffset` and `fitSlope` are null
static Function [WAVE/D fitOffset, WAVE/D fitSlope, string errMsg] PSQ_DS_FitFrequencyCurrentData(string device, variable sweepNo, WAVE apfreq, WAVE DAScales, variable numPointsForLineFit)

variable i, numPoints, numFits, first, last, hasEnoughPoints, initialFit
string line, databrowser, key
Expand All @@ -1861,7 +1862,7 @@ static Function [WAVE/D fitOffset, WAVE/D fitSlope] PSQ_DS_FitFrequencyCurrentDa
ED_AddEntryToLabnotebook(device, key, hasEnoughPointsLBN, overrideSweepNo = sweepNo, unit = LABNOTEBOOK_BINARY_UNIT)

if(!hasEnoughPoints)
return [$"", $""]
return [$"", $"", "Not enough points for fit"]
endif

numFits = (numPoints - numPointsForLineFit) + 1
Expand Down Expand Up @@ -1919,7 +1920,7 @@ static Function [WAVE/D fitOffset, WAVE/D fitSlope] PSQ_DS_FitFrequencyCurrentDa
WAVE/Z fitCoeff = JWN_GetNumericWaveFromWaveNote(fitResult, SF_META_USER_GROUP + SF_META_FIT_COEFF)

if(!WaveExists(fitCoeff))
return [$"", $""]
return [$"", $"", "Fit failed"]
endif

WAVE/Z fitParams = JWN_GetTextWaveFromWaveNote(fitResult, SF_META_USER_GROUP + SF_META_FIT_PARAMETER)
Expand All @@ -1931,10 +1932,10 @@ static Function [WAVE/D fitOffset, WAVE/D fitSlope] PSQ_DS_FitFrequencyCurrentDa
endfor

if(!HasOneValidEntry(fitOffset) && !HasOneValidEntry(fitSlope))
return [$"", $""]
return [$"", $"", "All fit results are NaN"]
endif

return [fitOffset, fitSlope]
return [fitOffset, fitSlope, ""]
End

/// @brief Check if the fit results from PSQ_DS_FitFrequencyCurrentData are valid
Expand Down Expand Up @@ -2139,7 +2140,7 @@ End
/// @retval futureDAScales
static Function [WAVE futureDAScales, variable fitOffset, variable fitSlope, variable apfreq] PSQ_DS_EvaluateAdaptiveThresholdSweep(string device, variable sweepNo, variable headstage, variable numPointsForLineFit, variable slopePercentage, variable maxFrequencyChangePercent)

string key
string key, errMsg
variable maxSlope, validFit

WAVE textualValues = GetLBTextualValues(device)
Expand All @@ -2152,7 +2153,7 @@ static Function [WAVE futureDAScales, variable fitOffset, variable fitSlope, var
// we only want to fit the last numPointsForLineFit pairs
DeletePoints/M=(ROWS) 0, (DimSize(apFreqs, ROWS) - numPointsForLineFit), apFreqs, DAScales

[WAVE fitOffsetAll, WAVE fitSlopeAll] = PSQ_DS_FitFrequencyCurrentData(device, sweepNo, apfreqs, DAScales, numPointsForLineFit)
[WAVE fitOffsetAll, WAVE fitSlopeAll, errMsg] = PSQ_DS_FitFrequencyCurrentData(device, sweepNo, apfreqs, DAScales, numPointsForLineFit)

validFit = PSQ_DS_AreFitResultsValid(device, sweepNo, headstage, fitOffsetAll, fitSlopeAll)

Expand Down Expand Up @@ -2764,7 +2765,7 @@ Function PSQ_DAScale(device, s)
variable sweepPassed, setPassed, length, minLength, reachedFinalSlope, fitOffset, fitSlope, apfreq, enoughFIPointsPassedQC
variable minimumSpikeCount, maximumSpikeCount, daScaleModifierParam, measuredAllFutureDAScales
variable sweepsInSet, passesInSet, acquiredSweepsInSet, multiplier, asyncAlarmPassed, supraStimsetCycle
string msg, stimset, key, opMode, offsetOp, textboxString, str
string msg, stimset, key, opMode, offsetOp, textboxString, str, errMsg
variable daScaleOffset
variable finalSlopePercent = NaN
variable daScaleModifier, chunk
Expand Down Expand Up @@ -2931,11 +2932,11 @@ Function PSQ_DAScale(device, s)
key = CreateAnaFuncLBNKey(PSQ_DA_SCALE, PSQ_FMT_LBN_DA_AT_DASCALE_SUPRA)
ED_AddEntryToLabnotebook(device, key, DAScalesTextLBN, overrideSweepNo = s.sweepNo)

[WAVE fitOffsetFromSupra, WAVE fitSlopeFromSupra] = PSQ_DS_FitFrequencyCurrentData(device, s.sweepNo, \
[WAVE fitOffsetFromSupra, WAVE fitSlopeFromSupra, errMsg] = PSQ_DS_FitFrequencyCurrentData(device, s.sweepNo, \
apfreqFromSupra, DAScalesFromSupra, numPointsForLineFit)

if(!WaveExists(fitOffsetFromSupra) || !WaveExists(fitSlopeFromSupra))
printf "The f-I fit of the supra data failed\r"
printf "The f-I fit of the supra data failed due to: \"%s\"\r", errMsg
ControlWindowToFront()
return 1
endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ static Function PS_DS_AD5([string str])
AcquireData_NG(s, str)

historyText = CaptureHistory(ref, 1)
CHECK_GE_VAR(strsearch(historyText, "The f-I fit of the supra data failed", 1), 0)
CHECK_GE_VAR(strsearch(historyText, "The f-I fit of the supra data failed due to: \"Not enough points for fit\"", 1), 0)

sweepNo = AFH_GetLastSweepAcquired(str)
CHECK_EQUAL_VAR(sweepNo, NaN)
Expand Down Expand Up @@ -801,3 +801,49 @@ static Function PS_DS_AD7_REENTRY([string str])

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

static Function PS_DS_AD8_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

AFH_AddAnalysisParameter("PSQ_DaScale_Adapt_DA_0", "MaxFrequencyChangePercent", var=25)

// 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})

Make/FREE/D daScalesFromSupra = {1, 1}
JWN_SetWaveInWaveNote(overrideResults, "DAScalesSupra", daScalesFromSupra)

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

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

variable ref, sweepNo
string historyText

ref = CaptureHistoryStart()

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

historyText = CaptureHistory(ref, 1)
CHECK_GE_VAR(strsearch(historyText, "The f-I fit of the supra data failed due to: \"All fit results are NaN\"", 1), 0)

sweepNo = AFH_GetLastSweepAcquired(str)
CHECK_EQUAL_VAR(sweepNo, NaN)
End

0 comments on commit 25aa831

Please sign in to comment.