MeteoIODoc 20241005.2ccf54a9
How to write a spatial interpolation algorithm

Point measurements can be spatially interpolated by MeteoIO, through the use of interpolation algorithms. The user will then be able to choose for each meteorological parameter which interpolations could be applicable and the system will choose (through a heuristic) which one to apply at each time step (depending on the conditions of the moment, like the number of measurements).

Structure

The selection of which interpolation algorithm to use at any given time step, for a given parameter is performed by the Meteo2DInterpolator class. This class provides the interface for the spatial interpolations. The interpolation algorithms themselves derive from the InterpolationAlgorithm class that standardizes their public API (which would not be used by anything but a Meteo2DInterpolator object). It contains a getQualityRating() method that must return a quality index between 0 (algorithm not applicable) and 1 (perfect result if using this algorithm). This is currently only based on extremely simple heuristics, using general knowledge about the applicability of the various spatial interpolation methods depending on some obvious factors (number of measurement points, etc). The Meteo2DInterpolator object will call this method from all the algorithms listed by the user (in his io.ini configuration file) and keep the one that gets the highest score for interpolating the current parameter at the current time step. The interpolation is then done calling the algorithm's calculate method.

Implementation

It is therefore necessary to create in InterpolationAlgorithms.cc (and declared in the .h) a new class, named after the algorithm that will be implemented and inheriting InterpolationAlgorithm. Three methods need to be implemented:

  • a constructor that does the arguments parsing (if any);
  • double getQualityRating()
  • void calculate(Grid2DObject& grid)

The getQualityRating() method takes the meteorological parameter that will be interpolated and set the param private member to it. It then computes the private member nrOfMeasurments that contains the number of stations that have this meteorological parameter available by either calling getData(param, vecData, vecMeta), which also fills the vectors vecData and vecMeta with the available data (as double) and metadata (as StationData) or directly filling vecMeteo and vecMeta. Custom data preparation can obviously be done in this method.

The calculate method must properly erase and reset the grid that it receives before filling it. If necessary, (as is the case for precipitation, relative humidity and snow height, for example) the grid can be checked for min/max by calling checkMinMax() at the end of Meteo2DInterpolator::interpolate.It can also add extra information about the interpolation process (such as a regression coefficient or error estimate) to the InterpolationAlgorithm::info stringstream (which will be made available to external programs, such as GUIs).

The new class and its associated end user key must be used and its constructor called in AlgorithmFactory::getAlgorithm. It is recommended that any generic statistical spatial processing be implemented as a static class in libinterpol2D.cc so that it could be reused by other algorithms (see for example Interpol2D::IDW and IDWCore). In any case, proper doxygen documentation must be written alongside the implementation.

Documentation

The newly added interpolation algorithm must be added to the list of available algorithms in InterpolationAlgorithms.cc with a proper description. An example can also be given in the example section of the same file. Please feel free to add necessary bibliographic references to the bibliographic section!