WSL/SLF GitLab Repository

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

The gridsmanager and timeseriesmanager can now provide a copy of their Config...

The gridsmanager and timeseriesmanager can now provide a copy of their Config object. This has been used to fix a bug in the USER and ALS_SCALING spatial interpolation methods that were not properly reading their input files from GRID2DPATH. Moreover, now ALS_SCALING switches to CST when only 1 station provides measurements.
parent 6ead955d
......@@ -43,6 +43,13 @@ class GridsManager {
void setProcessingLevel(const unsigned int& i_level);
void clear_cache();
/**
* @brief Returns a copy of the internal Config object.
* This is convenient to clone an iomanager
* @return new Config object as a copy of the internal Config
*/
const Config getConfig() const {return cfg;}
const std::string toString() const;
......
......@@ -58,11 +58,6 @@ double IOManager::getAvgSamplingRate() const
return tsmanager.getAvgSamplingRate();
}
const Config IOManager::getConfig() const
{
return cfg;
}
void IOManager::push_meteo_data(const IOUtils::ProcessingLevel& level, const Date& date_start, const Date& date_end,
const std::vector< METEO_SET >& vecMeteo)
{
......
......@@ -192,7 +192,7 @@ class IOManager {
* This is convenient to clone an iomanager
* @return new Config object as a copy of the internal Config
*/
const Config getConfig() const;
const Config getConfig() const {return cfg;}
const std::string toString() const;
......
......@@ -1063,13 +1063,18 @@ double USERInterpolation::getQualityRating(const Date& i_date, const MeteoData::
date = i_date;
param = in_param;
filename = getGridFileName();
if (grid2d_path.empty()) {
const Config cfg( gridsmanager.getConfig() );
cfg.getValue("GRID2DPATH", "Input", grid2d_path);
}
if (!IOUtils::validFileAndPath(filename)) {
cerr << "[E] Invalid grid filename for "+algo+" interpolation algorithm: " << filename << "\n";
if (!IOUtils::validFileAndPath(grid2d_path+"/"+filename)) {
cerr << "[E] Invalid grid filename for "+algo+" interpolation algorithm: " << grid2d_path+"/"+filename << "\n";
return 0.0;
}
return (IOUtils::fileExists(filename))? 1. : 0.;
return (IOUtils::fileExists(grid2d_path+"/"+filename))? 1. : 0.;
}
void USERInterpolation::calculate(const DEMObject& dem, Grid2DObject& grid)
......@@ -1107,17 +1112,22 @@ double ALS_Interpolation::getQualityRating(const Date& i_date, const MeteoData::
const size_t nr_args = vecArgs.size();
if (nr_args==2) {
base_algo = IOUtils::strToUpper( vecArgs[0] );
base_algo = (nrOfMeasurments>1)? IOUtils::strToUpper( vecArgs[0] ) : "CST";
filename = vecArgs[1];
} else if (nr_args!=2)
throw InvalidArgumentException("Wrong number of arguments supplied for the "+algo+" algorithm", AT);
if (grid2d_path.empty()) {
const Config cfg( gridsmanager.getConfig() );
cfg.getValue("GRID2DPATH", "Input", grid2d_path);
}
if (!IOUtils::validFileAndPath(filename)) {
cerr << "[E] Invalid grid filename for "+algo+" interpolation algorithm: " << filename << "\n";
if (!IOUtils::validFileAndPath(grid2d_path+"/"+filename)) {
cerr << "[E] Invalid grid filename for "+algo+" interpolation algorithm: " << grid2d_path+"/"+filename << "\n";
return 0.0;
}
return (IOUtils::fileExists(filename))? 1. : 0.;
return (IOUtils::fileExists(grid2d_path+"/"+filename))? 1. : 0.;
}
void ALS_Interpolation::calculate(const DEMObject& dem, Grid2DObject& grid)
......@@ -1142,7 +1152,7 @@ void ALS_Interpolation::calculate(const DEMObject& dem, Grid2DObject& grid)
if (!ALS_scan.isSameGeolocalization(dem)) {
throw InvalidArgumentException("[E] trying to load a grid(" + filename + ") that does not have the same georeferencing as the DEM!", AT);
} else {
info << IOUtils::getFilename(filename);
info << IOUtils::getFilename(filename) << " - ";
}
initGrid(dem, grid);
......
......@@ -519,12 +519,12 @@ class USERInterpolation : public InterpolationAlgorithm {
USERInterpolation(Meteo2DInterpolator& i_mi,
const std::vector<std::string>& i_vecArgs,
const std::string& i_algo, TimeSeriesManager& i_tsmanager, GridsManager& i_gridsmanager)
: InterpolationAlgorithm(i_mi, i_vecArgs, i_algo, i_tsmanager, i_gridsmanager), filename() {nrOfMeasurments=0;}
: InterpolationAlgorithm(i_mi, i_vecArgs, i_algo, i_tsmanager, i_gridsmanager), filename(), grid2d_path() {nrOfMeasurments=0;}
virtual double getQualityRating(const Date& i_date, const MeteoData::Parameters& in_param);
virtual void calculate(const DEMObject& dem, Grid2DObject& grid);
private:
std::string getGridFileName() const;
std::string filename;
std::string filename, grid2d_path;
};
/**
......@@ -532,6 +532,8 @@ class USERInterpolation : public InterpolationAlgorithm {
* @brief Scale and distribute the precipitation according to Airborn Laser Scans (ALS) grids.
* This needs two arguments: first the base method to fill the grid (for example, idw_lapse) and
* then the name of the file (in GRID2DPATH) containing the gridded ALS data (relying on the GRID2D plugin).
* If there are some time steps when only one station provides the necessary parameter, the base method will
* automatically switch to "CST".
*
* @code
* PSUM::algorithms = ALS_SCALING
......@@ -543,13 +545,13 @@ class ALS_Interpolation : public InterpolationAlgorithm {
ALS_Interpolation(Meteo2DInterpolator& i_mi,
const std::vector<std::string>& i_vecArgs,
const std::string& i_algo, TimeSeriesManager& i_tsmanager, GridsManager& i_gridsmanager)
: InterpolationAlgorithm(i_mi, i_vecArgs, i_algo, i_tsmanager, i_gridsmanager), ALS_scan(), filename(), base_algo(), inputIsAllZeroes(false) {nrOfMeasurments=0;}
: InterpolationAlgorithm(i_mi, i_vecArgs, i_algo, i_tsmanager, i_gridsmanager), ALS_scan(), filename(), grid2d_path(), base_algo(), inputIsAllZeroes(false) {nrOfMeasurments=0;}
virtual double getQualityRating(const Date& i_date, const MeteoData::Parameters& in_param);
virtual void calculate(const DEMObject& dem, Grid2DObject& grid);
private:
void initGrid(const DEMObject& dem, Grid2DObject& grid);
Grid2DObject ALS_scan;
std::string filename, base_algo;
std::string filename, grid2d_path, base_algo;
bool inputIsAllZeroes;
};
......
......@@ -136,6 +136,13 @@ class TimeSeriesManager {
*/
void clear_cache();
/**
* @brief Returns a copy of the internal Config object.
* This is convenient to clone an iomanager
* @return new Config object as a copy of the internal Config
*/
const Config getConfig() const {return cfg;}
private:
void setDfltBufferProperties();
void fill_filtered_cache();
......
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