Skip to content

Instantly share code, notes, and snippets.

@christopherlovell
Created March 25, 2019 17:39
Show Gist options
  • Save christopherlovell/4bb57b4516dd83621b04ffc34cdd89f8 to your computer and use it in GitHub Desktop.
Save christopherlovell/4bb57b4516dd83621b04ffc34cdd89f8 to your computer and use it in GitHub Desktop.
Read hdf5 snaps and concatenate
import numpy as np
import h5py
import glob
files = glob.glob('snap*')
coods = [None] * len(files)
ages = [None] * len(files)
metals = [None] * len(files)
mass = [None] * len(files)
for i,f in enumerate(files):
hf = h5py.File(f,'r')
coods[i] = hf['PartType4/Coordinates'][:]
ages[i] = hf['PartType4/GFM_StellarFormationTime'][:]
metals[i] = hf['PartType4/GFM_Metallicity'][:]
mass[i] = hf['PartType4/GFM_InitialMass'][:]
coods = np.vstack(coods)
ages = np.hstack(ages)
metals = np.hstack(metals)
mass = np.hstack(mass)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment