MeteoIODoc 2.11.0
SnowlineAlgorithm.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-3.0-or-later
2/***********************************************************************************/
3/* Copyright 2020 ALPsolut.eu */
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
20#ifndef SNOWLINE_ALGORITHM_H
21#define SNOWLINE_ALGORITHM_H
22
24
25#include <meteoio/thirdParty/tinyexpr.h>
26#include <string>
27#include <utility>
28#include <vector>
29
30namespace mio {
31
107 public:
108 SnowlineAlgorithm(const std::vector< std::pair<std::string, std::string> >& vecArgs,
109 const std::string& i_algo, const std::string& i_param, TimeSeriesManager& i_tsm,
110 GridsManager& i_gdm, Meteo2DInterpolator& i_mi);
111 virtual double getQualityRating(const Date& i_date);
112 virtual void calculate(const DEMObject& dem, Grid2DObject& grid);
113
114 private:
115 struct aspect {
116 double deg_beg;
117 double deg_end;
118 double sl_elevation;
119 aspect() : deg_beg(0.), deg_end(0.), sl_elevation(IOUtils::nodata) {}
120 //to check if a vector of aspects is sorted:
121 bool operator< (const aspect &other) const { return this->deg_beg < other.deg_beg; }
122 bool operator<= (const aspect &other) const { return this->deg_beg <= other.deg_beg; }
123 };
124
125 void baseInterpol(const double& snowline, const DEMObject& dem, Grid2DObject& grid);
126 void assimilateCutoff(const double& snowline, const DEMObject& dem, Grid2DObject& grid);
127 void assimilateBands(const double& snowline, const DEMObject& dem, Grid2DObject& grid);
128 void assimilateFormula(const double& snowline, const DEMObject& dem, Grid2DObject& grid);
129 Grid2DObject mergeSlopes(const DEMObject& dem, const std::vector<Grid2DObject>& azi_grids);
130 void initExpressionVars(const std::vector< std::pair<std::string, double> >& substitutions, te_variable* vars) const;
131 te_expr* compileExpression(const std::string& expression, const te_variable* te_vars, const size_t& sz) const;
132 std::vector<aspect> readSnowlineFile();
133 void getSnowlines();
134 double probeTrend();
135 double calculateRate(const double& snowline);
136 std::vector< std::pair<std::string, std::string> > prepareBaseArgs(const double& snowline, const std::string& base_alg_fallback);
137 void msg(const std::string& message);
138
139 template <class T> static bool isSorted(std::vector<T> vec, const bool& strict = false)
140 { //check if a vector is sorted (with 'strict', duplicates are not allowed either)
141 if (vec.empty())
142 return true;
143 for (typename std::vector<T>::iterator it = vec.begin() + 1; it != vec.end(); ++it) {
144 if (strict) {
145 if (*it <= *(it - 1))
146 return false;
147 } else {
148 if (*it < *(it - 1))
149 return false;
150 }
151 }
152 return true;
153 }
154
155 GridsManager& gdm_;
157 std::string base_alg_;
158 std::vector< std::pair<std::string, std::string> > input_args_; //store ini input args from constructor
159 std::string where_;
160 void (SnowlineAlgorithm::*assimilateFunction_)(const double& snowline, const DEMObject& dem, Grid2DObject& grid); //points to enabled assimilation function
161 bool smoothing_;
162 std::vector<aspect> snowlines_;
163 std::string snowlines_file_;
164 bool enforce_positive_rate_; //deduce lapse rate from snowline if data has "reversed" rate
165 bool calc_base_rate_; //deduce lapse rate from snowline in any case
166 double fallback_rate_;
167 double cutoff_val_;
168 double band_height_;
169 unsigned int band_no_;
170 std::string formula_;
171 bool has_warned_deduced_trend_;
172 bool has_warned_fixed_trend_;
173 bool verbose_; //suppress warnings?
174};
175
176} //end namespace mio
177
178#endif //SNOWLINE_ALGORITHM_H
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 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
A class to spatially interpolate meteo parameters. For more, see Spatial interpolations.
Definition: Meteo2DInterpolator.h:97
Assimilation of snowline elevation information into snow maps.
Definition: SnowlineAlgorithm.h:106
SnowlineAlgorithm(const std::vector< std::pair< std::string, std::string > > &vecArgs, const std::string &i_algo, const std::string &i_param, TimeSeriesManager &i_tsm, GridsManager &i_gdm, Meteo2DInterpolator &i_mi)
Definition: SnowlineAlgorithm.cc:30
virtual void calculate(const DEMObject &dem, Grid2DObject &grid)
Definition: SnowlineAlgorithm.cc:100
virtual double getQualityRating(const Date &i_date)
Definition: SnowlineAlgorithm.cc:88
Definition: TimeSeriesManager.h:31
const double nodata
This is the internal nodata value.
Definition: IOUtils.h:75
Definition: Config.cc:31