Skip to content

Commit 78fcd16

Browse files
authored
Merge pull request #2097 from AllenInstitute/bugfix/2097-fix_lnb_sweepnumber_overlap_readout
Bugfix: lnb sweepnumber overlap readout
2 parents cb86624 + 2da872d commit 78fcd16

File tree

4 files changed

+61
-37
lines changed

4 files changed

+61
-37
lines changed

Packages/MIES/MIES_MiesUtilities.ipf

Lines changed: 46 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -532,28 +532,28 @@ Function/S GetPanelControl(channelIndex, channelType, controlType)
532532
End
533533

534534
/// @brief Find the first and last point index of a consecutive range of
535-
/// values in the labnotebook
535+
/// values in the labnotebook, searches the range from the back
536536
///
537537
/// @param[in] wv wave to search
538538
/// @param[in] col column to look for
539539
/// @param[in] val value to search
540-
/// @param[in] forwardORBackward find the first(1) or last(0) range
541540
/// @param[in] entrySourceType type of the labnotebook entry, one of @ref DataAcqModes
542541
/// @param[out] first point index of the beginning of the range
543542
/// @param[out] last point index of the end of the range
544-
threadsafe static Function FindRange(wv, col, val, forwardORBackward, entrySourceType, first, last)
543+
threadsafe static Function FindRange(wv, col, val, entrySourceType, first, last)
545544
WAVE wv
546-
variable col, val, forwardORBackward, entrySourceType
545+
variable col, val, entrySourceType
547546
variable &first, &last
548547

549-
variable numRows, i, sourceTypeCol, firstRow, lastRow
548+
variable numRows, i, j, sourceTypeCol, firstRow, lastRow, isNumeric, index
550549

551-
first = NaN
552-
last = NaN
550+
first = NaN
551+
last = NaN
552+
isNumeric = IsNumericWave(wv)
553553

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

566+
sourceTypeCol = FindDimLabel(wv, COLS, "EntrySourceType")
566567
if(IsFinite(entrySourceType))
567-
sourceTypeCol = FindDimLabel(wv, COLS, "EntrySourceType")
568568

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

617-
if(forwardORBackward)
618-
619-
first = indizes[0]
620-
last = indizes[0]
621-
622-
for(i = 1; i < numRows; i += 1)
623-
// a forward search stops after the end of the first sequence
624-
if(indizes[i] > last + 1)
625-
return NaN
626-
endif
627-
628-
last = indizes[i]
629-
endfor
630-
else
617+
if(!IsNumeric)
618+
WAVE/T wt = wv
619+
endif
631620

632-
first = indizes[numRows - 1]
633-
last = indizes[numRows - 1]
621+
first = indizes[numRows - 1]
622+
last = indizes[numRows - 1]
634623

635-
for(i = numRows - 2; i >= 0; i -= 1)
636-
// a backward search stops when the beginning of the last sequence was found
637-
if(indizes[i] < first - 1)
638-
return NaN
624+
for(i = numRows - 2; i >= 0; i -= 1)
625+
index = indizes[i]
626+
// a backward search stops when the beginning of the last sequence was found
627+
if(index < first - 1)
628+
if(IsNumeric)
629+
for(j = index + 1; j < first; j += 1)
630+
if(!IsNaN(wv[j][sourceTypeCol][0]))
631+
return NaN
632+
endif
633+
endfor
634+
else
635+
for(j = index + 1; j < first; j += 1)
636+
if(!IsEmpty(wt[j][sourceTypeCol][0]))
637+
return NaN
638+
endif
639+
endfor
639640
endif
640-
641-
first = indizes[i]
642-
endfor
643-
endif
641+
endif
642+
first = index
643+
endfor
644644
End
645645

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

11621162
if(!ParamIsDefault(rowIndex))
11631163
rowIndex = LABNOTEBOOK_MISSING_VALUE
@@ -1184,9 +1184,9 @@ threadsafe Function/WAVE GetLastSettingNoCache(values, sweepNo, setting, entrySo
11841184
return $""
11851185
endif
11861186

1187+
sweepCol = GetSweepColumn(values)
11871188
if(mode == GET_LB_MODE_NONE || mode == GET_LB_MODE_WRITE)
1188-
sweepCol = GetSweepColumn(values)
1189-
FindRange(values, sweepCol, sweepNo, 0, entrySourceType, firstValue, lastValue)
1189+
FindRange(values, sweepCol, sweepNo, entrySourceType, firstValue, lastValue)
11901190

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

12111211
for(i = lastValue; i >= firstValue; i -= 1)
1212+
1213+
sweepNoInLNB = str2num(textualValues[i][sweepCol][0])
1214+
if(!IsNaN(sweepNoInLNB) && sweepNoInLNB != sweepNo)
1215+
continue
1216+
endif
1217+
12121218
if(IsFinite(entrySourceType))
12131219
if(!sourceTypeCol)
12141220
sourceTypeCol = FindDimLabel(textualValues, COLS, "EntrySourceType")
@@ -1245,6 +1251,10 @@ threadsafe Function/WAVE GetLastSettingNoCache(values, sweepNo, setting, entrySo
12451251

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

1254+
if(!IsNaN(sweepNo) && numericalValues[i][sweepCol][0] != sweepNo)
1255+
continue
1256+
endif
1257+
12481258
if(IsFinite(entrySourceType))
12491259
if(!sourceTypeCol)
12501260
sourceTypeCol = FindDimLabel(numericalValues, COLS, "EntrySourceType")

Packages/MIES/MIES_WaveDataFolderGetters.ipf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2047,7 +2047,7 @@ threadsafe Function/WAVE GetLBRowCache(values)
20472047
variable actual, sweepNo, first, last
20482048
string key, name
20492049

2050-
variable versionOfNewWave = 5
2050+
variable versionOfNewWave = 6
20512051

20522052
actual = WaveModCountWrapper(values)
20532053
name = GetWavesDataFolder(values, 2)

Packages/tests/Basic/Basic.pxp

2.18 KB
Binary file not shown.

Packages/tests/Basic/UTF_Labnotebook.ipf

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,20 @@ Function GetLastSettingFindsNaNSweep()
150150
CHECK_EQUAL_WAVES(settings, settingsRef, mode = WAVE_DATA, tol = 1e-13)
151151
End
152152

153+
static Function GetLastSettingFindsWithinNonConsecutiveSweepOrder()
154+
155+
string key
156+
variable chunkPassed
157+
variable sweepNo = 41
158+
DFREF dfr = root:Labnotebook_misc:
159+
160+
WAVE/SDFR=dfr numericalValuesTest
161+
162+
key = CreateAnaFuncLBNKey(PSQ_RHEOBASE, PSQ_FMT_LBN_CHUNK_PASS, chunk = 0, query = 1)
163+
chunkPassed = GetLastSettingIndep(numericalValuesTest, sweepNo, key, UNKNOWN_MODE, defValue = NaN)
164+
CHECK_EQUAL_VAR(chunkPassed, 0)
165+
End
166+
153167
Function GetLastSettingQueryWoMatch()
154168

155169
variable first, last

0 commit comments

Comments
 (0)