synthesizer.grid

The Grid class containing tabulated spectral and line data.

This object underpins all of Synthesizer function which generates synthetic spectra and line luminosities from models or simulation outputs. The Grid object contains attributes and methods for interfacing with spectral and line grids.

The grids themselves use a standardised HDF5 format which can be generated using the synthesizer-grids sister package.

Example usage:

from synthesizer import Grid

# Load a grid grid = Grid(“bc03_salpeter”)

# Get the axes of the grid print(grid.axes)

# Get the spectra grid print(grid.spectra)

Classes

class synthesizer.grid.Grid(grid_name, grid_dir=None, read_spectra=True, read_lines=True, new_lam=None, filters=None, lam_lims=())[source]

The Grid class containing tabulated spectral and line data.

This object contains attributes and methods for reading and manipulating the spectral grids which underpin all spectra/line generation in synthesizer.

grid_dir

The directory containing the grid HDF5 file.

Type:

str

grid_name

The name of the grid (as defined by the file name) with no extension.

Type:

str

grid_ext

The grid extension. Either “.hdf5” or “.h5”. If the passed grid_name has no extension then “.hdf5” is assumed.

Type:

str

grid_filename

The full path to the grid file.

Type:

str

available_lines

A list of lines on the Grid.

Type:

bool/list

available_spectra

A list of spectra on the Grid.

Type:

bool/list

reprocessed

Flag for whether the grid has been reprocessed through cloudy.

Type:

bool

lines_available

Flag for whether lines are available on this grid.

Type:

bool

lam

The wavelengths at which the spectra are defined.

Type:

Quantity, float

spectra

The spectra array from the grid. This is an N-dimensional grid where N is the number of axes of the SPS grid. The final dimension is always wavelength.

Type:

dict, array-like, float

lines

The lines array from the grid. This is an N-dimensional grid where N is the number of axes of the SPS grid. The final dimension is always wavelength.

Type:

array-like, float

parameters

A dictionary containing the grid’s parameters used in its generation.

Type:

dict

axes

A list of the names of the spectral grid axes.

Type:

list, str

naxes

The number of axes the spectral grid has.

logQ10

A dictionary of ionisation Q parameters. (DEPRECATED)

Type:

dict

log10_specific_ionising_luminosity

A dictionary of log10 specific ionising luminosities.

Type:

dict

<grid_axis>

A Grid will always contain 1D arrays corresponding to the axes of the spectral grid. These are read dynamically from the HDF5 file so can be anything but usually contain at least stellar ages and stellar metallicity.

Type:

array-like, float

lam

The wavelengths at which the spectra are defined.

Type:

array_like, float

animate_grid(show=False, save_path=None, fps=30, spectra_type='incident')[source]

Create an animation of the grid stepping through wavelength.

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.

Returns:

The animation object.

Return type:

matplotlib.animation.FuncAnimation

get_delta_lambda(spectra_id='incident')[source]

Calculate the delta lambda for the given spectra.

Parameters:

spectra_id (str) – Identifier for the spectra (default is “incident”).

Returns:

tuple

A tuple containing the list of wavelengths and delta lambda.

get_grid_line_ids()[source]

Get a list of the lines available on a grid.

Returns:

List of available lines list:

List of associated wavelengths.

Return type:

list

get_grid_point(values)[source]

Identify the nearest grid point for a tuple of values.

Parameters:

values (tuple) – The values for which we want the grid point. These have to be in the same order as the axes.

Returns:

tuple

A tuple of integers specifying the closest grid point.

get_grid_spectra_ids()[source]

Get a list of the spectra available on a grid.

Returns:

List of available spectra

Return type:

list

get_line(grid_point, line_id)[source]

Create a Line object for a given line_id and grid_point.

Parameters:
  • grid_point (tuple) – A tuple of integers specifying the closest grid point.

  • line_id (str) – The id of the line.

Returns:

line (synthesizer.line.Line)

A synthesizer Line object.

get_lines(grid_point, line_ids=None)[source]

Create a LineCollection for multiple lines.

Parameters:
  • grid_point (tuple) – A tuple of the grid point indices.

  • line_ids (list) – A list of lines, if None use all available lines.

Returns:

lines (lines.LineCollection)

static get_nearest_index(value, array)[source]

Calculate the closest index in an array for a given value.

Parameters:
  • value (float/unyt_quantity) – The target value.

  • array (np.ndarray/unyt_array) – The array to search.

Returns:

int

The index of the closet point in the grid (array)

get_sed(spectra_type)[source]

Get the spectra grid as an Sed object.

This enables grid wide use of Sed methods for flux, photometry, indices, ionising photons, etc.

Parameters:

spectra_type (string) – The key of the spectra grid to extract as an Sed object.

