@@ -1593,7 +1593,7 @@ def create_depth_map(mesh: pv.core.pointset.PolyData,
1593
1593
return mesh
1594
1594
1595
1595
1596
- def create_depth_maps_from_gempy (geo_model , # gp.core.model,
1596
+ def create_depth_maps_from_gempy (geo_model ,
1597
1597
surfaces : Union [str , List [str ]]) \
1598
1598
-> Dict [str , List [Union [pv .core .pointset .PolyData , np .ndarray , List [str ]]]]:
1599
1599
"""Creating depth map of model surfaces, adapted from
@@ -1617,8 +1617,8 @@ def create_depth_maps_from_gempy(geo_model, # gp.core.model,
1617
1617
1618
1618
.. versionadded:: 1.0.x
1619
1619
1620
- .. versionchanged:: 1.1
1621
- Fixed an indexing bug
1620
+ .. versionchanged:: 1.1.8
1621
+ Ensure compatibility with GemPy>=3
1622
1622
1623
1623
Example
1624
1624
_______
@@ -1652,14 +1652,6 @@ def create_depth_maps_from_gempy(geo_model, # gp.core.model,
1652
1652
raise ModuleNotFoundError (
1653
1653
'GemPy package is not installed. Use pip install gempy to install the latest version' )
1654
1654
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
-
1663
1655
# Checking if surface is of type string
1664
1656
if not isinstance (surfaces , (str , list )):
1665
1657
raise TypeError ('Surface name must be of type string' )
@@ -1668,28 +1660,68 @@ def create_depth_maps_from_gempy(geo_model, # gp.core.model,
1668
1660
if isinstance (surfaces , str ):
1669
1661
surfaces = [surfaces ]
1670
1662
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 ())
1673
1705
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' )
1677
1709
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 ]
1680
1712
1681
- # Creating empty dict to store data
1682
- surfaces_poly = {}
1713
+ # Creating empty dict to store data
1714
+ surfaces_poly = {}
1683
1715
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 ())
1687
1719
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 ]
1690
1722
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 ]]
1693
1725
1694
1726
return surfaces_poly
1695
1727
0 commit comments