-
Notifications
You must be signed in to change notification settings - Fork 18
Gridpp API
The gridpp library contains functions for the core algorithms in gridpp. Gridpp is written in C++, but automatic wrappers for python and R are created using SWIG. This wiki focuses on examples using the python interface.
The documentation for the functions in the API is found at https://metno.github.io/gridpp/. This wiki describes the features of the latest released version of gridpp, however the API reference contains lists of functions for all versions of the API
Many gridpp functions are configured to run on multiple processors. To enable this, either set the OMP_NUM_THREADS= environment variable to the number of parallel threads to use, or call the following function, before calling any other functions:
gridpp.set_omp_threads(4)If OMP_NUM_THREADS= is not set and gridpp.set_omp_threads() is never called, a default of 1 thread will be used. This applies not only to python, but C++, and R bindings.
Functions will throw std::invalid_argument exceptions when input arguments are invalid and std::runtime_error for other errors. These exceptions are passed through the SWIG layer and trapped by the language bindings. The language bindings can in addition throw a type error exception when the wrong object type is passed to the function. Here is how the exceptions are translated into python:
| C++ | Python | Causes |
|---|---|---|
std::invalid_argument |
ValueError |
Invalid argument value (for example a negative radius, or dimension mismatch among arguments) |
| N/A | TypeError |
Argument has wrong type (for example passing an array when a scalar is expected) |
std::runtime_error |
RuntimeError |
Error during processing |