Field Operations¶
A Field is a three-dimensional NumPy array with simulation-time and grid-spacing metadata. Use extend() to add cells according to boundary conditions, or resample() to change the grid resolution while preserving its physical extent. Both methods return a new Field; they do not modify the original.
Extend a Field¶
Field.extend() adds cells on either side of the selected axes. Specify each extension as (lower, upper) in physical x, y, z order. The underlying array shape remains ordered (z, y, x).
from micpy.bin import read
field = read("A001_Delta_Gamma.conc1", -1)
extended = field.extend(x=(100, 200), boundary_x=("symmetric", "symmetric"))
print(field.shape, extended.shape)
The rectangle marks the original field within the extended domain. The regions to the left and right show the cells added using symmetric boundary conditions on both sides.
Each axis accepts its own lower and upper boundary conditions:
| Boundary condition | Behavior and example |
|---|---|
"symmetric" | Reflects values without repeating the outermost cell. C B A B C D C B |
"insulating" | Reflects values and repeats the outermost cell. B A A B C D D C |
"periodic" | Wraps values from the opposite side of the axis. Both sides must be periodic. C D A B C D A B |
| Original cells Extended cells | |
The default is zero extension on all axes, with periodic boundary conditions. Extensions must be non-negative. A singleton axis (length 1) cannot be extended; leave its extension at (0, 0). extend() requires a three-dimensional field and preserves its simulation time and spacing.
Resample a Field¶
Field.resample() changes the number of cells without changing the physical size of the domain. Pass the target shape in NumPy (z, y, x) order.
from micpy.bin import read
field = read("A001_Delta_Gamma.conc1", -1)
# Continuous values: interpolate to a finer grid.
fine = field.resample((3000, 1, 1000), method="linear")
# Continuous values: coarsen by cell-overlap-weighted averaging.
coarse = field.resample((150, 1, 50), method="mean")
print(f"{'Original:':<11} {str(field.shape):<15} {field.spacing}")
print(f"{'Refined:':<11} {str(fine.shape):<15} {fine.spacing}")
print(f"{'Coarsened:':<11} {str(coarse.shape):<15} {coarse.spacing}")
Choose the method according to the meaning of the data:
| Method | Behavior | Typical use |
|---|---|---|
"nearest" (default) | Uses the nearest source cell; preserves the input data type. | Phase labels, grain IDs, and other categorical fields. |
"linear" | Interpolates between source cell centers; produces floating-point values. | Concentration, temperature, and other continuous fields. |
"mean" | Computes overlap-weighted averages; produces floating-point values. | Conservative coarsening of continuous cell data. |
"mean" only supports coarsening: no target axis may have more cells than its corresponding source axis. Use "nearest" or "linear" for refinement. All target dimensions must be positive integers.
The returned field retains the original simulation time. When spacing metadata is available, cell spacing is adjusted to preserve the physical extent. The original field remains unchanged.
Continuous Field (.intf)¶
Continuous fields are resampled using linear interpolation for refinement and overlap-weighted averaging for coarsening.
Shape: 100 × 100 × 100 · Method: N/A
Shape: 200 × 100 × 200 · Method: "linear"
Shape: 50 × 100 × 50 · Method: "mean"
Categorical Field (.korn)¶
Categorical fields use nearest-neighbor sampling for both refinement and coarsening, preserving discrete grain IDs without introducing intermediate values.
Shape: 100 × 100 × 100 · Method: N/A
Shape: 200 × 100 × 200 · Method: "nearest"
Shape: 50 × 100 × 50 · Method: "nearest"
API Reference¶
micpy.bin.Field.extend(x=(0, 0), y=(0, 0), z=(0, 0), boundary_x=('periodic', 'periodic'), boundary_y=('periodic', 'periodic'), boundary_z=('periodic', 'periodic')) ¶
Return a field extended using MICRESS-style boundary conditions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x | tuple of int | Lower and upper extension in the x direction. Defaults to | (0, 0) |
y | tuple of int | Lower and upper extension in the y direction. Defaults to | (0, 0) |
z | tuple of int | Lower and upper extension in the z direction. Defaults to | (0, 0) |
boundary_x | tuple of str | Lower and upper boundary conditions for x. Defaults to | ('periodic', 'periodic') |
boundary_y | tuple of str | Lower and upper boundary conditions for y. Defaults to | ('periodic', 'periodic') |
boundary_z | tuple of str | Lower and upper boundary conditions for z. Defaults to
| ('periodic', 'periodic') |
Returns:
| Name | Type | Description |
|---|---|---|
Field | Field | Extended field with the original time and spacing. |
Raises:
| Type | Description |
|---|---|
ValueError | If the field is not three-dimensional, an extension is negative, a boundary condition is invalid, or periodic conditions are not used on both sides of an axis. |
micpy.bin.Field.resample(shape, method='nearest') ¶
Resample the field to a new cell geometry.
The physical extent of the field is preserved. Consequently, changing the number of cells changes the spacing accordingly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape | Tuple[int, int, int] | Target shape in NumPy axis order, i.e. | required |
method | str | Resampling method. Defaults to | 'nearest' |
Returns:
| Name | Type | Description |
|---|---|---|
Field | Field | Resampled field with updated spacing and preserved time. |
Raises:
| Type | Description |
|---|---|
ValueError | If the target shape or method is invalid, or if |