Paicos: A Python package for analysis of (cosmological) simulations performed with Arepo

Summary Cosmological simulations evolve dark matter and baryons subject to gravitational and hydrodynamic forces (Vogelsberger et al


Statement of need
The Arepo code stores its data output as HDF5 files, which can easily be loaded as NumPy arrays using h5py.However, data visualization of the unstructured mesh used in Arepo is non-trivial and keeping track of the units used in the data outputs can also be a tedious task.The general purpose visualization and data analysis software package yt1 (Turk et al., 2011) and the visualization package py-sphviewer (Benitez-Llambay, 2015) are both able to perform visualizations of Arepo simulations.Paicos provides an alternative, which is specifically tailored to Arepo simulations.It is in this regard similar to swiftsimio (Borrow & Borrisov, 2020), which was developed specifically for SWIFT simulations (Schaller & others, 2023).
We have developed Paicos because we identified a need for an analysis code that simultaneously fulfills the following requirements: 1) is specifically written for analysis of Arepo simulations discretized on a Voronoi mesh 2) provides safeguards against errors related to conversions of cosmological and physical units 3) facilitates working with large data sets by supporting the saving and loading of reduced/derived data including units and metadata 4) contains enough functionality to be useful for practical research tasks while still being light-weight and well-documented enough that it can be installed, used and understood by a junior researcher with little or no assistance.

Overview of key Paicos features
The key Paicos features, which were implemented to fulfill the above requirements, are as follows: • Functionality for reading cell/particle and group/subhalo catalog data as saved by Arepo in the HDF5 format.• Unit-handling via astropy with additional support for the  and ℎ factors that are used in cosmological simulations.2• Functionality for automatically obtaining derived variables from the variables present in the Arepo snapshot (e.g. the cell volume, temperature, or magnetic field strength).Within Jupyter notebooks or an Ipython terminal: Tab completion to show which variables are available for a given data group (either by directly loading from the HDF5-file or by automatically calculating a derived variable).• Functionality for saving and loading data including cosmological and physical units in HDF5-files that automatically include all metadata from the original Arepo snapshot (i.e. the Header, Config and Param groups).• Functionality for creating slices and projections and saving them in a format that additionally includes information about the size, center and orientation of the image.• Functionality for creating 1D and 2D histograms (e.g.radial profiles and - phase-space plots) of large data sets (using OpenMP-enabled Cython).• Functionality for user customization, e.g.adding new units or functions for computing derived variables.• Functionality for selecting only a part of a snapshot for analysis and for storing this selection as a new reduced snapshot.
Finally, we also make public GPU implementations of projection functionalities, which are much faster than the OpenMP-parallel CPU implementations described above.The GPU implementations include a mass-conserving SPH-like projection and a ray tracing implementation using a bounding volume hierarchy (BVH) in the form of a binary radix tree for nearest neighbor searches.These GPU implementations use Numba (Lam et al., 2015) and CuPy (Okuta et al., 2017) and require that the user has a CUDA-enabled GPU.Our binary tree implementation follows the the GPU-optimized tree-construction algorithm described in (Karras, 2012) and the implementation of it found in the publicly available Cornerstone Octree GPU-library (Keller et al., 2023).Using our SPH-like implementation on an Nvidia A100 GPU, it takes less than a second to project 100 mio.particles onto an image plane with 4096 2 pixels.This speed enables interactive data exploration.We provide an example IPython widget illustrating this feature.Finally, we note that the returned images include physical units and can be used for scientific analysis.
Paicos is hosted on GitHub at https://github.com/tberlok/paicos.We strongly encourage contributions to Paicos by opening issues and submitting pull requests.