Skip to content

Commit

Permalink
glocal detrending with buffer areas
Browse files Browse the repository at this point in the history
  • Loading branch information
cate-to committed Oct 28, 2024
1 parent dcf4eaf commit cbab5e0
Show file tree
Hide file tree
Showing 10 changed files with 163 additions and 47 deletions.
16 changes: 12 additions & 4 deletions agrolib/interpolation/interpolation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1723,7 +1723,7 @@ bool multipleDetrendingMain(std::vector <Crit3DInterpolationDataPoint> &myPoints

if (elevationPos != NODATA && mySettings->getCurrentCombination().isProxyActive(elevationPos))
{
if (!multipleDetrendingElevationFitting(elevationPos, myPoints, mySettings, myVar, errorStr))
if (!multipleDetrendingElevationFitting(elevationPos, myPoints, mySettings, myVar, errorStr, true))
return false;

detrendingElevation(elevationPos, myPoints, mySettings);
Expand All @@ -1739,7 +1739,7 @@ bool multipleDetrendingMain(std::vector <Crit3DInterpolationDataPoint> &myPoints
}

bool multipleDetrendingElevationFitting(int elevationPos, std::vector <Crit3DInterpolationDataPoint> &myPoints,
Crit3DInterpolationSettings* mySettings, meteoVariable myVar, std::string &errorStr)
Crit3DInterpolationSettings* mySettings, meteoVariable myVar, std::string &errorStr, bool isWeighted)
{
mySettings->getProxy(elevationPos)->setRegressionR2(NODATA);
if (! getUseDetrendingVar(myVar)) return true;
Expand Down Expand Up @@ -1799,8 +1799,13 @@ bool multipleDetrendingElevationFitting(int elevationPos, std::vector <Crit3DInt

std::vector<std::vector<double>> firstGuessCombinations = mySettings->getProxy(elevationPos)->getFirstGuessCombinations();
// multiple non linear fitting
double R2 = interpolation::bestFittingMarquardt_nDimension_singleFunction(*(myFunc.target<double(*)(double, std::vector<double>&)>()), 400, 4, parametersMin, parametersMax, parameters, parametersDelta,
double R2 = NODATA;
if (isWeighted)
R2 = interpolation::bestFittingMarquardt_nDimension_singleFunction(*(myFunc.target<double(*)(double, std::vector<double>&)>()), 400, 4, parametersMin, parametersMax, parameters, parametersDelta,
stepSize, numSteps, 1000, 0.002, 0.005, predictors, predictands, weights,firstGuessCombinations);
else
R2 = interpolation::bestFittingMarquardt_nDimension_singleFunction(*(myFunc.target<double(*)(double, std::vector<double>&)>()), 400, 4, parametersMin, parametersMax, parameters, parametersDelta,
stepSize, numSteps, 1000, 0.002, 0.005, predictors, predictands,firstGuessCombinations);

mySettings->getProxy(elevationPos)->setRegressionR2(R2);

Expand Down Expand Up @@ -2088,15 +2093,18 @@ bool glocalDetrendingFitting(std::vector <Crit3DInterpolationDataPoint> &myPoint

for (int k = 0; k < myPoints.size(); k++)
if (myPoints[k].index == temp[l])
{
subsetPoints.push_back(myPoints[k]);
break;
}
}

mySettings->setCurrentCombination(mySettings->getSelectedCombination());
mySettings->clearFitting();

if (elevationPos != NODATA && mySettings->getCurrentCombination().isProxyActive(elevationPos))
{
if (!multipleDetrendingElevationFitting(elevationPos, subsetPoints, mySettings, myVar, errorStr)) return false;
if (!multipleDetrendingElevationFitting(elevationPos, subsetPoints, mySettings, myVar, errorStr, false)) return false;

detrendingElevation(elevationPos, subsetPoints, mySettings);

Expand Down
2 changes: 1 addition & 1 deletion agrolib/interpolation/interpolation.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
meteoVariable myVar, std::string &errorStr);

bool multipleDetrendingElevationFitting(int elevationPos, std::vector <Crit3DInterpolationDataPoint> &myPoints,
Crit3DInterpolationSettings* mySettings, meteoVariable myVar, std::string &errorStr);
Crit3DInterpolationSettings* mySettings, meteoVariable myVar, std::string &errorStr, bool isWeighted);

void detrendingElevation(int elevationPos, std::vector <Crit3DInterpolationDataPoint> &myPoints, Crit3DInterpolationSettings* mySettings);

Expand Down
4 changes: 2 additions & 2 deletions agrolib/interpolation/interpolationSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1039,13 +1039,13 @@ std::vector<int> Crit3DMacroArea::getMeteoPoints()
return meteoPoints;
}

void Crit3DMacroArea::setAreaCells (std::vector<int> myCells)
void Crit3DMacroArea::setAreaCells (std::vector<float> myCells)
{
areaCells = myCells;
return;
}

std::vector<int> Crit3DMacroArea::getAreaCells()
std::vector<float> Crit3DMacroArea::getAreaCells()
{
return areaCells;
}
Expand Down
6 changes: 3 additions & 3 deletions agrolib/interpolation/interpolationSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
Crit3DProxyCombination areaCombination;
std::vector<std::vector<float>> areaParameters;
std::vector<int> meteoPoints;
std::vector<int> areaCells;
std::vector<float> areaCells;

public:
Crit3DMacroArea();
Expand All @@ -149,8 +149,8 @@
std::vector<std::vector<float>> getParameters();
void setCombination (Crit3DProxyCombination myCombination);
Crit3DProxyCombination getCombination();
void setAreaCells (std::vector<int> myCells);
std::vector<int> getAreaCells();
void setAreaCells (std::vector<float> myCells);
std::vector<float> getAreaCells();
void clear();

};
Expand Down
7 changes: 0 additions & 7 deletions agrolib/pragaProject/pragaProject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2636,13 +2636,6 @@ bool PragaProject::interpolationMeteoGridPeriod(QDate dateIni, QDate dateFin, QL
return false;
}

if (interpolationSettings.getUseGlocalDetrending())
{
logInfoGUI("Loading macro areas map for glocal detrending...");
if (loadGlocalFiles() < 1)
return false;
}

// save also time aggregated variables
foreach (myVar, aggrVariables)
varToSave.push_back(myVar);
Expand Down
Loading

0 comments on commit cbab5e0

Please sign in to comment.