WSL/SLF GitLab Repository

Commit b489efef authored by Mathias Bavay's avatar Mathias Bavay
Browse files

The structure of Meteo2DInterpolator has been brought closer to the structure...

The structure of Meteo2DInterpolator has been brought closer to the structure of DataGenerators. More methods are static.
parent 28da250f
......@@ -132,7 +132,7 @@ void DataGenerator::setAlgorithms(const Config& cfg)
}
}
size_t DataGenerator::get_parameters(const Config& cfg, std::set<std::string>& set_parameters) const
size_t DataGenerator::get_parameters(const Config& cfg, std::set<std::string>& set_parameters)
{
std::vector<std::string> vec_keys;
cfg.findKeys(vec_keys, std::string(), "Generators");
......@@ -171,7 +171,7 @@ size_t DataGenerator::getAlgorithmsForParameter(const Config& cfg, const std::st
size_t DataGenerator::getArgumentsForAlgorithm(const Config& cfg,
const std::string& parname,
const std::string& algorithm,
std::vector<std::string>& vecArgs) const
std::vector<std::string>& vecArgs)
{
vecArgs.clear();
cfg.getValue(parname+"::"+algorithm, "Generators", vecArgs, IOUtils::nothrow);
......
......@@ -118,12 +118,12 @@ class DataGenerator {
const std::string toString() const;
private:
void setAlgorithms(const Config& cfg);
size_t get_parameters(const Config& cfg, std::set<std::string>& set_parameters) const;
size_t getAlgorithmsForParameter(const Config& cfg, const std::string& parname, std::vector<std::string>& vecAlgorithms);
size_t getArgumentsForAlgorithm(const Config& cfg, const std::string& parname,
static size_t get_parameters(const Config& cfg, std::set<std::string>& set_parameters);
static size_t getAlgorithmsForParameter(const Config& cfg, const std::string& parname, std::vector<std::string>& vecAlgorithms);
static size_t getArgumentsForAlgorithm(const Config& cfg, const std::string& parname,
const std::string& algorithm,
std::vector<std::string>& vecArgs) const;
std::vector<std::string>& vecArgs);
void setAlgorithms(const Config& cfg);
std::map< std::string, std::vector<GeneratorAlgorithm*> > mapAlgorithms; //per parameter data generators algorithms
bool generators_defined; //if true, there are some generators to run. if false, nothing to do
......
......@@ -46,6 +46,10 @@ Meteo2DInterpolator& Meteo2DInterpolator::operator=(const Meteo2DInterpolator& s
return *this;
}
void Meteo2DInterpolator::setIOManager(IOManager& i_iomanager) {
iomanager = &i_iomanager;
}
void Meteo2DInterpolator::setAlgorithms()
{
/* By reading the Config object build up a list of user configured algorithms
......@@ -56,32 +60,27 @@ void Meteo2DInterpolator::setAlgorithms()
for (size_t 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
const size_t nrOfAlgorithms = getAlgorithmsForParameter(parname, tmpAlgorithms);
const size_t nrOfAlgorithms = getAlgorithmsForParameter(cfg, parname, tmpAlgorithms);
if (nrOfAlgorithms > 0)
mapAlgorithms[parname] = tmpAlgorithms;
}
}
void Meteo2DInterpolator::setIOManager(IOManager& i_iomanager) {
iomanager = &i_iomanager;
}
void Meteo2DInterpolator::check_projections(const DEMObject& dem, const std::vector<MeteoData>& vec_meteo)
size_t Meteo2DInterpolator::get_parameters(const Config& cfg, std::set<std::string>& set_parameters)
{
//check that the stations are using the same projection as the dem
for (size_t i=0; i<vec_meteo.size(); i++) {
const StationData& meta = vec_meteo[i].meta;
if(!meta.position.isSameProj(dem.llcorner)) {
std::stringstream os;
std::string type, args;
meta.position.getProj(type, args);
os << "Station " << meta.stationID << " is using projection (" << type << " " << args << ") ";
dem.llcorner.getProj(type, args);
os << "while DEM is using projection ("<< type << " " << args << ") ";
throw IOException(os.str(), AT);
std::vector<std::string> vec_keys;
cfg.findKeys(vec_keys, std::string(), "Interpolations2D");
for (size_t ii=0; ii<vec_keys.size(); ii++) {
const size_t found = vec_keys[ii].find_first_of(":");
if (found != std::string::npos){
const string tmp = vec_keys[ii].substr(0,found);
set_parameters.insert( IOUtils::strToUpper(tmp) );
}
}
return set_parameters.size();
}
void Meteo2DInterpolator::interpolate(const Date& date, const DEMObject& dem, const MeteoData::Parameters& meteoparam,
......@@ -150,12 +149,11 @@ void Meteo2DInterpolator::interpolate(const Date& date, const DEMObject& dem, co
}
}
size_t Meteo2DInterpolator::getAlgorithmsForParameter(const std::string& parname, std::vector<std::string>& vecAlgorithms)
size_t Meteo2DInterpolator::getAlgorithmsForParameter(const Config& cfg, const std::string& parname, std::vector<std::string>& vecAlgorithms)
{
// This function retrieves the user defined interpolation algorithms for
// parameter 'parname' by querying the Config object
vecAlgorithms.clear();
std::vector<std::string> vecKeys;
cfg.findKeys(vecKeys, parname+"::algorithms", "Interpolations2D");
......@@ -165,9 +163,7 @@ size_t Meteo2DInterpolator::getAlgorithmsForParameter(const std::string& parname
if (vecKeys.empty())
return 0;
cfg.getValue(vecKeys.at(0), "Interpolations2D", vecAlgorithms, IOUtils::nothrow);
cfg.getValue(vecKeys[0], "Interpolations2D", vecAlgorithms, IOUtils::nothrow);
return vecAlgorithms.size();
}
......@@ -199,6 +195,24 @@ void Meteo2DInterpolator::checkMinMax(const double& minval, const double& maxval
}
}
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 (size_t ii=0; ii<vec_meteo.size(); ii++) {
const StationData& meta = vec_meteo[ii].meta;
if(!meta.position.isSameProj(dem.llcorner)) {
std::stringstream os;
std::string type, args;
meta.position.getProj(type, args);
os << "Station " << meta.stationID << " is using projection (" << type << " " << args << ") ";
dem.llcorner.getProj(type, args);
os << "while DEM is using projection ("<< type << " " << args << ") ";
throw IOException(os.str(), AT);
}
}
}
const std::string Meteo2DInterpolator::toString() const {
ostringstream os;
os << "<Meteo2DInterpolator>\n";
......
......@@ -137,14 +137,6 @@ class Meteo2DInterpolator {
void interpolate(const Date& date, const DEMObject& dem, const MeteoData::Parameters& meteoparam,
Grid2DObject& result, std::string& InfoString);
/**
* @brief A min/max filter for 2D grids
* @param minval Minimum value allowed in the 2D grid
* @param maxval Maximum value allowed in the 2D grid
* @param gridobj A Grid2DObject that will be min/max checked
*/
static void checkMinMax(const double& minval, const double& maxval, Grid2DObject& gridobj);
/**
* @brief Retrieve the arguments vector for a given interpolation algorithm
* @param param the meteorological parameter that is concerned
......@@ -160,14 +152,17 @@ class Meteo2DInterpolator {
const std::string toString() const;
private:
static void checkMinMax(const double& minval, const double& maxval, Grid2DObject& gridobj);
static void check_projections(const DEMObject& dem, const std::vector<MeteoData>& vec_meteo);
static size_t get_parameters(const Config& cfg, std::set<std::string>& set_parameters);
static size_t getAlgorithmsForParameter(const Config& cfg, const std::string& parname, std::vector<std::string>& vecAlgorithms);
void setAlgorithms();
void check_projections(const DEMObject& dem, const std::vector<MeteoData>& vec_meteo);
size_t getAlgorithmsForParameter(const std::string& parname, std::vector<std::string>& vecAlgorithms);
const Config& cfg; ///< Reference to Config object, initialized during construction
IOManager *iomanager; ///< Reference to IOManager object, used for callbacks, initialized during construction
std::map< std::string, std::vector<std::string> > mapAlgorithms; //per parameter interpolation algorithms
std::map< std::string, std::vector<std::string> > mapAlgorithms;
};
} //end namespace
......
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