gizio

A light-weight Python package for GIZMO snapshot IO

Build Status Documentation Status

About

There are two snapshot reading scripts readsnap.py and load_from_snapshot.py accompanying the GIZMO source code. gizio aims to replace load_from_snapshot.py with several improvements:

  • A more flexible interface to access field

  • A unit system powered by unyt

  • Easier format spec customization without source code modification

  • Easier to install and maintain as a Python package

We acknowledge yt and pynbody for interface design inspirations.

Demo

The sample data could be downloaded here.

Load a snapshot:

>>> import gizio
>>> snap = gizio.load('data/FIRE_M12i_ref11/snapshot_600.hdf5')

View its header:

>>> snap.header
{'time': unyt_quantity(13.79874688, 'Gyr'),
 'n_file': 1,
 'mass_tab': unyt_array([0., 0., 0., 0., 0., 0.], 'code_mass'),
 'f_sfr': 1,
 'f_cool': 1,
 'f_fb': 1,
 'f_age': 1,
 'f_met': 11,
 'n_part': array([ 753678, 1104128, 2567905,       0,  361239,       0], dtype=uint32),
 'n_part_pf': [array([ 753678, 1104128, 2567905,       0,  361239,       0], dtype=int32)],
 'box_size': unyt_quantity(60000., 'code_length'),
 'Om0': 0.272,
 'OmL': 0.728,
 'h': 0.702,
 'z': 0.0,
 'cosmological': True}

Load a field:

>>> snap['PartType0', 'Masses']
unyt_array([3.175186e-05, 3.175186e-05, 3.175186e-05, ..., 3.175186e-05,
            3.175186e-05, 3.175186e-05], dtype=float32, units='code_mass')

Load a field using shorthands:

>>> snap.pt['gas']['m']
unyt_array([3.175186e-05, 3.175186e-05, 3.175186e-05, ..., 3.175186e-05,
            3.175186e-05, 3.175186e-05], dtype=float32, units='code_mass')

Select particles by masking:

>>> gas = snap.pt['gas']
>>> hot_gas = gas[gas['t'].to_value('K') > 1e5]
>>> hot_gas['t'].min()
unyt_quantity(100000.79, dtype=float32, units='K')

Select particles by composing:

>>> star = snap.pt['star']
>>> baryon = gas | star
>>> len(gas)
753678
>>> len(star)
361239
>>> len(baryon)
1114917
>>> baryon['m']
unyt_array([3.1751861e-05, 3.1751861e-05, 3.1751861e-05, ...,
            2.2581291e-05, 2.3056862e-05, 2.7417644e-05], dtype=float32, units='code_mass')

Installation

Install latest stable version from PyPI:

pip install gizio

Install development version from source:

git clone https://github.com/galaxy-lab/gizio.git
cd gizio
pip install -e .