WSL/SLF GitLab Repository

Commit 145a9db4 authored by Mathias Bavay's avatar Mathias Bavay
Browse files

A new spatial interpolation algorithm has been implemented: "NONE". This just...

A new spatial interpolation algorithm has been implemented: "NONE". This just fills the grid with nodata. Otherwise, an unnecessary check has been removed in Meteo2DInterpolator and some comments editing, white spaces...
parent 33c0e4e3
......@@ -329,7 +329,7 @@ size_t IOManager::getVirtualMeteoData(const Date& i_date, METEO_SET& vecMeteo)
}
DEMObject dem;
bufferedio.readDEM(dem);
bufferedio.readDEM(dem); //this is not a big deal since it will be in the buffer
//create stations without measurements
for(size_t ii=0; ii<v_stations.size(); ii++) {
......
......@@ -199,7 +199,7 @@ class IOManager {
/**
* @brief Add a METEO_SET for a specific instance to the point cache. This is a way to manipulate
* MeteoData variables and be sure that the manipulated values are later used for requests
* MeteoData variables and be sure that the manipulated values are later used for requests
* regarding that specific date (e.g. 2D interpolations)
*
* @param i_date Representing a point in time
......@@ -209,7 +209,7 @@ class IOManager {
/**
* @brief Clear the point cache. All resampled values are dismissed, will need to be recalculated.
*/
*/
void clear_cache();
private:
......
......@@ -31,7 +31,9 @@ InterpolationAlgorithm* AlgorithmFactory::getAlgorithm(const std::string& i_algo
{
const std::string algoname( IOUtils::strToUpper(i_algoname) );
if (algoname == "CST"){// constant fill
if (algoname == "NONE"){// return a nodata grid
return new NoneAlgorithm(i_mi, i_vecArgs, i_algoname, iom);
} else if (algoname == "CST"){// constant fill
return new ConstAlgorithm(i_mi, i_vecArgs, i_algoname, iom);
} else if (algoname == "STD_PRESS"){// standard air pressure interpolation
return new StandardPressureAlgorithm(i_mi, i_vecArgs, i_algoname, iom);
......@@ -214,6 +216,16 @@ void InterpolationAlgorithm::retrend(const DEMObject& dem, const Fit1D& trend, G
/**********************************************************************************/
/* Implementation of the various algorithms */
/**********************************************************************************/
double NoneAlgorithm::getQualityRating(const Date& /*i_date*/, const MeteoData::Parameters& /*in_param*/)
{
return 1e-6;
}
void NoneAlgorithm::calculate(const DEMObject& dem, Grid2DObject& grid) {
grid.set(dem.ncols, dem.nrows, dem.cellsize, dem.llcorner, IOUtils::nodata);
}
double StandardPressureAlgorithm::getQualityRating(const Date& i_date, const MeteoData::Parameters& in_param)
{
date = i_date;
......@@ -233,6 +245,7 @@ void StandardPressureAlgorithm::calculate(const DEMObject& dem, Grid2DObject& gr
Interpol2D::stdPressure(dem, grid);
}
double ConstAlgorithm::getQualityRating(const Date& i_date, const MeteoData::Parameters& in_param)
{
date = i_date;
......@@ -254,6 +267,7 @@ void ConstAlgorithm::calculate(const DEMObject& dem, Grid2DObject& grid) {
Interpol2D::constant(Interpol1D::arithmeticMean(vecData), dem, grid);
}
double ConstLapseRateAlgorithm::getQualityRating(const Date& i_date, const MeteoData::Parameters& in_param)
{
date = i_date;
......@@ -293,6 +307,7 @@ void ConstLapseRateAlgorithm::calculate(const DEMObject& dem, Grid2DObject& grid
retrend(dem, trend, grid);
}
double IDWAlgorithm::getQualityRating(const Date& i_date, const MeteoData::Parameters& in_param)
{
date = i_date;
......@@ -315,6 +330,7 @@ void IDWAlgorithm::calculate(const DEMObject& dem, Grid2DObject& grid)
Interpol2D::IDW(vecData, vecMeta, dem, grid);
}
double IDWLapseAlgorithm::getQualityRating(const Date& i_date, const MeteoData::Parameters& in_param)
{
date = i_date;
......@@ -343,6 +359,7 @@ void IDWLapseAlgorithm::calculate(const DEMObject& dem, Grid2DObject& grid)
retrend(dem, trend, grid);
}
LocalIDWLapseAlgorithm::LocalIDWLapseAlgorithm(Meteo2DInterpolator& i_mi, const std::vector<std::string>& i_vecArgs,
const std::string& i_algo, IOManager& iom)
: InterpolationAlgorithm(i_mi, i_vecArgs, i_algo, iom), nrOfNeighbors(0)
......@@ -376,6 +393,7 @@ void LocalIDWLapseAlgorithm::calculate(const DEMObject& dem, Grid2DObject& grid)
info << "using nearest " << nrOfNeighbors << " neighbors";
}
double RHAlgorithm::getQualityRating(const Date& i_date, const MeteoData::Parameters& in_param)
{
//This algorithm is only valid for RH
......@@ -441,6 +459,7 @@ void RHAlgorithm::calculate(const DEMObject& dem, Grid2DObject& grid)
}
}
double ILWRAlgorithm::getQualityRating(const Date& i_date, const MeteoData::Parameters& in_param)
{
//This algorithm is only valid for ILWR
......@@ -494,6 +513,7 @@ void ILWRAlgorithm::calculate(const DEMObject& dem, Grid2DObject& grid)
}
}
double SimpleWindInterpolationAlgorithm::getQualityRating(const Date& i_date, const MeteoData::Parameters& in_param)
{
//This algorithm is only valid for VW
......@@ -544,6 +564,7 @@ void SimpleWindInterpolationAlgorithm::calculate(const DEMObject& dem, Grid2DObj
Interpol2D::SimpleDEMWindInterpolate(dem, grid, dw);
}
std::string USERInterpolation::getGridFileName() const
{
//HACK: use read2DGrid(grid, MeteoGrid::Parameters, Date) instead?
......@@ -589,6 +610,7 @@ void USERInterpolation::calculate(const DEMObject& dem, Grid2DObject& grid)
}
}
double SnowHNWInterpolation::getQualityRating(const Date& i_date, const MeteoData::Parameters& in_param)
{
date = i_date;
......@@ -640,6 +662,7 @@ void SnowHNWInterpolation::calculate(const DEMObject& dem, Grid2DObject& grid)
internal_dem.update();
}
void OrdinaryKrigingAlgorithm::getDataForVariogram(std::vector<double> &distData, std::vector<double> &variData)
{
distData.clear();
......@@ -709,6 +732,7 @@ void OrdinaryKrigingAlgorithm::calculate(const DEMObject& dem, Grid2DObject& gri
Interpol2D::ODKriging(vecData, vecMeta, dem, variogram, grid);
}
void LapseOrdinaryKrigingAlgorithm::calculate(const DEMObject& dem, Grid2DObject& grid)
{
info.clear(); info.str("");
......
......@@ -74,6 +74,7 @@ class Meteo2DInterpolator; // forward declaration, cyclic header include
*
* @section interpol2D_keywords Available algorithms
* The keywords defining the algorithms are the following:
* - NONE: returns a nodata filled grid (see NoneAlgorithm)
* - STD_PRESS: standard atmospheric pressure as a function of the elevation of each cell (see StandardPressureAlgorithm)
* - CST: constant value in each cell (see ConstAlgorithm)
* - CST_LAPSE: constant value reprojected to the elevation of the cell (see ConstLapseRateAlgorithm)
......@@ -178,6 +179,23 @@ class AlgorithmFactory {
const std::vector<std::string>& i_vecArgs, IOManager& iom);
};
/**
* @class NoneAlgorithm
* @brief Returns a nodata filled grid
* This allows to tolerate missing data, which can be usefull if an alternate strategy could
* later be used to generate the data (ie. a parametrization). This algorithm will only run
* after all others failed.
*/
class NoneAlgorithm : public InterpolationAlgorithm {
public:
NoneAlgorithm(Meteo2DInterpolator& i_mi,
const std::vector<std::string>& i_vecArgs,
const std::string& i_algo, IOManager& iom)
: InterpolationAlgorithm(i_mi, i_vecArgs, i_algo, iom) {}
virtual double getQualityRating(const Date& i_date, const MeteoData::Parameters& in_param);
virtual void calculate(const DEMObject& dem, Grid2DObject& grid);
};
/**
* @class ConstAlgorithm
* @brief Constant filling interpolation algorithm.
......
......@@ -141,15 +141,10 @@ void Meteo2DInterpolator::interpolate(const Date& date, const DEMObject& dem, co
//finally execute the algorithm with the best quality rating or throw an exception
if(maxQualityRating<=0.0)
throw IOException("No interpolation algorithm with quality rating >0 found for parameter "+param_name, AT);
throw IOException("No interpolation algorithm with quality rating >0 found for parameter "+param_name+" on "+date.toString(Date::ISO_TZ), AT);
vecAlgs[bestalgorithm]->calculate(dem, result);
InfoString = vecAlgs[bestalgorithm]->getInfo();
//check that the output grid is using the same projection as the dem
if(!result.llcorner.isSameProj(dem.llcorner)) {
throw IOException("The output grid is not using the same geographic projection as the DEM", AT);
}
//Run soft min/max filter for RH, HNW and HS
if (meteoparam == MeteoData::RH){
Meteo2DInterpolator::checkMinMax(0.0, 1.0, result);
......
......@@ -142,8 +142,9 @@ inline double Interpol2D::weightInvDistN(const double& d2)
* @param dem array of elevations (dem)
* @param grid 2D array to fill
*/
void Interpol2D::stdPressure(const DEMObject& dem, Grid2DObject& grid) {
grid.set(dem.ncols, dem.nrows, dem.cellsize, dem.llcorner);
void Interpol2D::stdPressure(const DEMObject& dem, Grid2DObject& grid)
{
grid.set(dem.ncols, dem.nrows, dem.cellsize, dem.llcorner);
//provide each point with an altitude dependant pressure... it is worth what it is...
for (size_t j=0; j<grid.nrows; j++) {
......
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