Skip to content
Thomas Nipen edited this page Apr 21, 2020 · 60 revisions

The gridpp library contains a set of functions. As the command-line version of gridpp was built first, we are gradually collecting all the funtionality into a library. The library is written in C++, but automatic wrappers for python are created using SWIG. Bindings for other languages (like R) will be added in the future. All examples using the library in this wiki use the python interface.

The documentation for the library is found here. The header file with the available functions can be found in include/gridpp.h.

Python

After installing the package, gridpp can be loaded with import gridpp. There are no submodules in gridpp, so all functions are accessed with gridpp.<function>.

Although the documentation page above is for C++, the same functions are available in python, with the same function signature.

C++ type Python types
float Any scalar
int Any scalar
vec 1D np.array, list, tuple
vec2 2D np.array, list of lists, tuple of tuples
vec3 3D np.array, list of list of lists, tuple of tuple of tuples
Staticstic One of gridpp.Min, gridpp.Mean, gridpp.Median, gridpp.Max, gridpp.Std, gridpp.Variance, gridpp.Sum

Numpy arrays can be of any numeric dtype, such as 'float32', 'float64', 'int32'.

The functions in the library generally take scalar or arrays as inputs. Arrays can be passed in as tuples, lists, or numpy arrays. When a function returns an array, it will return it as a tuple.

Required setup for examples

To get ready for the examples in the next sections, run the code below to set up necessary variables (you will also need the test dataset). This retrieves air temperature from the first timestep of the test file.

import gridpp
import netCDF4

# Input grid
with netCDF4('input.nc', 'r) as input:
    ilats = input.variables['latitude'][:]
    ilons = input.variables['longitude'][:]
    ivalues = input.variables['air_temperature_2m'][0, :, :]
    igrid = gridpp.Grid(ilats, ilons)

# Output grid
with netCDF4('output.nc', 'r) as output:
    olats = output.variables['latitude'][:]
    olons = output.variables['longitude'][:]
    ogrid = gridpp.Grid(olats, olons)
Clone this wiki locally