:mod:`swiftsimio` is a toolkit for reading data produced by the SWIFT
astrophysics simulation code. It is used to ensure that all data have a
symbolic unit attached, and can be used for visualisation. Another key
feature is the use of the cell metadata in SWIFT snapshots to enable
efficient reading of sub-regions.
The SWIFT astrophysical simulation code is used widely. There exists many ways of reading the data from SWIFT, which outputs HDF5 files. These range from reading directly using :mod:`h5py` to using a complex system such as :mod:`yt`; however these either are unsatisfactory (e.g. a lack of unit information in reading HDF5), or too complex for most use-cases. :mod:`swiftsimio` provides an object-oriented API to dynamically read data from SWIFT outputs, including FOF and SOAP catalogues. An extension module for :mod:`swiftsimio` for using catalogues and snapshots in tandem is available: :mod:`swiftgalaxy`.
Getting set up with :mod:`swiftsimio` is easy; it (by design) has very few requirements. There are a number of optional packages that you can install to make the experience better and these are recommended.
Full documentation is available at [ReadTheDocs](http://swiftsimio.readthedocs.org).
is required. Unfortunately it is not
possible to support :mod:`swiftsimio` on versions of python lower than this.
- :mod:`numpy`, required for the core numerical routines.
- :mod:`h5py`, required to read data from the SWIFT HDF5 output files.
- :mod:`unyt`, required for symbolic unit calculations (depends on sympy`).
- :mod:`astropy`, required to represent cosmology information.
- :mod:`numba`, highly recommended should you wish to use the in-built visualisation tools.
- :mod:`scipy`, required if you wish to generate smoothing lengths for particle types that do not store this variable in the snapshots (e.g. dark matter)
- :mod:`tqdm`, required for progress bars for some long-running tasks. If not installed no progress bar will be shown.
:mod:`swiftsimio` can be installed using the pip python packaging manager,
or any other packaging manager that you wish to use:
pip install swiftsimio
Example usage is shown below, which plots a density-temperature phase diagram, with density and temperature given in CGS units:
import swiftsimio as sw
# This loads all metadata but explicitly does _not_ read any particle data yet
data = sw.load("/path/to/swift/output")
import matplotlib.pyplot as plt
data.gas.densities.convert_to_cgs()
data.gas.temperatures.convert_to_cgs()
plt.loglog()
plt.scatter(
data.gas.densities,
data.gas.temperatures,
s=1
)
plt.xlabel(fr"Gas density $\left[{data.gas.densities.units.latex_repr}\right]$")
plt.ylabel(fr"Gas temperature $\left[{data.gas.temperatures.units.latex_repr}\right]$")
plt.tight_layout()
plt.savefig("test_plot.png", dpi=300)In the above:
- All metadata is read in when the :meth:`swiftsimio.load` function is called.
- Only the densities and temperatures (corresponding to the
PartType0/DensitiesandPartType0/Temperatures) datasets are read in. - That data is only read in once the :meth:`~swiftsimio.objects.cosmo_array.convert_to_cgs` method is called.
- :meth:`~swiftsimio.objects.cosmo_array.convert_to_cgs` converts data in-place; i.e. it returns None.
- The data is cached: it is not re-read when
plt.scatteris called.
Please cite :mod:`swiftsimio` using the JOSS paper:
@article{Borrow2020,
doi = {10.21105/joss.02430},
url = {https://doi.org/10.21105/joss.02430},
year = {2020},
publisher = {The Open Journal},
volume = {5},
number = {52},
pages = {2430},
author = {Josh Borrow and Alexei Borrisov},
title = {swiftsimio: A Python library for reading SWIFT data},
journal = {Journal of Open Source Software}
}If you use any of the subsampled projection backends, we ask that you cite our relevant SPHERIC paper. Citing the arXiv version here is recommended as the ADS cannot track conference proceedings well.
@article{Borrow2021,
title={Projecting SPH Particles in Adaptive Environments},
author={Josh Borrow and Ashley J. Kelly},
year={2021},
eprint={2106.05281},
archivePrefix={arXiv},
primaryClass={astro-ph.GA}
}Code contributions are very welcome! A good place to start is the contributing guide and how to set up a development environment.
:mod:`swiftsimio` is licensed under GPL-3.0 and community members are expected to abide by the code of conduct.