MeteoIODoc 2.11.0
InterpolationAlgorithms.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-3.0-or-later
2/***********************************************************************************/
3/* Copyright 2010 WSL Institute for Snow and Avalanche Research SLF-DAVOS */
4/***********************************************************************************/
5/* This file is part of MeteoIO.
6 MeteoIO is free software: you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 MeteoIO is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public License
17 along with MeteoIO. If not, see <http://www.gnu.org/licenses/>.
18*/
19#ifndef INTERPOLATIONALGORITHMS_H
20#define INTERPOLATIONALGORITHMS_H
21
28
29#include <vector>
30#include <string>
31
32namespace mio {
33
34class Meteo2DInterpolator; // forward declaration, cyclic header include
35
36class Trend {
37 public:
38 Trend(const std::vector< std::pair<std::string, std::string> >& vecArgs, const std::string& algo, const std::string& i_param);
39
40 void detrend(const std::vector<StationData>& vecMeta, std::vector<double> &vecDat);
41 void retrend(const DEMObject& dem, Grid2DObject &grid) const;
42
43 std::string getInfo() const;
44 bool has_user_lapse() const {return (user_lapse!=IOUtils::nodata);}
45 bool is_soft() const {return soft;}
46
47 std::string toString() const;
48 private:
49 void initTrendModel(const std::vector<double>& vecAltitudes, const std::vector<double>& vecDat);
50 bool multilinearDetrend(const std::vector<StationData>& vecMeta, std::vector<double> &vecDat);
51 void multilinearRetrend(const DEMObject& dem, Grid2DObject &grid) const;
52 static std::vector<double> getStationAltitudes(const std::vector<StationData>& vecMeta);
53
54 FitLinClosedForm multi_trend;
55 Fit1D trend_model;
56 const std::string param;
57 double user_lapse;
58 double trend_min_alt, trend_max_alt;
59 bool frac, soft, multilinear;
60};
61
71 public:
72 InterpolationAlgorithm(const std::vector< std::pair<std::string, std::string> >& /*vecArgs*/,
73 const std::string& i_algo, const std::string& i_param, TimeSeriesManager& i_tsm) :
74 algo(i_algo), tsmanager(i_tsm), date(0., 0), vecMeteo(), vecData(),
75 vecMeta(), info(), param(i_param), nrOfMeasurments(0) {}
77
78 //if anything is not ok (wrong parameter for this algo, insufficient data, etc) -> return zero
79 virtual double getQualityRating(const Date& i_date) = 0;
80 virtual void calculate(const DEMObject& dem, Grid2DObject& grid) = 0;
81
82 std::string getInfo() const;
83 const std::string algo;
84
85 protected:
86 std::vector<double> getData(const Date& i_date, const std::string& i_param);
87 size_t getData(const Date& i_date, const std::string& i_param,
88 std::vector<double>& o_vecData, std::vector<StationData>& o_vecMeta);
89
92 std::vector<MeteoData> vecMeteo;
93 std::vector<double> vecData;
94 std::vector<StationData> vecMeta;
95 std::ostringstream info;
96 const std::string param;
98};
99
101 public:
102 static InterpolationAlgorithm* getAlgorithm(std::string algoname,
104 const std::vector< std::pair<std::string, std::string> >& vecArgs, TimeSeriesManager& tsm, GridsManager& gdm, const std::string& param);
105};
106
107} //end namespace mio
108
109#endif
Definition: InterpolationAlgorithms.h:100
static InterpolationAlgorithm * getAlgorithm(std::string algoname, Meteo2DInterpolator &mi, const std::vector< std::pair< std::string, std::string > > &vecArgs, TimeSeriesManager &tsm, GridsManager &gdm, const std::string &param)
Definition: InterpolationAlgorithms.cc:177
A class to represent DEMs and automatically compute some properties. This class stores elevation grid...
Definition: DEMObject.h:40
A class to handle timestamps. This class handles conversion between different time display formats (I...
Definition: Date.h:87
A class to perform 1D regressions.
Definition: libfit1D.h:159
A class to perform multiple linear regressions relying on the closed form solution.
Definition: libfit1D.h:377
A class to represent 2D Grids. Typical application as DEM or Landuse Model.
Definition: Grid2DObject.h:42
Definition: GridsManager.h:33
A class to perform 2D spatial interpolations. For more, see Spatial interpolations.
Definition: InterpolationAlgorithms.h:70
virtual ~InterpolationAlgorithm()
Definition: InterpolationAlgorithms.h:76
std::vector< double > vecData
store the measurement for the given parameter
Definition: InterpolationAlgorithms.h:93
Date date
Definition: InterpolationAlgorithms.h:91
virtual void calculate(const DEMObject &dem, Grid2DObject &grid)=0
std::ostringstream info
to store some extra information about the interplation process
Definition: InterpolationAlgorithms.h:95
size_t nrOfMeasurments
Number of stations that have been used, so this can be reported to the user.
Definition: InterpolationAlgorithms.h:97
const std::string algo
Definition: InterpolationAlgorithms.h:83
InterpolationAlgorithm(const std::vector< std::pair< std::string, std::string > > &, const std::string &i_algo, const std::string &i_param, TimeSeriesManager &i_tsm)
Definition: InterpolationAlgorithms.h:72
TimeSeriesManager & tsmanager
Definition: InterpolationAlgorithms.h:90
std::string getInfo() const
Return an information string about the interpolation process.
Definition: InterpolationAlgorithms.cc:274
std::vector< double > getData(const Date &i_date, const std::string &i_param)
Definition: InterpolationAlgorithms.cc:236
std::vector< StationData > vecMeta
store the station data for the given parameter
Definition: InterpolationAlgorithms.h:94
const std::string param
the parameter that we will interpolate
Definition: InterpolationAlgorithms.h:96
std::vector< MeteoData > vecMeteo
Definition: InterpolationAlgorithms.h:92
virtual double getQualityRating(const Date &i_date)=0
A class to spatially interpolate meteo parameters. For more, see Spatial interpolations.
Definition: Meteo2DInterpolator.h:97
Definition: TimeSeriesManager.h:31
Definition: InterpolationAlgorithms.h:36
std::string getInfo() const
Definition: InterpolationAlgorithms.cc:516
std::string toString() const
Definition: InterpolationAlgorithms.cc:524
void detrend(const std::vector< StationData > &vecMeta, std::vector< double > &vecDat)
Compute the trend according to the provided data and detrend vecDat.
Definition: InterpolationAlgorithms.cc:394
void retrend(const DEMObject &dem, Grid2DObject &grid) const
Re-apply the trend computed in a previous call to detrend() to the gridded results.
Definition: InterpolationAlgorithms.cc:448
Trend(const std::vector< std::pair< std::string, std::string > > &vecArgs, const std::string &algo, const std::string &i_param)
Build a Trend object.
Definition: InterpolationAlgorithms.cc:306
bool is_soft() const
Definition: InterpolationAlgorithms.h:45
bool has_user_lapse() const
Definition: InterpolationAlgorithms.h:44
const double nodata
This is the internal nodata value.
Definition: IOUtils.h:75
Definition: Config.cc:31