Skip to content

Commit

Permalink
Merge commit '262f590f6240637fa314fd8a1d9c2cbfa0a6593b'
Browse files Browse the repository at this point in the history
  • Loading branch information
ftomei committed May 8, 2024
2 parents 6027909 + 262f590 commit a0f56c0
Show file tree
Hide file tree
Showing 20 changed files with 390 additions and 193 deletions.
42 changes: 41 additions & 1 deletion agrolib/interpolation/interpolation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1374,9 +1374,49 @@ bool setAllFittingParameters(Crit3DProxyCombination myCombination, Crit3DInterpo
if (mySettings->getProxy(i)->getIsSignificant())
{
if (getProxyPragaName(mySettings->getProxy(i)->getName()) == proxyHeight)
myFunc.push_back(lapseRatePiecewiseForInterpolation);
{
if (mySettings->getChosenElevationFunction() == frei)
{
myFunc.push_back(lapseRateFrei);
mySettings->getProxy(i)->setFittingFunctionName(frei);
if (!(mySettings->getProxy(i)->getFittingParametersRange().empty()))
{
double min = mySettings->getProxy(i)->getMinMaxTemperature(0);
double max = mySettings->getProxy(i)->getMinMaxTemperature(1);
std::vector <double> tempParam = {min, 0, -10, -200, 0.1, max+10, 0.006, 10, 1800, 1000};
mySettings->getProxy(i)->setFittingParametersRange(tempParam);
}
}
else if (mySettings->getChosenElevationFunction() == piecewiseTwo)
{
myFunc.push_back(lapseRatePiecewise_two);
mySettings->getProxy(i)->setFittingFunctionName(piecewiseTwo);
if (!(mySettings->getProxy(i)->getFittingParametersRange().empty()))
{
double min = mySettings->getProxy(i)->getMinMaxTemperature(0);
double max = mySettings->getProxy(i)->getMinMaxTemperature(1);
std::vector <double> tempParam = {-200, min-2, 0, -0.006, 1800, max+2, 0.01, 0};
mySettings->getProxy(i)->setFittingParametersRange(tempParam);
}
}
else if (mySettings->getChosenElevationFunction() == piecewiseThree)
{
myFunc.push_back(lapseRatePiecewiseForInterpolation);
mySettings->getProxy(i)->setFittingFunctionName(piecewiseThree);
if (!(mySettings->getProxy(i)->getFittingParametersRange().empty()))
{
double min = mySettings->getProxy(i)->getMinMaxTemperature(0);
double max = mySettings->getProxy(i)->getMinMaxTemperature(1);
std::vector <double> tempParam = {-200, min-2, 100, 0, -0.006, 1800, max+2, 1000, (max-min-2), 0};
mySettings->getProxy(i)->setFittingParametersRange(tempParam);
}
}
}
else
{
myFunc.push_back(functionLinear);
mySettings->getProxy(i)->setFittingFunctionName(linear);
}

std::vector <double> myParam = mySettings->getProxy(i)->getFittingParametersRange();
unsigned int nrParam = unsigned(myParam.size() / 2);
Expand Down
9 changes: 9 additions & 0 deletions agrolib/interpolation/interpolationConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@
{ "water_index", proxyWaterIndex}
};

enum TFittingFunction { piecewiseTwo, piecewiseThree, frei, linear, noFunction };

const std::map<std::string, TFittingFunction> fittingFunctionNames = {
{ "Double piecewise", piecewiseTwo },
{ "Triple piecewise", piecewiseThree },
{ "Nonlinear Frei function", frei },
{ "linear", linear }
};


enum TkrigingMode {KRIGING_SPHERICAL = 1,
KRIGING_EXPONENTIAL=2,
Expand Down
55 changes: 55 additions & 0 deletions agrolib/interpolation/interpolationSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,16 @@ void Crit3DInterpolationSettings::setFittingFunction(const std::vector<std::func
fittingFunction = newFittingFunction;
}

TFittingFunction Crit3DInterpolationSettings::getChosenElevationFunction()
{
return chosenElevationFunction;
}

void Crit3DInterpolationSettings::setChosenElevationFunction(TFittingFunction chosenFunction)
{
chosenElevationFunction = chosenFunction;
}

void Crit3DInterpolationSettings::clearFitting()
{
fittingFunction.clear();
Expand Down Expand Up @@ -345,6 +355,7 @@ void Crit3DInterpolationSettings::initialize()
meteoGridAggrMethod = aggrAverage;
meteoGridUpscaleFromDem = true;
indexHeight = unsigned(NODATA);
chosenElevationFunction = frei;

isKrigingReady = false;
precipitationAllZero = false;
Expand Down Expand Up @@ -375,6 +386,22 @@ std::string getKeyStringInterpolationMethod(TInterpolationMethod value)
return key;
}

std::string getKeyStringElevationFunction(TFittingFunction value)
{
std::map<std::string, TFittingFunction>::const_iterator it;
std::string key = "";

for (it = fittingFunctionNames.begin(); it != fittingFunctionNames.end(); ++it)
{
if (it->second == value)
{
key = it->first;
break;
}
}
return key;
}

TInterpolationMethod Crit3DInterpolationSettings::getInterpolationMethod()
{ return interpolationMethod;}

Expand Down Expand Up @@ -573,9 +600,36 @@ std::vector<double> Crit3DProxy::getFittingParametersRange() const

void Crit3DProxy::setFittingParametersRange(const std::vector<double> &newFittingParametersRange)
{
fittingParametersRange.clear();
fittingParametersRange = newFittingParametersRange;
}

void Crit3DProxy::setFittingFunctionName(TFittingFunction functionName)
{
fittingFunctionName = functionName;
return;
}

TFittingFunction Crit3DProxy::getFittingFunctionName()
{
return fittingFunctionName;
}

void Crit3DProxy::setMinMaxTemperature(double min, double max)
{
tempMinMax.clear();
tempMinMax.push_back(min);
tempMinMax.push_back(max);
}

double Crit3DProxy::getMinMaxTemperature(int i)
{
if (tempMinMax.empty())
return NODATA;

return tempMinMax[i];
}

Crit3DProxy::Crit3DProxy()
{
name = "";
Expand All @@ -592,6 +646,7 @@ Crit3DProxy::Crit3DProxy()
lapseRateT1 = NODATA;
inversionLapseRate = NODATA;
inversionIsSignificative = false;
tempMinMax;

avg = NODATA;
stdDev = NODATA;
Expand Down
11 changes: 11 additions & 0 deletions agrolib/interpolation/interpolationSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <deque>

std::string getKeyStringInterpolationMethod(TInterpolationMethod value);
std::string getKeyStringElevationFunction(TFittingFunction value);
TProxyVar getProxyPragaName(std::string name_);

class Crit3DProxy
Expand All @@ -34,7 +35,9 @@
float regressionR2;
float regressionSlope;
float regressionIntercept;
TFittingFunction fittingFunctionName;
std::vector <double> fittingParametersRange;
std::vector <double> tempMinMax;

float avg;
float stdDev;
Expand Down Expand Up @@ -96,6 +99,10 @@
void setStdDevThreshold(float newStdDevThreshold);
std::vector<double> getFittingParametersRange() const;
void setFittingParametersRange(const std::vector<double> &newFittingParametersRange);
TFittingFunction getFittingFunctionName();
void setFittingFunctionName(TFittingFunction functionName);
void setMinMaxTemperature(double min, double max);
double getMinMaxTemperature (int i);
};


Expand Down Expand Up @@ -126,6 +133,7 @@
gis::Crit3DRasterGrid* currentDEM; //for TD

TInterpolationMethod interpolationMethod;
TFittingFunction chosenElevationFunction;

float minRegressionR2;
bool useThermalInversion;
Expand Down Expand Up @@ -162,6 +170,7 @@
std::vector <std::vector<double>> fittingParameters;
std::vector<std::function<double(double, std::vector<double>&)>> fittingFunction;


public:
Crit3DInterpolationSettings();

Expand Down Expand Up @@ -251,6 +260,8 @@
bool getProxiesComplete() const;
void setProxiesComplete(bool newProxiesComplete);
void clearFitting();
TFittingFunction getChosenElevationFunction();
void setChosenElevationFunction(TFittingFunction chosenFunction);
};

#endif // INTERPOLATIONSETTINGS_H
32 changes: 8 additions & 24 deletions agrolib/mathFunctions/furtherMathFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ double lapseRateFrei(double x, std::vector <double>& par)
par[1] = gamma;
par[2] = a;
par[3] = h0;
par[4] = h1;
par[4] = h1-h0;
*/

if (par.size() < 4) return NODATA;
Expand All @@ -62,11 +62,11 @@ double lapseRateFrei(double x, std::vector <double>& par)
{
return y - par[2];
}
else if (x >= par[4])
else if (x >= (par[4]+par[3]))
{
return y;
}
return y - 0.5*par[2]*(1 + cos(PI*(x-par[3])/(par[4]-par[3])));
return y - 0.5*par[2]*(1 + cos(PI*(x-par[3])/(par[4])));
}

