synthesizer.particle.stars

A module for working with arrays of stellar particles.

Contains the Stars class for use with particle based systems. This contains all the data detailing collections of stellar particles. Each property is stored in (N_star, ) shaped arrays for efficiency.

We also provide functions for creating “fake” stellar distributions, by sampling a SFZH.

In both cases a myriad of extra optional properties can be set by providing them as keyword arguments.

Example usages:

stars = Stars(initial_masses, ages, metallicities,

redshift=redshift, current_masses=current_masses, …)

stars = sample_sfzh(sfzh, n, total_initial_mass,

smoothing_lengths=smoothing_lengths, tau_v=tau_vs, coordinates=coordinates, …)

Functions

synthesizer.particle.stars.sample_sfzh(sfzh, log10ages, log10metallicities, nstar, initial_mass=unyt_quantity(1.98841586e+30, 'kg'), **kwargs)[source]

Create “fake” stellar particles by sampling a SFZH.

Parameters:
  • sfhz (array-like, float) – The Star Formation Metallicity History grid (from parametric.Stars).

  • log10ages (array-like, float) – The log of the SFZH age axis.

  • log10metallicities (array-like, float) – The log of the SFZH metallicities axis.

  • nstar (int) – The number of stellar particles to produce.

  • intial_mass (int) – The intial mass of the fake stellar particles.

Returns:

stars (Stars)

An instance of Stars containing the fake stellar particles.

Examples using synthesizer.particle.stars.sample_sfzh

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

Classes

class synthesizer.particle.stars.Stars(initial_masses, ages, metallicities, redshift=None, tau_v=None, alpha_enhancement=None, coordinates=None, velocities=None, current_masses=None, smoothing_lengths=None, s_oxygen=None, s_hydrogen=None, softening_lengths=None, centre=None, metallicity_floor=1e-05, fesc=None, fesc_ly_alpha=None, **kwargs)[source]

The base Stars class.

This contains all data a collection of stars could contain. It inherits from the base Particles class holding attributes and methods common to all particle types.

The Stars class can be handed to methods elsewhere to pass information about the stars needed in other computations. For example a Galaxy object can be passed a stars object for use with any of the Galaxy helper methods.

Note that due to the many possible operations, this class has a large number of optional attributes which are set to None if not provided.

initial_masses

The intial stellar mass of each particle in Msun.

Type:

array-like, float

ages

The age of each stellar particle in yrs.

Type:

array-like, float

metallicities

The metallicity of each stellar particle.

Type:

array-like, float

tau_v

V-band dust optical depth of each stellar particle.

Type:

array-like, float

alpha_enhancement

The alpha enhancement [alpha/Fe] of each stellar particle.

Type:

array-like, float

resampled

Flag for whether the young particles have been resampled.

Type:

bool

current_masses

The current mass of each stellar particle in Msun.

Type:

array-like, float

smoothing_lengths

The smoothing lengths (describing the sph kernel) of each stellar particle in simulation length units.

Type:

array-like, float

s_oxygen

fractional oxygen abundance.

Type:

array-like, float

s_hydrogen

fractional hydrogen abundance.

Type:

array-like, float

imf_hmass_slope

The slope of high mass end of the initial mass function (WIP).

Type:

float

nstars

The number of stellar particles in the object.

Type:

int

fesc

The escape fractions of each stellar particle (i.e. the fraction of incident photons that escape the galaxy unreprocessed by the interstellar medium).

Type:

array-like, float

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

Generate the metallicity distribution of these stars in terms of mass.

Parameters:
  • metallicities (array-like, float) – The metallicity bins of the desired metallicity distribution.

  • grid_assignment_method (string) – The type of method used to assign particles to a SPS grid point. Allowed methods are cic (cloud in cell) or nearest grid point (ngp) or their uppercase equivalents (CIC, NGP). Defaults to cic.

  • nthreads (int) – The number of threads to use in the computation. If set to -1 all available threads will be used. Defaults to 0.

Returns:

Numpy array of containing the SFH.

Return type:

numpy.ndarray

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

Generate the SFH of these stars in terms of mass.

The SFH is calculated by summing the mass of the particles in each age bin defined by the input log10ages.

Parameters:
  • log10ages (array-like, float) – The log10 ages of the desired SFH.

  • grid_assignment_method (string) – The type of method used to assign particles to a SPS grid point. Allowed methods are cic (cloud in cell) or nearest grid point (ngp) or their uppercase equivalents (CIC, NGP). Defaults to cic.

  • nthreads (int) – The number of threads to use in the computation. If set to -1 all available threads will be used. Defaults to 0.

Returns:

Numpy array of containing the SFH.

Return type:

numpy.ndarray

get_sfr(timescale=unyt_quantity(10, 'Myr'))[source]

Return the star formation rate of the stellar particles.

Parameters:

timescale (float) – The timescale over which to calculate the star formation rate.

Returns:

sfr (float)

The star formation rate of the stellar particles.

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

Generate the binned SFZH history of these stars.

The binned SFZH is calculated by binning the particles onto the desired grid defined by the input log10ages and metallicities.

The binned SFZH produced by this method is equivalent to the weights used to extract spectra from the grid.

Parameters:
  • log10ages (array-like, float) – The log10 ages of the desired SFZH.

  • log10metallicities (array-like, float) – The logged metallicities of the desired SFZH.

  • grid_assignment_method (string) – The type of method used to assign particles to a SPS grid point. Allowed methods are cic (cloud in cell) or nearest grid point (ngp) or their uppercase equivalents (CIC, NGP). Defaults to cic.

  • nthreads (int) – The number of threads to use in the computation. If set to -1 all available threads will be used.

Returns:

Numpy array of containing the SFZH.

Return type:

numpy.ndarray

property log10ages

Return stellar particle ages in log (base 10).

Returns:

log10ages (array)

log10 stellar ages

parametric_young_stars(age, parametric_sfh, grid, **kwargs)[source]

Replace young stars with individual parametric SFH’s.

Can be either a constant or truncated exponential, selected with the parametric_sfh argument. The metallicity is set to the metallicity of the parent star particle.

Parameters:
  • age (float) – Age in Myr below which we replace Star particles. Used to set the duration of parametric SFH

  • parametric_sfh (string) – Form of the parametric SFH to use for young stars. Currently two are supported, Constant and TruncatedExponential, selected using the keyword arguments constant and exponential.

  • grid (Grid) – The spectral grid object.

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

Plot the metallicity distribution in terms of mass.

Parameters:
  • metallicities (array-like, float) – The metallicity bins of the desired metallicity distribution.

  • nthreads (int) – The number of threads to use in the computation. If set to -1 all available threads will be used. Defaults to 0.

  • xlimits (tuple) – The limits of the x-axis. If not set, the limits are set to the minimum and maximum of the log10ages.

  • ylimits (tuple) – The limits of the y-axis. If not set, the limits are set to the minimum and maximum of the SFH.

  • 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(log10ages, nthreads=0, xlimits=(), ylimits=(), show=True)[source]

Plot the SFH in terms of mass.

Parameters:
  • log10ages (array-like, float) – The log10 ages of the desired SFH.

  • nthreads (int) – The number of threads to use in the computation. If set to -1 all available threads will be used. Defaults to 0.

  • xlimits (tuple) – The limits of the x-axis. If not set, the limits are set to the minimum and maximum of the log10ages.

  • ylimits (tuple) – The limits of the y-axis. If not set, the limits are set to the minimum and maximum of the SFH.

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

renormalise_mass(stellar_mass)[source]

Renormalises and overwrites the initial masses. Useful when rescaling the mass of the system of stellar particles.

Parameters:

stellar_mass (array-like, float) – The stellar mass array to be renormalised.

resample_young_stars(min_age=100000000.0, min_mass=700, max_mass=1000000.0, power_law_index=-1.3, n_samples=1000.0, force_resample=False, verbose=False)[source]

Resample young stellar particles into individual HII regions, with a power law distribution of masses. A young stellar particle is a stellar particle with an age < min_age (defined in Myr?).

This function overwrites the properties stored in attributes with the resampled properties.

Note: Resampling and imaging are not supported. If attempted an error

is thrown.

Parameters:
  • min_age (float) – The age below which stars will be resampled, in yrs.

  • min_mass (float) – The lower bound of the mass interval used in the power law sampling, in Msun.

  • max_mass (float) – The upper bound of the mass interval used in the power law sampling, in Msun.

  • power_law_index (float) – The index of the power law from which to sample stellar

  • n_samples (int) – The number of samples to generate for each stellar particles younger than min_age.

  • force_resample (bool) – A flag for whether resampling should be forced. Only applicable if trying to resample and already resampled Stars object.

  • verbose (bool) – Are we talking?

property total_mass

Return the total mass of the stellar particles.

Returns:

total_mass (float)

The total mass of the stellar particles.