Skip to content

Commit

Permalink
PSQ_DS_AddDAScaleFillinBetweenPosAndNegSlope: Fix neg pos fillin
Browse files Browse the repository at this point in the history
We need to search for a change of the f-I neg slope QC, so going from 0 to
1. Unfortunately FindSequence has a bug when reverse searching, so we need
to workaround that.
  • Loading branch information
t-b committed Feb 5, 2025
1 parent 32d7507 commit 82df058
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
26 changes: 18 additions & 8 deletions Packages/MIES/MIES_AnalysisFunctions_PatchSeq.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -3246,9 +3246,12 @@ static Function PSQ_DS_NegativefISlopePassingCriteria(WAVE numericalValues, WAVE
return 0
End

/// @brief Add fillin value between the last positive f-I slope and the next negative f-I slope
///
/// @retval zero if a value could be added, one if not
static Function PSQ_DS_AddDAScaleFillinBetweenPosAndNegSlope(string device, variable sweepNo, variable headstage, [variable fromRhSuAd])

variable emptySCI, numFitSlopes, i, numEntries
variable emptySCI, numFitSlopes, idx
string type, msg
variable centerDASCale = NaN

Expand All @@ -3264,16 +3267,23 @@ static Function PSQ_DS_AddDAScaleFillinBetweenPosAndNegSlope(string device, vari
[WAVE negSlopePassed, emptySCI] = PSQ_DS_GetLabnotebookData(numericalValues, textualValues, sweepNo, headstage, PSQ_DS_FI_NEG_SLOPE_PASS, fromRhSuAd = fromRhSuAd)
[WAVE DAScale, emptySCI] = PSQ_DS_GetLabnotebookData(numericalValues, textualValues, sweepNo, headstage, PSQ_DS_DASCALE, fromRhSuAd = fromRhSuAd)

numEntries = DimSize(DAScale, ROWS)
ASSERT(numEntries == (DimSize(negSlopePassed, ROWS) + 1), "Non-matching negSlopePassedAll and DAScale waves")
InsertPoints/V=(NaN) 0, 1, negSlopePassed

ASSERT(DimSize(DAScale, ROWS) == DimSize(negSlopePassed, ROWS), "Non-matching negSlopePassed and DAScale waves")

[WAVE DAScaleSorted, WAVE negSlopePassedSorted] = SortKeyAndData(DAScale, negSlopePassed)
WaveClear DAScale, negSlopePassed

Make/FREE seq = {0, 1}
idx = FindSequenceReverseWrapper(seq, negSlopePassedSorted)

FindValue/R/V=(0) negSlopePassed
if(V_Value >= 0)
centerDAScale = round((DAScale[V_Value] + DAScale[V_Value + 1]) / 2)
if(idx >= 0)
// -1 because negSlopePassedSorted is calculated for two sweeps
centerDAScale = round((DAScaleSorted[idx - (idx == 0 ? 0 : 1)] + DAScaleSorted[idx]) / 2)
endif

#ifdef DEBUGGING_ENABLED
sprintf msg, "centerDAScale %g: DAScales=%s; fitSlopes=%s", centerDAScale, NumericWaveToList(DAScale, ", ", trailSep = 0), NumericWaveToList(negSlopePassed, ", ", trailSep = 0)
sprintf msg, "centerDAScale %g: idx=%g; DAScales=%s; negSlopePassed=%s", centerDAScale, idx, NumericWaveToList(DAScaleSorted, ", ", trailSep = 0), NumericWaveToList(negSlopePassedSorted, ", ", trailSep = 0)
DEBUGPRINT(msg)
#endif

Expand All @@ -3283,7 +3293,7 @@ static Function PSQ_DS_AddDAScaleFillinBetweenPosAndNegSlope(string device, vari
return 1
endif

if(IsFinite(GetRowIndex(DASCale, val = centerDAScale)))
if(IsFinite(GetRowIndex(DAScaleSorted, val = centerDAScale)))
// already measured, do nothing
return 1
endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2658,7 +2658,6 @@ static Function PS_DS_AD15_REENTRY([string str])
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, 0, 0}
Make/FREE/D fiOffsetsFromRhSuAdRef = {1, 1, 1}
Expand Down

0 comments on commit 82df058

Please sign in to comment.