finam.UniformGrid#

class finam.UniformGrid(dims, spacing=(1.0, 1.0, 1.0), origin=(0.0, 0.0, 0.0), data_location=Location.CELLS, order='F', axes_reversed=False, axes_increase=None, axes_attributes=None, axes_names=None, crs=None)[source]#

Bases: RectilinearGrid

Regular grid with uniform spacing in up to three coordinate directions.

Parameters:
  • dims (iterable) – Dimensions of the uniform grid for each direction. Spatial dimension will be determined by len(dims).

  • spacing (iterable, optional) – Spacing of the uniform in each dimension. Defaults to (1.0, 1.0, 1.0). Must be positive.

  • origin (iterable, optional) – Origin of the uniform grid. Defaults to (0.0, 0.0, 0.0).

  • data_location (Location, str, int, optional) – Data location in the grid, by default Location.CELLS

  • order (str, optional) – Point and cell ordering. Either Fortran-like (“F”) or C-like (“C”), by default “F”

  • axes_reversed (bool, optional) – Indicate reversed axes order for the associated data, by default False

  • axes_increase (arraylike or None, optional) – False to indicate a bottom up axis (xyz order), by default None

  • axes_attributes (list of dict or None, optional) – Axes attributes following the CF convention (xyz order), by default None

  • axes_names (list of str or None, optional) – Axes names (in xyz order), by default [“x”, “y”, “z”]

  • crs (str or None, optional) – The coordinate reference system, by default None

Attributes:
axes

list of np.ndarray: Grid points.

axes_attributes

list of dict: Axes attributes following the CF convention (xyz order).

axes_increase

list of bool: False to indicate a bottom up axis (xyz order).

axes_names

list of str: Axes names (xyz order).

axes_reversed

bool: Indicate reversed axes order for the associated data.

cell_axes

list of np.ndarray: Axes of the cell centers (xyz order, all increase).

cell_centers

np.ndarray: Grid cell centers in given order starting top left corner.

cell_count

int: Number of grid cells.

cell_node_counts

np.ndarray: Node count for each cell.

cell_types

np.ndarray: Cell types.

cells

np.ndarray: Cell nodes in ESMF format.

crs

The coordinate reference system.

data_axes

list of np.ndarray: Axes as used for the data matrix.

data_axes_names

list of str: Axes names of the data matrix.

data_location

Location of the associated data (either CELLS or POINTS).

data_points

Points of the associated data (either cell_centers or points).

data_shape

tuple: Shape of the associated data.

data_size

int: Size of the associated data.

dim

int: Dimension of the grid.

dims

tuple: Axes lengths (xyz order).

mesh_dim

int: Maximal cell dimension.

name

Grid name.

order

str: Point, cell and data order (C- or Fortran-like).

point_count

int: Number of grid points.

points

np.ndarray: Grid points in given order starting top left corner.

Methods

compatible_with(other)

Check for compatibility with other Grid.

export_vtk(path[, data, cell_data, ...])

Export grid and data to a VTK file.

from_canonical(data)

Convert canonical data to grid specific form.

get_transform_to(other)

Get transformation for compatible grids.

to_canonical(data)

Convert grid specific data to canonical form.

to_unstructured()

Cast grid to an unstructured grid.

export_vtk(path, data=None, cell_data=None, point_data=None, field_data=None, mesh_type='uniform')[source]#

Export grid and data to a VTK file.

Parameters:
  • path (pathlike) – File path. Suffix will be replaced according to mesh type (.vti, .vtr, .vtu)

  • data (dict or None, optional) – Data in the corresponding shape given by name, by default None

  • cell_data (dict or None, optional) – Additional cell data, by default None

  • point_data (dict or None, optional) – Additional point data, by default None

  • field_data (dict or None, optional) – Additional field data, by default None

  • mesh_type (str, optional) – Mesh type (“uniform”/”structured”/”unstructured”), by default “structured”

Raises:

ValueError – If mesh type is not supported.

property axes#

Grid points.

Type:

list of np.ndarray

property axes_attributes#

Axes attributes following the CF convention (xyz order).

Type:

list of dict

property axes_increase#

False to indicate a bottom up axis (xyz order).

Type:

list of bool

property axes_names#

Axes names (xyz order).

Type:

list of str

property axes_reversed#

Indicate reversed axes order for the associated data.

Type:

bool

property cell_axes#

Axes of the cell centers (xyz order, all increase).

Type:

list of np.ndarray

property cell_centers#

Grid cell centers in given order starting top left corner.

Type:

np.ndarray

property cell_count#

Number of grid cells.

Type:

int

property cell_node_counts#

Node count for each cell.

Type:

np.ndarray

property cell_types#

Cell types.

Type:

np.ndarray

property cells#

Cell nodes in ESMF format.

Type:

np.ndarray

compatible_with(other)#

Check for compatibility with other Grid.

Parameters:

other (instance of Grid) – Other grid to compatibility with.

Returns:

compatibility

Return type:

bool

property crs#

The coordinate reference system.

property data_axes#

Axes as used for the data matrix.

Type:

list of np.ndarray

property data_axes_names#

Axes names of the data matrix.

Type:

list of str

property data_location#

Location of the associated data (either CELLS or POINTS).

property data_points#

Points of the associated data (either cell_centers or points).

property data_shape#

Shape of the associated data.

Type:

tuple

property data_size#

Size of the associated data.

Type:

int

property dim#

Dimension of the grid.

Type:

int

property dims#

Axes lengths (xyz order).

Type:

tuple

from_canonical(data)#

Convert canonical data to grid specific form.

Canonical means, that data axis are in xyz order and following increasing axis values.

Parameters:

data (arraylike) – Data to convert.

Returns:

Grid specific Data.

Return type:

arraylike

Raises:

ValueError – When data has wrong shape.

get_transform_to(other)#

Get transformation for compatible grids.

Parameters:

other (instance of Grid) – Other grid to compatibility with.

Returns:

data transformation

Return type:

callable

property mesh_dim#

Maximal cell dimension.

Type:

int

property name#

Grid name.

property order#

Point, cell and data order (C- or Fortran-like).

Type:

str

property point_count#

Number of grid points.

Type:

int

property points#

Grid points in given order starting top left corner.

Type:

np.ndarray

to_canonical(data)#

Convert grid specific data to canonical form.

Canonical means, that data axis are in xyz order and following increasing axis values.

Parameters:

data (arraylike) – Data to convert.

Returns:

Canonical Data.

Return type:

arraylike

Raises:

ValueError – When data has wrong shape.

to_unstructured()#

Cast grid to an unstructured grid.

Returns:

Grid as unstructured grid.

Return type:

UnstructuredGrid