Skip to content

Commit

Permalink
Merge commit '66a8e5eb64b827dcfd2c23f664dc41ff6f293b57'
Browse files Browse the repository at this point in the history
  • Loading branch information
ftomei committed Sep 12, 2024
2 parents c30d383 + 66a8e5e commit cec709d
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 24 deletions.
2 changes: 1 addition & 1 deletion agrolib/criteriaOutput/criteriaOutputProject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ int CriteriaOutputProject::initializeProject(const QString &settingsFileName, co
return ERROR_SETTINGS_WRONGFILENAME;
}

if (!readSettings())
if (! readSettings())
{
projectError = "Read settings: " + projectError;
return ERROR_SETTINGS_MISSINGDATA;
Expand Down
2 changes: 2 additions & 0 deletions agrolib/dbMeteoGrid/dbMeteoGrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3062,6 +3062,7 @@ bool Crit3DMeteoGridDbHandler::saveListHourlyData(QString *errorStr, QString met
return true;
}


bool Crit3DMeteoGridDbHandler::saveListDailyData(QString *errorStr, QString meteoPointID, QDate firstDate, meteoVariable meteoVar, QList<float> values, bool reverseOrder)
{
QSqlQuery qry(_db);
Expand Down Expand Up @@ -3111,6 +3112,7 @@ bool Crit3DMeteoGridDbHandler::saveListDailyData(QString *errorStr, QString mete
return false;
}
}

return true;
}

Expand Down
12 changes: 7 additions & 5 deletions agrolib/interpolation/interpolation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1458,11 +1458,13 @@ bool proxyValidityWeighted(std::vector <Crit3DInterpolationDataPoint> &myPoints,
return true;
}

