@@ -1593,7 +1593,7 @@ def create_depth_map(mesh: pv.core.pointset.PolyData,
15931593 return mesh
15941594
15951595
1596- def create_depth_maps_from_gempy (geo_model , # gp.core.model,
1596+ def create_depth_maps_from_gempy (geo_model ,
15971597 surfaces : Union [str , List [str ]]) \
15981598 -> Dict [str , List [Union [pv .core .pointset .PolyData , np .ndarray , List [str ]]]]:
15991599 """Creating depth map of model surfaces, adapted from
@@ -1617,8 +1617,8 @@ def create_depth_maps_from_gempy(geo_model, # gp.core.model,
16171617
16181618 .. versionadded:: 1.0.x
16191619
1620- .. versionchanged:: 1.1
1621- Fixed an indexing bug
1620+ .. versionchanged:: 1.1.8
1621+ Ensure compatibility with GemPy>=3
16221622
16231623 Example
16241624 _______
@@ -1652,14 +1652,6 @@ def create_depth_maps_from_gempy(geo_model, # gp.core.model,
16521652 raise ModuleNotFoundError (
16531653 'GemPy package is not installed. Use pip install gempy to install the latest version' )
16541654
1655- # Checking if geo_model is a GemPy geo_model
1656- if not isinstance (geo_model , gp .core .model .Project ):
1657- raise TypeError ('geo_model must be a GemPy geo_model' )
1658-
1659- # Checking that the model was computed
1660- if all (pd .isna (geo_model .surfaces .df .vertices )) == True and all (pd .isna (geo_model .surfaces .df .edges )) == True :
1661- raise ValueError ('Model must be created before depth map extraction' )
1662-
16631655 # Checking if surface is of type string
16641656 if not isinstance (surfaces , (str , list )):
16651657 raise TypeError ('Surface name must be of type string' )
@@ -1668,28 +1660,68 @@ def create_depth_maps_from_gempy(geo_model, # gp.core.model,
16681660 if isinstance (surfaces , str ):
16691661 surfaces = [surfaces ]
16701662
1671- # Extracting surface data_df for all surfaces
1672- data_df = geo_model .surfaces .df .copy (deep = True )
1663+ # Checking if geo_model is a GemPy geo_model
1664+ try :
1665+ # GemPy<3
1666+ if not isinstance (geo_model , gp .core .model .Project ):
1667+ raise TypeError ('geo_model must be a GemPy geo_model' )
1668+
1669+ # Checking that the model was computed
1670+ if all (pd .isna (geo_model .surfaces .df .vertices )) == True and all (pd .isna (geo_model .surfaces .df .edges )) == True :
1671+ raise ValueError ('Model must be created before depth map extraction' )
1672+
1673+ # Extracting surface data_df for all surfaces
1674+ data_df = geo_model .surfaces .df .copy (deep = True )
1675+
1676+ # Checking that surfaces are valid
1677+ if not all (item in data_df .surface .unique ().tolist () for item in surfaces ):
1678+ raise ValueError ('One or more invalid surface names provided' )
1679+
1680+ # Extracting geometric data of selected surfaces
1681+ geometric_data = pd .concat ([data_df .groupby ('surface' ).get_group (group ) for group in surfaces ])
1682+
1683+ # Creating empty dict to store data
1684+ surfaces_poly = {}
1685+
1686+ for idx , val in geometric_data [['vertices' , 'edges' , 'color' , 'surface' , 'id' ]].dropna ().iterrows ():
1687+ # Creating PolyData from each surface
1688+ surf = pv .PolyData (val ['vertices' ][0 ], np .insert (val ['edges' ][0 ], 0 , 3 , axis = 1 ).ravel ())
1689+
1690+ # Append depth to PolyData
1691+ surf ['Depth [m]' ] = val ['vertices' ][0 ][:, 2 ]
1692+
1693+ # Store mesh, depth values and color values in dict
1694+ surfaces_poly [val ['surface' ]] = [surf , val ['color' ]]
1695+
1696+ except AttributeError :
1697+ # GemPy>=3
1698+ if not isinstance (geo_model , gp .core .data .geo_model .GeoModel ):
1699+ raise TypeError ('geo_model must be a GemPy geo_model' )
1700+
1701+ # TODO Add check that arrays are not empty
1702+
1703+ # Getting a list of all surfaces
1704+ list_surfaces = list (geo_model .structural_frame .element_name_id_map .keys ())
16731705
1674- # Checking that surfaces are valid
1675- if not all (item in data_df . surface . unique (). tolist () for item in surfaces ):
1676- raise ValueError ('One or more invalid surface names provided' )
1706+ # Checking that surfaces are valid
1707+ if not all (item in list_surfaces for item in surfaces ):
1708+ raise ValueError ('One or more invalid surface names provided' )
16771709
1678- # Extracting geometric data of selected surfaces
1679- geometric_data = pd . concat ([ data_df . groupby ( ' surface' ). get_group ( group ) for group in surfaces ])
1710+ # Getting indices of provided surfaces
1711+ list_indices = [ list_surfaces . index ( surface ) for surface in surfaces ]
16801712
1681- # Creating empty dict to store data
1682- surfaces_poly = {}
1713+ # Creating empty dict to store data
1714+ surfaces_poly = {}
16831715
1684- for idx , val in geometric_data [[ 'vertices' , 'edges' , 'color' , 'surface' , 'id' ]]. dropna (). iterrows () :
1685- # Creating PolyData from each surface
1686- surf = pv . PolyData ( val [ 'vertices' ][ 0 ], np .insert (val [ ' edges' ][ 0 ], 0 , 3 , axis = 1 ).ravel ())
1716+ for index in list_indices :
1717+ surf = pv . PolyData ( geo_model . solutions . raw_arrays . vertices [ index ],
1718+ np .insert (geo_model . solutions . raw_arrays . edges [ index ], 0 , 3 , axis = 1 ).ravel ())
16871719
1688- # Append depth to PolyData
1689- surf ['Depth [m]' ] = val [ ' vertices' ][ 0 ][:,2 ]
1720+ # Append depth to PolyData
1721+ surf ['Depth [m]' ] = geo_model . solutions . raw_arrays . vertices [ index ][:, 2 ]
16901722
1691- # Store mesh, depth values and color values in dict
1692- surfaces_poly [val [ 'surface' ]] = [surf , val [ 'color' ]]
1723+ # Store mesh, depth values and color values in dict
1724+ surfaces_poly [list_surfaces [ index ]] = [surf , geo_model . structural_frame . elements_colors [ index ]]
16931725
16941726 return surfaces_poly
16951727
0 commit comments