sarracen.SarracenDataFrame.sph_interpolate

SarracenDataFrame.sph_interpolate(target: str, x: str | None = None, y: str | None = None, z: str | None = None, kernel: BaseKernel | None = None, rotation: ndarray | list | Rotation | None = None, rot_origin: ndarray | list | str | None = None, x_pixels: int | None = None, y_pixels: int | None = None, z_pixels: int | None = None, xlim: Tuple[float | None, float | None] | None = None, ylim: Tuple[float | None, float | None] | None = None, zlim: Tuple[float, float] | None = None, exact: bool = False, backend: str = 'cpu', dens_weight: bool = False, normalize: bool = False, hmin: bool = False) ndarray

Interpolate this data to a 2D or 3D grid, depending on the dimensionality of the data.

Parameters:
  • target (str) – The column label of the target data.

  • x (str) – The column labels of the directional data to interpolate over. Defaults to the x, y, and z columns detected in data.

  • y (str) – The column labels of the directional data to interpolate over. Defaults to the x, y, and z columns detected in data.

  • z (str) – The column labels of the directional data to interpolate over. Defaults to the x, y, and z columns detected in data.

  • kernel (BaseKernel) – The kernel to use for smoothing the target data. Defaults to the kernel specified in data.

  • rotation (array_like or SciPy Rotation, optional) – The rotation to apply to the data before interpolation. If defined as an array, the order of rotations is [z, y, x] in degrees. Only applies to 3D datasets.

  • rot_origin (array_like or ['com', 'midpoint'], optional) – Point of rotation of the data. Only applies to 3D datasets. If array_like, then the [x, y, z] coordinates specify the point around which the data is rotated. If ‘com’, then data is rotated around the centre of mass. If ‘midpoint’, then data is rotated around the midpoint, that is, min + max / 2. Defaults to the midpoint.

  • x_pixels (int, optional) – Number of pixels in the output image in the x, y & z directions. Default values are chosen to keep a consistent aspect ratio.

  • y_pixels (int, optional) – Number of pixels in the output image in the x, y & z directions. Default values are chosen to keep a consistent aspect ratio.

  • z_pixels (int, optional) – Number of pixels in the output image in the x, y & z directions. Default values are chosen to keep a consistent aspect ratio.

  • xlim (tuple of float, optional) – The minimum and maximum values to use in interpolation, in particle data space. Defaults to the minimum and maximum values of x, y and z.

  • ylim (tuple of float, optional) – The minimum and maximum values to use in interpolation, in particle data space. Defaults to the minimum and maximum values of x, y and z.

  • zlim (tuple of float, optional) – The minimum and maximum values to use in interpolation, in particle data space. Defaults to the minimum and maximum values of x, y and z.

  • exact (bool) – Whether to use exact interpolation of the data. Only applies to 2D datasets.

  • backend (['cpu', 'gpu']) – The computation backend to use when interpolating this data. Defaults to ‘gpu’ if CUDA is enabled, otherwise ‘cpu’ is used. A manually specified backend in data will override the default.

  • dens_weight (bool) – If True, the target will be multiplied by density. Defaults to False.

  • normalize (bool) – If True, will normalize the interpolation. Defaults to False (this may change in future versions).

  • hmin (bool) – If True, a minimum smoothing length of 0.5 * pixel size will be imposed. This ensures each particle contributes to at least one grid cell / pixel. Defaults to False (this may change in a future verison).

Returns:

The interpolated output image, in a multi-dimensional numpy array. The number of dimensions match the dimensions of the data. Dimensions are structured in reverse order, where (x, y, z) -> [z, y, x].

Return type:

ndarray (n-Dimensional)

Raises:
  • ValueError – If x_pixels, y_pixels or z_pixels are less than or equal to zero, or if the specified x, y and z minimum and maximum values result in an invalid region, or if data is not 2 or 3-dimensional.

  • KeyError – If target, x, y, z, mass, density, or smoothing length columns do not exist in data.

Examples

Interpolate SPH particles to a uniform grid.

>>> sdf, sdf_sinks = sarracen.read_phantom('dustydisc_00250')
>>> grid = sdf.sph_interpolate('rho')

The grid is a NumPy array in order of [z, y, x].

The default dimensions of the grid are scaled to keep a similar aspect ratio. In this example, the z-direction is shorter because of the geometry of the data (accretion disc).

>>> grid.shape
(165,  526, 512)