WSL/SLF GitLab Repository

ResamplingAlgorithms.h 3.7 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/***********************************************************************************/
/*  Copyright 2009 WSL Institute for Snow and Avalanche Research    SLF-DAVOS      */
/***********************************************************************************/
/* This file is part of MeteoIO.
    MeteoIO is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    MeteoIO is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with MeteoIO.  If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __RESAMPLINGALGORITHMS_H__
#define __RESAMPLINGALGORITHMS_H__

#include <meteoio/MeteoData.h>
#include <meteoio/StationData.h>
23
#include <meteoio/meteostats/libinterpol1D.h>
24
25
26
27
28
29
30
31
32
33

#include <iostream>
#include <string>
#include <vector>
#include <map>

namespace mio {

/**
 * @class ResamplingAlgorithms
34
35
36
 * @brief Temporal resampling algorithms
 *
 * @ingroup stats
37
38
39
40
41
 * @author Thomas Egger
 * @date   2010-06-25
 */
class ResamplingAlgorithms {
	public:
42
43
44
		enum ResamplingPosition {
			exact_match,
			before,
45
46
			after,
			begin,
47
48
49
50
			end
		};

		typedef void(*resamplingptr)(const size_t& index, const ResamplingPosition& position, const size_t& paramindex,
51
52
		                             const std::vector<std::string>& taskargs, const double& window_size,
		                             const std::vector<MeteoData>& vecM, MeteoData& md);
53
54
55
56

		static const resamplingptr& getAlgorithm(const std::string& algorithmname);

		//Available algorithms
57
		static void NoResampling(const size_t& index, const ResamplingPosition& position, const size_t& paramindex,
58
		                         const std::vector<std::string>& taskargs, const double& window_size, const std::vector<MeteoData>& vecM, MeteoData& md);
59
		static void LinearResampling(const size_t& index, const ResamplingPosition& position, const size_t& paramindex,
60
		                             const std::vector<std::string>& taskargs, const double& window_size, const std::vector<MeteoData>& vecM, MeteoData& md);
61
		static void NearestNeighbour(const size_t& index, const ResamplingPosition& position, const size_t& paramindex,
62
		                             const std::vector<std::string>& taskargs, const double& window_size, const std::vector<MeteoData>& vecM, MeteoData& md);
63

64
		static void Accumulate(const size_t& index, const ResamplingPosition& position, const size_t& paramindex,
65
		                       const std::vector<std::string>& taskargs, const double& window_size, const std::vector<MeteoData>& vecM, MeteoData& md);
66

67
 	private:
68
69
		static double funcval(size_t position, const size_t& paramindex, const std::vector<MeteoData>& vecM,
		                      const Date& date, const bool& start_pt);
70
		static void getNearestValidPts(const size_t& pos, const size_t& paramindex, const std::vector<MeteoData>& vecM, const Date& resampling_date,
71
		                               const double& window_size, size_t& indexP1, size_t& indexP2);
72
73
		static double linearInterpolation(const double& x1, const double& y1,
		                                  const double& x2, const double& y2, const double& x3);
74

75
76
77
78
79
		static std::map<std::string, resamplingptr> algorithmMap;
		static const bool __init;    ///<helper variable to enable the init of static collection data
		static bool initStaticData();///<initialize the static map algorithmMap
};

80
} //end namespace
81
#endif