WSL/SLF GitLab Repository

Commit 622b5979 authored by Thomas Egger's avatar Thomas Egger
Browse files

Added functionality to the Meteo2DInterpolator: it is now possible to access...

Added functionality to the Meteo2DInterpolator: it is now possible to access the iomanager and hence to access historical data points from within any spatial interpolation.

The IOManager has been expanded to:
1) cache already filtered data points and
2) provide a getAvgSamplingRate() function that returns the average data points seen per day.
parent 56e6e3bc
......@@ -281,6 +281,23 @@ void BufferedIOHandler::legacy_readMeteoData(const Date& date_start, const Date&
meteoBuffer = vecMeteo; //copy by value
}
double BufferedIOHandler::getAvgSamplingRate()
{
if (vec_buffer_meteo.size() > 0){
unsigned int sum = 0;
for (unsigned int ii=0; ii<vec_buffer_meteo.size(); ii++){
//count all data
sum += vec_buffer_meteo[ii].size();
}
if (sum > 0){
double days = buffer_end.getJulianDate() - buffer_start.getJulianDate();
return ((double)sum / days);
}
}
return IOUtils::nodata;
}
void BufferedIOHandler::readMeteoData(const Date& date_start, const Date& date_end,
std::vector< std::vector<MeteoData> >& vecMeteo,
const unsigned int& /*stationindex*/)
......
......@@ -155,6 +155,8 @@ class BufferedIOHandler : public IOInterface {
*/
void setBufferDuration(const Date& _bufferbefore, const Date& _bufferafter);
double getAvgSamplingRate();
friend std::ostream& operator<<(std::ostream& os, const BufferedIOHandler& data);
private:
......
......@@ -9,6 +9,7 @@ IF(PROJ4)
ENDIF(PROJ4)
SET(meteoio_sources
IOManager.cc
Matrix.cc
IOPlugin.cc
MeteoProcessor.cc
......
......@@ -34,6 +34,15 @@ void IOManager::setProcessingLevel(const unsigned int& i_level)
processing_level = i_level;
}
double IOManager::getAvgSamplingRate()
{
if (processing_level == IOManager::raw){
return IOUtils::nodata;
} else {
return bufferedio.getAvgSamplingRate();
}
}
unsigned int IOManager::getStationData(const Date& date, std::vector<StationData>& vecStation)
{
vecStation.clear();
......@@ -64,6 +73,17 @@ unsigned int IOManager::getMeteoData(const Date& dateStart, const Date& dateEnd,
return vecMeteo.size(); //equivalent with the number of stations that have data
}
void IOManager::add_to_cache(const Date& i_date, const std::vector<MeteoData>& vecMeteo)
{
//Check cache size, delete oldest elements if necessary
if (meteo_cache.size() > 200){
meteo_cache.clear();
//meteo_cache.erase(meteo_cache.begin(), meteo_cache.begin()+50);
}
meteo_cache[i_date] = vecMeteo;
}
//data can be raw or processed (filtered, resampled)
unsigned int IOManager::getMeteoData(const Date& i_date, std::vector<MeteoData>& vecMeteo)
{
......@@ -89,6 +109,12 @@ unsigned int IOManager::getMeteoData(const Date& i_date, std::vector<MeteoData>&
//2. Check which data is available, buffered locally
map<Date, vector<MeteoData> >::const_iterator it = meteo_cache.find(i_date);
if (it != meteo_cache.end()){
vecMeteo = it->second;
return vecMeteo.size();
}
// request an appropriate window of data from bufferedio
// Hand window of data over to meteo processor
bufferedio.readMeteoData(i_date-time_before, i_date+time_after, vec_cache);
......@@ -98,6 +124,9 @@ unsigned int IOManager::getMeteoData(const Date& i_date, std::vector<MeteoData>&
vecMeteo.push_back(tmpmd);
}
//Store result in the local cache
add_to_cache(i_date, vecMeteo);
return vecMeteo.size();
}
......@@ -120,11 +149,8 @@ void IOManager::interpolate(const Date& date, const DEMObject& dem, const MeteoD
void IOManager::interpolate(const Date& date, const DEMObject& dem, const MeteoData::Parameters& meteoparam,
Grid2DObject& result, std::string& info_string)
{
vector<MeteoData> vec_meteo;
getMeteoData(date, vec_meteo);
Meteo2DInterpolator mi(cfg, dem, vec_meteo);
mi.interpolate(meteoparam, result, info_string);
Meteo2DInterpolator mi(cfg, *this);
mi.interpolate(date, dem, meteoparam, result, info_string);
}
void IOManager::read2DGrid(Grid2DObject& grid2D, const std::string& filename)
......
......@@ -61,14 +61,19 @@ class IOManager {
void setProcessingLevel(const unsigned int& i_level);
double getAvgSamplingRate();
void writeMeteoData(const std::vector< std::vector<MeteoData> >& vecMeteo, const std::string& name="");
private:
void add_to_cache(const Date& i_date, const std::vector<MeteoData>& vecMeteo);
Config cfg;
IOHandler rawio;
BufferedIOHandler bufferedio;
MeteoProcessor meteoprocessor;
std::map<Date, std::vector<MeteoData> > meteo_cache; ///< stores already fetched data points
unsigned int processing_level;
};
} //end namespace
......
......@@ -51,10 +51,11 @@ bool AlgorithmFactory::initStaticData()
//HACK: do not build a new object at every time step!!
InterpolationAlgorithm* AlgorithmFactory::getAlgorithm(const std::string& _algoname,
const Meteo2DInterpolator& _mi,
Meteo2DInterpolator& _mi,
const Date& date,
const DEMObject& _dem,
const std::vector<MeteoData>& _vecMeteo,
const std::vector<std::string>& _vecArgs)
const std::vector<std::string>& _vecArgs,
IOManager& iom)
{
std::string algoname(_algoname);
IOUtils::toUpper(algoname);
......@@ -64,27 +65,27 @@ InterpolationAlgorithm* AlgorithmFactory::getAlgorithm(const std::string& _algon
throw UnknownValueException("The interpolation algorithm '"+algoname+"' does not exist" , AT);
if (algoname == "CST"){
return new ConstAlgorithm(_mi, _dem, _vecMeteo, _vecArgs, _algoname);
return new ConstAlgorithm(_mi, date, _dem, _vecArgs, _algoname, iom);
} else if (algoname == "STD_PRESS"){
return new StandardPressureAlgorithm(_mi, _dem, _vecMeteo, _vecArgs, _algoname);
return new StandardPressureAlgorithm(_mi, date, _dem, _vecArgs, _algoname, iom);
} else if (algoname == "CST_LAPSE"){
return new ConstLapseRateAlgorithm(_mi, _dem, _vecMeteo, _vecArgs, _algoname);
return new ConstLapseRateAlgorithm(_mi, date, _dem, _vecArgs, _algoname, iom);
} else if (algoname == "IDW"){
return new IDWAlgorithm(_mi, _dem, _vecMeteo, _vecArgs, _algoname);
return new IDWAlgorithm(_mi, date, _dem, _vecArgs, _algoname, iom);
} else if (algoname == "IDW_LAPSE"){
return new IDWLapseAlgorithm(_mi, _dem, _vecMeteo, _vecArgs, _algoname);
return new IDWLapseAlgorithm(_mi, date, _dem, _vecArgs, _algoname, iom);
} else if (algoname == "LIDW_LAPSE"){
return new LocalIDWLapseAlgorithm(_mi, _dem, _vecMeteo, _vecArgs, _algoname);
return new LocalIDWLapseAlgorithm(_mi, date, _dem, _vecArgs, _algoname, iom);
} else if (algoname == "RH"){
return new RHAlgorithm(_mi, _dem, _vecMeteo, _vecArgs, _algoname);
return new RHAlgorithm(_mi, date, _dem, _vecArgs, _algoname, iom);
} else if (algoname == "WIND_CURV"){
return new SimpleWindInterpolationAlgorithm(_mi, _dem, _vecMeteo, _vecArgs, _algoname);
return new SimpleWindInterpolationAlgorithm(_mi, date, _dem, _vecArgs, _algoname, iom);
} else if (algoname == "ODKRIG"){
return new OrdinaryKrigingAlgorithm(_mi, _dem, _vecMeteo, _vecArgs, _algoname);
return new OrdinaryKrigingAlgorithm(_mi, date, _dem, _vecArgs, _algoname, iom);
} else if (algoname == "USER"){
return new USERInterpolation(_mi, _dem, _vecMeteo, _vecArgs, _algoname);
return new USERInterpolation(_mi, date, _dem, _vecArgs, _algoname, iom);
} else if (algoname == "HNW_SNOW"){
return new SnowHNWInterpolation(_mi, _dem, _vecMeteo, _vecArgs, _algoname);
return new SnowHNWInterpolation(_mi, date, _dem, _vecArgs, _algoname, iom);
} else {
throw IOException("The interpolation algorithm '"+algoname+"' is not implemented" , AT);
}
......@@ -92,6 +93,18 @@ InterpolationAlgorithm* AlgorithmFactory::getAlgorithm(const std::string& _algon
return NULL;
}
InterpolationAlgorithm::InterpolationAlgorithm(Meteo2DInterpolator& i_mi,
const Date& i_date,
const DEMObject& i_dem,
const std::vector<std::string>& i_vecArgs,
const std::string& i_algo, IOManager& iom)
: mi(i_mi), date(i_date), dem(i_dem), vecArgs(i_vecArgs), algo(i_algo), iomanager(iom)
{
nrOfMeasurments = 0;
param = MeteoData::firstparam; //this is a stupid default value, but since we never check it...
iomanager.getMeteoData(date, vecMeteo);
}
unsigned int InterpolationAlgorithm::getData(const MeteoData::Parameters& param,
std::vector<double>& vecData) const
{
......@@ -103,12 +116,12 @@ unsigned int InterpolationAlgorithm::getData(const MeteoData::Parameters& param,
unsigned int InterpolationAlgorithm::getData(const MeteoData::Parameters& param,
std::vector<double>& vecData, std::vector<StationData>& vecMeta) const
{
if(vecData.size()>0) {
if (vecData.size() > 0)
vecData.clear();
}
if(vecMeta.size()>0) {
if (vecMeta.size() > 0)
vecMeta.clear();
}
for (unsigned int ii=0; ii<vecMeteo.size(); ii++){
const double& val = vecMeteo[ii].param(param);
if (val != IOUtils::nodata){
......@@ -442,7 +455,7 @@ void RHAlgorithm::calculate(Grid2DObject& grid)
throw IOException("Interpolation FAILED for parameter " + MeteoData::getParameterName(param), AT);
Grid2DObject ta;
mi.interpolate(MeteoData::TA, ta); //get TA interpolation from call back to Meteo2DInterpolator
mi.interpolate(date, dem, MeteoData::TA, ta); //get TA interpolation from call back to Meteo2DInterpolator
//here, RH->Td, interpolations, Td->RH
std::vector<double> vecTd(vecDataRH.size(), 0.0); // init to 0.0
......@@ -519,7 +532,7 @@ void SimpleWindInterpolationAlgorithm::calculate(Grid2DObject& grid)
throw IOException("Interpolation FAILED for parameter " + MeteoData::getParameterName(param), AT);
Grid2DObject dw;
mi.interpolate(MeteoData::DW, dw); //get DW interpolation from call back to Meteo2DInterpolator
mi.interpolate(date, dem, MeteoData::DW, dw); //get DW interpolation from call back to Meteo2DInterpolator
//Krieging
std::vector<double> vecCoefficients;
......@@ -608,7 +621,7 @@ void SnowHNWInterpolation::calculate(Grid2DObject& grid)
IOUtils::toUpper(base_algo);
vector<string> vecArgs2;
mi.getArgumentsForAlgorithm(param, base_algo, vecArgs2);
auto_ptr<InterpolationAlgorithm> algorithm(AlgorithmFactory::getAlgorithm(base_algo, mi, dem, vecMeteo, vecArgs2));
auto_ptr<InterpolationAlgorithm> algorithm(AlgorithmFactory::getAlgorithm(base_algo, mi, date, dem, vecArgs2, iomanager));
algorithm->initialize(param);
algorithm->calculate(grid);
info << algorithm->getInfo();
......@@ -616,7 +629,7 @@ void SnowHNWInterpolation::calculate(Grid2DObject& grid)
//get TA interpolation from call back to Meteo2DInterpolator
Grid2DObject ta;
mi.interpolate(MeteoData::TA, ta);
mi.interpolate(date, dem, MeteoData::TA, ta);
//slope/curvature correction for solid precipitation
Interpol2D::PrecipSnow(dem, ta, grid);
......
......@@ -27,6 +27,7 @@
namespace mio {
class IOManager;
class Meteo2DInterpolator; // forward declaration, cyclic header include
/**
......@@ -127,30 +128,28 @@ class Meteo2DInterpolator; // forward declaration, cyclic header include
class InterpolationAlgorithm {
public:
InterpolationAlgorithm(const Meteo2DInterpolator& _mi,
InterpolationAlgorithm(Meteo2DInterpolator& _mi,
const Date& date,
const DEMObject& _dem,
const std::vector<MeteoData>& _vecMeteo,
const std::vector<std::string>& _vecArgs,
const std::string _algo)
: mi(_mi), dem(_dem), vecMeteo(_vecMeteo), vecArgs(_vecArgs), algo(_algo)
{
nrOfMeasurments = 0;
param = MeteoData::firstparam; //this is a stupid default value, but since we never check it...
}
const std::string& _algo, IOManager& iom);
virtual ~InterpolationAlgorithm() {}
virtual void initialize(const MeteoData::Parameters& in_param) = 0;
virtual double getQualityRating() = 0;
virtual void calculate(Grid2DObject& grid) = 0;
std::string getInfo() const;
protected:
const Meteo2DInterpolator& mi;
Meteo2DInterpolator& mi;
const Date& date;
const DEMObject& dem;
const std::vector<MeteoData>& vecMeteo;
const std::vector<std::string> vecArgs; //we must keep our own copy, it is different for each algorithm!
const std::string algo;
IOManager& iomanager;
MeteoData::Parameters param; ///<the parameter that we will interpolate
unsigned int nrOfMeasurments; ///<the available number of measurements
std::vector<MeteoData> vecMeteo;
std::vector<double> vecData; ///<store the measurement for the given parameter
std::vector<StationData> vecMeta; ///<store the station data for the given parameter
std::stringstream info; ///<to store some extra information about the interoplation process
......@@ -164,10 +163,11 @@ class InterpolationAlgorithm {
class AlgorithmFactory {
public:
static InterpolationAlgorithm* getAlgorithm(const std::string& _algoname,
const Meteo2DInterpolator& _mi,
Meteo2DInterpolator& _mi,
const Date& date,
const DEMObject& _dem,
const std::vector<MeteoData>& _vecMeteo,
const std::vector<std::string>& _vecArgs);
const std::vector<std::string>& _vecArgs,
IOManager& iom);
static std::set<std::string> setAlgorithms; ///<all algorithms that are configured
static const bool __init; ///<helper variable to enable the init of static collection data
......@@ -181,12 +181,12 @@ class AlgorithmFactory {
*/
class ConstAlgorithm : public InterpolationAlgorithm {
public:
ConstAlgorithm(const Meteo2DInterpolator& _mi,
const DEMObject& _dem,
const std::vector<MeteoData>& _vecMeteo,
const std::vector<std::string>& _vecArgs,
const std::string _algo)
: InterpolationAlgorithm(_mi, _dem, _vecMeteo, _vecArgs, _algo) {}
ConstAlgorithm(Meteo2DInterpolator& _mi,
const Date& date,
const DEMObject& _dem,
const std::vector<std::string>& _vecArgs,
const std::string& _algo, IOManager& iom)
: InterpolationAlgorithm(_mi, date, _dem, _vecArgs, _algo, iom) {}
virtual void initialize(const MeteoData::Parameters& in_param);
virtual double getQualityRating();
virtual void calculate(Grid2DObject& grid);
......@@ -199,12 +199,12 @@ class ConstAlgorithm : public InterpolationAlgorithm {
*/
class StandardPressureAlgorithm : public InterpolationAlgorithm {
public:
StandardPressureAlgorithm(const Meteo2DInterpolator& _mi,
const DEMObject& _dem,
const std::vector<MeteoData>& _vecMeteo,
const std::vector<std::string>& _vecArgs,
const std::string _algo)
: InterpolationAlgorithm(_mi, _dem, _vecMeteo, _vecArgs, _algo) {}
StandardPressureAlgorithm(Meteo2DInterpolator& _mi,
const Date& date,
const DEMObject& _dem,
const std::vector<std::string>& _vecArgs,
const std::string& _algo, IOManager& iom)
: InterpolationAlgorithm(_mi, date, _dem, _vecArgs, _algo, iom) {}
virtual void initialize(const MeteoData::Parameters& in_param);
virtual double getQualityRating();
virtual void calculate(Grid2DObject& grid);
......@@ -224,12 +224,12 @@ class StandardPressureAlgorithm : public InterpolationAlgorithm {
*/
class ConstLapseRateAlgorithm : public InterpolationAlgorithm {
public:
ConstLapseRateAlgorithm(const Meteo2DInterpolator& _mi,
const DEMObject& _dem,
const std::vector<MeteoData>& _vecMeteo,
const std::vector<std::string>& _vecArgs,
const std::string _algo)
: InterpolationAlgorithm(_mi, _dem, _vecMeteo, _vecArgs, _algo) {}
ConstLapseRateAlgorithm(Meteo2DInterpolator& _mi,
const Date& date,
const DEMObject& _dem,
const std::vector<std::string>& _vecArgs,
const std::string& _algo, IOManager& iom)
: InterpolationAlgorithm(_mi, date, _dem, _vecArgs, _algo, iom) {}
virtual void initialize(const MeteoData::Parameters& in_param);
virtual double getQualityRating();
virtual void calculate(Grid2DObject& grid);
......@@ -244,12 +244,12 @@ class ConstLapseRateAlgorithm : public InterpolationAlgorithm {
*/
class IDWAlgorithm : public InterpolationAlgorithm {
public:
IDWAlgorithm(const Meteo2DInterpolator& _mi,
const DEMObject& _dem,
const std::vector<MeteoData>& _vecMeteo,
const std::vector<std::string>& _vecArgs,
const std::string _algo)
: InterpolationAlgorithm(_mi, _dem, _vecMeteo, _vecArgs, _algo) {}
IDWAlgorithm(Meteo2DInterpolator& _mi,
const Date& date,
const DEMObject& _dem,
const std::vector<std::string>& _vecArgs,
const std::string& _algo, IOManager& iom)
: InterpolationAlgorithm(_mi, date, _dem, _vecArgs, _algo, iom) {}
virtual void initialize(const MeteoData::Parameters& in_param);
virtual double getQualityRating();
virtual void calculate(Grid2DObject& grid);
......@@ -271,12 +271,12 @@ class IDWAlgorithm : public InterpolationAlgorithm {
*/
class IDWLapseAlgorithm : public InterpolationAlgorithm {
public:
IDWLapseAlgorithm(const Meteo2DInterpolator& _mi,
const DEMObject& _dem,
const std::vector<MeteoData>& _vecMeteo,
const std::vector<std::string>& _vecArgs,
const std::string _algo)
: InterpolationAlgorithm(_mi, _dem, _vecMeteo, _vecArgs, _algo) {}
IDWLapseAlgorithm(Meteo2DInterpolator& _mi,
const Date& date,
const DEMObject& _dem,
const std::vector<std::string>& _vecArgs,
const std::string& _algo, IOManager& iom)
: InterpolationAlgorithm(_mi, date, _dem, _vecArgs, _algo, iom) {}
virtual void initialize(const MeteoData::Parameters& in_param);
virtual double getQualityRating();
virtual void calculate(Grid2DObject& grid);
......@@ -292,12 +292,12 @@ class IDWLapseAlgorithm : public InterpolationAlgorithm {
*/
class LocalIDWLapseAlgorithm : public InterpolationAlgorithm {
public:
LocalIDWLapseAlgorithm(const Meteo2DInterpolator& _mi,
const DEMObject& _dem,
const std::vector<MeteoData>& _vecMeteo,
const std::vector<std::string>& _vecArgs,
const std::string _algo)
: InterpolationAlgorithm(_mi, _dem, _vecMeteo, _vecArgs, _algo) {}
LocalIDWLapseAlgorithm(Meteo2DInterpolator& _mi,
const Date& date,
const DEMObject& _dem,
const std::vector<std::string>& _vecArgs,
const std::string& _algo, IOManager& iom)
: InterpolationAlgorithm(_mi, date, _dem, _vecArgs, _algo, iom) {}
virtual void initialize(const MeteoData::Parameters& in_param);
virtual double getQualityRating();
virtual void calculate(Grid2DObject& grid);
......@@ -315,12 +315,12 @@ class LocalIDWLapseAlgorithm : public InterpolationAlgorithm {
*/
class RHAlgorithm : public InterpolationAlgorithm {
public:
RHAlgorithm(const Meteo2DInterpolator& _mi,
const DEMObject& _dem,
const std::vector<MeteoData>& _vecMeteo,
const std::vector<std::string>& _vecArgs,
const std::string _algo)
: InterpolationAlgorithm(_mi, _dem, _vecMeteo, _vecArgs, _algo) {}
RHAlgorithm(Meteo2DInterpolator& _mi,
const Date& date,
const DEMObject& _dem,
const std::vector<std::string>& _vecArgs,
const std::string& _algo, IOManager& iom)
: InterpolationAlgorithm(_mi, date, _dem, _vecArgs, _algo, iom) {}
virtual void initialize(const MeteoData::Parameters& in_param);
virtual double getQualityRating();
virtual void calculate(Grid2DObject& grid);
......@@ -339,12 +339,12 @@ class RHAlgorithm : public InterpolationAlgorithm {
*/
class SimpleWindInterpolationAlgorithm : public InterpolationAlgorithm {
public:
SimpleWindInterpolationAlgorithm(const Meteo2DInterpolator& _mi,
const DEMObject& _dem,
const std::vector<MeteoData>& _vecMeteo,
const std::vector<std::string>& _vecArgs,
const std::string _algo)
: InterpolationAlgorithm(_mi, _dem, _vecMeteo, _vecArgs, _algo) {}
SimpleWindInterpolationAlgorithm(Meteo2DInterpolator& _mi,
const Date& date,
const DEMObject& _dem,
const std::vector<std::string>& _vecArgs,
const std::string& _algo, IOManager& iom)
: InterpolationAlgorithm(_mi, date, _dem, _vecArgs, _algo, iom) {}
virtual void initialize(const MeteoData::Parameters& in_param);
virtual double getQualityRating();
virtual void calculate(Grid2DObject& grid);
......@@ -359,12 +359,12 @@ class SimpleWindInterpolationAlgorithm : public InterpolationAlgorithm {
*/
class USERInterpolation : public InterpolationAlgorithm {
public:
USERInterpolation(const Meteo2DInterpolator& _mi,
const DEMObject& _dem,
const std::vector<MeteoData>& _vecMeteo,
const std::vector<std::string>& _vecArgs,
const std::string _algo)
: InterpolationAlgorithm(_mi, _dem, _vecMeteo, _vecArgs, _algo) {}
USERInterpolation(Meteo2DInterpolator& _mi,
const Date& date,
const DEMObject& _dem,
const std::vector<std::string>& _vecArgs,
const std::string& _algo, IOManager& iom)
: InterpolationAlgorithm(_mi, date, _dem, _vecArgs, _algo, iom) {}
virtual void initialize(const MeteoData::Parameters& in_param);
virtual double getQualityRating();
virtual void calculate(Grid2DObject& grid);
......@@ -387,12 +387,12 @@ class USERInterpolation : public InterpolationAlgorithm {
*/
class SnowHNWInterpolation : public InterpolationAlgorithm {
public:
SnowHNWInterpolation(const Meteo2DInterpolator& _mi,
const DEMObject& _dem,
const std::vector<MeteoData>& _vecMeteo,
const std::vector<std::string>& _vecArgs,
const std::string _algo)
: InterpolationAlgorithm(_mi, _dem, _vecMeteo, _vecArgs, _algo) {}
SnowHNWInterpolation(Meteo2DInterpolator& _mi,
const Date& date,
const DEMObject& _dem,
const std::vector<std::string>& _vecArgs,
const std::string& _algo, IOManager& iom)
: InterpolationAlgorithm(_mi, date, _dem, _vecArgs, _algo, iom) {}
virtual void initialize(const MeteoData::Parameters& in_param);
virtual double getQualityRating();
virtual void calculate(Grid2DObject& grid);
......@@ -405,12 +405,12 @@ class SnowHNWInterpolation : public InterpolationAlgorithm {
*/
class OrdinaryKrigingAlgorithm : public InterpolationAlgorithm {
public:
OrdinaryKrigingAlgorithm(const Meteo2DInterpolator& _mi,
const DEMObject& _dem,
const std::vector<MeteoData>& _vecMeteo,
const std::vector<std::string>& _vecArgs,
const std::string _algo)
: InterpolationAlgorithm(_mi, _dem, _vecMeteo, _vecArgs, _algo) {}
OrdinaryKrigingAlgorithm(Meteo2DInterpolator& _mi,
const Date& date,
const DEMObject& _dem,
const std::vector<std::string>& _vecArgs,
const std::string& _algo, IOManager& iom)
: InterpolationAlgorithm(_mi, date, _dem, _vecArgs, _algo, iom) {}
virtual void initialize(const MeteoData::Parameters& in_param);
virtual double getQualityRating();
virtual void calculate(Grid2DObject& grid);
......
......@@ -21,10 +21,32 @@
using namespace std;
namespace mio {
/*
Meteo2DInterpolator::Meteo2DInterpolator(const Config& i_cfg, const DEMObject& i_dem,
const std::vector<MeteoData>& i_vecMeteo)
: cfg(i_cfg), dem(i_dem), vecMeteo(i_vecMeteo)
{
*/
/*
* By reading the Config object build up a list of user configured algorithms
* for each MeteoData::Parameters parameter (i.e. each member variable of MeteoData like ta, p, hnw, ...)
* Concept of this constructor: loop over all MeteoData::Parameters and then look
* for configuration of interpolation algorithms within the Config object.
*/
/*
for (unsigned int ii=0; ii < MeteoData::nrOfParameters; ii++){ //loop over all MeteoData member variables
std::vector<std::string> tmpAlgorithms;
const std::string& parname = MeteoData::getParameterName(ii); //Current parameter name
unsigned int nrOfAlgorithms = getAlgorithmsForParameter(parname, tmpAlgorithms);
if (nrOfAlgorithms > 0)
mapAlgorithms[parname] = tmpAlgorithms;
}
check_projections(dem, vecMeteo);
}
*/
Meteo2DInterpolator::Meteo2DInterpolator(const Config& i_cfg, IOManager& i_iom) : cfg(i_cfg), iomanager(i_iom)
{
/*
* By reading the Config object build up a list of user configured algorithms
......@@ -40,10 +62,13 @@ Meteo2DInterpolator::Meteo2DInterpolator(const Config& i_cfg, const DEMObject& i
if (nrOfAlgorithms > 0)
mapAlgorithms[parname] = tmpAlgorithms;
}
}
void Meteo2DInterpolator::check_projections(const DEMObject& dem, const std::vector<MeteoData>& vec_meteo)
{
//check that the stations are using the same projection as the dem
for (unsigned int i=0; i<(unsigned int)vecMeteo.size(); i++) {
const StationData& meta = vecMeteo[i].meta;
for (unsigned int i=0; i<(unsigned int)vec_meteo.size(); i++) {
const StationData& meta = vec_meteo[i].meta;
if(!meta.position.isSameProj(dem.llcorner)) {
std::stringstream os;
std::string type, args;
......@@ -56,13 +81,15 @@ Meteo2DInterpolator::Meteo2DInterpolator(const Config& i_cfg, const DEMObject& i
}
}
void Meteo2DInterpolator::interpolate(const MeteoData::Parameters& meteoparam, Grid2DObject& result) const