MeteoIODoc  2.10.0
DataEditingAlgorithms.h
Go to the documentation of this file.
1 // SPDX-License-Identifier: LGPL-3.0-or-later
2 /***********************************************************************************/
3 /* Copyright 2020 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 DATAEDITINGALGS_H
20 #define DATAEDITINGALGS_H
21 
22 #include <meteoio/IOInterface.h>
24 
25 #include <map>
26 #include <set>
27 #include <string>
28 
29 namespace mio {
30 
35 class EditingBlock {
36  public:
37  EditingBlock(const std::string& i_stationID, const std::vector< std::pair<std::string, std::string> >& vecArgs, const std::string& name, const Config &cfg);
38 
39  virtual ~EditingBlock() {}
40 
47  virtual void editTimeSeries(std::vector<METEO_SET>& vecMeteo) {(void)vecMeteo;}
48 
55  virtual void editTimeSeries(STATIONS_SET& vecStation) {(void)vecStation;}
56 
61  virtual std::set<std::string> requiredIDs() const {return std::set<std::string>();}
62 
67  virtual std::set<std::string> providedIDs() const {return std::set<std::string>();}
68 
73  virtual std::set<std::string> purgeIDs() const {return requiredIDs();}
74 
75  const std::string toString() const;
76 
77  protected:
78  std::string getName() const {return block_name;}
79  static std::set<std::string> initStationSet(const std::vector< std::pair<std::string, std::string> >& vecArgs, const std::string& keyword);
80  bool skipStation(const std::vector<MeteoData>& vecMeteo) const;
81  METEO_SET timeFilterFromStation(const METEO_SET& vecMeteo) const; //merge and automerge need this method
82 
83  const std::set<std::string> excluded_stations, kept_stations;
84  const std::vector<DateRange> time_restrictions;
85  const std::string stationID, block_name;
86 };
87 
103 class EditingSwap : public EditingBlock {
104  public:
105  EditingSwap(const std::string& i_stationID, const std::vector< std::pair<std::string, std::string> >& vecArgs, const std::string& name, const Config &cfg);
106 
107  virtual void editTimeSeries(std::vector<METEO_SET>& vecMeteo);
108 
109  private:
110  void parse_args(const std::vector< std::pair<std::string, std::string> >& vecArgs);
111  std::string dest_param, src_param;
112 };
113 
114 
139 class EditingRename : public EditingBlock {
140  public:
141  EditingRename(const std::string& i_stationID, const std::vector< std::pair<std::string, std::string> >& vecArgs, const std::string& name, const Config &cfg);
142 
143  virtual void editTimeSeries(std::vector<METEO_SET>& vecMeteo);
144 
145  private:
146  void parse_args(const std::vector< std::pair<std::string, std::string> >& vecArgs);
147  std::set< std::string > src_params;
148  std::string dest_param;
149 };
150 
170 class EditingExclude : public EditingBlock {
171  public:
172  EditingExclude(const std::string& i_stationID, const std::vector< std::pair<std::string, std::string> >& vecArgs, const std::string& name, const Config &cfg);
173 
174  virtual void editTimeSeries(std::vector<METEO_SET>& vecMeteo);
175 
176  private:
177  void parse_args(const std::vector< std::pair<std::string, std::string> >& vecArgs);
178  void processStation(METEO_SET& vecMeteo, const size_t& startIdx, const size_t& endIdx, const std::set< std::string >& params) const;
179  std::set< std::string > exclude_params;
180  bool wildcard;
181 };
182 
201 class EditingKeep : public EditingBlock {
202  public:
203  EditingKeep(const std::string& i_stationID, const std::vector< std::pair<std::string, std::string> >& vecArgs, const std::string& name, const Config &cfg);
204 
205  virtual void editTimeSeries(std::vector<METEO_SET>& vecMeteo);
206  static void processStation(METEO_SET& vecMeteo, const size_t& startIdx, const size_t& endIdx, const std::set< std::string >& params); //for use in DataEditingAlgorithms
207 
208  private:
209  void parse_args(const std::vector< std::pair<std::string, std::string> >& vecArgs);
210  std::set< std::string > keep_params;
211 };
212 
262 class EditingMerge : public EditingBlock {
263  public:
264  EditingMerge(const std::string& i_stationID, const std::vector< std::pair<std::string, std::string> >& vecArgs, const std::string& name, const Config &cfg);
265 
266  virtual void editTimeSeries(std::vector<METEO_SET>& vecMeteo);
267  virtual void editTimeSeries(STATIONS_SET& vecStation);
268 
269  std::set<std::string> requiredIDs() const;
270  private:
271  void parse_args(const std::vector< std::pair<std::string, std::string> >& vecArgs);
272  std::vector< std::string > merged_stations;
273  std::set< std::string > merged_params;
274  MeteoData::Merge_Type merge_strategy;
275  MeteoData::MERGE_CONFLICTS merge_conflicts;
276 };
277 
296  public:
297  EditingAutoMerge(const std::string& i_stationID, const std::vector< std::pair<std::string, std::string> >& vecArgs, const std::string& name, const Config &cfg);
298 
299  virtual void editTimeSeries(std::vector<METEO_SET>& vecMeteo);
300  virtual void editTimeSeries(STATIONS_SET& vecStation);
301 
302  private:
303  void parse_args(const std::vector< std::pair<std::string, std::string> >& vecArgs);
304  static void mergeStations(const size_t& toStationIdx, STATIONS_SET& vecStation);
305  void mergeMeteo(const size_t& toStationIdx, std::vector<METEO_SET>& vecMeteo) const;
306  MeteoData::Merge_Type merge_strategy;
307  MeteoData::MERGE_CONFLICTS merge_conflicts;
308 };
309 
328 class EditingCopy : public EditingBlock {
329  public:
330  EditingCopy(const std::string& i_stationID, const std::vector< std::pair<std::string, std::string> >& vecArgs, const std::string& name, const Config &cfg);
331 
332  virtual void editTimeSeries(std::vector<METEO_SET>& vecMeteo);
333 
334  private:
335  void parse_args(const std::vector< std::pair<std::string, std::string> >& vecArgs);
336  std::string dest_param, src_param;
337 };
338 
369 class EditingCreate : public EditingBlock {
370  public:
371  EditingCreate(const std::string& i_stationID, const std::vector< std::pair<std::string, std::string> >& vecArgs, const std::string& name, const Config &cfg);
372 
373  virtual void editTimeSeries(std::vector<METEO_SET>& vecMeteo);
374 
375  private:
376  static const std::vector< std::pair<std::string, std::string> > cleanGeneratorArgs(const std::vector< std::pair<std::string, std::string> >& vecArgs);
377  void parse_args(const std::vector< std::pair<std::string, std::string> >& vecArgs);
378 
379  const Config &cfg_copy;
380  const std::vector< std::pair<std::string, std::string> > vecArgs_copy;
381  std::string algorithm, dest_param;
382 };
383 
423  public:
424  EditingMetadata(const std::string& i_stationID, const std::vector< std::pair<std::string, std::string> >& vecArgs, const std::string& name, const Config &cfg);
425 
426  virtual void editTimeSeries(std::vector<METEO_SET>& vecMeteo);
427 
428  virtual void editTimeSeries(STATIONS_SET& vecStation);
429 
430  std::set<std::string> providedIDs() const;
431 
432  private:
433  void parse_args(const std::vector< std::pair<std::string, std::string> >& vecArgs);
434  void mergeMigratedData(std::vector<METEO_SET>& vecMeteo, const std::vector<METEO_SET>& vecTmp) const;
435 
436  std::string new_name, new_id;
437  double lat, lon, alt, slope, azi;
438  bool edit_in_place;
439 };
440 
442  public:
443  static EditingBlock* getBlock(const std::string& i_stationID, const std::vector< std::pair<std::string, std::string> >& vecArgs, const std::string& name, const Config &cfg);
444 };
445 
446 } //namespace
447 
448 #endif
A class that reads a key/value file. These files (typically named *.ini) follow the INI file format s...
Definition: Config.h:79
AUTOMERGE input editing command.
Definition: DataEditingAlgorithms.h:295
virtual void editTimeSeries(std::vector< METEO_SET > &vecMeteo)
Apply this editing block.
Definition: DataEditingAlgorithms.cc:473
EditingAutoMerge(const std::string &i_stationID, const std::vector< std::pair< std::string, std::string > > &vecArgs, const std::string &name, const Config &cfg)
Definition: DataEditingAlgorithms.cc:394
Definition: DataEditingAlgorithms.h:441
static EditingBlock * getBlock(const std::string &i_stationID, const std::vector< std::pair< std::string, std::string > > &vecArgs, const std::string &name, const Config &cfg)
Definition: DataEditingAlgorithms.cc:127
Base class for DataEditing algorithms.
Definition: DataEditingAlgorithms.h:35
virtual void editTimeSeries(std::vector< METEO_SET > &vecMeteo)
Apply this editing block.
Definition: DataEditingAlgorithms.h:47
virtual std::set< std::string > requiredIDs() const
Get the station IDs this editing block depends on for this station.
Definition: DataEditingAlgorithms.h:61
std::string getName() const
Definition: DataEditingAlgorithms.h:78
virtual ~EditingBlock()
Definition: DataEditingAlgorithms.h:39
const std::vector< DateRange > time_restrictions
Definition: DataEditingAlgorithms.h:84
virtual std::set< std::string > providedIDs() const
Get the station IDs this editing block provides based on this station.
Definition: DataEditingAlgorithms.h:67
const std::set< std::string > kept_stations
Definition: DataEditingAlgorithms.h:83
const std::string toString() const
Definition: DataEditingAlgorithms.cc:120
METEO_SET timeFilterFromStation(const METEO_SET &vecMeteo) const
Prepare a station that will be merged in case of time restrictions.
Definition: DataEditingAlgorithms.cc:164
virtual std::set< std::string > purgeIDs() const
Get the station IDs to purge after using them for this station ID.
Definition: DataEditingAlgorithms.h:73
const std::string stationID
Definition: DataEditingAlgorithms.h:85
bool skipStation(const std::vector< MeteoData > &vecMeteo) const
Return true if this station ID should be skipped.
Definition: DataEditingAlgorithms.cc:108
const std::string block_name
Definition: DataEditingAlgorithms.h:85
virtual void editTimeSeries(STATIONS_SET &vecStation)
Apply this editing block to the StationData.
Definition: DataEditingAlgorithms.h:55
static std::set< std::string > initStationSet(const std::vector< std::pair< std::string, std::string > > &vecArgs, const std::string &keyword)
Definition: DataEditingAlgorithms.cc:83
EditingBlock(const std::string &i_stationID, const std::vector< std::pair< std::string, std::string > > &vecArgs, const std::string &name, const Config &cfg)
Definition: DataEditingAlgorithms.cc:80
const std::set< std::string > excluded_stations
Definition: DataEditingAlgorithms.h:83
COPY input editing command.
Definition: DataEditingAlgorithms.h:328
virtual void editTimeSeries(std::vector< METEO_SET > &vecMeteo)
Apply this editing block.
Definition: DataEditingAlgorithms.cc:635
EditingCopy(const std::string &i_stationID, const std::vector< std::pair< std::string, std::string > > &vecArgs, const std::string &name, const Config &cfg)
Definition: DataEditingAlgorithms.cc:608
CREATE input editing command.
Definition: DataEditingAlgorithms.h:369
EditingCreate(const std::string &i_stationID, const std::vector< std::pair< std::string, std::string > > &vecArgs, const std::string &name, const Config &cfg)
Definition: DataEditingAlgorithms.cc:654
virtual void editTimeSeries(std::vector< METEO_SET > &vecMeteo)
Apply this editing block.
Definition: DataEditingAlgorithms.cc:692
EXCLUDE input editing command.
Definition: DataEditingAlgorithms.h:170
EditingExclude(const std::string &i_stationID, const std::vector< std::pair< std::string, std::string > > &vecArgs, const std::string &name, const Config &cfg)
Definition: DataEditingAlgorithms.cc:285
virtual void editTimeSeries(std::vector< METEO_SET > &vecMeteo)
Apply this editing block.
Definition: DataEditingAlgorithms.cc:324
KEEP input editing command.
Definition: DataEditingAlgorithms.h:201
virtual void editTimeSeries(std::vector< METEO_SET > &vecMeteo)
Apply this editing block.
Definition: DataEditingAlgorithms.cc:380
EditingKeep(const std::string &i_stationID, const std::vector< std::pair< std::string, std::string > > &vecArgs, const std::string &name, const Config &cfg)
Definition: DataEditingAlgorithms.cc:341
static void processStation(METEO_SET &vecMeteo, const size_t &startIdx, const size_t &endIdx, const std::set< std::string > &params)
Definition: DataEditingAlgorithms.cc:362
MERGE input editing command.
Definition: DataEditingAlgorithms.h:262
std::set< std::string > requiredIDs() const
Get the station IDs this editing block depends on for this station.
Definition: DataEditingAlgorithms.cc:600
EditingMerge(const std::string &i_stationID, const std::vector< std::pair< std::string, std::string > > &vecArgs, const std::string &name, const Config &cfg)
Definition: DataEditingAlgorithms.cc:499
virtual void editTimeSeries(std::vector< METEO_SET > &vecMeteo)
Apply this editing block.
Definition: DataEditingAlgorithms.cc:559
METADATA input editing command.
Definition: DataEditingAlgorithms.h:422
virtual void editTimeSeries(std::vector< METEO_SET > &vecMeteo)
Apply this editing block.
Definition: DataEditingAlgorithms.cc:797
std::set< std::string > providedIDs() const
Get the station IDs this editing block provides based on this station.
Definition: DataEditingAlgorithms.cc:749
EditingMetadata(const std::string &i_stationID, const std::vector< std::pair< std::string, std::string > > &vecArgs, const std::string &name, const Config &cfg)
Definition: DataEditingAlgorithms.cc:712
RENAME input editing command.
Definition: DataEditingAlgorithms.h:139
EditingRename(const std::string &i_stationID, const std::vector< std::pair< std::string, std::string > > &vecArgs, const std::string &name, const Config &cfg)
Definition: DataEditingAlgorithms.cc:231
virtual void editTimeSeries(std::vector< METEO_SET > &vecMeteo)
Apply this editing block.
Definition: DataEditingAlgorithms.cc:259
SWAP input editing command.
Definition: DataEditingAlgorithms.h:103
virtual void editTimeSeries(std::vector< METEO_SET > &vecMeteo)
Apply this editing block.
Definition: DataEditingAlgorithms.cc:208
EditingSwap(const std::string &i_stationID, const std::vector< std::pair< std::string, std::string > > &vecArgs, const std::string &name, const Config &cfg)
Definition: DataEditingAlgorithms.cc:181
Merge_Type
Available MeteoData merging strategies. When the two stations both have data at a given time step,...
Definition: MeteoData.h:125
Definition: Config.cc:30
std::vector< MeteoData > METEO_SET
Definition: MeteoData.h:31
std::vector< StationData > STATIONS_SET
Definition: StationData.h:141