-
Notifications
You must be signed in to change notification settings - Fork 16
Gridpp library
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.
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.
As of now, when a function returns an array, it will return it as a tuple.
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)