@@ -51,6 +51,14 @@ def GetStratigraphicInformationGroup(rootGroup, verbose=False):
5151 )
5252
5353
54+ def GetStratigraphicThicknessGroup (rootGroup , verbose = False ):
55+ resp = GetExtractedInformationGroup (rootGroup , verbose )
56+ if resp ["errorFlag" ]:
57+ return resp
58+ else :
59+ return LoopProjectFileUtils .GetGroup (resp ["value" ], "StratigraphicThickness" , verbose )
60+
61+
5462def GetDrillholeDescriptionGroup (rootGroup , verbose = False ):
5563 resp = GetExtractedInformationGroup (rootGroup , verbose )
5664 if resp ["errorFlag" ]:
@@ -255,12 +263,9 @@ def GetDiscontinuityLog(root, indexList=[], indexRange=(0, 0), verbose=False):
255263 )
256264
257265
258-
259266def SetStratigraphicLog (
260267 root ,
261268 data ,
262- thickness_calculator_data = None ,
263- thickness_calculator_active_flags = None ,
264269 append = False ,
265270 verbose = False
266271):
@@ -313,35 +318,13 @@ def SetStratigraphicLog(
313318 zlib = True ,
314319 complevel = 9 ,
315320 )
316-
317- # Define compound types for thickness calculator and active flags (list of length 5)
318- thicknessCalculatorType_t = siGroup .createCompoundType (
319- LoopProjectFile .thicknessCalculatorType , "ThicknessCalculator"
320- )
321- siGroup .createVariable (
322- "thicknessCalculator" ,
323- thicknessCalculatorType_t ,
324- zlib = True ,
325- complevel = 9 ,
326- )
327321
328- thicknessCalculatorActiveFlagsType_t = siGroup .createCompoundType (
329- LoopProjectFile .thicknessCalculatorType , "ThicknessCalculatorActiveFlags"
330- )
331- siGroup .createVariable (
332- "thicknessCalculatorActiveFlags" ,
333- thicknessCalculatorActiveFlagsType_t ,
334- zlib = True ,
335- complevel = 9 ,
336- )
337322 else :
338323 siGroup = resp ["value" ]
339324
340325 if siGroup :
341326 stratigraphicLayersLocation = siGroup .variables ["stratigraphicLayers" ]
342- thickness_calculator = siGroup .variables ["thicknessCalculator" ]
343- thickness_calculator_active_flags_var = siGroup .variables ["thicknessCalculatorActiveFlags" ]
344-
327+
345328 index = 0
346329 if append :
347330 index = siGroup .dimensions ["index" ].size
@@ -350,112 +333,134 @@ def SetStratigraphicLog(
350333 index += 1
351334 siGroup .setncattr ("index_MaxValid" , index )
352335
353- # Write thickness calculator data (must match expected structure)
354- if thickness_calculator_data :
355- for tc in thickness_calculator_data :
356- if len (tc ) != 5 :
357- errStr = "(ERROR) Each entry of thickness calculator data must be of length 5; this one is of length " + str (len (tc ))
358- if verbose :
359- print (errStr )
360- return {"errorFlag" : True , "errorString" : errStr }
361- structured_data = numpy .array ([thickness_calculator_data [0 ]], dtype = LoopProjectFile .thicknessCalculatorType )
362- thickness_calculator [:] = structured_data [0 ]
363-
364- # Write thickness calculator active flags (must match expected structure)
365- if thickness_calculator_active_flags :
366- for tcf in thickness_calculator_active_flags :
367- if len (tcf ) != 5 :
368- errStr = "(ERROR) Each entry of thickness calculator active flags must be of length 5; this one is of length " + str (len (tcf ))
369- if verbose :
370- print (errStr )
371- return {"errorFlag" : True , "errorString" : errStr }
372- structured_active_flags = numpy .array ([thickness_calculator_active_flags [0 ]], dtype = LoopProjectFile .thicknessCalculatorType )
373- thickness_calculator_active_flags_var [:] = structured_active_flags [0 ]
374-
336+
375337 else :
376338 errStr = "(ERROR) Failed to create stratigraphic log group for strata setting"
377339 if verbose :
378340 print (errStr )
379341 response = {"errorFlag" : True , "errorString" : errStr }
380-
342+
381343 return response
382344
383- def GetStratigraphicLog (
384- root ,
385- indexList = [],
386- indexRange = (0 , 0 ),
387- verbose = False
388- ):
345+
346+ def GetStratigraphicLog (root , indexList = [], indexRange = (0 , 0 ), verbose = False ):
389347 response = {"errorFlag" : False }
390348 resp = GetStratigraphicInformationGroup (root )
391-
392349 if resp ["errorFlag" ]:
393- return resp
394- siGroup = resp ["value" ]
395- data = []
396-
397- try :
398- # Get max valid index
399- maxValidIndex = min (
400- siGroup .dimensions ["index" ].size , siGroup .getncattr ("index_MaxValid" )
401- )
402-
403- # Check if variables exist in the group
404- if "thicknessCalculator" not in siGroup .variables or "thicknessCalculatorActiveFlags" not in siGroup .variables :
405- errStr = "Missing 'thicknessCalculator' or 'thicknessCalculatorActiveFlags' in the NetCDF file."
406- if verbose :
407- print (errStr )
408- return {"errorFlag" : True , "errorString" : errStr }
409-
410- # Fetch thickness calculator and active flags
411- thickness_calculator_data = siGroup .variables ["thicknessCalculator" ][:]
412- thickness_calculator_active_flags = siGroup .variables ["thicknessCalculatorActiveFlags" ][:]
413-
414- # Select all layers
415- if (
416- not indexList
417- and len (indexRange ) == 2
418- and indexRange == (0 , 0 )
419- ):
420- for i in range (maxValidIndex ):
421- data .append (siGroup .variables ["stratigraphicLayers" ][i ])
422-
423- # Select based on list of indices
424- elif indexList :
350+ response = resp
351+ else :
352+ siGroup = resp ["value" ]
353+ data = []
354+ maxValidIndex = min (siGroup .dimensions ["index" ].size , siGroup .getncattr ("index_MaxValid" ))
355+ # Select all option
356+ if indexList == [] and len (indexRange ) == 2 and indexRange [0 ] == 0 and indexRange [1 ] == 0 :
357+ # Select all
358+ for i in range (0 , maxValidIndex ):
359+ data .append ((siGroup .variables .get ("stratigraphicLayers" )[i ]))
360+ response ["value" ] = data
361+ # Select based on list of indices option
362+ elif indexList != []:
425363 for i in indexList :
426- if 0 <= int (i ) < maxValidIndex :
427- data .append (siGroup .variables ["stratigraphicLayers" ][i ])
428-
429- # Select based on index range
430- elif (
431- len (indexRange ) == 2
432- and 0 <= indexRange [0 ] < indexRange [1 ] <= maxValidIndex
433- ):
364+ if int (i ) >= 0 and int (i ) < maxValidIndex :
365+ data .append ((siGroup .variables .get ("stratigraphicLayers" )[i ]))
366+ response ["value" ] = data
367+ # Select based on indices range option
368+ elif len (indexRange ) == 2 and indexRange [0 ] >= 0 and indexRange [1 ] >= indexRange [0 ]:
434369 for i in range (indexRange [0 ], indexRange [1 ]):
435- data .append (siGroup .variables ["stratigraphicLayers" ][i ])
436-
370+ if int (i ) >= 0 and int (i ) < maxValidIndex :
371+ data .append ((siGroup .variables .get ("stratigraphicLayers" )[i ]))
372+ response ["value" ] = data
437373 else :
438- errStr = "Invalid filter option for stratigraphic log retrieval. "
374+ errStr = "Non-implemented filter option"
439375 if verbose :
440376 print (errStr )
441- return {"errorFlag" : True , "errorString" : errStr }
377+ response = {"errorFlag" : True , "errorString" : errStr }
378+ return response
442379
443- # Construct response
444- response ["value" ] = {
445- "stratigraphicLayers" : data ,
446- "thicknessCalculatorData" : thickness_calculator_data .tolist (),
447- "thicknessCalculatorActiveFlags" : thickness_calculator_active_flags .tolist (),
448- }
449380
450- except Exception as e :
451- errStr = f"(ERROR) Exception during stratigraphic log retrieval: { str (e )} "
381+ def SetStratigraphicThicknesses (root , data , headers = None ,ncols = None ,append = False , verbose = False ):
382+ response = {"errorFlag" : False }
383+ resp = GetExtractedInformationGroup (root )
384+ if resp ["errorFlag" ]:
385+ # Create Extracted Information Group as it doesn't exist
386+ eiGroup = root .createGroup ("ExtractedInformation" )
387+ else :
388+ eiGroup = resp ["value" ]
389+
390+ resp = GetStratigraphicThicknessGroup (root )
391+ if resp ["errorFlag" ]:
392+ stGroup = eiGroup .createGroup ("StratigraphicThickness" )
393+ stGroup .setncattr ("index_MaxValid" , - 1 )
394+ stGroup .createDimension ("index" , None )
395+ stratigraphicThicknessType_t = stGroup .createCompoundType (
396+ LoopProjectFile .stratigraphicThicknessType , "stratigraphicThickness"
397+ )
398+ stGroup .createVariable (
399+ "stratigraphicThicknesses" ,
400+ stratigraphicThicknessType_t ,
401+ ("index" ),
402+ zlib = True ,
403+ complevel = 9 ,
404+ )
405+ else :
406+ stGroup = resp ["value" ]
407+
408+ if stGroup :
409+ stratigraphicThicknesses = stGroup .variables ["stratigraphicThicknesses" ]
410+ if headers :
411+ stGroup .setncattr ("headers" , headers )
412+ if ncols :
413+ stGroup .setncattr ("ncols" , ncols )
414+ index = 0
415+ if append :
416+ index = stGroup .dimensions ["index" ].size
417+ for i in data :
418+ stratigraphicThicknesses [index ] = i
419+ index += 1
420+ stGroup .setncattr ("index_MaxValid" , index )
421+ else :
422+ errStr = "(ERROR) Failed to create stratigraphic log group for strata setting"
452423 if verbose :
453424 print (errStr )
454- return {"errorFlag" : True , "errorString" : errStr }
425+ response = {"errorFlag" : True , "errorString" : errStr }
455426
456427 return response
457428
458429
430+ def GetStratigraphicThicknesses (root , indexList = [], indexRange = (0 , 0 ), verbose = False ):
431+ response = {"errorFlag" : False }
432+ resp = GetStratigraphicThicknessGroup (root )
433+ if resp ["errorFlag" ]:
434+ response = resp
435+ else :
436+ siGroup = resp ["value" ]
437+ data = []
438+ maxValidIndex = min (siGroup .dimensions ["index" ].size , siGroup .getncattr ("index_MaxValid" ))
439+ # Select all option
440+ response ['attributes' ] = {a :siGroup .getncattr (a ) for a in siGroup .ncattrs ()}
441+ if indexList == [] and len (indexRange ) == 2 and indexRange [0 ] == 0 and indexRange [1 ] == 0 :
442+ # Select all
443+ for i in range (0 , maxValidIndex ):
444+ data .append ((siGroup .variables .get ("stratigraphicThicknesses" )[i ]))
445+ response ["value" ] = data
446+ # Select based on list of indices option
447+ elif indexList != []:
448+ for i in indexList :
449+ if int (i ) >= 0 and int (i ) < maxValidIndex :
450+ data .append ((siGroup .variables .get ("stratigraphicThicknesses" )[i ]))
451+ response ["value" ] = data
452+ # Select based on indices range option
453+ elif len (indexRange ) == 2 and indexRange [0 ] >= 0 and indexRange [1 ] >= indexRange [0 ]:
454+ for i in range (indexRange [0 ], indexRange [1 ]):
455+ if int (i ) >= 0 and int (i ) < maxValidIndex :
456+ data .append ((siGroup .variables .get ("stratigraphicThicknesses" )[i ]))
457+ response ["value" ] = data
458+ else :
459+ errStr = "Non-implemented filter option"
460+ if verbose :
461+ print (errStr )
462+ response = {"errorFlag" : True , "errorString" : errStr }
463+ return response
459464
460465
461466# Set drillhole log
0 commit comments