WSL/SLF GitLab Repository

libinterpol2D.h 5.03 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
23
24
/***********************************************************************************/
/*  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/>.
*/
/**
 * @file libinterpol2D.h
 * This is the two 2D meteo interpolation statistical library.
 */
#ifndef INTERPOL2D_H
#define INTERPOL2D_H

25
26
27
28
#include <meteoio/StationData.h>
#include <meteoio/DEMObject.h>
#include <meteoio/meteostats/libfit1D.h>
#include <meteoio/meteostats/libinterpol1D.h>
29
30
31
32
33
34
35
#include <vector>

namespace mio {

/**
 * @class Interpol2D
 * @brief A class to perform 2D spatial interpolations.
36
 * Each parameter to be interpolated declares which interpolation method to use.
37
38
 * Then the class computes the interpolation for each 2D grid point,
 * combining the inputs provided by the available data sources.
39
40
 *
 * @ingroup stats
41
42
43
44
45
46
47
48
49
50
 * @author Mathias Bavay
 */

class Interpol2D {
	public:
		///Keywords for selecting the regression algorithm to use
		typedef enum REG_TYPES {
			R_CST, ///< no elevation dependence (ie: constant)
			R_LIN ///< linear elevation dependence
		} reg_types;
51

52
53
		static void stdPressure(const DEMObject& dem, Grid2DObject& grid);
		static void constant(const double& value, const DEMObject& dem, Grid2DObject& grid);
54
55
		static void IDW(const std::vector<double>& vecData_in, const std::vector<StationData>& vecStations_in,
                                const DEMObject& dem, Grid2DObject& grid);
56
		/*static void LocalLapseIDW(const std::vector<double>& vecData_in,
57
		                          const std::vector<StationData>& vecStations_in,
58
		                          const DEMObject& dem, const size_t& nrOfNeighbors,
59
		                          Grid2DObject& grid, double& r2);*/
60
		static void SimpleDEMWindInterpolate(const DEMObject& i_dem, Grid2DObject& VW, Grid2DObject& DW);
61
62
		static void CurvatureCorrection(DEMObject& dem, const Grid2DObject& ta, Grid2DObject& grid);
		static void SteepSlopeRedistribution(const DEMObject& dem, const Grid2DObject& ta, Grid2DObject& grid);
63
64
		static void ODKriging(const std::vector<double>& vecData,
		                      const std::vector<StationData>& vecStations,
65
		                      const DEMObject& dem, const Fit1D& variogram, Grid2DObject& grid);
66
67
68

	private:
		//generic functions
69
		static double InvHorizontalDistance(const double& X1, const double& Y1, const double& X2, const double& Y2);
70
		static double HorizontalDistance(const double& X1, const double& Y1, const double& X2, const double& Y2);
71
		static double HorizontalDistance(const DEMObject& dem, const int& i, const int& j,
72
		                                 const double& X2, const double& Y2);
73
74
		static void getNeighbors(const double& x, const double& y,
		                         const std::vector<StationData>& vecStations,
75
		                         std::vector< std::pair<double, size_t> >& list);
76
77
		static void buildPositionsVectors(const std::vector<StationData>& vecStations,
		                                  std::vector<double>& vecEastings, std::vector<double>& vecNorthings);
78

79
80
81
		//core methods
		static double IDWCore(const double& x, const double& y,
		                      const std::vector<double>& vecData_in,
82
		                      const std::vector<double>& vecEastings, const std::vector<double>& vecNorthings);
83
		static double LLIDW_pixel(const size_t& i, const size_t& j,
84
85
		                          const std::vector<double>& vecData_in,
		                          const std::vector<StationData>& vecStations_in,
86
		                          const DEMObject& dem, const size_t& nrOfNeighbors, double& r2);
87
88
89

        static void steepestDescentDisplacement(const DEMObject& dem, const Grid2DObject& grid, const size_t& ii, const size_t& jj, short &d_i_dest, short &d_j_dest);
        static double depositAroundCell(const DEMObject& dem, const size_t& ii, const size_t& jj, const double& precip, Grid2DObject &grid);
90
		//weighting methods
91
92
93
		static double weightInvDist(const double& d2);
		static double weightInvDistSqrt(const double& d2);
		static double weightInvDist2(const double& d2);
94
95
96
		double weightInvDistN(const double& d2);
		double dist_pow; //power for the weighting method weightInvDistN

97
98
	private:
		//static members
99
100
		const static double wind_ys; ///<coefficient for wind dependency on slope
		const static double wind_yc; ///<coefficient for wind dependency on curvature
101
102
103
104
};
} //end namespace

#endif