Vtkhdf
pysammos.data_write.vtkhdf package
Core module
pysammos.data_write.vtkhdf.core module
vtkhdf_enhanced3_flexible.py - ECP Breard Enhanced VTK HDF ImageData format library with full vector and flexible tensor support. Supports tensors of arbitrary dimensions (6, 9, 27, or any component count).
- pysammos.data_write.vtkhdf.core.c2f_reshape(array)[source]
Convert C-order array to Fortran-order.
- Return type:
ndarray
- pysammos.data_write.vtkhdf.core.create_adaptive_chunks(shape_c, component_size=1, dtype=<class 'numpy.float64'>)[source]
Create chunk shape adapted to grid asymmetry.
- Return type:
tuple
- pysammos.data_write.vtkhdf.core.create_cell_dataset(h5_file, var, is_vector=False, is_tensor=False, tensor_components=None, **kwargs)[source]
Create cell dataset with adaptive chunking and flexible tensor support.
- Return type:
Dataset
- pysammos.data_write.vtkhdf.core.create_field_dataset(h5_file, var, data, **kwargs)[source]
Create field dataset.
- pysammos.data_write.vtkhdf.core.create_point_dataset(h5_file, var, is_vector=False, is_tensor=False, tensor_components=None, **kwargs)[source]
Create point dataset with adaptive chunking and flexible tensor support.
- Return type:
Dataset
- pysammos.data_write.vtkhdf.core.dimensions2extent(dimensions)[source]
Convert dimensions to extent.
- Return type:
tuple
- pysammos.data_write.vtkhdf.core.extent2dimensions(extent)[source]
Convert extent to dimensions.
- Return type:
tuple
- pysammos.data_write.vtkhdf.core.f2c_reshape(array)[source]
Convert Fortran-order array to C-order.
- Return type:
ndarray
- pysammos.data_write.vtkhdf.core.get_cell_array(image_data, var)[source]
Get cell array from ImageData.
- pysammos.data_write.vtkhdf.core.get_cell_data_shape(h5_file)[source]
Get cell data shape in C order.
- Return type:
tuple
- pysammos.data_write.vtkhdf.core.get_cell_dataset(h5_file, var)[source]
Get cell dataset from HDF5 file.
- Return type:
Dataset
- pysammos.data_write.vtkhdf.core.get_data_order(h5_file)[source]
Get data ordering from file metadata.
- Return type:
str
- pysammos.data_write.vtkhdf.core.get_field_array(image_data, var)[source]
Get field array from ImageData.
- Return type:
ndarray
- pysammos.data_write.vtkhdf.core.get_field_dataset(h5_file, var)[source]
Get field dataset from HDF5 file.
- Return type:
Dataset
- pysammos.data_write.vtkhdf.core.get_point_array(image_data, var)[source]
Get point array from ImageData.
- pysammos.data_write.vtkhdf.core.get_point_data_shape(h5_file)[source]
Get point data shape in C order.
- Return type:
tuple
- pysammos.data_write.vtkhdf.core.get_point_dataset(h5_file, var)[source]
Get point dataset from HDF5 file.
- Return type:
Dataset
- pysammos.data_write.vtkhdf.core.get_point_tensor(image_data, var, components=None)[source]
Get tensor field as 4D array with flexible component count.
- Return type:
ndarray
- Args:
image_data: PyVista ImageData object var: Variable name components: Expected number of components (for validation).
If None, accepts any component count > 3.
- pysammos.data_write.vtkhdf.core.get_point_vector(image_data, var)[source]
Get vector field as 4D array.
- Return type:
ndarray
- pysammos.data_write.vtkhdf.core.initialize(file, extent, origin=(0, 0, 0), spacing=(1, 1, 1), direction=(1, 0, 0, 0, 1, 0, 0, 0, 1), data_order='FortranOrder')[source]
Initialize VTK HDF file structure with orientation tracking.
- pysammos.data_write.vtkhdf.core.is_tensor_data(array, expected_size, components=None)[source]
Check if array is tensor data.
- Return type:
Union[bool,int]
- Args:
array: Input array expected_size: Expected number of points/cells components: If specified, check for exact component count.
If None, return component count if it's tensor data, False otherwise.
- Returns:
If components specified: bool indicating if array matches If components is None: component count if tensor-like (>3), False otherwise
- pysammos.data_write.vtkhdf.core.is_vector_data(array, expected_size)[source]
Check if array is vector data (always 3 components).
- Return type:
bool
- pysammos.data_write.vtkhdf.core.point2cell_dimensions(dimensions)[source]
Convert point dimensions to cell dimensions.
- Return type:
tuple
- pysammos.data_write.vtkhdf.core.point2cell_extent(extent)[source]
Convert point extent to cell extent.
- Return type:
tuple
- pysammos.data_write.vtkhdf.core.read_slice(h5_file, var, index, data_type='point')[source]
Read a single slice from dataset.
- Return type:
ndarray
- pysammos.data_write.vtkhdf.core.read_vtkhdf(filename)[source]
Read VTK HDF file with flexible tensor support.
- pysammos.data_write.vtkhdf.core.set_point_4d_tensor(image_data, tensor_array, var)[source]
Add 27-component 3x3x3 tensor to point data.
- pysammos.data_write.vtkhdf.core.set_point_scalar(image_data, scalar_array, var)[source]
Add scalar field to point data.
- pysammos.data_write.vtkhdf.core.set_point_symmetric_tensor(image_data, tensor_array, var)[source]
Add 6-component symmetric tensor to point data.
- pysammos.data_write.vtkhdf.core.set_point_tensor(image_data, tensor_array, var, components=None)[source]
Add tensor field to point data with flexible component count.
- Args:
image_data: PyVista ImageData object tensor_array: 4D array with shape (nx, ny, nz, n_components) var: Variable name components: Expected number of components (for validation).
If None, accepts any component count > 3.
- pysammos.data_write.vtkhdf.core.set_point_vector(image_data, vector_array, var)[source]
Add vector field to point data.
- pysammos.data_write.vtkhdf.core.validate_imagedata_consistency(imagedata, verbose=True)[source]
Validate ImageData consistency and return diagnostics.
- Return type:
Dict[str,any]
- pysammos.data_write.vtkhdf.core.write_multicomponent_slice(dset, array, index, data_order='FortranOrder')[source]
Write multi-component data slice (vectors or tensors) with explicit ordering.
- pysammos.data_write.vtkhdf.core.write_scalar_slice(dset, array, index)[source]
Write scalar data slice.
Writer module
pysammos.data_write.vtkhdf.writer module
This module provides the VTKHDFWriter class, which is used to write data to VTKHDF files.
It also includes functionality to set the origin and dimensions of the data grid.
It is particularly useful for visualizing simulation data in a format compatible with VTK and HDF5 standards.
- This module contains the following class:
1.
VTKHDFWriterThis class manages the writing of VTKHDF files with specified node dimensions, spacing, and origin. It provides methods to write scalar, vector, and tensor data, and can handle both single-phase and polydisperse data. It uses pyvista for creating the VTK data structure and h5py for writing the data to HDF5 files. It is designed to ensure that the data is stored in a format that can be easily read and visualized using VTK-compatible tools.- Methods:
write(): Writes the provided data dictionary to a VTKHDF file, handling different data shapes (scalar, vector, tensor).write_polydisperse(): Writes polydisperse data to a VTKHDF file, handling both phase-independent and phase-dependent fields.
- class pysammos.data_write.vtkhdf.writer.VTKHDFWriter(node_dimensions, node_spacing, origin, path)[source]
Bases:
objectThis class manages the writing of VTKHDF files with specified node dimensions, spacing, and origin. It provides methods to write scalar, vector, and tensor data, and can handle both single-phase and polydisperse data.
Inputs
- node_dimensionstuple
Dimensions of the grid in number of nodes (e.g., (nx, ny, nz)).
- node_spacingtuple
Spacing between nodes in each dimension (e.g., (dx, dy, dz)).
- origintuple
Origin of the grid in the coordinate system (e.g., (ox, oy, oz)).
- pathstr
Path where the VTKHDF file will be saved.
Outputs
- node_dimensionstuple
Dimensions of the grid in number of nodes.
- node_spacingtuple
Spacing between nodes in each dimension.
- pathstr
Path where the VTKHDF file will be saved.
- origintuple
Origin of the grid in the coordinate system.
Examples
>>> writer = VTKHDFWriter((100, 100, 100), (1.0, 1.0, 1.0), (0.0, 0.0, 0.0), "output/data") >>> writer.write(data_dict) >>> writer.write_polydisperse(data_dict, n_phases=3, phase_indepen_field_names=['velocity', 'pressure']) This initializes a VTKHDFWriter with a 100x100x100 grid, 1.0 spacing, origin at (0,0,0), and saves the file to "output/data.vtkhdf". It then writes data to the file.
- write(data_dict)[source]
Writes the provided data dictionary to a VTKHDF file, handling various data shapes (scalar, vector, tensor).
Inputs
- data_dictdict
Dictionary containing data to be written, where keys are variable names and values are numpy arrays.
The data arrays should be structured as follows:
Scalar data: 1D array (shape: (n_nodes,))
Vector data: 2D array (shape: (n_nodes, 3))
Tensor data: 3D array (shape: (n_nodes, 3, 3))
Each key in the dictionary corresponds to a variable name, and the values are the data arrays to be written to the VTKHDF file. If the data is not in the expected shape, it will be reshaped to fit the node dimensions.
- write_polydisperse(data_dict, n_phases, phase_indepen_field_names)[source]
Writes polydisperse data to a VTKHDF file, handling both phase-independent and phase-dependent fields.
Inputs
- data_dictdict
Dictionary containing data to be written, where keys are variable names and values are numpy arrays. The data arrays should be structured as follows:
Phase-independent fields: 1D, 2D, or 3D arrays (shape: (n_nodes,) or (n_nodes, 3) or (n_nodes, 3, 3))
Phase-dependent fields: 2D or 3D arrays with shape (n_nodes, n_phases, ...) for each phase (including the bulk!)
- n_phasesint
Number of phases in the polydisperse system.
- phase_indepen_field_nameslist
List of field names that are independent of the phase. These fields will be written once for all phases.
Notes
This method creates a pyvista ImageData object with the specified dimensions and spacing, iterates over the data dictionary, and writes each field to the ImageData object. It handles both phase-independent fields (written once) and phase-dependent fields (written for each phase). The resulting data is then written to a VTKHDF file with gzip compression.