tberlok / paicos

An object-oriented Python package for analysis of (cosmological) simulations performed with Arepo
GNU General Public License v3.0
11 stars 3 forks source link

Support for several unit systems within same Python session #59

Open tberlok opened 8 months ago

tberlok commented 8 months ago

Here is a brief explanation of the "Re-declaration of arepo code units attempted within same Python session" error message that Paicos throws when a user tries to load two arepo snapshots that have differing unit systems.

Paicos is currently unable to handle this because the arepo code units, such as e.g. 'arepo_mass', need to be uniquely defined. This limitation of Paicos might become a problem if someone wants to compare snapshots from simulations using different unit systems. One approach would be to initialize the arepo code units only when they are actually needed. Users could then for each simulation make derived hdf5-files in e.g. cgs and then make their comparison using these derived hdf5-files.

Below is a more detailed description of the problem:

We use astropy to handle units. The strategy is to load data with the numeric values in the hdf5-files, i.e., we do not convert e.g. CGS during loading. This has the advantage that one can work with the code units, if one so wishes. In order to support this, we define Python session wide arepo units, e.g.,

arepo_mass = u.def_unit(
                ["arepo_mass"],
                unit_mass,
                prefixes=False,
                namespace=_ns,
                doc="Arepo mass unit",
                format={"latex": r"arepo\_mass"},
            )

where unit_mass is defined unit_mass = self.Parameters['UnitMass_in_g'] * u.g.

This becomes a problem if another snapshot is loaded which has a differing value of self.Parameters['UnitMass_in_g'].