WSL/SLF GitLab Repository

Commit 18f4e14a authored by Mathias Bavay's avatar Mathias Bavay
Browse files

Since Rob has committed his precipitation spatial interpolation, the...

Since Rob has committed his precipitation spatial interpolation, the 2D_interpolation reference result had to be updated. Several members in filter classes could be made const/static/private.
parent 3a04efea
......@@ -25,17 +25,6 @@ FilterBlock::FilterBlock(const std::string& filter_name) : ProcessingBlock(filte
FilterBlock::~FilterBlock() {}
bool FilterBlock::is_soft(std::vector<std::string>& vec_args) {
if (!vec_args.empty()){
if (vec_args.front() == "soft"){
vec_args.erase(vec_args.begin());
return true;
}
}
return false;
}
void FilterBlock::extract_dbl_vector(const unsigned int& param, const std::vector<MeteoData>& ivec,
std::vector<double>& ovec)
{
......
......@@ -39,15 +39,13 @@ class FilterBlock : public ProcessingBlock {
virtual void process(const unsigned int& param, const std::vector<MeteoData>& ivec,
std::vector<MeteoData>& ovec) = 0;
static bool is_soft(std::vector<std::string>& vec_args);
protected:
FilterBlock(const std::string& filter_name); ///< protected constructor only to be called by children
static void extract_dbl_vector(const unsigned int& param, const std::vector<MeteoData>& ivec,
std::vector<double>& ovec);
static void extract_dbl_vector(const unsigned int& param, const std::vector<const MeteoData*>& ivec,
std::vector<double>& ovec);
protected:
FilterBlock(const std::string& filter_name); ///< protected constructor only to be called by children
};
}
......
......@@ -82,7 +82,7 @@ void FilterMAD::parse_args(std::vector<std::string> vec_args)
vector<double> filter_args;
if (vec_args.size() > 2){
is_soft = FilterBlock::is_soft(vec_args);
is_soft = ProcessingBlock::is_soft(vec_args);
}
if (vec_args.size() > 2)
......
......@@ -52,7 +52,7 @@ void FilterMax::parse_args(std::vector<std::string> vec_args) {
is_soft = false;
if (vec_args.size() > 1){
is_soft = FilterBlock::is_soft(vec_args);
is_soft = ProcessingBlock::is_soft(vec_args);
}
convert_args(1, 2, vec_args, filter_args);
......
......@@ -69,7 +69,7 @@ void FilterMeanAvg::parse_args(std::vector<std::string> vec_args)
vector<double> filter_args;
if (vec_args.size() > 2){
is_soft = FilterBlock::is_soft(vec_args);
is_soft = ProcessingBlock::is_soft(vec_args);
}
if (vec_args.size() > 2)
......
......@@ -80,7 +80,7 @@ void FilterMedianAvg::parse_args(std::vector<std::string> vec_args)
vector<double> filter_args;
if (vec_args.size() > 2){
is_soft = FilterBlock::is_soft(vec_args);
is_soft = ProcessingBlock::is_soft(vec_args);
}
if (vec_args.size() > 2)
......
......@@ -52,7 +52,7 @@ void FilterMin::parse_args(std::vector<std::string> vec_args) {
is_soft = false;
if (vec_args.size() > 1){
is_soft = FilterBlock::is_soft(vec_args);
is_soft = ProcessingBlock::is_soft(vec_args);
}
convert_args(1, 2, vec_args, filter_args);
......
......@@ -59,7 +59,7 @@ void FilterMinMax::parse_args(std::vector<std::string> vec_args)
is_soft = false;
if (vec_args.size() > 2){
is_soft = FilterBlock::is_soft(vec_args);
is_soft = ProcessingBlock::is_soft(vec_args);
}
convert_args(2, 4, vec_args, filter_args);
......
......@@ -105,7 +105,7 @@ void FilterStdDev::parse_args(std::vector<std::string> vec_args)
vector<double> filter_args;
if (vec_args.size() > 2){
is_soft = FilterBlock::is_soft(vec_args);
is_soft = ProcessingBlock::is_soft(vec_args);
}
if (vec_args.size() > 2)
......
......@@ -147,7 +147,7 @@ void FilterTukey::parse_args(std::vector<std::string> vec_args)
vector<double> filter_args;
if (vec_args.size() > 2){
is_soft = FilterBlock::is_soft(vec_args);
is_soft = ProcessingBlock::is_soft(vec_args);
}
if (vec_args.size() > 2)
......
......@@ -89,7 +89,7 @@ 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);
is_soft = ProcessingBlock::is_soft(vec_args);
}
if (vec_args.size() > 2)
......
......@@ -90,7 +90,7 @@ void ProcExpSmoothing::parse_args(std::vector<std::string> vec_args)
vector<double> filter_args;
if (vec_args.size() > 2){
is_soft = FilterBlock::is_soft(vec_args);
is_soft = ProcessingBlock::is_soft(vec_args);
}
if (vec_args.size() > 2)
......
......@@ -97,7 +97,7 @@ void ProcUnventilatedT::parse_args(std::vector<std::string> vec_args) {
is_soft = false;
if (!vec_args.empty()){
is_soft = FilterBlock::is_soft(vec_args);
is_soft = ProcessingBlock::is_soft(vec_args);
}
convert_args(0, 1, vec_args, filter_args);
......
......@@ -88,7 +88,7 @@ void ProcWMASmoothing::parse_args(std::vector<std::string> vec_args)
vector<double> filter_args;
if (vec_args.size() > 2){
is_soft = FilterBlock::is_soft(vec_args);
is_soft = ProcessingBlock::is_soft(vec_args);
}
if (vec_args.size() > 2)
......
......@@ -178,7 +178,7 @@ ProcessingBlock::ProcessingBlock(const std::string& name) : properties(), block_
{}
void ProcessingBlock::convert_args(const size_t& min_nargs, const size_t& max_nargs,
const std::vector<std::string>& vec_args, std::vector<double>& dbl_args)
const std::vector<std::string>& vec_args, std::vector<double>& dbl_args) const
{
if ((vec_args.size() < min_nargs) || (vec_args.size() > max_nargs))
throw InvalidArgumentException("Wrong number of arguments for filter/processing element \"" + getName() + "\"", AT);
......@@ -190,6 +190,17 @@ void ProcessingBlock::convert_args(const size_t& min_nargs, const size_t& max_na
}
}
bool ProcessingBlock::is_soft(std::vector<std::string>& vec_args) {
if (!vec_args.empty()){
if (vec_args.front() == "soft"){
vec_args.erase(vec_args.begin());
return true;
}
}
return false;
}
std::string ProcessingBlock::getName() const {
return block_name;
}
......
......@@ -62,9 +62,6 @@ class ProcessingBlock {
virtual void process(const unsigned int& param, const std::vector<MeteoData>& ivec,
std::vector<MeteoData>& ovec) = 0;
void convert_args(const size_t& min_nargs, const size_t& max_nargs,
const std::vector<std::string>& vec_args, std::vector<double>& dbl_args);
std::string getName() const;
const ProcessingProperties& getProperties() const;
const std::string toString() const;
......@@ -72,8 +69,13 @@ class ProcessingBlock {
protected:
ProcessingBlock(const std::string& name); ///< protected constructor only to be called by children
void convert_args(const size_t& min_nargs, const size_t& max_nargs,
const std::vector<std::string>& vec_args, std::vector<double>& dbl_args) const;
static bool is_soft(std::vector<std::string>& vec_args);
ProcessingProperties properties;
std::string block_name;
const std::string block_name;
};
class BlockFactory {
......
......@@ -40,8 +40,6 @@ ProcessingStack::ProcessingStack(const Config& cfg, const std::string& parname)
ProcessingStack::~ProcessingStack()
{
//this is suboptimal, shared_ptr<> would be the preference
//it's unfortunately a part of boost only
for (size_t ii=0; ii<filter_stack.size(); ii++)
delete filter_stack[ii];
}
......@@ -67,59 +65,62 @@ void ProcessingStack::getWindowSize(ProcessingProperties& o_properties)
}
}
size_t ProcessingStack::getArgumentsForFilter(const Config& cfg, const std::string& keyname,
void ProcessingStack::getArgumentsForFilter(const Config& cfg, const std::string& keyname,
std::vector<std::string>& vecArguments)
{
// Retrieve the values for a given 'keyname' and store them in a vector calles 'vecArguments'
cfg.getValue(keyname, "Filters", vecArguments, IOUtils::nothrow);
return vecArguments.size();
}
//this method applies the whole processing stack for all the stations, all the data points for one meteo param
//(as defined in the constructor)
void ProcessingStack::process(const std::vector< std::vector<MeteoData> >& ivec,
std::vector< std::vector<MeteoData> >& ovec, const bool& second_pass)
{
ovec.resize( ivec.size() );
const size_t nr_of_filters = filter_stack.size();
const size_t nr_stations = ivec.size();
for (size_t ii=0; ii<nr_stations; ii++){ //for every station
if( ivec[ii].empty() ) continue; //no data, nothing to do!
//pick one element and check whether the param_name parameter exists
const size_t param = ivec[ii].front().getParameterIndex(param_name);
if (param != IOUtils::npos){
std::vector<MeteoData> tmp( ivec[ii] );
//Now call the filters in a row
bool appliedFilter = false;
for (size_t jj=0; jj<nr_of_filters; jj++){
if (second_pass){
if ((*filter_stack[jj]).getProperties().stage==ProcessingProperties::first
|| (*filter_stack[jj]).getProperties().stage==ProcessingProperties::none)
continue;
}
if (!second_pass){
if ((*filter_stack[jj]).getProperties().stage==ProcessingProperties::second
|| (*filter_stack[jj]).getProperties().stage==ProcessingProperties::none)
continue;
}
appliedFilter = true;
for (size_t ii=0; ii<ivec.size(); ii++){ //for every station
if (!ivec[ii].empty()){
//pick one element and check whether the param_name parameter exists
const size_t param = ivec[ii].front().getParameterIndex(param_name);
if (param != IOUtils::npos){
std::vector<MeteoData> tmp = ivec[ii];
//Now call the filters in a row
bool appliedFilter = false;
for (size_t jj=0; jj<filter_stack.size(); jj++){
if (second_pass){
if ((*filter_stack[jj]).getProperties().stage==ProcessingProperties::first
|| (*filter_stack[jj]).getProperties().stage==ProcessingProperties::none)
continue;
}
if (!second_pass){
if ((*filter_stack[jj]).getProperties().stage==ProcessingProperties::second
|| (*filter_stack[jj]).getProperties().stage==ProcessingProperties::none)
continue;
}
appliedFilter = true;
(*filter_stack[jj]).process(static_cast<unsigned int>(param), tmp, ovec[ii]);
(*filter_stack[jj]).process(static_cast<unsigned int>(param), tmp, ovec[ii]);
if (tmp.size() == ovec[ii].size()){
if ((jj+1) != filter_stack.size()){//after the last filter not necessary
for (size_t kk=0; kk<ovec[ii].size(); kk++){
tmp[kk](param) = ovec[ii][kk](param);
}
if (tmp.size() == ovec[ii].size()){
if ((jj+1) != nr_of_filters){//after the last filter not necessary
for (size_t kk=0; kk<ovec[ii].size(); kk++){
tmp[kk](param) = ovec[ii][kk](param);
}
} else {
tmp = ovec[ii];
}
} else {
tmp = ovec[ii];
}
}
if (!appliedFilter) //if not a single filter was applied
ovec[ii] = ivec[ii]; //just copy input to output
} else {
if (!appliedFilter) //if not a single filter was applied
ovec[ii] = ivec[ii]; //just copy input to output
}
} else {
ovec[ii] = ivec[ii]; //just copy input to output
}
}
}
......
......@@ -48,10 +48,10 @@ class ProcessingStack {
const std::string toString() const;
private:
static size_t getArgumentsForFilter(const Config& cfg, const std::string& keyname, std::vector<std::string>& vecArguments);
static void getArgumentsForFilter(const Config& cfg, const std::string& keyname, std::vector<std::string>& vecArguments);
std::vector<ProcessingBlock*> filter_stack; //for now: strictly linear chain of processing blocks
std::string param_name;
const std::string param_name;
};
} //end namespace
......
......@@ -99,7 +99,7 @@ const std::vector<const MeteoData*>& WindowedFilter::get_window(const size_t& in
* @param end the end index of the window
* @return true if success, false if a window could not be computed
*/
bool WindowedFilter::get_window_specs(const size_t& index, const std::vector<MeteoData>& ivec, size_t& start, size_t& end)
bool WindowedFilter::get_window_specs(const size_t& index, const std::vector<MeteoData>& ivec, size_t& start, size_t& end) const
{ /*
The principle is too compute the first index that matches the minimum number of points criteria,
the the one that matches the minimum time window,
......
......@@ -42,15 +42,14 @@ class WindowedFilter : public FilterBlock {
WindowedFilter(const std::string& name);
virtual void process(const unsigned int& param, const std::vector<MeteoData>& ivec,
std::vector<MeteoData>& ovec) = 0; //HACK: param should be size_t
static unsigned int get_centering(std::vector<std::string>& vec_args);
std::vector<MeteoData>& ovec) = 0;
protected:
static unsigned int get_centering(std::vector<std::string>& vec_args);
const std::vector<const MeteoData*>& get_window(const size_t& index,
const std::vector<MeteoData>& ivec);
bool get_window_specs(const size_t& index, const std::vector<MeteoData>& ivec,
size_t& start, size_t& end);
size_t& start, size_t& end) const;
Duration min_time_span;
Centering centering;
......
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