kwave.utils.io module

assign_str_attr(attrs, attr_name, attr_val)[source]

Assigns HDF5 attribute with value as a fixed-length string

Parameters:
  • attrs – HDF5 attribute object

  • attr_name – name of attribute

  • attr_val – value of attribute

get_h5_literals()[source]
load_image(path, is_gray)[source]
write_attributes(filename, file_description=None)[source]

Write attributes to a HDF5 file.

This function writes attributes to a HDF5 file using a deprecated legacy method if legacy is set to True, or a new typed method if legacy is set to False. The function warns if legacy is set to True and deprecates it. If file_description is not provided, a default file description will be used.

Parameters:
  • filename (str) – The name of the HDF5 file.

  • file_description (str | None) – The description of the file. If not provided, a default description will be used.

Return type:

None

write_flags(filename)[source]

writeFlags reads the input HDF5 file and derives and writes the required source and medium flags based on the datasets present in the file. For example, if the file contains a data set named ‘BonA’, the nonlinear_flag will be written as true. Conditional flags are also written. The source mode flags are written when appropriate if they are not already present in the file. The default source mode is ‘additive’.

List of flags that are always written

ux_source_flag uy_source_flag uz_source_flag sxx_source_flag sxy_source_flag sxz_source_flag syy_source_flag syz_source_flag szz_source_flag p_source_flag p0_source_flag transducer_source_flag nonuniform_grid_flag nonlinear_flag absorbing_flag axisymmetric_flag elastic_flag sensor_mask_type

List of conditional flags

u_source_mode u_source_many p_source_mode p_source_many s_source_mode s_source_many

Parameters:

filename

write_grid(filename, grid_size, grid_spacing, pml_size, pml_alpha, Nt, dt, c_ref)[source]

Creates and writes the wavenumber grids and PML variables required by the k-Wave C++ code to the HDF5 file specified by the user.

List of parameters that are written:

Nx Ny Nz Nt dt dx dy dz c_ref pml_x_alpha pml_y_alpha pml_z_alpha pml_x_size pml_y_size pml_z_size

write_matrix(filename, matrix, matrix_name, compression_level=None, auto_chunk=True)[source]
Parameters:
  • matrix (ndarray)

  • matrix_name (str)

  • compression_level (int | None)

  • auto_chunk (bool)