paicos.readers package
Submodules
paicos.readers.arepo_catalog module
This defines a reader for Arepo Friends-of-Friends (FoF) and subhalo catalog files
- class paicos.readers.arepo_catalog.Catalog(basedir='.', snapnum=None, load_all=False, to_physical=False, subfind_catalog=True, readonly_first_file=False, verbose=False)
Bases:
PaicosReaderThis is a Python class for reading Arepo group and subhalo catalogs. The class is based on a script originally written by Ewald Puchwein, which has since then been modified and included in Paicos.
The class takes in the path of the directory containing the catalog, the catalog number, and an optional basename parameter, and uses this information to locate and open the catalog files. The class also loads the catalog’s header, parameters, and configuration. The class also includes methods to extract the redshift, scale factor, and other properties of the catalog.
Important methods and attributes:
cat = Catalog()
- cat.Groupdict
Contains a dictionary of the FoF-catalog.
- cat.Subdict
Contains a dictionary of the Subfind-catalog.
- cat.Parametersdict
Contains information from the parameter file used in the simulation (e.g. param.txt).
- cat.Configdict
Contains information from the Config file used in the simulation (e.g. Config.txt).
- cat.Headerdict
Contains information about this particular catalog such as its time (e.g scale factor).
- cat.zfloat
The redshift.
- cat.hfloat
Reduced Hubble param (e.g. 0.67).
- cat.agefloat
The age of the Universe (only for cosmological runs).
- cat.lookback_timefloat
The age of the Universe (only for cosmological runs).
- __init__(basedir='.', snapnum=None, load_all=False, to_physical=False, subfind_catalog=True, readonly_first_file=False, verbose=False)
Initializes the Catalog class.
- Parameters:
basedir (str) – The path of the directory containing the catalogs (e.g. the ‘output’ folder).
snapnum (int) – The snapshot number.
load_all (bool) – Whether to immediately load all fields or not.
to_physical (bool) – whether to convert to physical unit upon loading the data. Default is False.
subfind_catalog (bool) – whether the simulation has subfind catalogs, when False the code will look for FoF-catalogs only.
readonly_first_file (bool) – when set to True the code will only read one catalog file (the first). This can significantly speed things up when one is only interested in the properties of the most massive groups in a simulation.
verbose (bool) – whether to print information, default is False.
- load_all_data()
Calling this method simply loads all the data in the catalog.
- save_new_catalog(basename, basedir=None, single_precision=False)
Save a new catalog containing only the currently loaded variables. Useful for reducing datasets to smaller sizes.
- class paicos.readers.arepo_catalog.PaicosDict(cat, subfind_catalog=True)
Bases:
dict
paicos.readers.arepo_snap module
This defines a reader for Arepo snapshot files
- class paicos.readers.arepo_snap.Snapshot(basedir, snapnum=None, basename='snap', load_all=False, to_physical=False, load_catalog=None, subhalonum=None, fofnum=None, verbose=False)
Bases:
PaicosReaderThis is a Python class for reading Arepo snapshots, which are simulations of the evolution of the universe using a code called Arepo. The class is based on a script originally written by Ewald Puchwein, which has since then been modified and included in Paicos.
The class takes in the path of the directory containing the snapshot, the snapshot number, and an optional basename parameter, and uses this information to locate and open the snapshot files. The class also loads the snapshot’s header, parameters, and configuration, and uses them to create a converter object that can be used to convert units in the snapshot. The class also includes methods to extract the redshift, scale factor, and other properties of the snapshot, as well as the subfind catalog if present.
Important methods and attributes:
snap = Snapshot()
- snap.Groupdict
Contains a dictionary of the FoF-catalog.
- snap.Subdict
Contains a dictionary of the Subfind-catalog.
- snap.Parametersdict
Contains information from the parameter file used in the simulation (e.g. param.txt).
- snap.Configdict
Contains information from the Config file used in the simulation (e.g. Config.txt).
- snap.Headerdict
Contains information about this particular catalog such as its time (e.g scale factor).
- snap.zfloat
The redshift.
- snap.hfloat
Reduced Hubble param (e.g. 0.67).
- snap.agefloat
The age of the Universe (only for cosmological runs).
- snap.lookback_timefloat
The age of the Universe (only for cosmological runs).
- snap.timefloat
The time stamp of the snapshot (only for non-cosmological runs).
- snap.box_sizearray with length 3
The dimensions of the simulation domain.
- __init__(basedir, snapnum=None, basename='snap', load_all=False, to_physical=False, load_catalog=None, subhalonum=None, fofnum=None, verbose=False)
Initialize the Snapshot class.
- Parameters:
basedir (str) – path of the directory containing the snapshot (e.g. the ‘output’ folder).
snapnum (int) – snapshot number.
basename (str) – name of the snapshot file, default is “snap”.
verbose (bool) – whether to print information about the snapshot, default is False.
no_snapdir (bool) – whether there is no snap directory, i.e., default is False.
load_catalog (bool) – whether to load the subfind catalog. The default None is internally changed to True for comoving simulations and to False for non-comoving simulations.
subhalonum (int) – optional parameter to only load a single subhalo.
fofnum (int) – optional parameter to only load a single FoF group.
- center_of_mass(parttype=None)
Finds the center of mass for the entire snapshot.
- parttype (default None):
If None, then all parttypes are included in the center-of-mass calculation. If e.g. parttype=0, then the center of mass of the gas is returned. if parttype=None, then the total center and a list of of the parttype centers are returned
This method can be used in combination with the select method to find the center of mass of a selection.
- info(parttype, verbose=True)
This function provides information about the keys of a certain particle type in a snapshot.
- Parameters:
(int) (partType) – An integer representing the particle type of interest, e.g. 0 for gas, 1 for DM etc.
(bool) (verbose) – A flag indicating whether or not to print the keys to the console. Defaults to True.
- Returns:
If the requested PartType exists in the file, a list of keys for that PartType is returned, otherwise None.
- Return type:
list or None
- load_data(parttype, blockname, debug=False)
Load data from hdf5 file(s). Example usage:
snap = Snapshot(...) snap.load_data(0, 'Density')
Note that subsequent calls does not reload the data. Reloading the data can be done explicitly:
snap.remove_data(0, 'Density') snap.load_data(0, 'Density')
- remove_data(parttype, blockname)
Remove data from object. Sometimes useful for for large datasets
- save_new_snapshot(basename, basedir=None, single_precision=False)
Save a new snapshot containing the currently loaded (derived) variables. Useful for reducing datasets to smaller sizes.
- select(selection_index, parttype=None)
Create a new snapshot object which will only contain cells with a selection_index.
Example use:
index = snap['0_Density'] > snap['0_Density'].unit_quantity*1e-6 selected_snap = snap.select(index, parttype=0)
- total_angular_momentum(center, parttype=None)
Finds the total angular momentum for the entire snapshot.
center: the center around which to calculate the angular momentum
- parttype (default None):
If None, then all parttypes are included in the calculation. If e.g. parttype=0, then total angular momentum of the gas is returned.
This method can be used in combination with the select method to find the total angular momentum of a selection.
paicos.readers.generic_snap module
- class paicos.readers.generic_snap.GenericSnapshot(basedir='.', snapnum=None, basename='snap', basesubdir='snapdir', load_all=True, to_physical=False, only_init=False, verbose=False)
Bases:
PaicosReaderThis is a very simple Snapshot class, which was written for use with general data (e.g. if one wants to make images of Ramses simulations).
Detailed documentation/example usage remains to be written, so please create an issue if you have trouble getting this to work.
- __init__(basedir='.', snapnum=None, basename='snap', basesubdir='snapdir', load_all=True, to_physical=False, only_init=False, verbose=False)
Please use see the docstring for the method ‘give_info’.
- give_info(boxsize_in_code_units, time_in_code_units, snapnum=None, length_unit=None, time_unit=None, mass_unit=None, comoving_sim=False, hubble_param=1, redshift=0, Omega0=1, OmegaLambda=0, OmegaBaryon=1)
- Parameters:
snapnum (int) – The snapshot number that you are analyzing
boxsize_in_code_units (float) – The box size of your simulation box, which is assumed to be cubic.
Optional parameters (needed when using units are enabled)
time_in_code_units : float
- length_unitastropy unit
The code unit used in the simulation. For length e.g. 0.2 * u.Unit(‘kpc’)
- time_unitastropy unit
The code unit used in the simulation. For time e.g. u.Unit(‘Myr’)
- mass_unitastropy unit
The code unit used in the simulation. For mass e.g. u.Unit(‘Msun’)
- set_data(data, key, unit=None)
Set data in the snapshot
- Parameters:
data (numpy array) – For instance the density, temperature etc
key (str) – The dictionary key.
unit (astropy unit) – You only need to set this if you have units turned on.
- set_positions(data, unit='arepo_length')
Use this to set the cell positions.
- set_volumes(data, unit='arepo_length^3')
Use this to set the cell volumes.
paicos.readers.paicos_readers module
Defines the PaicosReader, Histogram2DReader and ImageReader which can be used to load derived variables.
- class paicos.readers.paicos_readers.Histogram2DReader(basedir='.', snapnum=None, basename='2d_histogram')
Bases:
PaicosReaderThis is a subclass of the PaicosReader.
It reads the additional information stored by a Histogram2D instance and makes them accessible as attributes, i.e., colorlabel, normalize, logscale, hist2d, centers_x, centers_y.
- __init__(basedir='.', snapnum=None, basename='2d_histogram')
See documentation for the PaicosReader.
Returns a dictionary with additional attributes.
- class paicos.readers.paicos_readers.ImageReader(basedir='.', snapnum=None, basename='projection', load_all=True)
Bases:
PaicosReaderThis is a subclass of the PaicosReader.
It reads the additional information stored in image files and makes them accessible as attributes, i.e., extent, widths, center, direction and image_creator.
For projection files, it also tries to automatically get derived variables, e.g., if the hdf5 file contains
‘MagneticFieldSquaredTimesVolume’ and ‘Volume’
then it will automatically divide them to obtain the MagneticFieldSquared.
- __init__(basedir='.', snapnum=None, basename='projection', load_all=True)
See documentation for the PaicosReader.
Returns a dictionary with additional attributes.
- get_centered_image_coordinates()
- get_derived_images()
Calculate images automatically for convenience, e.g., 0_MagneticFieldSquaredTimesVolume and 0_Volume are divided to obtain a 2D-array with 0_MagneticFieldSquared
- get_image_coordinates()
- class paicos.readers.paicos_readers.PaicosReader(basedir='.', snapnum=None, basename='snap', basesubdir='snapdir', load_all=True, to_physical=False, verbose=False)
Bases:
dictThe PaicosReader can read any hdf5 file that contains the three groups: Header, Config and Parameters.
It uses these to automatically construct a variety quantities which become accessible as properties.
This class is subclassed by the Snapshot and Catalog classes.
- __init__(basedir='.', snapnum=None, basename='snap', basesubdir='snapdir', load_all=True, to_physical=False, verbose=False)
Initialize the PaicosReader class.
- Parameters:
basedir (str) – The path of the directory containing the hdf5 files (e.g. the ‘output’ folder).
snapnum (int) – e.g. the snapshot number
basename (str) – name of the file takes the form
basename_{:03d}.hdf5orbasename_{:03d}.{}.hdf5. Default issnap.basesubdir (str) – The name of the subfolder. Default is
snapdir.load_all (bool) – Whether to simply load all data, default is True.
to_physical (bool) – Whether to convert from comoving to physical variables upon load.
verbose (bool) – Whether to print information, default is False.
- property a
The scale factor.
- property age
The age of the universe in the simulation.
- find_unit(name, field)
Find unit for a given quantity.
- Parameters:
name – corresponds to a block name in Arepo snapshots, i.e., a key in one of the dictionaries defined in unit_specifications.py
field –
the name of of one of the dictionaries defined in the unit specifications, e.g,:
[‘default’, ‘voronoi_cells’, ‘dark_matter’, ‘stars’, ‘black_holes’, ‘groups’, ‘subhalos’]
- get_adiabiatic_index()
Returns the adiabatic index
- get_age(z)
Returns the age of the universe for a given redshift, z.
- get_lookback_time(z)
Returns the lookback time for a given redshift, z.
- get_paicos_quantity(data, name, field='default')
Convert some data to a PaicosQuantity.
- Parameters:
data – typically some numpy array, integer or float
name – corresponds to a block name in Arepo snapshots, i.e., a key in one of the dictionaries defined in unit_specifications.py
field –
the name of of one of the dictionaries defined in the unit specifications, e.g,:
[‘default’, ‘voronoi_cells’, ‘dark_matter’, ‘stars’, ‘black_holes’, ‘groups’, ‘subhalos’]
Returns: A PaicosQuantity
- property h
The reduced Hubble parameter
- property length
The unit of length used in the simulation.
- load_data(name, group=None)
Load data from a generic Paicos hdf5 file (written by a PaicosWriter instance).
The method requires that the data sets have a ‘unit’ attribute and hence does not work for Arepo hdf5 files. For this reason, this method is overloaded in the Snapshot and Catalog classes.
- property lookback_time
The lookback time.
- property mass
The unit of mass used in the simulation.
- rho_crit(z)
Returns the physical critical density (no a or h factors)
- property time
The time elapsed since the beginning of the simulation.
Only defined for non-comoving simulations.
- unit_quantity(astropy_unit_str)
Returns a Paicos quantity with value 1 and any astropy unit.
- uq(astropy_unit_str)
A short hand for the unit_quantity method.
- property velocity
One of the units used for velocities in the simulation.
Note: The a and h-scalings are not the same for velocities in the halo catalogs and in the snapshots.
- property z
The redshift.