Galaxy class

This will read in a data file for a given galaxy and snap, returning the data in a variety of formats.

class galaxy.galaxy.Galaxy(name, snap=0, datadir=None, usesql=False, ptype=None, stride=1)[source]

A class to find, read and manipulate files for a single galaxy.

Args:
name (str):
short name used in filename of type ‘name_000.txt’, eg ‘MW’, ‘M31’.
snap (int):
Snap number, equivalent to time elapsed. Zero is starting conditions.
datadir (str):
Directory to search first for the required file. Optional, and a default list of locations will be searched.
usesql (bool):
If True, data will be taken from a PostgreSQL database instead of text files.
ptype (int or list):
Optional. Restrict data to this particle type, for speed. Only valid with usesql=True.
stride (int):
Optional. For stride=n, get every nth row in the table. Only valid with usesql=True.
Class attributes:
filepath (pathlib.Path object):
directory containing the data file
filename (str):
in name_snap.txt format, something like ‘MW_000.txt’
data (np.ndarray):
type, mass, position_xyz, velocity_xyz for each particle
read_db(ptype, stride)[source]

Get relevant data from a PostgreSQL database and format it to be identical to that read from test files.

Args:
ptype (int):
Optional. Restrict data to this particle type.
stride (int):
Optional. For stride=n, get every nth row in the table.
Changes:
self.time, self.particle_count and self.data are set.

Returns: nothing

get_filepath(datadir)[source]
Args:
datadir (str): path to search first for the required file
Returns:
pathlib.Path object. A directory containing the file.
Raises:
FileNotFoundError

Pretty boring housekeeping code, but may make things more resilient.

read_file()[source]

Read in a datafile in np.ndarray format, store in self.data.

Requires:
self.path and self.filename are already set.
Changes:
self.time, self.particle_count and self.data are set.

Returns: nothing

type2name(particle_type)[source]

Args: particle_type (int): valid values are 1, 2, or 3

Returns: typename (str): ‘DM’, ‘disk’ or ‘bulge’

name2type(typename)[source]

Args: typename (str): valid values are ‘DM’, ‘disk’ or ‘bulge’

Returns: particle_type (int): 1, 2, or 3 as used in data files

filter_by_type(particle_type, dataset=None)[source]

Subsets the data to a single particle type.

Args:
particle_type (int): for particles, 1=DM, 2=disk, 3=bulge dataset (array including a type column): defaults to self.data
Kwargs:
dataset (np.ndarray): optionally, a starting dataset other than self.data

Returns: np.ndarray: subset data

single_particle_properties(particle_type=None, particle_num=0)[source]

Calculates distance from the origin and magnitude of the velocity.

Kwargs:
particle_type (int):
a subset of the data filtered by 1=DM, 2=disk, 3=bulge
particle_num (int):
zero-based index to an array of particles
returns:
3-tuple of
Euclidean distance from origin (kpc), Euclidean velocity magnitude (km/s), particle mass (M_sun)
all_particle_properties(particle_type=None, as_table=True)[source]

Calculates distances from the origin and magnitude of the velocities for all particles (default) or a specied particle type.

Kwargs:
particle_type (int):
A subset of the data filtered by 1=DM, 2=disk, 3=bulge
as_table (boolean): Return type.
If True, an astropy QTable with units. If False, np.ndarrays for position and velocity
Returns:
QTable: The full list, optionally with units, optionally filtered by type.
component_count(particle_type=None)[source]
Kwargs: particle_type (int):
a subset of the data filtered by 1=DM, 2=disk, 3=bulge
Returns: Quantity:
The number of particles in the galaxy of this type
all_component_counts()[source]
Returns: list:
The number of particles of each type in the galaxy Ordered as [halo, disk, bulge]
component_mass(particle_type=None)[source]
Kwargs: particle_type (int):
a subset of the data filtered by 1=DM, 2=disk, 3=bulge
Returns: Quantity:
The aggregate mass of all particles in the galaxy of this type
all_component_masses()[source]
Returns: list:
The aggregate masses of particles of each type in the galaxy
get_array()[source]

Returns: all particle data in np.ndarray format

Pretty superfluous in Python (which has no private class members)

get_df()[source]

Returns: data as pandas dataframe

get_qtable()[source]

Returns: data as astropy QTable, with units

xyz()[source]

Returns position as a (3,N) array

vxyz()[source]

Returns velocity as a (3,N) array

m()[source]

Conventience method to return array of masses