remesh_array#
- remesh_array(data, imesh, omesh=None, order='F')[source]#
Shift an array from one mesh stagger to another.
Compares the source mesh imesh against the target mesh omesh axis by axis and applies adjacent-element averaging on every axis that needs to move from half mesh to main mesh. Only the half → main direction is supported; requesting main → half raises
ValueError.This is commonly needed before performing interpolation or arithmetic between quantities on different mesh positions. For example, computing the magnitude of the magnetic requires \(B_r\), \(B_\theta\), and \(B_\varphi\) on the same mesh: each must be remeshed from its native stagger (
0b100,0b010,0b001) to a common target before squaring and summing.If omesh is
None, the array is returned unchanged.- Parameters:
- data
np.ndarray Input array on the stagger described by imesh.
- imesh
MeshCodeType Source mesh stagger in any form accepted by
MeshCodeType.- omesh
MeshCodeTypeorNone, optional Target mesh stagger.
None(default) is a no-op. Pass0or'main'to move every half-mesh axis to the main mesh.- order
ArrayOrdering, optional Memory-order convention controlling how mesh-code bits map to numpy axes; see
ArrayOrdering. Defaults to'F'(Fortran / PSI HDF column-major: last numpy axis = \(r\)).
- data
- Returns:
- out
np.ndarray Array on the target mesh. Each remeshed axis is reduced by one element via adjacent averaging; axes that already match are left unchanged.
- out
- Raises:
ValueErrorIf any axis in omesh requests half mesh where imesh is already main (upsampling is not supported).
See also
MeshEnum representing the two mesh positions.
MeshCodeTypeAccepted forms for mesh stagger specifications.
ArrayOrderingMemory-order convention for bit–axis mapping.
Examples
Convert a radial magnetic-field array (half-mesh in \(r\), the last numpy axis) to the all-main mesh:
>>> import numpy as np >>> from psi_io._mesh import remesh_array >>> br = np.ones((128, 64, 57)) # shape (Nφ, Nθ, Nr); Nr is half-mesh size >>> br_main = remesh_array(br, imesh=0b100, omesh='main') >>> br_main.shape (128, 64, 56)
Remesh a scalar quantity (all-half,
0b111) to all-main:>>> rho = np.ones((128, 64, 57)) >>> remesh_array(rho, imesh=0b111, omesh='main').shape (127, 63, 56)
omesh=Noneis a no-op:>>> remesh_array(br, imesh=0b100).shape (128, 64, 57)
No-op when source and target stagger already match:
>>> remesh_array(br, imesh=0b100, omesh=0b100).shape (128, 64, 57)