@@ -70,6 +70,11 @@ def GetDrillholesGroup(rootGroup, verbose=False):
7070
7171def CreateObservationGroup (dataCollectionGroup ):
7272 obGroup = dataCollectionGroup .createGroup ("Observations" )
73+ obGroup .setncattr ("faultObservationIndex_MaxValid" , - 1 )
74+ obGroup .setncattr ("foldObservationIndex_MaxValid" , - 1 )
75+ obGroup .setncattr ("foliationObservationIndex_MaxValid" , - 1 )
76+ obGroup .setncattr ("discontinuityObservationIndex_MaxValid" , - 1 )
77+ obGroup .setncattr ("stratigraphicObservationIndex_MaxValid" , - 1 )
7378 obGroup .createDimension ("faultObservationIndex" , None )
7479 obGroup .createDimension ("foldObservationIndex" , None )
7580 obGroup .createDimension ("foliationObservationIndex" , None )
@@ -90,6 +95,9 @@ def CreateObservationGroup(dataCollectionGroup):
9095
9196def CreateDrillholeGroup (dataCollectionGroup ):
9297 dhGroup = dataCollectionGroup .createGroup ("Drillholes" )
98+ dhGroup .setncattr ("drillholeObservationIndex_MaxValid" , - 1 )
99+ dhGroup .setncattr ("drillholeSurveyIndex_MaxValid" , - 1 )
100+ dhGroup .setncattr ("drillholePropertyIndex_MaxValid" , - 1 )
93101 dhGroup .createDimension ("drillholeObservationIndex" , None )
94102 dhGroup .createDimension ("drillholeSurveyIndex" , None )
95103 dhGroup .createDimension ("drillholePropertyIndex" , None )
@@ -113,30 +121,31 @@ def GetObservations(root, indexName, variableName, indexList=[], indexRange=(0,
113121 print ("Getting variable " + variableName )
114122 oGroup = resp ["value" ]
115123 data = []
124+ maxValidIndex = min (oGroup .dimensions [indexName ].size , oGroup .getncattr (indexName + "_MaxValid" ))
116125 # Select all option
117126 if (indexList == [] and len (indexRange ) == 2 and indexRange [0 ] == 0
118127 and indexRange [1 ] == 0 and keyword == "" ):
119128 if verbose :
120129 print ("Getting all" )
121130 # Create list of observations as:
122131 # ((easting, northing, altitude), dipdir, dip, formation, layer)
123- for i in range (0 , oGroup . dimensions [ indexName ]. size ):
132+ for i in range (0 , maxValidIndex ):
124133 data .append ((oGroup .variables .get (variableName )[i ]))
125134 response ["value" ] = data
126135 # Select based on keyword and list of indices option
127136 elif keyword != "" and indexList != []:
128137 if verbose :
129138 print ("Getting keyword and index list" )
130139 for i in indexList :
131- if (int (i ) >= 0 and int (i ) < oGroup . dimensions [ indexName ]. size
140+ if (int (i ) >= 0 and int (i ) < maxValidIndex
132141 and oGroup .variables .get (variableName )[i ] == keyword ):
133142 data .append ((oGroup .variables .get (variableName )[i ]))
134143 response ["value" ] = data
135144 # Select based on keyword option
136145 elif keyword != "" :
137146 if verbose :
138147 print ("Getting keyword" )
139- for i in range (0 , oGroup . dimensions [ indexName ]. size ):
148+ for i in range (0 , maxValidIndex ):
140149 if oGroup .variables .get (variableName )[i ] == keyword :
141150 data .append ((oGroup .variables .get (variableName )[i ]))
142151 response ["value" ] = data
@@ -145,15 +154,15 @@ def GetObservations(root, indexName, variableName, indexList=[], indexRange=(0,
145154 if verbose :
146155 print ("Getting index list" )
147156 for i in indexList :
148- if int (i ) >= 0 and int (i ) < oGroup . dimensions [ indexName ]. size :
157+ if int (i ) >= 0 and int (i ) < maxValidIndex :
149158 data .append ((oGroup .variables .get (variableName )[i ]))
150159 response ["value" ] = data
151160 # Select based on indices range option
152161 elif len (indexRange ) == 2 and indexRange [0 ] >= 0 and indexRange [1 ] >= indexRange [0 ]:
153162 if verbose :
154163 print ("Getting index range" )
155164 for i in range (indexRange [0 ], indexRange [1 ]):
156- if int (i ) >= 0 and int (i ) < oGroup . dimensions [ indexName ]. size :
165+ if int (i ) >= 0 and int (i ) < maxValidIndex :
157166 data .append ((oGroup .variables .get (variableName )[i ]))
158167 response ["value" ] = data
159168 else :
@@ -224,13 +233,13 @@ def SetObservations(root, data, indexName, variableName, append=False, verbose=F
224233
225234 if oGroup :
226235 observationLocation = oGroup .variables [variableName ]
236+ index = 0
227237 if append :
228238 index = oGroup .dimensions [indexName ].size
229- else :
230- index = 0
231239 for i in data :
232240 observationLocation [index ] = i
233241 index += 1
242+ oGroup .setncattr (indexName + "_MaxValid" , index )
234243 else :
235244 errStr = "(ERROR) Failed to Create observations group for observations setting"
236245 if verbose :
@@ -269,37 +278,38 @@ def GetContacts(root, indexList=[], indexRange=(0, 0), keyword="", verbose=False
269278 else :
270279 group = resp ["value" ]
271280 data = []
281+ maxValidIndex = min (group .dimensions ['index' ].size , group .getncattr ("index_MaxValid" ))
272282 # Select all option
273283 if (indexList == [] and len (indexRange ) == 2 and indexRange [0 ] == 0
274284 and indexRange [1 ] == 0 and keyword == "" ):
275285 # Create list of observations as:
276286 # ((easting, northing, altitude), dipdir, dip, formation, layer)
277- for i in range (0 , group . dimensions [ 'index' ]. size ):
287+ for i in range (0 , maxValidIndex ):
278288 data .append ((group .variables .get ('contacts' )[i ]))
279289 response ["value" ] = data
280290 # Select based on keyword and list of indices option
281291 elif keyword != "" and indexList != []:
282292 for i in indexList :
283- if (int (i ) >= 0 and int (i ) < group . dimensions [ 'index' ]. size
293+ if (int (i ) >= 0 and int (i ) < maxValidIndex
284294 and group .variables .get ('layer' )[i ] == keyword ):
285295 data .append ((group .variables .get ('contacts' )[i ]))
286296 response ["value" ] = data
287297 # Select based on keyword option
288298 elif keyword != "" :
289- for i in range (0 , group . dimensions [ 'index' ]. size ):
299+ for i in range (0 , maxValidIndex ):
290300 if group .variables .get ('layer' )[i ] == keyword :
291301 data .append ((group .variables .get ('contacts' )[i ]))
292302 response ["value" ] = data
293303 # Select based on list of indices option
294304 elif indexList != []:
295305 for i in indexList :
296- if int (i ) >= 0 and int (i ) < group . dimensions [ 'index' ]. size :
306+ if int (i ) >= 0 and int (i ) < maxValidIndex :
297307 data .append ((group .variables .get ('contacts' )[i ]))
298308 response ["value" ] = data
299309 # Select based on indices range option
300310 elif len (indexRange ) == 2 and indexRange [0 ] >= 0 and indexRange [1 ] >= indexRange [0 ]:
301311 for i in range (indexRange [0 ], indexRange [1 ]):
302- if int (i ) >= 0 and int (i ) < group . dimensions [ 'index' ]. size :
312+ if int (i ) >= 0 and int (i ) < maxValidIndex :
303313 data .append ((group .variables .get ('contacts' )[i ]))
304314 response ["value" ] = data
305315 else :
@@ -346,6 +356,7 @@ def SetContacts(root, data, append=False, verbose=False):
346356 resp = GetContactsGroup (root )
347357 if resp ["errorFlag" ]:
348358 group = dcGroup .createGroup ("Contacts" )
359+ group .setncattr ("index_MaxValid" , - 1 )
349360 group .createDimension ("index" , None )
350361 contactObservationType_t = group .createCompoundType (LoopProjectFile .contactObservationType , 'contactObservation' )
351362 group .createVariable ('contacts' , contactObservationType_t , ('index' ), zlib = True , complevel = 9 )
@@ -354,13 +365,13 @@ def SetContacts(root, data, append=False, verbose=False):
354365
355366 if group :
356367 contactsLocation = group .variables ['contacts' ]
368+ index = 0
357369 if append :
358370 index = group .dimensions ['index' ].size
359- else :
360- index = 0
361371 for i in data :
362372 contactsLocation [index ] = i
363373 index += 1
374+ group .setncattr ("index_MaxValid" , index )
364375 else :
365376 errStr = "(ERROR) Failed to Create contacts group for contact setting"
366377 if verbose :
@@ -379,37 +390,38 @@ def GetDrillholeData(root, indexName, variableName, indexList=[], indexRange=(0,
379390 else :
380391 group = resp ["value" ]
381392 data = []
393+ maxValidIndex = min (group .dimensions [indexName ].size , group .getncattr (indexName + "_MaxValid" ))
382394 # Select all option
383395 if (indexList == [] and len (indexRange ) == 2 and indexRange [0 ] == 0
384396 and indexRange [1 ] == 0 and keyword == "" ):
385397 # Create list of observations as:
386398 # ((easting, northing, altitude), dipdir, dip, formation, layer)
387- for i in range (0 , group . dimensions [ indexName ]. size ):
399+ for i in range (0 , maxValidIndex ):
388400 data .append ((group .variables .get (variableName )[i ]))
389401 response ["value" ] = data
390402 # Select based on keyword and list of indices option
391403 elif keyword != "" and indexList != []:
392404 for i in indexList :
393- if (int (i ) >= 0 and int (i ) < group . dimensions [ indexName ]. size
405+ if (int (i ) >= 0 and int (i ) < maxValidIndex
394406 and group .variables .get ('layer' )[i ] == keyword ):
395407 data .append ((group .variables .get (variableName )[i ]))
396408 response ["value" ] = data
397409 # Select based on keyword option
398410 elif keyword != "" :
399- for i in range (0 , group . dimensions [ indexName ]. size ):
411+ for i in range (0 , maxValidIndex ):
400412 if group .variables .get ('layer' )[i ] == keyword :
401413 data .append ((group .variables .get (variableName )[i ]))
402414 response ["value" ] = data
403415 # Select based on list of indices option
404416 elif indexList != []:
405417 for i in indexList :
406- if int (i ) >= 0 and int (i ) < group . dimensions [ indexName ]. size :
418+ if int (i ) >= 0 and int (i ) < maxValidIndex :
407419 data .append ((group .variables .get (variableName )[i ]))
408420 response ["value" ] = data
409421 # Select based on indices range option
410422 elif len (indexRange ) == 2 and indexRange [0 ] >= 0 and indexRange [1 ] >= indexRange [0 ]:
411423 for i in range (indexRange [0 ], indexRange [1 ]):
412- if int (i ) >= 0 and int (i ) < group . dimensions [ indexName ]. size :
424+ if int (i ) >= 0 and int (i ) < maxValidIndex :
413425 data .append ((group .variables .get (variableName )[i ]))
414426 response ["value" ] = data
415427 else :
@@ -473,13 +485,13 @@ def SetDrillholeData(root, data, indexName, variableName, append=False, verbose=
473485
474486 if group :
475487 drillholeObservationsLocation = group .variables [variableName ]
488+ index = 0
476489 if append :
477490 index = group .dimensions [indexName ].size
478- else :
479- index = 0
480491 for i in data :
481492 drillholeObservationsLocation [index ] = i
482493 index += 1
494+ group .setncattr (indexName + "_MaxValid" , index )
483495 else :
484496 errStr = "(ERROR) Failed to Create drillhole group for drillhole setting"
485497 if verbose :
0 commit comments