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_code
MeshLike 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 existingMesh(returned as-is).- ndim
int, 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.
- mesh_code
- Returns:
- Raises:
ValueErrorIf ndim is required but not supplied, if ndim conflicts with the sequence length, or if any token is unrecognized.
TypeErrorIf 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