Skip to content

Instantly share code, notes, and snippets.

@smutch
Created July 8, 2020 09:24
Show Gist options
  • Save smutch/23d1200c1d4c44b72c5d2bb32dc98abb to your computer and use it in GitHub Desktop.
Save smutch/23d1200c1d4c44b72c5d2bb32dc98abb to your computer and use it in GitHub Desktop.
py: read postprocess grid
import numpy as np
import xarray as xa
import h5py as h5
PATH_IN = "/fred/oz078/smutch/intensity_mapping/baseline/imapping_testrun/HIMass_grids.h5"
SNAPSHOT = 250 # z=0
with h5.File(PATH_IN, "r") as fp:
ds = fp[f"Snap{SNAPSHOT:03d}"]
box_size = ds.attrs["box_size"][:]
dim = ds.attrs["dim"][:]
grid = xa.DataArray(
ds[:],
coords=[np.linspace(0, bs, d) for bs, d in zip(box_size, dim)],
dims=list("xyz"),
name="HIMass",
)
grid = grid.where(np.isfinite(grid), np.nan)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment