quickpaver.resample_grid#

quickpaver.resample_grid(original_grid: RectilinearGrid, factor_x: float, factor_y: float, factor_z: float) RectilinearGrid[source]#

Resample a rectilinear grid by changing the number of cells along each axis.

The physical extent, centre coordinates, and rotation angles of the original grid are preserved. Only the number of cells and corresponding cell sizes are updated. The new number of cells along each axis is computed as the ceiling of the original number of cells multiplied by the corresponding resampling factor.

Parameters:
  • original_grid (RectilinearGrid) – Grid to resample.

  • factor_x (float) – Resampling factor along the x-axis. Values greater than 1 refine the grid along x, while values between 0 and 1 coarsen it.

  • factor_y (float) – Resampling factor along the y-axis. Values greater than 1 refine the grid along y, while values between 0 and 1 coarsen it.

  • factor_z (float) – Resampling factor along the z-axis. Values greater than 1 refine the grid along z, while values between 0 and 1 coarsen it.

Returns:

New rectilinear grid with updated shape and cell dimensions. The grid centre, total physical dimensions, and rotation angles are preserved.

Return type:

RectilinearGrid

Notes

The new number of cells is computed as:

new_nx = max(ceil(original_grid.nx * factor_x), 1)

new_ny = max(ceil(original_grid.ny * factor_y), 1)

new_nz = max(ceil(original_grid.nz * factor_z), 1)

The new cell dimensions are then adjusted so that the physical extent along each axis remains unchanged:

new_dx = original_grid.nx * original_grid.dx / new_nx

new_dy = original_grid.ny * original_grid.dy / new_ny

new_dz = original_grid.nz * original_grid.dz / new_nz

Therefore, this function changes the discretisation of the grid, but not its physical size or position.

A minimum of one cell is enforced along each axis to avoid returning an empty grid.