Galaxies class¶
This stores and manipulates data for multiple galaxies and snaps.
-
class
galaxy.galaxies.Galaxies(names=('MW', 'M31', 'M33'), snaps=(0, 0, 0), datadir=None, usesql=False, ptype=None, stride=1)[source]¶ A class to manipulate data for multiple galaxies.
- Kwargs:
- names (iterable of str):
- short names used in filename of type ‘name_000.txt’, eg ‘MW’, ‘M31’.
- snaps (iterable of 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):
- 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:
- path (pathlib.Path object):
- directory (probably) containing the data files
- filenames (list of str):
- in name_snap format, something like ‘MW_000’ (no extension)
- galaxies (dict):
- key is filename, value is the corresponding Galaxy object
-
read_data_files()[source]¶ Attempts to create a Galaxy object for each name/snap combination set in self.names and self.snaps
No return value. Sets self.galaxies, a dictionary keyed on name_snap
-
get_pivot(aggfunc, values='m')[source]¶ Generic method to make a pandas pivot table from the 9 combinations of galaxy and particle type.
- Args:
- aggfunc (str): ‘count’, ‘sum’, etc as aggregation method values (str): column name to aggregate
Returns: pandas dataframe
-
get_full_df()[source]¶ Combined data for all input files.
- Returns:
- Concatenated pandas dataframe from all galaxies Includes ‘name’ and ‘snap’ columns
-
get_coms(tolerance=0.1, ptypes=(1, 2, 3))[source]¶ Center of Mass determination for all galaxies. Defaults to all particle types, but ptypes=(2,) may be more useful.
- Args:
- tolerance (float): convergence criterion (kpc)
- Returns:
- QTable with COM positions and velocities colnames: [‘name’, ‘ptype’, ‘x’, ‘y’, ‘z’, ‘vx’, ‘vy’, ‘vz’, ‘R’, ‘V’]
-
separations(g1, g2)[source]¶ Position and velocity of galaxy g2 COM relative to g1 COM. Uses only disk particles for the COM determination.
- Args:
- g1, g2 (str): galaxies matching entries in self.filenames
- Returns:
- Dictionary containing relative position, distance, velocities in Cartesian and radial coordinates