parse

Contents

parse#

classmethod Mesh.parse(mesh_code, *args)[source]#
classmethod Mesh.parse(mesh_code, ndim)
classmethod Mesh.parse(mesh_code, ndim)
classmethod Mesh.parse(mesh_code, ndim=None)
classmethod Mesh.parse(mesh_code, ndim=None)

Normalize mesh_code into a Mesh.

Parameters:
mesh_codeMeshLike

Stagger specification in any accepted form: an integer, the 'main'/'half' shorthands, a per-axis sequence of tokens (0/1, 'm'/'h', True/False, etc.), or an existing Mesh (returned as-is).

ndimint, optional

Number of dimensions. Required when mesh_code is an integer or the 'main'/'half' shorthand; inferred from sequence length otherwise. If both are provided they must agree.

Returns:
outMesh

Normalized Mesh with the specified stagger and dimensionality.

Raises:
ValueError

If ndim is required but not supplied, if ndim conflicts with the sequence length, or if any token is unrecognized.

TypeError

If mesh_code is of an unsupported type.

Examples

>>> from psi_io.mesh import Mesh
>>> str(Mesh.parse(0b100, ndim=3))
'HALF, MAIN, MAIN'
>>> str(Mesh.parse('half', ndim=2))
'HALF, HALF'
>>> str(Mesh.parse([1, 0, 1], ndim=3))
'HALF, MAIN, HALF'
>>> m = Mesh.parse(0b010, ndim=3)
>>> Mesh.parse(m) is m
True