convert_to_np module

This module contains utility functions to convert results of the gprMax computation into numpy ndarrays.

src.dataset_creation.convert_to_np.convert_geometry_to_np(filename: str | Path, output_file: str | Path | None = None, remove_files: bool = False) ndarray[source]

Converts the given geometry and materials files into numpy arrays of shape [4, height, width].

Parameters:
filenamestr | Path

filename of the h5 file containing the geometry. The materials file must be in the same folder and named the same, adding “_materials.txt”

output_filestr | Path, default: None

output file to store the result in .npy format. If ‘None’, then does not write to disk, but returns the array.

remove_filesbool, default: False

if set, deletes the initial h5 and txt files.

Returns:
retnp.ndarray of shape [4, height, width]
  • ret[0] contains the relative permittivity (epsilon),

  • ret[1] contains the conductivity (sigma),

  • ret[2] contains the relative permeability (mu),

  • ret[3] contains the magnetic loss (sigma*).

src.dataset_creation.convert_to_np.convert_snapshots_to_np(snapshot_folder: str | Path, output_file: str | Path, remove_files: bool = False, pool_window: tuple[int, int] | None = None) dict[str, ndarray][source]

Converts snapshots related to a full B-scan into numpy arrays.

Creates a single .npz file containing all the arrays.

Each array inside the npz file is of shape:
  • [n_snapshots, height, width] for E-fields (z component of the field)

  • [n_snapshots, 2, height, width] for H-fields (x, y components)

Parameters:
snapshot_folderstr | Path

path to the folder containing all the snapshots of a B-scan.

output_filestr | Path

path to the output to store the results in .npz format

remove_filesbool, default: False

if set, deletes the original .vti files.

pool_windowtuple[int, int] | None, default: None

if set, applies average pooling of the specified size to the resulting snapshot.

Returns:
dict[str, np.ndarray]

the in-memory dictionary that has been saved to disk

src.dataset_creation.convert_to_np.extract_snapshot_fields_numpy(snapshot_path: str | Path)[source]

Extract the electric and magnetic fields from a snapshot .vti file.

Parameters:
snapshot_pathstr | Path

path to the snapshot file generated from gprMax

Returns:
tuple[np.ndarray, np.ndarray] of shape [height, width, 3]

Electric and magnetic fields in the x, y, z directions