Skip to content

Commit

Permalink
Merge pull request #2097 from AllenInstitute/bugfix/2097-fix_lnb_swee…
Browse files Browse the repository at this point in the history
…pnumber_overlap_readout

Bugfix: lnb sweepnumber overlap readout
  • Loading branch information
t-b authored Apr 29, 2024
2 parents cb86624 + 2da872d commit 78fcd16
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 37 deletions.
82 changes: 46 additions & 36 deletions Packages/MIES/MIES_MiesUtilities.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -532,28 +532,28 @@ Function/S GetPanelControl(channelIndex, channelType, controlType)
End

/// @brief Find the first and last point index of a consecutive range of
/// values in the labnotebook
/// values in the labnotebook, searches the range from the back
///
/// @param[in] wv wave to search
/// @param[in] col column to look for
/// @param[in] val value to search
/// @param[in] forwardORBackward find the first(1) or last(0) range
/// @param[in] entrySourceType type of the labnotebook entry, one of @ref DataAcqModes
/// @param[out] first point index of the beginning of the range
/// @param[out] last point index of the end of the range
threadsafe static Function FindRange(wv, col, val, forwardORBackward, entrySourceType, first, last)
threadsafe static Function FindRange(wv, col, val, entrySourceType, first, last)
WAVE wv
variable col, val, forwardORBackward, entrySourceType
variable col, val, entrySourceType
variable &first, &last

variable numRows, i, sourceTypeCol, firstRow, lastRow
variable numRows, i, j, sourceTypeCol, firstRow, lastRow, isNumeric, index

first = NaN
last = NaN
first = NaN
last = NaN
isNumeric = IsNumericWave(wv)

