synthesizer.particle.stars¶
A module for working with arrays of stellar particles.
Contains the Stars class for use with particle based systems. This houses 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_sfhz(sfzh, n, total_initial_mass,
smoothing_lengths=smoothing_lengths, tau_v=tau_vs, coordinates=coordinates, …)
Functions
- synthesizer.particle.stars.sample_sfhz(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_sfhz
¶
Compare parametric and particle SEDs
Compare SPS grid assignment methods
Plot line of sight diagnostics
Plot line of sight optical depth calculations
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_length=None, centre=None, metallicity_floor=1e-05, **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
- generate_line(grid, line_id, line_type, fesc, mask=None, method='cic', nthreads=0, verbose=False)[source]¶
Calculate rest frame line luminosity and continuum from an SPS Grid.
This is a flexible base method which extracts the rest frame line luminosity of this stellar population from the SPS grid based on the passed arguments.
- Parameters:
grid (Grid) – A Grid object.
line_id (list/str) – A list of line_ids or a str denoting a single line. Doublets can be specified as a nested list or using a comma (e.g. ‘OIII4363,OIII4959’).
line_type (str) – The type of line to extract from the Grid. This must match a type of spectra/lines stored in the Grid.
fesc (float/array-like, float) – Fraction of stellar emission that escapes unattenuated from the birth cloud. Can either be a single value or an value per star (defaults to 0.0).
mask (array) – A mask to apply to the particles (only applicable to particle)
method (str) – The method to use for the interpolation. Options are: ‘cic’ - Cloud in cell ‘ngp’ - Nearest grid point
nthreads (int) – The number of threads to use in the C extension. If -1 then all available threads are used.
- Returns:
- Line
An instance of Line contain this lines wavelenth, luminosity, and continuum.
- generate_lnu(grid, spectra_name, fesc=0.0, young=None, old=None, mask=None, verbose=False, do_grid_check=False, grid_assignment_method='cic', parametric_young_stars=None, parametric_sfh='constant', aperture=None, nthreads=0)[source]¶
Generate the integrated rest frame spectra for a given grid key spectra for all stars. Can optionally apply masks.
- Parameters:
grid (Grid) – The spectral grid object.
spectra_name (string) – The name of the target spectra inside the grid file.
fesc (float/array-like, float) – Fraction of stellar emission that escapes unattenuated from the birth cloud. Can either be a single value or an value per star (defaults to 0.0).
young (bool/float) – If not None, specifies age in Myr at which to filter for young star particles.
old (bool/float) – If not None, specifies age in Myr at which to filter for old star particles.
mask (array) – Boolean array of star particles to include
verbose (bool) – Flag for verbose output.
do_grid_check (bool) – Whether to check how many particles lie outside the grid. This is a sanity check that can be used to check the consistency of your particles with the grid. It is False by default because the check is extreme expensive.
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 there uppercase equivalents (CIC, NGP). Defaults to cic.
parametric_young_stars (bool/float) – If not None, specifies age in Myr below which we replace individual star particles with a 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.
aperture (float) – If not None, specifies the radius of a spherical aperture to apply to the particles.
nthreads (int) – The number of threads to use in the C extension. If -1 then all available threads are used.
- Returns:
Numpy array of integrated spectra in units of (erg / s / Hz).
- Return type:
numpy.ndarray
- generate_particle_line(grid, line_id, line_type, fesc, mask=None, method='cic', nthreads=0, verbose=False)[source]¶
Calculate rest frame line luminosity and continuum from an SPS Grid.
This is a flexible base method which extracts the rest frame line luminosity of this stellar population from the SPS grid based on the passed arguments and calculate the luminosity and continuum for each individual particle.
- Parameters:
grid (Grid) – A Grid object.
line_id (list/str) – A list of line_ids or a str denoting a single line. Doublets can be specified as a nested list or using a comma (e.g. ‘OIII4363,OIII4959’).
line_type (str) – The type of line to extract from the Grid. This must match a type of spectra/lines stored in the Grid.
fesc (float/array-like, float) – Fraction of stellar emission that escapes unattenuated from the birth cloud. Can either be a single value or an value per star (defaults to 0.0).
mask (array) – A mask to apply to the particles (only applicable to particle)
method (str) – The method to use for the interpolation. Options are: ‘cic’ - Cloud in cell ‘ngp’ - Nearest grid point
nthreads (int) – The number of threads to use in the C extension. If -1 then all available threads are used.
- Returns:
- Line
An instance of Line contain this lines wavelenth, luminosity, and continuum.
- generate_particle_lnu(grid, spectra_name, fesc=0.0, verbose=False, do_grid_check=False, mask=None, grid_assignment_method='cic', nthreads=0)[source]¶
Generate the particle rest frame spectra for a given grid key spectra for all stars. Can optionally apply masks.
- Parameters:
grid (Grid) – The spectral grid object.
spectra_name (string) – The name of the target spectra inside the grid file.
fesc (float/array-like, float) – Fraction of stellar emission that escapes unattenuated from the birth cloud. Can either be a single value or an value per star (defaults to 0.0).
young (bool/float) – If not None, specifies age in Myr at which to filter for young star particles.
old (bool/float) – If not None, specifies age in Myr at which to filter for old star particles.
verbose (bool) – Flag for verbose output. By default False.
do_grid_check (bool) – Whether to check how many particles lie outside the grid. This is a sanity check that can be used to check the consistency of your particles with the grid. It is False by default because the check is extreme expensive.
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 there uppercase equivalents (CIC, NGP). Defaults to cic.
nthreads (int) – The number of threads to use in the C extension. If -1 then all available threads are used.
- Returns:
Numpy array of integrated spectra in units of (erg / s / Hz).
- Return type:
numpy.ndarray
- get_sfzh(grid, grid_assignment_method='cic', nthreads=0)[source]¶
Generate the binned SFZH history of this collection of particles.
The binned SFZH produced by this method is equivalent to the weights used to extract spectra from the grid.
- Parameters:
grid (Grid) – The spectral grid object.
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 there 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
- plot_sfzh(grid, grid_assignment_method='cic', 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?