MeteoIODoc 20260428.5e5bc68a
Environmental timeseries pre-processing
Loading...
Searching...
No Matches
ARIMAResampling.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-3.0-or-later
2/***********************************************************************************/
3/* Copyright 2013 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 ARIMARESAMPLING_H
20#define ARIMARESAMPLING_H
21
25#include <vector>
26
27namespace mio {
28
29using namespace ARIMAutils;
30
321 public:
322 ARIMAResampling(const std::string &i_algoname, const std::string &i_parname, const double &dflt_max_gap_size,
323 const std::vector<std::pair<std::string, std::string>> &vecArgs);
324
325 // Performs ARIMA interpolation the first time it is called, as this is also the first time the data is available
326 bool resample(const std::string &stationHash, const size_t &index, const ResamplingPosition &position, const size_t &paramindex,
327 const std::vector<MeteoData> &vecM, MeteoData &md) override;
328 std::string toString() const override;
329
330 private:
331 bool verbose;
332 // ARIMA related data
333 std::vector<ARIMA_GAP> gap_data;
334 std::vector<std::vector<double>> filled_data;
335 std::vector<std::vector<Date>> all_dates;
336
337 // Window parameters (in Julian days)
338 // Time window before and after gap to accumulate data for ARIMA model fitting
339 double before_window, after_window;
340
341 // ARIMA model parameters - non-seasonal component
342 int max_p = 8;
343 int max_d = 3;
344 int max_q = 8;
345 int start_p = 2;
346 int start_q = 2;
347
348 // ARIMA model parameters - seasonal component
349 int max_P = 2;
350 int max_D = 1;
351 int max_Q = 2;
352 int start_P = 1;
353 int start_Q = 1;
354 double period = 0;
355
356 // Model fitting parameters
357 ObjectiveFunction method = CSS_MLE;
358 OptimizationMethod opt_method = BFGS;
359 bool stepwise = true;
360 bool approximation = true;
361 int num_models = 94;
362 bool seasonal = true;
363 bool stationary = false;
364 Normalization::Mode normalize = Normalization::Mode::Nothing;
365
366 // Manual ARIMA parameter settings (overrides auto-selection)
367 bool set_arima_manual = false;
368 bool fill_backward_manual = false;
369 int p = 0, d = 0, q = 0;
370 int P = 0, D = 0, Q = 0;
371
372 // State and warning flags
373 bool is_zero_possible = false;
374 bool checked_vecM = false;
375 bool gave_warning_end = false;
376 bool gave_warning_start = false;
377 bool gave_warning_interpol = false;
378 std::vector<bool> is_valid_gap_data;
379 std::vector<bool> warned_about_gap;
380
381 ARIMA_GAP newest_gap;
382
383 // Private methods
388 void setMetaData(InterpolARIMA &arima);
389
399 std::vector<double> predictData(std::vector<double> &data, const std::string &direction, size_t startIdx_interpol,
400 size_t length_gap_interpol, int sr_period);
401
402 // Helper methods for resample
408 void checkZeroPossibility(const std::vector<MeteoData> &vecM, size_t paramindex);
409
419 bool processKnownGaps(const Date &resampling_date, const size_t paramindex,
420 const ResamplingAlgorithms::ResamplingPosition &position, const std::vector<MeteoData> &vecM, MeteoData &md);
421
430 double interpolVecAt(const std::vector<MeteoData> &vecM, const size_t &idx, const Date &date, const size_t &paramindex);
431
440 double interpolVecAt(const std::vector<double> &data, const std::vector<Date> &dates, const size_t &pos, const Date &date);
441
449 double interpolVecAt(std::vector<MeteoData> &vecMet, const Date &date, const size_t &paramindex);
450
468 void resampleInterpolationData(size_t &length_gap_interpol, size_t &endIdx_interpol, size_t &startIdx_interpol,
469 const ARIMA_GAP &new_gap, const Date &data_start_date, const Date &data_end_date,
470 std::vector<MeteoData> &data_vec_before, std::vector<MeteoData> &data_vec_after,
471 bool has_data_before, bool has_data_after, size_t paramindex, std::vector<double> &data,
472 std::vector<Date> &dates, size_t length);
473
484 std::vector<double> getInterpolatedData(std::vector<double> &data, size_t size_before, size_t size_after, size_t startIdx_interpol,
485 size_t length_gap_interpol, int period);
486
493 void cacheGap(const std::vector<double> &interpolated_data, const std::vector<Date> &interpolated_dates, const ARIMA_GAP &new_gap);
494
495 // info
500 void infoARIMA(InterpolARIMA arima);
501 };
502} // end namespace mio
503
504#endif
This class is designed to handle interpolation (resampling) of data using the ARIMA (AutoRegressive I...
Definition ARIMAResampling.h:320
bool resample(const std::string &stationHash, const size_t &index, const ResamplingPosition &position, const size_t &paramindex, const std::vector< MeteoData > &vecM, MeteoData &md) override
Definition ARIMAResampling.cc:486
std::string toString() const override
Definition ARIMAResampling.cc:140
Mode
Definition ARIMAutils.h:58
A class to handle timestamps. This class handles conversion between different time display formats (I...
Definition Date.h:87
This class is used for interpolating or predicting missing data in a time series using the Auto ARIMA...
Definition InterpolARIMA.h:104
A class to represent a singular measurement received from one station at a certain time (represented ...
Definition MeteoData.h:108
Interface class for the temporal resampling algorithms.
Definition ResamplingAlgorithms.h:43
ResamplingPosition
Definition ResamplingAlgorithms.h:57
OptimizationMethod
Definition ARIMAutils.h:42
@ BFGS
Definition ARIMAutils.h:48
ObjectiveFunction
Definition ARIMAutils.h:35
@ CSS_MLE
Definition ARIMAutils.h:36
Definition Config.cc:34
Definition ARIMAutils.h:151