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

A new tutorial for Field.mesh() #93

Closed
LSchueler opened this issue May 29, 2020 · 9 comments · Fixed by #132
Closed

A new tutorial for Field.mesh() #93

LSchueler opened this issue May 29, 2020 · 9 comments · Fixed by #132
Assignees
Milestone

Comments

@LSchueler
Copy link
Member

We should add a tutorial showing how to use the Field.mesh method to generate random fields on pre-existing meshes.

@LSchueler LSchueler changed the title A new tutorial for Field.mesh A new tutorial for Field.mesh() May 29, 2020
@LSchueler LSchueler assigned LSchueler and MuellerSeb and unassigned LSchueler May 29, 2020
@MuellerSeb
Copy link
Member

You are totally right! I'll take a look at this next week.

@banesullivan
Copy link
Collaborator

It'd be awesome to have this tutorial use PyVista 😉

@LSchueler
Copy link
Member Author

Why not provide 2 or more tutorials? - Maybe you already have something like a minimal working example?
I can also beef it up a little with text, if you just want to provide the mesh file and the code.

@MuellerSeb MuellerSeb added this to the 2.0 milestone Aug 18, 2020
@MuellerSeb MuellerSeb linked a pull request Aug 18, 2020 that will close this issue
6 tasks
@MuellerSeb
Copy link
Member

There are now some tutorials with MeshIO: #112. PyVista examples still missing, but the interface is now ready: #59

@MuellerSeb
Copy link
Member

@MuellerSeb MuellerSeb modified the milestones: 2.0, 1.3 Jun 4, 2021
@MatusGasparik
Copy link

Even though this issue has been already closed, what I am still missing is a tutorial with the Field.mesh() + pyvista in conjunction with the Field.transform() functionality. I am not quite sure what is the best way to use the two APIs together...

Calling the Field.mesh() with an instance of the pv.Grid as an arg, saves the field into the pv.Grid. What if you then want to generate some transformations of the original field using Field.transform() and also want to have these saved in the pv.Grid as well?

Inspired by the example for discrete fields, this is how I got it to work:

import gstools as gs
import pyvista as pv

dim, spacing = (30, 20, 10), (.1, .1, 0.1)
grid = pv.UniformGrid(dim, spacing)

model = gs.Gaussian(dim=3, len_scale=[2, 1, 0.1])
srf = gs.SRF(model, seed=19970221)

srf.mesh(grid, points="points", name="random-field")          # stores "random-field" scalar array in the `grid` object

vals = np.linspace(np.min(srf.field), np.max(srf.field), 5)
srf.transform("discrete", field="field", store="discrete", values=vals)     # stores "discrete" field in `srf` object

grid['discrete'] = srf['discrete']          # copies data from `srf` to `grid`


plotter = pv.Plotter(window_size=(800, 600))
plotter.background_color = 'gray'
plotter.enable_anti_aliasing()
plotter.add_mesh(grid, scalars="discrete", show_edges=True)
plotter.show()

Result:

image

Is this how those two APIs are supposed to be used together? It would make sense to call srf.mesh after all the transformed fields have been defined in, or can subsequent calls of srf.mesh be used to add new fields to the pv.Grid object?

@LSchueler LSchueler reopened this Dec 1, 2021
@banesullivan
Copy link
Collaborator

Just a drive-by thought/comment:

After calling, srf.mesh, srf could keep a pointer to the mesh and add fields to it anytime an operation is performed. Otherwise, grid['discrete'] = srf['discrete'] is exactly what you'd have to do.


I also want to give a plug for an example I put together here: https://banesullivan.com/pyvista/examples/kriging.html

@MatusGasparik
Copy link

I also want to give a plug for an example I put together here: https://banesullivan.com/pyvista/examples/kriging.html

Kudos for that link to your blog website! Looks fantastic. Added to my reading list.

@MuellerSeb
Copy link
Member

As @banesullivan pointed out, you can add more fields afterwards. Closing this for now. If you have further ideas on how to improve the interoperability, just open another issue or discussion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants