pynbody.test_utils.pyread_gadget_hdf5.pyread_gadget_hdf5#
- pynbody.test_utils.pyread_gadget_hdf5.pyread_gadget_hdf5(filename, ptype, var_name, sub_dir=None, smooth=None, cgsunits=None, physunits=None, floatunits=None, silent=None, nopanda=None, noloop=None, leaveh=None)[source]#
- NAME:
PYREAD_GADGET_HDF5
- PURPOSE:
This function reads in HDF5 outputs (snapshots, FOF and SubFind files) of the OWLS Gadget3 code
- CATEGORY:
I/O, HDF5, OWLS / PAISTE :)
- REQUIREMENTS:
import pandas as pd import h5py import numpy import fnmatch import os
- CALLING SEQUENCE:
from pyread_gadget_hdf5 import *
Result = pyread_gadget_hdf5(filename, ptype, var_name [, sub_dir=sub_dir, smooth=True, cgsunits=True, physunits=True,
floatunits=True, silent=True, nopanda=True, noloop=True, leaveh=True] )
- INPUTS:
- filename: Name of the file to read in. In case of a multiple files
output, any sub-file name can be given. The routine will take care of reading data from each sub-file.
- ptype: Defines either the particle type or the sub-set for
which the data has to be read in (see table below).
- sub_dir: Define the group (/FOF or /SUBFIND) from which
particle and/or subhaloes properties are read-in from (see table below).
ptype | snapshot | Old FOF ——+——————————+————-
0 | gas particles | FOF/ 1 | dark matter particles | FOF/NSF 2 | extra collisionless parts | FOF/SF 3 | extra collisionless parts | FOF/Stars 4 | star particles | - 5 | extra collisionless parts | - 6 | - | - 7 | virtual particles (TRAPHIC) | - 8 | - | - 9 | - | -
10 | - | -
ptype | SubFind / sub_dir=’FOF’ | SubFind / sub_dir=’SUBFIND’ ——+——————————+—————————–
0 | gas particles | gas particles 1 | dark matter particles | dark matter particles 2 | extra collisionless parts | extra collisionless parts 3 | extra collisionless parts | extra collisionless parts 4 | star particles | star particles 5 | extra collisionless parts | extra collisionless parts 6 | - | - 7 | - | - 8 | - | - 9 | - | -
10 | FOF | SUBFIND 11 | FOF/NSF | SUBFIND/NSF 12 | FOF/SF | SUBFIND/SF 13 | FOF/Stars | SUBFIND/Stars
var_name: Dataset to read in.
OPTIONAL INPUTS:
- sub_dir: Kind of data group to read:
‘FOF’ - friends-of-friends group file ‘SUBFIND’ - subfind group file
- KEYWORD PARAMETERS (set to True)
floatunits: returns quantities in single precision cgsunits: Converts from Gadget code units to CGS physunits: Converts from Gadget code units to Proper (with h-> h_73)
and a small change with 10^10 Msol to Msol, and ENTROPY!
silent: does not print any message on the screen smooth: reads SPH smoothed quantities noloop: limit the read in to only the file selected nopanda: convert from PANDAS dataframe to Numpy array (you still need Pandas to run!) leaveh: set to true to leave ‘litte h’ values as code ‘h’ dependency, will have no effect
unless cgsunits or physunits selected in which case it overrides them regarding h
- OUTPUTS:
An array (either 1D or 2D depending on variable) in PANDAS dataframe format or Numpy style, if nopanda=True set… but you shouldn’t as PANDAS is fast.
RESTRICTIONS:
PROCEDURE:
EXAMPLE:
Reading star positions from a snapshot file in CGS units:
pos = pyread_gadget_hdf5(‘snap_035.0.hdf5’, 4, ‘Coordinates’, cgsunits=True)
and in phys units (proper h_73^-1 Mpc):
pos = pyread_gadget_hdf5(‘snap_035.0.hdf5’, 4, ‘Coordinates’, physunits=True)
and in code units:
pos = pyread_gadget_hdf5(‘snap_035.0.hdf5’, 4, ‘Coordinates’)
Reading of FOF data from a SubFind output:
pos = pyread_gadget_hdf5(‘subhalo_035.0.hdf5’, 10, ‘CenterOfMass’, sub_dir=’fof’)
Reading of FOF gas particle data from a SubFind output:
FeIa= pyread_gadget_hdf5(‘subhalo_035.0.hdf5’, 0, ‘IronFromSNIa’, sub_dir=’fof’)
Reading of SPH Smoothed FOF gas particle data from a SubFind output:
SmoothFeIa = pyread_gadget_hdf5(‘subhalo_035.0.hdf5’, 0, ‘IronFromSNIa’, sub_dir=’fof’, smooth=True)
Reading of SUBFIND non-star-forming gas data from a SubFind output:
pos = pyread_gadget_hdf5(‘subhalo_035.0.hdf5’, 11, ‘Temperature’, sub_dir=’subfind’)
MODIFICATION HISTORY (by Alan Duffy):
1/09/13 Converted Claudio Dalla Vecchia’s superlative IDL script nread_gadget_hdf5.pro 5/09/13 Removed ‘ input ‘ as an option in the script 5/09/13 Removed ‘ noconversion ‘, default is to leave in Code units, i.e. don’t convert 5/09/13 Added ‘ cgsunits ‘ as the option to convert variables entirely to CGS units (the default switch in the IDL version) 5/09/13 Added ‘ physunits ‘ as an option to convert variables to proper units with h-> h_73 as well as masses to Msol instead of 10^10, and MaximumEntropy in particular changes 6/09/13 Added ‘ noloop ‘ as an option to force a read in from one file alone 6/09/13 Changed header information to match flake8 standard 25/09/13 Added ‘ leaveh ‘ as an option to make units remain in code ‘h’ dependency 08/01/14 Fixed bug on looping over subfiles 08/01/14 Force C-Contiguous array
Any issues please contact Alan Duffy on mail@alanrduffy.com or (preferred) twitter @astroduff