22import LoopProjectFile
33import LoopProjectFile .LoopProjectFileUtils as LoopProjectFileUtils
44
5- # import numpy
65
76
87# Check Extracted Information valid if present
@@ -51,6 +50,14 @@ def GetStratigraphicInformationGroup(rootGroup, verbose=False):
5150 )
5251
5352
53+ def GetStratigraphicThicknessGroup (rootGroup , verbose = False ):
54+ resp = GetExtractedInformationGroup (rootGroup , verbose )
55+ if resp ["errorFlag" ]:
56+ return resp
57+ else :
58+ return LoopProjectFileUtils .GetGroup (resp ["value" ], "StratigraphicThickness" , verbose )
59+
60+
5461def GetDrillholeDescriptionGroup (rootGroup , verbose = False ):
5562 resp = GetExtractedInformationGroup (rootGroup , verbose )
5663 if resp ["errorFlag" ]:
@@ -255,8 +262,12 @@ def GetDiscontinuityLog(root, indexList=[], indexRange=(0, 0), verbose=False):
255262 )
256263
257264
258- # Set stratigraphic log
259- def SetStratigraphicLog (root , data , append = False , verbose = False ):
265+ def SetStratigraphicLog (
266+ root ,
267+ data ,
268+ append = False ,
269+ verbose = False
270+ ):
260271 """
261272 **SetStratigraphicLog** - Saves a list of strata in (formation,
262273 thickness) format into the netCDF Loop Project File
@@ -267,15 +278,19 @@ def SetStratigraphicLog(root, data, append=False, verbose=False):
267278 The root group node of a Loop Project File
268279 data: list of (formation, thickness)
269280 The data to save
281+ thickness_calculator_data: list of tuples
282+ Labels for thickness calculators (e.g., [('Label1', 'Label2', ...)])
283+ thickness_calculator_active_flags: list of tuples
284+ Flags for active thickness calculators (e.g., [('None', 'Active', ...)])
270285 append: bool
271286 Flag of whether to append new data to existing log
272287 verbose: bool
273288 A flag to indicate a higher level of console logging (more if True)
274289
275290 Returns
276291 -------
277- dict {"errorFlag", "errorString"}
278- errorString exist and contains error message only when errorFlag is
292+ dict {"errorFlag", "errorString"}
293+ errorString exists and contains error message only when errorFlag is
279294 True
280295
281296 """
@@ -302,23 +317,28 @@ def SetStratigraphicLog(root, data, append=False, verbose=False):
302317 zlib = True ,
303318 complevel = 9 ,
304319 )
320+
305321 else :
306322 siGroup = resp ["value" ]
307323
308324 if siGroup :
309325 stratigraphicLayersLocation = siGroup .variables ["stratigraphicLayers" ]
326+
310327 index = 0
311328 if append :
312329 index = siGroup .dimensions ["index" ].size
313330 for i in data :
314331 stratigraphicLayersLocation [index ] = i
315332 index += 1
316333 siGroup .setncattr ("index_MaxValid" , index )
334+
335+
317336 else :
318337 errStr = "(ERROR) Failed to create stratigraphic log group for strata setting"
319338 if verbose :
320339 print (errStr )
321340 response = {"errorFlag" : True , "errorString" : errStr }
341+
322342 return response
323343
324344
@@ -330,16 +350,9 @@ def GetStratigraphicLog(root, indexList=[], indexRange=(0, 0), verbose=False):
330350 else :
331351 siGroup = resp ["value" ]
332352 data = []
333- maxValidIndex = min (
334- siGroup .dimensions ["index" ].size , siGroup .getncattr ("index_MaxValid" )
335- )
353+ maxValidIndex = min (siGroup .dimensions ["index" ].size , siGroup .getncattr ("index_MaxValid" ))
336354 # Select all option
337- if (
338- indexList == []
339- and len (indexRange ) == 2
340- and indexRange [0 ] == 0
341- and indexRange [1 ] == 0
342- ):
355+ if indexList == [] and len (indexRange ) == 2 and indexRange [0 ] == 0 and indexRange [1 ] == 0 :
343356 # Select all
344357 for i in range (0 , maxValidIndex ):
345358 data .append ((siGroup .variables .get ("stratigraphicLayers" )[i ]))
@@ -351,11 +364,7 @@ def GetStratigraphicLog(root, indexList=[], indexRange=(0, 0), verbose=False):
351364 data .append ((siGroup .variables .get ("stratigraphicLayers" )[i ]))
352365 response ["value" ] = data
353366 # Select based on indices range option
354- elif (
355- len (indexRange ) == 2
356- and indexRange [0 ] >= 0
357- and indexRange [1 ] >= indexRange [0 ]
358- ):
367+ elif len (indexRange ) == 2 and indexRange [0 ] >= 0 and indexRange [1 ] >= indexRange [0 ]:
359368 for i in range (indexRange [0 ], indexRange [1 ]):
360369 if int (i ) >= 0 and int (i ) < maxValidIndex :
361370 data .append ((siGroup .variables .get ("stratigraphicLayers" )[i ]))
@@ -368,6 +377,91 @@ def GetStratigraphicLog(root, indexList=[], indexRange=(0, 0), verbose=False):
368377 return response
369378
370379
380+ def SetStratigraphicThicknesses (root , data , headers = None ,ncols = None ,append = False , verbose = False ):
381+ response = {"errorFlag" : False }
382+ resp = GetExtractedInformationGroup (root )
383+ if resp ["errorFlag" ]:
384+ # Create Extracted Information Group as it doesn't exist
385+ eiGroup = root .createGroup ("ExtractedInformation" )
386+ else :
387+ eiGroup = resp ["value" ]
388+
389+ resp = GetStratigraphicThicknessGroup (root )
390+ if resp ["errorFlag" ]:
391+ stGroup = eiGroup .createGroup ("StratigraphicThickness" )
392+ stGroup .setncattr ("index_MaxValid" , - 1 )
393+ stGroup .createDimension ("index" , None )
394+ stratigraphicThicknessType_t = stGroup .createCompoundType (
395+ LoopProjectFile .stratigraphicThicknessType , "stratigraphicThickness"
396+ )
397+ stGroup .createVariable (
398+ "stratigraphicThicknesses" ,
399+ stratigraphicThicknessType_t ,
400+ ("index" ),
401+ zlib = True ,
402+ complevel = 9 ,
403+ )
404+ else :
405+ stGroup = resp ["value" ]
406+
407+ if stGroup :
408+ stratigraphicThicknesses = stGroup .variables ["stratigraphicThicknesses" ]
409+ if headers :
410+ stGroup .setncattr ("headers" , headers )
411+ if ncols :
412+ stGroup .setncattr ("ncols" , ncols )
413+ index = 0
414+ if append :
415+ index = stGroup .dimensions ["index" ].size
416+ for i in data :
417+ stratigraphicThicknesses [index ] = i
418+ index += 1
419+ stGroup .setncattr ("index_MaxValid" , index )
420+ else :
421+ errStr = "(ERROR) Failed to create stratigraphic log group for strata setting"
422+ if verbose :
423+ print (errStr )
424+ response = {"errorFlag" : True , "errorString" : errStr }
425+
426+ return response
427+
428+
429+ def GetStratigraphicThicknesses (root , indexList = [], indexRange = (0 , 0 ), verbose = False ):
430+ response = {"errorFlag" : False }
431+ resp = GetStratigraphicThicknessGroup (root )
432+ if resp ["errorFlag" ]:
433+ response = resp
434+ else :
435+ siGroup = resp ["value" ]
436+ data = []
437+ maxValidIndex = min (siGroup .dimensions ["index" ].size , siGroup .getncattr ("index_MaxValid" ))
438+ # Select all option
439+ response ['attributes' ] = {a :siGroup .getncattr (a ) for a in siGroup .ncattrs ()}
440+ if indexList == [] and len (indexRange ) == 2 and indexRange [0 ] == 0 and indexRange [1 ] == 0 :
441+ # Select all
442+ for i in range (0 , maxValidIndex ):
443+ data .append ((siGroup .variables .get ("stratigraphicThicknesses" )[i ]))
444+ response ["value" ] = data
445+ # Select based on list of indices option
446+ elif indexList != []:
447+ for i in indexList :
448+ if int (i ) >= 0 and int (i ) < maxValidIndex :
449+ data .append ((siGroup .variables .get ("stratigraphicThicknesses" )[i ]))
450+ response ["value" ] = data
451+ # Select based on indices range option
452+ elif len (indexRange ) == 2 and indexRange [0 ] >= 0 and indexRange [1 ] >= indexRange [0 ]:
453+ for i in range (indexRange [0 ], indexRange [1 ]):
454+ if int (i ) >= 0 and int (i ) < maxValidIndex :
455+ data .append ((siGroup .variables .get ("stratigraphicThicknesses" )[i ]))
456+ response ["value" ] = data
457+ else :
458+ errStr = "Non-implemented filter option"
459+ if verbose :
460+ print (errStr )
461+ response = {"errorFlag" : True , "errorString" : errStr }
462+ return response
463+
464+
371465# Set drillhole log
372466def SetDrillholeLog (root , data , append = False , verbose = False ):
373467 """
0 commit comments