Getting Started
swiftgalaxy
facilitates analyses of individual galaxies from cosmological hydrodynamical simulations executed with the SWIFT code. The core SWIFTGalaxy
class makes selecting particles belonging to a galaxy, transforming their coordinates, masking its particle arrays, working with spherical or cylindrical coordinates, accessing its integrated properties computed by a halo finder, and more, easy. It is built upon the SWIFTDataset
from swiftsimio
and takes advantage of that module’s lazy-loading and unit-awareness features. Users already familiar with usage of swiftsimio
will find that any syntax to interact with a SWIFTDataset
also works with a SWIFTGalaxy
.
Requirements
python3.8
or higher is required (>=3.9
is preferred).
Python packages
Required:
swiftsimio
, required to provide theSWIFTDataset
class and related functionality (note thatswiftsimio
has additional required dependencies).numpy
, required to support various array operations.unyt
, required for unit calculations.
Optional:
scipy
, required to specify rotations via theRotation
class.velociraptor
, required to enable support for Velociraptor halo finder outputs.
Installing
swiftgalaxy
can be installed using the python packaging manager, pip
, or any other packaging manager that you wish to use:
pip install swiftgalaxy
Note
swiftgalaxy
is not hosted on PyPI yet, so pip install swiftgalaxy
will fail. Use the instructions below instead.
Note that this will also install required dependencies.
To set up the code for development, first clone the latest master from github:
git clone https://github.com/SWIFTSIM/swiftgalaxy.git
and install with pip
using the -e
flag,
pip install -e swiftgalaxy/
Quick start
Assuming we have a snapshot file snap.hdf5
, and a halo catalogue provided by Velociraptor halos.properties
, halos.catalog_groups
, etc., with the default names for the arrays of coordinates, velocities and particle_ids, we can initialise a SWIFTGalaxy
for the first row (indexed from 0) in the halo catalogue very easily:
from swiftgalaxy import SWIFTGalaxy, Velociraptor
sg = SWIFTGalaxy(
'snap.hdf5',
Velociraptor(
'halos',
halo_index=0
)
)
Like a SWIFTDataset
, the particle datasets are accessed as below, and all data are loaded ‘lazily’, on demand.
sg.gas.particle_ids
sg.dark_matter.coordinates
However, information from the halo finder is used to select only the particles identified as bound to this galaxy. The coordinate system is centred in both position and velocity on the centre and peculiar velocity of the galaxy, as determined by the halo finder. The coordinate system can be further manipulated, and all particle arrays will stay in a consistent reference frame at all times.
Again like for a SWIFTDataset
, the units and metadata are available:
sg.units
sg.metadata
The halo finder interface is accessible as shown below. What this interface looks like depends on the halo finder being used, but will provide values for the individual galaxy of interest.
sg.halo_finder
In this case with Velociraptor
, we can get the virial mass like this:
sg.halo_finder.masses.mvir
The further features of a SWIFTGalaxy
are detailed in the next sections.