SWIFTGalaxy is a module that extends SWIFTSimIO tailored to analyses of particles belonging to individual simulated galaxies. It inherits from and extends the functionality of the SWIFTDataset
. It understands the content of halo catalogues (supported: Velociraptor, Caesar, SOAP) and therefore which particles belong to a galaxy or other group of particles, and its integrated properties. The particles occupy a coordinate frame that is enforced to be consistent, such that particles loaded on-the-fly will match e.g. rotations and translations of particles already in memory. Intuitive masking of particle datasets is also enabled. Utilities to make working in cylindrical and spherical coordinate systems more convenient are also provided. Finally, tools to iterate efficiently over multiple galaxies are also provided.
Installation is as simple as pip install swiftgalaxy
. Dependencies for using Velociraptor catalogues can be installed with pip install swiftgalaxy[velociraptor]
. For SOAP and Caesar support use:
pip install git+https://github.com/SWIFTSIM/soap.git@soap_runtime pip install git+https://github.com/dnarayanan/caesar.git
Once installed, creating a SWIFTGalaxy
object to get started with analysis is simple! For instance, for a SWIFT simulation with a SOAP-format halo catalogue (an example - 300 MB - will be automatically downloaded):
from swiftgalaxy import SWIFTGalaxy, SOAP
from swiftgalaxy.demo_data import web_examples
sg = SWIFTGalaxy(
web_examples.virtual_snapshot,
SOAP(web_examples.soap, soap_index=0)
)
# access data for particles belonging to the galaxy:
sg.gas.temperatures
# access integrated properties from the halo catalogue
sg.halo_catalogue.spherical_overdensity_200_crit.soradius
# automatically generated spherical/cylindrical coordinates:
sg.gas.spherical_coordinates.r
# consistent coordinate transformations of all particles, even those not loaded yet:
from scipy.spatial.transform import Rotation
sg.rotate(Rotation.from_euler("x", 90, degrees=True))
# compatible with swiftsimio visualisation:
import numpy as np
import unyt as u
from swiftsimio import cosmo_array
from swiftsimio.visualisation import project_gas
import matplotlib.pyplot as plt
img = project_gas(
sg,
periodic=False,
resolution=256,
region=cosmo_array(
[-30, 30, -30, 30],
u.kpc,
comoving=True,
scale_factor=sg.metadata.a,
scale_exponent=1
),
)
plt.imsave("eagle6_galaxy.png", np.log10(img.T), origin="lower", cmap="inferno")
More usage examples can be found in the examples folder on github.
If your use of SWIFTGalaxy leads to a publication, please cite the swiftgalaxy entry in the ASCL (indexed on ADS). Ideally specify the version used (Zenodo DOI, git commit ID and/or version number) and link to the github repository. A PyOpenSci review leading to a JOSS submission is in progress, please check back for updated citation information.
@MISC{
2025ascl.soft05002O,
author = {{Oman}, Kyle A.},
title = "{swiftgalaxy}",
keywords = {Software},
howpublished = {Astrophysics Source Code Library, record ascl:2505.002},
year = 2025,
month = may,
eid = {ascl:2505.002},
pages = {ascl:2505.002},
archivePrefix = {ascl},
eprint = {2505.002},
adsurl = {https://ui.adsabs.harvard.edu/abs/2025ascl.soft05002O},
adsnote = {Provided by the SAO/NASA Astrophysics Data System}
}
Please also consider the citations requested for SWIFTSimIO.
Code contributions are very welcome! A good place to start is the contributing guide and how to set up a development environment.
SWIFTGalaxy is licensed under GPL-3.0 and community members are expected to abide by the code of conduct.