synthesizer.components.component

A module containing generic component functionality.

This module contains the abstract base class for all components in the synthesizer. It defines the basic structure of a component and the methods that all components should have.

StellarComponents and BlackHoleComponents are children of this class and contain the specific functionality for stellar and black hole components respectively.

Classes

class synthesizer.components.component.Component(component_type, fesc, **kwargs)[source]

The parent class for all components in the synthesizer.

This class contains the basic structure of a component and the methods that all components should have.

component_type

The type of component, either “Stars” or “BlackHole”.

Type:

str

spectra

A dictionary to hold the stellar spectra.

Type:

dict

lines

A dictionary to hold the stellar emission lines.

Type:

dict

photo_lnu

A dictionary to hold the stellar photometry in luminosity units.

Type:

dict

photo_fnu

A dictionary to hold the stellar photometry in flux units.

Type:

dict

images_lnu

A dictionary to hold the images in luminosity units.

Type:

dict

images_fnu

A dictionary to hold the images in flux units

Type:

dict

fesc

The escape fraction of the component.

Type:

float

apply_noise_to_images_fnu(instrument, limit_to=None, apply_to_psf=True)[source]

Apply instrument noise to this component’s images.

Parameters:
  • instrument (Instrument) – The instrument with the noise to apply.

  • limit_to (str/list) – If not None, defines a specific model (or list of models) to limit the image generation to. Otherwise, all models with saved spectra will have images generated.

  • apply_to_psf (bool) – If True, apply the noise to the PSF images. Otherwise, apply to the non-PSF images.

Returns:

dict The images with the noise applied.

apply_noise_to_images_lnu(instrument, limit_to=None, apply_to_psf=True)[source]

Apply instrument noise to this component’s images.

Parameters:
  • instrument (Instrument) – The instrument with the noise to apply.

  • limit_to (str/list) – If not None, defines a specific model (or list of models) to limit the image generation to. Otherwise, all models with saved spectra will have images generated.

  • apply_to_psf (bool) – If True, apply the noise to the PSF images. Otherwise, apply to the non-PSF images.

Returns:

dict The images with the noise applied.

apply_psf_to_images_fnu(instrument, psf_resample_factor=1, limit_to=None)[source]

Apply instrument PSFs to this component’s flux images.

Parameters:
  • instrument (Instrument) – The instrument with the PSF to apply.

  • psf_resample_factor (int) – The resample factor for the PSF. This should be a value greater than 1. The image will be resampled by this factor before the PSF is applied and then downsampled back to the original after convolution. This can help minimize the effects of using a generic PSF centred on the galaxy centre, a simplification we make for performance reasons (the effects are sufficiently small that this simplifications is justified).

  • limit_to (str/list) – If not None, defines a specific model (or list of models) to limit the image generation to. Otherwise, all models with saved spectra will have images generated.

Returns:

dict The images with the PSF applied.

apply_psf_to_images_lnu(instrument, psf_resample_factor=1, limit_to=None)[source]

Apply instrument PSFs to this component’s luminosity images.

Parameters:
  • instrument (Instrument) – The instrument with the PSF to apply.

  • psf_resample_factor (int) – The resample factor for the PSF. This should be a value greater than 1. The image will be resampled by this factor before the PSF is applied and then downsampled back to the original after convolution. This can help minimize the effects of using a generic PSF centred on the galaxy centre, a simplification we make for performance reasons (the effects are sufficiently small that this simplifications is justified).

  • limit_to (str/list) – If not None, defines a specific model (or list of models) to limit the image generation to. Otherwise, all models with saved spectra will have images generated.

Returns:

dict The images with the PSF applied.

clear_all_emissions()[source]

Clear all emissions from the component.

This clears all spectra, lines, and photometry.

clear_all_lines()[source]

Clear all lines from the component.

clear_all_photometry()[source]

Clear all photometry from the component.

clear_all_spectra()[source]

Clear all spectra from the component.

clear_all_spectroscopy()[source]

Clear all spectroscopy from the component.

clear_weights()[source]

Clear all cached grid weights from the component.

This clears all grid weights calculated using different methods from this component, and resets the _grid_weights dictionary.

get_images_flux(resolution, fov, emission_model, img_type='smoothed', kernel=None, kernel_threshold=1, nthreads=1, limit_to=None, instrument=None, cosmo=None)[source]

Make an ImageCollection from fluxes.

For Parametric components, images can only be smoothed. An exception will be raised if a histogram is requested.

For Particle components, images can either be a simple histogram (“hist”) or an image with particles smoothed over their SPH kernel.

