WSL/SLF GitLab Repository

Commit 360dbe9b authored by Mathias Bavay's avatar Mathias Bavay
Browse files

The WIND_AVG filter has been ported. The problem is that it is not possible to...

The WIND_AVG filter has been ported. The problem is that it is not possible to get at the same time VW and DW. This will have to be fixed later... 

More documentation has been written. 
parent bfd33efd
......@@ -154,7 +154,8 @@ namespace mio {
* how to practically set up your first configuration file. Please read \ref general documentation page before starting!
*
* You first need to create the various sections:
* - [General] : the documentation about this section is found in ??
* - [General] : The documentation about this section is found in ??. It currently contains the PLUGIN_PATH key that
* points to the place where to find the plugins as well as some buffering keys (see BufferedIOHandler).
* - [Input] : This section contains the list of all the plugins that you want to use as well as their parameters. You can
* use one plugin for the meteorological data (key=METEO), one for grids (key=GRID2D), one for special points
* (key=SPECIALPTS), one for data assimilation (key=DA), one for landuse (key=LANDUSE) and one for Digital
......@@ -166,14 +167,19 @@ namespace mio {
*
* - [Filters] : This section lists the pre-processing that has to be performed on the incoming meteorological data.
* It builds a stack of processing elements one after the other one, for each meteorological parameter.
* See \ref processing for more information.
* See \ref processing for more information. It also contains
*
* - [Interpolations1D] : This section deals with temporal resampling of the incoming meteorological data.
* - [Interpolations1D] : This section deals with temporal resampling of the incoming meteorological data. The goal is
* to be able to take in data at any sampling rate and to extract values at any user given time step
* according to the resampling specifications of the user. The search window size can be given with
* key WINDOW_SIZE that expresses (in seconds) how far a valid point can be searched for when
* re-interpolating a missing value (up to WINDOW_SIZE/2 before and after the requested point).
* See \ref resampling .
*
* - [Interpolations2D] : This section deals with the spatial interpolation of meteorological data, based on a provided
* Digital Elevation Model. See \ref interpol2d .
*
* Digital Elevation Model. The goal is to populate two dimensional grids with meteorological
* parameters from point measurements, according to the specifications of the user.
* See \ref interpol2d .
*
* The application that you are using might also need its own section(s), check this with your application.
*
......
......@@ -47,14 +47,6 @@ Meteo1DInterpolator::Meteo1DInterpolator(const Config& in_cfg) : cfg(in_cfg) {
if (window_size <= 0.01)
throw IOException("WINDOW_SIZE not valid", AT);
/*//For debugging only:
for (unsigned int jj=0; jj<tasklist.size(); jj++){
cout << MeteoData::getParameterName(jj) << "::" << tasklist[jj] << endl;
for (unsigned int ii=0; ii<taskargs[jj].size(); ii++){
cout << "\tARGS: " << taskargs[jj][ii] << endl;
}
}
*/
}
void Meteo1DInterpolator::getWindowSize(ProcessingProperties& o_properties)
......
......@@ -7,6 +7,7 @@ SET(meteofilters_sources
meteofilters/FilterMinMax.cc
meteofilters/FilterMedianAvg.cc
meteofilters/FilterMeanAvg.cc
meteofilters/FilterWindAvg.cc
meteofilters/FilterStdDev.cc
meteofilters/RateFilter.cc
meteofilters/FilterBlock.cc
......
/***********************************************************************************/
/* Copyright 2009 WSL Institute for Snow and Avalanche Research SLF-DAVOS */
/***********************************************************************************/
/* This file is part of MeteoIO.
MeteoIO is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
MeteoIO is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with MeteoIO. If not, see <http://www.gnu.org/licenses/>.
*/
#include <meteoio/meteofilters/FilterWindAvg.h>
#include <cmath>
using namespace std;
namespace mio {
FilterWindAvg::FilterWindAvg(const std::vector<std::string>& vec_args) : WindowedFilter("WIND_AVG")
{
parse_args(vec_args);
//This is safe, but maybe too imprecise:
properties.time_before = min_time_span;
properties.time_after = min_time_span;
properties.points_before = min_data_points;
properties.points_after = min_data_points;
}
void FilterWindAvg::process(const unsigned int& index, const std::vector<MeteoData>& ivec,
std::vector<MeteoData>& ovec)
{
if(index!=MeteoData::VW && index!=MeteoData::DW) {
stringstream ss;
ss << "Can not use WIND_AVG processing on " << MeteoData::getParameterName(index);
throw InvalidArgumentException(ss.str(), AT);
}
ovec.clear();
for (unsigned int ii=0; ii<ivec.size(); ii++){ //for every element in ivec, get a window
ovec.push_back(ivec[ii]);
double& value = ovec[ii].param(index);
const vector<const MeteoData*>& vec_window = get_window(ii, ivec);
if (is_soft){
if (vec_window.size() > 0){
value = calc_avg(index, vec_window);
} else {
value = IOUtils::nodata;
}
} else {
if (vec_window.size() >= min_data_points){
value = calc_avg(index, vec_window);
} else {
value = IOUtils::nodata;
}
}
}
}
/**
* @brief Actual algorithm to calculate the average value for all values in vec_window.param(index)
* @param index The MeteoData parameter to be averaged (e.g. MeteoData::TA, etc)
* @param vec_window A vector of pointers to MeteoData that shall be used for the averaging
* @return A double either representing the average or IOUtils::nodata if averaging fails
*/
double FilterWindAvg::calc_avg(const unsigned int& index, const std::vector<const MeteoData*>& vec_window)
{
unsigned int vecSize = vec_window.size();
double meanspeed = IOUtils::nodata;
double meandirection = IOUtils::nodata;
if (vecSize == 0){
return IOUtils::nodata;
} else {
//calculate ve and vn
double ve=0.0, vn=0.0;
for (unsigned int jj=0; jj<vecSize; jj++){
ve += vec_window[jj]->vw * sin(vec_window[jj]->dw * M_PI / 180.); //turn into radians
vn += vec_window[jj]->vw * cos(vec_window[jj]->dw * M_PI / 180.); //turn into radians
}
ve /= vecSize;
vn /= vecSize;
meanspeed = sqrt(ve*ve + vn*vn);
meandirection = fmod( atan2(ve,vn) * 180. / M_PI + 360. , 360.); // turn into degrees [0;360)
}
if(index==MeteoData::VW)
return meanspeed;
else
return meandirection;
}
void FilterWindAvg::parse_args(std::vector<std::string> vec_args)
{
vector<double> filter_args;
if (vec_args.size() > 2){
is_soft = FilterBlock::is_soft(vec_args);
}
if (vec_args.size() > 2)
centering = (WindowedFilter::Centering)WindowedFilter::get_centering(vec_args);
FilterBlock::convert_args(2, 2, vec_args, filter_args);
if ((filter_args[0] < 1) || (filter_args[1] < 0)){
throw InvalidArgumentException("Invalid window size configuration for filter " + getName(), AT);
}
min_data_points = (unsigned int)floor(filter_args[0]);
min_time_span = Duration(filter_args[1] / 86400.0, 0.);
}
}
/***********************************************************************************/
/* Copyright 2009 WSL Institute for Snow and Avalanche Research SLF-DAVOS */
/***********************************************************************************/
/* This file is part of MeteoIO.
MeteoIO is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
MeteoIO is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with MeteoIO. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __FILTERWINDAVG_H__
#define __FILTERWINDAVG_H__
#include <meteoio/meteofilters/WindowedFilter.h>
#include <vector>
#include <string>
namespace mio {
/**
* @class FilterWindAvg
* @ingroup processing
* @author Thomas Egger
* @date 2011-01-24
* @brief Wind vector averaging.
* This calculates the vector average over a user given time period. Each wind vector within this period
* is added and the final sum is normalized by the number of vectors that have been added. Important information:
* - nodata values are excluded from the mean
* - Two arguments expected (both have to be fullfilled for the filter to start operating):
* - minimal number of points in window
* - minimal time interval spanning the window (in seconds)
* - the two arguments may be preceded by the keywords "left", "center" or "right", indicating the window position
* (centered by default)
* - the keyword "soft" maybe added, if the window position is allowed to be adjusted to the data present
* Please notice that this filter can currently ONLY be used on VW and DW. It also makes no sens to use it only on one of
* these two parameters: both should be processed by this filter.
* CURRENTLY, THIS FILTER DOES NOT WORK PROPERLY (the first parameter is correctly calculated but the second one
* uses the modified output of the first one and therefore is WRONG).
* @code
* Valid examples for the io.ini file:
* VW::filter1 = WIND_AVG
* VW::arg1 = soft left 1 1800 (1800 seconds time span for the left leaning window)
* VW::filter1 = WIND_AVG
* VW::arg1 = 10 600 (strictly centered window spanning 600 seconds and at least 10 points)
* @endcode
*/
class FilterWindAvg : public WindowedFilter {
public:
FilterWindAvg(const std::vector<std::string>& vec_args);
virtual void process(const unsigned int& index, const std::vector<MeteoData>& ivec,
std::vector<MeteoData>& ovec);
private:
void parse_args(std::vector<std::string> vec_args);
double calc_avg(const unsigned int& index, const std::vector<const MeteoData*>& vec_window);
};
} //end namespace
#endif
......@@ -21,6 +21,7 @@
#include <meteoio/meteofilters/FilterMinMax.h>
#include <meteoio/meteofilters/FilterMeanAvg.h>
#include <meteoio/meteofilters/FilterMedianAvg.h>
#include <meteoio/meteofilters/FilterWindAvg.h>
#include <meteoio/meteofilters/FilterStdDev.h>
#include <meteoio/meteofilters/RateFilter.h>
......@@ -70,7 +71,7 @@ namespace mio {
* - wma_smoothing window moving average smoothing of data, see FilterAlgorithms::WMASmoothingProcess
* - MEDIAN_AVG: running median average over a given window, see FilterMedianAvg
* - MEAN_AVG: running mean average over a given window, see FilterMeanAvg
* - wind_avg: vector average over a given window, see FilterAlgorithms::WindAvgProcess
* - WIND_AVG: vector average over a given window, see FilterWindAvg (currently, getting both vw AND dw is broken)
*/
std::set<std::string> BlockFactory::availableBlocks;
......@@ -83,6 +84,7 @@ bool BlockFactory::initStaticData()
availableBlocks.insert("MIN_MAX");
availableBlocks.insert("MEAN_AVG");
availableBlocks.insert("MEDIAN_AVG");
availableBlocks.insert("WIND_AVG");
availableBlocks.insert("STD_DEV");
availableBlocks.insert("RATE");
......@@ -106,6 +108,8 @@ ProcessingBlock* BlockFactory::getBlock(const std::string& blockname, const std:
return new FilterMeanAvg(vec_args);
} else if (blockname == "MEDIAN_AVG"){
return new FilterMedianAvg(vec_args);
} else if (blockname == "WIND_AVG"){
return new FilterWindAvg(vec_args);
} else if (blockname == "STD_DEV"){
return new FilterStdDev(vec_args);
} else if (blockname == "RATE"){
......
......@@ -134,7 +134,7 @@ void ProcessingStack::process(const std::vector< std::vector<MeteoData> >& ivec,
ovec[ii] = ivec[ii]; //just copy input to output
} else {
ovec[ii] = ivec[ii]; //just copy input to output
}
}
}
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment