gempy-project / gempy

GemPy is an open-source, Python-based 3-D structural geological modeling software, which allows the implicit (i.e. automatic) creation of complex geological models from interface and orientation data. It also offers support for stochastic modeling to address parameter and model uncertainties.
https://gempy.org
European Union Public License 1.2
986 stars 235 forks source link

Model Save #905

Closed glory21 closed 5 months ago

glory21 commented 5 months ago

How do I save the model? for example as an obj file.

javoha commented 5 months ago

Hello @glory21, we appreciate you using gempy and we hope you have a good experience. We would also appreciate if you take a little time to formulate your issues (e.g using the template) and maybe say hello. Regarding your problem. Gempy v3 does not have the functionality to save the complete model. You can however easiliy access all results using geo_model.solutions.raw_arrays. All results are saved there. If you can give me more specifics on what exactly you need I can probably give you more specific directions. Cheers; Jan

AlexanderJuestel commented 5 months ago

@javoha, I think what @glory21 needs is an extraction of the PyVista meshes from the GemPy Model. GemGIS has this functionality implemented for GemPy< 3 but I have not tested it yet for GemPy 3. But I will do so soonish and can report then.

javoha commented 5 months ago

OK, so all the resulting dual contouring meshes are in geo_model.solutions.dc_meshes. Does that work for you?

glory21 commented 5 months ago

Thank you very much for your reply. I am trying to save the built 3D mesh model as a model file, such as the a 3D mesh obj file, so that the modeling results can be used in other 3D modeling software.

glory21 commented 5 months ago

@javoha, I think what @glory21 needs is an extraction of the PyVista meshes from the GemPy Model. GemGIS has this functionality implemented for GemPy< 3 but I have not tested it yet for GemPy 3. But I will do so soonish and can report then.

Thank you very much for your reply. I am trying to use gempy2.3.1 to save model. And I ran the code but there was an error:

code:

获取顶点数据

vertices, faces = gp.get_surfaces(geo_data)

enter values to shift model

x0, y0, z0 = 0, 0, 0

save model as .obj file

cells = [] for i in range(len(vertices)):

shift vertices

shifted_vertices = vertices[i] - [x0, y0, z0]

# create cells (faces) dictionary
cells.append({"triangle": faces[i]})

# print the number of vertices for each surface
print(f"Surface {i} has {len(shifted_vertices)} vertices.")

write the .obj file

meshio.write_obj("model.obj", np.vstack(vertices), cells)

error: vertices, faces = gp.get_surfaces(geo_data) AttributeError: module 'gempy' has no attribute 'get_surfaces'

javoha commented 5 months ago

Hi, is there any specific reason why you are not using the new gempy version. For the old version there is the gempy_legacy repository. Cheers Jan

glory21 commented 5 months ago

Thanks! I have addressed the problem and save the model as a VTK file by running the following codes.

dict_SimpleMafic2 = gg.visualization.create_depth_maps_from_gempy(geo_model=data, surfaces='SimpleMafic2') dict_SimpleMafic2['SimpleMafic2'][0].save('Layer1.vtk')

javoha commented 5 months ago

Happy to hear, I will close this issue then. Just maybe as a general advice - I would try to switch to gempy v3 rather sooner than later, as the legacy version will not be supported anymore. So transfering to the new version makes a lot of sense. Cheers and have fun modelling, Jan