Skip to content

Commit ba578e1

Browse files
fix: Off by one error for max valid indexes
1 parent bd568e0 commit ba578e1

File tree

3 files changed

+40
-40
lines changed

3 files changed

+40
-40
lines changed

LoopProjectFile/DataCollection.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -121,31 +121,31 @@ def GetObservations(root, indexName, variableName, indexList=[], indexRange=(0,
121121
print("Getting variable " + variableName)
122122
oGroup = resp["value"]
123123
data = []
124-
maxIndex = min(oGroup.dimensions[indexName].size, oGroup.getncattr(indexName + "_MaxValid"))
124+
maxValidIndex = min(oGroup.dimensions[indexName].size, oGroup.getncattr(indexName + "_MaxValid"))
125125
# Select all option
126126
if (indexList == [] and len(indexRange) == 2 and indexRange[0] == 0
127127
and indexRange[1] == 0 and keyword == ""):
128128
if verbose:
129129
print("Getting all")
130130
# Create list of observations as:
131131
# ((easting, northing, altitude), dipdir, dip, formation, layer)
132-
for i in range(0, maxIndex):
132+
for i in range(0, maxValidIndex):
133133
data.append((oGroup.variables.get(variableName)[i]))
134134
response["value"] = data
135135
# Select based on keyword and list of indices option
136136
elif keyword != "" and indexList != []:
137137
if verbose:
138138
print("Getting keyword and index list")
139139
for i in indexList:
140-
if (int(i) >= 0 and int(i) < maxIndex
140+
if (int(i) >= 0 and int(i) < maxValidIndex
141141
and oGroup.variables.get(variableName)[i] == keyword):
142142
data.append((oGroup.variables.get(variableName)[i]))
143143
response["value"] = data
144144
# Select based on keyword option
145145
elif keyword != "":
146146
if verbose:
147147
print("Getting keyword")
148-
for i in range(0, maxIndex):
148+
for i in range(0, maxValidIndex):
149149
if oGroup.variables.get(variableName)[i] == keyword:
150150
data.append((oGroup.variables.get(variableName)[i]))
151151
response["value"] = data
@@ -154,15 +154,15 @@ def GetObservations(root, indexName, variableName, indexList=[], indexRange=(0,
154154
if verbose:
155155
print("Getting index list")
156156
for i in indexList:
157-
if int(i) >= 0 and int(i) < maxIndex:
157+
if int(i) >= 0 and int(i) < maxValidIndex:
158158
data.append((oGroup.variables.get(variableName)[i]))
159159
response["value"] = data
160160
# Select based on indices range option
161161
elif len(indexRange) == 2 and indexRange[0] >= 0 and indexRange[1] >= indexRange[0]:
162162
if verbose:
163163
print("Getting index range")
164164
for i in range(indexRange[0], indexRange[1]):
165-
if int(i) >= 0 and int(i) < maxIndex:
165+
if int(i) >= 0 and int(i) < maxValidIndex:
166166
data.append((oGroup.variables.get(variableName)[i]))
167167
response["value"] = data
168168
else:
@@ -239,7 +239,7 @@ def SetObservations(root, data, indexName, variableName, append=False, verbose=F
239239
for i in data:
240240
observationLocation[index] = i
241241
index += 1
242-
oGroup.setncattr(indexName + "_MaxValid", index - 1)
242+
oGroup.setncattr(indexName + "_MaxValid", index)
243243
else:
244244
errStr = "(ERROR) Failed to Create observations group for observations setting"
245245
if verbose:
@@ -278,38 +278,38 @@ def GetContacts(root, indexList=[], indexRange=(0, 0), keyword="", verbose=False
278278
else:
279279
group = resp["value"]
280280
data = []
281-
maxIndex = min(group.dimensions['index'].size, group.getncattr("index_MaxValid"))
281+
maxValidIndex = min(group.dimensions['index'].size, group.getncattr("index_MaxValid"))
282282
# Select all option
283283
if (indexList == [] and len(indexRange) == 2 and indexRange[0] == 0
284284
and indexRange[1] == 0 and keyword == ""):
285285
# Create list of observations as:
286286
# ((easting, northing, altitude), dipdir, dip, formation, layer)
287-
for i in range(0, maxIndex):
287+
for i in range(0, maxValidIndex):
288288
data.append((group.variables.get('contacts')[i]))
289289
response["value"] = data
290290
# Select based on keyword and list of indices option
291291
elif keyword != "" and indexList != []:
292292
for i in indexList:
293-
if (int(i) >= 0 and int(i) < maxIndex
293+
if (int(i) >= 0 and int(i) < maxValidIndex
294294
and group.variables.get('layer')[i] == keyword):
295295
data.append((group.variables.get('contacts')[i]))
296296
response["value"] = data
297297
# Select based on keyword option
298298
elif keyword != "":
299-
for i in range(0, maxIndex):
299+
for i in range(0, maxValidIndex):
300300
if group.variables.get('layer')[i] == keyword:
301301
data.append((group.variables.get('contacts')[i]))
302302
response["value"] = data
303303
# Select based on list of indices option
304304
elif indexList != []:
305305
for i in indexList:
306-
if int(i) >= 0 and int(i) < maxIndex:
306+
if int(i) >= 0 and int(i) < maxValidIndex:
307307
data.append((group.variables.get('contacts')[i]))
308308
response["value"] = data
309309
# Select based on indices range option
310310
elif len(indexRange) == 2 and indexRange[0] >= 0 and indexRange[1] >= indexRange[0]:
311311
for i in range(indexRange[0], indexRange[1]):
312-
if int(i) >= 0 and int(i) < maxIndex:
312+
if int(i) >= 0 and int(i) < maxValidIndex:
313313
data.append((group.variables.get('contacts')[i]))
314314
response["value"] = data
315315
else:
@@ -371,7 +371,7 @@ def SetContacts(root, data, append=False, verbose=False):
371371
for i in data:
372372
contactsLocation[index] = i
373373
index += 1
374-
group.setncattr("index_MaxValid", index - 1)
374+
group.setncattr("index_MaxValid", index)
375375
else:
376376
errStr = "(ERROR) Failed to Create contacts group for contact setting"
377377
if verbose:
@@ -390,38 +390,38 @@ def GetDrillholeData(root, indexName, variableName, indexList=[], indexRange=(0,
390390
else:
391391
group = resp["value"]
392392
data = []
393-
maxIndex = min(group.dimensions[indexName].size, group.getncattr(indexName + "_MaxValid"))
393+
maxValidIndex = min(group.dimensions[indexName].size, group.getncattr(indexName + "_MaxValid"))
394394
# Select all option
395395
if (indexList == [] and len(indexRange) == 2 and indexRange[0] == 0
396396
and indexRange[1] == 0 and keyword == ""):
397397
# Create list of observations as:
398398
# ((easting, northing, altitude), dipdir, dip, formation, layer)
399-
for i in range(0, maxIndex):
399+
for i in range(0, maxValidIndex):
400400
data.append((group.variables.get(variableName)[i]))
401401
response["value"] = data
402402
# Select based on keyword and list of indices option
403403
elif keyword != "" and indexList != []:
404404
for i in indexList:
405-
if (int(i) >= 0 and int(i) < maxIndex
405+
if (int(i) >= 0 and int(i) < maxValidIndex
406406
and group.variables.get('layer')[i] == keyword):
407407
data.append((group.variables.get(variableName)[i]))
408408
response["value"] = data
409409
# Select based on keyword option
410410
elif keyword != "":
411-
for i in range(0, maxIndex):
411+
for i in range(0, maxValidIndex):
412412
if group.variables.get('layer')[i] == keyword:
413413
data.append((group.variables.get(variableName)[i]))
414414
response["value"] = data
415415
# Select based on list of indices option
416416
elif indexList != []:
417417
for i in indexList:
418-
if int(i) >= 0 and int(i) < maxIndex:
418+
if int(i) >= 0 and int(i) < maxValidIndex:
419419
data.append((group.variables.get(variableName)[i]))
420420
response["value"] = data
421421
# Select based on indices range option
422422
elif len(indexRange) == 2 and indexRange[0] >= 0 and indexRange[1] >= indexRange[0]:
423423
for i in range(indexRange[0], indexRange[1]):
424-
if int(i) >= 0 and int(i) < maxIndex:
424+
if int(i) >= 0 and int(i) < maxValidIndex:
425425
data.append((group.variables.get(variableName)[i]))
426426
response["value"] = data
427427
else:
@@ -491,7 +491,7 @@ def SetDrillholeData(root, data, indexName, variableName, append=False, verbose=
491491
for i in data:
492492
drillholeObservationsLocation[index] = i
493493
index += 1
494-
group.setncattr(indexName + "_MaxValid", index - 1)
494+
group.setncattr(indexName + "_MaxValid", index)
495495
else:
496496
errStr = "(ERROR) Failed to Create drillhole group for drillhole setting"
497497
if verbose:

LoopProjectFile/ExtractedInformation.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def SetEventLog(root, data, indexName, variableName, append=False, verbose=False
117117
for i in data:
118118
eventLocation[index] = i
119119
index += 1
120-
elGroup.setncattr(indexName + "_MaxValid", index - 1)
120+
elGroup.setncattr(indexName + "_MaxValid", index)
121121
else:
122122
errStr = "(ERROR) Failed to create event log group"
123123
if verbose:
@@ -150,24 +150,24 @@ def GetEventLog(root, indexName, variableName, indexList=[], indexRange=(0, 0),
150150
else:
151151
elGroup = resp["value"]
152152
data = []
153-
maxIndex = min(elGroup.dimensions[indexName].size, elGroup.getncattr(indexName + "_MaxValid"))
153+
maxValidIndex = min(elGroup.dimensions[indexName].size, elGroup.getncattr(indexName + "_MaxValid"))
154154
# Select all option
155155
if (indexList == [] and len(indexRange) == 2 and indexRange[0] == 0
156156
and indexRange[1] == 0):
157157
# Select all
158-
for i in range(0, maxIndex):
158+
for i in range(0, maxValidIndex):
159159
data.append((elGroup.variables.get(variableName)[i]))
160160
response["value"] = data
161161
# Select based on list of indices option
162162
elif indexList != []:
163163
for i in indexList:
164-
if int(i) >= 0 and int(i) < maxIndex:
164+
if int(i) >= 0 and int(i) < maxValidIndex:
165165
data.append((elGroup.variables.get(variableName)[i]))
166166
response["value"] = data
167167
# Select based on indices range option
168168
elif len(indexRange) == 2 and indexRange[0] >= 0 and indexRange[1] >= indexRange[0]:
169169
for i in range(indexRange[0], indexRange[1]):
170-
if int(i) >= 0 and int(i) < maxIndex:
170+
if int(i) >= 0 and int(i) < maxValidIndex:
171171
data.append((elGroup.variables.get(variableName)[i]))
172172
response["value"] = data
173173
else:
@@ -244,7 +244,7 @@ def SetStratigraphicLog(root, data, append=False, verbose=False):
244244
for i in data:
245245
stratigraphicLayersLocation[index] = i
246246
index += 1
247-
siGroup.setncattr("index_MaxValid", index - 1)
247+
siGroup.setncattr("index_MaxValid", index)
248248
else:
249249
errStr = "(ERROR) Failed to create stratigraphic log group for strata setting"
250250
if verbose:
@@ -261,24 +261,24 @@ def GetStratigraphicLog(root, indexList=[], indexRange=(0, 0), verbose=False):
261261
else:
262262
siGroup = resp["value"]
263263
data = []
264-
maxIndex = min(siGroup.dimensions['index'].size, siGroup.getncattr("index_MaxValid"))
264+
maxValidIndex = min(siGroup.dimensions['index'].size, siGroup.getncattr("index_MaxValid"))
265265
# Select all option
266266
if (indexList == [] and len(indexRange) == 2 and indexRange[0] == 0
267267
and indexRange[1] == 0):
268268
# Select all
269-
for i in range(0, maxIndex):
269+
for i in range(0, maxValidIndex):
270270
data.append((siGroup.variables.get('stratigraphicLayers')[i]))
271271
response["value"] = data
272272
# Select based on list of indices option
273273
elif indexList != []:
274274
for i in indexList:
275-
if int(i) >= 0 and int(i) < maxIndex:
275+
if int(i) >= 0 and int(i) < maxValidIndex:
276276
data.append((siGroup.variables.get('stratigraphicLayers')[i]))
277277
response["value"] = data
278278
# Select based on indices range option
279279
elif len(indexRange) == 2 and indexRange[0] >= 0 and indexRange[1] >= indexRange[0]:
280280
for i in range(indexRange[0], indexRange[1]):
281-
if int(i) >= 0 and int(i) < maxIndex:
281+
if int(i) >= 0 and int(i) < maxValidIndex:
282282
data.append((siGroup.variables.get('stratigraphicLayers')[i]))
283283
response["value"] = data
284284
else:
@@ -339,7 +339,7 @@ def SetDrillholeLog(root, data, append=False, verbose=False):
339339
for i in data:
340340
drillholeDescriptionsLocation[index] = i
341341
index += 1
342-
diGroup.setncattr("index_MaxValid", index - 1)
342+
diGroup.setncattr("index_MaxValid", index)
343343
else:
344344
errStr = "(ERROR) Failed to create drillhole description log group for setting drillhole data"
345345
if verbose:
@@ -356,24 +356,24 @@ def GetDrillholeLog(root, indexList=[], indexRange=(0, 0), verbose=False):
356356
else:
357357
diGroup = resp["value"]
358358
data = []
359-
maxIndex = min(diGroup.dimensions['index'].size, diGroup.getncattr("index_MaxValid"))
359+
maxValidIndex = min(diGroup.dimensions['index'].size, diGroup.getncattr("index_MaxValid"))
360360
# Select all option
361361
if (indexList == [] and len(indexRange) == 2 and indexRange[0] == 0
362362
and indexRange[1] == 0):
363363
# Select all
364-
for i in range(0, maxIndex):
364+
for i in range(0, maxValidIndex):
365365
data.append((diGroup.variables.get('drillholeDescriptions')[i]))
366366
response["value"] = data
367367
# Select based on list of indices option
368368
elif indexList != []:
369369
for i in indexList:
370-
if int(i) >= 0 and int(i) < maxIndex:
370+
if int(i) >= 0 and int(i) < maxValidIndex:
371371
data.append((diGroup.variables.get('drillholeDescriptions')[i]))
372372
response["value"] = data
373373
# Select based on indices range option
374374
elif len(indexRange) == 2 and indexRange[0] >= 0 and indexRange[1] >= indexRange[0]:
375375
for i in range(indexRange[0], indexRange[1]):
376-
if int(i) >= 0 and int(i) < maxIndex:
376+
if int(i) >= 0 and int(i) < maxValidIndex:
377377
data.append((diGroup.variables.get('drillholeDescriptions')[i]))
378378
response["value"] = data
379379
else:
@@ -412,7 +412,7 @@ def SetEventRelationships(root, data, append=False, verbose=False):
412412
for i in data:
413413
eventRelationshipsLocation[index] = i
414414
index += 1
415-
erGroup.setncattr("index_MaxValid", index - 1)
415+
erGroup.setncattr("index_MaxValid", index)
416416
else:
417417
errStr = "(ERROR) Failed to create event relationships group for event links"
418418
if verbose:
@@ -428,9 +428,9 @@ def GetEventRelationships(root, verbose=False):
428428
response = resp
429429
else:
430430
erGroup = resp["value"]
431-
maxIndex = min(erGroup.dimensions['index'].size, erGroup.getncattr("index_MaxValid"))
431+
maxValidIndex = min(erGroup.dimensions['index'].size, erGroup.getncattr("index_MaxValid"))
432432
data = []
433-
for i in range(0, maxIndex):
433+
for i in range(0, maxValidIndex):
434434
data.append((erGroup.variables.get('eventRelationships')[i]))
435435
response["value"] = data
436436
return response

LoopProjectFile/projectfile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ def faultOrientations(self, value: pd.DataFrame):
245245

246246
@property
247247
def faultLog(self) -> pd.DataFrame:
248-
return self.__getitem__('faultLog').set_index('name')
248+
return self.__getitem__('faultLog') # .set_index('name')
249249

250250
@faultLog.setter
251251
def faultLog(self, value: pd.DataFrame):

0 commit comments

Comments
 (0)