MeteoIODoc 20241005.2ccf54a9
IOManager.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 IOMANAGER_H
20#define IOMANAGER_H
21
27
28namespace mio {
29
30class TimeSeriesManager;
31class GridsManager;
32class Meteo2DInterpolator;
33
34class IOManager {
35 public:
36 IOManager(const std::string& filename_in);
37 IOManager(const Config& i_cfg);
38
39 //Legacy support to support functionality of the IOInterface superclass:
40 void read2DGrid(Grid2DObject& grid_out, const std::string& options="") {gdm1.read2DGrid(grid_out, options);}
41 void read2DGrid(Grid2DObject& grid_out, const MeteoGrids::Parameters& parameter, const Date& date) {gdm1.read2DGrid(grid_out, parameter, date);}
42 void read3DGrid(Grid3DObject& grid_out, const std::string& options="") {gdm1.read3DGrid(grid_out, options);}
43 void read3DGrid(Grid3DObject& grid_out, const MeteoGrids::Parameters& parameter, const Date& date) {gdm1.read3DGrid(grid_out, parameter, date);}
44 void readDEM(DEMObject& dem_out) {gdm1.readDEM(dem_out);}
45 void readAssimilationData(const Date& date_in, Grid2DObject& da_out) {gdm1.readAssimilationData(date_in, da_out);}
46 void readLanduse(Grid2DObject& landuse_out) {gdm1.readLanduse(landuse_out);}
47 void readGlacier(Grid2DObject& glacier_out) {gdm1.readGlacier(glacier_out);}
48 void readPOI(std::vector<Coords>& pts) {iohandler.readPOI(pts);}
49 void write2DGrid(const Grid2DObject& grid_in, const std::string& options="") {gdm1.write2DGrid(grid_in, options);}
50 void write2DGrid(const Grid2DObject& grid_in, const MeteoGrids::Parameters& parameter, const Date& date) {gdm1.write2DGrid(grid_in, parameter, date);}
51 void write3DGrid(const Grid3DObject& grid_in, const std::string& options="") {gdm1.write3DGrid(grid_in, options);}
52 void write3DGrid(const Grid3DObject& grid_in, const MeteoGrids::Parameters& parameter, const Date& date) {gdm1.write3DGrid(grid_in, parameter, date);}
53 bool list2DGrids(const Date& start, const Date& end, std::map<Date, std::set<size_t> > &list){return iohandler.list2DGrids(start,end,list);}
54 void setOfstreamDefault(const Config& i_cfg);
55 //end legacy support
56
57 size_t getStationData(const Date& date, STATIONS_SET& vecStation);
58
82 size_t getMeteoData(const Date& dateStart, const Date& dateEnd, std::vector< METEO_SET >& vecVecMeteo);
83
105 size_t getMeteoData(const Date& i_date, METEO_SET& vecMeteo);
106
118 void push_meteo_data(const IOUtils::ProcessingLevel& level, const Date& date_start, const Date& date_end,
119 const std::vector< METEO_SET >& vecMeteo) {tsm1.push_meteo_data(level, date_start, date_end, vecMeteo);}
120
145 bool getMeteoData(const Date& date, const DEMObject& dem, const MeteoData::Parameters& meteoparam,
146 Grid2DObject& result);
147
148 bool getMeteoData(const Date& date, const DEMObject& dem, const std::string& param_name,
149 Grid2DObject& result);
150
151 bool getMeteoData(const Date& date, const DEMObject& dem, const MeteoData::Parameters& meteoparam,
152 Grid2DObject& result, std::string& info_string);
153
154 bool getMeteoData(const Date& date, const DEMObject& dem, const std::string& param_name,
155 Grid2DObject& result, std::string& info_string);
156
157 void interpolate(const Date& date, const DEMObject& dem, const MeteoData::Parameters& meteoparam,
158 const std::vector<Coords>& in_coords, std::vector<double>& result);
159
160 void interpolate(const Date& date, const DEMObject& dem, const MeteoData::Parameters& meteoparam,
161 const std::vector<Coords>& in_coords, std::vector<double>& result, std::string& info_string);
162
163 void interpolate(const Date& date, const DEMObject& dem, const MeteoData::Parameters& meteoparam,
164 const std::vector<StationData>& in_stations, std::vector<double>& result, std::string& info_string);
165
178 void setProcessingLevel(const unsigned int& i_level);
179
188 void setMinBufferRequirements(const double& buffer_size, const double& buff_before) {tsm1.setBufferProperties(buffer_size, buff_before);}
189
199 double getAvgSamplingRate() const;
200
201 void writeMeteoData(const std::vector< METEO_SET >& vecMeteo, const std::string& option="") {tsm1.writeMeteoData(vecMeteo, option);}
202
208 const Config getConfig() const {return cfg;}
209
210 const std::string toString() const;
211
220 void add_to_points_cache(const Date& i_date, const METEO_SET& vecMeteo);
221
225 void clear_cache();
226
227
228 private:
234 static IOUtils::OperationMode getIOManagerTSMode(const Config& i_cfg);
235
241 static IOUtils::OperationMode getIOManagerGridMode(const Config& i_cfg);
242
243 void initVirtualStations();
244 std::vector<METEO_SET> getVirtualStationsData(const DEMObject& dem, const Date& dateStart, const Date& dateEnd);
245 void initIOManager();
246
247 const Config cfg;
248 const IOUtils::OperationMode ts_mode;
249 IOHandler iohandler;
250 TimeSeriesManager tsm1, tsm2;
251 GridsManager gdm1;
252 Meteo2DInterpolator interpolator;
253 DEMObject source_dem;
254 std::vector<size_t> v_params, grids_params;
255 std::vector<StationData> v_stations, v_gridstations;
256 unsigned int vstations_refresh_rate, vstations_refresh_offset;
257 bool write_resampled_grids = false;
258};
259} //end namespace
260#endif
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 represent DEMs and automatically compute some properties. This class stores elevation grid...
Definition: DEMObject.h:40
A class to handle timestamps. This class handles conversion between different time display formats (I...
Definition: Date.h:87
A class to represent 2D Grids. Typical application as DEM or Landuse Model.
Definition: Grid2DObject.h:42
A class to represent 3D Grids. Typical application: wind field.
Definition: Grid3DObject.h:39
Definition: GridsManager.h:33
void readAssimilationData(const Date &date_in, Grid2DObject &da_out)
Definition: GridsManager.cc:139
void read3DGrid(Grid3DObject &grid_out, const std::string &i_filename="")
Definition: GridsManager.h:42
void read2DGrid(Grid2DObject &grid_out, const std::string &option="")
Read the requested grid, according to the configured processing level.
Definition: GridsManager.cc:70
void readGlacier(Grid2DObject &landuse_out)
Definition: GridsManager.cc:126
void write3DGrid(const Grid3DObject &grid_out, const std::string &options="")
Definition: GridsManager.h:52
void write2DGrid(const Grid2DObject &grid_in, const std::string &options="")
Definition: GridsManager.h:50
void readDEM(DEMObject &dem_out)
Definition: GridsManager.cc:96
void readLanduse(Grid2DObject &landuse_out)
Definition: GridsManager.cc:113
This class is the class to use for raw I/O operations. It is responsible for transparently loading th...
Definition: IOHandler.h:37
virtual bool list2DGrids(const Date &start, const Date &end, std::map< Date, std::set< size_t > > &list)
Return the list of grids within a given time period that could be read by the plugin,...
Definition: IOHandler.cc:425
virtual void readPOI(std::vector< Coords > &pts)
Read a list of points by their grid coordinates This allows for example to get a list of points where...
Definition: IOHandler.cc:538
Definition: IOManager.h:34
void write3DGrid(const Grid3DObject &grid_in, const std::string &options="")
Definition: IOManager.h:51
void write3DGrid(const Grid3DObject &grid_in, const MeteoGrids::Parameters &parameter, const Date &date)
Definition: IOManager.h:52
double getAvgSamplingRate() const
Returns the average sampling rate in the data. This computes the average sampling rate of the data th...
Definition: IOManager.cc:605
void interpolate(const Date &date, const DEMObject &dem, const MeteoData::Parameters &meteoparam, const std::vector< Coords > &in_coords, std::vector< double > &result)
Definition: IOManager.cc:585
bool list2DGrids(const Date &start, const Date &end, std::map< Date, std::set< size_t > > &list)
Definition: IOManager.h:53
void add_to_points_cache(const Date &i_date, const METEO_SET &vecMeteo)
Add a METEO_SET for a specific instance to the point cache. This is a way to manipulate MeteoData var...
Definition: IOManager.cc:610
void setProcessingLevel(const unsigned int &i_level)
Set the desired ProcessingLevel of the IOManager instance The processing level affects the way meteo ...
Definition: IOManager.cc:302
void read2DGrid(Grid2DObject &grid_out, const MeteoGrids::Parameters &parameter, const Date &date)
Definition: IOManager.h:41
void read2DGrid(Grid2DObject &grid_out, const std::string &options="")
Definition: IOManager.h:40
void readDEM(DEMObject &dem_out)
Definition: IOManager.h:44
void readLanduse(Grid2DObject &landuse_out)
Definition: IOManager.h:46
void setOfstreamDefault(const Config &i_cfg)
Definition: IOManager.cc:315
void readAssimilationData(const Date &date_in, Grid2DObject &da_out)
Definition: IOManager.h:45
IOManager(const std::string &filename_in)
Definition: IOManager.cc:229
void write2DGrid(const Grid2DObject &grid_in, const MeteoGrids::Parameters &parameter, const Date &date)
Definition: IOManager.h:50
size_t getStationData(const Date &date, STATIONS_SET &vecStation)
Definition: IOManager.cc:321
const Config getConfig() const
Returns a copy of the internal Config object. This is convenient to clone an iomanager.
Definition: IOManager.h:208
void readPOI(std::vector< Coords > &pts)
Definition: IOManager.h:48
void clear_cache()
Clear the all cache. All raw, filtered and resampled values are dismissed, will need to be re-read an...
Definition: IOManager.cc:308
const std::string toString() const
Definition: IOManager.cc:658
size_t getMeteoData(const Date &dateStart, const Date &dateEnd, std::vector< METEO_SET > &vecVecMeteo)
Fill vecMeteo with a time series of objects corresponding to the interval indicated by dateStart and ...
Definition: IOManager.cc:384
void setMinBufferRequirements(const double &buffer_size, const double &buff_before)
Set buffer window properties requirements as known to the application itself. This will compare these...
Definition: IOManager.h:188
void write2DGrid(const Grid2DObject &grid_in, const std::string &options="")
Definition: IOManager.h:49
void writeMeteoData(const std::vector< METEO_SET > &vecMeteo, const std::string &option="")
Definition: IOManager.h:201
void read3DGrid(Grid3DObject &grid_out, const std::string &options="")
Definition: IOManager.h:42
void read3DGrid(Grid3DObject &grid_out, const MeteoGrids::Parameters &parameter, const Date &date)
Definition: IOManager.h:43
void push_meteo_data(const IOUtils::ProcessingLevel &level, const Date &date_start, const Date &date_end, const std::vector< METEO_SET > &vecMeteo)
Push a vector of time series of MeteoData objects into the IOManager. This overwrites any internal bu...
Definition: IOManager.h:118
void readGlacier(Grid2DObject &glacier_out)
Definition: IOManager.h:47
A class to spatially interpolate meteo parameters. For more, see Spatial interpolations.
Definition: Meteo2DInterpolator.h:97
Parameters
this enum provides indexed access to meteorological fields
Definition: MeteoData.h:145
Parameters
this enum provides names for possible meteogrids (from an ARPS file, etc)
Definition: MeteoData.h:46
Definition: TimeSeriesManager.h:31
void setBufferProperties(const double &buffer_size, const double &buff_before)
Set buffer window properties requirements as known to the application itself.
Definition: TimeSeriesManager.cc:75
void writeMeteoData(const std::vector< METEO_SET > &vecMeteo, const std::string &name="")
Definition: TimeSeriesManager.cc:343
void push_meteo_data(const IOUtils::ProcessingLevel &level, const Date &date_start, const Date &date_end, const std::vector< MeteoData > &vecMeteo, const bool &invalidate_cache=true)
Push a vector of time series of MeteoData objects into the TimeSeriesManager. This overwrites any int...
Definition: TimeSeriesManager.cc:196
Definition: getopt.h:65
OperationMode
Keywords for mode of operation. Please keep all the GRID_xxx last!
Definition: IOUtils.h:63
ProcessingLevel
Definition: IOUtils.h:54
Definition: Config.cc:31
std::vector< MeteoData > METEO_SET
Definition: MeteoData.h:32
std::vector< StationData > STATIONS_SET
Definition: StationData.h:145