// still correct without startLayer/endLayer coordinates
// as we always have sweepNumber/etc. in the first layer
if(IsNaN(val) && IsNumericWave(wv))
if(IsNaN(val) && isNumeric)
WAVE/Z indizesSetting = FindIndizes(wv, col = col, prop = PROP_EMPTY)
else
WAVE/Z indizesSetting = FindIndizes(wv, col = col, var = val)
Expand All @@ -563,8 +563,8 @@ threadsafe static Function FindRange(wv, col, val, forwardORBackward, entrySourc
return NaN
endif

sourceTypeCol = FindDimLabel(wv, COLS, "EntrySourceType")
if(IsFinite(entrySourceType))
sourceTypeCol = FindDimLabel(wv, COLS, "EntrySourceType")

if(sourceTypeCol >= 0) // labnotebook has a entrySourceType column
[firstRow, lastRow] = WaveMinAndMax(indizesSetting)
Expand Down Expand Up @@ -614,33 +614,33 @@ threadsafe static Function FindRange(wv, col, val, forwardORBackward, entrySourc
return NaN
endif

if(forwardORBackward)

first = indizes[0]
last = indizes[0]

for(i = 1; i < numRows; i += 1)
// a forward search stops after the end of the first sequence
if(indizes[i] > last + 1)
return NaN
endif

last = indizes[i]
endfor
else
if(!IsNumeric)
WAVE/T wt = wv
endif

first = indizes[numRows - 1]
last = indizes[numRows - 1]
first = indizes[numRows - 1]
last = indizes[numRows - 1]

for(i = numRows - 2; i >= 0; i -= 1)
// a backward search stops when the beginning of the last sequence was found
if(indizes[i] < first - 1)
return NaN
for(i = numRows - 2; i >= 0; i -= 1)
index = indizes[i]
// a backward search stops when the beginning of the last sequence was found
if(index < first - 1)
if(IsNumeric)
for(j = index + 1; j < first; j += 1)
if(!IsNaN(wv[j][sourceTypeCol][0]))
return NaN
endif
endfor
else
for(j = index + 1; j < first; j += 1)
if(!IsEmpty(wt[j][sourceTypeCol][0]))
return NaN
endif
endfor
endif

first = indizes[i]
endfor
endif
endif
first = index
endfor
End

/// @brief Test helper to enforce that every query done for an INDEP_HEADSTAGE setting
Expand Down Expand Up @@ -1157,7 +1157,7 @@ threadsafe Function/WAVE GetLastSettingNoCache(values, sweepNo, setting, entrySo
variable settingCol, numLayers, i, sweepCol, numEntries
variable firstValue, lastValue, sourceTypeCol, peakResistanceCol, pulseDurationCol
variable testpulseBlockLength, blockType, hasValidTPPulseDurationEntry
variable mode
variable mode, sweepNoInLNB

if(!ParamIsDefault(rowIndex))
rowIndex = LABNOTEBOOK_MISSING_VALUE
Expand All @@ -1184,9 +1184,9 @@ threadsafe Function/WAVE GetLastSettingNoCache(values, sweepNo, setting, entrySo
return $""
endif

sweepCol = GetSweepColumn(values)
if(mode == GET_LB_MODE_NONE || mode == GET_LB_MODE_WRITE)
sweepCol = GetSweepColumn(values)
FindRange(values, sweepCol, sweepNo, 0, entrySourceType, firstValue, lastValue)
FindRange(values, sweepCol, sweepNo, entrySourceType, firstValue, lastValue)

if(!IsFinite(firstValue) && !IsFinite(lastValue)) // sweep number is unknown
return $""
Expand All @@ -1209,6 +1209,12 @@ threadsafe Function/WAVE GetLastSettingNoCache(values, sweepNo, setting, entrySo
Make/FREE/N=(numLayers) lengths

for(i = lastValue; i >= firstValue; i -= 1)

sweepNoInLNB = str2num(textualValues[i][sweepCol][0])
if(!IsNaN(sweepNoInLNB) && sweepNoInLNB != sweepNo)
continue
endif

if(IsFinite(entrySourceType))
if(!sourceTypeCol)
sourceTypeCol = FindDimLabel(textualValues, COLS, "EntrySourceType")
Expand Down Expand Up @@ -1245,6 +1251,10 @@ threadsafe Function/WAVE GetLastSettingNoCache(values, sweepNo, setting, entrySo

for(i = lastValue; i >= firstValue; i -= 1)

if(!IsNaN(sweepNo) && numericalValues[i][sweepCol][0] != sweepNo)
continue
endif

if(IsFinite(entrySourceType))
if(!sourceTypeCol)
sourceTypeCol = FindDimLabel(numericalValues, COLS, "EntrySourceType")
Expand Down
2 changes: 1 addition & 1 deletion Packages/MIES/MIES_WaveDataFolderGetters.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -2047,7 +2047,7 @@ threadsafe Function/WAVE GetLBRowCache(values)
variable actual, sweepNo, first, last
string key, name

variable versionOfNewWave = 5
variable versionOfNewWave = 6

actual = WaveModCountWrapper(values)
name = GetWavesDataFolder(values, 2)
Expand Down
Binary file modified Packages/tests/Basic/Basic.pxp
Binary file not shown.
14 changes: 14 additions & 0 deletions Packages/tests/Basic/UTF_Labnotebook.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,20 @@ Function GetLastSettingFindsNaNSweep()
CHECK_EQUAL_WAVES(settings, settingsRef, mode = WAVE_DATA, tol = 1e-13)
End

static Function GetLastSettingFindsWithinNonConsecutiveSweepOrder()

string key
variable chunkPassed
variable sweepNo = 41
DFREF dfr = root:Labnotebook_misc:

WAVE/SDFR=dfr numericalValuesTest

key = CreateAnaFuncLBNKey(PSQ_RHEOBASE, PSQ_FMT_LBN_CHUNK_PASS, chunk = 0, query = 1)
chunkPassed = GetLastSettingIndep(numericalValuesTest, sweepNo, key, UNKNOWN_MODE, defValue = NaN)
CHECK_EQUAL_VAR(chunkPassed, 0)
End

Function GetLastSettingQueryWoMatch()

variable first, last
Expand Down

0 comments on commit 78fcd16

Please sign in to comment.