mesh¶
mesh
: This module provides numerous methods and classes for discretizing
data in a convienant way that makes sense for our spatially referenced
data/models.
meshgrid¶
-
wtools.mesh.
meshgrid
(x, y, z=None)[source]¶ Use this convienance method for your meshgrid needs. This ensures that we always use <ij> indexing to stay consistant with Cartesian grids.
This simply provides a wrapper for
np.meshgrid
ensuring we always useindexing='ij'
which makes sense for typical Cartesian coordinate systems (<x,y,z>).Note
This method handles 2D or 3D grids.
saveUBC¶
-
wtools.mesh.
saveUBC
(fname, x, y, z, models, header='Data', widths=False, origin=(0.0, 0.0, 0.0))[source]¶ Saves a 3D gridded array with spatail reference to the UBC mesh/model format. Use PVGeo to visualize this data. For more information on the UBC mesh format, reference the GIFtoolsCookbook website.
Warning
This method assumes your mesh and data are defined on a normal cartesian system: <x,y,z>
Parameters: - fname (str) – the string file name of the mesh file. Model files will be saved next to this file.
- x (ndarray or float) – a 1D array of unique coordinates along the X axis,
float for uniform cell widths, or an array with
widths==True
to treat as cell spacing on X axis - y (ndarray or float) – a 1D array of unique coordinates along the Y axis,
float for uniform cell widths, or an array with
widths==True
to treat as cell spacing on Y axis - z (ndarray or float) – a 1D array of unique coordinates along the Z axis,
float for uniform cell widths, or an array with
widths==True
to treat as cell spacing on Z axis - models (dict) – a dictionary of models. Key is model name and value is a 3D array with dimensions <x,y,z> containing cell data.
- header (str) – a string header for your mesh/model files
- widths (bool) – flag for whether to treat the (
x
,y
,z
) args as cell sizes/widths - origin (tuple(float)) – optional origin value used if
widths==True
, or used on a component basis if any of thex
,y
, orz
args are scalars.
Yields: Saves out a mesh file named {
fname
}.msh and a model file for every key/value pair in themodels
argument (key is file extension for model file and value is the data.Examples
>>> import numpy as np >>> # Create the unique coordinates along each axis : 11 nodes on each axis >>> x = np.linspace(0, 100, 11) >>> y = np.linspace(220, 500, 11) >>> z = np.linspace(0, 50, 11) >>> # Create some model data: 10 cells on each axis >>> arr = np.array([i*j*k for i in range(10) for j in range(10) for k in range(10)]).reshape(10, 10, 10) >>> models = dict( foo=arr ) >>> # Define the name of the file >>> fname = 'test' >>> # Perfrom the write out >>> saveUBC(fname, x, y, z, models, header='A simple model') >>> # Two files saved: 'test.msh' and 'test.foo'
>>> import numpy as np >>> # Uniform cell sizes >>> d = np.random.random(1000).reshape((10, 10, 10)) >>> v = np.random.random(1000).reshape((10, 10, 10)) >>> models = dict(den=d, vel=v) >>> saveUBC('volume', 25, 25, 2, models, widths=True, origin=(200.0, 100.0, 500.0)) >>> # Three files saved: 'volume.msh', 'volume.den', and 'volume.vel'
transpose¶
-
wtools.mesh.
transpose
(arr)[source]¶ Transpose matrix from Cartesian to Earth Science coordinate system. This is useful for UBC Meshgrids where +Z is down.
Note
Works forward and backward.
Parameters: arr (ndarray) – 3D NumPy array to transpose with ordering: <i,j,k> Returns: same array transposed from <i,j,k> to <j,i,-k> Return type: ndarray