MeteoIODoc 2.11.0
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
96 static void readCorrections(const std::string& filter, const std::string& filename, std::vector<double> &X, std::vector<double> &Y);
97 static void readCorrections(const std::string& filter, const std::string& filename, std::vector<double> &X, std::vector<double> &Y1, std::vector<double> &Y2);
98 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);
99 static std::vector<offset_spec> readCorrections(const std::string& filter, const std::string& filename, const double& TZ, const size_t& col_idx=2);
100 static std::map< std::string, std::vector<DateRange> > readDates(const std::string& filter, const std::string& filename, const double& TZ);
101
102 protected:
103 ProcessingBlock(const std::vector< std::pair<std::string, std::string> >& vecArgs, const std::string& name, const Config& cfg);
104
105 static void extract_dbl_vector(const unsigned int& param, const std::vector<MeteoData>& ivec,
106 std::vector<double>& ovec);
107 static void extract_dbl_vector(const unsigned int& param, const std::vector<const MeteoData*>& ivec,
108 std::vector<double>& ovec);
109
110 const std::set<std::string> excluded_stations, kept_stations;
111 const std::vector<DateRange> time_restrictions;
113 const std::string block_name;
114
115 static const double soil_albedo, snow_albedo, snow_thresh;
116};
117
119 public:
120 static ProcessingBlock* getBlock(const std::string& blockname, const std::vector< std::pair<std::string, std::string> >& vecArgs, const Config& cfg);
121 static ProcessingBlock* getTimeBlock(const std::string& blockname, const std::vector< std::pair<std::string, std::string> >& vecArgs, const Config& cfg);
122};
123
124} //end namespace
125
126#endif
#define AT
Definition: IOExceptions.h:28
Definition: ProcessingBlock.h:118
static ProcessingBlock * getBlock(const std::string &blockname, const std::vector< std::pair< std::string, std::string > > &vecArgs, const Config &cfg)
Definition: ProcessingBlock.cc:178
static ProcessingBlock * getTimeBlock(const std::string &blockname, const std::vector< std::pair< std::string, std::string > > &vecArgs, const Config &cfg)
Definition: ProcessingBlock.cc:266
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
bool skipStation(const std::string &station_id) const
Should the provided station be skipped in the processing?
Definition: ProcessingBlock.cc:295
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:590
static const double snow_thresh
parametrize the albedo from HS
Definition: ProcessingBlock.h:115
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
const std::set< std::string > excluded_stations
Definition: ProcessingBlock.h:110
static const double soil_albedo
Definition: ProcessingBlock.h:115
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:111
ProcessingProperties properties
Definition: ProcessingBlock.h:112
static void extract_dbl_vector(const unsigned int &param, const std::vector< MeteoData > &ivec, std::vector< double > &ovec)
Definition: ProcessingBlock.cc:659
static const double snow_albedo
Definition: ProcessingBlock.h:115
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:286
bool noStationsRestrictions() const
Definition: ProcessingBlock.h:93
const std::set< std::string > kept_stations
Definition: ProcessingBlock.h:110
const std::string block_name
Definition: ProcessingBlock.h:113
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:310
const std::string toString() const
Definition: ProcessingBlock.cc:677
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:685
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