MeteoIODoc 20240426.aefd3c94
FilterDespikingPS.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-3.0-or-later
2/***********************************************************************************/
3/* Copyright 2018 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 FilterDespikingPS_H
20#define FilterDespikingPS_H
21
24
25#include <vector>
26#include <string>
27
28namespace mio {
29
91 public:
92 FilterDespikingPS(const std::vector< std::pair<std::string, std::string> >& vecArgs, const std::string& name, const Config& cfg);
93
94 virtual void process(const unsigned int& param, const std::vector<MeteoData>& ivec,
95 std::vector<MeteoData>& ovec);
96
97 private:
98 typedef enum IMPLEMENTATION_TYPE {
99 GORING,
100 MORI
101 } implementation_type;
102
103 void parse_args(const std::vector< std::pair<std::string, std::string> >& vecArgs);
104
105 std::vector<int> findSpikesGoring(const std::vector<double>& timeVec, const std::vector<double>& ivec, unsigned int& nNewSpikes) const;
106 std::vector<int> findSpikesMori(const std::vector<double>& timeVec, const std::vector<double>& ivec, unsigned int& nNewSpikes) const;
107 void replaceSpikes(const std::vector<double>& timeVec, std::vector<double>& uVec, std::vector<int>& spikesVec) const;
108
109 static std::vector<double> calculateDerivatives(const std::vector<double>& ivec, const std::vector<double>& timeVec);
110 static double calculateCrossCorrelation(const std::vector<double>& aVec,const std::vector<double>& bVec);
111 static unsigned int nNodataElements(const std::vector<double>& iVec);
112 static void findPointsOutsideEllipse(const std::vector<double>& xVec,const std::vector<double>& yVec,
113 const double a,const double b,const double theta, std::vector<int>& outsideVec);
114 static void findPointsOutsideEllipsoid(const std::vector<double>& xVec,const std::vector<double>& yVec, const std::vector<double>& zVec,
115 const double a,const double b,const double c, std::vector<int>& outsideVec);
116 void getWindowForInterpolation(const size_t index,const std::vector<double>& timeVec, const std::vector<double>& uVec,
117 const std::vector<int>& spikesVec, std::vector<double>& xVec, std::vector<double>& yVec) const;
118 static bool checkIfWindowForInterpolationIsSufficient(const std::vector<double>& xVec,const double time,const unsigned int minPoints,
119 const bool avoidExtrapolation);
120 //helper functions:
121 static void solve2X2LinearEquations(const double* a, const double* b, const double* c, double* x);
122 static const std::vector<double> helperGetDoubleVectorOutOfMeteoDataVector(const std::vector<MeteoData>& ivec, const unsigned int& param);
123 static const std::vector<double> helperGetTimeVectorOutOfMeteoDataVector(const std::vector<MeteoData>& ivec);
124
125 double sensitivityParam; //this parameter controls the sensitivity of the filter. standard value: 1
126 implementation_type methodParam; //this parameter controls which implementation of the filter is used: according to Mori or Goring
127 int nIterations; //this counts the iterations
128 int maxIterations; //this is a hard-coded parameter to stop the iteration
129
130 unsigned int degreeOfInterpolation; //1: linear fit, 2: quadratic fit, 3: cubic fit
131 unsigned int windowWidth; //wished width of the window for interpolation
132};
133
134} //end namespace
135
136#endif
A class that reads a key/value file. These files (typically named *.ini) follow the INI file format s...
Definition: Config.h:79
Despiking filter using phase space.
Definition: FilterDespikingPS.h:90
FilterDespikingPS(const std::vector< std::pair< std::string, std::string > > &vecArgs, const std::string &name, const Config &cfg)
Definition: FilterDespikingPS.cc:29
virtual void process(const unsigned int &param, const std::vector< MeteoData > &ivec, std::vector< MeteoData > &ovec)
This function is the main function to do the filtering:
Definition: FilterDespikingPS.cc:46
The base class for all filters that provides the interface and a few helper methods.
Definition: ProcessingBlock.h:67
Definition: Config.cc:31