Returns:

Sed

The spectra grid as an Sed object.

get_spectra(grid_point, spectra_id='incident')[source]

Create an Sed object for a specific grid point.

Parameters:
  • grid_point (tuple) – A tuple of integers specifying the closest grid point.

  • spectra_id (str) – The name of the spectra (in the grid) that is desired.

Returns:

synthesizer.sed.Sed

A synthesizer Sed object

property has_lines

Return whether the Grid has lines.

property has_spectra

Return whether the Grid has spectra.

interp_spectra(new_lam, loop_grid=False)[source]

Interpolates the spectra grid onto the provided wavelength grid.

NOTE: this will overwrite self.lam and self.spectra, overwriting the attributes loaded from the grid file. To get these back a new grid will need to instantiated with no lam argument passed.

Parameters:
  • new_lam (unyt_array/array-like, float) – The new wavelength array to interpolate the spectra onto.

  • loop_grid (bool) – flag for whether to do the interpolation over the whole grid, or loop over the first axes. The latter is less memory intensive, but slower. Defaults to False.

property lines_available

Flag for whether line emission information is available on this grid.

This will only access the file the first time this property is accessed.

Returns:

True if lines are available, False otherwise.

Return type:

bool

property log10ages

Return the log10 age axis.

This is an alias to provide a pluralised version of the log10age attribute.

property log10metallicities

Return the log10 metallicity axis.

plot_specific_ionising_lum(ion='HI', hsize=3.5, vsize=None, cmap=<matplotlib.colors.ListedColormap object>, vmin=None, vmax=None, max_log10age=None)[source]

Make a simple plot of the specific ionising photon luminosity.

The resulting figure will show the (log) specific ionsing photon luminosity as a function of (log) age and metallicity for a given grid and ion.

Parameters:

ion (str) –

The desired ion. Most grids only have HI and HII calculated by

default.

hsize (float)

The horizontal size of the figure

vsize (float)

The vertical size of the figure

cmap (object/str)

A colourmap object or string defining the matplotlib colormap.

vmin (float)

The minimum specific ionising luminosity used in the colourmap

vmax (float)

The maximum specific ionising luminosity used in the colourmap

max_log10age (float)

The maximum log10(age) to plot

Returns:

matplotlib.Figure

The created figure containing the axes.

matplotlib.Axis

The axis on which to plot.

property reprocessed

Flag for whether grid has been reprocessed through cloudy.

This will only access the file the first time this property is accessed.

Returns:

True if reprocessed, False otherwise.

property shape

Return the shape of the grid.

truncate_grid_lam(min_lam, max_lam)[source]

Truncate the grid to a specific wavelength range.

If out of range wavlengths are requested, the grid will be truncated to the nearest wavelength within the grid.

Parameters:
  • min_lam (unyt_quantity) – The minimum wavelength to truncate the grid to.

  • max_lam (unyt_quantity) – The maximum wavelength to truncate the grid to.

unify_with_filters(filters)[source]

Unify the grid with a FilterCollection object.

This will: - Find the Grid wavelengths at which transmission is non-zero. - Limit the Grid’s spectra and wavelength array to where transmision

is non-zero.

  • Interpolate the filter collection onto the Grid’s new wavelength array.

Parameters:

filters (synthesizer.filter.FilterCollection) – The FilterCollection object to unify with this grid.

Examples using synthesizer.grid.Grid

Aperture Mask Example

Aperture Mask Example

Parametric Young Stars Example

Parametric Young Stars Example

SC-SAM example

SC-SAM example

Plot quiescent UVJ diagram

Plot quiescent UVJ diagram

Photometry example

Photometry example

Plot ionising luminosity

Plot ionising luminosity

Plot the line continuum for a given grid point

Plot the line continuum for a given grid point

Plot spectra example

Plot spectra example

Get lines example

Get lines example

Plot spectra by age

Plot spectra by age

Image addition example

Image addition example

Plot delta_lambda for a grid.

Plot delta_lambda for a grid.

Create image example

Create image example

Generate parametric observed SED

Generate parametric observed SED

Generate parametric galaxy SED

Generate parametric galaxy SED

An example showing how to scale a galaxy’s mass by luminosity/flux.

An example showing how to scale a galaxy's mass by luminosity/flux.

Plot equivalent width for UV indices

Plot equivalent width for UV indices

Create sampled SED

Create sampled SED

Compare parametric and particle SEDs

Compare parametric and particle SEDs

Compare SPS grid assignment methods

Compare SPS grid assignment methods

Compare Single star particle to instantaneous SFZH

Compare Single star particle to instantaneous SFZH

Plot line of sight diagnostics

Plot line of sight diagnostics

Plot line of sight diagnostics

Plot line of sight diagnostics