Skip to content

Instantly share code, notes, and snippets.

@prl900
Created April 1, 2019 21:40
Show Gist options
  • Save prl900/235139e6f2cc1d2e943f9819ba0f006c to your computer and use it in GitHub Desktop.
Save prl900/235139e6f2cc1d2e943f9819ba0f006c to your computer and use it in GitHub Desktop.
NetCDF to Numpy array conversion
import xarray as xr
import numpy as np
tp = xr.open_dataset("EU_TP_ERAI.nc").tp[:].data.astype(np.float32)
print(tp.shape)
np.savez("/g/data/fj4/scratch/tp", tp[:, :, :])
z = xr.open_dataset("EU_Z_ERAI.nc").z[:].data.astype(np.float32)
print(z.shape)
np.savez("/g/data/fj4/scratch/z", z[:, :, :, :])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment