MeteoIODoc 20260811.aeb9aef5
Environmental timeseries pre-processing
Loading...
Searching...
No Matches
MeteoCH.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-3.0-or-later
2/***********************************************************************************/
3/* Copyright 2026 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 METEOCH_H
20#define METEOCH_H
21
23#include <meteoio/IOInterface.h>
24
25#include <string>
26#include <vector>
27#include <optional>
28
29#ifdef _MSC_VER
30 #pragma warning(disable:4512) //we don't need any = operator!
31#endif
32
33namespace mio {
34
35class JsonWrapper; //forward declaration, it is defined in an include called in the .cc file
36
45class MeteoCH : public IOInterface {
46 public:
47 MeteoCH(const std::string& configfile);
48 MeteoCH(const Config&);
49 MeteoCH(const MeteoCH&);
50 ~MeteoCH() override;
51
53
54 virtual void readStationData(const Date& date, std::vector<StationData>& vecStation) override;
55
56 virtual void readMeteoData(const Date& dateStart, const Date& dateEnd,
57 std::vector< std::vector<MeteoData> >& vecMeteo) override;
58
59 private:
60 // Metadata field identifiers
61 enum MetaField { ID, NAME, LATITUDE, LONGITUDE, ALTITUDE, WIGOS_ID, DATA_OWNER, NR_META };
62
63 // For building the list of files to fetch for a given station
64 using FileInfo = std::pair<DateRange, std::string>; //pair of date range and file name
65
66 // Data source combining primary (10min preferred) and optional hourly fallback
67 struct DataSource {
68 FileInfo primary;
69 FileInfo fallback;
70 bool hasFallback;
71 DataSource() : primary(), fallback(), hasFallback(false) {}
72 };
73
74 void initMeteoCHConnection(const Config& cfg);
75 void readStationMeta();
76 void parseMetaHeader(std::istringstream& csv_stream);
77 void parseMetaContent(std::istringstream& csv_stream);
78 void getStationDataFiles(std::string station_id);
79 DateRange createDateRangeFromPeriod(const std::string& period, char type = 'h');
80
81 // Structure for mapping MeteoSwiss CSV fields to MeteoIO parameters with unit conversions
82 struct FieldMapping {
83 size_t field_index;
84 std::string meteoio_param;
85 double units_factor;
86 double units_offset;
87
88 FieldMapping(size_t idx, const std::string& param,
89 double factor = 1.0, double offset = 0.0)
90 : field_index(idx), meteoio_param(param),
91 units_factor(factor), units_offset(offset) {}
92 };
93 std::vector<FieldMapping> mapMeteoSwissParams(const std::vector<std::string>& meteoswiss_fields);
94 std::vector<MeteoData> readCSVFile(const StationData& sd, const Date& start, const Date& end, const std::string& stationID, const std::string& filename);
95 std::vector<MeteoData> parseCSVMeteoData(const StationData& sd, const Date& dateStart, const Date& dateEnd, std::istringstream& csv_stream);
96 static Date parseTimestamp(const std::string& timestamp);
97 void merge(std::vector<MeteoData>& results, std::vector<MeteoData>& vecData);
98 void merge(std::vector<MeteoData>& results, std::vector<MeteoData>& vec10minutes, std::vector<MeteoData>& vecHourly);
99 std::vector<MeteoData> readMeteoData(Date dateStart, Date dateEnd, const StationData& sd);
100
101 std::map<std::string, std::vector<DataSource>> sources;
102 std::map<std::string, size_t> requestedStationsMap;
103 std::map<MetaField, size_t> metadataFields;
104 std::vector<StationData> vecMeta;
105 std::string coordin;
106 std::string coordinparam;
107 DateRange coverageRestrict;
108 JsonWrapper *json;
109 bool meteoch_debug;
110
111 static const int http_timeout_dflt;
112 static const std::string base_url;
113 static const std::string metadata_path;
114 static const std::string meteo_collection_path;
115};
116
117} //end namespace mio
118
119#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 and handle date ranges. They can be sorted, checked for uniqueness and a date ca...
Definition Date.h:242
A class to handle timestamps. This class handles conversion between different time display formats (I...
Definition Date.h:86
A class representing the IO Layer of the software Alpine3D. For each type of IO (File,...
Definition IOInterface.h:121
This is a wrapper class around picoJson and Curl.
Definition JsonWrapper.h:75
This class enables the access to the MeteoSwiss STAC API web service.
Definition MeteoCH.h:45
virtual void readStationData(const Date &date, std::vector< StationData > &vecStation) override
Fill vecStation with StationData objects for a certain date of interest.
Definition MeteoCH.cc:652
virtual void readMeteoData(const Date &dateStart, const Date &dateEnd, std::vector< std::vector< MeteoData > > &vecMeteo) override
Fill vecMeteo with a time series of objects corresponding to the interval indicated by dateStart and ...
Definition MeteoCH.cc:724
MeteoCH & operator=(const mio::MeteoCH &)
Definition MeteoCH.cc:125
~MeteoCH() override
Definition MeteoCH.cc:109
A class to represent meteo stations with attributes like longitude, latitude, etc.
Definition StationData.h:40
Definition Config.cc:34