MeteoIODoc 20241102.51576d50
ProcessingBlock.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-3.0-or-later
2/***********************************************************************************/
3/* Copyright 2009 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 PROCESSINGBLOCK_H
20#define PROCESSINGBLOCK_H
21
23#include <meteoio/IOUtils.h>
24#include <meteoio/Config.h>
25#include <vector>
26#include <string>
27#include <set>
28#include <map>
29
30#ifdef _MSC_VER
31 #pragma warning(disable:4512) //we don't need any = operator!
32#endif
33
34namespace mio {
35
37 public:
38 typedef enum PROC_STAGE { none,
41 both
42 //once ///< activate at stage one or two, but only once
44
47 stage(first) {}
48
49 ProcessingProperties(const Duration& t_before, const Duration& t_after, const size_t& pt_before, const size_t& pt_after, const proc_stage& i_stage)
50 : time_before(t_before), time_after(t_after), points_before(pt_before), points_after(pt_after), stage(i_stage) {}
51
52 const std::string toString() const;
53
56
59
61};
62
68 public:
69
70 typedef struct OFFSET_SPEC {
71 OFFSET_SPEC() : date(), value(0.) {}
72 OFFSET_SPEC(const Date& d1, const double& i_value) : date(d1), value(i_value) {}
73 bool operator<(const OFFSET_SPEC& a) const { //needed for "sort"
74 return date < a.date;
75 }
76
77 Date date;
78 double value;
80
81 virtual ~ProcessingBlock() {}
82
83 virtual void process(const unsigned int& param, const std::vector<MeteoData>& ivec,
84 std::vector<MeteoData>& ovec) = 0;
85
86 //this call is for some timefilters
87 virtual void process(Date &dateStart, Date &dateEnd) {(void)dateStart; (void)dateEnd; throw InvalidArgumentException("Invalid call for this kind of filter", AT);}
88
89 std::string getName() const {return block_name;}
91 const std::string toString() const;
92 bool skipStation(const std::string& station_id) const;
93 bool noStationsRestrictions() const {return excluded_stations.empty() && kept_stations.empty();}
94 const std::vector<DateRange> getTimeRestrictions() const {return time_restrictions;}
95 bool skipHeight(const double& height) const;
96
97 static void readCorrections(const std::string& filter, const std::string& filename, std::vector<double> &X, std::vector<double> &Y);
98 static void readCorrections(const std::string& filter, const std::string& filename, std::vector<double> &X, std::vector<double> &Y1, std::vector<double> &Y2);
99 static std::vector<double> readCorrections(const std::string& filter, const std::string& filename, const size_t& col_idx, const char& c_type, const double& init);
100 static std::vector<offset_spec> readCorrections(const std::string& filter, const std::string& filename, const double& TZ, const size_t& col_idx=2);
101 static std::map< std::string, std::vector<DateRange> > readDates(const std::string& filter, const std::string& filename, const double& TZ);
102
103 static const double default_height; // the height that default values get asigned to to have equal parsing (TA..)
104
105
106 protected:
107 ProcessingBlock(const std::vector< std::pair<std::string, std::string> >& vecArgs, const std::string& name, const Config& cfg);
108
109 static void extract_dbl_vector(const unsigned int& param, const std::vector<MeteoData>& ivec,
110 std::vector<double>& ovec);
111 static void extract_dbl_vector(const unsigned int& param, const std::vector<const MeteoData*>& ivec,
112 std::vector<double>& ovec);
113
114 const std::set<std::string> excluded_stations, kept_stations;
115 const std::vector<DateRange> time_restrictions;
119 const std::string block_name;
120
121 static const double soil_albedo, snow_albedo, snow_thresh;
122
123 private:
124 void initHeightRestrictions(const std::vector<std::pair<std::string, std::string>> vecArgs);
125};
126
128 public:
129 static ProcessingBlock* getBlock(const std::string& blockname, const std::vector< std::pair<std::string, std::string> >& vecArgs, const Config& cfg);
130 static ProcessingBlock* getTimeBlock(const std::string& blockname, const std::vector< std::pair<std::string, std::string> >& vecArgs, const Config& cfg);
131};
132
133} //end namespace
134
135#endif
#define AT
Definition: IOExceptions.h:28
Definition: ProcessingBlock.h:127
static ProcessingBlock * getBlock(const std::string &blockname, const std::vector< std::pair< std::string, std::string > > &vecArgs, const Config &cfg)
Definition: ProcessingBlock.cc:197
static ProcessingBlock * getTimeBlock(const std::string &blockname, const std::vector< std::pair< std::string, std::string > > &vecArgs, const Config &cfg)
Definition: ProcessingBlock.cc:287
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
thrown when encountered an unexpected function's argument (e.g. bad index, bad or missing parameter n...
Definition: IOExceptions.h:130
The base class for all filters that provides the interface and a few helper methods.
Definition: ProcessingBlock.h:67
static const double default_height
Definition: ProcessingBlock.h:103
bool skipStation(const std::string &station_id) const
Should the provided station be skipped in the processing?
Definition: ProcessingBlock.cc:370
static std::map< std::string, std::vector< DateRange > > readDates(const std::string &filter, const std::string &filename, const double &TZ)
Read a list of date ranges by stationIDs from a file.
Definition: ProcessingBlock.cc:680
static const double snow_thresh
parametrize the albedo from HS
Definition: ProcessingBlock.h:121
std::string getName() const
Definition: ProcessingBlock.h:89
virtual void process(const unsigned int &param, const std::vector< MeteoData > &ivec, std::vector< MeteoData > &ovec)=0
bool skipHeight(const double &height) const
Should the provided height be skipped in the processing?
Definition: ProcessingBlock.cc:383
const std::set< std::string > excluded_stations
Definition: ProcessingBlock.h:114
static const double soil_albedo
Definition: ProcessingBlock.h:121
std::set< double > excluded_heights
Definition: ProcessingBlock.h:116
const ProcessingProperties & getProperties() const
Definition: ProcessingBlock.h:90
virtual void process(Date &dateStart, Date &dateEnd)
Definition: ProcessingBlock.h:87
virtual ~ProcessingBlock()
Definition: ProcessingBlock.h:81
const std::vector< DateRange > time_restrictions
Definition: ProcessingBlock.h:115
ProcessingProperties properties
Definition: ProcessingBlock.h:118
static void extract_dbl_vector(const unsigned int &param, const std::vector< MeteoData > &ivec, std::vector< double > &ovec)
Definition: ProcessingBlock.cc:749
static const double snow_albedo
Definition: ProcessingBlock.h:121
std::set< double > included_heights
Definition: ProcessingBlock.h:116
ProcessingBlock(const std::vector< std::pair< std::string, std::string > > &vecArgs, const std::string &name, const Config &cfg)
protected constructor only to be called by children
Definition: ProcessingBlock.cc:307
bool all_heights
Definition: ProcessingBlock.h:117
bool noStationsRestrictions() const
Definition: ProcessingBlock.h:93
const std::set< std::string > kept_stations
Definition: ProcessingBlock.h:114
const std::string block_name
Definition: ProcessingBlock.h:119
const std::vector< DateRange > getTimeRestrictions() const
Definition: ProcessingBlock.h:94
static void readCorrections(const std::string &filter, const std::string &filename, std::vector< double > &X, std::vector< double > &Y)
Read a data file structured as X Y value on each lines.
Definition: ProcessingBlock.cc:400
const std::string toString() const
Definition: ProcessingBlock.cc:767
Definition: ProcessingBlock.h:36
proc_stage stage
Definition: ProcessingBlock.h:60
Duration time_after
Definition: ProcessingBlock.h:55
ProcessingProperties(const Duration &t_before, const Duration &t_after, const size_t &pt_before, const size_t &pt_after, const proc_stage &i_stage)
Definition: ProcessingBlock.h:49
Duration time_before
Definition: ProcessingBlock.h:54
const std::string toString() const
Definition: ProcessingBlock.cc:775
size_t points_after
Definition: ProcessingBlock.h:58
ProcessingProperties()
Definition: ProcessingBlock.h:45
size_t points_before
Definition: ProcessingBlock.h:57
proc_stage
Definition: ProcessingBlock.h:38
@ second
activate at second stage
Definition: ProcessingBlock.h:40
@ none
never activate this block
Definition: ProcessingBlock.h:38
@ first
activate at first stage
Definition: ProcessingBlock.h:39
@ both
activate at both first and second stage
Definition: ProcessingBlock.h:41
Definition: Config.cc:31
Definition: ProcessingBlock.h:70
bool operator<(const OFFSET_SPEC &a) const
Definition: ProcessingBlock.h:73
Date date
Definition: ProcessingBlock.h:77
double value
Definition: ProcessingBlock.h:78
OFFSET_SPEC(const Date &d1, const double &i_value)
Definition: ProcessingBlock.h:72
OFFSET_SPEC()
Definition: ProcessingBlock.h:71