Description
the structured methods in this library (to my knowledge) only support 1-D arrays representing the axial coordinates of a rectilinear grid (the inputs to the numpy.meshgrid
) for structured points. This is okay... but in cases of curvilinear structured grids where the user has their own tooling for building those grids, we may want to pass prebuilt coordinate arrays.
For example, take this curvilinear structured grid: curvi_mesh.vts.zip
import pyvista as pv
mesh = pv.read("curvi_mesh.vts")
mesh.plot(show_edges=True, show_grid=True)
This type of grid cannot be made with NumPy's meshgrid
function as it cannot be represented as 3 1D coordinate arrays. This is a set of structured coordinates just like what numpy.meshgrid
yields. These structured coordinates can be accessed by the x
, y
, and z
attributes of a PyVista StructuredGrid
object.
Note that this is something that is really common outside of PyVista too - take discretize
's CurvilinearMesh
class for instance.
>>> mesh.x.shape, mesh.y.shape, mesh.z.shape
((17, 17, 5), (17, 17, 5), (17, 17, 5))
So how can we pass these kinds of pre-built structured points to the field classes such that we can leverage any performance/optimization for structured grids and plotting routines?
Just to drive home that this is a pretty common thing, even matplotlib can handle these types of structured coordinates:
plt.pcolormesh(mesh.x[:,:,0],
mesh.y[:,:,0],
np.random.rand(*mesh.dimensions[0:2]),
color="k")
plt.axis("image")
plt.show()
So basically, how might I use that structured gird with GSTools without just sending the points as an unstructured pointset. e.g.
from gstools import SRF, Gaussian
model = Gaussian(dim=2, var=0.2, len_scale=0.05)
srf = SRF(model, seed=20170519)
field = srf.structured([mesh.x[:,:,0],
mesh.y[:,:,0]])
>>> field.shape
(289, 289)
This is the wrong shape as it should be (17, 17) but it instead flattened the x
and y
arrays that I passed and used all of those coordinates... (17*17=289)
srf.plot()
This is not the plot that I would expect.