double lapseRatePiecewise_three(double x, std::vector <double>& par)
Expand Down Expand Up @@ -100,7 +100,7 @@ double lapseRatePiecewise_three(double x, std::vector <double>& par)
double lapseRatePiecewiseForInterpolation(double x, std::vector <double>& par)
{
// the piecewise line is parameterized as follows
// the line passes through A(par[0];par[1])and B(par[0]+par[2];par[3]). par[4] is the slope of the 2 externals pieces
// the line passes through A(par[0];par[1])and B(par[0]+par[2];par[1]+par[3]). par[4] is the slope of the 2 externals pieces
// "y = mx + q" piecewise function;
double xb;
par[2] = MAXVALUE(10, par[2]);
Expand All @@ -115,14 +115,14 @@ double lapseRatePiecewiseForInterpolation(double x, std::vector <double>& par)
else if (x>xb)
{
//m = par[4];
//q = par[3]-m*xb;
return par[4]*x + par[3]-par[4]*xb;
//q = (par[1]+par[3])-m*xb;
return par[4]*x + (par[1]+par[3])-par[4]*xb;
}
else
{
//m = (par[3]-par[1])/par[2];
//m = ((par[1]+par[3])-par[1])/par[2];
//q = par[1]-m*par[0];
return ((par[3]-par[1])/par[2])*x+ par[1]-(par[3]-par[1])/par[2]*par[0];
return (par[3]/par[2])*x + par[1]-(par[3])/par[2]*par[0];
}
}

