synthesizer.particle.galaxy¶
A module containing all the funtionality for Particle based galaxies.
Like it’s parametric variant this module contains the Galaxy object definition from which all galaxy focused functionality can be performed. This variant uses Particle objects, which can either be derived from simulation data or generated from parametric models. A Galaxy can contain Stars, Gas, and / or BlackHoles.
Despite its name a Particle based Galaxy can be used for any collection of particles to enable certain functionality (e.g. imaging of a galaxy group, or spectra for all particles in a simulation.)
Example usage:
galaxy = Galaxy(stars, gas, black_holes, …) galaxy.stars.get_spectra(…)
Classes
- class synthesizer.particle.galaxy.Galaxy(name='particle galaxy', stars=None, gas=None, black_holes=None, redshift=None, centre=None, **kwargs)[source]¶
The Particle based Galaxy object.
When working with particles this object provides interfaces for calculating spectra, galaxy properties and images. A galaxy can be composed of any combination of particle.Stars, particle.Gas, or particle.BlackHoles objects.
Attributes:
- calculate_black_hole_metallicity(default_metallicity=0.012)[source]¶
Calculates the metallicity of the region surrounding a black hole. This is defined as the mass weighted average metallicity of all gas particles whose SPH kernels intersect the black holes position.
- Parameters:
default_metallicity (float) – The metallicity value used when no gas particles are in range of the black hole. The default is solar metallcity.
- dust_to_metal_vijayan19(stellar_mass_weighted_age=None, ism_metallicity=None)[source]¶
Calculate the dust to metal ratio based on stellar age and metallicity.
This uses a fitting function for the dust-to-metals ratio based on galaxy properties, from L-GALAXIES dust modeling.
Vijayan+19: https://arxiv.org/abs/1904.02196
Note this will recalculate the dust masses based on the new dust-to- metal ratio.
- Parameters:
stellar_mass_weighted_age (float) – Mass weighted age of stars in Myr. Defaults to None, and uses value provided on this galaxy object (in Gyr)
ism_metallicity (float) – Mass weighted gas-phase metallicity. Defaults to None, and uses value provided on this galaxy object (dimensionless)
- get_black_hole_los_tau_v(kappa, kernel, mask=None, threshold=1, force_loop=0, min_count=100, nthreads=1)[source]¶
Calculate the LOS optical depth for each black hole particle.
This will calculate the optical depth for each black hole particle based on the gas particle distribution. The black holes are considered to interact with a gas particle if gas_z > black_hole_z and the black hole postion is within the SPH kernel of the gas particle.
Note: the resulting tau_vs will be associated to the black_holes object at self.black_holes.tau_v.
- Parameters:
kappa (float) – The dust opacity in units of Msun / pc**2.
kernel (array_like/float) – A 1D description of the SPH kernel. Values must be in ascending order such that a k element array can be indexed for the value of impact parameter q via kernel[int(k*q)]. Note, this can be an arbitrary kernel.
mask (bool) – A mask to be applied to the black holes. Surface densities will only be computed and returned for black holes with True in the mask.
threshold (float) – The threshold above which the SPH kernel is 0. This is normally at a value of the impact parameter of q = r / h = 1.
force_loop (bool) – By default (False) the C function will only loop over nearby gas particles to search for contributions to the LOS surface density. This forces the loop over all gas particles.
min_count (int) – The minimum number of particles in a leaf cell of the tree used to search for gas particles. Can be used to tune the performance of the tree search in extreme cases. If there are fewer particles in a leaf cell than this value, the search will be performed with a brute force loop.
nthreads (int) – The number of threads to use in the tree search. Default is 1.
- get_data_cube(resolution, fov, lam, cube_type='hist', stellar_spectra=None, blackhole_spectra=None, kernel=None, kernel_threshold=1, quantity='lnu', nthreads=1)[source]¶
Make a SpectralCube from an Sed held by this galaxy.
Data cubes are calculated by smoothing spectra over the component morphology. The Sed used is defined by <component>_spectra.
If multiple components are requested they will be combined into a single output data cube.
NOTE: Either npix or fov must be defined.
- Parameters:
resolution (Quantity, float) – The size of a pixel. (Ignoring any supersampling defined by psf_resample_factor)
fov – float The width of the image in image coordinates.
lam (unyt_array, float) – The wavelength array to use for the data cube.
cube_type (str) – The type of data cube to make. Either “smoothed” to smooth particle spectra over a kernel or “hist” to sort particle spectra into individual spaxels.
stellar_spectra (string) – The stellar spectra key to make into a data cube.
blackhole_spectra (string) – The black hole spectra key to make into a data cube.
kernel (array-like, 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).
quantity (str) – The Sed attribute/quantity to sort into the data cube, i.e. “lnu”, “llam”, “luminosity”, “fnu”, “flam” or “flux”.
nthreads (int) – The number of threads to use in the tree search. Default is 1.
- Returns:
- SpectralCube
The spectral data cube object containing the derived data cube.
- get_map_gas_mass(resolution, fov, img_type='hist', kernel=None, kernel_threshold=1, nthreads=1)[source]¶
Make a mass map, either with or without smoothing.
- Parameters:
resolution (float) – The size of a pixel.
fov (float) – The width of the image in image coordinates.
img_type (str) – The type of image to be made, either “hist” -> a histogram, or “smoothed” -> particles smoothed over a kernel.
kernel (array-like, 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.
- Returns:
Image
- get_map_gas_metal_mass(resolution, fov, img_type='hist', kernel=None, kernel_threshold=1, nthreads=1)[source]¶
Make a gas metal mass map, either with or without smoothing.
TODO: make dust map!
- Parameters:
resolution (float) – The size of a pixel.
fov (float) – The width of the image in image coordinates.
img_type (str) – The type of image to be made, either “hist” -> a histogram, or “smoothed” -> particles smoothed over a kernel.
kernel (array-like, 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.
- Returns:
Image
- get_map_gas_metallicity(resolution, fov, img_type='hist', kernel=None, kernel_threshold=1, nthreads=1)[source]¶
Make a gas metallicity map, either with or without smoothing.
The metallicity in a pixel is the mass weighted average metallicity in that pixel.
TODO: make dust map!
- Parameters:
resolution (float) – The size of a pixel.
fov (float) – The width of the image in image coordinates.
img_type (str) – The type of image to be made, either “hist” -> a histogram, or “smoothed” -> particles smoothed over a kernel.
kernel (array-like, 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.
- Returns:
Image
- get_map_sfr(resolution, fov, img_type='hist', kernel=None, kernel_threshold=1, age_bin=unyt_quantity(100, 'Myr'), nthreads=1)[source]¶
Make a SFR map, either with or without smoothing.
Only stars younger than age_bin are included in the map. This is calculated by computing the initial mass map for stars in the age bin and then dividing by the size of the age bin.
- Parameters:
resolution (float) – The size of a pixel.
fov (float) – The width of the image in image coordinates.
img_type (str) – The type of image to be made, either “hist” -> a histogram, or “smoothed” -> particles smoothed over a kernel.
kernel (array-like, 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).
age_bin (unyt_quantity/float) – The size of the age bin used to calculate the star formation rate. If supplied without units, the unit system is assumed.
nthreads (int) – The number of threads to use in the tree search. Default is 1.
- Returns:
Image
- get_map_ssfr(resolution, fov, img_type='hist', kernel=None, kernel_threshold=1, age_bin=unyt_quantity(100, 'Myr'), nthreads=1)[source]¶
Make a SFR map, either with or without smoothing.
Only stars younger than age_bin are included in the map. This is calculated by computing the initial mass map for stars in the age bin and then dividing by the size of the age bin and stellar mass of the galaxy.
- Parameters:
resolution (float) – The size of a pixel.
fov (float) – The width of the image in image coordinates.
img_type (str) – The type of image to be made, either “hist” -> a histogram, or “smoothed” -> particles smoothed over a kernel.
kernel (array-like, 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).
age_bin (unyt_quantity/float) – The size of the age bin used to calculate the star formation rate. If supplied without units, the unit system is assumed.
nthreads (int) – The number of threads to use in the tree search. Default is 1.
- Returns:
Image
- get_map_stellar_age(resolution, fov, img_type='hist', kernel=None, kernel_threshold=1, nthreads=1)[source]¶
Make an age map, either with or without smoothing.
The age in a pixel is the initial mass weighted average age in that pixel.
- Parameters:
resolution (float) – The size of a pixel.
fov (float) – The width of the image in image coordinates.
img_type (str) – The type of image to be made, either “hist” -> a histogram, or “smoothed” -> particles smoothed over a kernel.
kernel (array-like, 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.
- Returns:
Image
- get_map_stellar_mass(resolution, fov, img_type='hist', kernel=None, kernel_threshold=1, nthreads=1)[source]¶
Make a mass map, either with or without smoothing.
- Parameters:
resolution (float) – The size of a pixel.
fov (float) – The width of the image in image coordinates.
img_type (str) – The type of image to be made, either “hist” -> a histogram, or “smoothed” -> particles smoothed over a kernel.
kernel (array-like, 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.
- Returns:
Image
- get_map_stellar_metal_mass(resolution, fov, img_type='hist', kernel=None, kernel_threshold=1, nthreads=1)[source]¶
Make a stellar metal mass map, either with or without smoothing.
- Parameters:
resolution (float) – The size of a pixel.
fov (float) – The width of the image in image coordinates.
img_type (str) – The type of image to be made, either “hist” -> a histogram, or “smoothed” -> particles smoothed over a kernel.
kernel (array-like, 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.
- Returns:
Image
- get_map_stellar_metallicity(resolution, fov, img_type='hist', kernel=None, kernel_threshold=1, nthreads=1)[source]¶
Make a stellar metallicity map, either with or without smoothing.
The metallicity in a pixel is the mass weighted average metallicity in that pixel.
- Parameters:
resolution (float) – The size of a pixel.
fov (float) – The width of the image in image coordinates.
img_type (str) – The type of image to be made, either “hist” -> a histogram, or “smoothed” -> particles smoothed over a kernel.
kernel (array-like, 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.
- Returns:
Image
- get_stellar_los_tau_v(kappa, kernel, mask=None, threshold=1, force_loop=0, min_count=100, nthreads=1)[source]¶
Calculate the LOS optical depth for each star particle.
This will calculate the optical depth for each star particle based on the gas particle distribution. The stars are considered to interact with a gas particle if gas_z > star_z and the star postion is within the SPH kernel of the gas particle.
Note: the resulting tau_vs will be associated to the stars object at self.stars.tau_v.
- Parameters:
kappa (float) – The dust opacity in units of Msun / pc**2.
kernel (array_like/float) – A 1D description of the SPH kernel. Values must be in ascending order such that a k element array can be indexed for the value of impact parameter q via kernel[int(k*q)]. Note, this can be an arbitrary kernel.
mask (bool) – A mask to be applied to the stars. Surface densities will only be computed and returned for stars with True in the mask.
threshold (float) – The threshold above which the SPH kernel is 0. This is normally at a value of the impact parameter of q = r / h = 1.
force_loop (bool) – By default (False) the C function will only loop over nearby gas particles to search for contributions to the LOS surface density. This forces the loop over all gas particles.
min_count (int) – The minimum number of particles in a leaf cell of the tree used to search for gas particles. Can be used to tune the performance of the tree search in extreme cases. If there are fewer particles in a leaf cell than this value, the search will be performed with a brute force loop.
nthreads (int) – The number of threads to use in the tree search. Default is 1.
- load_gas(masses=None, metallicities=None, gas=None, **kwargs)[source]¶
Load arrays for gas particle properties into a Gas object.
This will populate the gas attribute with the instantiated Gas object.
- Parameters:
masses – array_like (float) gas particle masses, Msol
metallicities – array_like (float) gas particle metallicity (total metal fraction)
gas (gas particle object) – A pre-existing gas particle object to use. Defaults to None.
**kwargs – Arbitrary keyword arguments.
- load_stars(initial_masses=None, ages=None, metallicities=None, stars=None, **kwargs)[source]¶
Load arrays for star properties into a Stars object.
This will populate the stars attribute with the instantiated Stars object.
- Parameters:
initial_masses (array_like, float) – Initial stellar particle masses (mass at birth), Msol
ages (array_like, float) – Star particle age, Myr
metallicities (array_like, float) – Star particle metallicity (total metal fraction)
stars (stars particle object) – A pre-existing stars particle object to use. Defaults to None.
**kwargs – Arbitrary keyword arguments.
- Returns:
None
- rotate_edge_on(component='stars', inplace=True)[source]¶
Rotate the particle distribution to edge-on.
This will rotate the particle distribution such that the angular momentum vector is aligned with the y-axis in an image
- Parameters:
component (str) – The component whose angular momentum vector should be used for the rotation. Options are “stars”, “gas” and “black_holes”.
inplace (bool) – Whether to perform the rotation in place or return a new instance.
- Returns:
- Particles
A new instance of the particles with rotated coordinates, if inplace is False.
- rotate_face_on(component='stars', inplace=True)[source]¶
Rotate the particle distribution to face-on.
This will rotate the particle distribution such that the angular momentum vector is aligned with the z-axis in an image.
- Parameters:
component (str) – The component whose angular momentum vector should be used for the rotation. Options are “stars”, “gas” and “black_holes”.
inplace (bool) – Whether to perform the rotation in place or return a new instance.
- Returns:
- Particles
A new instance of the particles with rotated coordinates, if inplace is False.
- rotate_particles(phi=unyt_quantity(0, 'rad'), theta=unyt_quantity(0, 'rad'), rot_matrix=None, inplace=True)[source]¶
Rotate coordinates.
This method can either use angles or a provided rotation matrix.
When using angles phi is the rotation around the z-axis while theta is the rotation around the y-axis.
This can both be done in place or return a new instance, by default this will be done in place.
- Parameters:
phi (unyt_quantity) – The angle in radians to rotate around the z-axis. If rot_matrix is defined this will be ignored.
theta (unyt_quantity) – The angle in radians to rotate around the y-axis. If rot_matrix is defined this will be ignored.
rot_matrix (array-like, float) – A 3x3 rotation matrix to apply to the coordinates instead of phi and theta.
inplace (bool) – Whether to perform the rotation in place or return a new instance.
- Returns:
- Particles
A new instance of the particles with the rotated coordinates, if inplace is False.
- screen_dust_gamma_parameter(gamma_min=0.01, gamma_max=1.8, beta=0.1, Z_norm=0.035, sf_gas_metallicity=None, sf_gas_mass=None, stellar_mass=None)[source]¶
Calculate the gamma parameter, controlling the optical depth due to dust dependent on the mass and metallicity of star forming gas.
gamma = gamma_max - (gamma_max - gamma_min) / C
C = 1 + (Z_SF / Z_MW) * (M_SF / M_star) * (1 / beta)
gamma_max and gamma_min set the upper and lower bounds to which gamma asymptotically approaches where the star forming gas mass is high (low) and the star forming gas metallicity is high (low), respectively.
Z_SF is the star forming gas metallicity, Z_MW is the Milky Way value (defaults to value from Zahid+14), M_SF is the star forming gas mass, M_star is the stellar mass, and beta is a normalisation value.
The gamma array can be used directly in attenuation methods.
Zahid+14: https://iopscience.iop.org/article/10.1088/0004-637X/791/2/130
- Parameters:
gamma_min (float) – Lower limit of the gamma parameter.
gamma_max (float) – Upper limit of the gamma parameter.
beta (float) – Normalisation value, default 0.1
Z_norm (float) – Metallicity normsalition value, defaults to Zahid+14 value for the Milky Way (0.035)
sf_gas_metallicity (array) – Custom star forming gas metallicity array. If None, defaults to value attached to this galaxy object.
sf_gas_mass (array) – Custom star forming gas mass array, units Msun. If None, defaults to value attached to this galaxy object.
stellar_mass (array) – Custom stellar mass array, units Msun. If None, defaults to value attached to this galaxy object.
- Returns:
Dust attentuation scaling parameter for this galaxy
- Return type:
gamma (array)