Child pages
  • Hyak_python_netcdf
Skip to end of metadata
Go to start of metadata

Below are steps to install the Python netCDF4 package:

srun -p build --time=2:00:00 --mem=100G --pty /bin/bash

module load anaconda_2.4

pip install netCDF4 --user


Below are steps to use the Python netCDF4 package.

Here is some netCDF file.


>>> import netCDF4 as nc

>>> q = nc.Dataset('')

>>> print q.dimensions.keys()

>>> print q.variables.keys()

>>> t=q.variables['temp']

>>> p=q.variables['p']

>>> p[1,2,3,4]                     #access element (1,2,3,4) of the netCDF variable p

Note that t and p are netCDF variable objects similar to a numpy multi-dimensional array.

(Indexing starts at 0 like in numpy but different from Matlab where indexing starts from 1.

Also the order of the indices in Python is reverse of the order in Matlab for the same netcdf file variable.)

Below tells you about the size of each axis.

>>> t.shape[0]


>>> t.shape[1]


>>> t.shape[2]


>>> t.shape[3]






  • No labels