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 helper methods for generating random coordinate arrays from various distribution functions.

generate_3D_gaussian(mean=array([0., 0., 0.]), cov=None)[source]

A generator for coordinates from a 3D gaussian distribution.

Parameters:
  • n (int) – The number of coordinates to sample.

  • mean (array-like, float) – The centre of the gaussian distribution. Must be a 3D array containing the centre along each axis.

  • cov (array-like, float) – The covariance of the gaussian distribution.

Returns:

coords (array-like, float)

The sampled coordinates in an (n, 3) array.

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:

array-like, float

velocities

The 3D velocity of each stellar particle.

Type:

array-like, float

masses

The mass of each particle in Msun.

Type:

array-like, float

redshift

The redshift/s of the stellar particles.

Type:

array-like/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:

array-like, float

property angular_momentum

Calculate the total angular momentum vector of the particles.

Returns:

unyt_array

The angular momentum vector of the particle system.

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:

radius (float)

The radius of the particle distribution.

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:

radius (float)

The radius of the particle distribution.

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:

radius (float)

The half flux radius of the particle distribution.

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:

radius (float)

The half luminosity radius of the particle distribution.

get_half_mass_radius()[source]

Calculate the half mass radius of the particle distribution.

Returns:

radius (float)

The half mass radius of the particle distribution.

get_los_column_density(other_parts, density_attr, kernel, 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 (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 (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:

column_density (float)

The column density of the particles.

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:

radius (float)

The radius of the particle distribution.

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:

mask (array)

The mask array.

get_particle_photo_fnu(filters, verbose=True)[source]

Calculate flux photometry using a FilterCollection object.

Parameters:
  • filters (object) – A FilterCollection object.

  • verbose (bool) – Are we talking?

Returns:

(dict)

A dictionary of fluxes in each filter in filters.

get_particle_photo_lnu(filters, verbose=True)[source]

Calculate luminosity photometry using a FilterCollection object.

Parameters:
Returns:

photo_lnu (dict)

A dictionary of rest frame broadband luminosities.

get_radii()[source]

Calculate the radii of the particles.

Returns:

radii (array-like, float)

The radii of the particles.

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:

log10metallicities (array)

log10 particle metallicities.

property particle_photo_fluxes

Get the particle photometry fluxes.

Returns:

dict

The photometry fluxes.

property 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 (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.