Readers
HDF5
read_hdf5(fpath, timestep=None)
Read a CFD HDF5 file into dict-of-arrays form.
Automatically detects the layout:
- Timestep groups --
/flow/00001/uvel,/flow/00002/uvel - Flat flow group --
/flow/uvel(single timestep) - Flat root --
/uvel(single timestep)
For multi-timestep files the flow dict uses integer keys::
1 | |
For single-timestep files (or when timestep is specified) the
flow dict is flat::
1 | |
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fpath
|
str | Path
|
Path to the HDF5 file. |
required |
timestep
|
int | None
|
If given, read only this timestep from a
multi-timestep file. Returns flat |
None
|
Returns:
| Type | Description |
|---|---|
Dataset
|
Tuple of |
Dataset
|
|
Dataset
|
|
Dataset
|
|
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If fpath does not exist. |
KeyError
|
If timestep is given but not present in file. |
Plot3D
read_plot3d(fpath)
Read a Plot3D grid file (ASCII or binary, 2-D or 3-D).
The file format is auto-detected by inspecting the first 4 bytes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fpath
|
str | Path
|
Path to the |
required |
Returns:
| Type | Description |
|---|---|
Dataset
|
Tuple of |
Dataset
|
|
Dataset
|
|
Dataset
|
|
read_plot3d_flow(fpath)
Read a Plot3D solution file (ASCII or binary, 2-D or 3-D).
The file format is auto-detected by inspecting the first 4 bytes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fpath
|
str | Path
|
Path to the |
required |
Returns:
| Type | Description |
|---|---|
Dataset
|
Tuple of |
Dataset
|
|
Dataset
|
|
Dataset
|
|
Tecplot ASCII
read_tecplot_ascii(fpath)
Read a Tecplot ASCII .dat file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fpath
|
str | Path
|
Path to the |
required |
Returns:
| Type | Description |
|---|---|
Dataset
|
|
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If fpath does not exist. |
ValueError
|
If the header cannot be parsed. |
Fortran Binary Sequential
FortranBinaryReader
Read files containing Fortran unformatted sequential records.
Each record is bracketed by 4-byte integer length markers (header
and trailer). This is the default format produced by gfortran and
most other Fortran compilers for FORM='UNFORMATTED', ACCESS='SEQUENTIAL'.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fname
|
str | PathLike[str]
|
Path to the binary file. |
required |
endianness
|
str
|
Byte order ( |
'<'
|
int_dtype
|
dtype
|
NumPy dtype for integer records. |
int32
|
real_dtype
|
dtype
|
NumPy dtype for real-valued records. |
float64
|
Example
Read a double-precision, little-endian grid file:
Single-precision file with big-endian byte order:
read_string_fixed(length=64, encoding='ascii')
Read a fixed-length string record, strip trailing spaces, decode.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
length
|
int
|
Expected byte length of the string record. |
64
|
encoding
|
str
|
Character encoding. |
'ascii'
|
Returns:
| Type | Description |
|---|---|
str
|
Decoded and right-stripped string. |
read_ints(*, expected_count=None)
Read an integer record.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expected_count
|
int | None
|
If given, verify the number of integers read. |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
1-D integer array. |
read_reals(*, expected_count=None)
Read a real-valued record.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expected_count
|
int | None
|
If given, verify the number of reals read. |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
1-D real array. |
read_array_real(shape, *, fortran_order=True)
Read a real-valued array written as one record.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
tuple[int, ...]
|
Desired shape of the returned array. |
required |
fortran_order
|
bool
|
If True, interpret bytes as column-major (Fortran) order. |
True
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Array reshaped to shape. |
skip_records(n=1)
Discard the next n Fortran records without returning data.
close()
Close the underlying file.
Binary Direct (split format)
BinaryHeader
dataclass
Grid dimensions and metadata parsed from a header file.
Attributes:
| Name | Type | Description |
|---|---|---|
nx |
int
|
Number of grid points in x. |
ny |
int
|
Number of grid points in y. |
nz |
int
|
Number of grid points in z. |
nt |
int
|
Number of timesteps. |
np |
int
|
Number of field variables (parameters). |
var_names |
list[str]
|
Variable names in ivar order (from the header file). |
info_lines |
list[str]
|
Free-form info lines from the header file. |
timesteps |
list[int]
|
Integer timestep indices from the header file. |
precision |
str
|
|
dtype
property
NumPy dtype corresponding to the file precision.
bytes_per_value
property
Bytes consumed by one scalar value on disk.
apply_byteswap(vals)
Byteswap vals if needed, caching the result for future calls.
read_header(fpath)
Read grid dimensions and metadata from a header file.
Parses both the minimal format (4 lines) and the extended format that includes variable names, info lines, and timestep indices.
Expected extended format::
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | |
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fpath
|
str | Path
|
Path to the header file. |
required |
Returns:
| Type | Description |
|---|---|
BinaryHeader
|
Parsed header with grid dimensions and metadata. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If fpath does not exist. |
read_binary_direct(fpath, gpath, *, it=1)
Read IOS grid and flow binary files into dict-of-arrays form.
Reads the companion .cd header files to determine grid
dimensions and variable names.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fpath
|
str | Path
|
Path to the flow binary file. |
required |
gpath
|
str | Path
|
Path to the grid binary file. |
required |
it
|
int
|
Timestep index (1-based). Default 1. |
1
|
Returns:
| Type | Description |
|---|---|
dict[str, ndarray]
|
Tuple of |
dict[str, ndarray]
|
|
dict[str, Any]
|
|
tuple[dict[str, ndarray], dict[str, ndarray], dict[str, Any]]
|
|
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If any input file or its |
ValueError
|
If a |
read_binary_direct_xy_plane(fpath, header, k, ivar, it)
Read an xy plane from a binary file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fpath
|
str | Path
|
Path to the binary data file. |
required |
header
|
BinaryHeader
|
Parsed header from |
required |
k
|
int
|
Z-index (1-based). |
required |
ivar
|
int
|
Variable index (1-based). |
required |
it
|
int
|
Timestep index (1-based). |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
2-D array with shape |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If fpath does not exist. |
ValueError
|
If any index is out of range. |
read_binary_direct_x_line(fpath, header, j, k, ivar, it)
Read a single x-line from an IOS binary file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fpath
|
str | Path
|
Path to the binary data file. |
required |
header
|
BinaryHeader
|
Parsed header from |
required |
j
|
int
|
Y-index (1-based). |
required |
k
|
int
|
Z-index (1-based). |
required |
ivar
|
int
|
Variable index (1-based). |
required |
it
|
int
|
Timestep index (1-based). |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
1-D array with shape |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If fpath does not exist. |
ValueError
|
If any index is out of range. |
read_binary_direct_xyz_volume(fpath, header, ivar, it)
Read a full 3-D volume for one variable from a binary file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fpath
|
str | Path
|
Path to the binary data file. |
required |
header
|
BinaryHeader
|
Parsed header from |
required |
ivar
|
int
|
Variable index (1-based). |
required |
it
|
int
|
Timestep index (1-based). |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
3-D array with shape |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If fpath does not exist. |
ValueError
|
If any index is out of range. |