19#ifndef RESAMPLINGALGORITHMS_H
20#define RESAMPLINGALGORITHMS_H
29 #pragma warning(disable:4512)
54 typedef struct GAP_INFO {
56 void extend(
const size_t& idx,
const std::vector<MeteoData>& vecM) {
if (idx<startIdx) setStart(idx, vecM);
if (idx>endIdx) setEnd(idx, vecM);}
57 void setStart(
const size_t& idx,
const std::vector<MeteoData>& vecM) {
if (idx>=vecM.size())
return; startIdx=idx; start=vecM[idx].date;}
58 void setEnd(
const size_t& idx,
const std::vector<MeteoData>& vecM) {
if (idx>=vecM.size())
return; endIdx=idx;
end=vecM[idx].date;}
59 std::string
toString()
const {std::ostringstream os; os << start.toString(
Date::ISO) <<
" (" << startIdx <<
") - " <<
end.toString(
Date::ISO) <<
" (" << endIdx <<
")";
return os.str();}
60 double size()
const {
return std::abs(
end.getJulian(
true)-start.getJulian(
true));}
65 static size_t searchBackward(
gap_info &last_gap,
const size_t& pos,
const size_t& paramindex,
const std::vector<MeteoData>& vecM,
const Date& resampling_date,
66 const double& i_max_gap_size);
67 static size_t searchForward(
gap_info &last_gap,
const size_t& pos,
const size_t& paramindex,
const std::vector<MeteoData>& vecM,
const Date& resampling_date,
68 const double& i_max_gap_size,
const size_t& indexP1);
70 static gap_info findGap(
const size_t& pos,
const size_t& paramindex,
const std::vector<MeteoData>& vecM,
const Date& resampling_date,
71 const double& i_max_gap_size);
73 ResamplingAlgorithms(
const std::string& i_algoname,
const std::string& i_parname,
const double& dflt_max_gap_size,
const std::vector< std::pair<std::string, std::string> >& )
81 const std::vector<MeteoData>& vecM,
MeteoData& md) = 0;
89 const size_t& pos,
const Date& curr_date);
91 const size_t& pos,
const Date& curr_date);
92 void getNearestValidPts(
const std::string& stationHash,
const size_t& pos,
const size_t& paramindex,
const std::vector<MeteoData>& vecM,
const Date& resampling_date,
93 const double& i_max_gap_size,
size_t& indexP1,
size_t& indexP2);
95 const double& x2,
const double& y2,
const double& x3);
97 static size_t getDailyValue(
const std::vector<MeteoData>& vecM,
const size_t& paramindex,
size_t pos,
const Date& intervalStart,
const Date& intervalEnd);
104 std::map<std::string, gap_info> gaps;
110 static ResamplingAlgorithms*
getAlgorithm(
const std::string& i_algoname,
const std::string& parname,
const double& max_gap_size,
const std::vector< std::pair<std::string, std::string> >& vecArgs,
const Config &cfg);
A class that reads a key/value file. These files (typically named *.ini) follow the INI file format s...
Definition: Config.h:79
A class to handle timestamps. This class handles conversion between different time display formats (I...
Definition: Date.h:87
@ ISO
ISO 8601 extended format combined date: YYYY-MM-DDTHH:mm:SS.sss (fields might be dropped,...
Definition: Date.h:91
A class to represent a singular measurement received from one station at a certain time (represented ...
Definition: MeteoData.h:108
Definition: ResamplingAlgorithms.h:108
static ResamplingAlgorithms * getAlgorithm(const std::string &i_algoname, const std::string &parname, const double &max_gap_size, const std::vector< std::pair< std::string, std::string > > &vecArgs, const Config &cfg)
Definition: ResamplingAlgorithms.cc:95
Interface class for the temporal resampling algorithms.
Definition: ResamplingAlgorithms.h:43
static const double snow_thresh
These thresholds are used to handle solar radiation.
Definition: ResamplingAlgorithms.h:101
static double partialAccumulateAtRight(const std::vector< MeteoData > &vecM, const size_t ¶mindex, const size_t &pos, const Date &curr_date)
Definition: ResamplingAlgorithms.cc:144
virtual ~ResamplingAlgorithms()
Definition: ResamplingAlgorithms.h:76
const std::string parname
Definition: ResamplingAlgorithms.h:99
ResamplingAlgorithms(const std::string &i_algoname, const std::string &i_parname, const double &dflt_max_gap_size, const std::vector< std::pair< std::string, std::string > > &)
Definition: ResamplingAlgorithms.h:73
void getNearestValidPts(const std::string &stationHash, const size_t &pos, const size_t ¶mindex, const std::vector< MeteoData > &vecM, const Date &resampling_date, const double &i_max_gap_size, size_t &indexP1, size_t &indexP2)
This function returns the last and next valid points around a given position.
Definition: ResamplingAlgorithms.cc:284
virtual std::string toString() const =0
static gap_info findGap(const size_t &pos, const size_t ¶mindex, const std::vector< MeteoData > &vecM, const Date &resampling_date, const double &i_max_gap_size)
Definition: ResamplingAlgorithms.cc:258
void resetResampling()
Definition: ResamplingAlgorithms.h:83
virtual void resample(const std::string &stationHash, const size_t &index, const ResamplingPosition &position, const size_t ¶mindex, const std::vector< MeteoData > &vecM, MeteoData &md)=0
const std::string getAlgo() const
Definition: ResamplingAlgorithms.h:78
static double partialAccumulateAtLeft(const std::vector< MeteoData > &vecM, const size_t ¶mindex, const size_t &pos, const Date &curr_date)
Definition: ResamplingAlgorithms.cc:125
const std::string algo
Definition: ResamplingAlgorithms.h:99
static const double snow_albedo
snow albedo
Definition: ResamplingAlgorithms.h:101
static Date getDailyStart(const Date &resampling_date)
For a given date, find the start of the day, considering that for midnight we return the day before!...
Definition: ResamplingAlgorithms.cc:318
ResamplingPosition
Definition: ResamplingAlgorithms.h:46
@ after
Definition: ResamplingAlgorithms.h:49
@ end
Definition: ResamplingAlgorithms.h:51
@ before
Definition: ResamplingAlgorithms.h:48
@ exact_match
Definition: ResamplingAlgorithms.h:47
@ begin
Definition: ResamplingAlgorithms.h:50
static const double soil_albedo
grass albedo
Definition: ResamplingAlgorithms.h:101
static double linearInterpolation(const double &x1, const double &y1, const double &x2, const double &y2, const double &x3)
This function solves the equation y = ax + b for two given points and returns y for a given x.
Definition: ResamplingAlgorithms.cc:301
static size_t getDailyValue(const std::vector< MeteoData > &vecM, const size_t ¶mindex, size_t pos, const Date &intervalStart, const Date &intervalEnd)
Find a unique value in a given time interval. This is useful for retrieving a unique daily average,...
Definition: ResamplingAlgorithms.cc:338
static size_t searchBackward(gap_info &last_gap, const size_t &pos, const size_t ¶mindex, const std::vector< MeteoData > &vecM, const Date &resampling_date, const double &i_max_gap_size)
Definition: ResamplingAlgorithms.cc:164
double max_gap_size
Definition: ResamplingAlgorithms.h:100
static size_t searchForward(gap_info &last_gap, const size_t &pos, const size_t ¶mindex, const std::vector< MeteoData > &vecM, const Date &resampling_date, const double &i_max_gap_size, const size_t &indexP1)
Definition: ResamplingAlgorithms.cc:212
const size_t npos
npos is the out-of-range value
Definition: IOUtils.h:80
Definition: ResamplingAlgorithms.h:54
std::string toString() const
Definition: ResamplingAlgorithms.h:59
void extend(const size_t &idx, const std::vector< MeteoData > &vecM)
Definition: ResamplingAlgorithms.h:56
size_t endIdx
Definition: ResamplingAlgorithms.h:62
GAP_INFO()
Definition: ResamplingAlgorithms.h:55
void setStart(const size_t &idx, const std::vector< MeteoData > &vecM)
Definition: ResamplingAlgorithms.h:57
double size() const
Definition: ResamplingAlgorithms.h:60
Date end
Definition: ResamplingAlgorithms.h:61
void setEnd(const size_t &idx, const std::vector< MeteoData > &vecM)
Definition: ResamplingAlgorithms.h:58