iwopy.utils.discretization¶
Classes¶
A lightweight regular grid in n dimensions, |
Module Contents¶
-
class iwopy.utils.discretization.RegularDiscretizationGrid(origin: numpy.typing.ArrayLike, deltas: numpy.typing.ArrayLike, n_steps: numpy.typing.ArrayLike, interpolation: 'nearest' | 'linear' | None =
None, tol: numpy.typing.ArrayLike | None =None, digits: int =12)[source]¶ A lightweight regular grid in n dimensions, without points storage.
- Parameters:¶
- origin: numpy.typing.ArrayLike¶
The origin point, len: n_dims
- deltas: numpy.typing.ArrayLike¶
The step sizes, len: n_dims.
- n_steps: numpy.typing.ArrayLike¶
The number of steps, len: n_dims. Use INT_INF for infinite.
- interpolation: 'nearest' | 'linear' | None =
None¶ The interpolation method: None, nearest, linear
- tol: numpy.typing.ArrayLike | None =
None¶ The tolerances for grid bounds, default is 0, shape: (n_dims,)
- digits: int =
12¶ The grid point precision
-
all_gridpoints(pts: numpy.ndarray, allow_outer: bool =
True) bool[source]¶ Checks if all points are on grid.
- apply_tol(p: numpy.ndarray) numpy.ndarray[source]¶
Get tolerance corrected point
- Parameters:¶
- p: numpy.ndarray¶
The point, shape: (n_dims,)
- Returns:¶
q – The corrected point, shape: (n_dims,)
- apply_tols(pts: numpy.ndarray) numpy.ndarray[source]¶
Get tolerance corrected points
- Parameters:¶
- pts: numpy.ndarray¶
The points, shape: (n_pts, n_dims)
- Returns:¶
q – The corrected points, shape: (n_pts, n_dims)
-
deriv_coeffs(pts: numpy.ndarray, var: int, order: int =
2, orderb: int =1) tuple[numpy.ndarray, numpy.ndarray][source]¶ Calculates the derivative coefficients at points.
-
deriv_coeffs_gridpoints(inds: numpy.ndarray, var: int, order: int =
2, orderb: int =1) tuple[numpy.ndarray, numpy.ndarray][source]¶ Calculates the derivative coefficients at grid points.
- find_grid_inds(inds: numpy.ndarray) numpy.ndarray[source]¶
Finds indices that are on grid
- Parameters:¶
- inds: numpy.ndarray¶
The grid point index candidates, shape: (n_inds, n_dims)
- Returns:¶
sel_grid – Subset selection of on-grid indices, shape: (n_inds, n_dims)
-
find_gridpoints(pts: numpy.ndarray, allow_outer: bool =
True, ret_inds: False =False) numpy.ndarray[source]¶ - find_gridpoints(pts: numpy.ndarray, allow_outer: bool, ret_inds: True) tuple[numpy.ndarray, numpy.ndarray]
- find_gridpoints(pts: numpy.ndarray, allow_outer: bool, ret_inds: bool) numpy.ndarray | tuple[numpy.ndarray, numpy.ndarray]
Finds points that are on grid.
- find_ingrid(pts: numpy.ndarray) numpy.ndarray[source]¶
Finds points that are on grid.
- Parameters:¶
- pts: numpy.ndarray¶
The points, shape: (n_pts, n_dims)
- Returns:¶
sel_grid – Subset selection of points that are in grid, shape: (n_pts, n_dims)
- get_cell(p: numpy.ndarray) numpy.ndarray[source]¶
Get the grid cell that contains a point.
- Parameters:¶
- p: numpy.ndarray¶
The point, shape: (n_dims,)
- Returns:¶
cell – The min and max values of each dimension. Shape: (n_dims, 2)
- get_cells(pts: numpy.ndarray) numpy.ndarray[source]¶
Get the grid cells that contain the given points, one cell per point.
- Parameters:¶
- pts: numpy.ndarray¶
The points, shape: (n_pts, n_dims)
- Returns:¶
cells – The min and max values of each dimension. Shape: (n_pts, n_dims, 2)
-
get_corner(p: numpy.ndarray, allow_outer: bool =
True) numpy.ndarray[source]¶ Get the lower-left grid corner of a point.
-
get_corners(pts: numpy.ndarray, allow_outer: bool =
True) numpy.ndarray[source]¶ Get the lower-left grid corners of points.
-
gp2i(gp: numpy.ndarray, allow_outer: bool =
True, error: True =True) numpy.ndarray[source]¶ - gp2i(gp: numpy.ndarray, allow_outer: bool, error: False) numpy.ndarray | None
- gp2i(gp: numpy.ndarray, allow_outer: bool, error: bool) numpy.ndarray | None
Get grid index of a grid point
-
gpts2inds(gpts: numpy.ndarray, allow_outer: bool =
True, error: True =True) numpy.ndarray[source]¶ - gpts2inds(gpts: numpy.ndarray, allow_outer: bool, error: False) numpy.ndarray | None
- gpts2inds(gpts: numpy.ndarray, allow_outer: bool, error: bool) numpy.ndarray | None
Get grid indices of grid points.
-
grad_coeffs(pts: numpy.ndarray, vars: collections.abc.Sequence[int] | numpy.ndarray | None, order: int | collections.abc.Sequence[int] | numpy.ndarray =
2, orderb: int | collections.abc.Sequence[int] | numpy.ndarray =1) tuple[numpy.ndarray, numpy.ndarray][source]¶ Calculates the gradient coefficients at grid points.
- Parameters:¶
- pts: numpy.ndarray¶
The evaluation points, shape: (n_pts, n_dims)
- vars: collections.abc.Sequence[int] | numpy.ndarray | None¶
The dimensions representing the variables wrt which to differentiate, shape: (n_vars,). Default is all dimensions
- order: int | collections.abc.Sequence[int] | numpy.ndarray =
2¶ The finite difference order, 1 = forward, -1 = backward, 2 = centre
- orderb: int | collections.abc.Sequence[int] | numpy.ndarray =
1¶ The finite difference order at boundary points
- Returns:¶
gpts – The grid points relevant for coeffs, shape: (n_gpts, n_dims)
coeffs – The gradient coefficients, shape: (n_pts, n_vars, n_gpts)
-
grad_coeffs_gridpoints(inds: numpy.ndarray, vars: collections.abc.Sequence[int] | numpy.ndarray | None, order: int | collections.abc.Sequence[int] | numpy.ndarray =
2, orderb: int | collections.abc.Sequence[int] | numpy.ndarray =1) tuple[numpy.ndarray, numpy.ndarray][source]¶ Calculates the gradient coefficients at grid points.
- Parameters:¶
- inds: numpy.ndarray¶
The integer grid point indices, shape: (n_inds, n_dims)
- vars: collections.abc.Sequence[int] | numpy.ndarray | None¶
The dimensions representing the variables wrt which to differentiate, shape: (n_vars,). Default is all dimensions
- order: int | collections.abc.Sequence[int] | numpy.ndarray =
2¶ The finite difference order, 1 = forward, -1 = backward, 2 = centre
- orderb: int | collections.abc.Sequence[int] | numpy.ndarray =
1¶ The finite difference order at boundary points
- Returns:¶
gpts – The grid points relevant for coeffs, shape: (n_gpts, n_dims)
coeffs – The gradient coefficients, shape: (n_inds, n_vars, n_gpts)
-
i2gp(inds: numpy.ndarray, error: True =
True) numpy.ndarray[source]¶ - i2gp(inds: numpy.ndarray, error: False) numpy.ndarray | None
- i2gp(inds: numpy.ndarray, error: bool) numpy.ndarray | None
Translates grid point indices to grid point.
- in_grid(p: numpy.ndarray) bool[source]¶
Checks if a point is located within the grid.
- Parameters:¶
- p: numpy.ndarray¶
The point, shape: (n_dims,)
- Returns:¶
in_grid – True if within grid
- inds2gpts(inds: numpy.ndarray) numpy.ndarray[source]¶
Translates grid point indices to grid points.
- Parameters:¶
- inds: numpy.ndarray¶
The integer grid point indices, shape: (n_gpts, dims)
- Returns:¶
gpts – The grid points, shape: (n_gpts, n_dims)
- interpolation_coeffs_point(p: numpy.ndarray) tuple[numpy.ndarray, numpy.ndarray][source]¶
Get the interpolation coefficients for a point.
Examples
>>> import numpy as np >>> from iwopy.utils import RegularDiscretizationGrid >>> grid = RegularDiscretizationGrid( ... [0.0], [1.0], [2], interpolation="linear" ... ) >>> points, coefficients = grid.interpolation_coeffs_point( ... np.array([0.5]) ... ) >>> points.tolist() [[0.0], [1.0]] >>> coefficients.tolist() [0.5, 0.5]- Parameters:¶
- p: numpy.ndarray¶
The point, shape: (n_dims,)
- Returns:¶
gpts – The grid points relevant for coeffs, shape: (n_gpts, n_dims)
coeffs – The interpolation coefficients, shape: (n_gpts,)
-
interpolation_coeffs_points(pts: numpy.ndarray, ret_pmap: False =
False) tuple[numpy.ndarray, numpy.ndarray][source]¶ - interpolation_coeffs_points(pts: numpy.ndarray, ret_pmap: True) tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray]
- interpolation_coeffs_points(pts: numpy.ndarray, ret_pmap: bool) tuple[numpy.ndarray, numpy.ndarray] | tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray]
Get the interpolation coefficients for a set of points.
Examples
>>> import numpy as np >>> from iwopy.utils import RegularDiscretizationGrid >>> grid = RegularDiscretizationGrid( ... [0.0], [1.0], [2], interpolation="linear" ... ) >>> points, coefficients, point_map = grid.interpolation_coeffs_points( ... np.array([[0.5], [1.5]]), ret_pmap=True ... ) >>> points.tolist() [[0.0], [1.0], [2.0]] >>> coefficients.tolist() [[0.5, 0.5, 0.0], [0.0, 0.5, 0.5]] >>> point_map.tolist() [[0, 1], [1, 2]]- Parameters:¶
- pts: numpy.ndarray¶
The points, shape: (n_pts, n_dims)
- ret_pmap: False =
False¶ - ret_pmap: True
- ret_pmap: bool
Additionally return the map from pts to gpts
- Returns:¶
gpts – The grid points relevant for coeffs, shape: (n_gpts, n_dims)
coeffs – The interpolation coefficients, shape: (n_pts, n_gpts)
pmap – The map from pts to gpts, shape: (n_pts, n_gp)
- is_gridi(inds: numpy.ndarray) bool[source]¶
Checks if grid indices are valid
- Parameters:¶
- inds: numpy.ndarray¶
The grid point indices, shape: (n_dims,)
- Returns:¶
on_grid – True if on grid
-
is_gridpoint(p: numpy.ndarray, allow_outer: bool =
True, ret_inds: False =False) bool[source]¶ - is_gridpoint(p: numpy.ndarray, allow_outer: bool, ret_inds: True) tuple[bool, numpy.ndarray]
- is_gridpoint(p: numpy.ndarray, allow_outer: bool, ret_inds: bool) bool | tuple[bool, numpy.ndarray]
Checks if a point is on grid.
- deltas¶
-
digits =
12¶
-
interpolation =
None¶
- property n_points : numpy.ndarray¶
The number of points in each dimension
- Returns:¶
n_points – The number of points in each dimension, shape: (n_dims,)
- n_steps¶
- origin¶
- property p_max : numpy.ndarray¶
The maximal grid point values
- Returns:¶
p_max – The maximal grid point values, shape: (n_dims,)
- property p_min : numpy.ndarray¶
The minimal grid point values
- Returns:¶
p_min – The minimal grid point values, shape: (n_dims,)
- tol : numpy.ndarray | None¶