Which images are produced is defined by the emission model. If any of the necessary photometry is missing for generating a particular image, an exception will be raised.

The limit_to argument can be used if only a specific image is desired.

Note that black holes will never be smoothed and only produce a histogram due to the point source nature of black holes.

All images that are created will be stored on the emitter (Stars or BlackHole/s) under the images_fnu attribute. The image collection at the root of the emission model will also be returned.

Parameters:
  • resolution (unyt_quantity of float) – The size of a pixel. (Ignoring any supersampling defined by psf_resample_factor)

  • fov (float) – The width of the image in image coordinates.

  • emission_model (EmissionModel) – The emission model to use to generate the images.

  • img_type (str) – The type of image to be made, either “hist” -> a histogram, or “smoothed” -> particles smoothed over a kernel for a particle galaxy. Otherwise, only smoothed is applicable.

  • kernel (np.ndarray of float) – The values from one of the kernels from the kernel_functions module. Only used for smoothed images.

  • kernel_threshold (float) – The kernel’s impact parameter threshold (by default 1).

  • nthreads (int) – The number of threads to use in the tree search. Default is 1.

  • limit_to (str) – The label of the image to limit to. If None, all images are returned.

  • instrument (Instrument) – The instrument to use to generate the images.

  • cosmo (astropy.cosmology) – The cosmology to use for the calculation of the luminosity distance. Only needed for internal conversions from cartesian to angular coordinates when an angular resolution is used.

Returns:

array-like

A 2D array containing the image.

Return type:

Image

get_images_luminosity(resolution, fov, emission_model, img_type='smoothed', kernel=None, kernel_threshold=1, nthreads=1, limit_to=None, instrument=None, cosmo=None)[source]

Make an ImageCollection from component luminosities.

For Parametric components, images can only be smoothed. An exception will be raised if a histogram is requested.

For Particle components, images can either be a simple histogram (“hist”) or an image with particles smoothed over their SPH kernel.

Which images are produced is defined by the emission model. If any of the necessary photometry is missing for generating a particular image, an exception will be raised.

The limit_to argument can be used if only a specific image is desired.

Note that black holes will never be smoothed and only produce a histogram due to the point source nature of black holes.

All images that are created will be stored on the emitter (Stars or BlackHole/s) under the images_lnu attribute. The image collection at the root of the emission model will also be returned.

Parameters:
  • resolution (unyt_quantity of float) – The size of a pixel. (Ignoring any supersampling defined by psf_resample_factor)

  • fov (float) – The width of the image in image coordinates.

  • emission_model (EmissionModel) – The emission model to use to generate the images.

  • img_type (str) – The type of image to be made, either “hist” -> a histogram, or “smoothed” -> particles smoothed over a kernel for a particle galaxy. Otherwise, only smoothed is applicable.

  • kernel (np.ndarray of float) – The values from one of the kernels from the kernel_functions module. Only used for smoothed images.

  • kernel_threshold (float) – The kernel’s impact parameter threshold (by default 1).

  • nthreads (int) – The number of threads to use in the tree search. Default is 1.

  • limit_to (str) – The label of the image to limit to. If None, all images are returned.

  • instrument (Instrument) – The instrument to use to generate the images.

  • cosmo (astropy.cosmology) – The cosmology to use for the calculation of the luminosity distance. Only needed for internal conversions from cartesian to angular coordinates when an angular resolution is used.

Returns:

array-like

A 2D array containing the image.

Return type:

Image

get_lines(line_ids, emission_model, dust_curves=None, tau_v=None, fesc=None, mask=None, verbose=True, **kwargs)[source]

Generate stellar lines as described by the emission model.

Parameters:
  • line_ids (list) – A list of line_ids. Doublets can be specified as a nested list or using a comma (e.g. ‘OIII4363,OIII4959’).

  • emission_model (EmissionModel) – The emission model to use.

  • dust_curves (dict) –

    An override to the emission model dust curves. Either:
    • None, indicating the dust_curves defined on the emission models should be used.

    • A single dust curve to apply to all emission models.

    • A dictionary of the form {<label>: <dust_curve instance>} to use a specific dust curve instance with particular properties.

  • tau_v (dict) –

    An override to the dust model optical depth. Either:
    • None, indicating the tau_v defined on the emission model should be used.

    • A float to use as the optical depth for all models.

    • A dictionary of the form {<label>: float(<tau_v>)} to use a specific optical depth with a particular model or {<label>: str(<attribute>)} to use an attribute of the component as the optical depth.

  • fesc (dict) –

    An override to the emission model escape fraction. Either:
    • None, indicating the fesc defined on the emission model should be used.

    • A float to use as the escape fraction for all models.

    • A dictionary of the form {<label>: float(<fesc>)} to use a specific escape fraction with a particular model or {<label>: str(<attribute>)} to use an attribute of the component as the escape fraction.

  • mask (dict) –

    An override to the emission model mask. Either:
    • None, indicating the mask defined on the emission model should be used.

    • A dictionary of the form {<label>: {“attr”: attr, “thresh”: thresh, “op”: op}} to add a specific mask to a particular model.

  • verbose (bool) – Are we talking?

  • kwargs (dict) – Any additional keyword arguments to pass to the generator function.

Returns:

LineCollection

A LineCollection object containing the lines defined by the root model.

get_luminosity_distance(cosmo)[source]

Get the luminosity distance of the component.

This requires the redshift to be set on the component.

This will use the astropy cosmology module to calculate the luminosity distance. If the redshift is 0, the distance will be set to 10 pc to avoid any issues with 0s.

Parameters:

cosmo (astropy.cosmology) – The cosmology to use for the calculation.

Returns:

The luminosity distance of the component in kpc.

Return type:

unyt_quantity

abstract get_mask(attr, thresh, op, mask=None)[source]

Return a mask based on the attribute and threshold.

get_photo_fnu(filters, verbose=True, nthreads=1)[source]

Calculate flux photometry using a FilterCollection object.

Parameters:
  • filters (FilterCollection) – A FilterCollection object.

  • verbose (bool) – Are we talking?

  • nthreads (int) – The number of threads to use for the integration. If -1, all threads will be used.

Returns:

A dictionary of fluxes in each filter in filters.

Return type:

dict

get_photo_lnu(filters, verbose=True, nthreads=1)[source]

Calculate luminosity photometry using a FilterCollection object.

Parameters:
  • filters (filters.FilterCollection) – A FilterCollection object.

  • verbose (bool) – Are we talking?

  • nthreads (int) – The number of threads to use for the integration. If -1, all threads will be used.

Returns:

A dictionary of rest frame broadband luminosities.

Return type:

photo_lnu (dict)

get_spectra(emission_model, dust_curves=None, tau_v=None, fesc=None, mask=None, vel_shift=None, verbose=True, nthreads=1, grid_assignment_method='cic', **kwargs)[source]

Generate stellar spectra as described by the emission model.

Parameters:
  • emission_model (EmissionModel) – The emission model to use.

  • dust_curves (dict) –

    An override to the emission model dust curves. Either:
    • None, indicating the dust_curves defined on the emission models should be used.

    • A single dust curve to apply to all emission models.

    • A dictionary of the form {<label>: <dust_curve instance>} to use a specific dust curve instance with particular properties.

  • tau_v (dict) –

    An override to the dust model optical depth. Either:
    • None, indicating the tau_v defined on the emission model should be used.

    • A float to use as the optical depth for all models.

    • A dictionary of the form {<label>: float(<tau_v>)} to use a specific optical depth with a particular model or {<label>: str(<attribute>)} to use an attribute of the component as the optical depth.

  • fesc (dict) –

    An override to the emission model escape fraction. Either:
    • None, indicating the fesc defined on the emission model should be used.

    • A float to use as the escape fraction for all models.

    • A dictionary of the form {<label>: float(<fesc>)} to use a specific escape fraction with a particular model or {<label>: str(<attribute>)} to use an attribute of the component as the escape fraction.

  • mask (dict) –

    An override to the emission model mask. Either:
    • None, indicating the mask defined on the emission model should be used.

    • A dictionary of the form {<label>: {“attr”: attr, “thresh”: thresh, “op”: op}} to add a specific mask to a particular model.

  • vel_shift (bool) – Flags whether to apply doppler shift to the spectra.

  • verbose (bool) – Are we talking?

  • nthreads (int) – The number of threads to use for the tree search. If -1, all available threads will be used.

  • grid_assignment_method (str) – The method to use for assigning particles to the grid. Options are “cic” (cloud-in-cell) or “ngp” (nearest grid point).”

  • **kwargs (dict) – Any additional keyword arguments to pass to the generator function.

Returns:

dict

A dictionary of spectra which can be attached to the appropriate spectra attribute of the component (spectra/particle_spectra)

get_spectroscopy(instrument)[source]

Get spectroscopy for the component based on a specific instrument.

This will apply the instrument’s wavelength array to each spectra stored on the component.

Parameters:

instrument (Instrument) – The instrument to use for the spectroscopy.

Returns:

dict

