11 Create Netcdf Python
11 Create Netcdf Python
Python
Thanks to:
Stephen Pascoe.
We are using netCDF4-python!
There are many options for working with NetCDF files
in Python. In this example we have chosen to highlight
the use of the netCDF4-python module.
import time
# Global Attributes
dataset.description = 'bogus example script'
dataset.history = 'Created ' + time.ctime(time.time())
dataset.source = 'netCDF4 python module tutorial'
Attributes (variable)
Variable attributes are set by assigning values to
Variable instance variables:
# Variable Attributes
latitudes.units = 'degree_north'
longitudes.units = 'degree_east'
levels.units = 'hPa'
temp.units = 'K'
>>> dataset.close()
# and the file is written!
I wonder what it looks like
netcdf test {
dimensions:
level = 10 ;
time = UNLIMITED ; // (5 currently)
lat = 73 ;
lon = 144 ;
variables:
double time(time) ;
time:units = "hours since 0001-01-01 00:00:00.0" ;
time:calendar = "gregorian" ;
int level(level) ;
level:units = "hPa" ;
float latitude(lat) ;
latitude:units = "degrees north" ;
float longitude(lon) ;
longitude:units = "degrees east" ;
float temp(time, level, lat, lon) ;
temp:units = "K" ;
// global attributes:
:description = "bogus example script" ;
:history = "Created Mon Mar 17 01:12:31 2014" ;
:source = "netCDF4 python module tutorial" ;
}
Further reading
Python-netCDF4:
http://netcdf4-python.googlecode.com/svn/trunk/docs/netCDF4-module.html