Skip to content

Commit

Permalink
PSQ_DS_FitFrequencyCurrentData: Remove it
Browse files Browse the repository at this point in the history
In (PSQ_DAScale: Change fitting logic and drop NumPointsForLineFit,
2024-07-10) we added dropping duplicated AP frequencies in the input data
for fitting. We do catch that now with the neg fI slope QC better. And
that also removes the hack to find a good DAScale in case this was
filtered out.
  • Loading branch information
t-b committed Jan 28, 2025
1 parent c4277fd commit ae1e170
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 72 deletions.
48 changes: 11 additions & 37 deletions Packages/MIES/MIES_AnalysisFunctions_PatchSeq.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -2206,19 +2206,7 @@ static Function [WAVE/D fitOffset, WAVE/D fitSlope, string errMsg] PSQ_DS_FitFre
[WAVE DAScalesSorted, WAVE apfreqSorted] = SortKeyAndData(DAScales, apfreq)
WaveClear DAScales, apfreq

// original data:
// apfreq: {5, 8, 9, 9, 15}
// DAScale: {50, 100, 130, 160, 200}
// numPoints = 5
//
// after filtering:
// apfreq: {5, 8, 9, 15}
// DAScale: {50, 100, 130, 200}
// deletedIndizes: {3}
// numPoints = 4
[WAVE apfreqFiltered, WAVE DAScalesFiltered, WAVE deletedIndizes, numPoints] = PSQ_DS_FilterFrequencyCurrentData(apfreqSorted, DAScalesSorted)
WaveClear DAScalesSorted, apfreqSorted

numPoints = DimSize(DAScalesSorted, ROWS)
hasEnoughPoints = (numPoints >= PSQ_DA_NUM_POINTS_LINE_FIT)

if(writeEnoughPointsLBN)
Expand All @@ -2235,27 +2223,22 @@ static Function [WAVE/D fitOffset, WAVE/D fitSlope, string errMsg] PSQ_DS_FitFre
if(singleFit)
numPoints = PSQ_DA_NUM_POINTS_LINE_FIT

Duplicate/FREE/RMD=[0, PSQ_DA_NUM_POINTS_LINE_FIT - 1] apfreqFiltered, apfreqFinal
Duplicate/FREE/RMD=[0, PSQ_DA_NUM_POINTS_LINE_FIT - 1] DAScalesFiltered, DAScalesFinal
Duplicate/FREE/RMD=[0, PSQ_DA_NUM_POINTS_LINE_FIT - 1] apfreqSorted, apfreqFinal
Duplicate/FREE/RMD=[0, PSQ_DA_NUM_POINTS_LINE_FIT - 1] DAScalesSorted, DAScalesFinal

// now we need to grab PSQ_DA_NUM_POINTS_LINE_FIT points
// going from back to front starting at DAScaleRef
FindValue/R/V=(DAScaleRef) DAScalesFiltered
if(V_Value >= 0)
idx = V_Value
else
// but if we can't find it, because it was filtered out
// we take the last PSQ_DA_NUM_POINTS_LINE_FIT values
idx = DimSize(DAScalesFiltered, ROWS) - 1
endif
FindValue/R/V=(DAScaleRef) DAScalesSorted
ASSERT(V_Value >= 0, "Invalid DAScaleRef")
idx = V_Value

apfreqFinal[] = apfreqFiltered[idx - PSQ_DA_NUM_POINTS_LINE_FIT + 1 + p]
DAScalesFinal[] = DAScalesFiltered[idx - PSQ_DA_NUM_POINTS_LINE_FIT + 1 + p]
apfreqFinal[] = apfreqSorted[idx - PSQ_DA_NUM_POINTS_LINE_FIT + 1 + p]
DAScalesFinal[] = DAScalesSorted[idx - PSQ_DA_NUM_POINTS_LINE_FIT + 1 + p]
else
WAVE apfreqFinal = apfreqFiltered
WAVE DAScalesFinal = DAScalesFiltered
WAVE apfreqFinal = apfreqSorted
WAVE DAScalesFinal = DAScalesSorted
endif
WAVEClear DAScalesFiltered, apfreqFiltered
WAVEClear DAScalesSorted, apfreqSorted

numFits = (numPoints - PSQ_DA_NUM_POINTS_LINE_FIT) + 1

Expand Down Expand Up @@ -2322,15 +2305,6 @@ static Function [WAVE/D fitOffset, WAVE/D fitSlope, string errMsg] PSQ_DS_FitFre
fitSlope[i] = fitCoeff[%Slope] / ONE_TO_PICO * ONE_TO_PERCENT // % Hz / pA
endfor

// readd NaN entries for filtered out apFreq/DAScale
if(!singleFit && WaveExists(deletedIndizes))
Sort/A deletedIndizes, deletedIndizes
for(elem : deletedIndizes)
idx = floor(elem / PSQ_DA_NUM_POINTS_LINE_FIT)
InsertPoints/M=(ROWS)/V=(PSQ_DS_SKIPPED_FI_SLOPE) idx, 1, fitOffset, fitSlope
endfor
endif

if(!HasOneValidEntry(fitOffset) && !HasOneValidEntry(fitSlope))
return [$"", $"", "All fit results are NaN"]
endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2159,7 +2159,7 @@ static Function PS_DS_AD11_REENTRY([string str])
CHECK_EQUAL_WAVES(entries[%validSlopePass], {1, 1}, mode = WAVE_DATA)
CHECK_EQUAL_WAVES(entries[%initialValidSlopePass], {1, NaN}, mode = WAVE_DATA)
CHECK_EQUAL_WAVES(entries[%fiSlopeReachedPassFromRhSuAd], {0, 0, 0}, mode = WAVE_DATA)
CHECK_EQUAL_WAVES(entries[%fiNegSlopesPassFromRhSuAd], {0, 0, 0}, mode = WAVE_DATA)
CHECK_EQUAL_WAVES(entries[%fiNegSlopesPassFromRhSuAd], {1, 0, 0}, mode = WAVE_DATA)
CHECK_EQUAL_WAVES(entries[%fillinPassFromRhSuAd], {0, 0, 0, 0}, mode = WAVE_DATA)

Make/FREE/D minDAScaleNormRef = {2.142857142857143, NaN}
Expand All @@ -2183,8 +2183,8 @@ static Function PS_DS_AD11_REENTRY([string str])

// we do have three pairs in apFrequenciesFromRhSuAd/DAScalesFromRhSuAd but a neighboring duplicate
// so only two valid slopes and offsets
Make/FREE/D fiSlopesFromRhSuAdRef = {PSQ_DS_SKIPPED_FI_SLOPE, 1.5e-11, 3e-11}
Make/FREE/D fiOffsetsFromRhSuAdRef = {PSQ_DS_SKIPPED_FI_SLOPE, 8.5, 4}
Make/FREE/D fiSlopesFromRhSuAdRef = {0, 3e-11, 3e-11}
Make/FREE/D fiOffsetsFromRhSuAdRef = {10, 4, 4}
Make/FREE/D DAScalesRef = {63, 112}

CHECK_EQUAL_WAVES(entries[%maxSlope], maxSlopeRef, mode = WAVE_DATA, tol = 1e-24)
Expand Down Expand Up @@ -2613,38 +2613,38 @@ static Function PS_DS_AD15_REENTRY([string str])

variable sweepNo

sweepNo = 2
sweepNo = 0

WAVE/WAVE entries = GetEntries_IGNORE(str, sweepNo)

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

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

CHECK_EQUAL_WAVES(entries[%rmsShortPass], {1, 1, 1}, mode = WAVE_DATA)
CHECK_EQUAL_WAVES(entries[%rmsLongPass], {1, 1, 1}, mode = WAVE_DATA)
CHECK_EQUAL_WAVES(entries[%baselinePass], {1, 1, 1}, mode = WAVE_DATA)
CHECK_EQUAL_WAVES(entries[%asyncPass], {1, 1, 1}, mode = WAVE_DATA)
CHECK_EQUAL_WAVES(entries[%samplingPass], {1, 1, 1}, mode = WAVE_DATA)
CHECK_EQUAL_WAVES(entries[%fillinPass], {0, 0, 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[%fillinPass], {0}, mode = WAVE_DATA)

CHECK_EQUAL_WAVES(entries[%futureDAScalesPass], {0, 0, 0}, mode = WAVE_DATA)
CHECK_EQUAL_WAVES(entries[%fiSlopeReachedPass], {0, 0, 0}, mode = WAVE_DATA)
CHECK_EQUAL_WAVES(entries[%fiNegSlopePass], {0, 0, 0}, mode = WAVE_DATA)
CHECK_EQUAL_WAVES(entries[%enoughFIPointsPass], {1, 1, 1}, mode = WAVE_DATA)
CHECK_EQUAL_WAVES(entries[%validSlopePass], {1, 1, 1}, mode = WAVE_DATA)
CHECK_EQUAL_WAVES(entries[%initialValidSlopePass], {1, NaN, NaN}, mode = WAVE_DATA)
CHECK_EQUAL_WAVES(entries[%futureDAScalesPass], {1}, mode = WAVE_DATA)
CHECK_EQUAL_WAVES(entries[%fiSlopeReachedPass], {0}, mode = WAVE_DATA)
CHECK_EQUAL_WAVES(entries[%fiNegSlopePass], {0}, mode = WAVE_DATA)
CHECK_EQUAL_WAVES(entries[%enoughFIPointsPass], {1}, mode = WAVE_DATA)
CHECK_EQUAL_WAVES(entries[%validSlopePass], {0}, mode = WAVE_DATA)
CHECK_EQUAL_WAVES(entries[%initialValidSlopePass], {1}, mode = WAVE_DATA)
CHECK_EQUAL_WAVES(entries[%fiSlopeReachedPassFromRhSuAd], {0, 0, 0}, mode = WAVE_DATA)
CHECK_EQUAL_WAVES(entries[%fiNegSlopesPassFromRhSuAd], {1, 0, 0}, mode = WAVE_DATA)
CHECK_EQUAL_WAVES(entries[%fiNegSlopesPassFromRhSuAd], {1, 1, 1}, mode = WAVE_DATA)
CHECK_EQUAL_WAVES(entries[%fillinPassFromRhSuAd], {0, 0, 0, 0}, mode = WAVE_DATA)

// range of DAScalesFromRhSuAd times 2
Make/FREE/D minDAScaleNormRef = {6, NaN, NaN}
Make/FREE/D minDAScaleNormRef = {6}
CHECK_EQUAL_WAVES(entries[%minDaScaleNorm], minDAScaleNormRef, mode = WAVE_DATA, tol = 1e-24)

Make/FREE/D maxDAScaleNormRef = {18, NaN, NaN}
Make/FREE/D maxDAScaleNormRef = {18}
CHECK_EQUAL_WAVES(entries[%maxDaScaleNorm], maxDAScaleNormRef, mode = WAVE_DATA, tol = 1e-24)

[WAVE apFreqRef, WAVE apFreqFromRhSuAd, WAVE DAScalesFromRhSuAd, WAVE sweepPassedFRomRhSuAd] = ExtractRefValuesFromOverride(sweepNo, baselineQC = entries[%baselinePass])
Expand All @@ -2655,26 +2655,24 @@ static Function PS_DS_AD15_REENTRY([string str])
CHECK_EQUAL_WAVES(entries[%dascaleFromRhSuAd], DAScalesFromRhSuAd, mode = WAVE_DATA)
CHECK_EQUAL_WAVES(entries[%sweepPassFromRhSuAd], sweepPassedFRomRhSuAd, mode = WAVE_DATA)

Make/FREE/D maxSlopeRef = {4.444444444444444e-11, 4.444444444444444e-11, 4.444444444444444e-11}
Make/FREE/D fiSlopeRef = {4.444444444444444e-11, 4.444444444444444e-11, 4.444444444444444e-11}
Make/FREE/D fiOffsetRef = {0.5555555555555558, 0.5555555555555558, 0.5555555555555558}
Make/FREE/T futureDAScalesRef = {"RegRhSuAd:10;Reg:40;", \
"RegRhSuAd:10;Reg:40;Fillin:21;", \
"RegRhSuAd:10;Reg:40;Fillin:21;Reg:70;"}
Make/FREE/D maxSlopeRef = {0}
Make/FREE/D fiSlopeRef = {4.444444444444444e-11}
Make/FREE/D fiOffsetRef = {0.5555555555555558}
Make/FREE/T futureDAScalesRef = {"RegRhSuAd:10;"}

Make/FREE/D fiSlopesFromRhSuAdRef = {0, PSQ_DS_SKIPPED_FI_SLOPE, PSQ_DS_SKIPPED_FI_SLOPE}
Make/FREE/D fiOffsetsFromRhSuAdRef = {1, PSQ_DS_SKIPPED_FI_SLOPE, PSQ_DS_SKIPPED_FI_SLOPE}
Make/FREE/D DAScalesRef = {10, 40, 21}
Make/FREE/D fiSlopesFromRhSuAdRef = {0, 0, 0}
Make/FREE/D fiOffsetsFromRhSuAdRef = {1, 1, 1}
Make/FREE/D DAScalesRef = {1}

CHECK_EQUAL_WAVES(entries[%maxSlope], maxSlopeRef, mode = WAVE_DATA, tol = 1e-24)
CHECK_EQUAL_WAVES(entries[%fiSlope], fiSlopeRef, mode = WAVE_DATA, tol = 1e-24)
CHECK_EQUAL_WAVES(entries[%fiOffset], fiOffsetRef, mode = WAVE_DATA, tol = 1e-24)
CHECK_EQUAL_TEXTWAVES(entries[%futureDAScales], futureDAScalesRef, mode = WAVE_DATA)
CHECK_WAVE(entries[%fiSlope], NULL_WAVE)
CHECK_WAVE(entries[%fiOffset], NULL_WAVE)
CHECK_WAVE(entries[%futureDAScales], NULL_WAVE)
CHECK_EQUAL_WAVES(entries[%fiSlopesFromRhSuAd], fiSlopesFromRhSuAdRef, mode = WAVE_DATA, tol = 1e-24)
CHECK_EQUAL_WAVES(entries[%fiOffsetsFromRhSuAd], fiOffsetsFromRhSuAdRef, mode = WAVE_DATA, tol = 1e-24)
CHECK_EQUAL_WAVES(entries[%dascale], DAScalesRef, mode = WAVE_DATA, tol = 1e-24)

CHECK_EQUAL_WAVES(entries[%oorDAScale], {0, 0, NaN}, mode = WAVE_DATA)
CHECK_WAVE(entries[%oorDAScale], NULL_WAVE)

CommonAnalysisFunctionChecks(str, sweepNo, entries[%setPass])
CheckSurveyPlot(str, entries)
Expand Down

0 comments on commit ae1e170

Please sign in to comment.