Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] gg.visualization.create_depth_maps_from_gempy ValueError #288

Closed
hntig opened this issue Jul 24, 2023 · 5 comments
Closed

[BUG] gg.visualization.create_depth_maps_from_gempy ValueError #288

hntig opened this issue Jul 24, 2023 · 5 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@hntig
Copy link

hntig commented Jul 24, 2023

Using the function gg.visualization.create_depth_maps_from_gempy produces a ValueError:

gemgis error

I believe (I might be wrong) that it is some incompatibility with pyvista 0.39, which is required by the latest version of gempy. More specifically, I'm using:
python=3.10.12
gemgis=1.0.11
gempy=2.3.0
pyvista=0.39.1

@github-actions
Copy link

Hello and welcome! Thanks for posting your first issue in the GemGIS project! Someone from our developers will get back to you. If your question is support related, we may transfer it to the Discussions.

@AlexanderJuestel
Copy link
Collaborator

AlexanderJuestel commented Jul 25, 2023

Dear @hntigkakis,

this is a known error. It was fixed in 781c594 and will be merged and released soon. Please copy the function below to have a hot fix for your issue.

Let me know if any other issues arise.

Cheers
Alex

def create_depth_maps_from_gempy(geo_model,  # gp.core.model,
                                 surfaces: Union[str, List[str]]) \
        -> Dict[str, List[Union[pv.core.pointset.PolyData, np.ndarray, List[str]]]]:
        # Checking if geo_model is a GemPy geo_model
    if not isinstance(geo_model, gp.core.model.Project):
        raise TypeError('geo_model must be a GemPy geo_model')

    # Checking that the model was computed
    if all(pd.isna(geo_model.surfaces.df.vertices)) == True and all(pd.isna(geo_model.surfaces.df.edges)) == True:
        raise ValueError('Model must be created before depth map extraction')

    # Checking if surface is of type string
    if not isinstance(surfaces, (str, list)):
        raise TypeError('Surface name must be of type string')

    # Converting string to list if only one surface is provided
    if isinstance(surfaces, str):
        surfaces = [surfaces]

    # Extracting surface data_df for all surfaces
    data_df = geo_model.surfaces.df.copy(deep=True)

    # Checking that surfaces are valid
    if not all(item in data_df.surface.unique().tolist() for item in surfaces):
        raise ValueError('One or more invalid surface names provided')

    # Extracting geometric data of selected surfaces
    geometric_data = pd.concat([data_df.groupby('surface').get_group(group) for group in surfaces])

    # Creating empty dict to store data
    surfaces_poly = {}

    for idx, val in geometric_data[['vertices', 'edges', 'color', 'surface', 'id']].dropna().iterrows():
        # Creating PolyData from each surface
        surf = pv.PolyData(val['vertices'][0], np.insert(val['edges'][0], 0, 3, axis=1).ravel())
       
        # Append depth to PolyData
        surf['Depth [m]'] = val['vertices'][0][:,2]

        # Store mesh, depth values and color values in dict
        surfaces_poly[val['surface']] = [surf, val['color']]

    return surfaces_poly

@AlexanderJuestel AlexanderJuestel changed the title gg.visualization.create_depth_maps_from_gempy ValueError [BUG] gg.visualization.create_depth_maps_from_gempy ValueError Jul 25, 2023
@AlexanderJuestel AlexanderJuestel self-assigned this Jul 25, 2023
@AlexanderJuestel AlexanderJuestel added the bug Something isn't working label Jul 25, 2023
@AlexanderJuestel AlexanderJuestel added this to the GemGIS 1.1 milestone Jul 25, 2023
@hntig
Copy link
Author

hntig commented Jul 26, 2023

Thank you @AlexanderJuestel.

I tried it and I'm now getting the following:

gemgis error2

Correct me if I'm doing something wrong, but it works by adding [0] before the [:,2] at end for the command to extract depth data for each surface:

depth = geometric_data['vertices'][geometric_data[geometric_data['surface'] == val['surface']].index[0]][0][:, 2]

@AlexanderJuestel
Copy link
Collaborator

@hntigkakis I updated the comment as I noticed this error as well. Try it now :)

@AlexanderJuestel
Copy link
Collaborator

Will be fixed in #286

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants