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=None, **kwargs)[source]¶
Create stellar particles by sampling an SFZH array.
Deprecated since version Use:
sample_sfzh_from_array()instead, which samples within the grid cell for a continuous distribution and correctly conserves the total mass.- Parameters:
sfzh (np.ndarray) – The SFZH array (from parametric.Stars).
log10ages (np.ndarray) – The log10 age axis of the SFZH grid.
log10metallicities (np.ndarray) – The log10 metallicity axis of the SFZH grid.
nstar (int) – Number of stellar particles to produce.
initial_mass (unyt_quantity, optional) – The initial mass of each stellar particle. If
None, the total mass is split equally among nstar particles.**kwargs – Extra keyword arguments passed to
Stars.
- Returns:
A
Starsinstance.- Return type:
Examples using synthesizer.particle.stars.sample_sfzh¶
- synthesizer.particle.stars.sample_sfzh_from_array(sfzh, log10ages, log10metallicities, nstar, initial_mass=None, seed=None, **kwargs)[source]¶
Create stellar particles by continuously sampling an SFZH array.
This is the recommended replacement for
sample_sfzh(). Rather than returning ages and metallicities at the exact grid points it samples uniformly within each 2‑D histogram cell, producing a smooth continuous distribution.The total stellar mass is conserved: if initial_mass is
None, every particle receives the same mass such that the sum equals the total mass encoded in the SFZH.- Parameters:
sfzh (np.ndarray) – The 2‑D SFZH array from
Stars.log10ages (np.ndarray) – The log10 age axis of the SFZH grid.
log10metallicities (np.ndarray) – The log10 metallicity axis of the SFZH grid.
nstar (int) – Number of stellar particles to produce.
initial_mass (unyt_quantity, optional) – Total initial mass to assign. If
None, the total mass is taken fromnp.sum(sfzh)and split equally.seed (int, optional) – Random seed for reproducibility.
**kwargs – Extra keyword arguments passed to
Stars.
- Returns:
A
Starsinstance containing the sampled particles.- Return type:
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:
np.ndarray of float
- ages¶
The age of each stellar particle in yrs.
- Type:
np.ndarray of float
- metallicities¶
The metallicity of each stellar particle.
- Type:
np.ndarray of float
- tau_v¶
V-band dust optical depth of each stellar particle.
- Type:
np.ndarray of float
- alpha_enhancement¶
The alpha enhancement [alpha/Fe] of each stellar particle.
- Type:
np.ndarray of 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:
np.ndarray of float
- smoothing_lengths¶
The smoothing lengths (describing the sph kernel) of each stellar particle in simulation length units.
- Type:
np.ndarray of float
- s_oxygen¶
fractional oxygen abundance.
- Type:
np.ndarray of float
- s_hydrogen¶
fractional hydrogen abundance.
- Type:
np.ndarray of 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:
np.ndarray of float
- calculate_surviving_mass(grid, grid_assignment_method='cic')[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.
grid_assignment_method (str) – 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).
- Returns:
The total surviving mass of the stellar population in Msun.
- Return type:
unyt_quantity
- get_metal_dist(metallicities, grid_assignment_method='cic', nthreads=0)[source]¶
Generate the metallicity distribution in terms of mass.
- Parameters:
metallicities (np.ndarray of 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 (np.ndarray of 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:
The star formation rate of the stellar particles.
- Return type:
sfr (float)
- get_sfzh(log10ages, metallicities, 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 (np.ndarray of float) – The log10 ages of the desired SFZH.
metallicities (np.ndarray of float) – The 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
- 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.
**kwargs (dict) – Additional keyword arguments to be passed to the SFH object.
- plot_metal_dist(metallicities, nthreads=0, xlimits=(), ylimits=(), show=True)[source]¶
Plot the metallicity distribution in terms of mass.
- Parameters:
metallicities (np.ndarray of 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 (np.ndarray of 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:
The Figure object contain the plot axes. ax: The Axes object containing the plotted data.
- Return type:
fig
- renormalise_mass(stellar_mass)[source]¶
Renormalise the initial masses of the stars.
Renormalises and overwrites the initial masses inplace based on the input total stellar mass.
- Parameters:
stellar_mass (np.ndarray of 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 stars below a given age.
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?
- spatially_resample(resample_factor, kernel=None, seed=None, mask=None, attr_modes=None, velocity_dispersion=None, sfzh=None, sfh=None, metal_dist=None)[source]¶
Resample this stellar distribution spatially.
Each particle is replaced by resample_factor new particles whose positions are sampled from the SPH kernel centred on the original position. All standard Stars attributes and any extras registered at construction time (see
_custom_attr_names) are harvested automatically.When an SFZH is provided the ages, metallicities and masses are sampled from the joint SFZH distribution; otherwise
ages/metallicitiesare duplicated andinitial_masses/current_massesare divided proportionally.Per-attribute resampling is controlled via attr_modes. See
resample_by_mode()for available modes.Default modes per attribute:
initial_masses,current_masses→"proportional"softening_lengths→ scaled byresample_factor ** (-1/3)and tiled, likesmoothing_lengthsages,metallicities,alpha_enhancement,s_oxygen,s_hydrogen,tau_v→"duplicated"if per-particle, kept as-is if scalar**kwargsextras →"duplicated"
Warning
Optical depths need special treatment. Per-particle
tau_vis duplicated by default, which is appropriate for simple dust-screen optical depths. Iftau_vwas derived from line-of-sight column densities, recompute the line-of-sight optical depths on the resampled distribution to remain self-consistent.When sfzh, sfh, or metal_dist are provided, ages and metallicities are sampled from those distributions; attr_modes entries for
agesandmetallicitiesare ignored.- Parameters:
resample_factor (int) – Number of new particles per original particle (>= 2).
kernel (Kernel) – SPH kernel for position sampling (e.g.
Kernel("cubic")). Required.seed (int, optional) – Random seed for reproducibility.
mask (array-like, optional) – Boolean mask.
Trueparticles are resampled;Falseparticles are kept unchanged.attr_modes (dict, optional) – Override resampling mode for individual attributes. See
resample_by_mode().velocity_dispersion (float or unyt_quantity, optional) – Std. dev. of Gaussian velocity noise.
sfzh (parametric.Stars, optional) – Pre-built 2-D SFZH object. When provided, ages, metallicities and masses are sampled from this distribution.
sfh (synthesizer.parametric.sf_hist.Common, optional) – A star-formation history functional form. When provided with metal_dist, the two are evaluated on auto-derived grid axes and combined via outer product into a 2-D SFZH for joint sampling. When provided alone, ages are sampled from the 1-D SFH and metallicities are kept from the input particles.
metal_dist (synthesizer.parametric.metal_dist.Common, optional) – A metallicity distribution functional form. When provided with sfh, combined into a 2-D SFZH. When provided alone, metallicities are sampled from the 1-D MetalDist and ages are kept from the input.
- Returns:
A new Stars object with the resampled distribution.
- Return type:
- property total_mass¶
Return the total mass of the stellar particles.
- Returns:
The total mass of the stellar particles.
- Return type:
total_mass (float)