Skip to content

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)
(1500, 1, 500) (1500, 1, 800)

Plot of the extended field with the original field marked by a rectanglePlot of the extended field with the original field marked by a rectangle

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}")
Original:  (1500, 1, 500)  (1e-4, 1e-4, 1e-4)
Refined:   (3000, 1, 1000) (5e-5, 1e-4, 5e-5)
Coarsened: (150, 1, 50)    (1e-3, 1e-4, 1e-3)

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

resample continuous originalresample continuous original

Shape: 200 × 100 × 200 · Method: "linear"

resample continuous fineresample continuous fine

Shape: 50 × 100 × 50 · Method: "mean"

resample continuous coarseresample continuous coarse

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

resample categorical originalresample categorical original

Shape: 200 × 100 × 200 · Method: "nearest"

resample categorical fineresample categorical fine

Shape: 50 × 100 × 50 · Method: "nearest"

resample categorical coarseresample categorical coarse

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).

(0, 0)
y tuple of int

Lower and upper extension in the y direction. Defaults to (0, 0).

(0, 0)
z tuple of int

Lower and upper extension in the z direction. Defaults to (0, 0).

(0, 0)
boundary_x tuple of str

Lower and upper boundary conditions for x. Defaults to ("periodic", "periodic").

('periodic', 'periodic')
boundary_y tuple of str

Lower and upper boundary conditions for y. Defaults to ("periodic", "periodic").

('periodic', 'periodic')
boundary_z tuple of str

Lower and upper boundary conditions for z. Defaults to ("periodic", "periodic").

"insulating" mirrors while duplicating the outermost sample, "symmetric" mirrors without duplicating it, and "periodic" wraps. Extensions and boundary pairs are specified in physical x/y/z order.

('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. (z, y, x).

required
method str

Resampling method. Defaults to "nearest". "nearest" samples the nearest source cell, preserving the input dtype and suiting categorical data such as grain or phase IDs. "linear" interpolates between source cell centres and returns floating-point data for continuous fields. "mean" computes an overlap-weighted mean of source cells covered by each target cell, returning floating-point data for conservative coarsening of continuous cell data.

'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 "mean" would refine an axis.