The spectroscopy for the galaxy.

abstract get_weighted_attr(attr, weights, **kwargs)[source]

Return the weighted attribute.

property is_parametric

Return whether the component is parametric.

Returns:

bool

Whether the component is parametric.

property is_particle

Return whether the component is particle based.

Returns:

bool

Whether the component is particle based.

property photo_fluxes

Get the photometric fluxes.

Returns:

dict

The photometry fluxes.

property photo_luminosities

Get the photometric luminosities.

Returns:

dict

The photometry luminosities.

plot_spectra(spectra_to_plot=None, show=False, ylimits=(), xlimits=(), figsize=(3.5, 5), **kwargs)[source]

Plot the spectra of the component.

Can either plot specific spectra (specified via spectra_to_plot) or all spectra on the child object.

Parameters:
  • spectra_to_plot (string/list, string) –

    The specific spectra to plot.
    • If None all spectra are plotted.

    • If a list of strings each specifc spectra is plotted.

    • If a single string then only that spectra is plotted.

  • show (bool) – Flag for whether to show the plot or just return the figure and axes.

  • ylimits (tuple) – The limits to apply to the y axis. If not provided the limits will be calculated with the lower limit set to 1000 (100) times less than the peak of the spectrum for rest_frame (observed) spectra.

  • xlimits (tuple) – The limits to apply to the x axis. If not provided the optimal limits are found based on the ylimits.

  • figsize (tuple) – Tuple with size 2 defining the figure size.

  • kwargs (dict) – Arguments to the sed.plot_spectra method called from this wrapper.

Returns:

fig (matplotlib.pyplot.figure)

The matplotlib figure object for the plot.

ax (matplotlib.axes)

The matplotlib axes object containing the plotted data.

plot_spectroscopy(instrument_label, spectra_to_plot=None, show=False, ylimits=(), xlimits=(), figsize=(3.5, 5), fig=None, ax=None, **kwargs)[source]

Plot the instrument’s spectroscopy of the component.

This will plot the spectroscopy for the component using the instrument’s wavelength array. The spectra are plotted in the order they are stored in the spectroscopy dictionary.

Can either plot specific spectroscopy (specified via spectra_to_plot) or all spectroscopy on the component.

Parameters:
  • instrument_label (str) – The label of the instrument to use for the spectroscopy.

  • spectra_to_plot (string/list, string) –

    The specific spectroscopy to plot.
    • If None all spectra are plotted.

    • If a list of strings each specifc spectra is plotted.

    • If a single string then only that spectra is plotted.

  • show (bool) – Flag for whether to show the plot or just return the figure and axes.

  • ylimits (tuple) – The limits to apply to the y axis. If not provided the limits will be calculated with the lower limit set to 1000 (100) times less than the peak of the spectrum for rest_frame (observed) spectra.

  • xlimits (tuple) – The limits to apply to the x axis. If not provided the optimal limits are found based on the ylimits.

  • figsize (tuple) – Tuple with size 2 defining the figure size.

  • fig (matplotlib.pyplot.figure) – The matplotlib figure object for the plot.

  • ax (matplotlib.axes) – The matplotlib axes object containing the plotted data.

  • **kwargs (dict) – Arguments to the sed.plot_spectra method called from this wrapper.

Returns:

fig (matplotlib.pyplot.figure)

The matplotlib figure object for the plot.

ax (matplotlib.axes)

The matplotlib axes object containing the plotted data.

Examples using synthesizer.components.component.Component

Parametric Young Stars Example

Parametric Young Stars Example

Photometry example

Photometry example

Plot spectra example

Plot spectra example

Image addition example

Image addition example

Create image example

Create image example

Plot delta_lambda for a grid.

Plot delta_lambda for a grid.

Demonstrate the dense basis approach for describing the SFZH

Demonstrate the dense basis approach for describing the SFZH

Plot equivalent width for UV indices

Plot equivalent width for UV indices

Generating Lines from a Parametric Galaxy

Generating Lines from a Parametric Galaxy

Generate parametric observed SED

Generate parametric observed 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.

Generate parametric galaxy SED

Generate parametric galaxy SED

Compare SPS grid assignment methods

Compare SPS grid assignment methods

Compare parametric and particle SEDs

Compare parametric and particle SEDs

Create sampled SED

Create sampled SED

Plot line of sight optical depth calculations

Plot line of sight optical depth calculations

Plot line of sight diagnostics

Plot line of sight diagnostics

Rotating particle distributions

Rotating particle distributions

Compare Single star particle to instantaneous SFZH

Compare Single star particle to instantaneous SFZH