synthesizer.particle.particles¶
The base module from which all other particle types inherit.
This generic particle class forms the base class containing all attributes and methods common to all child particle types. It should rarely if ever be directly instantiated.
Classes
- class synthesizer.particle.particles.CoordinateGenerator[source]¶
A collection of functions for generating random coordinate arrays.
- generate_3D_gaussian(mean=array([0., 0., 0.]), cov=None)[source]¶
Generate for coordinates from a 3D gaussian distribution.
- Parameters:
n (int) – The number of coordinates to sample.
mean (np.ndarray of float) – The centre of the gaussian distribution. Must be a 3D array containing the centre along each axis.
cov (np.ndarray of float) – The covariance of the gaussian distribution.
- Returns:
The sampled coordinates in an (n, 3) array.
- Return type:
coords (np.ndarray of float)
- class synthesizer.particle.particles.Particles(coordinates, velocities, masses, redshift, softening_lengths, nparticles, centre, metallicity_floor=1e-05, tau_v=None, name='Particles')[source]¶
The base particle class.
All attributes of this class are optional keyword arguments in the child classes. Here we demand they are passed as positional arguments to protect against future changes.
- coordinates¶
The 3D coordinates of each particle.
- Type:
np.ndarray of float
- velocities¶
The 3D velocity of each stellar particle.
- Type:
np.ndarray of float
- masses¶
The mass of each particle in Msun.
- Type:
np.ndarray of float
- redshift¶
The redshift/s of the stellar particles.
- Type:
np.ndarray of float
- softening_length¶
The physical gravitational softening length.
- Type:
float
- nparticle¶
int How many particles are there?
- centre¶
Centre of the particle distribution.
- Type:
array, float
- metallicity_floor¶
The metallicity floor when using log properties (only matters for baryons). This is used to avoid log(0) errors.
- Type:
float
- tau_v¶
The V band optical depth.
- Type:
float
- radii¶
The radii of the particles.
- Type:
np.ndarray of float
- _grid_weights¶
Weights for each particle sorted onto a grid. This dictionary takes the form of {<method>: {grid_name: weights}} where weights is an array of the same shape as the grid containg the particles sorted onto the grid.
- Type:
dict, np.ndarray of float
- property angular_momentum¶
Calculate the total angular momentum vector of the particles.
- Returns:
The angular momentum vector of the particle system.
- Return type:
unyt_array
- calculate_centre_of_mass()[source]¶
Calculate the centre of mass of the collection of particles.
Uses the masses and coordinates attributes, and assigns the centre of mass to the centre attribute
- property centered_coordinates¶
Returns the coordinates centred on the geometric mean.
- get_attr_radius(weight_attr, frac=0.5)[source]¶
Calculate the radius of a particle distribution.
By default this will return the “half attr radius.”
- Parameters:
weight_attr (str) – The attribute to use to weight the particles.
frac (float) – The fraction of the total attribute for the radius.
- Returns:
The radius of the particle distribution.
- Return type:
radius (float)
- get_flux_radius(spectra_type, filter_code, frac=0.5)[source]¶
Calculate the radius of a particle distribution based on flux.
- Parameters:
spectra_type (str) – The type of spectra to use to compute radius.
filter_code (str) – The filter code to compute the radius for.
frac (float) – The fraction of the total light for the radius.
- Returns:
The radius of the particle distribution.
- Return type:
radius (float)
- get_flux_weighted_attr(attr, spectra_type, filter_code, axis=None)[source]¶
Get a flux weighted attribute.
This will compute the flux weighted average of an attribute using the provided weights.
- Parameters:
attr (str) – The attribute to weight.
spectra_type (str) – The type of spectra to use to compute the flux.
filter_code (str) – The filter code to compute the flux for.
axis (int) – The axis to compute the weighted attribute along.
- Returns:
The flux weighted attribute.
- Return type:
weighted_attr (float)
- get_half_flux_radius(spectra_type, filter_code)[source]¶
Calculate the half flux radius of the particle distribution.
- Parameters:
spectra_type (str) – The type of spectra to use to compute radius.
filter_code (str) – The filter code to compute the radius for.
- Returns:
The half flux radius of the particle distribution.
- Return type:
radius (float)
- get_half_luminosity_radius(spectra_type, filter_code)[source]¶
Calculate the half luminosity radius of the particle distribution.
- Parameters:
spectra_type (str) – The type of spectra to use to compute radius.
filter_code (str) – The filter code to compute the radius for.
- Returns:
The half luminosity radius of the particle distribution.
- Return type:
radius (float)
- get_half_mass_radius()[source]¶
Calculate the half mass radius of the particle distribution.
- Returns:
The half mass radius of the particle distribution.
- Return type:
radius (float)
- get_los_column_density(other_parts, density_attr, kernel, column_density_attr=None, mask=None, threshold=1, force_loop=0, min_count=100, nthreads=1)[source]¶
Calculate the column density of an attribute.
This will calculate the column density of an attribute on another Particles child instance at the positions of the particles in this Particles instance.
- Parameters:
other_parts (Particles) – The other particles to calculate the column density with.
density_attr (str) – The attribute to use to calculate the column density.
kernel (np.ndarray of 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.
column_density_attr (str) – The attribute to store the column density in on the Particles instance. If None, the column density will not be stored. By default this is None.
mask (array-like, 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) – Whether to force the use of a simple loop rather than the tree.
min_count (int) – The minimum number of particles allowed in a leaf cell when using the tree. This can be used for tuning the tree performance.
nthreads (int) – The number of threads to use for the calculation.
- Returns:
The column density of the particles.
- Return type:
column_density (float)
- get_lum_weighted_attr(attr, spectra_type, filter_code, axis=None)[source]¶
Get a luminosity weighted attribute.
This will compute the luminosity weighted average of an attribute using the provided weights.
- Parameters:
attr (str) – The attribute to weight.
spectra_type (str) – The type of spectra to use to compute the luminosity.
filter_code (str) – The filter code to compute the luminosity for.
axis (int) – The axis to compute the weighted attribute along.
- Returns:
The luminosity weighted attribute.
- Return type:
weighted_attr (float)
- get_luminosity_radius(spectra_type, filter_code, frac=0.5)[source]¶
Calculate the radius of a particle distribution based on luminoisty.
- Parameters:
spectra_type (str) – The type of spectra to use to compute radius.
filter_code (str) – The filter code to compute the radius for.
frac (float) – The fraction of the total light for the radius.
- Returns:
The radius of the particle distribution.
- Return type:
radius (float)
- get_mask(attr, thresh, op, mask=None)[source]¶
Create a mask using a threshold and attribute on which to mask.
- 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 (array) – Optionally, a mask to combine with the new mask.
- Returns:
The mask array.
- Return type:
mask (np.ndarray)
- get_particle_photo_fnu(filters, verbose=True, nthreads=1)[source]¶
Calculate flux photometry using a FilterCollection object.
- Parameters:
filters (object) – A FilterCollection object.
verbose (bool) – Are we talking?
nthreads (int) – The number of threads to use for the integration. If -1, all threads will be used.
- Returns:
A dictionary of fluxes in each filter in filters.
- Return type:
dict
- get_particle_photo_lnu(filters, verbose=True, nthreads=1)[source]¶
Calculate luminosity photometry using a FilterCollection object.
- Parameters:
filters (FilterCollection) – A FilterCollection object.
verbose (bool) – Are we talking?
nthreads (int) – The number of threads to use for the integration. If -1, all threads will be used.
- Returns:
- A dictionary of rest frame broadband
luminosities.
- Return type:
photo_lnu (dict)
- get_projected_angular_coordinates(cosmo=None, los_dists=None)[source]¶
Get the projected angular coordinates in radians.
This will return the angular coordinates of the particles in radians projected along the line of sight axis (always the z-axis). The coordinates along the line of sight axis will be set to 0.0, to maintain the shape of coordinates array.
The coordinates will be centred on the centre of the particle distribution before calculating the angular coordinates. If the centre is not set then an error will be raised.
Note that a redshift is required if the los_dists aren’t given to convert the coordinates to angular coordinates. If this redshift is 0.0 then the particles will be treated as if they are at 10 pc (minimum distance) from the observer.
- Parameters:
cosmo (astropy.cosmology) – The cosmology object from which to derive the luminosity distance.
los_dists (unyt_quantity) – The line of sight distances to the particles. If None, this will be calculated using the redshift and cosmology object.
- Returns:
- The projected angular coordinates of the particles
in radians.
- Return type:
unyt_array
- get_projected_angular_imaging_props(cosmo)[source]¶
Get the projected angular imaging properties.
This is a convenience method to reduce repeated calculations when getting angular coordinates and smoothing lengths since they both require similar calculations. This method will return the projected angular coordinates and projected angular smoothing lengths of the particles in radians projected along the line of sight axis (always the z-axis). The coordinates along the line of sight axis will be set to 0.0, to maintain the shape of coordinates array.
- Parameters:
cosmo (astropy.cosmology) – The cosmology object from which to derive the luminosity distance.
- Returns:
- A tuple containing the projected angular coordinates and
projected angular smoothing lengths of the particles in radians.
- Return type:
tuple
- get_projected_angular_smoothing_lengths(cosmo=None, los_dists=None)[source]¶
Get the projected angular smoothing lengths in radians.
This will return the angular smoothing lengths of the particles in radians projected along the line of sight axis (always the z-axis). The coordinates along the line of sight axis will be set to 0.0, to maintain the shape of coordinates array.
Note that a redshift is required if the los_dists aren’t given to convert the coordinates to angular coordinates. If this redshift is 0.0 then the particles will be treated as if they are at 10 pc (minimum distance) from the observer.
- Parameters:
cosmo (astropy.cosmology) – The cosmology object from which to derive the luminosity distance.
los_dists (unyt_quantity) – The line of sight distances to the particles. If None, this will be calculated using the redshift and cosmology object.
- Returns:
- The projected angular smoothing lengths of the
particles in radians.
- Return type:
unyt_array
- get_radii()[source]¶
Calculate the radii of the particles.
- Returns:
The radii of the particles.
- Return type:
radii (np.ndarray of float)
- get_weighted_attr(attr, weights, axis=None)[source]¶
Get a weighted attribute.
This will compute the weighted average of an attribute using the provided weights.
- Parameters:
attr (str) – The attribute to weight.
weights (str/np.ndarray of float) – The weights to apply to the attribute. This can either be a string to get the attribute from the particle object or an array-like of the weights.
axis (int) – The axis to compute the weighted attribute along.
- Returns:
The weighted attribute.
- Return type:
weighted_attr (float)
- integrate_particle_spectra()[source]¶
Integrate any particle spectra to get integrated spectra.
This will take all spectra in self.particle_spectra and call the sum method on them, populating self.spectra with the results.
- property log10metallicities¶
Return particle metallicities in log (base 10).
Zero valued metallicities are set to metallicity_floor, which is set on initialisation of this particle object.
- Returns:
log10 particle metallicities.
- Return type:
log10metallicities (np.ndarray)
- property particle_photo_fluxes¶
Get the particle photometry fluxes.
- Returns:
- dict
The photometry fluxes.
- property particle_photo_luminosities¶
Get the photometry luminosities.
- Returns:
- dict
The photometry luminosities.
- rotate_edge_on(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:
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(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:
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 (np.ndarray of 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:
- A new instance of the particles with the rotated
coordinates, if inplace is False.
- Return type: