synthesizer.imaging.image

A module containing the definition of an image.

This module contains the definition of an image.

An image can be generated from particle based data with or without smoothing, and from parametric data with smoothing defined by a morphology derived density grid.

Example Usage:

# Particle based case img = Image(resolution=0.1 * kpc, fov=1.0 * kpc) img.get_img(signal, coordinates * kpc, smoothing_lengths * kpc, kernel)

# Parametric case img = Image(resolution=0.1 * kpc, fov=1.0 * kpc) img.get_img(signal, density_grid)

Classes

class synthesizer.imaging.image.Image(resolution, fov, img=None)[source]

A class for generating images.

This class is used to generate images from particle based data with or without smoothing, and from parametric data with smoothing defined by a morphology derived density grid.

This can be used in isolation to generate singular images or generated by an ImageCollection to generate a collection of images in various filters.

resolution

The resolution of the image.

Type:

unyt_quantity, float

fov

The field of view of the image.

Type:

unyt_quantity, float

npix

The number of pixels in the image.

Type:

tuple

arr

The array containing the image.

Type:

array_like, float

units

The units of the image.

Type:

unyt.Units

apply_noise_array(noise_arr)[source]

Apply a noise array.

Parameters:

noise_arr (np.ndarray) – The noise array to add to the image.

Returns:

Image

The image including the noise array

np.ndarray

The weight map, derived from 1 / std^2

apply_noise_from_snr(snr, depth, aperture_radius=None)[source]

Apply noise derived from a SNR and depth.

This can either be for a point source or an aperture if aperture_radius is passed.

This assumes the SNR is defined as SNR = S / sqrt(noise_std)

Args:

Returns:

Image

The image including the noise array

np.ndarray

The noise array.

np.ndarray

The weight map.

apply_noise_from_std(noise_std)[source]

Apply noise derived from a standard deviation.

This creates noise with a normal distribution centred on 0 with the passed standard deviation.

Parameters:

noise_std (float) – The standard deviation of the noise to add to the image.

Returns:

Image

The image including the noise array

np.ndarray

The weight map.

apply_psf(psf)[source]

Apply a Point Spread Function to this image.

Parameters:

psf (np.ndarray) – An array describing the point spread function.

Returns:

Image

The image convolved with the psf.

get_img_hist(signal, coordinates=None)[source]

Calculate an image with no smoothing.

This is only applicable to particle based images and is just a wrapper for numpy.histogram2d.

Parameters:
  • signal (array_like, float) – The signal to be sorted into the image.

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

Returns:

img (array_like, float)

A 2D array containing the pixel values sorted into the image. (npix, npix)

get_img_smoothed(signal, coordinates=None, smoothing_lengths=None, kernel=None, kernel_threshold=1, density_grid=None, nthreads=1)[source]

Calculate a smoothed image.

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:
  • signal (array_like, float) – The signal to be sorted into the image.

  • 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)

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

Returns:

array_like (float)

A 2D array containing particles sorted into an image. (npix[0], npix[1])

Return type:

img

Raises:

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

get_signal_in_aperture(aperture_radius, aperture_cent=None, nthreads=1)[source]

Return the sum of the image within an aperture.

This uses fractional pixel coverage to calculate the overlap between the aperture and each pixel.

Parameters:
  • aperture_radius (unyt_quantity, float) – The radius of the aperture.

  • aperture_cent (unyt_array, float) – The centre of the aperture (in pixel coordinates, i.e. the centre is [npix/2, npix/2], top left is [0, 0], and bottom right is [npix, npix]). If None then the centre is assumed to be the maximum pixel.

  • nthreads (int) – The number of threads to use for the calculation. Default is 1.

Returns:

float

The sum of the image within the aperture.

plot_img(show=False, cmap='Greys_r', norm=None, fig=None, ax=None)[source]

Plot an image.

Parameters:
  • show (bool) – Whether to show the plot or not (Default False).

  • cmap (str) – The name of the matplotlib colormap for image plotting. Can be any valid string that can be passed to the cmap argument of imshow. Defaults to “Greys_r”.

  • norm (function) – A normalisation function. This can be custom made or one of matplotlib’s normalisation functions. It must take an array and return the same array after normalisation.

  • tick_formatter (matplotlib.ticker.FuncFormatter) – An instance of the tick formatter for formatting the colorbar ticks.

  • fig (matplotlib.pyplot.figure) – The figure object to plot on. If None a new figure is created.

  • ax (matplotlib.pyplot.figure.axis) – The axis object to plot on. If None a new axis is created.

Returns:

matplotlib.pyplot.figure

The figure object containing the plot

matplotlib.pyplot.figure.axis

The axis object containing the image.

plot_map(show=False, extent=None, cmap='Greys_r', cbar_label=None, norm=None, tick_formatter=None, fig=None, ax=None)[source]

Plot a map.

Unlike an image we want a colorbar and axes for a map.

Parameters:
  • show (bool) – Whether to show the plot or not (Default False).

  • extent (array_like) – The extent of the x and y axes.

  • cmap (str) – The name of the matplotlib colormap for image plotting. Can be any valid string that can be passed to the cmap argument of imshow. Defaults to “Greys_r”.

  • cbar_label (str) – The label for the colorbar.

  • norm (function) – A normalisation function. This can be custom made or one of matplotlib’s normalisation functions. It must take an array and return the same array after normalisation.

  • tick_formatter (matplotlib.ticker.FuncFormatter) – An instance of the tick formatter for formatting the colorbar ticks.

  • fig (matplotlib.pyplot.figure) – The figure object to plot on. If None a new figure is created.

  • ax (matplotlib.pyplot.figure.axis) – The axis object to plot on. If None a new axis is created.

Returns:

matplotlib.pyplot.figure

The figure object containing the plot

matplotlib.pyplot.figure.axis

The axis object containing the image.

plot_unknown_pleasures(constrast=100, target_lines=50, figsize=(8, 8), title='SYNTHESIZER')[source]

Create a representation of an image similar in style to Joy Division’s seminal 1979 album Unknown Pleasures.

Borrows some code from this matplotlib examples: https://matplotlib.org/stable/gallery/animation/unchained.html

Arguments
constrast (float)

The contrast.

target_lines (int)

The target number of individual lines to use.

print_ascii()[source]

Print an ASCII representation of an image.

resample(factor)[source]

Resample the image by factor.

Parameters:

factor (float) – The factor by which to resample the image, >1 increases resolution, <1 decreases resolution.