Skip to content

Commit

Permalink
Merge commit '0c0bf6420695aecffa1b7752a2c3712330d9d6a9'
Browse files Browse the repository at this point in the history
  • Loading branch information
ftomei committed May 15, 2024
2 parents 54fd698 + 0c0bf64 commit 2340891
Show file tree
Hide file tree
Showing 34 changed files with 1,276 additions and 216 deletions.
1 change: 0 additions & 1 deletion agrolib/climate/climate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,6 @@ float loadFromMp_SaveOutput(Crit3DMeteoPoint* meteoPoint,
return percValue;
}


float loadHourlyVarSeries(QString *myError, Crit3DMeteoPointsDbHandler* meteoPointsDbHandler,
Crit3DMeteoGridDbHandler* meteoGridDbHandler, Crit3DMeteoPoint* meteoPoint, bool isMeteoGrid,
meteoVariable variable, QDateTime first, QDateTime last)
Expand Down
2 changes: 1 addition & 1 deletion agrolib/climate/climate.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@

float loadFromMp_SaveOutput(Crit3DMeteoPoint* meteoPoint,
meteoVariable variable, QDate first, QDate last, std::vector<float> &outputValues);

void setMpValues(Crit3DMeteoPoint meteoPointGet, Crit3DMeteoPoint* meteoPointSet, QDate myDate, meteoVariable myVar, Crit3DMeteoSettings* meteoSettings);
meteoComputation getMeteoCompFromString(std::map<std::string, meteoComputation> map, std::string value);

Expand Down
7 changes: 3 additions & 4 deletions agrolib/climate/crit3dPhenologyList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,13 @@ void Crit3DPhenologyList::eraseElement(unsigned int index)
{
_listScale.erase(_listScale.begin() + index);
}

}


