WSL/SLF GitLab Repository

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

The example io.ini file was missing some new changes. The Winstral algorithm...

The example io.ini file was missing some new changes. The Winstral algorithm had a bug when operating on dems with holes (nodata). It now takes its wind direction as argument (the base algorithm also has to be provided).
parent ddb34fd4
......@@ -178,9 +178,9 @@ ILWR::cst_lapse = -0.03125
RSWR::algorithms = IDW CST
[Generators]
ILWR::generators = AllSky CLearSky
ILWR::Allsky = Unsworth
ILWR::Clearsky = Dilley
ILWR::generators = AllSky_LW CLearSky_LW
ILWR::Allsky_LW = Unsworth
ILWR::Clearsky_LW = Dilley
RH::generators = CST
RH::Cst = 0.7
......
......@@ -579,6 +579,12 @@ double WinstralAlgorithm::getQualityRating(const Date& i_date, const MeteoData::
param = in_param;
nrOfMeasurments = getData(date, param, vecData, vecMeta);
if (vecArgs.size() == 2) { //fixed wind direction
IOUtils::convertString(synoptic_bearing, vecArgs[1]);
} else { //incorrect arguments, throw an exception
throw InvalidArgumentException("Please provide the wind direction to use for the "+algo+" algorithm", AT);
}
if (nrOfMeasurments==0)
return 0.0;
......@@ -591,7 +597,7 @@ void WinstralAlgorithm::initGrid(const DEMObject& dem, Grid2DObject& grid)
std::string base_algo;
if (vecArgs.empty()){
base_algo=std::string("IDW_LAPSE");
} else if (vecArgs.size() == 1){
} else if (vecArgs.size() <= 2){
IOUtils::convertString(base_algo, vecArgs[0]);
} else { //incorrect arguments, throw an exception
throw InvalidArgumentException("Wrong number of arguments supplied for the "+algo+" algorithm", AT);
......@@ -607,22 +613,48 @@ void WinstralAlgorithm::initGrid(const DEMObject& dem, Grid2DObject& grid)
info << algorithm->getInfo();
}
double WinstralAlgorithm::getSynopticBearing(const std::vector<MeteoData>& vecMeteo)
{
// 1) locate the stations in DEM and check if they are higher than their surroundings within a given radius
// 2) simply compute a mean or median direction
// (2) can be used on all the stations selected in (1)
double ve=0.0, vn=0.0;
size_t count=0;
for(size_t ii=0; ii<vecMeteo.size(); ii++) {
const double VW = vecMeteo[ii](MeteoData::VW);
const double DW = vecMeteo[ii](MeteoData::DW);
if(VW!=IOUtils::nodata && DW!=IOUtils::nodata) {
ve += VW * sin(DW*Cst::to_rad);
vn += VW * cos(DW*Cst::to_rad);
count++;
}
}
if(count!=0) {
ve /= static_cast<double>(count);
vn /= static_cast<double>(count);
//const double meanspeed = sqrt(ve*ve + vn*vn);
const double meandirection = fmod( atan2(ve,vn) * Cst::to_deg + 360., 360.);
return meandirection;
}
return IOUtils::nodata;
}
void WinstralAlgorithm::calculate(const DEMObject& dem, Grid2DObject& grid)
{
info.clear(); info.str("");
initGrid(dem, grid);
//get synoptic wind direction
const double synoptic_bearing = 315.; //HACK
//two options:
// 1) locate the stations in DEM and check if they are higher than their surroundings within a given radius
// 2) simply compute a mean or median direction
// (2) can be used on all the stations selected in (1)
//get synoptic wind direction. Three options:
// a) use a fixed wind direction b) use a user provided list of directions c) get it from the data
//look for
//synoptic_bearing = (vecMeteo);
//alter the field with Winstral and the chosen wind direction
Interpol2D::Winstral(dem, 300., synoptic_bearing, grid);
Interpol2D::Winstral(dem, 300., synoptic_bearing, grid); //HACK
}
......
......@@ -382,17 +382,26 @@ class SimpleWindInterpolationAlgorithm : public InterpolationAlgorithm {
* The DEM is used to compute wind exposure factors that are used to alter the precipitation fields.
* It is usually a good idea to provide a DEM that also contain the accumulated snow height in order
* to get a progrfessive softening of the terrain features.
* It takes two arguments: the base algorithm to generate the initial wind field and the
* synoptic wind direction.
* @code
* HNW::algorithms = WINSTRAL
* HNW::winstral = idw_lapse 180
* @endcode
*/
class WinstralAlgorithm : public InterpolationAlgorithm {
public:
WinstralAlgorithm(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) {}
: InterpolationAlgorithm(i_mi, i_vecArgs, i_algo, iom), synoptic_bearing(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);
static double getSynopticBearing(const std::vector<MeteoData>& vecMeteo);
double synoptic_bearing;
};
/**
......
......@@ -605,8 +605,7 @@ double Interpol2D::WinstralSX_core(const Grid2DObject& dem, const double& dmax,
size_t nb_cells = 0;
while( !(ll<0 || ll>ncols-1 || mm<0 || mm>nrows-1) ) {
const double altitude = dem(ll, mm);
if(altitude==mio::IOUtils::nodata) continue; //jump over nodata cells
if( !(ll==ii && mm==jj) ) {
if( (altitude!=mio::IOUtils::nodata) && !(ll==ii && mm==jj) ) {
//compute local sx
const double delta_elev = altitude - ref_altitude;
const double inv_distance = Optim::invSqrt( cellsize_sq*(Optim::pow2(ll-ii) + Optim::pow2(mm-jj)) );
......
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