Expand Down Expand Up @@ -1127,22 +1127,6 @@ namespace interpolation
parameters, parametersDelta,correspondenceTag, maxIterationsNr,
myEpsilon, x, y, weights);

//SOLO PER ALTEZZA
if (parameters[0][3] < parameters[0][1])
{
for (i=0; i<nrPredictors; i++)
{
for (j=0; j<nrParameters[i]; j++)
{
do {
truncNormal = normal_dis(gen);
} while(truncNormal <= 0.0 || truncNormal >= 1.0);
parameters[i][j] = parametersMin[i][j] + (truncNormal)*(parametersMax[i][j]-parametersMin[i][j]);
}
}
continue;
}

for (i=0;i<nrData;i++)
{
ySim[i]= func(myFunc,x[i], parameters);
Expand Down
64 changes: 4 additions & 60 deletions agrolib/meteo/quality.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,80 +23,22 @@
[email protected]
*/


#include "commonConstants.h"
#include "basicMath.h"
#include "quality.h"
#include "meteoPoint.h"

namespace quality
{
Range::Range()
{
min = NODATA;
max = NODATA;
}

Range::Range(float myMin, float myMax)
{
min = myMin;
max = myMax;
}

float Range::getMin() { return min; }

float Range::getMax() { return max; }
}


float Crit3DQuality::getReferenceHeight() const
{
return referenceHeight;
}

void Crit3DQuality::setReferenceHeight(float value)
{
referenceHeight = value;
}

float Crit3DQuality::getDeltaTSuspect() const
{
return deltaTSuspect;
}

void Crit3DQuality::setDeltaTSuspect(float value)
{
deltaTSuspect = value;
}

float Crit3DQuality::getDeltaTWrong() const
{
return deltaTWrong;
}

void Crit3DQuality::setDeltaTWrong(float value)
{
deltaTWrong = value;
}

float Crit3DQuality::getRelHumTolerance() const
{
return relHumTolerance;
}

void Crit3DQuality::setRelHumTolerance(float value)
{
relHumTolerance = value;
}

void Crit3DQuality::initialize()
{
referenceHeight = DEF_VALUE_REF_HEIGHT;
deltaTSuspect = DEF_VALUE_DELTA_T_SUSP;
deltaTWrong = DEF_VALUE_DELTA_T_WRONG;
relHumTolerance = DEF_VALUE_REL_HUM_TOLERANCE;
waterTableMaximumDepth = DEF_VALUE_WATERTABLE_MAX_DEPTH;
}


Crit3DQuality::Crit3DQuality()
{
qualityHourlyT = new quality::Range(-60, 60);
Expand All @@ -122,6 +64,7 @@ Crit3DQuality::Crit3DQuality()
initialize();
}


Crit3DQuality::~Crit3DQuality()
{
delete qualityHourlyT;
Expand All @@ -145,6 +88,7 @@ Crit3DQuality::~Crit3DQuality()
delete qualityDailyET0;
}


quality::Range* Crit3DQuality::getQualityRange(meteoVariable myVar)
{
// hourly
Expand Down
Loading

0 comments on commit a0f56c0

Please sign in to comment.