bool Crit3DPhenologyList::addPhenology(unsigned int index)
{

QString dateStart = _listDateStart[index].toString("dd/MM/yyyy");
QString dateEnd = _listDateEnd[index].toString("dd/MM/yyyy");
QString dateStart = _listDateStart[index].toString("yyyy-MM-dd");
QString dateEnd = _listDateEnd[index].toString("yyyy-MM-dd");
QString computation;
QString variety;
QString scale;
Expand Down
12 changes: 6 additions & 6 deletions agrolib/commonDialogs/formTimePeriod.ui
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
</property>
<property name="dateTime">
<datetime>
<hour>23</hour>
<hour>22</hour>
<minute>0</minute>
<second>0</second>
<year>2013</year>
Expand All @@ -50,14 +50,14 @@
</property>
<property name="time">
<time>
<hour>23</hour>
<hour>22</hour>
<minute>0</minute>
<second>0</second>
</time>
</property>
<property name="minimumDateTime">
<datetime>
<hour>23</hour>
<hour>22</hour>
<minute>0</minute>
<second>0</second>
<year>1900</year>
Expand All @@ -66,7 +66,7 @@
</datetime>
</property>
<property name="displayFormat">
<string>dd/MM/yyyy HH.mm</string>
<string>yyyy-MM-dd HH.mm</string>
</property>
<property name="calendarPopup">
<bool>true</bool>
Expand All @@ -86,7 +86,7 @@
</property>
<property name="dateTime">
<datetime>
<hour>23</hour>
<hour>22</hour>
<minute>0</minute>
<second>0</second>
<year>2014</year>
Expand All @@ -102,7 +102,7 @@
</date>
</property>
<property name="displayFormat">
<string>dd/MM/yyyy HH.mm</string>
<string>yyyy-MM-dd HH.mm</string>
</property>
<property name="calendarPopup">
<bool>true</bool>
Expand Down
184 changes: 160 additions & 24 deletions agrolib/interpolation/interpolation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1360,12 +1360,138 @@ bool proxyValidity(std::vector <Crit3DInterpolationDataPoint> &myPoints, int pro
return true;
}

bool setAllFittingRanges(Crit3DProxyCombination myCombination, Crit3DInterpolationSettings* mySettings)
{
if (mySettings->getMinMaxTemperature().empty())
return 0;

for (unsigned i=0; i < myCombination.getProxySize(); i++)
if (myCombination.isProxyActive(i) == true)
{
if (getProxyPragaName(mySettings->getProxy(i)->getName()) == proxyHeight)
{
double min = mySettings->getMinMaxTemperature()[0];
double max = mySettings->getMinMaxTemperature()[1];
std::vector <double> tempParam;
if (mySettings->getChosenElevationFunction() == frei)
{
mySettings->getProxy(i)->setFittingFunctionName(frei);
if (!(mySettings->getProxy(i)->getFittingParametersRange().empty()))
tempParam = {min, 0, -4, -200, 0.1, max+10, 0.006, 4, 1800, 1000};
}
else if (mySettings->getChosenElevationFunction() == piecewiseTwo)
{
mySettings->getProxy(i)->setFittingFunctionName(piecewiseTwo);
if (!(mySettings->getProxy(i)->getFittingParametersRange().empty()))
tempParam = {-200, min-2, 0, -0.006, 1800, max+2, 0.01, 0};
}
else if (mySettings->getChosenElevationFunction() == piecewiseThree)
{
mySettings->getProxy(i)->setFittingFunctionName(piecewiseThree);
if (!(mySettings->getProxy(i)->getFittingParametersRange().empty()))
tempParam = {-200, min-2, 100, 0, -0.006, 1800, max+2, 1000, (max-min-2), 0};
}
else if (mySettings->getChosenElevationFunction() == piecewiseThreeFree)
{
mySettings->getProxy(i)->setFittingFunctionName(piecewiseThreeFree);
if (!(mySettings->getProxy(i)->getFittingParametersRange().empty()))
tempParam = {-200, min-2, 100, 0.001, -0.006, -0.006, 1800, max+2, 1000, 0.007, 0, 0};
}
else if (mySettings->getChosenElevationFunction() == piecewiseThreeSlope)
{
mySettings->getProxy(i)->setFittingFunctionName(piecewiseThreeSlope);
if (!(mySettings->getProxy(i)->getFittingParametersRange().empty()))
tempParam = {-200, min-2, 100, 0.001, -0.006, 1800, max+2, 1000, 0.007, 0};
}
else if (mySettings->getChosenElevationFunction() == freiFree)
{
mySettings->getProxy(i)->setFittingFunctionName(freiFree);
if (!(mySettings->getProxy(i)->getFittingParametersRange().empty()))
tempParam = {min, 0, -4, -200, 0.1, 0, max+10, 0.006, 4, 1800, 1000, 0.006};
}
mySettings->getProxy(i)->setFittingParametersRange(tempParam);
}
else
{
mySettings->getProxy(i)->setFittingFunctionName(linear);
mySettings->getProxy(i)->setFittingParametersRange({0,100});
}
}
return 1;
}

bool setAllFittingParameters_noRange(Crit3DProxyCombination myCombination, Crit3DInterpolationSettings* mySettings,
std::vector<std::function<double(double, std::vector<double>&)>>& myFunc,
std::vector <std::vector<double>> &paramMin, std::vector <std::vector<double>> &paramMax,
std::vector <std::vector<double>> &paramDelta, std::vector <std::vector<double>> &paramFirstGuess,
std::string &errorStr)
{
const double RATIO_DELTA = 1000;
bool isPreviousParam = !paramFirstGuess.empty();

for (unsigned i=0; i < myCombination.getProxySize(); i++)
if (mySettings->getProxy(i)->getIsSignificant())
{
if (getProxyPragaName(mySettings->getProxy(i)->getName()) == proxyHeight)
{
if (mySettings->getChosenElevationFunction() == frei)
myFunc.push_back(lapseRateFrei);
else if (mySettings->getChosenElevationFunction() == piecewiseTwo)
myFunc.push_back(lapseRatePiecewise_two);
else if (mySettings->getChosenElevationFunction() == piecewiseThree)
myFunc.push_back(lapseRatePiecewiseForInterpolation);
else if (mySettings->getChosenElevationFunction() == piecewiseThreeFree)
myFunc.push_back(lapseRatePiecewiseFree);
else if (mySettings->getChosenElevationFunction() == piecewiseThreeSlope)
myFunc.push_back(lapseRatePiecewiseThree_withSlope);
else if (mySettings->getChosenElevationFunction() == freiFree)
myFunc.push_back(lapseRateFreiFree);
}
else
{
myFunc.push_back(functionLinear);
}

std::vector <double> myParam = mySettings->getProxy(i)->getFittingParametersRange();
unsigned int nrParam = unsigned(myParam.size() / 2);

if (nrParam == 0)
{
errorStr = "Missing fitting parameters for proxy: " + mySettings->getProxy(i)->getName();
return false;
}

double min_,max_;
std::vector <double> proxyParamMin;
std::vector <double> proxyParamMax;
std::vector <double> proxyParamDelta;
std::vector <double> proxyParamFirstGuess;

for (unsigned j=0; j < nrParam; j++)
{
min_ = myParam[j];
max_ = myParam[nrParam+j];
proxyParamMin.push_back(min_);
proxyParamMax.push_back(max_);
proxyParamDelta.push_back((max_ - min_) / RATIO_DELTA);
proxyParamFirstGuess.push_back((max_ - min_) / 2);
}

paramMin.push_back(proxyParamMin);
paramMax.push_back(proxyParamMax);
paramDelta.push_back(proxyParamDelta);
if (!isPreviousParam)
paramFirstGuess.push_back(proxyParamFirstGuess);
}

return myFunc.size() > 0;
}

bool setAllFittingParameters(Crit3DProxyCombination myCombination, Crit3DInterpolationSettings* mySettings,
std::vector<std::function<double(double, std::vector<double>&)>>& myFunc,
std::vector <std::vector<double>> &paramMin, std::vector <std::vector<double>> &paramMax,
std::vector <std::vector<double>> &paramDelta, std::vector <std::vector<double>> &paramFirstGuess,
std::string &errorStr)
std::vector<std::function<double(double, std::vector<double>&)>>& myFunc,
std::vector <std::vector<double>> &paramMin, std::vector <std::vector<double>> &paramMax,
std::vector <std::vector<double>> &paramDelta, std::vector <std::vector<double>> &paramFirstGuess,
std::string &errorStr)
{
const double RATIO_DELTA = 1000;
bool isPreviousParam = !paramFirstGuess.empty();
Expand All @@ -1375,42 +1501,52 @@ bool setAllFittingParameters(Crit3DProxyCombination myCombination, Crit3DInterpo
{
if (getProxyPragaName(mySettings->getProxy(i)->getName()) == proxyHeight)
{
double min = mySettings->getMinMaxTemperature()[0];
double max = mySettings->getMinMaxTemperature()[1];
std::vector <double> tempParam;
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);
}
tempParam = {min, 0, -10, -200, 0.1, max+10, 0.006, 10, 1800, 1000};
}
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);
}
tempParam = {-200, min-2, 0, -0.006, 1800, max+2, 0.01, 0};
}
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);
}
tempParam = {-200, min-2, 100, 0, -0.006, 1800, max+2, 1000, (max-min-2), 0};
}
else if (mySettings->getChosenElevationFunction() == piecewiseThreeFree)
{
myFunc.push_back(lapseRatePiecewiseFree);
mySettings->getProxy(i)->setFittingFunctionName(piecewiseThreeFree);
if (!(mySettings->getProxy(i)->getFittingParametersRange().empty()))
tempParam = {-200, min-2, 100, 0.001, -0.006, -0.006, 1800, max+2, 1000, 0.01, 0, 0};
}
else if (mySettings->getChosenElevationFunction() == piecewiseThreeSlope)
{
myFunc.push_back(lapseRatePiecewiseThree_withSlope);
mySettings->getProxy(i)->setFittingFunctionName(piecewiseThreeSlope);
if (!(mySettings->getProxy(i)->getFittingParametersRange().empty()))
tempParam = {-200, min-2, 100, 0.002, -0.006, 1800, max+2, 1000, 0.01, 0};
}
else if (mySettings->getChosenElevationFunction() == freiFree)
{
myFunc.push_back(lapseRateFreiFree);
mySettings->getProxy(i)->setFittingFunctionName(freiFree);
if (!(mySettings->getProxy(i)->getFittingParametersRange().empty()))
tempParam = {min, 0, -4, -200, 0.1, 0, max+10, 0.006, 4, 1800, 1000, 0.006};
}
mySettings->getProxy(i)->setFittingParametersRange(tempParam);
}
else
{
Expand Down Expand Up @@ -1609,14 +1745,14 @@ bool multipleDetrending(std::vector <Crit3DInterpolationDataPoint> &myPoints,
//std::vector <std::vector<double>> parameters;
std::vector<std::function<double(double, std::vector<double>&)>> myFunc;

if (! setAllFittingParameters(myCombination, mySettings, myFunc, parametersMin, parametersMax,
if (! setAllFittingParameters_noRange(myCombination, mySettings, myFunc, parametersMin, parametersMax,
parametersDelta, parameters, errorStr))
{
return false;
}

// multiple non linear fitting
interpolation::bestFittingMarquardt_nDimension(&functionSum, myFunc, 100, 4, parametersMin, parametersMax, parameters, parametersDelta,
interpolation::bestFittingMarquardt_nDimension(&functionSum, myFunc, 30, 4, parametersMin, parametersMax, parameters, parametersDelta,
80, 0.005, 0.002, predictors, predictands, weights);

mySettings->setFittingFunction(myFunc);
Expand Down
8 changes: 8 additions & 0 deletions agrolib/interpolation/interpolation.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@
bool proxyValidity(std::vector <Crit3DInterpolationDataPoint> &myPoints, int proxyPos,
float stdDevThreshold, double &avg, double &stdDev);

bool setAllFittingRanges(Crit3DProxyCombination myCombination, Crit3DInterpolationSettings* mySettings);

bool setAllFittingParameters_noRange(Crit3DProxyCombination myCombination, Crit3DInterpolationSettings* mySettings,
std::vector<std::function<double(double, std::vector<double>&)>>& myFunc,
std::vector <std::vector<double>> &paramMin, std::vector <std::vector<double>> &paramMax,
std::vector <std::vector<double>> &paramDelta, std::vector <std::vector<double>> &paramFirstGuess,
std::string &errorStr);

bool setAllFittingParameters(Crit3DProxyCombination myCombination, Crit3DInterpolationSettings* mySettings,
std::vector<std::function<double(double, std::vector<double>&)>>& myFunc,
std::vector <std::vector<double>> &paramMin, std::vector <std::vector<double>> &paramMax,
Expand Down
7 changes: 5 additions & 2 deletions agrolib/interpolation/interpolationConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,15 @@
{ "water_index", proxyWaterIndex}
};

enum TFittingFunction { piecewiseTwo, piecewiseThree, frei, linear, noFunction };
enum TFittingFunction { piecewiseTwo, piecewiseThree, piecewiseThreeFree, piecewiseThreeSlope, frei, freiFree, linear, noFunction };

const std::map<std::string, TFittingFunction> fittingFunctionNames = {
{ "Double piecewise", piecewiseTwo },
{ "Triple piecewise", piecewiseThree },
{ "Nonlinear Frei function", frei },
{ "Triple piecewise (6 parameters)", piecewiseThreeFree},
{ "Triple piecewise (5 parameters)", piecewiseThreeSlope},
{ "Nonlinear Frei function (5 parameters)", frei },
{ "Nonlinear Frei function (6 parameters)", freiFree},
{ "linear", linear }
};

Expand Down
Loading

0 comments on commit 2340891

Please sign in to comment.