bool setHeightTemperatureRange(Crit3DProxyCombination myCombination, Crit3DInterpolationSettings* mySettings)
bool setMultipleDetrendingHeightTemperatureRange(Crit3DInterpolationSettings* mySettings)
{
if (mySettings->getPointsRange().empty() || !mySettings->getUseMultipleDetrending())
return 0;

Crit3DProxyCombination myCombination = mySettings->getSelectedCombination();

for (unsigned i=0; i < myCombination.getProxySize(); i++)
if (myCombination.isProxyActive(i) == true)
{
Expand All @@ -1478,19 +1480,19 @@ bool setHeightTemperatureRange(Crit3DProxyCombination myCombination, Crit3DInter
if (mySettings->getChosenElevationFunction() == piecewiseTwo)
{
tempParam[1] = MIN_T-2;
tempParam[5] = MAX_T+2;
tempParam[5] = MAX_T+6;
mySettings->addFittingFunction(lapseRatePiecewise_two);
}
else if (mySettings->getChosenElevationFunction() == piecewiseThreeFree)
{
tempParam[1] = MIN_T-2;
tempParam[7] = MAX_T+2;
tempParam[7] = MAX_T+6;
mySettings->addFittingFunction(lapseRatePiecewise_three_free);
}
else if (mySettings->getChosenElevationFunction() == piecewiseThree)
{
tempParam[1] = MIN_T-2;
tempParam[6] = MAX_T+2;
tempParam[6] = MAX_T+6;
mySettings->addFittingFunction(lapseRatePiecewise_three);
}
mySettings->getProxy(i)->setFittingParametersRange(tempParam);
Expand Down Expand Up @@ -2155,7 +2157,7 @@ bool preInterpolation(std::vector <Crit3DInterpolationDataPoint> &myPoints, Crit
if (mySettings->getUseMultipleDetrending())
{
if (!mySettings->getUseLocalDetrending())
setHeightTemperatureRange(mySettings->getSelectedCombination(), mySettings);
setMultipleDetrendingHeightTemperatureRange(mySettings);

if (! multipleDetrendingMain(myPoints, mySettings, myVar, errorStr)) return false;
}
Expand Down
2 changes: 1 addition & 1 deletion agrolib/interpolation/interpolation.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
bool proxyValidityWeighted(std::vector <Crit3DInterpolationDataPoint> &myPoints, int proxyPos,
float stdDevThreshold);

bool setHeightTemperatureRange(Crit3DProxyCombination myCombination, Crit3DInterpolationSettings* mySettings);
bool setMultipleDetrendingHeightTemperatureRange(Crit3DInterpolationSettings* mySettings);

void calculateFirstGuessCombinations(Crit3DProxy* myProxy);

Expand Down
12 changes: 6 additions & 6 deletions agrolib/interpolation/interpolationSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,17 +363,17 @@ void Crit3DInterpolationSettings::setChosenElevationFunction(TFittingFunction ch
if (chosenFunction == piecewiseTwo)
{
tempParam[1] = MIN_T-2;
tempParam[5] = MAX_T+2;
tempParam[5] = MAX_T+6;
}
else if (chosenFunction == piecewiseThree)
{
tempParam[1] = MIN_T-2;
tempParam[6] = MAX_T+2;
tempParam[6] = MAX_T+6;
}
else if (chosenFunction == piecewiseThreeFree)
{
tempParam[1] = MIN_T-2;
tempParam[7] = MAX_T+2;
tempParam[7] = MAX_T+6;
}

getProxy(elPos)->setFittingParametersRange(tempParam);
Expand All @@ -383,19 +383,19 @@ void Crit3DInterpolationSettings::setChosenElevationFunction(TFittingFunction ch
if (chosenFunction == piecewiseTwo)
{
getProxy(elPos)->setFittingParametersRange({0, MIN_T-2, SLOPE_MIN, INVSLOPE_MIN,
H0_MAX, MAX_T+2, SLOPE_MAX, INVSLOPE_MAX});
H0_MAX, MAX_T+6, SLOPE_MAX, INVSLOPE_MAX});
getProxy(elPos)->setFittingFirstGuess({0,1,1,1});
}
else if (chosenFunction == piecewiseThree)
{
getProxy(elPos)->setFittingParametersRange({H0_MIN, MIN_T-2, DELTA_MIN, SLOPE_MIN, INVSLOPE_MIN,
H0_MAX, MAX_T+2, DELTA_MAX, SLOPE_MAX, INVSLOPE_MAX});
H0_MAX, MAX_T+6, DELTA_MAX, SLOPE_MAX, INVSLOPE_MAX});
getProxy(elPos)->setFittingFirstGuess({0,1,1,1,1});
}
else if (chosenFunction == piecewiseThreeFree)
{
getProxy(elPos)->setFittingParametersRange({H0_MIN, MIN_T-2, DELTA_MIN, SLOPE_MIN, INVSLOPE_MIN, INVSLOPE_MIN,
H0_MAX, MAX_T+2, DELTA_MAX, SLOPE_MAX, INVSLOPE_MAX, INVSLOPE_MAX});
H0_MAX, MAX_T+6, DELTA_MAX, SLOPE_MAX, INVSLOPE_MAX, INVSLOPE_MAX});
getProxy(elPos)->setFittingFirstGuess({0,1,1,1,1,1});
}
getProxy(elPos)->setFittingFunctionName(chosenFunction);
Expand Down
20 changes: 12 additions & 8 deletions agrolib/project/project.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2296,6 +2296,12 @@ bool Project::interpolationCv(meteoVariable myVar, const Crit3DTime& myTime, cro
}
else
{
if(!setMultipleDetrendingHeightTemperatureRange(&interpolationSettings))
{
errorString = "Error in function preInterpolation: \n couldn't set temperature ranges for height proxy.";
return false;
}

if (! computeResidualsLocalDetrending(myVar, myTime, meteoPoints, nrMeteoPoints, interpolationPoints,
&interpolationSettings, meteoSettings, &climateParameters, true, true))
return false;
Expand Down Expand Up @@ -2417,7 +2423,7 @@ bool Project::interpolationDemLocalDetrending(meteoVariable myVar, const Crit3DT
gis::Crit3DRasterHeader myHeader = *(DEM.header);
myRaster->initializeGrid(myHeader);

if(!setHeightTemperatureRange(myCombination, &interpolationSettings))
if(!setMultipleDetrendingHeightTemperatureRange(&interpolationSettings))
{
errorString = "Error in function preInterpolation: \n couldn't set temperature ranges for height proxy.";
return false;
Expand Down Expand Up @@ -2681,6 +2687,11 @@ bool Project::interpolationGrid(meteoVariable myVar, const Crit3DTime& myTime)
{
myCombination = interpolationSettings.getSelectedCombination();
interpolationSettings.setCurrentCombination(myCombination);
if(!setMultipleDetrendingHeightTemperatureRange(&interpolationSettings))
{
errorString = "Error in function preInterpolation: \n couldn't set temperature ranges for height proxy.";
return false;
}
}

// proxy aggregation
Expand All @@ -2694,13 +2705,6 @@ bool Project::interpolationGrid(meteoVariable myVar, const Crit3DTime& myTime)
std::vector <double> proxyValues;
proxyValues.resize(unsigned(interpolationSettings.getProxyNr()));

if (interpolationSettings.getUseLocalDetrending())
if(!setHeightTemperatureRange(myCombination, &interpolationSettings))
{
errorString = "Error in function preInterpolation: \n couldn't set temperature ranges for height proxy.";
return false;
}

float interpolatedValue = NODATA;
unsigned int i, proxyIndex;

Expand Down
2 changes: 1 addition & 1 deletion agrolib/proxyWidget/localProxyWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ void Crit3DLocalProxyWidget::modelLRClicked(int toggled)
if (comboAxisX.currentText() == "elevation")
{
std::string errorStr;
setHeightTemperatureRange(interpolationSettings->getSelectedCombination(), interpolationSettings);
setMultipleDetrendingHeightTemperatureRange(interpolationSettings);
interpolationSettings->setCurrentCombination(interpolationSettings->getSelectedCombination());
interpolationSettings->clearFitting();
if (! multipleDetrendingElevationFitting(proxyPos, subsetInterpolationPoints, interpolationSettings, myVar, errorStr)) return;
Expand Down
2 changes: 1 addition & 1 deletion agrolib/proxyWidget/proxyWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ void Crit3DProxyWidget::modelLRClicked(int toggled)
{
std::string errorStr;

setHeightTemperatureRange(interpolationSettings->getSelectedCombination(), interpolationSettings);
setMultipleDetrendingHeightTemperatureRange(interpolationSettings);
interpolationSettings->setCurrentCombination(interpolationSettings->getSelectedCombination());
interpolationSettings->clearFitting();
if (! multipleDetrendingElevationFitting(proxyPos, outInterpolationPoints, interpolationSettings, myVar, errorStr)) return;
Expand Down
4 changes: 3 additions & 1 deletion agrolib/utilities/logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ Logger::Logger()

bool Logger::setLog(QString path, QString fileName, bool addDateTime)
{
if (!QDir(path + "log").exists())
if (! QDir(path + "log").exists())
{
QDir().mkdir(path + "log");
}

m_showDate = true;
if (!fileName.isEmpty())
Expand Down

0 comments on commit cec709d

Please sign in to comment.