API Reference [update in progress]
platerecipy.grid
File brief
grid.py
Module for grid input, output and visualizations.
This is a part of platerecipy package. For license and citation, please
refer to the main repository:
github.com/pjavaheri/platerecipy
Author(s): Pejvak Javaheri; pejvak.javaheri@mail.utoronto.ca
Grid
Bases: object
Generic class for a grid structure.
xs
property
2D mesh grid of Cartesian x coordinates
ys
property
2D mesh grid of Cartesian y coordinates
zs
property
2D mesh grid of Cartesian z coordinates
__init__()
Construct a generic grid structure.
PartialSphericalGrid
Bases: Grid
Partial uniform spherical grid.
phi_range
property
Range of phi (polar angle)
phis
property
2D grid of spherical azimuthal coordinates [-pi, pi]
r
property
Radius at the surface
theta_range
property
Range of theta (polar angle)
thetas
property
2D grid of spherical colatitude coordinates [0, pi]
__init__(original_xs, original_ys, original_zs, theta_range, phi_range, theta_res=None, phi_res=None)
Constructs a partial uniform spherical grid structure, spanning
[theta_range[0],theta_range[1]] x [phi_range[0], phi_range[1]].
If theta_res and phi_res are provided, the resolution will be
determined by those values. Alternatively, the resolution close enough
to what provided by the Cartesian arguments.
Warning
The Cartesian arguments will be the basis upon which the class method
interpolate_field() operates. In consistent values will impact the
interpolation process.
Warning
The input requires a range that is increasing in phi. That is, ranges such that cross the -pi/+pi boundary are not acceptable unless the full sphere is covered. An examples of unacceptable range is [pi/2, -pi/3]. Max range for theta: [0, pi] Max range for phi: [-pi, pi]
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
original_xs
|
ndarray
|
array of original input Cartesian x coordinates. |
required |
original_ys
|
ndarray
|
array of original input Cartesian y coordinates. |
required |
original_zs
|
ndarray
|
array of original input Cartesian z coordinates. |
required |
theta_range
|
tuple
|
the polar (colatitude) range. |
required |
phi_range
|
tuple
|
the azimuthal (longitude) range. |
required |
theta_res
|
int
|
polar (colatitude) resolution. |
None
|
phi_res
|
int
|
azimuthal (longitude) resolution. |
None
|
interpolate_field(field, take_log=False, method='lat-lon', **method_kwargs)
Interpolates the input field to the grid objects nodes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
ndarray
|
array corresponding to the original Cartesian coordinate inputs. |
required |
take_log
|
(bool, False)
|
whether to perform the interpolation on the log space (suitable for fields that vary by orders of magnitude), default = False. |
False
|
method
|
str
|
Whether to interpolate on the lat-lon space or to interpolate the data points linearly on the tangent plane. Options: "lat-lon" or "tangent-plane" |
= "lat-lon"
|
method_kwargs
|
dict
|
Additional arguments for |
{}
|
Note
method = "tangent-plane" is recommended for speed and accuracy.
Returns:
| Type | Description |
|---|---|
ndarray
|
|
map_to_original_input(field, take_log=False, method='lat-lon', **method_kwargs)
Maps the spherical field back to the original input format by interpolating the nodes using the nearest method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
(ndarray,)
|
array corresponding to the original Cartesian coordinate inputs. |
required |
take_log
|
(bool, False)
|
whether to perform the interpolation on the log space (suitable for
fields that vary by orders of magnitude), and makes a substantive
difference if |
False
|
method
|
str
|
Whether to interpolate on the lat-lon space or to interpolate the data points linearly on the tangent plane. Options: "lat-lon" or "tangent-plane" |
= "lat-lon"
|
method_kwargs
|
dict
|
Additional arguments for |
{}
|
Note
method = "tangent-plane" is recommended for speed and accuracy.
Returns:
| Type | Description |
|---|---|
ndarray
|
|
SphericalGrid
Bases: PartialSphericalGrid
Uniform spherical grid.
__init__(original_xs, original_ys, original_zs, theta_res=None, phi_res=None)
Constructs a uniform spherical grid structure.
If theta_res and phi_res are provided, the resolution will be
determined by those values. Alternatively, the resolution close enough
to what provided by the Cartesian arguments.
Warning
The Cartesian arguments will be the basis upon which the class method
interpolate_field() operates. In consistent values will impact the
interpolation process.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
original_xs
|
(ndarray,)
|
array of original input Cartesian x coordinates. |
required |
original_ys
|
(ndarray,)
|
array of original input Cartesian y coordinates. |
required |
original_zs
|
(ndarray,)
|
array of original input Cartesian z coordinates. |
required |
theta_res
|
int
|
polar (colatitude) resolution. |
None
|
phi_res
|
int
|
azimuthal (longitude) resolution. |
None
|
convert_grid_to_mesh(gridded_fields, field_names, radius=1.0)
(Internal)
Stores all gridded fields onto a spherical mesh (with nodal connectivity).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gridded_fields
|
List[ndarray]
|
A list of field data in array form. |
required |
field_names
|
List[str]
|
A list of field names. |
required |
radius
|
float
|
Radius of the sphere. |
1.
|
Returns:
| Type | Description |
|---|---|
pyvista mesh
|
|
Warning
Gridded fields are assumed to be C-like (row-major) arrays with the first dimension corresponding to theta (the polar angle) and the second to phi (the azimuthal angle).
Warning
This function requires vtk and pyvista packages.