MeteoIODoc 2.11.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
29namespace mio {
30
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
103class 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
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
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
201class 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
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
328class 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
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
478 public:
483 };
484
485 public:
486 EditingRegFill(const std::string& i_stationID, const std::vector< std::pair<std::string, std::string> >& vecArgs, const std::string& name, const Config &cfg);
487
488 virtual void editTimeSeries(std::vector<METEO_SET>& vecMeteo);
489
490 private:
491 void parse_args(const std::vector< std::pair<std::string, std::string> >& vecArgs);
492 void fillTimeseries(METEO_SET& vecMeteo1, const METEO_SET& vecMeteo2);
493 std::vector< std::string > source_stations;
494 std::set< std::string > params_to_merge;
495 RegressionType regtype;
496};
497
499 public:
500 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);
501};
502
503} //namespace
504
505#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:477
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:398
Definition: DataEditingAlgorithms.h:498
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:129
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
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 > requiredIDs() const
Get the station IDs this editing block depends on for this station.
Definition: DataEditingAlgorithms.h:61
const std::set< std::string > kept_stations
Definition: DataEditingAlgorithms.h:83
const std::string toString() const
Definition: DataEditingAlgorithms.cc:122
METEO_SET timeFilterFromStation(const METEO_SET &vecMeteo) const
Prepare a station that will be merged in case of time restrictions.
Definition: DataEditingAlgorithms.cc:168
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:110
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:85
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:82
const std::set< std::string > excluded_stations
Definition: DataEditingAlgorithms.h:83
virtual std::set< std::string > purgeIDs() const
Get the station IDs to purge after using them for this station ID.
Definition: DataEditingAlgorithms.h:73
virtual std::set< std::string > providedIDs() const
Get the station IDs this editing block provides based on this station.
Definition: DataEditingAlgorithms.h:67
COPY input editing command.
Definition: DataEditingAlgorithms.h:328
virtual void editTimeSeries(std::vector< METEO_SET > &vecMeteo)
Apply this editing block.
Definition: DataEditingAlgorithms.cc:639
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:612
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:658
virtual void editTimeSeries(std::vector< METEO_SET > &vecMeteo)
Apply this editing block.
Definition: DataEditingAlgorithms.cc:696
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:289
virtual void editTimeSeries(std::vector< METEO_SET > &vecMeteo)
Apply this editing block.
Definition: DataEditingAlgorithms.cc:328
KEEP input editing command.
Definition: DataEditingAlgorithms.h:201
virtual void editTimeSeries(std::vector< METEO_SET > &vecMeteo)
Apply this editing block.
Definition: DataEditingAlgorithms.cc:384
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:345
static void processStation(METEO_SET &vecMeteo, const size_t &startIdx, const size_t &endIdx, const std::set< std::string > &params)
Definition: DataEditingAlgorithms.cc:366
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:604
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:503
virtual void editTimeSeries(std::vector< METEO_SET > &vecMeteo)
Apply this editing block.
Definition: DataEditingAlgorithms.cc:563
METADATA input editing command.
Definition: DataEditingAlgorithms.h:422
virtual void editTimeSeries(std::vector< METEO_SET > &vecMeteo)
Apply this editing block.
Definition: DataEditingAlgorithms.cc:801
std::set< std::string > providedIDs() const
Get the station IDs this editing block provides based on this station.
Definition: DataEditingAlgorithms.cc:753
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:716
RegFill input editing command.
Definition: DataEditingAlgorithms.h:477
virtual void editTimeSeries(std::vector< METEO_SET > &vecMeteo)
Apply this editing block.
Definition: DataEditingAlgorithms.cc:938
EditingRegFill(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:874
RegressionType
Definition: DataEditingAlgorithms.h:479
@ QUADRATIC
Definition: DataEditingAlgorithms.h:481
@ CUBIC
Definition: DataEditingAlgorithms.h:482
@ LINEAR
Definition: DataEditingAlgorithms.h:480
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:235
virtual void editTimeSeries(std::vector< METEO_SET > &vecMeteo)
Apply this editing block.
Definition: DataEditingAlgorithms.cc:263
SWAP input editing command.
Definition: DataEditingAlgorithms.h:103
virtual void editTimeSeries(std::vector< METEO_SET > &vecMeteo)
Apply this editing block.
Definition: DataEditingAlgorithms.cc:212
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:185
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:31
std::vector< MeteoData > METEO_SET
Definition: MeteoData.h:32
std::vector< StationData > STATIONS_SET
Definition: StationData.h:141