geodat.nc - Variable and Dimension utilities

This module contains the main classes for handling geophysical (climate) variables and dimensions. It also reads and writes NetCDF files.

The Dimension and Variable classes in this module act as containers of numpy arrays which can be easily accessed.

class geodat.nc.Variable(reader=None, varname=None, data=None, dims=None, attributes=None, history=None, parent=None, ensureMasked=False, **kwargs)[source]

A container for handling physical variable together with its dimensions so that while the variable is manipulated (e.g. averaged along one axis), the information of the dimensions change accordingly.

It can be indexed/sliced the same way as indexing a numpy array

class geodat.nc.Dimension(data, dimname=None, units=None, attributes=None, parent=None)[source]

A container for handling physical dimensions such as time, latitude. It can be indexed/sliced the same way as indexing a numpy array

See also

Examples

A physical variable of dimension (time,latitude,longitude) can be initialised:

>>> ## Defining dimension sizes
>>> ntime = 12; nlat=50; nlon=60

>>> # Time, with units and calendar
>>> time_dim = geodat.nc.Dimension(data=numpy.arange(ntime),
>>>                                units="months since 0001-01-01",
>>>                                dimname="time",
>>>                                attributes={"calendar":"julian"})

>>> # Latitudes, with units
>>> lat_dim = geodat.nc.Dimension(data=numpy.linspace(-90.,90.,nlat),
>>>                               units="degreeN", dimname="lat")

>>> # Longitudes, with units
>>> lon_dim = geodat.nc.Dimension(data=numpy.linspace(0.,360.,nlon),
>>>                               units="degreeE", dimname="lon")

>>> ## Defining the variable using the dimensions
>>> var = geodat.nc.Variable(data=numpy.arange(float(ntime*nlat*nlon)).reshape(ntime,nlat,nlon),
>>>                          dims=[time_dim,lat_dim,lon_dim],
>>>                          varname="temp")

>>> print var
<geodat.nc.Variable temp(time,lat,lon), shape: (12, 50, 60)>
Fork me on GitHub