synthesizer.parametric.stars

A module for creating and manipulating parametric stellar populations.

This is the parametric analog of particle.Stars. It not only computes and holds the SFZH grid but everything describing a parametric Galaxy’s stellar component.

Example usage:

stars = Stars(log10ages, metallicities, sfzh=sfzh)
stars.get_spectra(emission_model)
stars.plot_spectra()

Classes

class synthesizer.parametric.stars.Stars(log10ages, metallicities, initial_mass=None, surviving_mass=None, grid=None, morphology=None, sfzh=None, sf_hist=None, metal_dist=None, fesc=None, fesc_ly_alpha=None, **kwargs)[source]

The parametric stellar population object.

This class holds a binned star formation and metal enrichment history describing the age and metallicity of the stellar population, an optional morphology model describing the distribution of those stars, and various other important attributes for defining a parametric stellar population.

ages

The array of ages defining the age axis of the SFZH.

Type:

np.ndarray of float

metallicities

The array of metallicitities defining the metallicity axes of the SFZH.

Type:

np.ndarray of float

initial_mass

The total initial stellar mass. This is the total mass of stars formed, i.e. the integral of the SFH over time, and is not the same as the surviving mass which accounts for stellar evolution.

Type:

unyt_quantity/float

surviving_mass

The total surviving stellar mass. This is the total mass of stars currently alive, i.e. the integral of the SFH over time weighted by the fraction of stars that survive to each age, and is not the same as the initial mass which does not account for stellar evolution.

Type:

unyt_quantity/float

morphology

An instance of one of the morphology classes describing the stellar population’s morphology. This can be any of the family of morphology classes from synthesizer.morphology.

Type:

morphology.* e.g. Sersic2D

sfzh

An array describing the binned SFZH. If provided all following arguments are ignored.

Type:

np.ndarray of float

sf_hist

An array describing the star formation history.

Type:

np.ndarray of float

metal_dist

An array describing the metallicity distribution.

Type:

np.ndarray of float

sf_hist_func

An instance of one of the child classes of SFH. This will be used to calculate sf_hist and takes precedence over a passed sf_hist if both are present.

Type:

SFH.*

metal_dist_func

An instance of one of the child classes of ZH. This will be used to calculate metal_dist and takes precedence over a passed metal_dist if both are present.

Type:

ZH.*

instant_sf

An age at which to compute an instantaneous SFH, i.e. all stellar mass populating a single SFH bin.

Type:

float

instant_metallicity

A metallicity at which to compute an instantaneous ZH, i.e. all stellar populating a single ZH bin.

Type:

float

log10ages_lims

The log10(age) limits of the SFZH grid.

Type:

array_like_float

metallicities_lims

The metallicity limits of the SFZH grid.

Type:

np.ndarray of float

log10metallicities_lims

The log10(metallicity) limits of the SFZH grid.

Type:

np.ndarray of float

metallicity_grid_type
The type of gridding for the metallicity axis. Either:
  • Regular linear (“Z”)

  • Regular logspace (“log10Z”)

  • Irregular (None)

Type:

str

calculate_average_sfr(t_range=(0, 100000000.0))[source]

Calculate the average SFR over a given age range.

This method assumes that stars form at discrete time points given by self.ages, with the mass in self.get_sfh(). To calculate a continuous rate, it treats this mass as having formed uniformly in bins constructed around each age point.

Parameters:

t_range (tuple[float, float]) – The lookback age limits (t_start, t_end) in years over which to calculate the average SFR.

Returns:

The average SFR over the specified time range in Msun/yr.

Return type:

unyt_quantity

calculate_initial_mass_at_age(age)[source]

Calculate the initial mass of the stellar population at a given age.

This is the total mass of stars that were formed at the specified age given the star formation and metal enrichment history.

Parameters:

age (float or unyt_quantity) – The age at which to calculate the initial mass. This can be a float in years or a unyt quantity with time units.

Returns:

The total mass formed prior to this age.

calculate_mean_age()[source]

Calculate the mean age of the stellar population.

calculate_mean_metallicity()[source]

Calculate the mean metallicity of the stellar population.

calculate_median_age()[source]

Calculate the median age of the stellar population.

calculate_surviving_mass(grid)[source]

Calculate the surviving mass of the stellar population.

This is the total mass of stars that have survived to the present day given the star formation and metal enrichment history.

Parameters:

grid (Grid) – The grid to use for calculating the surviving mass. This is used to get the stellar fraction at each SFZH bin.

Returns:

The total surviving mass of the stellar population in Msun.

Return type:

unyt_quantity

calculate_surviving_mass_at_age(age, grid)[source]

Calculate the surviving mass at a given age.

This is the mass of stars remaining at the specified age given the star formation and metal enrichment history.

Parameters:
  • age (float or unyt_quantity) – The age at which to calculate the surviving mass. This can be a float in years or a unyt quantity with time units.

  • grid (Grid) – The grid to use for calculating the surviving mass. This is used to get the stellar fraction at each SFZH bin.

Returns:

The total mass formed prior to this age.

calculate_surviving_sfh(grid)[source]

Calculate the surviving SFH of the stellar population.

This is the distribution of surviving stars in age.

Parameters:

grid (Grid) – The grid to use for calculating the surviving SFH. This is used to get the stellar fraction at each SFH bin.

Returns:

The surviving SFH grid in Msun.

Return type:

np.ndarray

calculate_surviving_sfzh(grid)[source]

Calculate the surviving SFZH of the stellar population.

