synthesizer.imaging.spectral_cube

Definitions for the SpectralCube class.

This file contains the definitions for the SpectralCube class. This class is used to generate and store spectral data cubes. This can be done in two ways: by sorting particle spectra into the data cube or by smoothing particles/a density grid over the data cube.

This file is part of the synthesizer package and is distributed under the terms of the MIT license. See the LICENSE.md file for details.

Example usage:

# Create a data cube
cube = SpectralCube(
    resolution=0.1,
    lam=np.arange(1000, 2000, 1),
    fov=1,
)

# Get a hist data cube
cube.get_data_cube_hist(
    sed=sed,
    coordinates=coordinates,
)

# Get a smoothed data cube
cube.get_data_cube_smoothed(
    sed=sed,
    coordinates=coordinates,
    smoothing_lengths=smoothing_lengths,
    kernel=kernel,
    kernel_threshold=kernel_threshold,
    quantity="lnu",
)

Classes

class synthesizer.imaging.spectral_cube.SpectralCube(resolution, lam, fov=None, npix=None)[source]

The Spectral data cube object.

This object is used to generate and store spectral data cube. This can be done in two ways: by sorting particle spectra into the data cube or by smoothing particles/a density grid over the data cube.

lam

The wavelengths of the data cube.

Type:

unyt_array, float

resolution

The spatial resolution of the data cube.

Type:

unyt_quantity, float

fov

The field of view of the data cube. If a single value is given, the FOV is assumed to be square.

Type:

unyt_array, float/tuple

npix

The number of pixels in the data cube. If a single value is given, the number of pixels is assumed to be square.

Type:

unyt_array, int/tuple

arr

A 3D array containing the data cube. (npix[0], npix[1], lam.size)

Type:

array_like, float

units

The units of the data cube.

Type:

unyt_quantity, float

sed

The Sed used to generate the data cube.

Type:

Sed

quantity

The Sed attribute/quantity to sort into the data cube, i.e. “lnu”, “llam”, “luminosity”, “fnu”, “flam” or “flux”.

Type:

str

animate_data_cube(show=False, save_path=None, fps=30, vmin=None, vmax=None)[source]

Create an animation of the spectral cube.

Each frame of the animation is a wavelength bin.

Parameters:
  • show (bool) – Should the animation be shown?

  • save_path (str, optional) – Path to save the animation. If not specified, the animation is not saved.

  • fps (int, optional) – the number of frames per second in the output animation. Default is 30 frames per second.

  • vmin (float) – The minimum of the normalisation.

  • vmax (float) – The maximum of the normalisation.

Returns:

The animation object.

Return type:

matplotlib.animation.FuncAnimation

property data_cube

Return the data cube.

This is a property to allow the data cube to be accessed as an attribute.

Returns:

A 3D array containing the data cube. (npix[0], npix[1], lam.size)

Return type:

array_like (float)

get_data_cube_hist(sed, coordinates=None, quantity='lnu', nthreads=1)[source]

Calculate a spectral data cube with no smoothing.

This is only applicable to particle based spectral cubes.

Parameters:
  • sed (Sed) – The Sed object containing the spectra to be sorted into the data cube.

  • coordinates (unyt_array, float) – The coordinates of the particles.

  • quantity (str) – The Sed attribute/quantity to sort into the data cube, i.e. “lnu”, “llam”, “luminosity”, “fnu”, “flam” or “flux”.

  • nthreads (int) – The number of threads to use for the C extensions.

Returns:

A 3D array containing particle spectra sorted into the data cube. (npix[0], npix[1], lam.size)

Return type:

array_like (float)

get_data_cube_smoothed(sed, coordinates=None, smoothing_lengths=None, kernel=None, kernel_threshold=1, density_grid=None, quantity='lnu', nthreads=1)[source]

Calculate a spectral data cube with smoothing.

In the particle case this smooths each particle’s signal over the SPH kernel defined by their smoothing length. This uses C extensions to calculate the image for each particle efficiently.

In the parametric case the signal is smoothed over a density grid. This density grid is an array defining the weight in each pixel.

Parameters:
  • sed (Sed) – The Sed object containing the spectra to be sorted into the data cube.

  • coordinates (unyt_array, float) – The coordinates of the particles. (particle case only)

  • smoothing_lengths (unyt_array, float) – The smoothing lengths of the particles. (particle case only)

  • kernel (str) – The kernel to use for smoothing. (particle case only)

  • kernel_threshold (float) – The threshold for the kernel. (particle case only)

  • density_grid (array_like, float) – The density grid to smooth over. (parametric case only)

  • quantity (str) – The Sed attribute/quantity to sort into the data cube, i.e. “lnu”, “llam”, “luminosity”, “fnu”, “flam” or “flux”.

  • nthreads (int) – The number of threads to use for the C extensions. (particle case only).

Returns:

A 3D array containing particle spectra sorted into the data cube. (npix[0], npix[1], lam.size)

Return type:

array_like (float)

Raises:

InconsistentArguments – If conflicting particle and parametric arguments are passed or any arguments are missing an error is raised.