galaxychop.data
module
Module galaxy-chop.
- class galaxychop.data.ParticleSetType(value)[source]
Bases:
enum.IntEnum
Name of the particle type.
Name and number that are used to describe the particle type in the
ParticleSet class
.
- class galaxychop.data.ParticleSet(ptype, m, x, y, z, vx, vy, vz, potential, softening)[source]
Bases:
object
ParticleSet class.
Creates a set particles of a particular type (stars, dark matter or gas) using masses, positions, velocities and potential energy.
- Parameters
ptype (ParticleSetType) – Indicates if this set corresponds to stars, dark matter or gas.
m (Quantity) – Particle masses. Shape: (n,1). Default unit: M_sun
x (Quantity) – Positions. Shapes: (n,1). Default unit: kpc.
y (Quantity) – Positions. Shapes: (n,1). Default unit: kpc.
z (Quantity) – Positions. Shapes: (n,1). Default unit: kpc.
vx (Quantity) – Velocities. Shapes: (n,1). Default unit: km/s.
vy (Quantity) – Velocities. Shapes: (n,1). Default unit: km/s.
vz (Quantity) – Velocities. Shapes: (n,1). Default unit: km/s.
potential (Quantity, default value = 0) – Specific potential energy of particles. Shape: (n,1). Default unit: (km/s)**2.
softening (Quantity, default value = 0) – Softening radius of particles. Shape: (1,). Default unit: kpc.
kinetic_energy (Quantity) – Specific kinetic energy of particles. Shape: (n,1). Default unit: (km/s)**2.
total_energy (Quantity) – Specific total energy of particles. Shape: (n,1). Default unit: (km/s)**2.
Jx (Quantity) – Components of angular momentum of particles. Shapes: (n,1). Default units: kpc*km/s.
Jy (Quantity) – Components of angular momentum of particles. Shapes: (n,1). Default units: kpc*km/s.
Jz (Quantity) – Components of angular momentum of particles. Shapes: (n,1). Default units: kpc*km/s.
has_potential (bool.) – Indicates if the specific potential energy is computed.
arr (Instances of
ArrayAccessor
) – Access to the attributes (defined with uttrs) of the provided instance, and if they are of atropy.units.Quantity type it converts them into numpy.ndarray.
- property angular_momentum_
Components of specific angular momentum in units of kpc*km/s.
- to_dataframe(attributes=None)[source]
Convert to pandas data frame.
This method constructs a data frame with the particles and parameters of
ParticleSet class
.- Parameters
attributes (tuple, default value = None) – Dictionary keys of ParticleSet parameters used to create the data frame. If it’s None, the data frame is constructed from all the parameters of the
ParticleSet class
.- Returns
DataFrame – Data frame of the particles with the selected parameters.
- Return type
pandas data frame
- class galaxychop.data.Galaxy(stars, dark_matter, gas)[source]
Bases:
object
Galaxy class.
Builds a galaxy object from a
ParticleSet
for each type of particle (stars, dark matter and gas).- Parameters
stars (
ParticleSet
) – Instance ofParticleSet
with stars particles.dark_matter (
ParticleSet
) – Instance ofParticleSet
with dark matter particles.gas (
ParticleSet
) – Instance of ParticleSet with gas particles.
- has_potential_
Indicates if this Galaxy instance has the potential energy computed.
- Type
bool
- to_dataframe(*, ptypes=None, attributes=None)[source]
Convert to pandas data frame.
This method builds a data frame from the particles of the Galaxy.
- Parameters
ptypes (tuple, default value = None) – Strings indicating the ParticleSetType to include. If it’s None, all particle types are included.
attributes (tuple, default value = None) – Dictionary keys of ParticleSet parameters used to create the data frame. If it’s None, the data frame is constructed from all the parameters of the
ParticleSet class
.
- Returns
DataFrame – Data frame of Galaxy with selected particles and parameters.
- Return type
pandas data frame
- to_hdf5(path_or_stream, metadata=None, **kwargs)[source]
Shortcut to
galaxychop.io.to_hdf5()
.It is responsible for storing a galaxy in HDF5 format. The procedure only stores the attributes
m
,x
,y
,z
,vx
,vy
andvz
, since all the other attributes can be derived from these, and thesoftenings
can be arbitrarily changed at the galaxy creation/reading process- Parameters
path_or_stream (str or file like.) – Path or file like objet to the h5 to store the galaxy.
metadata (dict or None (default None)) – Extra metadata to store in the h5 file.
kwargs – Extra arguments to the function
astropy.io.misc.hdf5.write_table_hdf5()
- property plot
Plot accessor.
- property kinetic_energy_
Specific kinetic energy of stars, dark matter and gas particles.
- Returns
tuple – (k_s, k_dm, k_g): Specific kinetic energy of stars, dark matter and gas respectively. Shape(n_s, n_dm, n_g). Unit: (km/s)**2
- Return type
Quantity
Examples
This returns the specific kinetic energy of stars, dark matter and gas particles respectively.
>>> import galaxychop as gchop >>> galaxy = gchop.Galaxy(...) >>> k_s, k_dm, k_g = galaxy.kinetic_energy_
- property potential_energy_
Specific potential energy of stars, dark matter and gas particles.
This property doesn’t compute the potential energy, only returns its value if it is already computed, i.e.
has_potential_
is True. To compute the potential use thegalaxychop.potential
function.- Returns
tuple – (p_s, p_dm, p_g): Specific potential energy of stars, dark matter and gas respectively. Shape(n_s, n_dm, n_g). Unit: (km/s)**2
- Return type
Quantity
Examples
This returns the specific potential energy of stars, dark matter and gas particles respectively.
>>> import galaxychop as gchop >>> galaxy = gchop.Galaxy(...) >>> galaxy_with_potential = gchop.potential(galaxy) >>> p_s, p_dm, p_g = galaxy_with_potential.potential_energy_
- property total_energy_
Specific total energy calculation.
Calculates the specific total energy of dark matter, star and gas particles.
- Returns
tuple – (Etot_s, Etot_dm, Etot_g): Specific total energy of stars, dark matter and gas respectively. Shape(n_s, n_dm, n_g). Unit: (km/s)**2
- Return type
Quantity
Examples
This returns the specific total energy of stars, dark matter and gas particles respectively.
>>> import galaxychop as gchop >>> galaxy = gchop.Galaxy(...) >>> E_s, E_dm, E_g = galaxy.total_energy_
- property angular_momentum_
Specific angular momentum calculation.
Compute the specific angular momentum of stars, dark matter and gas particles.
- Returns
tuple – (J_s, J_dm, J_g): Specific angular momentum of stars, dark matter and gas respectively. Shape(n_s, n_dm, n_g). Unit: (kpc * km / s)
- Return type
Quantity
Examples
This returns the specific angular momentum of stars, dark matter and gas particles respectively.
>>> import galaxychop as gchop >>> galaxy = gchop.Galaxy(...) >>> J_s, J_dm, J_g = galaxy.angular_momentum_
- galaxychop.data.galaxy_as_kwargs(galaxy)[source]
Galaxy init attributes as dictionary.
- Parameters
galaxy (Galaxy) – Instance of Galaxy.
- Returns
kwargs – Dictionary with
galaxy
attributes.- Return type
dict
- galaxychop.data.mkgalaxy(m_s: numpy.ndarray, x_s: numpy.ndarray, y_s: numpy.ndarray, z_s: numpy.ndarray, vx_s: numpy.ndarray, vy_s: numpy.ndarray, vz_s: numpy.ndarray, m_dm: numpy.ndarray, x_dm: numpy.ndarray, y_dm: numpy.ndarray, z_dm: numpy.ndarray, vx_dm: numpy.ndarray, vy_dm: numpy.ndarray, vz_dm: numpy.ndarray, m_g: numpy.ndarray, x_g: numpy.ndarray, y_g: numpy.ndarray, z_g: numpy.ndarray, vx_g: numpy.ndarray, vy_g: numpy.ndarray, vz_g: numpy.ndarray, softening_s: float = 0.0, softening_dm: float = 0.0, softening_g: float = 0.0, potential_s: Optional[numpy.ndarray] = None, potential_dm: Optional[numpy.ndarray] = None, potential_g: Optional[numpy.ndarray] = None)[source]
Galaxy builder.
This function builds a galaxy object from a star, dark matter and gas ParticleSet.
- Parameters
m_s (np.ndarray) – Star masses. Shape: (n,1).
x_s (np.ndarray) – Star positions. Shapes: (n,1).
y_s (np.ndarray) – Star positions. Shapes: (n,1).
z_s (np.ndarray) – Star positions. Shapes: (n,1).
vx_s (np.ndarray) – Star velocities. Shape: (n,1).
vy_s (np.ndarray) – Star velocities. Shape: (n,1).
vz_s (np.ndarray) – Star velocities. Shape: (n,1).
m_dm (np.ndarray) – Dark matter masses. Shape: (n,1).
x_dm (np.ndarray) – Dark matter positions. Shapes: (n,1).
y_dm (np.ndarray) – Dark matter positions. Shapes: (n,1).
z_dm (np.ndarray) – Dark matter positions. Shapes: (n,1).
vx_dm (np.ndarray) – Dark matter velocities. Shapes: (n,1).
vy_dm (np.ndarray) – Dark matter velocities. Shapes: (n,1).
vz_dm (np.ndarray) – Dark matter velocities. Shapes: (n,1).
m_g (np.ndarray) – Gas masses. Shape: (n,1).
x_g (np.ndarray) – Gas positions. Shapes: (n,1).
y_g (np.ndarray) – Gas positions. Shapes: (n,1).
z_g (np.ndarray) – Gas positions. Shapes: (n,1).
vx_g (np.ndarray) – Gas velocities. Shapes: (n,1).
vy_g (np.ndarray) – Gas velocities. Shapes: (n,1).
vz_g (np.ndarray) – Gas velocities. Shapes: (n,1).
potential_s (np.ndarray, default value = None) – Specific potential energy of star particles. Shape: (n,1).
potential_dm (np.ndarray, default value = None) – Specific potential energy of dark matter particles. Shape: (n,1).
potential_g (np.ndarray, default value = None) – Specific potential energy of gas particles. Shape: (n,1).
softening_s (float, default value = 0) – Softening radius of stellar particles. Shape: (1,).
softening_dm (float, default value = 0) – Softening radius of dark matter particles. Shape: (1,).
softening_g (float, default value = 0) – Softening radius of gas particles. Shape: (1,).
- Returns
galaxy
- Return type
Galaxy class
object.