77import numpy as np
88import pandas as pd
99from typing import List
10-
10+ import pathlib
1111from ...modelling .features .fault import FaultSegment
1212
1313from ...modelling .features .builders import (
@@ -111,7 +111,6 @@ def __init__(
111111
112112
113113 """
114- # print('tet')
115114 if logfile :
116115 self .logfile = logfile
117116 log_to_file (logfile , level = loglevel )
@@ -1540,6 +1539,9 @@ def evaluate_model(self, xyz: np.ndarray, scale: bool = True) -> np.ndarray:
15401539 strat_id = np .zeros (xyz .shape [0 ], dtype = int )
15411540 # set strat id to -1 to identify which areas of the model aren't covered
15421541 strat_id [:] = - 1
1542+ if self .stratigraphic_column is None :
1543+ logger .warning ("No stratigraphic column defined" )
1544+ return strat_id
15431545 for group in reversed (self .stratigraphic_column .keys ()):
15441546 if group == "faults" :
15451547 continue
@@ -1757,6 +1759,9 @@ def stratigraphic_ids(self):
17571759 list of unique stratigraphic ids, featurename, unit name and min and max scalar values
17581760 """
17591761 ids = []
1762+ if self .stratigraphic_column is None :
1763+ logger .warning ('No stratigraphic column defined' )
1764+ return ids
17601765 for group in self .stratigraphic_column .keys ():
17611766 if group == "faults" :
17621767 continue
@@ -1777,6 +1782,8 @@ def get_stratigraphic_surfaces(self, units: List[str] = [], bottoms: bool = True
17771782 ## TODO change the stratigraphic column to its own class and have methods to get the relevant surfaces
17781783 surfaces = []
17791784 units = []
1785+ if self .stratigraphic_column is None :
1786+ return []
17801787 for group in self .stratigraphic_column .keys ():
17811788 if group == "faults" :
17821789 continue
@@ -1800,10 +1807,60 @@ def get_stratigraphic_surfaces(self, units: List[str] = [], bottoms: bool = True
18001807
18011808 return surfaces
18021809
1803- def get_block_model (self ):
1804- grid = self .bounding_box .vtk ( )
1810+ def get_block_model (self , name = 'block model' ):
1811+ grid = self .bounding_box .structured_grid ( name = name )
18051812
1806- grid .cell_data ['stratigraphy' ] = self .evaluate_model (
1813+ grid .properties_cell ['stratigraphy' ] = self .evaluate_model (
18071814 self .bounding_box .cell_centers (), scale = False
18081815 )
18091816 return grid , self .stratigraphic_ids ()
1817+
1818+ def save (
1819+ self ,
1820+ filename : str ,
1821+ block_model : bool = True ,
1822+ stratigraphic_surfaces = True ,
1823+ fault_surfaces = True ,
1824+ stratigraphic_data = True ,
1825+ fault_data = True ,
1826+ ):
1827+ path = pathlib .Path (filename )
1828+ extension = path .suffix
1829+ name = path .stem
1830+ stratigraphic_surfaces = self .get_stratigraphic_surfaces ()
1831+ if fault_surfaces :
1832+ for s in self .get_fault_surfaces ():
1833+ ## geoh5 can save everything into the same file
1834+ if extension == ".geoh5" :
1835+ s .save (filename )
1836+ else :
1837+ s .save (f'{ name } _{ s .name } .{ extension } ' )
1838+ if stratigraphic_surfaces :
1839+ for s in self .get_stratigraphic_surfaces ():
1840+ if extension == ".geoh5" :
1841+ s .save (filename )
1842+ else :
1843+ s .save (f'{ name } _{ s .name } .{ extension } ' )
1844+ if block_model :
1845+ grid , ids = self .get_block_model ()
1846+ if extension == ".geoh5" :
1847+ grid .save (filename )
1848+ else :
1849+ grid .save (f'{ name } _block_model.{ extension } ' )
1850+ if stratigraphic_data :
1851+ if self .stratigraphic_column is not None :
1852+ for group in self .stratigraphic_column .keys ():
1853+ if group == "faults" :
1854+ continue
1855+ for series in self .stratigraphic_column [group ].keys ():
1856+ if extension == ".geoh5" :
1857+ self .__getitem__ (series ).save (filename )
1858+ else :
1859+ self .__getitem__ (series ).save (f'{ name } _{ series } .{ extension } ' )
1860+ if fault_data :
1861+ for f in self .fault_names ():
1862+ for d in self .__getitem__ (f ).get_data ():
1863+ if extension == ".geoh5" :
1864+ d .save (filename )
1865+ else :
1866+ d .save (f'{ name } _{ group } .{ extension } ' )
0 commit comments