rsqsim_api.tsunami.tsunami_multiprocessing
Multiprocessing utilities for computing tsunami Green’s functions in parallel.
Distributes the per-patch Green’s-function computation across multiple worker processes and writes the results incrementally to a set of netCDF output files via a producer/consumer pattern.
Attributes
Functions
|
Compute tsunami Green's functions for all patches and write to netCDF files. |
|
Consumer process that writes sea-surface displacement data to an HDF5 file. |
|
Consumer process that writes sea-surface displacement data to a netCDF4 file. |
|
Worker process that computes Green's functions for patches received from the input queue. |
Module Contents
- rsqsim_api.tsunami.tsunami_multiprocessing.multiprocess_gf_to_hdf(fault, x_range, y_range, out_file_prefix, x_grid=None, y_grid=None, z_grid=None, slip_magnitude=1.0, num_processors=None, num_write=8)[source]
Compute tsunami Green’s functions for all patches and write to netCDF files.
Distributes patch computations across
num_processorsworker processes and writes results tonum_writenetCDF output files via per-file output queues. Patches are randomly shuffled before distribution to balance load.- Parameters:
fault (RsqSimSegment or RsqSimMultiFault) – Fault model containing the patches to process.
x_range (numpy.ndarray of shape (nx,)) – 1-D easting coordinate array (NZTM metres).
y_range (numpy.ndarray of shape (ny,)) – 1-D northing coordinate array (NZTM metres).
out_file_prefix (str) – Prefix for output netCDF files; files are named
{out_file_prefix}{i}.ncforiinrange(num_write).x_grid (numpy.ndarray or None, optional) – 2-D easting grid of shape
(ny, nx). IfNone, constructed fromx_rangeandy_rangevia meshgrid.y_grid (numpy.ndarray or None, optional) – 2-D northing grid; must match
x_gridshape.z_grid (numpy.ndarray or None, optional) – 2-D elevation grid (m); defaults to all zeros.
slip_magnitude (float or int, optional) – Unit slip magnitude used for the Green’s function calculation. Defaults to 1.
num_processors (int or None, optional) – Number of worker processes. Defaults to half the available CPU count.
num_write (int, optional) – Number of output netCDF files (and output processes). Defaults to 8.
- rsqsim_api.tsunami.tsunami_multiprocessing.handle_output(output_queue, output_file, dset_shape)[source]
Consumer process that writes sea-surface displacement data to an HDF5 file.
Reads
(index, vert_disp)tuples from the queue until the sentinel value is received.- Parameters:
output_queue (multiprocessing.Queue) – Queue delivering
(index, disp_array)tuples.output_file (str) – Output HDF5 file path.
dset_shape (tuple) – Shape of the
"ssd_1m"dataset.
- rsqsim_api.tsunami.tsunami_multiprocessing.handle_output_netcdf(output_queue, patch_indices, output_file, dset_shape, x_range, y_range)[source]
Consumer process that writes sea-surface displacement data to a netCDF4 file.
Creates a netCDF4 file with dimensions
(npatch, y, x)and reads(index, patch_index, disp_array)tuples from the queue until the sentinel value is received.- Parameters:
output_queue (multiprocessing.Queue) – Queue delivering
(local_index, patch_index, disp_array)tuples.patch_indices (numpy.ndarray) – Array of global patch indices stored in this file.
output_file (str) – Output netCDF4 file path.
dset_shape (tuple of int) – Shape
(n_patches, ny, nx)of the SSD variable.x_range (numpy.ndarray) – 1-D easting coordinate array.
y_range (numpy.ndarray) – 1-D northing coordinate array.
- rsqsim_api.tsunami.tsunami_multiprocessing.patch_greens_functions(in_queue, x_sites, y_sites, z_sites, out_queue_dic, grid_shape, slip_magnitude=1)[source]
Worker process that computes Green’s functions for patches received from the input queue.
Reads
(file_no, file_index, patch_number, patch)tuples fromin_queue, callscalculate_tsunami_greens_functions(), and forwards the result to the appropriate output queue.- Parameters:
in_queue (multiprocessing.Queue) – Input queue of
(file_no, file_index, patch_number, patch)tuples. ANonesentinel signals termination.x_sites (numpy.ndarray) – Flattened easting coordinates of the output grid.
y_sites (numpy.ndarray) – Flattened northing coordinates.
z_sites (numpy.ndarray) – Flattened elevation coordinates.
out_queue_dic (dict) – Mapping of file index to output queue.
grid_shape (tuple) – Shape of the output displacement grid.
slip_magnitude (int or float, optional) – Unit slip magnitude. Defaults to 1.