synthesizer.kernel_functions

A module defining SPH kernels integrated along the line-of-sight.

This module provides a class for calculating SPH kernels integrated along the line-of-sight. These tables are used when computing LOS column densities and optical depths for particle data.

Available kernels include:
  • uniform

  • sph_anarchy

  • gadget_2

  • cubic

  • quintic

Functions

synthesizer.kernel_functions.cubic(r)[source]

Calculate the cubic kernel.

Parameters:

r (float) – The distance from the center of the kernel.

Returns:

The value of the cubic kernel.

Return type:

float

synthesizer.kernel_functions.gadget_2(r)[source]

Calculate the Gadget-2 kernel.

Parameters:

r (float) – The distance from the center of the kernel.

Returns:

The value of the Gadget-2 kernel.

Return type:

float

synthesizer.kernel_functions.quintic(r)[source]

Calculate the quintic kernel.

Parameters:

r (float) – The distance from the center of the kernel.

Returns:

The value of the quintic kernel.

Return type:

float

synthesizer.kernel_functions.sph_anarchy(r)[source]

Calculate the SPH Anarchy kernel.

Parameters:

r (float) – The distance from the center of the kernel.

Returns:

The value of the SPH Anarchy kernel.

Return type:

float

synthesizer.kernel_functions.uniform(r)[source]

Calculate the uniform kernel.

Parameters:

r (float) – The distance from the center of the kernel.

Returns:

The value of the uniform kernel.

Return type:

float

Classes

class synthesizer.kernel_functions.Kernel(name='sph_anarchy', binsize=10000, truncated_q_binsize=None, truncated_z_binsize=1000, overlap_q_binsize=64, overlap_u_binsize=128, overlap_eta_binsize=48, overlap_eta_min=0.1, overlap_eta_max=10.0, overlap_build_ndim=16, projected_integration_steps=256)[source]

A class describing a SPH kernel integrated along the line-of-sight.

This class packages three related lookup tables used by the LOS machinery.

  1. The projected LOS kernel for point-like input particles.

  2. The truncated LOS kernel for cases where the input lies inside the source kernel and only part of the source contributes in front of the input particle.

  3. The overlap kernel for cases where the input particle itself has a finite smoothing length and its own kernel must be averaged over.

For a source particle with smoothing length h, a sight line passing the source at impact parameter b intersects the source support over a chord of length

l = 2 * sqrt(h^2 - b^2),

provided b < h. To convert this geometric path length into a LOS column density we must weight the path by the SPH kernel W(r), where

r = sqrt(z^2 + b^2).

The full projected contribution of the source kernel is therefore

D(b, h) = 2 * integral W(r) dz,

with the integral running from z = 0 to z = sqrt(h^2 - b^2). Here W(r) has units of h^-3, so the LOS integral has units of h^-2 as required for a surface density kernel.

The key simplification is that the LOS integral can be written in terms of support-normalized coordinates. If we define

q = b / h, z_hat = z / h,

then r / h = sqrt(z_hat^2 + q^2), and the projected kernel becomes

D(q, h) = h^-2 * 2 * integral W_hat(sqrt(z_hat^2 + q^2)) dz_hat,

where the integral now runs from z_hat = 0 to z_hat = sqrt(1 - q^2), and W_hat denotes the dimensionless kernel shape. The factor of h^-2 is applied separately when evaluating each particle pair, while the dimensionless part of the integral can be tabulated once as a 1D function of q. That is the projected LOS kernel returned by get_kernel().

When the input particle lies inside the source kernel, not all of the LOS chord contributes: only the part of the source kernel in front of the input particle should be counted. In that case the LOS integral must be truncated at the input particle’s LOS coordinate. We tabulate this cumulative foreground contribution as a 2D function of projected separation and support-normalized truncation coordinate,

z_trunc = (z_input - z_source) / h,

where z_input and z_source are the LOS coordinates of the input and source particles. This truncated table is returned by get_truncated_los_kernel().

Finally, if the input particle is not treated as point-like, then the LOS signal seen by that particle must itself be averaged over the input particle’s kernel support. The smoothed-input overlap table does exactly that: for each point sampled inside the input kernel, it evaluates the truncated source-kernel contribution and then averages those values using the input-kernel weights. The overlap table is indexed by three dimensionless quantities,

q = b / (R_input + R_source), u = (z_input - z_source) / (R_input + R_source), eta = h_input / h_source,

where R_input and R_source are the support radii of the input and source kernels. This table is returned by get_overlap_kernel() and is the lookup used by the smoothed-input LOS path.

W_dz(z, b)[source]

Calculate the kernel density function W(r) as a function of z.

Parameters:
  • z (float) – The distance along the line-of-sight.

  • b (float) – The impact parameter.

Returns:

The value of the kernel density function W(r).

Return type:

float

create_kernel(filepath=None, nthreads=1)[source]

Build and save the kernel lookup tables to an HDF5 file.

Parameters:
  • filepath (str, optional) – The path to the HDF5 file to write. If omitted this defaults to kernel_<name>.hdf5.

  • nthreads (int) – The number of threads to use when building the overlap table if it has not already been cached.

Returns:

The projected LOS kernel table.

Return type:

np.ndarray

get_kernel()[source]

Compute the projected LOS kernel table.

This is the full LOS integral through the source kernel at each support-normalised impact parameter.

Returns:

The projected kernel values for each impact parameter.

Return type:

np.ndarray

get_overlap_kernel(nthreads=1)[source]

Compute the overlap kernel lookup table.

Returns:

The overlap kernel table together with its q, u, and eta grids.

Return type:

tuple

get_truncated_los_kernel()[source]

Compute the truncated LOS kernel lookup table.

This helper tabulates the cumulative LOS integral of the kernel as a function of impact parameter and support-normalised LOS truncation coordinate. It is used when an input particle lies inside a source kernel and therefore only sees part of the source along the line of sight.

Returns:

A tuple containing the truncated kernel table and the radial and LOS-coordinate grids that index it.

Return type:

tuple

classmethod load(filepath)[source]

Load a Kernel from an HDF5 file.

Parameters:

filepath (str) – The path to the HDF5 file containing the serialized kernel.

Returns:

The reloaded Kernel instance.

Return type:

Kernel

to_hdf5(group, nthreads=1)[source]

Save the kernel lookup tables and metadata to an HDF5 group.

Parameters:
  • group (h5py.Group) – The group in which to save the kernel tables.

  • nthreads (int) – The number of threads to use when building the overlap table if it has not already been cached.

Examples using synthesizer.kernel_functions.Kernel

Line of sight example

Line of sight example

Point LOS Column Densities With A Truncated Source Kernel

Point LOS Column Densities With A Truncated Source Kernel

Compare smoothed and point-particle LOS column densities

Compare smoothed and point-particle LOS column densities

Plot line of sight optical depth calculations

Plot line of sight optical depth calculations

Plot line of sight diagnostics

Plot line of sight diagnostics

Smoothed LOS Kernel Overlap Geometries

Smoothed LOS Kernel Overlap Geometries

Rotating particle distributions

Rotating particle distributions