@@ -1586,7 +1586,7 @@ def create_depth_map(mesh: pv.core.pointset.PolyData,
15861586 return mesh
15871587
15881588
1589- def create_depth_maps_from_gempy (geo_model , # gp.core.model,
1589+ def create_depth_maps_from_gempy (geo_model ,
15901590 surfaces : Union [str , List [str ]]) \
15911591 -> Dict [str , List [Union [pv .core .pointset .PolyData , np .ndarray , List [str ]]]]:
15921592 """Creating depth map of model surfaces, adapted from
@@ -1610,8 +1610,8 @@ def create_depth_maps_from_gempy(geo_model, # gp.core.model,
16101610
16111611 .. versionadded:: 1.0.x
16121612
1613- .. versionchanged:: 1.1
1614- Fixed an indexing bug
1613+ .. versionchanged:: 1.1.8
1614+ Ensure compatibility with GemPy>=3
16151615
16161616 Example
16171617 _______
@@ -1645,14 +1645,6 @@ def create_depth_maps_from_gempy(geo_model, # gp.core.model,
16451645 raise ModuleNotFoundError (
16461646 'GemPy package is not installed. Use pip install gempy to install the latest version' )
16471647
1648- # Checking if geo_model is a GemPy geo_model
1649- if not isinstance (geo_model , gp .core .model .Project ):
1650- raise TypeError ('geo_model must be a GemPy geo_model' )
1651-
1652- # Checking that the model was computed
1653- if all (pd .isna (geo_model .surfaces .df .vertices )) == True and all (pd .isna (geo_model .surfaces .df .edges )) == True :
1654- raise ValueError ('Model must be created before depth map extraction' )
1655-
16561648 # Checking if surface is of type string
16571649 if not isinstance (surfaces , (str , list )):
16581650 raise TypeError ('Surface name must be of type string' )
@@ -1661,28 +1653,68 @@ def create_depth_maps_from_gempy(geo_model, # gp.core.model,
16611653 if isinstance (surfaces , str ):
16621654 surfaces = [surfaces ]
16631655
1664- # Extracting surface data_df for all surfaces
1665- data_df = geo_model .surfaces .df .copy (deep = True )
1656+ # Checking if geo_model is a GemPy geo_model
1657+ try :
1658+ # GemPy<3
1659+ if not isinstance (geo_model , gp .core .model .Project ):
1660+ raise TypeError ('geo_model must be a GemPy geo_model' )
1661+
1662+ # Checking that the model was computed
1663+ if all (pd .isna (geo_model .surfaces .df .vertices )) == True and all (pd .isna (geo_model .surfaces .df .edges )) == True :
1664+ raise ValueError ('Model must be created before depth map extraction' )
1665+
1666+ # Extracting surface data_df for all surfaces
1667+ data_df = geo_model .surfaces .df .copy (deep = True )
1668+
1669+ # Checking that surfaces are valid
1670+ if not all (item in data_df .surface .unique ().tolist () for item in surfaces ):
1671+ raise ValueError ('One or more invalid surface names provided' )
1672+
1673+ # Extracting geometric data of selected surfaces
1674+ geometric_data = pd .concat ([data_df .groupby ('surface' ).get_group (group ) for group in surfaces ])
1675+
1676+ # Creating empty dict to store data
1677+ surfaces_poly = {}
1678+
1679+ for idx , val in geometric_data [['vertices' , 'edges' , 'color' , 'surface' , 'id' ]].dropna ().iterrows ():
1680+ # Creating PolyData from each surface
1681+ surf = pv .PolyData (val ['vertices' ][0 ], np .insert (val ['edges' ][0 ], 0 , 3 , axis = 1 ).ravel ())
1682+
1683+ # Append depth to PolyData
1684+ surf ['Depth [m]' ] = val ['vertices' ][0 ][:, 2 ]
1685+
1686+ # Store mesh, depth values and color values in dict
1687+ surfaces_poly [val ['surface' ]] = [surf , val ['color' ]]
1688+
1689+ except AttributeError :
1690+ # GemPy>=3
1691+ if not isinstance (geo_model , gp .core .data .geo_model .GeoModel ):
1692+ raise TypeError ('geo_model must be a GemPy geo_model' )
1693+
1694+ # TODO Add check that arrays are not empty
1695+
1696+ # Getting a list of all surfaces
1697+ list_surfaces = list (geo_model .structural_frame .element_name_id_map .keys ())
16661698
1667- # Checking that surfaces are valid
1668- if not all (item in data_df . surface . unique (). tolist () for item in surfaces ):
1669- raise ValueError ('One or more invalid surface names provided' )
1699+ # Checking that surfaces are valid
1700+ if not all (item in list_surfaces for item in surfaces ):
1701+ raise ValueError ('One or more invalid surface names provided' )
16701702
1671- # Extracting geometric data of selected surfaces
1672- geometric_data = pd . concat ([ data_df . groupby ( ' surface' ). get_group ( group ) for group in surfaces ])
1703+ # Getting indices of provided surfaces
1704+ list_indices = [ list_surfaces . index ( surface ) for surface in surfaces ]
16731705
1674- # Creating empty dict to store data
1675- surfaces_poly = {}
1706+ # Creating empty dict to store data
1707+ surfaces_poly = {}
16761708
1677- for idx , val in geometric_data [[ 'vertices' , 'edges' , 'color' , 'surface' , 'id' ]]. dropna (). iterrows () :
1678- # Creating PolyData from each surface
1679- surf = pv . PolyData ( val [ 'vertices' ][ 0 ], np .insert (val [ ' edges' ][ 0 ], 0 , 3 , axis = 1 ).ravel ())
1709+ for index in list_indices :
1710+ surf = pv . PolyData ( geo_model . solutions . raw_arrays . vertices [ index ],
1711+ np .insert (geo_model . solutions . raw_arrays . edges [ index ], 0 , 3 , axis = 1 ).ravel ())
16801712
1681- # Append depth to PolyData
1682- surf ['Depth [m]' ] = val [ ' vertices' ][ 0 ][:,2 ]
1713+ # Append depth to PolyData
1714+ surf ['Depth [m]' ] = geo_model . solutions . raw_arrays . vertices [ index ][:, 2 ]
16831715
1684- # Store mesh, depth values and color values in dict
1685- surfaces_poly [val [ 'surface' ]] = [surf , val [ 'color' ]]
1716+ # Store mesh, depth values and color values in dict
1717+ surfaces_poly [list_surfaces [ index ]] = [surf , geo_model . structural_frame . elements_colors [ index ]]
16861718
16871719 return surfaces_poly
16881720
0 commit comments