This is the distribution of surviving stars in age and metallicity given the star formation and metal enrichment history.

Parameters:

grid (Grid) – The grid to use for calculating the surviving SFZH. This is used to get the stellar fraction at each SFZH bin.

Returns:

The surviving SFZH grid in Msun.

Return type:

np.ndarray

get_at_earlier_time(age_offset=<synthesizer.units.Quantity object>)[source]

Get a new Stars object representing the population at age_offset.

This is done by applying a lookback time to the age grid and then remapping the SFZH onto the new grid using a particle Stars object to perform the remapping.

Parameters:

age_offset (unyt_quantity) – The offset to apply to the age grid.

Returns:

New Stars object on the requested grid.

Return type:

Stars

get_ionising_photon_luminosity(grid, ion='HI')[source]

Calculate the ionising photon luminosity from the grid.

Parameters:
  • grid (object, Grid) – The SPS Grid object from which to extract spectra.

  • ion (str) – The ion for which to calculate the ionising photon luminosity. Must be a recognised ion in the grid’s log10_specific_ionising_lum dictionary.

Return type:

float

Returns:

The ionising photon luminosity summed over the grid dimensions.

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

Return a mask based on the attribute and threshold.

Will derive a mask of the form attr op thresh, e.g. age > 10 Myr.

Parameters:
  • attr (str) – The attribute to derive the mask from.

  • thresh (float) – The threshold value.

  • op (str) – The operation to apply. Can be ‘<’, ‘>’, ‘<=’, ‘>=’, “==”, or “!=”.

  • mask (np.ndarray) – Optionally, a mask to combine with the new mask.

  • attr_override_obj (object) – An alternative object to check from the attribute. This is specifically used when an EmissionModel may have a fixed parameter override, but can be used more generally.

Returns:

The mask array.

Return type:

mask (np.ndarray)

get_metal_dist()[source]

Get the metallicity distribution of the stellar population.

Returns:

The metallicity distribution of the stellar population.

Return type:

unyt_array

get_sfh()[source]

Get the star formation history of the stellar population.

Returns:

The star formation history of the stellar population.

Return type:

unyt_array

get_sfzh(log10ages, metallicities, grid_assignment_method='cic', nthreads=0)[source]

Get the binned SFZH at the provided axes.

This method remaps the parametric SFZH onto a new grid defined by log10ages and metallicities. To do so, it first goes through a particle Stars object to perform the remapping using a conservative remap.

TODO: Along with spectra generation, this should be improved going forward to use a “cookie cutter” approach based on the bins overlaid on the existing grid.

Parameters:
  • log10ages (np.ndarray of float) – The log10 ages of the desired SFZH (bin centers, strictly monotonic).

  • metallicities (np.ndarray of float) – The metallicities of the desired SFZH (bin centers, strictly monotonic).

  • grid_assignment_method (str) –

    The grid assignment method to use when remapping from the particle Stars to the parametric Stars. Options are:

    • ”cic”: Cloud-in-cell assignment.

    • ”ngp”: Nearest grid point assignment.

  • nthreads (int) – The number of threads to use for the remapping. If -1 all available threads are used.

Returns:

New Stars object on the requested grid.

Return type:

Stars

get_weighted_attr(attr)[source]

Get a weighted attribute of the stellar population.

Parameters:

attr (str) – The attribute to get.

Returns:

The weighted attribute.

Return type:

unyt_quantity

plot_metal_dist(xlimits=(), ylimits=(), show=True)[source]

Plot the metallicity distribution of the stellar population.

Parameters:
  • xlimits (tuple) – The limits of the x-axis.

  • ylimits (tuple) – The limits of the y-axis.

  • show (bool) – Should we invoke plt.show()?

Returns:

fig

The Figure object contain the plot axes.

ax

The Axes object containing the plotted data.

plot_sfh(xlimits=(), ylimits=(), show=True)[source]

Plot the star formation history of the stellar population.

Parameters:
  • xlimits (tuple) – The limits of the x-axis.

  • ylimits (tuple) – The limits of the y-axis.

  • show (bool) – Should we invoke plt.show()?

Returns:

fig

The Figure object contain the plot axes.

ax

The Axes object containing the plotted data.

plot_sfzh(show=True)[source]

Plot the binned SZFH.

Parameters:

show (bool) – Should we invoke plt.show()?

Returns:

fig

The Figure object contain the plot axes.

ax

The Axes object containing the plotted data.

scale_mass_by_flux(flux, scale_filter, spectra_type)[source]

Scale the stellar mass to match a flux in a specific filter.

NOTE: This will overwrite the initial mass attribute.

Parameters:
  • flux (unyt_quantity) – The desired flux in scale_filter.

  • scale_filter (Filter) – The filter in which flux is measured.

  • spectra_type (str) – The spectra key with which to do this scaling, e.g. “incident” or “emergent”.

Raises:

MissingSpectraType – If the requested spectra doesn’t exist an error is thrown.

scale_mass_by_luminosity(lum, scale_filter, spectra_type)[source]

Scale the stellar mass to match a luminosity in a specific filter.

NOTE: This will overwrite the initial mass attribute.

Parameters:
  • lum (unyt_quantity) – The desired luminosity in scale_filter.

  • scale_filter (Filter) – The filter in which lum is measured.

  • spectra_type (str) – The spectra key with which to do this scaling, e.g. “incident” or “emergent”.

Raises:

MissingSpectraType – If the requested spectra doesn’t exist an error is thrown.

property sfh

Alias for get_sfh.