WSL/SLF GitLab Repository

Commit 8eddac38 authored by Mathias Bavay's avatar Mathias Bavay
Browse files

Now testing the array1d<double>. The Undercatch filter has been renamed as...

Now testing the array1d<double>. The Undercatch filter has been renamed as Undercatch_wmo so we can offer competing models (hint: Hamon 1973).
parent dd97b4a9
......@@ -13,7 +13,7 @@ SET(meteofilters_sources
meteofilters/FilterRate.cc
meteofilters/FilterUnheatedHNW.cc
meteofilters/ProcUnventilatedT.cc
meteofilters/ProcUndercatch.cc
meteofilters/ProcUndercatch_WMO.cc
meteofilters/ProcAdd.cc
meteofilters/ProcMult.cc
meteofilters/ProcExpSmoothing.cc
......
......@@ -15,7 +15,7 @@
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/ProcUndercatch.h>
#include <meteoio/meteofilters/ProcUndercatch_WMO.h>
#include <meteoio/meteolaws/Atmosphere.h>
#include <cmath>
......@@ -23,20 +23,20 @@ using namespace std;
namespace mio {
const double ProcUndercatch::Tsnow_WMO=-2., ProcUndercatch::Train_WMO=2.; //WMO values from Yan et al (2001)
const double ProcUndercatch_WMO::Tsnow_WMO=-2., ProcUndercatch_WMO::Train_WMO=2.; //WMO values from Yan et al (2001)
ProcUndercatch::ProcUndercatch(const std::vector<std::string>& vec_args) : ProcessingBlock("UNDERCATCH") {
ProcUndercatch_WMO::ProcUndercatch_WMO(const std::vector<std::string>& vec_args) : ProcessingBlock("UNDERCATCH_WMO") {
Tsnow = Tsnow_WMO;
Train = Train_WMO;
parse_args(vec_args);
properties.stage = ProcessingProperties::first; //for the rest: default values
}
void ProcUndercatch::process(const unsigned int& param, const std::vector<MeteoData>& ivec,
void ProcUndercatch_WMO::process(const unsigned int& param, const std::vector<MeteoData>& ivec,
std::vector<MeteoData>& ovec)
{
if(param!=MeteoData::HNW)
throw InvalidArgumentException("Trying to use UNDERCATCH filter on " + MeteoData::getParameterName(param) + " but it can only be applied to precipitation!!" + getName(), AT);
throw InvalidArgumentException("Trying to use UNDERCATCH_WMO filter on " + MeteoData::getParameterName(param) + " but it can only be applied to precipitation!!" + getName(), AT);
ovec.clear();
ovec.reserve(ivec.size());
......@@ -121,7 +121,7 @@ void ProcUndercatch::process(const unsigned int& param, const std::vector<MeteoD
}
}
void ProcUndercatch::parse_args(std::vector<std::string> filter_args)
void ProcUndercatch_WMO::parse_args(std::vector<std::string> filter_args)
{
if (filter_args.size() < 1)
throw InvalidArgumentException("Wrong number of arguments for filter " + getName(), AT);
......
......@@ -15,8 +15,8 @@
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 __PROCUNDERCATCH_H__
#define __PROCUNDERCATCH_H__
#ifndef __PROCUNDERCATCH_WMO_H__
#define __PROCUNDERCATCH_WMO_H__
#include <meteoio/meteofilters/FilterBlock.h>
#include <vector>
......@@ -25,7 +25,7 @@
namespace mio {
/**
* @class ProcUndercatch
* @class ProcUndercatch_WMO
* @ingroup processing
* @author Mathias Bavay
* @date 2012-02-06
......@@ -57,14 +57,14 @@ of the Hellmann Gauges"</i>, Daqing Yang et al, Nordic Hydrology, <b>30</b>, 199
* - Hellmannsh - Hellmann rain gauge with shield, mixed precipitation from a fit on the published data
*
* @code
* HNW::filter1 = undercatch
* HNW::filter1 = undercatch_wmo
* HNW::arg1 = cst 1.3 1.1
* @endcode
*/
class ProcUndercatch : public ProcessingBlock {
class ProcUndercatch_WMO : public ProcessingBlock {
public:
ProcUndercatch(const std::vector<std::string>& vec_args);
ProcUndercatch_WMO(const std::vector<std::string>& vec_args);
virtual void process(const unsigned int& param, const std::vector<MeteoData>& ivec,
std::vector<MeteoData>& ovec);
......
......@@ -27,7 +27,7 @@
#include <meteoio/meteofilters/FilterUnheatedHNW.h>
#include <meteoio/meteofilters/FilterTukey.h>
#include <meteoio/meteofilters/FilterMAD.h>
#include <meteoio/meteofilters/ProcUndercatch.h>
#include <meteoio/meteofilters/ProcUndercatch_WMO.h>
#include <meteoio/meteofilters/ProcUnventilatedT.h>
#include <meteoio/meteofilters/ProcAdd.h>
#include <meteoio/meteofilters/ProcMult.h>
......@@ -88,7 +88,7 @@ namespace mio {
* - WIND_AVG: vector average over a given window, see FilterWindAvg (currently, getting both vw AND dw is broken)
* - ADD: adds a given offset to the data, see ProcAdd
* - MULT: multiply the data by a given factor, see ProcMult
* - UNDERCATCH: rain gauge correction for undercatch, using various correction models, see ProcUndercatch
* - UNDERCATCH_WMO: WMO rain gauge correction for undercatch, using various correction models, see ProcUndercatch_WMO
* - UNVENTILATED_T: unventilated temperature sensor correction, see ProcUnventilatedT
*
*/
......@@ -109,7 +109,7 @@ bool BlockFactory::initStaticData()
availableBlocks.insert("TUKEY");
availableBlocks.insert("MAD");
availableBlocks.insert("UNHEATED_RAINGAUGE");
availableBlocks.insert("UNDERCATCH");
availableBlocks.insert("UNDERCATCH_WMO");
availableBlocks.insert("UNVENTILATED_T");
availableBlocks.insert("ADD");
availableBlocks.insert("MULT");
......@@ -146,8 +146,8 @@ ProcessingBlock* BlockFactory::getBlock(const std::string& blockname, const std:
return new FilterMAD(vec_args);
} else if (blockname == "UNHEATED_RAINGAUGE"){
return new FilterUnheatedHNW(vec_args);
} else if (blockname == "UNDERCATCH"){
return new ProcUndercatch(vec_args);
} else if (blockname == "UNDERCATCH_WMO"){
return new ProcUndercatch_WMO(vec_args);
} else if (blockname == "UNVENTILATED_T"){
return new ProcUnventilatedT(vec_args);
} else if (blockname == "MULT"){
......
......@@ -56,7 +56,7 @@ HNW::filter2 = min
HNW::arg2 = soft 0.
HNW::filter3 = unheated_raingauge
HNW::arg3 = soft 0.5 3.
HNW::filter4 = undercatch
HNW::filter4 = undercatch_wmo
HNW::arg4 = Hellmannsh
ISWR::filter1 = min_max
......
......@@ -4,48 +4,42 @@
using namespace std;
using namespace mio;
bool grid3d(const unsigned int& n) {
cout << "Testing Grid3DObject\n";
bool array1d(const unsigned int& n) {
cout << "Testing Array1D<double>\n";
bool status = true;
srand((unsigned)time(0));
const double range = 10.;
Coords llcorner("CH1903","");
llcorner.setXY(785425. , 191124., 1400.);
Grid3DObject grid1(n, n, n, 100, llcorner);
Array1D<double> grid1(n);
for(unsigned int kk=0; kk<grid1.getNz(); kk++) {
for(unsigned int jj=0; jj<grid1.getNy(); jj++) {
for(unsigned int ii=0; ii<grid1.getNx(); ii++) {
grid1.grid3D(ii,jj,kk) = (double)rand()/(double)RAND_MAX*range;
}
}
for(unsigned int ii=0; ii<grid1.getNx(); ii++) {
grid1(ii) = (double)rand()/(double)RAND_MAX*range;
}
Grid3DObject grid2(n, n, n, 100, llcorner, grid1.grid3D);
grid2.grid3D -= 8.;
grid2.grid3D /= 2.;
grid2.grid3D += 4.;
grid2.grid3D *= 2.;
if(!grid2.grid3D.checkEpsilonEquality(grid1.grid3D, 1e-6)) {
Array1D<double> grid2=grid1;
grid2 -= 8.;
grid2 /= 2.;
grid2 += 4.;
grid2 *= 2.;
if(!grid2.checkEpsilonEquality(grid1, 1e-6)) {
cout << "\terror: basic operations with constants fail!\n";
status=false;
}
grid2.set(n, n, n, 100, llcorner, 0.);
grid2.grid3D += grid1.grid3D;
grid2.grid3D /= grid1.grid3D;
if(!IOUtils::checkEpsilonEquality(grid2.grid3D.getMean(), 1., 1e-6)) {
grid2.resize(n, 0.);
grid2 += grid1;
grid2 /= grid1;
if(!IOUtils::checkEpsilonEquality(grid2.getMean(), 1., 1e-6)) {
cout << "\terror: grids addition or division fails!\n";
status=false;
}
grid2.grid3D *= grid1.grid3D;
if(!grid2.grid3D.checkEpsilonEquality(grid1.grid3D, 1e-6)) {
grid2 *= grid1;
if(!grid2.checkEpsilonEquality(grid1, 1e-6)) {
cout << "\terror: grids multiplication fails!\n";
status=false;
}
grid2.grid3D -= grid1.grid3D;
if(!IOUtils::checkEpsilonEquality(grid2.grid3D.getMean(), 0., 1e-6)) {
grid2 -= grid1;
if(!IOUtils::checkEpsilonEquality(grid2.getMean(), 0., 1e-6)) {
cout << "\terror: grids substraction fails!\n";
status=false;
}
......@@ -100,6 +94,55 @@ bool grid2d(const unsigned int& n) {
return status;
}
bool grid3d(const unsigned int& n) {
cout << "Testing Grid3DObject\n";
bool status = true;
srand((unsigned)time(0));
const double range = 10.;
Coords llcorner("CH1903","");
llcorner.setXY(785425. , 191124., 1400.);
Grid3DObject grid1(n, n, n, 100, llcorner);
for(unsigned int kk=0; kk<grid1.getNz(); kk++) {
for(unsigned int jj=0; jj<grid1.getNy(); jj++) {
for(unsigned int ii=0; ii<grid1.getNx(); ii++) {
grid1.grid3D(ii,jj,kk) = (double)rand()/(double)RAND_MAX*range;
}
}
}
Grid3DObject grid2(n, n, n, 100, llcorner, grid1.grid3D);
grid2.grid3D -= 8.;
grid2.grid3D /= 2.;
grid2.grid3D += 4.;
grid2.grid3D *= 2.;
if(!grid2.grid3D.checkEpsilonEquality(grid1.grid3D, 1e-6)) {
cout << "\terror: basic operations with constants fail!\n";
status=false;
}
grid2.set(n, n, n, 100, llcorner, 0.);
grid2.grid3D += grid1.grid3D;
grid2.grid3D /= grid1.grid3D;
if(!IOUtils::checkEpsilonEquality(grid2.grid3D.getMean(), 1., 1e-6)) {
cout << "\terror: grids addition or division fails!\n";
status=false;
}
grid2.grid3D *= grid1.grid3D;
if(!grid2.grid3D.checkEpsilonEquality(grid1.grid3D, 1e-6)) {
cout << "\terror: grids multiplication fails!\n";
status=false;
}
grid2.grid3D -= grid1.grid3D;
if(!IOUtils::checkEpsilonEquality(grid2.grid3D.getMean(), 0., 1e-6)) {
cout << "\terror: grids substraction fails!\n";
status=false;
}
return status;
}
bool matrix(const unsigned int& n) {
cout << "Testing Matrix\n";
bool status=true;
......@@ -165,9 +208,10 @@ bool matrix(const unsigned int& n) {
int main() {
const unsigned int n=50;
const bool grid1d_status = array1d(n);
const bool grid2d_status = grid2d(n);
const bool grid3d_status = grid3d(n);
const bool matrix_status = matrix(n);
if(grid2d_status!=true || grid3d_status!=true || matrix_status!=true) throw IOException("Grid/Matrix error", AT);
if(grid1d_status!=true || grid2d_status!=true || grid3d_status!=true || matrix_status!=true) throw IOException("Grid/Matrix error", AT);
return 0;
}
......@@ -39,7 +39,7 @@ HNW::filter2 = min
HNW::arg2 = soft 0.
HNW::filter3 = unheated_raingauge
HNW::arg3 = soft 0.5 3.
HNW::filter4 = undercatch
HNW::filter4 = undercatch_wmo
HNW::arg4 = Hellmannsh
ISWR::filter1 = min_max
......
......@@ -39,7 +39,7 @@ HNW::filter2 = min
HNW::arg2 = soft 0.
HNW::filter3 = unheated_raingauge
HNW::arg3 = soft 0.5 3.
HNW::filter4 = undercatch
HNW::filter4 = undercatch_wmo
HNW::arg4 = Hellmannsh
ISWR::filter1 = min_max
......
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