strainimport.py¶
- import_2d(data, binary=False, layout='matrix', delimiter=',')[source]¶
Import strain result data from human readable text or binary files.
- Parameters:
data (
strorpathlib.Path) – Path pattern to the data files (can include wildcards). Default is “./”.layout (
str, optional) – Format of the output data layout: “column” (flat array per frame) or “matrix” (reshaped grid per frame). Default is “column”.binary (
bool, optional) – If True, expects files in a specific binary format. If False, expects text data. Default is False.delimiter (
str, optional) – Delimiter used in text data files. Ignored if binary=True. Default is a single space.
- Returns:
StrainResults–- A named container with the following fields:
window_x, window_y (grid arrays if layout==”matrix”; otherwise, 1D integer arrays)
def_grad, eps (deformation gradient and strain arrays with shape depending on layout)
filenames (python list)
- Raises:
ValueError: – If layout is not “column” or “matrix”, or text data has insufficient columns, or binary rows are malformed.
FileNotFoundError: – If no matching data files are found.
- read_binary(file, delimiter)[source]¶
Read a binary Strain result file and extract DIC fields.
Assumes a fixed binary structure with each row containing: - 2x int32 (subset coordinates) - 8x float64 (deformation matrix, strain matrix)
- Parameters:
- Returns:
tupleofnp.ndarray– Arrays corresponding to: (window_x, window_y, def_grad, eps)- Raises:
ValueError – If the binary file size does not align with expected row size.
- read_text(file, delimiter)[source]¶
Read a human-readable text DIC result file and extract DIC fields.
Expects at least 9 columns: [ss_x, ss_y, u, v, m, cost, ftol, xtol, niter]
- Parameters:
- Returns:
tupleofnp.ndarray– Arrays corresponding to: (ss_x, ss_y, u, v, m, cost, ftol, xtol, niter)- Raises:
ValueError – If the text file has fewer than 9 columns.
- to_grid(data, shape, ss_x_ref, ss_y_ref, x_unique, y_unique)[source]¶
Reshape a 2D DIC field from flat (column) format into grid (matrix) format.
This is used when output layout is specified as “matrix”. Maps values using reference subset coordinates (ss_x_ref, ss_y_ref).
- Parameters:
data (
np.ndarray) – Array of shape (n_frames, n_points) to be reshaped into (n_frames, height, width).shape (
tuple) – Target shape of output array: (n_frames, height, width).ss_x_ref (
np.ndarray) – X coordinates of subset centers.ss_y_ref (
np.ndarray) – Y coordinates of subset centers.x_unique (
np.ndarray) – Sorted unique X coordinates in the grid.y_unique (
np.ndarray) – Sorted unique Y coordinates in the grid.
- Returns:
np.ndarray– Reshaped array with shape shape, filled with NaNs where no data exists.