From b1c0d8c5c24994229f90273d773e094a48d37d48 Mon Sep 17 00:00:00 2001 From: lauracosta Date: Tue, 12 Mar 2024 09:17:44 +0100 Subject: [PATCH 01/72] add prefix and suffix to filename --- inOutDataXML/inOutDataXML.cpp | 14 ++++++++++---- inOutDataXML/inOutDataXML.h | 3 ++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/inOutDataXML/inOutDataXML.cpp b/inOutDataXML/inOutDataXML.cpp index 2e7fd427..27656324 100644 --- a/inOutDataXML/inOutDataXML.cpp +++ b/inOutDataXML/inOutDataXML.cpp @@ -83,9 +83,13 @@ bool InOutDataXML::parserXML(QString *myError) { fileName_pragaName = secondChild.toElement().text(); } - else if (mySecondTag == "TEXT" || mySecondTag == "FIXEDTEXT") + else if (mySecondTag == "PREFIX" || mySecondTag == "FIXEDPREFIX") { - fileName_fixedText.append(secondChild.toElement().text()); + fileName_fixedPrefix.append(secondChild.toElement().text()); + } + else if (mySecondTag == "SUFFIX" || mySecondTag == "FIXEDSUFFIX") + { + fileName_fixedSuffix.append(secondChild.toElement().text()); } else if (mySecondTag == "NRCHAR" || mySecondTag == "NR_CHAR") { @@ -1253,9 +1257,11 @@ QString InOutDataXML::parseXMLFilename(QString code) { return filename; } - QString suffix = fileName_fixedText.join(","); + QString prefix = fileName_fixedPrefix.join(","); + prefix.replace(",",""); + QString suffix = fileName_fixedSuffix.join(","); suffix.replace(",",""); - filename = fileName_path + code + suffix; + filename = fileName_path + prefix + code + suffix; return filename; } diff --git a/inOutDataXML/inOutDataXML.h b/inOutDataXML/inOutDataXML.h index fedcdf36..9037b716 100644 --- a/inOutDataXML/inOutDataXML.h +++ b/inOutDataXML/inOutDataXML.h @@ -61,7 +61,8 @@ class InOutDataXML QString format_decimalSeparator; QString fileName_path; QString fileName_pragaName; - QList fileName_fixedText; + QList fileName_fixedPrefix; + QList fileName_fixedSuffix; int fileName_nrChar; FieldXML time; FieldXML pointCode; From 5c96f9d8ee37b8fe1482f7a42edd8872a961620d Mon Sep 17 00:00:00 2001 From: lauracosta Date: Tue, 12 Mar 2024 10:00:42 +0100 Subject: [PATCH 02/72] check filename field for import --- inOutDataXML/inOutDataXML.cpp | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/inOutDataXML/inOutDataXML.cpp b/inOutDataXML/inOutDataXML.cpp index 27656324..6e84a378 100644 --- a/inOutDataXML/inOutDataXML.cpp +++ b/inOutDataXML/inOutDataXML.cpp @@ -1145,11 +1145,32 @@ QString InOutDataXML::parseXMLPointCode(QString text) { if (format_type == XMLFORMATFIXED || (format_type == XMLFORMATDELIMITED && pointCode.getType().toUpper() == "FILENAMEDEFINED")) { - QString substring = text.mid(0,pointCode.getNrChar()); - if (pointCode.getFormat().isEmpty() || pointCode.getFormat() == "%s") + if (fileName_pragaName.isEmpty()) { - // pointCode is a string - myPointCode = substring; + QString substring = text.mid(0,pointCode.getNrChar()); + if (pointCode.getFormat().isEmpty() || pointCode.getFormat() == "%s") + { + // pointCode is a string + myPointCode = substring; + } + } + else + { + // con questa casistica l'import funziona anche con gli xml di export che hanno il campo filename e prefissi o suffissi nel nome del file + QString substring = text; + for (int i = 0; i Date: Tue, 12 Mar 2024 11:55:10 +0100 Subject: [PATCH 03/72] drawSum TO DO --- meteoWidget/meteoWidget.cpp | 52 +++++++++++++++++++++++++++++++++---- meteoWidget/meteoWidget.h | 1 + 2 files changed, 48 insertions(+), 5 deletions(-) diff --git a/meteoWidget/meteoWidget.cpp b/meteoWidget/meteoWidget.cpp index 78daab9d..65cdc479 100644 --- a/meteoWidget/meteoWidget.cpp +++ b/meteoWidget/meteoWidget.cpp @@ -625,8 +625,6 @@ void Crit3DMeteoWidget::resetValues() { QLineSeries* line = new QLineSeries(); line->setName(getFormattedLabel(pointName, nameLines[i])); - - //QColor lineColor = colorLine[i]; QColor lineColor = colorLines[i]; if (nMeteoPoints == 1) { @@ -2312,16 +2310,60 @@ void Crit3DMeteoWidget::on_actionDataAvailability() void Crit3DMeteoWidget::on_actionDataSum() { - // TO DO; - // Apre una finestra con l'elenco delle variabili attualmente visualizzate in modo che siano selezionabili quali vogliamo switchare sulla comulata DialogVariableToSum varToSum(currentVariables); QList varToSumList; if (varToSum.result() == QDialog::Accepted) { varToSumList = varToSum.getSelectedVariable(); } - qDebug() << "varToSumList " << varToSumList.join(","); + else + { + return; + } + if (!varToSumList.isEmpty()) + { + drawSum(varToSumList); + } +} +void Crit3DMeteoWidget::drawSum(QList varToSumList) +{ + // TO DO + int nMeteoPoints = meteoPoints.size(); + for (int i = 0; i < varToSumList.size(); i++) + { + qDebug() << "varToSumList: " << varToSumList[i]; + if (!lineSeries.isEmpty()) + { + for (int j = 0; j < nameLines.size(); j++) + { + qDebug() << "nameLines[j]: " << nameLines[j]; + if (nameLines[j] == varToSumList[i]) + { + qDebug() << "found: " << varToSumList[i]; + for (int mp=0; mppoints().size(); n++) + { + qDebug() << "lineSeries[mp][j]->points()[n].x(): " << lineSeries[mp][j]->points()[n].x(); + qDebug() << "lineSeries[mp][j]->points()[n].y(): " << lineSeries[mp][j]->points()[n].y(); + } + } + } + } + } + if (! barSeries.isEmpty()) + { + for (int j = 0; j < nameBar.size(); j++) + { + qDebug() << "nameBar[j]: " << nameBar[j]; + if (nameBar[j] == varToSumList[i]) + { + qDebug() << "found: " << varToSumList[i]; + } + } + } + } } diff --git a/meteoWidget/meteoWidget.h b/meteoWidget/meteoWidget.h index 3d5a9da2..497df9b3 100644 --- a/meteoWidget/meteoWidget.h +++ b/meteoWidget/meteoWidget.h @@ -58,6 +58,7 @@ void on_actionInfoPoint(); void on_actionDataAvailability(); void on_actionDataSum(); + void drawSum(QList varToSumList); private: int meteoWidgetID; From c29ac41ca66e82b54a8c932bec152f630afc636e Mon Sep 17 00:00:00 2001 From: Antonio Volta Date: Tue, 12 Mar 2024 12:08:07 +0100 Subject: [PATCH 04/72] eliminati commenti debugging --- interpolation/interpolation.cpp | 20 -------------------- mathFunctions/furtherMathFunctions.cpp | 19 +------------------ project/project.cpp | 14 -------------- 3 files changed, 1 insertion(+), 52 deletions(-) diff --git a/interpolation/interpolation.cpp b/interpolation/interpolation.cpp index 521c35b7..adc3b649 100644 --- a/interpolation/interpolation.cpp +++ b/interpolation/interpolation.cpp @@ -28,11 +28,6 @@ #include #include -/*#include -#include -#include -*/ - #include "commonConstants.h" #include "basicMath.h" #include "furtherMathFunctions.h" @@ -1517,25 +1512,10 @@ bool multipleDetrending(std::vector &myPoints, Cr std::vector&)>> myFunc; setFittingParameters(myCombination, mySettings, myFunc, parametersMin, parametersMax, parametersDelta, parameters); - //auto start2 = std::chrono::high_resolution_clock::now(); - // multiple non linear fitting - /*interpolation::bestFittingMarquardt_nDimension(&functionSum, myFunc, 4, 3, parametersMin, parametersMax, parameters, parametersDelta, - 20, 0.05, 0.02, predictors, predictands, false, weights);*/ - interpolation::bestFittingMarquardt_nDimension(&functionSum, myFunc, 500, 5, parametersMin, parametersMax, parameters, parametersDelta, 100, 0.005, 0.01, predictors, predictands, false, weights); - /*auto end2 = std::chrono::high_resolution_clock::now(); - std::chrono::duration tempo2 = end2 - start2; - std::ofstream csvfile("C:/Github/tempoBestFit.csv", std::ios::app); - - if (!csvfile.is_open()) { - std::cerr << "Errore apertura file\n"; - } - csvfile << tempo2.count() << std::endl; - csvfile.close(); -*/ mySettings->setFittingFunction(myFunc); mySettings->setFittingParameters(parameters); diff --git a/mathFunctions/furtherMathFunctions.cpp b/mathFunctions/furtherMathFunctions.cpp index 825ca65f..8f50d6b3 100644 --- a/mathFunctions/furtherMathFunctions.cpp +++ b/mathFunctions/furtherMathFunctions.cpp @@ -32,9 +32,6 @@ #include "commonConstants.h" #include "furtherMathFunctions.h" -#include -#include -#include double lapseRateRotatedSigmoid(double x, std::vector par) { @@ -1094,7 +1091,7 @@ namespace interpolation R2 = computeR2(y,ySim); else R2 = computeWeighted_R2(y,ySim,weights); - //printf("%d R2 = %f\n",iRandom,R2); + if (R2 > (bestR2-deltaR2)) { for (j=0;j deltaR2) ); -/* std::ofstream csvfile("C:/Github/counterR2.csv", std::ios::app); - - if (!csvfile.is_open()) { - std::cerr << "Errore apertura file\n"; - } - csvfile << counter << "," << R2 << std::endl; - csvfile.close(); -*/ for (i=0;i= 0; i--) { diff --git a/project/project.cpp b/project/project.cpp index 484e8e62..773e6fbf 100644 --- a/project/project.cpp +++ b/project/project.cpp @@ -23,9 +23,6 @@ #include #include -/*#include -#include -*/ Project::Project() { @@ -2309,7 +2306,6 @@ bool Project::interpolationDemLocalDetrending(meteoVariable myVar, const Crit3DT float z = DEM.value[row][col]; if (! isEqual(z, myHeader.flag)) { - //auto start1 = std::chrono::high_resolution_clock::now(); gis::getUtmXYFromRowCol(myHeader, row, col, &x, &y); std::vector subsetInterpolationPoints; @@ -2318,16 +2314,6 @@ bool Project::interpolationDemLocalDetrending(meteoVariable myVar, const Crit3DT getProxyValuesXY(x, y, &interpolationSettings, proxyValues); myRaster->value[row][col] = interpolate(subsetInterpolationPoints, &interpolationSettings, meteoSettings, myVar, x, y, z, proxyValues, true); - - /*auto end1 = std::chrono::high_resolution_clock::now(); - std::chrono::duration tempo1 = end1 - start1; - std::ofstream csvfile("C:/Github/rowCol.csv", std::ios::app); - - if (!csvfile.is_open()) { - std::cerr << "Errore apertura file\n"; - } - csvfile << row << "," << col << "," << tempo1.count() << std::endl; - csvfile.close();*/ } } } From f3dccf60f453b63445435ffdb22ffd236a163214 Mon Sep 17 00:00:00 2001 From: Antonio Volta Date: Tue, 12 Mar 2024 17:17:48 +0100 Subject: [PATCH 05/72] pulizia commenti debugging interpolazione --- pragaProject/pragaProject.cpp | 1 + project/project.cpp | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/pragaProject/pragaProject.cpp b/pragaProject/pragaProject.cpp index 0fd21c63..615caa07 100644 --- a/pragaProject/pragaProject.cpp +++ b/pragaProject/pragaProject.cpp @@ -2438,6 +2438,7 @@ bool PragaProject::interpolationMeteoGrid(meteoVariable myVar, frequencyType myF } else { + if (! interpolationGrid(myVar, myTime)) return false; } diff --git a/project/project.cpp b/project/project.cpp index 773e6fbf..74bb1f1a 100644 --- a/project/project.cpp +++ b/project/project.cpp @@ -2584,6 +2584,10 @@ bool Project::interpolationGrid(meteoVariable myVar, const Crit3DTime& myTime) if (interpolationSettings.getUseLocalDetrending()) { + if (row == 80 && col == 67) + { + std::cout << "cella individuata" << std::endl; + } std::vector subsetInterpolationPoints; localSelection(interpolationPoints, subsetInterpolationPoints, myX, myY, interpolationSettings); preInterpolation(subsetInterpolationPoints, &interpolationSettings, meteoSettings, &climateParameters, meteoPoints, nrMeteoPoints, myVar, myTime); @@ -2592,6 +2596,7 @@ bool Project::interpolationGrid(meteoVariable myVar, const Crit3DTime& myTime) if (interpolatedValue > 9000) { std::cout << "valore sballato" << std::endl; + std::cout << "riga " << row << " colonna " << col << std::endl; } } else From 07ee6f84fec78140d4092df6c1a1b188b81bd1f7 Mon Sep 17 00:00:00 2001 From: lauracosta Date: Tue, 12 Mar 2024 18:23:55 +0100 Subject: [PATCH 06/72] cumulative Bar TBC --- meteoWidget/meteoWidget.cpp | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/meteoWidget/meteoWidget.cpp b/meteoWidget/meteoWidget.cpp index 65cdc479..205813e6 100644 --- a/meteoWidget/meteoWidget.cpp +++ b/meteoWidget/meteoWidget.cpp @@ -2337,17 +2337,25 @@ void Crit3DMeteoWidget::drawSum(QList varToSumList) { for (int j = 0; j < nameLines.size(); j++) { - qDebug() << "nameLines[j]: " << nameLines[j]; if (nameLines[j] == varToSumList[i]) { - qDebug() << "found: " << varToSumList[i]; + QVector points; + QVector cumulativePoints; for (int mp=0; mppoints().size(); n++) { - qDebug() << "lineSeries[mp][j]->points()[n].x(): " << lineSeries[mp][j]->points()[n].x(); - qDebug() << "lineSeries[mp][j]->points()[n].y(): " << lineSeries[mp][j]->points()[n].y(); + points.append(QPointF(lineSeries[mp][j]->points()[n].x(),lineSeries[mp][j]->points()[n].y())); + } + cumulativePoints.append(points[0]); + for (int n = 1; nreplace(cumulativePoints); + axisY->setMax(cumulativePoints.last().ry()); + points.clear(); + cumulativePoints.clear(); } } } @@ -2360,6 +2368,22 @@ void Crit3DMeteoWidget::drawSum(QList varToSumList) if (nameBar[j] == varToSumList[i]) { qDebug() << "found: " << varToSumList[i]; + QVector values; + for (int mp=0; mpcount(): " << setVector[mp][j]->count(); + for (int n = 0; ncount(); n++) + { + qDebug() << "n " << n; + qDebug() << "setVector[mp][j]->at(n): " << setVector[mp][j]->at(n); + values << setVector[mp][j]->at(n); + } + for (int n = 1; nreplace(n,values[n] + values [n-1]); + qDebug() << "setVectorNew: " << setVector[mp][j]->at(n); + } + } } } } From 8e3d41e807379134579f85bca3093df77b39c27c Mon Sep 17 00:00:00 2001 From: ftomei Date: Tue, 12 Mar 2024 20:04:37 +0100 Subject: [PATCH 07/72] fix change dem --- graphics/mapGraphicsRasterUtm.cpp | 3 +-- project/project.cpp | 4 +++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/graphics/mapGraphicsRasterUtm.cpp b/graphics/mapGraphicsRasterUtm.cpp index 6722cc94..73d23b47 100644 --- a/graphics/mapGraphicsRasterUtm.cpp +++ b/graphics/mapGraphicsRasterUtm.cpp @@ -53,11 +53,10 @@ void RasterUtmObject::clear() _rasterPointer = nullptr; _colorLegendPointer = nullptr; + isLoaded = false; _utmZone = NODATA; _refCenterPixel = QPointF(NODATA, NODATA); - - isLoaded = false; } diff --git a/project/project.cpp b/project/project.cpp index 74bb1f1a..14259019 100644 --- a/project/project.cpp +++ b/project/project.cpp @@ -1002,7 +1002,8 @@ bool Project::loadDEM(QString myFileName) setColorScale(noMeteoTerrain, DEM.colorScale); // initialize radiation maps (slope, aspect, lat/lon, transmissivity, etc.) - if (radiationMaps != nullptr) radiationMaps->clear(); + if (radiationMaps != nullptr) + radiationMaps->clear(); radiationMaps = new Crit3DRadiationMaps(DEM, gisSettings); // initialize hourly meteo maps @@ -1707,6 +1708,7 @@ QDateTime Project::findDbPointFirstTime() return firstTime; } + void Project::checkMeteoPointsDEM() { for (int i=0; i < nrMeteoPoints; i++) From 19769c8699e544f8256f5cc7c1df23d9a12cdaff Mon Sep 17 00:00:00 2001 From: lauracosta Date: Wed, 13 Mar 2024 11:51:42 +0100 Subject: [PATCH 08/72] export point with date period --- dbMeteoPoints/dbMeteoPointsHandler.cpp | 17 +++++++++++++---- dbMeteoPoints/dbMeteoPointsHandler.h | 2 +- pragaProject/pragaProject.cpp | 10 +++++----- pragaProject/pragaProject.h | 4 ++-- 4 files changed, 21 insertions(+), 12 deletions(-) diff --git a/dbMeteoPoints/dbMeteoPointsHandler.cpp b/dbMeteoPoints/dbMeteoPointsHandler.cpp index 9cea7eca..46a492a3 100644 --- a/dbMeteoPoints/dbMeteoPointsHandler.cpp +++ b/dbMeteoPoints/dbMeteoPointsHandler.cpp @@ -686,7 +686,7 @@ std::vector Crit3DMeteoPointsDbHandler::loadDailyVar(QString *myError, me return dailyVarList; } -std::vector Crit3DMeteoPointsDbHandler::exportAllDataVar(QString *myError, frequencyType freq, meteoVariable variable, QString id, std::vector &dateStr) +std::vector Crit3DMeteoPointsDbHandler::exportAllDataVar(QString *myError, frequencyType freq, meteoVariable variable, QString id, QDateTime myFirstTime, QDateTime myLastTime, std::vector &dateStr) { QString myDateStr; QDateTime dateTime; @@ -699,14 +699,26 @@ std::vector Crit3DMeteoPointsDbHandler::exportAllDataVar(QString *myError QSqlQuery myQuery(_db); QString tableName; + QString startDate; + QString endDate; + QString statement; if (freq == daily) { tableName = id + "_D"; + startDate = myFirstTime.date().toString("yyyy-MM-dd"); + endDate = myLastTime.date().toString("yyyy-MM-dd"); + statement = QString( "SELECT * FROM `%1` WHERE `%2` = %3 AND date_time >= DATE('%4') AND date_time <= DATE('%5')") + .arg(tableName).arg(FIELD_METEO_VARIABLE).arg(idVar).arg(startDate).arg(endDate); + } else if (freq == hourly) { tableName = id + "_H"; + startDate = myFirstTime.date().toString("yyyy-MM-dd") + " " + myFirstTime.time().toString("hh:mm"); + endDate = myLastTime.date().toString("yyyy-MM-dd") + " " + myLastTime.time().toString("hh:mm"); + statement = QString( "SELECT * FROM `%1` WHERE `%2` = %3 AND date_time >= DATETIME('%4') AND date_time <= DATETIME('%5')") + .arg(tableName).arg(FIELD_METEO_VARIABLE).arg(idVar).arg(startDate).arg(endDate); } else { @@ -714,9 +726,6 @@ std::vector Crit3DMeteoPointsDbHandler::exportAllDataVar(QString *myError return allDataVarList; } - QString statement = QString( "SELECT * FROM `%1` WHERE `%2` = %3") - .arg(tableName).arg(FIELD_METEO_VARIABLE).arg(idVar); - if( !myQuery.exec(statement) ) { *myError = myQuery.lastError().text(); diff --git a/dbMeteoPoints/dbMeteoPointsHandler.h b/dbMeteoPoints/dbMeteoPointsHandler.h index a0f8d585..e159561b 100644 --- a/dbMeteoPoints/dbMeteoPointsHandler.h +++ b/dbMeteoPoints/dbMeteoPointsHandler.h @@ -68,7 +68,7 @@ std::vector loadDailyVar(QString *myError, meteoVariable variable, Crit3DDate dateStart, Crit3DDate dateEnd, QDate* firstDateDB, Crit3DMeteoPoint *meteoPoint); - std::vector exportAllDataVar(QString *myError, frequencyType freq, meteoVariable variable, QString id, std::vector &dateStr); + std::vector exportAllDataVar(QString *myError, frequencyType freq, meteoVariable variable, QString id, QDateTime myFirstTime, QDateTime myLastTime, std::vector &dateStr); bool loadHourlyData(const Crit3DDate &firstDate, const Crit3DDate &lastDate, Crit3DMeteoPoint *meteoPoint); diff --git a/pragaProject/pragaProject.cpp b/pragaProject/pragaProject.cpp index 615caa07..3d6544dd 100644 --- a/pragaProject/pragaProject.cpp +++ b/pragaProject/pragaProject.cpp @@ -3259,7 +3259,7 @@ bool PragaProject::loadXMLImportData(QString fileName) return true; } -bool PragaProject::loadXMLExportData(QString code) +bool PragaProject::loadXMLExportData(QString code, QDateTime myFirstTime, QDateTime myLastTime) { errorString = ""; QString filename = inOutData->parseXMLFilename(code); @@ -3318,7 +3318,7 @@ bool PragaProject::loadXMLExportData(QString code) return false; } QString flagAccepted = inOutData->getVariableFlagAccepted(); - int flagFirstChar; + int flagFirstChar = 0; if (!flagAccepted.isEmpty()) { flagFirstChar = inOutData->getVariableFlagFirstChar(); @@ -3341,7 +3341,7 @@ bool PragaProject::loadXMLExportData(QString code) std::vector dateStr; - std::vector values = meteoPointsDbHandler->exportAllDataVar(&errorString, freq, meteoVar, code, dateStr); + std::vector values = meteoPointsDbHandler->exportAllDataVar(&errorString, freq, meteoVar, code, myFirstTime, myLastTime, dateStr); if (values.size() == 0) { errorString = code + " has no data for variable: " + variable; @@ -3443,7 +3443,7 @@ bool PragaProject::loadXMLExportData(QString code) } // LC 2 funzioni separate per gliglie e punti per eventualmente diversificare anche i dati da esportare (es. le griglie hanno anche i mensili) -bool PragaProject::loadXMLExportDataGrid(QString code) +bool PragaProject::loadXMLExportDataGrid(QString code, QDateTime myFirstTime, QDateTime myLastTime) { errorString = ""; QString filename = inOutData->parseXMLFilename(code); @@ -3502,7 +3502,7 @@ bool PragaProject::loadXMLExportDataGrid(QString code) return false; } QString flagAccepted = inOutData->getVariableFlagAccepted(); - int flagFirstChar; + int flagFirstChar = 0; if (!flagAccepted.isEmpty()) { flagFirstChar = inOutData->getVariableFlagFirstChar(); diff --git a/pragaProject/pragaProject.h b/pragaProject/pragaProject.h index 3e3f23a8..dd670ab6 100644 --- a/pragaProject/pragaProject.h +++ b/pragaProject/pragaProject.h @@ -139,8 +139,8 @@ int executePragaCommand(QList argumentList, bool* isCommandFound); bool parserXMLImportExportData(QString xmlName, bool isGrid); bool loadXMLImportData(QString fileName); - bool loadXMLExportData(QString code); - bool loadXMLExportDataGrid(QString code); + bool loadXMLExportData(QString code, QDateTime myFirstTime, QDateTime myLastTime); + bool loadXMLExportDataGrid(QString code, QDateTime myFirstTime, QDateTime myLastTime); bool monthlyAggregateVariablesGrid(const QDate &firstDate, const QDate &lastDate, QList &variablesList); bool computeDroughtIndexGrid(droughtIndex index, int firstYear, int lastYear, QDate date, int timescale, meteoVariable myVar); bool computeDroughtIndexPoint(droughtIndex index, int timescale, int refYearStart, int refYearEnd); From f463f589105fda8b87ff57b20e3f1833fa52c421 Mon Sep 17 00:00:00 2001 From: lauracosta Date: Wed, 13 Mar 2024 12:53:19 +0100 Subject: [PATCH 09/72] export grid with date period --- dbMeteoGrid/dbMeteoGrid.cpp | 16 ++++++++++++---- dbMeteoGrid/dbMeteoGrid.h | 2 +- pragaProject/pragaProject.cpp | 2 +- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/dbMeteoGrid/dbMeteoGrid.cpp b/dbMeteoGrid/dbMeteoGrid.cpp index b94ea2b7..58e7903a 100644 --- a/dbMeteoGrid/dbMeteoGrid.cpp +++ b/dbMeteoGrid/dbMeteoGrid.cpp @@ -2438,7 +2438,7 @@ std::vector Crit3DMeteoGridDbHandler::loadGridDailyVar(QString *myError, return dailyVarList; } -std::vector Crit3DMeteoGridDbHandler::exportAllDataVar(QString *myError, frequencyType freq, meteoVariable variable, QString id, std::vector &dateStr) +std::vector Crit3DMeteoGridDbHandler::exportAllDataVar(QString *myError, frequencyType freq, meteoVariable variable, QString id, QDateTime myFirstTime, QDateTime myLastTime, std::vector &dateStr) { QString myDateStr; float value; @@ -2446,6 +2446,9 @@ std::vector Crit3DMeteoGridDbHandler::exportAllDataVar(QString *myError, QSqlQuery myQuery(_db); QString tableName; + QString statement; + QString startDate; + QString endDate; int idVar; if (freq == daily) @@ -2457,6 +2460,10 @@ std::vector Crit3DMeteoGridDbHandler::exportAllDataVar(QString *myError, return allDataVarList; } tableName = _tableDaily.prefix + id + _tableDaily.postFix; + startDate = myFirstTime.date().toString("yyyy-MM-dd"); + endDate = myLastTime.date().toString("yyyy-MM-dd"); + statement = QString( "SELECT * FROM `%1` WHERE VariableCode = '%2' AND `%3` >= '%4' AND `%3`<= '%5'") + .arg(tableName).arg(idVar).arg(_tableDaily.fieldTime).arg(startDate).arg(endDate); } else if (freq == hourly) { @@ -2467,15 +2474,16 @@ std::vector Crit3DMeteoGridDbHandler::exportAllDataVar(QString *myError, return allDataVarList; } tableName = _tableHourly.prefix + id + _tableHourly.postFix; + startDate = myFirstTime.date().toString("yyyy-MM-dd") + " " + myFirstTime.time().toString("hh:mm"); + endDate = myLastTime.date().toString("yyyy-MM-dd") + " " + myLastTime.time().toString("hh:mm"); + statement = QString( "SELECT * FROM `%1` WHERE VariableCode = '%2' AND `%3` >= '%4' AND `%3`<= '%5'") + .arg(tableName).arg(idVar).arg(_tableHourly.fieldTime).arg(startDate).arg(endDate); } else { *myError = "Frequency should be daily or hourly"; return allDataVarList; } - - QString statement = QString( "SELECT * FROM `%1` WHERE VariableCode = '%2'") - .arg(tableName).arg(idVar); QDateTime dateTime; QDate date; if( !myQuery.exec(statement) ) diff --git a/dbMeteoGrid/dbMeteoGrid.h b/dbMeteoGrid/dbMeteoGrid.h index 67701ad0..da8305e5 100644 --- a/dbMeteoGrid/dbMeteoGrid.h +++ b/dbMeteoGrid/dbMeteoGrid.h @@ -126,7 +126,7 @@ std::vector loadGridDailyVarFixedFields(QString *myError, QString meteoPoint, meteoVariable variable, QDate first, QDate last, QDate* firstDateDB); std::vector loadGridHourlyVar(QString *myError, QString meteoPoint, meteoVariable variable, QDateTime first, QDateTime last, QDateTime* firstDateDB); std::vector loadGridHourlyVarFixedFields(QString *myError, QString meteoPoint, meteoVariable variable, QDateTime first, QDateTime last, QDateTime* firstDateDB); - std::vector exportAllDataVar(QString *myError, frequencyType freq, meteoVariable variable, QString id, std::vector &dateStr); + std::vector exportAllDataVar(QString *myError, frequencyType freq, meteoVariable variable, QString id, QDateTime myFirstTime, QDateTime myLastTime, std::vector &dateStr); bool getYearList(QString *myError, QString meteoPoint, QList* yearList); bool idDailyList(QString *myError, QList* idMeteoList); diff --git a/pragaProject/pragaProject.cpp b/pragaProject/pragaProject.cpp index 3d6544dd..eb8ee865 100644 --- a/pragaProject/pragaProject.cpp +++ b/pragaProject/pragaProject.cpp @@ -3525,7 +3525,7 @@ bool PragaProject::loadXMLExportDataGrid(QString code, QDateTime myFirstTime, QD std::vector dateStr; - std::vector values = meteoGridDbHandler->exportAllDataVar(&errorString, freq, meteoVar, code, dateStr); + std::vector values = meteoGridDbHandler->exportAllDataVar(&errorString, freq, meteoVar, code, myFirstTime, myLastTime, dateStr); if (values.size() == 0) { errorString = code + " has no data for variable: " + variable; From 4655fedd2268cceb4125efea4a93f40268739c9e Mon Sep 17 00:00:00 2001 From: Gabriele Antolini Date: Wed, 13 Mar 2024 16:21:12 +0100 Subject: [PATCH 10/72] iterators in interpolation --- interpolation/interpolation.cpp | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/interpolation/interpolation.cpp b/interpolation/interpolation.cpp index adc3b649..6db3ce91 100644 --- a/interpolation/interpolation.cpp +++ b/interpolation/interpolation.cpp @@ -1431,17 +1431,18 @@ bool multipleDetrending(std::vector &myPoints, Cr // exclude points with incomplete proxies unsigned i; - std::vector finalPoints; + vector::iterator it; + //std::vector finalPoints; bool isValid; float proxyValue; - for (i=0; i < myPoints.size(); i++) + for (it = myPoints.begin(); it != myPoints.end(); it++) { isValid = true; for (pos=0; pos < mySettings->getProxyNr(); pos++) if (mySettings->getProxy(pos)->getIsSignificant()) { - proxyValue = myPoints[i].getProxyValue(pos); + proxyValue = it->getProxyValue(pos); if (proxyValue == NODATA) { isValid = false; @@ -1449,7 +1450,7 @@ bool multipleDetrending(std::vector &myPoints, Cr } } - if (isValid) finalPoints.push_back(myPoints[i]); + if (! isValid) myPoints.erase(it); } // proxy spatial variability (2nd step) @@ -1459,7 +1460,7 @@ bool multipleDetrending(std::vector &myPoints, Cr validNr = 0; for (pos=0; pos < int(mySettings->getProxyNr()); pos++) { - if (myCombination.getValue(pos) && proxyValidity(finalPoints, pos, mySettings->getProxy(pos)->getStdDevThreshold(), &avg, &stdDev)) + if (myCombination.getValue(pos) && proxyValidity(myPoints, pos, mySettings->getProxy(pos)->getStdDevThreshold(), &avg, &stdDev)) { avgs.push_back(avg); stdDevs.push_back(stdDev); @@ -1479,24 +1480,24 @@ bool multipleDetrending(std::vector &myPoints, Cr std::vector predictands; std::vector weights; - for (i=0; i < finalPoints.size(); i++) + for (i=0; i < myPoints.size(); i++) { rowPredictors.clear(); for (pos=0; pos < mySettings->getProxyNr(); pos++) if ((mySettings->getProxy(pos)->getIsSignificant())) { - proxyValue = finalPoints[i].getProxyValue(pos); + proxyValue = myPoints[i].getProxyValue(pos); //rowPredictors.push_back((proxyValue - avgs[index]) / stdDevs[index]); rowPredictors.push_back(proxyValue); } //predictorsNorm.push_back(rowPredictors); predictors.push_back(rowPredictors); - predictands.push_back(finalPoints[i].value); - weights.push_back(finalPoints[i].regressionWeight); + predictands.push_back(myPoints[i].value); + weights.push_back(myPoints[i].regressionWeight); } - if (finalPoints.size() < mySettings->getMinPointsLocalDetrending()) + if (myPoints.size() < mySettings->getMinPointsLocalDetrending()) { for (pos = 0; pos < mySettings->getProxyNr(); pos++) mySettings->getProxy(pos)->setIsSignificant(false); From 82d19670efc59edd4cc7cfea622af2166a40a215 Mon Sep 17 00:00:00 2001 From: lauracosta Date: Wed, 13 Mar 2024 16:45:47 +0100 Subject: [PATCH 11/72] fix drawSum bar --- meteoWidget/meteoWidget.cpp | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/meteoWidget/meteoWidget.cpp b/meteoWidget/meteoWidget.cpp index 205813e6..a330c4a6 100644 --- a/meteoWidget/meteoWidget.cpp +++ b/meteoWidget/meteoWidget.cpp @@ -2337,10 +2337,11 @@ void Crit3DMeteoWidget::drawSum(QList varToSumList) { for (int j = 0; j < nameLines.size(); j++) { + qreal max = NODATA; if (nameLines[j] == varToSumList[i]) { QVector points; - QVector cumulativePoints; + QVector cumulativePoints; for (int mp=0; mppoints().size(); n++) @@ -2353,11 +2354,15 @@ void Crit3DMeteoWidget::drawSum(QList varToSumList) cumulativePoints.append(QPointF(points[n].rx(), points[n].ry()+cumulativePoints[n-1].ry())); } lineSeries[mp][j]->replace(cumulativePoints); - axisY->setMax(cumulativePoints.last().ry()); + if (max < cumulativePoints.last().ry()) + { + max = cumulativePoints.last().ry(); + } points.clear(); cumulativePoints.clear(); } } + axisY->setRange(axisY->min(),max); } } if (! barSeries.isEmpty()) @@ -2365,26 +2370,33 @@ void Crit3DMeteoWidget::drawSum(QList varToSumList) for (int j = 0; j < nameBar.size(); j++) { qDebug() << "nameBar[j]: " << nameBar[j]; + double max = NODATA; if (nameBar[j] == varToSumList[i]) { qDebug() << "found: " << varToSumList[i]; QVector values; + QVector cumulativeValues; for (int mp=0; mpcount(): " << setVector[mp][j]->count(); for (int n = 0; ncount(); n++) { - qDebug() << "n " << n; - qDebug() << "setVector[mp][j]->at(n): " << setVector[mp][j]->at(n); values << setVector[mp][j]->at(n); } + cumulativeValues.append(values[0]); for (int n = 1; nreplace(n,values[n] + values [n-1]); - qDebug() << "setVectorNew: " << setVector[mp][j]->at(n); + cumulativeValues.append(values[n]+cumulativeValues[n-1]); + setVector[mp][j]->replace(n,cumulativeValues[n]); + } + if (max < cumulativeValues.last()) + { + max = cumulativeValues.last(); } + values.clear(); + cumulativeValues.clear(); } } + axisYdx->setRange(axisYdx->min(),max); } } } From 2a42aa31ded119eadb5d59be193762db29577bff Mon Sep 17 00:00:00 2001 From: lauracosta Date: Wed, 13 Mar 2024 18:15:22 +0100 Subject: [PATCH 12/72] clean debug print --- meteoWidget/meteoWidget.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/meteoWidget/meteoWidget.cpp b/meteoWidget/meteoWidget.cpp index a330c4a6..50151d45 100644 --- a/meteoWidget/meteoWidget.cpp +++ b/meteoWidget/meteoWidget.cpp @@ -2328,11 +2328,9 @@ void Crit3DMeteoWidget::on_actionDataSum() void Crit3DMeteoWidget::drawSum(QList varToSumList) { - // TO DO int nMeteoPoints = meteoPoints.size(); for (int i = 0; i < varToSumList.size(); i++) { - qDebug() << "varToSumList: " << varToSumList[i]; if (!lineSeries.isEmpty()) { for (int j = 0; j < nameLines.size(); j++) @@ -2369,11 +2367,9 @@ void Crit3DMeteoWidget::drawSum(QList varToSumList) { for (int j = 0; j < nameBar.size(); j++) { - qDebug() << "nameBar[j]: " << nameBar[j]; double max = NODATA; if (nameBar[j] == varToSumList[i]) { - qDebug() << "found: " << varToSumList[i]; QVector values; QVector cumulativeValues; for (int mp=0; mp Date: Thu, 14 Mar 2024 09:28:06 +0100 Subject: [PATCH 13/72] iterators in interpolation loop fix --- interpolation/interpolation.cpp | 12 +++++++++--- project/project.cpp | 10 ---------- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/interpolation/interpolation.cpp b/interpolation/interpolation.cpp index 6db3ce91..a2d47dcd 100644 --- a/interpolation/interpolation.cpp +++ b/interpolation/interpolation.cpp @@ -1431,12 +1431,12 @@ bool multipleDetrending(std::vector &myPoints, Cr // exclude points with incomplete proxies unsigned i; - vector::iterator it; //std::vector finalPoints; bool isValid; float proxyValue; + vector::iterator it = myPoints.begin(); - for (it = myPoints.begin(); it != myPoints.end(); it++) + while (it != myPoints.end()) { isValid = true; for (pos=0; pos < mySettings->getProxyNr(); pos++) @@ -1450,7 +1450,13 @@ bool multipleDetrending(std::vector &myPoints, Cr } } - if (! isValid) myPoints.erase(it); + if (! isValid) + { + it = myPoints.erase(it); + } + else { + it++; + } } // proxy spatial variability (2nd step) diff --git a/project/project.cpp b/project/project.cpp index 14259019..2b37dbdd 100644 --- a/project/project.cpp +++ b/project/project.cpp @@ -2586,20 +2586,10 @@ bool Project::interpolationGrid(meteoVariable myVar, const Crit3DTime& myTime) if (interpolationSettings.getUseLocalDetrending()) { - if (row == 80 && col == 67) - { - std::cout << "cella individuata" << std::endl; - } std::vector subsetInterpolationPoints; localSelection(interpolationPoints, subsetInterpolationPoints, myX, myY, interpolationSettings); preInterpolation(subsetInterpolationPoints, &interpolationSettings, meteoSettings, &climateParameters, meteoPoints, nrMeteoPoints, myVar, myTime); interpolatedValue = interpolate(subsetInterpolationPoints, &interpolationSettings, meteoSettings, myVar, myX, myY, myZ, proxyValues, true); - //debugging - if (interpolatedValue > 9000) - { - std::cout << "valore sballato" << std::endl; - std::cout << "riga " << row << " colonna " << col << std::endl; - } } else { From f8dbedb636c31c2099657eb6cf8b248b5762cda5 Mon Sep 17 00:00:00 2001 From: lauracosta Date: Thu, 14 Mar 2024 10:31:32 +0100 Subject: [PATCH 14/72] fix spei/spi dateStart --- pragaProject/pragaProject.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pragaProject/pragaProject.cpp b/pragaProject/pragaProject.cpp index eb8ee865..e35442f4 100644 --- a/pragaProject/pragaProject.cpp +++ b/pragaProject/pragaProject.cpp @@ -3136,7 +3136,7 @@ void PragaProject::showPointStatisticsWidgetGrid(std::string id) firstMonth = 12 + firstMonth; dateStart.setDate(listXMLDrought->listDate()[i].year()-1, firstMonth, 1); } - if (firstMonth < -11) + else if (firstMonth < -11) { firstMonth = 24 + firstMonth; dateStart.setDate(listXMLDrought->listDate()[i].year()-2, firstMonth, 1); @@ -3159,7 +3159,7 @@ void PragaProject::showPointStatisticsWidgetGrid(std::string id) fistMonth = 12 + fistMonth; dateStart.setDate(listXMLDrought->listDate()[i].year()-1, fistMonth, 1); } - if (fistMonth < -11) + else if (fistMonth < -11) { fistMonth = 24 + fistMonth; dateStart.setDate(listXMLDrought->listDate()[i].year()-2, fistMonth, 1); From 5c12310b06ed625b7107827a33b42c1c14155193 Mon Sep 17 00:00:00 2001 From: lauracosta Date: Thu, 14 Mar 2024 10:31:32 +0100 Subject: [PATCH 15/72] fix spei/spi dateStart --- pragaProject/pragaProject.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pragaProject/pragaProject.cpp b/pragaProject/pragaProject.cpp index eb8ee865..e35442f4 100644 --- a/pragaProject/pragaProject.cpp +++ b/pragaProject/pragaProject.cpp @@ -3136,7 +3136,7 @@ void PragaProject::showPointStatisticsWidgetGrid(std::string id) firstMonth = 12 + firstMonth; dateStart.setDate(listXMLDrought->listDate()[i].year()-1, firstMonth, 1); } - if (firstMonth < -11) + else if (firstMonth < -11) { firstMonth = 24 + firstMonth; dateStart.setDate(listXMLDrought->listDate()[i].year()-2, firstMonth, 1); @@ -3159,7 +3159,7 @@ void PragaProject::showPointStatisticsWidgetGrid(std::string id) fistMonth = 12 + fistMonth; dateStart.setDate(listXMLDrought->listDate()[i].year()-1, fistMonth, 1); } - if (fistMonth < -11) + else if (fistMonth < -11) { fistMonth = 24 + fistMonth; dateStart.setDate(listXMLDrought->listDate()[i].year()-2, fistMonth, 1); From a66c7c6edabfc34a2c8faf4e793afe0a15b1e951 Mon Sep 17 00:00:00 2001 From: lauracosta Date: Thu, 14 Mar 2024 11:31:03 +0100 Subject: [PATCH 16/72] fix dateEnd dateStart Anomaly --- pragaProject/pragaProject.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/pragaProject/pragaProject.cpp b/pragaProject/pragaProject.cpp index e35442f4..93778c49 100644 --- a/pragaProject/pragaProject.cpp +++ b/pragaProject/pragaProject.cpp @@ -956,8 +956,6 @@ bool PragaProject::elaborationPointsCycleGrid(bool isAnomaly, bool showInfo) startDate.setDate(climaUsed->yearStart() + climaUsed->nYears(), climaUsed->genericPeriodDateStart().month(), climaUsed->genericPeriodDateStart().day()); } - - //Crit3DMeteoPoint* meteoPointTemp = new Crit3DMeteoPoint; bool dataAlreadyLoaded = false; for (int row = 0; row < meteoGridDbHandler->gridStructure().header().nrRows; row++) @@ -1017,13 +1015,11 @@ bool PragaProject::elaborationPointsCycleGrid(bool isAnomaly, bool showInfo) { errorString = "no valid cells available"; } - //delete meteoPointTemp; delete climaUsed; return false; } else { - //delete meteoPointTemp; delete climaUsed; return true; } @@ -3099,8 +3095,8 @@ void PragaProject::showPointStatisticsWidgetGrid(std::string id) netcdfName = xmlPath + listXMLAnomaly->listFileName()[i]+".nc"; } - QDate dateEnd = QDate(listXMLElab->listYearEnd()[i] + listXMLElab->listNYears()[i], listXMLElab->listDateEnd()[i].month(), listXMLElab->listDateEnd()[i].day()); - QDate dateStart = QDate(listXMLElab->listYearStart()[i], listXMLElab->listDateStart()[i].month(), listXMLElab->listDateStart()[i].day()); + QDate dateEnd = QDate(listXMLAnomaly->listYearEnd()[i] + listXMLAnomaly->listNYears()[i], listXMLAnomaly->listDateEnd()[i].month(), listXMLAnomaly->listDateEnd()[i].day()); + QDate dateStart = QDate(listXMLAnomaly->listYearStart()[i], listXMLAnomaly->listDateStart()[i].month(), listXMLAnomaly->listDateStart()[i].day()); int nDays = dateStart.daysTo(dateEnd); exportMeteoGridToNetCDF(netcdfName, netcdfTitle, QString::fromStdString(MapDailyMeteoVarToString.at(listXMLAnomaly->listVariable()[i])), getUnitFromVariable(listXMLAnomaly->listVariable()[i]), getCrit3DDate(dateStart), From b2e84ab9fb71d1c38fb3158db41d1d28bdb771f0 Mon Sep 17 00:00:00 2001 From: ftomei Date: Thu, 14 Mar 2024 15:46:19 +0100 Subject: [PATCH 17/72] add comment --- pragaProject/pragaProject.cpp | 11 +++++++---- pragaProject/pragaShell.cpp | 5 ++++- project/project.cpp | 4 ++-- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/pragaProject/pragaProject.cpp b/pragaProject/pragaProject.cpp index 93778c49..586f8c89 100644 --- a/pragaProject/pragaProject.cpp +++ b/pragaProject/pragaProject.cpp @@ -1667,7 +1667,7 @@ bool PragaProject::averageSeriesOnZonesMeteoGrid(meteoVariable variable, meteoCo // save dailyElabAggregation result into DB if (showInfo) setProgressBar("Save data...", 0); - if (!aggregationDbHandler->saveAggrData(int(zoneGrid->maximum), aggregationString, periodType, startDate, endDate, variable, dailyElabAggregation, lonVector, latVector)) + if (! aggregationDbHandler->saveAggrData(int(zoneGrid->maximum), aggregationString, periodType, startDate, endDate, variable, dailyElabAggregation, lonVector, latVector)) { errorString = aggregationDbHandler->error(); if (showInfo) closeProgressBar(); @@ -3735,10 +3735,11 @@ bool PragaProject::computeDroughtIndexGrid(droughtIndex index, int firstYear, in return res; } + +// assume che sia stato caricato un progetto con solo aggregationDb bool PragaProject::computeDroughtIndexPoint(droughtIndex index, int timescale, int refYearStart, int refYearEnd) { - - if (!aggregationDbHandler) + if (! aggregationDbHandler) { logError("No db aggregation"); return false; @@ -3786,7 +3787,7 @@ bool PragaProject::computeDroughtIndexPoint(droughtIndex index, int timescale, i return false; } - if (!loadMeteoPointsData(firstDate, lastDate, loadHourly, loadDaily, showInfo)) + if (! loadMeteoPointsData(firstDate, lastDate, loadHourly, loadDaily, showInfo)) { logError("There are no data"); return false; @@ -3859,6 +3860,7 @@ bool PragaProject::computeDroughtIndexPoint(droughtIndex index, int timescale, i return true; } + bool PragaProject::computeDroughtIndexPointGUI(droughtIndex index, int timescale, int refYearStart, int refYearEnd, QDate myDate) { // check meteo point @@ -3968,6 +3970,7 @@ bool PragaProject::computeDroughtIndexPointGUI(droughtIndex index, int timescale return res; } + bool PragaProject::activeMeteoGridCellsWithDEM() { diff --git a/pragaProject/pragaShell.cpp b/pragaProject/pragaShell.cpp index 14f1fb5d..3ae30e3f 100644 --- a/pragaProject/pragaShell.cpp +++ b/pragaProject/pragaShell.cpp @@ -1,4 +1,5 @@ #include "pragaShell.h" +#include "pragaProject.h" #include "shell.h" #include "utilities.h" #include "commonConstants.h" @@ -975,9 +976,9 @@ int pragaShell(PragaProject* myProject) return PRAGA_OK; } + int cmdDroughtIndexPoint(PragaProject* myProject, QList argumentList) { - if (argumentList.size() < 5) { myProject->logError("Missing parameters for computing drought index point"); @@ -1041,6 +1042,7 @@ int pragaShell(PragaProject* myProject) } } } + if (! myProject->computeDroughtIndexPoint(index, timescale, ry1, ry2)) { return PRAGA_ERROR; @@ -1049,6 +1051,7 @@ int pragaShell(PragaProject* myProject) return PRAGA_OK; } + int cmdSaveLogDataProceduresGrid(PragaProject* myProject, QList argumentList) { if (argumentList.size() < 3) diff --git a/project/project.cpp b/project/project.cpp index 2b37dbdd..c53697d9 100644 --- a/project/project.cpp +++ b/project/project.cpp @@ -1384,7 +1384,7 @@ bool Project::loadAggregationdDB(QString dbName) logError(aggregationDbHandler->error()); return false; } - if (!aggregationDbHandler->loadVariableProperties()) + if (! aggregationDbHandler->loadVariableProperties()) { return false; } @@ -3065,7 +3065,7 @@ bool Project::loadProject() if (dbAggregationFileName != "") { - if (! loadAggregationdDB(projectPath+"/"+dbAggregationFileName)) + if (! loadAggregationdDB(projectPath + "/" + dbAggregationFileName)) { errorString = "load Aggregation DB failed"; errorType = ERROR_DBPOINT; From d571bbc71088e311a5086ab0cc7deb1f8adb8f36 Mon Sep 17 00:00:00 2001 From: Caterina Toscano Date: Thu, 14 Mar 2024 16:33:19 +0100 Subject: [PATCH 18/72] changed random first guess in Marquardt --- mathFunctions/furtherMathFunctions.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/mathFunctions/furtherMathFunctions.cpp b/mathFunctions/furtherMathFunctions.cpp index 8f50d6b3..afccca7c 100644 --- a/mathFunctions/furtherMathFunctions.cpp +++ b/mathFunctions/furtherMathFunctions.cpp @@ -1065,10 +1065,12 @@ namespace interpolation //int iRandom = 0; int counter = 0; - srand (unsigned(time(nullptr))); - //std::random_device rd; - //std::mt19937 gen(rd()); + //srand (unsigned(time(nullptr))); + std::random_device rd; + std::mt19937 gen(rd()); //std::uniform_real_distribution dis(0.0, 1.0); + std::normal_distribution normal_dis(0.5, 0.2); + double truncNormal; double randomNumber; do { @@ -1076,8 +1078,12 @@ namespace interpolation { for (j=0; j= 1.0); + parameters[i][j] = parametersMin[i][j] + (truncNormal)*(parametersMax[i][j]-parametersMin[i][j]); } } fittingMarquardt_nDimension(func,myFunc,parametersMin, parametersMax, From c4604f7d457dd64b61a7af6598697ab96fc02d48 Mon Sep 17 00:00:00 2001 From: ftomei Date: Thu, 14 Mar 2024 17:04:32 +0100 Subject: [PATCH 19/72] fix drought --- drought/drought.cpp | 2 ++ pragaProject/pragaProject.cpp | 57 +++++++++++++++++++++++------------ 2 files changed, 40 insertions(+), 19 deletions(-) diff --git a/drought/drought.cpp b/drought/drought.cpp index d682f060..8c7f8d96 100644 --- a/drought/drought.cpp +++ b/drought/drought.cpp @@ -79,6 +79,7 @@ void Drought::setComputeAll(bool value) computeAll = value; } + float Drought::computeDroughtIndex() { @@ -196,6 +197,7 @@ float Drought::computeDroughtIndex() return droughtResults[end]; } + bool Drought::computeSpiParameters() { if (meteoPoint->nrObsDataDaysM == 0) diff --git a/pragaProject/pragaProject.cpp b/pragaProject/pragaProject.cpp index 586f8c89..0578cfa6 100644 --- a/pragaProject/pragaProject.cpp +++ b/pragaProject/pragaProject.cpp @@ -3690,9 +3690,11 @@ bool PragaProject::computeDroughtIndexGrid(droughtIndex index, int firstYear, in logInfoGUI("Load monthly grid data..."); qApp->processEvents(); - meteoGridDbHandler->loadGridAllMonthlyData(errorString, firstDate, lastDate); + bool isOk = meteoGridDbHandler->loadGridAllMonthlyData(errorString, firstDate, lastDate); closeLogInfo(); + if (! isOk) return false; + setProgressBar("Drought Index - Meteo Grid", meteoGridDbHandler->meteoGrid()->gridStructure().header().nrRows); for (unsigned row = 0; row < unsigned(meteoGridDbHandler->meteoGrid()->gridStructure().header().nrRows); row++) { @@ -3819,44 +3821,51 @@ bool PragaProject::computeDroughtIndexPoint(droughtIndex index, int timescale, i { meteoPoints[i].computeMonthlyAggregate(getCrit3DDate(firstDate), getCrit3DDate(lastDate), dailyMeteoVar[j], meteoSettings, quality, &climateParameters); } + while(myDate <= lastDate) { - Drought mydrought(index, refYearStart, refYearEnd, getCrit3DDate(myDate), &(meteoPoints[i]), meteoSettings); + Drought myDrought(index, refYearStart, refYearEnd, getCrit3DDate(myDate), &(meteoPoints[i]), meteoSettings); if (timescale > 0) { - mydrought.setTimeScale(timescale); + myDrought.setTimeScale(timescale); } if (index == INDEX_DECILES) { - if (mydrought.computePercentileValuesCurrentDay()) + if (myDrought.computePercentileValuesCurrentDay()) { - value = mydrought.getCurrentPercentileValue(); + value = myDrought.getCurrentPercentileValue(); } } else if (index == INDEX_SPI || index == INDEX_SPEI) { - value = mydrought.computeDroughtIndex(); + value = myDrought.computeDroughtIndex(); } - listEntries.push_back(QString("(%1,%2,'%3',%4,%5,'%6',%7,%8)").arg(QString::number(myDate.year())).arg(QString::number(myDate.month())) - .arg(QString::fromStdString(meteoPoints[i].id)).arg(QString::number(refYearStart)).arg(QString::number(refYearEnd)).arg(indexStr) - .arg(QString::number(timescale)).arg(QString::number(value))); + + listEntries.push_back(QString("(%1,%2,'%3',%4,%5,'%6',%7,%8)").arg(QString::number(myDate.year()), QString::number(myDate.month()), + QString::fromStdString(meteoPoints[i].id), + QString::number(refYearStart), QString::number(refYearEnd), + indexStr, QString::number(timescale), QString::number(value))); myDate = myDate.addMonths(1); } } + if (listEntries.empty()) { logError("Failed to compute droughtIndex "); return false; } - if (!aggregationDbHandler->writeDroughtDataList(listEntries, &errorString)) + + if (! aggregationDbHandler->writeDroughtDataList(listEntries, &errorString)) { logError("Failed to write droughtIndex "+errorString); return false; } + if (showInfo) { logInfo("droughtIndex saved"); } + return true; } @@ -3929,10 +3938,10 @@ bool PragaProject::computeDroughtIndexPointGUI(droughtIndex index, int timescale std::vector dailyMeteoVar; dailyMeteoVar.push_back(dailyPrecipitation); dailyMeteoVar.push_back(dailyReferenceEvapotranspirationHS); - bool res = false; + bool isOk = false; int nrMonths = (lastDate.year()-firstDate.year())*12+lastDate.month()-(firstDate.month()-1); - for (int i=0; i < nrMeteoPoints; i++) + for (int i = 0; i < nrMeteoPoints; i++) { if (showInfo && (i % step) == 0) { @@ -3945,29 +3954,39 @@ bool PragaProject::computeDroughtIndexPointGUI(droughtIndex index, int timescale { meteoPoints[i].computeMonthlyAggregate(getCrit3DDate(firstDate), getCrit3DDate(lastDate), dailyMeteoVar[j], meteoSettings, quality, &climateParameters); } - Drought mydrought(index, refYearStart, refYearEnd, getCrit3DDate(myDate), &(meteoPoints[i]), meteoSettings); + + Drought myDrought(index, refYearStart, refYearEnd, getCrit3DDate(myDate), &(meteoPoints[i]), meteoSettings); + if (timescale > 0) { - mydrought.setTimeScale(timescale); + myDrought.setTimeScale(timescale); } + if (index == INDEX_DECILES) { - if (mydrought.computePercentileValuesCurrentDay()) + if (myDrought.computePercentileValuesCurrentDay()) + { + value = myDrought.getCurrentPercentileValue(); + } + else { - value = mydrought.getCurrentPercentileValue(); + value = NODATA; } } else if (index == INDEX_SPI || index == INDEX_SPEI) { - value = mydrought.computeDroughtIndex(); + value = myDrought.computeDroughtIndex(); } + meteoPoints[i].elaboration = value; + if (value != NODATA) { - res = true; + isOk = true; } } - return res; + + return isOk; } From 7e29897f5152504ba3b319fae0f08d54a8e72797 Mon Sep 17 00:00:00 2001 From: ftomei Date: Thu, 14 Mar 2024 17:18:15 +0100 Subject: [PATCH 20/72] fix drought --- dbMeteoGrid/dbMeteoGrid.cpp | 2 +- pragaProject/pragaProject.cpp | 20 +++++++++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/dbMeteoGrid/dbMeteoGrid.cpp b/dbMeteoGrid/dbMeteoGrid.cpp index 58e7903a..73e55ea3 100644 --- a/dbMeteoGrid/dbMeteoGrid.cpp +++ b/dbMeteoGrid/dbMeteoGrid.cpp @@ -2306,7 +2306,7 @@ bool Crit3DMeteoGridDbHandler::loadGridAllMonthlyData(QString &myError, QDate fi { if (! _meteoGrid->findMeteoPointFromId(&row, &col, pointCode.toStdString()) ) { - myError = "Missing MeteoPoint id"; + myError = "Missing cell id: " + pointCode; return false; } lastPointCode = pointCode; diff --git a/pragaProject/pragaProject.cpp b/pragaProject/pragaProject.cpp index 0578cfa6..a8341b02 100644 --- a/pragaProject/pragaProject.cpp +++ b/pragaProject/pragaProject.cpp @@ -3674,8 +3674,6 @@ bool PragaProject::computeDroughtIndexGrid(droughtIndex index, int firstYear, in return false; } - bool res = false; - QDate firstDate(firstYear, 1, 1); QDate lastDate; int maxYear = std::max(lastYear, date.year()); @@ -3693,8 +3691,17 @@ bool PragaProject::computeDroughtIndexGrid(droughtIndex index, int firstYear, in bool isOk = meteoGridDbHandler->loadGridAllMonthlyData(errorString, firstDate, lastDate); closeLogInfo(); - if (! isOk) return false; + if (! isOk) + { + if (! errorString.isEmpty()) + logError(); + else + logError("No data."); + + return false; + } + isOk = false; setProgressBar("Drought Index - Meteo Grid", meteoGridDbHandler->meteoGrid()->gridStructure().header().nrRows); for (unsigned row = 0; row < unsigned(meteoGridDbHandler->meteoGrid()->gridStructure().header().nrRows); row++) { @@ -3727,14 +3734,17 @@ bool PragaProject::computeDroughtIndexGrid(droughtIndex index, int firstYear, in } if (meteoGridDbHandler->meteoGrid()->meteoPointPointer(row,col)->elaboration != NODATA) { - res = true; + isOk = true; } } } } closeProgressBar(); - return res; + if (! isOk) + logError("No data."); + + return isOk; } From 932ca76914f8971170986106366a55d09f041588 Mon Sep 17 00:00:00 2001 From: ftomei Date: Thu, 14 Mar 2024 17:53:43 +0100 Subject: [PATCH 21/72] fix drought --- dbMeteoGrid/dbMeteoGrid.cpp | 8 +++++--- drought/drought.cpp | 15 +++++++++------ pragaProject/pragaProject.cpp | 2 ++ 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/dbMeteoGrid/dbMeteoGrid.cpp b/dbMeteoGrid/dbMeteoGrid.cpp index 73e55ea3..e52e77cb 100644 --- a/dbMeteoGrid/dbMeteoGrid.cpp +++ b/dbMeteoGrid/dbMeteoGrid.cpp @@ -2306,15 +2306,14 @@ bool Crit3DMeteoGridDbHandler::loadGridAllMonthlyData(QString &myError, QDate fi { if (! _meteoGrid->findMeteoPointFromId(&row, &col, pointCode.toStdString()) ) { - myError = "Missing cell id: " + pointCode; - return false; + continue; } lastPointCode = pointCode; } if (! getValue(qry.value("VariableCode"), &varCode)) { - myError = "Missing VariableCode"; + myError = "Missing VariableCode: " + QString::number(varCode); return false; } @@ -2330,7 +2329,10 @@ bool Crit3DMeteoGridDbHandler::loadGridAllMonthlyData(QString &myError, QDate fi } if (! _meteoGrid->meteoPointPointer(row, col)->setMeteoPointValueM(getCrit3DDate(monthDate), variable, value)) + { + myError = "Error in setMeteoPointValueM()"; return false; + } } } diff --git a/drought/drought.cpp b/drought/drought.cpp index 8c7f8d96..34be75b9 100644 --- a/drought/drought.cpp +++ b/drought/drought.cpp @@ -2,8 +2,11 @@ #include "commonConstants.h" #include "basicMath.h" #include "gammaFunction.h" +#include "meteo.h" + #include + Drought::Drought(droughtIndex index, int firstYear, int lastYear, Crit3DDate date, Crit3DMeteoPoint* meteoPoint, Crit3DMeteoSettings* meteoSettings) { this->index = index; @@ -82,26 +85,25 @@ void Drought::setComputeAll(bool value) float Drought::computeDroughtIndex() { - timeScale = timeScale - 1; // index start from 0 if (index == INDEX_SPI) { - if (!computeSpiParameters()) + if (! computeSpiParameters()) { return NODATA; } } else if (index == INDEX_SPEI) { - if (!computeSpeiParameters()) + if (! computeSpeiParameters()) { return NODATA; } } - int start; - int end; + + int start, end; std::vector mySum(meteoPoint->nrObsDataDaysM); - for (int i = 0; inrObsDataDaysM; i++) + for (int i = 0; i < meteoPoint->nrObsDataDaysM; i++) { droughtResults.push_back(NODATA); } @@ -194,6 +196,7 @@ float Drought::computeDroughtIndex() } } } + return droughtResults[end]; } diff --git a/pragaProject/pragaProject.cpp b/pragaProject/pragaProject.cpp index a8341b02..ce0d0a1f 100644 --- a/pragaProject/pragaProject.cpp +++ b/pragaProject/pragaProject.cpp @@ -3717,6 +3717,7 @@ bool PragaProject::computeDroughtIndexGrid(droughtIndex index, int firstYear, in mydrought.setTimeScale(timescale); } meteoGridDbHandler->meteoGrid()->meteoPointPointer(row,col)->elaboration = NODATA; + if (index == INDEX_DECILES) { if (myVar != noMeteoVar) @@ -3732,6 +3733,7 @@ bool PragaProject::computeDroughtIndexGrid(droughtIndex index, int firstYear, in { meteoGridDbHandler->meteoGrid()->meteoPointPointer(row,col)->elaboration = mydrought.computeDroughtIndex(); } + if (meteoGridDbHandler->meteoGrid()->meteoPointPointer(row,col)->elaboration != NODATA) { isOk = true; From cd213381e9d4cf16d7052a41987deaf701438b2a Mon Sep 17 00:00:00 2001 From: ftomei Date: Thu, 14 Mar 2024 18:45:33 +0100 Subject: [PATCH 22/72] fix drought --- drought/drought.cpp | 2 +- meteo/meteo.h | 6 ++++-- meteo/meteoPoint.cpp | 3 ++- pragaProject/pragaProject.cpp | 16 ++++++++-------- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/drought/drought.cpp b/drought/drought.cpp index 34be75b9..cfedf9fa 100644 --- a/drought/drought.cpp +++ b/drought/drought.cpp @@ -136,7 +136,7 @@ float Drought::computeDroughtIndex() for (int j = start; j <= end; j++) { mySum[j] = 0; - for(int i = 0; i<=timeScale; i++) + for(int i = 0; i <= timeScale; i++) { if ((j-i)>=0 && j < meteoPoint->nrObsDataDaysM) { diff --git a/meteo/meteo.h b/meteo/meteo.h index d640a172..5f9c7d03 100644 --- a/meteo/meteo.h +++ b/meteo/meteo.h @@ -172,7 +172,8 @@ { dailyCoolingDegreeDays, "DAILY_DEGREEDAYS_COOLING" }, { dailyWaterTableDepth, "DAILY_WATER_TABLE_DEPTH" }, { elaboration, "ELABORATION" }, - { anomaly, "ANOMALY" } + { anomaly, "ANOMALY" }, + { noMeteoVar, "NO_VARIABLE" } }; const std::map MapHourlyMeteoVar = { @@ -226,7 +227,8 @@ { snowSurfaceEnergy, "SNOW_SURF_ENERGY"}, { snowInternalEnergy, "SNOW_INT_ENERGY"}, { sensibleHeat, "SENSIBLE_HEAT"}, - { latentHeat, "LATENT_HEAT"} + { latentHeat, "LATENT_HEAT"}, + { noMeteoVar, "NO_VARIABLE" } }; const std::map MapMonthlyMeteoVar = { diff --git a/meteo/meteoPoint.cpp b/meteo/meteoPoint.cpp index 0b5ddb50..e18e7ecf 100644 --- a/meteo/meteoPoint.cpp +++ b/meteo/meteoPoint.cpp @@ -1298,11 +1298,12 @@ bool Crit3DMeteoPoint::computeMonthlyAggregate(Crit3DDate firstDate, Crit3DDate currentMonth = actualDate.addDays(1).month; nrDays = getDaysInMonth(currentMonth, actualDate.year); } - } + return aggregateDailyInMonthly; } + TObsDataH *Crit3DMeteoPoint::getObsDataH() const { return obsDataH; diff --git a/pragaProject/pragaProject.cpp b/pragaProject/pragaProject.cpp index ce0d0a1f..0bb13ad6 100644 --- a/pragaProject/pragaProject.cpp +++ b/pragaProject/pragaProject.cpp @@ -3910,12 +3910,7 @@ bool PragaProject::computeDroughtIndexPointGUI(droughtIndex index, int timescale lastDate.setDate(maxYear,12,1); } - bool loadHourly = false; - bool loadDaily = true; - bool showInfo = true; - float value = NODATA; QString indexStr; - if (index == INDEX_SPI) { indexStr = "SPI"; @@ -3934,9 +3929,12 @@ bool PragaProject::computeDroughtIndexPointGUI(droughtIndex index, int timescale return false; } - if (!loadMeteoPointsData(firstDate, lastDate, loadHourly, loadDaily, showInfo)) + bool loadHourly = false; + bool loadDaily = true; + bool showInfo = true; + if (! loadMeteoPointsData(firstDate, lastDate, loadHourly, loadDaily, showInfo)) { - logError("There are no data"); + logError("No data."); return false; } @@ -3950,9 +3948,11 @@ bool PragaProject::computeDroughtIndexPointGUI(droughtIndex index, int timescale std::vector dailyMeteoVar; dailyMeteoVar.push_back(dailyPrecipitation); dailyMeteoVar.push_back(dailyReferenceEvapotranspirationHS); + bool isOk = false; + float value = NODATA; - int nrMonths = (lastDate.year()-firstDate.year())*12+lastDate.month()-(firstDate.month()-1); + int nrMonths = (lastDate.year()-firstDate.year())*12 + lastDate.month() - (firstDate.month()-1); for (int i = 0; i < nrMeteoPoints; i++) { if (showInfo && (i % step) == 0) From 7b888462eefce71d88d0df41159ea571993d6e5b Mon Sep 17 00:00:00 2001 From: ftomei Date: Thu, 14 Mar 2024 19:00:37 +0100 Subject: [PATCH 23/72] fix drought --- pragaProject/pragaProject.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pragaProject/pragaProject.cpp b/pragaProject/pragaProject.cpp index 0bb13ad6..a8e8ee8c 100644 --- a/pragaProject/pragaProject.cpp +++ b/pragaProject/pragaProject.cpp @@ -3696,7 +3696,7 @@ bool PragaProject::computeDroughtIndexGrid(droughtIndex index, int firstYear, in if (! errorString.isEmpty()) logError(); else - logError("No data."); + logError("No monthly data."); return false; } @@ -3744,7 +3744,7 @@ bool PragaProject::computeDroughtIndexGrid(droughtIndex index, int firstYear, in closeProgressBar(); if (! isOk) - logError("No data."); + logError("Missing data."); return isOk; } From 7471a18e9a44e865a9294ea6d72f46f5a8684c0a Mon Sep 17 00:00:00 2001 From: Antonio Volta Date: Fri, 15 Mar 2024 09:20:33 +0100 Subject: [PATCH 24/72] aggiunta commenti --- mathFunctions/furtherMathFunctions.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mathFunctions/furtherMathFunctions.cpp b/mathFunctions/furtherMathFunctions.cpp index afccca7c..3104daae 100644 --- a/mathFunctions/furtherMathFunctions.cpp +++ b/mathFunctions/furtherMathFunctions.cpp @@ -1227,7 +1227,7 @@ namespace interpolation } } iterationNr++; - } while (iterationNr <= maxIterationsNr && fabs(diffSSE) > myEpsilon); + } while (fabs(diffSSE) > myEpsilon && iterationNr <= maxIterationsNr); return (fabs(diffSSE) <= myEpsilon); } @@ -1255,6 +1255,7 @@ namespace interpolation std::vector firstEst(nrData); std::vector> a(nrParametersTotal, std::vector(nrParametersTotal)); std::vector> P(nrParametersTotal, std::vector(nrData)); + // matrix P corresponds to the Jacobian // first set of estimates for (i = 0; i < nrData; i++) { @@ -1341,6 +1342,7 @@ namespace interpolation } } + // linear system resolution in order to get the Delta of each parameter parametersChange[nrPredictors - 1][nrParameters[nrPredictors-1]-1] = g[nrParametersTotal - 1] / a[nrParametersTotal - 1][nrParametersTotal - 1]; From 84a6bc3465f6bb3146cf698c9945cd69f0ca381f Mon Sep 17 00:00:00 2001 From: gantolini Date: Fri, 15 Mar 2024 11:26:08 +0100 Subject: [PATCH 25/72] bug fixed --- project/interpolationCmd.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project/interpolationCmd.cpp b/project/interpolationCmd.cpp index 9132e1d9..a86fc1ce 100644 --- a/project/interpolationCmd.cpp +++ b/project/interpolationCmd.cpp @@ -181,7 +181,7 @@ bool interpolateProxyGridSeries(const Crit3DProxyGridSeries& mySeries, QDate myD return false; } - if (! gis::readEsriGrid(gridNames[second].toStdString(), &secondGrid, myError)) return false; + if (! gis::readEsriGrid(gridNames[second].toStdString(), &secondGrid, myError)) { *error = QString::fromStdString(myError); return false; From fae7ea45093684b74e757ce53f1804167449d3f6 Mon Sep 17 00:00:00 2001 From: lauracosta Date: Fri, 15 Mar 2024 12:08:00 +0100 Subject: [PATCH 26/72] fix elaborationPointsCycleGrid startDate endDate --- pragaProject/pragaProject.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pragaProject/pragaProject.cpp b/pragaProject/pragaProject.cpp index a8e8ee8c..96072bee 100644 --- a/pragaProject/pragaProject.cpp +++ b/pragaProject/pragaProject.cpp @@ -944,16 +944,23 @@ bool PragaProject::elaborationPointsCycleGrid(bool isAnomaly, bool showInfo) } } - QDate startDate(climaUsed->yearStart(), climaUsed->genericPeriodDateStart().month(), climaUsed->genericPeriodDateStart().day()); - QDate endDate(climaUsed->yearEnd(), climaUsed->genericPeriodDateEnd().month(), climaUsed->genericPeriodDateEnd().day()); + QDate startDate; + QDate endDate; if (climaUsed->nYears() > 0) { + startDate.setDate(climaUsed->yearStart(), climaUsed->genericPeriodDateStart().month(), climaUsed->genericPeriodDateStart().day()); endDate.setDate(climaUsed->yearEnd() + climaUsed->nYears(), climaUsed->genericPeriodDateEnd().month(), climaUsed->genericPeriodDateEnd().day()); } else if (climaUsed->nYears() < 0) { startDate.setDate(climaUsed->yearStart() + climaUsed->nYears(), climaUsed->genericPeriodDateStart().month(), climaUsed->genericPeriodDateStart().day()); + endDate.setDate(climaUsed->yearEnd(), climaUsed->genericPeriodDateEnd().month(), climaUsed->genericPeriodDateEnd().day()); + } + else + { + startDate.setDate(climaUsed->yearStart(), climaUsed->genericPeriodDateStart().month(), climaUsed->genericPeriodDateStart().day()); + endDate.setDate(climaUsed->yearEnd(), climaUsed->genericPeriodDateEnd().month(), climaUsed->genericPeriodDateEnd().day()); } bool dataAlreadyLoaded = false; From f601becab9e061606eeaa36b3ff5bedd6eb35cae Mon Sep 17 00:00:00 2001 From: lauracosta Date: Fri, 15 Mar 2024 12:08:00 +0100 Subject: [PATCH 27/72] fix elaborationPointsCycleGrid startDate endDate --- pragaProject/pragaProject.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pragaProject/pragaProject.cpp b/pragaProject/pragaProject.cpp index a8e8ee8c..96072bee 100644 --- a/pragaProject/pragaProject.cpp +++ b/pragaProject/pragaProject.cpp @@ -944,16 +944,23 @@ bool PragaProject::elaborationPointsCycleGrid(bool isAnomaly, bool showInfo) } } - QDate startDate(climaUsed->yearStart(), climaUsed->genericPeriodDateStart().month(), climaUsed->genericPeriodDateStart().day()); - QDate endDate(climaUsed->yearEnd(), climaUsed->genericPeriodDateEnd().month(), climaUsed->genericPeriodDateEnd().day()); + QDate startDate; + QDate endDate; if (climaUsed->nYears() > 0) { + startDate.setDate(climaUsed->yearStart(), climaUsed->genericPeriodDateStart().month(), climaUsed->genericPeriodDateStart().day()); endDate.setDate(climaUsed->yearEnd() + climaUsed->nYears(), climaUsed->genericPeriodDateEnd().month(), climaUsed->genericPeriodDateEnd().day()); } else if (climaUsed->nYears() < 0) { startDate.setDate(climaUsed->yearStart() + climaUsed->nYears(), climaUsed->genericPeriodDateStart().month(), climaUsed->genericPeriodDateStart().day()); + endDate.setDate(climaUsed->yearEnd(), climaUsed->genericPeriodDateEnd().month(), climaUsed->genericPeriodDateEnd().day()); + } + else + { + startDate.setDate(climaUsed->yearStart(), climaUsed->genericPeriodDateStart().month(), climaUsed->genericPeriodDateStart().day()); + endDate.setDate(climaUsed->yearEnd(), climaUsed->genericPeriodDateEnd().month(), climaUsed->genericPeriodDateEnd().day()); } bool dataAlreadyLoaded = false; From 19a0e5f4aa409120ebea78b182871d212fafd1ef Mon Sep 17 00:00:00 2001 From: lauracosta Date: Fri, 15 Mar 2024 15:15:12 +0100 Subject: [PATCH 28/72] check leap year --- pragaProject/pragaProject.cpp | 108 +++++++++++++++++++++++++++++++--- 1 file changed, 101 insertions(+), 7 deletions(-) diff --git a/pragaProject/pragaProject.cpp b/pragaProject/pragaProject.cpp index 96072bee..023d71e1 100644 --- a/pragaProject/pragaProject.cpp +++ b/pragaProject/pragaProject.cpp @@ -946,23 +946,117 @@ bool PragaProject::elaborationPointsCycleGrid(bool isAnomaly, bool showInfo) QDate startDate; QDate endDate; - if (climaUsed->nYears() > 0) { - startDate.setDate(climaUsed->yearStart(), climaUsed->genericPeriodDateStart().month(), climaUsed->genericPeriodDateStart().day()); - endDate.setDate(climaUsed->yearEnd() + climaUsed->nYears(), climaUsed->genericPeriodDateEnd().month(), climaUsed->genericPeriodDateEnd().day()); + int myYearStart = climaUsed->yearStart(); + int myYearEnd = climaUsed->yearEnd() + climaUsed->nYears(); + startDate.setDate(myYearStart, climaUsed->genericPeriodDateStart().month(), climaUsed->genericPeriodDateStart().day()); + endDate.setDate(myYearEnd, climaUsed->genericPeriodDateEnd().month(), climaUsed->genericPeriodDateEnd().day()); + // check dates - leap case + if (climaUsed->genericPeriodDateStart().month() == 2 && climaUsed->genericPeriodDateStart().day() == 29) + { + if (!isLeapYear(myYearStart)) + { + if (climaUsed->periodType() != dailyPeriod) + { + startDate.setDate(myYearStart, 2, 28); + } + else + { + startDate.setDate(myYearStart, 3, 1); + } + } + } + if (climaUsed->genericPeriodDateEnd().month() == 2 && climaUsed->genericPeriodDateEnd().day() == 29) + { + if (!isLeapYear(myYearEnd)) + { + if (climaUsed->periodType() != dailyPeriod) + { + endDate.setDate(myYearEnd, 2, 28); + } + else + { + endDate.setDate(myYearEnd, 3, 1); + } + } + } } else if (climaUsed->nYears() < 0) { - startDate.setDate(climaUsed->yearStart() + climaUsed->nYears(), climaUsed->genericPeriodDateStart().month(), climaUsed->genericPeriodDateStart().day()); - endDate.setDate(climaUsed->yearEnd(), climaUsed->genericPeriodDateEnd().month(), climaUsed->genericPeriodDateEnd().day()); + int myYearStart = climaUsed->yearStart() + climaUsed->nYears(); + int myYearEnd = climaUsed->yearEnd(); + startDate.setDate(myYearStart, climaUsed->genericPeriodDateStart().month(), climaUsed->genericPeriodDateStart().day()); + endDate.setDate(myYearEnd, climaUsed->genericPeriodDateEnd().month(), climaUsed->genericPeriodDateEnd().day()); + // check dates - leap case + if (climaUsed->genericPeriodDateStart().month() == 2 && climaUsed->genericPeriodDateStart().day() == 29) + { + if (!isLeapYear(myYearStart)) + { + if (climaUsed->periodType() != dailyPeriod) + { + startDate.setDate(myYearStart, 2, 28); + } + else + { + startDate.setDate(myYearStart, 3, 1); + } + } + } + if (climaUsed->genericPeriodDateEnd().month() == 2 && climaUsed->genericPeriodDateEnd().day() == 29) + { + if (!isLeapYear(myYearEnd)) + { + if (climaUsed->periodType() != dailyPeriod) + { + endDate.setDate(myYearEnd, 2, 28); + } + else + { + endDate.setDate(myYearEnd, 3, 1); + } + } + } } else { - startDate.setDate(climaUsed->yearStart(), climaUsed->genericPeriodDateStart().month(), climaUsed->genericPeriodDateStart().day()); - endDate.setDate(climaUsed->yearEnd(), climaUsed->genericPeriodDateEnd().month(), climaUsed->genericPeriodDateEnd().day()); + int myYearStart = climaUsed->yearStart(); + int myYearEnd = climaUsed->yearEnd(); + startDate.setDate(myYearStart, climaUsed->genericPeriodDateStart().month(), climaUsed->genericPeriodDateStart().day()); + endDate.setDate(myYearEnd, climaUsed->genericPeriodDateEnd().month(), climaUsed->genericPeriodDateEnd().day()); + // check dates - leap case + if (climaUsed->genericPeriodDateStart().month() == 2 && climaUsed->genericPeriodDateStart().day() == 29) + { + if (!isLeapYear(myYearStart)) + { + if (climaUsed->periodType() != dailyPeriod) + { + startDate.setDate(myYearStart, 2, 28); + } + else + { + startDate.setDate(myYearStart, 3, 1); + } + } + } + if (climaUsed->genericPeriodDateEnd().month() == 2 && climaUsed->genericPeriodDateEnd().day() == 29) + { + if (!isLeapYear(myYearEnd)) + { + if (climaUsed->periodType() != dailyPeriod) + { + endDate.setDate(myYearEnd, 2, 28); + } + else + { + endDate.setDate(myYearEnd, 3, 1); + } + } + } } + + bool dataAlreadyLoaded = false; for (int row = 0; row < meteoGridDbHandler->gridStructure().header().nrRows; row++) From c9eae11a37ec3ecc0f609a786102e0fbc00b5f86 Mon Sep 17 00:00:00 2001 From: lauracosta Date: Fri, 15 Mar 2024 15:24:51 +0100 Subject: [PATCH 29/72] resolve conflict --- pragaProject/pragaProject.cpp | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/pragaProject/pragaProject.cpp b/pragaProject/pragaProject.cpp index 3f070aa5..c7a45d4e 100644 --- a/pragaProject/pragaProject.cpp +++ b/pragaProject/pragaProject.cpp @@ -1018,23 +1018,6 @@ bool PragaProject::elaborationPointsCycleGrid(bool isAnomaly, bool showInfo) } } } - - - if (climaUsed->nYears() > 0) - { - startDate.setDate(climaUsed->yearStart(), climaUsed->genericPeriodDateStart().month(), climaUsed->genericPeriodDateStart().day()); - endDate.setDate(climaUsed->yearEnd() + climaUsed->nYears(), climaUsed->genericPeriodDateEnd().month(), climaUsed->genericPeriodDateEnd().day()); - } - else if (climaUsed->nYears() < 0) - { - startDate.setDate(climaUsed->yearStart() + climaUsed->nYears(), climaUsed->genericPeriodDateStart().month(), climaUsed->genericPeriodDateStart().day()); - endDate.setDate(climaUsed->yearEnd(), climaUsed->genericPeriodDateEnd().month(), climaUsed->genericPeriodDateEnd().day()); - } - else - { - startDate.setDate(climaUsed->yearStart(), climaUsed->genericPeriodDateStart().month(), climaUsed->genericPeriodDateStart().day()); - endDate.setDate(climaUsed->yearEnd(), climaUsed->genericPeriodDateEnd().month(), climaUsed->genericPeriodDateEnd().day()); ->>>>>>> aa8ff6c55849eccf5df90c86fc7b86fb8bb72e6e } else { From 13d12b2bca1088ed9fdc6163ad10b37183308300 Mon Sep 17 00:00:00 2001 From: lauracosta Date: Fri, 15 Mar 2024 15:30:05 +0100 Subject: [PATCH 30/72] check leap elaborationPointsCycle --- pragaProject/pragaProject.cpp | 124 ++++++++++++++++++++++++++++++---- 1 file changed, 111 insertions(+), 13 deletions(-) diff --git a/pragaProject/pragaProject.cpp b/pragaProject/pragaProject.cpp index c7a45d4e..7e870568 100644 --- a/pragaProject/pragaProject.cpp +++ b/pragaProject/pragaProject.cpp @@ -826,16 +826,116 @@ bool PragaProject::elaborationPointsCycle(bool isAnomaly, bool showInfo) } } - QDate startDate(climaUsed->yearStart(), climaUsed->genericPeriodDateStart().month(), climaUsed->genericPeriodDateStart().day()); - QDate endDate(climaUsed->yearEnd(), climaUsed->genericPeriodDateEnd().month(), climaUsed->genericPeriodDateEnd().day()); + QDate startDate; + QDate endDate; if (climaUsed->nYears() > 0) { - endDate.setDate(climaUsed->yearEnd() + climaUsed->nYears(), climaUsed->genericPeriodDateEnd().month(), climaUsed->genericPeriodDateEnd().day()); + int myYearStart = climaUsed->yearStart(); + int myYearEnd = climaUsed->yearEnd() + climaUsed->nYears(); + startDate.setDate(myYearStart, climaUsed->genericPeriodDateStart().month(), climaUsed->genericPeriodDateStart().day()); + endDate.setDate(myYearEnd, climaUsed->genericPeriodDateEnd().month(), climaUsed->genericPeriodDateEnd().day()); + // check dates - leap case + if (climaUsed->genericPeriodDateStart().month() == 2 && climaUsed->genericPeriodDateStart().day() == 29) + { + if (!isLeapYear(myYearStart)) + { + if (climaUsed->periodType() != dailyPeriod) + { + startDate.setDate(myYearStart, 2, 28); + } + else + { + startDate.setDate(myYearStart, 3, 1); + } + } + } + if (climaUsed->genericPeriodDateEnd().month() == 2 && climaUsed->genericPeriodDateEnd().day() == 29) + { + if (!isLeapYear(myYearEnd)) + { + if (climaUsed->periodType() != dailyPeriod) + { + endDate.setDate(myYearEnd, 2, 28); + } + else + { + endDate.setDate(myYearEnd, 3, 1); + } + } + } } else if (climaUsed->nYears() < 0) { - startDate.setDate(climaUsed->yearStart() + climaUsed->nYears(), climaUsed->genericPeriodDateStart().month(), climaUsed->genericPeriodDateStart().day()); + int myYearStart = climaUsed->yearStart() + climaUsed->nYears(); + int myYearEnd = climaUsed->yearEnd(); + startDate.setDate(myYearStart, climaUsed->genericPeriodDateStart().month(), climaUsed->genericPeriodDateStart().day()); + endDate.setDate(myYearEnd, climaUsed->genericPeriodDateEnd().month(), climaUsed->genericPeriodDateEnd().day()); + // check dates - leap case + if (climaUsed->genericPeriodDateStart().month() == 2 && climaUsed->genericPeriodDateStart().day() == 29) + { + if (!isLeapYear(myYearStart)) + { + if (climaUsed->periodType() != dailyPeriod) + { + startDate.setDate(myYearStart, 2, 28); + } + else + { + startDate.setDate(myYearStart, 3, 1); + } + } + } + if (climaUsed->genericPeriodDateEnd().month() == 2 && climaUsed->genericPeriodDateEnd().day() == 29) + { + if (!isLeapYear(myYearEnd)) + { + if (climaUsed->periodType() != dailyPeriod) + { + endDate.setDate(myYearEnd, 2, 28); + } + else + { + endDate.setDate(myYearEnd, 3, 1); + } + } + } + } + else + { + int myYearStart = climaUsed->yearStart(); + int myYearEnd = climaUsed->yearEnd(); + startDate.setDate(myYearStart, climaUsed->genericPeriodDateStart().month(), climaUsed->genericPeriodDateStart().day()); + endDate.setDate(myYearEnd, climaUsed->genericPeriodDateEnd().month(), climaUsed->genericPeriodDateEnd().day()); + // check dates - leap case + if (climaUsed->genericPeriodDateStart().month() == 2 && climaUsed->genericPeriodDateStart().day() == 29) + { + if (!isLeapYear(myYearStart)) + { + if (climaUsed->periodType() != dailyPeriod) + { + startDate.setDate(myYearStart, 2, 28); + } + else + { + startDate.setDate(myYearStart, 3, 1); + } + } + } + if (climaUsed->genericPeriodDateEnd().month() == 2 && climaUsed->genericPeriodDateEnd().day() == 29) + { + if (!isLeapYear(myYearEnd)) + { + if (climaUsed->periodType() != dailyPeriod) + { + endDate.setDate(myYearEnd, 2, 28); + } + else + { + endDate.setDate(myYearEnd, 3, 1); + } + } + } } @@ -1056,17 +1156,15 @@ bool PragaProject::elaborationPointsCycleGrid(bool isAnomaly, bool showInfo) } } + bool dataAlreadyLoaded = false; + for (int row = 0; row < meteoGridDbHandler->gridStructure().header().nrRows; row++) + { + if (showInfo && (row % infoStep) == 0) + updateProgressBar(row); - bool dataAlreadyLoaded = false; - - for (int row = 0; row < meteoGridDbHandler->gridStructure().header().nrRows; row++) - { - if (showInfo && (row % infoStep) == 0) - updateProgressBar(row); - - for (int col = 0; col < meteoGridDbHandler->gridStructure().header().nrCols; col++) - { + for (int col = 0; col < meteoGridDbHandler->gridStructure().header().nrCols; col++) + { if (meteoGridDbHandler->meteoGrid()->getMeteoPointActiveId(row, col, &id)) { From c7e0a71a44fece028fc9dd10ed2c14298fd0abb7 Mon Sep 17 00:00:00 2001 From: ftomei Date: Fri, 15 Mar 2024 19:24:40 +0100 Subject: [PATCH 31/72] update 3D --- meteo/meteo.h | 6 +++++ outputPoints/dbOutputPointsHandler.cpp | 37 +++++++++++++++++++++++++- outputPoints/dbOutputPointsHandler.h | 4 ++- 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/meteo/meteo.h b/meteo/meteo.h index 5f9c7d03..edd95cfa 100644 --- a/meteo/meteo.h +++ b/meteo/meteo.h @@ -105,6 +105,12 @@ noMeteoVar}; + enum criteria3DVariable {volumetricWaterContent, waterTotalPotential, waterMatricPotential, + availableWaterContent, degreeOfSaturation, soilTemperature, + soilSurfaceMoisture, bottomDrainage, waterDeficit, waterInflow, waterOutflow, + factorOfSafety}; + + const std::map MapDailyMeteoVar = { { "DAILY_TMIN", dailyAirTemperatureMin }, { "DAILY_TMAX", dailyAirTemperatureMax }, diff --git a/outputPoints/dbOutputPointsHandler.cpp b/outputPoints/dbOutputPointsHandler.cpp index 3d96777b..4e8c9b04 100644 --- a/outputPoints/dbOutputPointsHandler.cpp +++ b/outputPoints/dbOutputPointsHandler.cpp @@ -1,6 +1,7 @@ #include "dbOutputPointsHandler.h" #include "commonConstants.h" #include "utilities.h" +#include "meteo.h" #include @@ -100,7 +101,41 @@ bool Crit3DOutputPointsDbHandler::addColumn(QString tableName, meteoVariable myV } -bool Crit3DOutputPointsDbHandler::saveHourlyData(QString tableName, const QDateTime& myTime, +// depth [cm] +bool Crit3DOutputPointsDbHandler::addCriteria3DColumn(const QString &tableName, criteria3DVariable myVar, int depth, QString& errorStr) +{ + // column name + /* + QString newField = QString::fromStdString(getMeteoVarName(myVar)); + if (newField == "") + { + errorStr = "Missing variable name."; + return false; + } + + // column exists already + QList fieldList = getFields(&_db, tableName); + if (fieldList.contains(newField)) + { + return true; + } + + // add column + QString queryString = "ALTER TABLE '" + tableName + "'"; + queryString += " ADD " + newField + " REAL"; + + QSqlQuery myQuery = _db.exec(queryString); + if (myQuery.lastError().isValid()) + { + errorStr = "Error in add column: " + newField + "\n" + myQuery.lastError().text(); + return false; + } +*/ + return true; +} + + +bool Crit3DOutputPointsDbHandler::saveHourlyMeteoData(QString tableName, const QDateTime& myTime, const std::vector& varList, const std::vector& values, QString& errorStr) diff --git a/outputPoints/dbOutputPointsHandler.h b/outputPoints/dbOutputPointsHandler.h index e2b446aa..467da87b 100644 --- a/outputPoints/dbOutputPointsHandler.h +++ b/outputPoints/dbOutputPointsHandler.h @@ -22,7 +22,9 @@ bool createTable(QString tableName, QString &errorStr); bool addColumn(QString tableName, meteoVariable myVar, QString &errorString); - bool saveHourlyData(QString tableName, const QDateTime &myTime, + bool addCriteria3DColumn(const QString &tableName, criteria3DVariable myVar, int depth, QString& errorStr); + + bool saveHourlyMeteoData(QString tableName, const QDateTime &myTime, const std::vector &varList, const std::vector &values, QString& errorStr); From 17859469c93684a1b0ff0df56c4ef1fc81fef7f1 Mon Sep 17 00:00:00 2001 From: ftomei Date: Fri, 15 Mar 2024 19:41:34 +0100 Subject: [PATCH 32/72] fix warning --- mathFunctions/furtherMathFunctions.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/mathFunctions/furtherMathFunctions.cpp b/mathFunctions/furtherMathFunctions.cpp index 3104daae..6804e75f 100644 --- a/mathFunctions/furtherMathFunctions.cpp +++ b/mathFunctions/furtherMathFunctions.cpp @@ -1071,7 +1071,6 @@ namespace interpolation //std::uniform_real_distribution dis(0.0, 1.0); std::normal_distribution normal_dis(0.5, 0.2); double truncNormal; - double randomNumber; do { for (i=0; i Date: Mon, 18 Mar 2024 10:40:12 +0100 Subject: [PATCH 33/72] aggiunta commento --- mathFunctions/furtherMathFunctions.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mathFunctions/furtherMathFunctions.cpp b/mathFunctions/furtherMathFunctions.cpp index 6804e75f..08798fe7 100644 --- a/mathFunctions/furtherMathFunctions.cpp +++ b/mathFunctions/furtherMathFunctions.cpp @@ -76,7 +76,7 @@ double lapseRatePiecewise(double x, std::vector & par) xb = par[0]+par[2]; if (x < par[0]) { - //m = par[4]; + //m = par[4];; //q = par[1]-m*par[0]; return par[4]*x + par[1]-par[4]*par[0]; } From e8b851ca0c486e9a8d43395cb92347b0e259dbda Mon Sep 17 00:00:00 2001 From: lauracosta Date: Mon, 18 Mar 2024 11:43:40 +0100 Subject: [PATCH 34/72] fix fixed multipoint --- inOutDataXML/inOutDataXML.cpp | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/inOutDataXML/inOutDataXML.cpp b/inOutDataXML/inOutDataXML.cpp index 6e84a378..489d1de9 100644 --- a/inOutDataXML/inOutDataXML.cpp +++ b/inOutDataXML/inOutDataXML.cpp @@ -499,9 +499,12 @@ bool InOutDataXML::importXMLDataFixed(QString& errorStr) QString myPointCode = ""; QString previousPointCode = ""; - if (! checkPointCodeFromFileName(myPointCode, errorStr)) + if (format_isSinglePoint) { - return false; + if (! checkPointCodeFromFileName(myPointCode, errorStr)) + { + return false; + } } QTextStream in(&myFile); @@ -801,9 +804,12 @@ bool InOutDataXML::importXMLDataDelimited(QString& errorStr) QString myPointCode = ""; QString previousPointCode = ""; - if (! checkPointCodeFromFileName(myPointCode, errorStr)) + if (format_isSinglePoint) { - return false; + if (! checkPointCodeFromFileName(myPointCode, errorStr)) + { + return false; + } } QTextStream in(&myFile); @@ -1140,14 +1146,24 @@ bool InOutDataXML::importXMLDataDelimited(QString& errorStr) QString InOutDataXML::parseXMLPointCode(QString text) { QString myPointCode = ""; + QString substring = ""; - if (pointCode.getType().toUpper() == "FIELDDEFINED" || pointCode.getType().toUpper() == "FIELDEFINED" || pointCode.getType().toUpper() == "FILENAMEDEFINED") + if (pointCode.getType().toUpper() == "FIELDDEFINED" || pointCode.getType().toUpper() == "FIELDEFINED" || pointCode.getType().toUpper() == "FILENAMEDEFINED" || pointCode.getType().toUpper() == "FIXED") { if (format_type == XMLFORMATFIXED || (format_type == XMLFORMATDELIMITED && pointCode.getType().toUpper() == "FILENAMEDEFINED")) { if (fileName_pragaName.isEmpty()) { - QString substring = text.mid(0,pointCode.getNrChar()); + if (pointCode.getType().toUpper() == "FILENAMEDEFINED") + { + // text is the name of the file + substring = text.mid(0,pointCode.getNrChar()); + } + else + { + // text is a line, firstChar start from 1 + substring = text.mid(pointCode.getFirstChar()-1,pointCode.getNrChar()); + } if (pointCode.getFormat().isEmpty() || pointCode.getFormat() == "%s") { // pointCode is a string From 383b4d38528430e11a5acbe2a342f8ec8f3ce774 Mon Sep 17 00:00:00 2001 From: lauracosta Date: Mon, 18 Mar 2024 11:43:40 +0100 Subject: [PATCH 35/72] fix fixed multipoint --- inOutDataXML/inOutDataXML.cpp | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/inOutDataXML/inOutDataXML.cpp b/inOutDataXML/inOutDataXML.cpp index 6e84a378..489d1de9 100644 --- a/inOutDataXML/inOutDataXML.cpp +++ b/inOutDataXML/inOutDataXML.cpp @@ -499,9 +499,12 @@ bool InOutDataXML::importXMLDataFixed(QString& errorStr) QString myPointCode = ""; QString previousPointCode = ""; - if (! checkPointCodeFromFileName(myPointCode, errorStr)) + if (format_isSinglePoint) { - return false; + if (! checkPointCodeFromFileName(myPointCode, errorStr)) + { + return false; + } } QTextStream in(&myFile); @@ -801,9 +804,12 @@ bool InOutDataXML::importXMLDataDelimited(QString& errorStr) QString myPointCode = ""; QString previousPointCode = ""; - if (! checkPointCodeFromFileName(myPointCode, errorStr)) + if (format_isSinglePoint) { - return false; + if (! checkPointCodeFromFileName(myPointCode, errorStr)) + { + return false; + } } QTextStream in(&myFile); @@ -1140,14 +1146,24 @@ bool InOutDataXML::importXMLDataDelimited(QString& errorStr) QString InOutDataXML::parseXMLPointCode(QString text) { QString myPointCode = ""; + QString substring = ""; - if (pointCode.getType().toUpper() == "FIELDDEFINED" || pointCode.getType().toUpper() == "FIELDEFINED" || pointCode.getType().toUpper() == "FILENAMEDEFINED") + if (pointCode.getType().toUpper() == "FIELDDEFINED" || pointCode.getType().toUpper() == "FIELDEFINED" || pointCode.getType().toUpper() == "FILENAMEDEFINED" || pointCode.getType().toUpper() == "FIXED") { if (format_type == XMLFORMATFIXED || (format_type == XMLFORMATDELIMITED && pointCode.getType().toUpper() == "FILENAMEDEFINED")) { if (fileName_pragaName.isEmpty()) { - QString substring = text.mid(0,pointCode.getNrChar()); + if (pointCode.getType().toUpper() == "FILENAMEDEFINED") + { + // text is the name of the file + substring = text.mid(0,pointCode.getNrChar()); + } + else + { + // text is a line, firstChar start from 1 + substring = text.mid(pointCode.getFirstChar()-1,pointCode.getNrChar()); + } if (pointCode.getFormat().isEmpty() || pointCode.getFormat() == "%s") { // pointCode is a string From 325cc9fe829bf6a412342d9789a226a271dd1d48 Mon Sep 17 00:00:00 2001 From: lauracosta Date: Mon, 18 Mar 2024 13:06:24 +0100 Subject: [PATCH 36/72] check pos value --- inOutDataXML/inOutDataXML.cpp | 78 +++++++++++++++++------------------ 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/inOutDataXML/inOutDataXML.cpp b/inOutDataXML/inOutDataXML.cpp index 489d1de9..214f8123 100644 --- a/inOutDataXML/inOutDataXML.cpp +++ b/inOutDataXML/inOutDataXML.cpp @@ -1148,58 +1148,58 @@ QString InOutDataXML::parseXMLPointCode(QString text) QString myPointCode = ""; QString substring = ""; - if (pointCode.getType().toUpper() == "FIELDDEFINED" || pointCode.getType().toUpper() == "FIELDEFINED" || pointCode.getType().toUpper() == "FILENAMEDEFINED" || pointCode.getType().toUpper() == "FIXED") + if (format_type == XMLFORMATFIXED || (format_type == XMLFORMATDELIMITED && pointCode.getType().toUpper() == "FILENAMEDEFINED")) { - if (format_type == XMLFORMATFIXED || (format_type == XMLFORMATDELIMITED && pointCode.getType().toUpper() == "FILENAMEDEFINED")) + if (fileName_pragaName.isEmpty()) { - if (fileName_pragaName.isEmpty()) + if (pointCode.getType().toUpper() == "FILENAMEDEFINED") { - if (pointCode.getType().toUpper() == "FILENAMEDEFINED") - { - // text is the name of the file - substring = text.mid(0,pointCode.getNrChar()); - } - else - { - // text is a line, firstChar start from 1 - substring = text.mid(pointCode.getFirstChar()-1,pointCode.getNrChar()); - } - if (pointCode.getFormat().isEmpty() || pointCode.getFormat() == "%s") - { - // pointCode is a string - myPointCode = substring; - } + // text is the name of the file + substring = text.mid(0,pointCode.getNrChar()); } else { - // con questa casistica l'import funziona anche con gli xml di export che hanno il campo filename e prefissi o suffissi nel nome del file - QString substring = text; - for (int i = 0; i list = text.split(format_delimiter); - if (format_isSinglePoint) + // con questa casistica l'import funziona anche con gli xml di export che hanno il campo filename e prefissi o suffissi nel nome del file + QString substring = text; + for (int i = 0; i list = text.split(format_delimiter); + int pos = pointCode.getPosition(); + if (pos < 0) + return myPointCode; + if (format_isSinglePoint) + { + myPointCode = list[pointCode.getPosition()]; + } + else + { + myPointCode = list[pointCode.getPosition()-1]; } } From abde4905a327f794c7bf68c7b303f3979d995bb3 Mon Sep 17 00:00:00 2001 From: Antonio Volta Date: Mon, 18 Mar 2024 17:12:24 +0100 Subject: [PATCH 37/72] cambio commento --- mathFunctions/furtherMathFunctions.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mathFunctions/furtherMathFunctions.h b/mathFunctions/furtherMathFunctions.h index 3887ec2b..dce8dcf9 100644 --- a/mathFunctions/furtherMathFunctions.h +++ b/mathFunctions/furtherMathFunctions.h @@ -150,7 +150,7 @@ enum estimatedFunction {FUNCTION_CODE_SPHERICAL, FUNCTION_CODE_LINEAR, FUNCTION_ namespace myrandom { - //float ran1(long *idum); + //float ran1(long *idum) ; //float gasdev(long *idum); double cauchyRandom(double gamma); float normalRandom(int *gasDevIset,float *gasDevGset); From c444f9eaa9131832c36dfaa405012cafaa533e40 Mon Sep 17 00:00:00 2001 From: cate-to Date: Tue, 19 Mar 2024 16:17:31 +0100 Subject: [PATCH 38/72] changed elevation function in multiple detrending --- interpolation/interpolation.cpp | 7 ++++--- mathFunctions/furtherMathFunctions.cpp | 21 ++++++++++++++++++++- mathFunctions/furtherMathFunctions.h | 3 ++- project/project.cpp | 2 +- 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/interpolation/interpolation.cpp b/interpolation/interpolation.cpp index a2d47dcd..82acf60e 100644 --- a/interpolation/interpolation.cpp +++ b/interpolation/interpolation.cpp @@ -40,6 +40,7 @@ #include "interpolation.h" #include + using namespace std; float getMinHeight(const std::vector &myPoints, bool useLapseRateCode) @@ -1329,7 +1330,7 @@ bool setFittingParameters(Crit3DProxyCombination myCombination, Crit3DInterpolat if (mySettings->getProxy(i)->getIsSignificant()) { if (getProxyPragaName(mySettings->getProxy(i)->getName()) == height) - myFunc.push_back(lapseRatePiecewise); + myFunc.push_back(lapseRatePiecewise_two); else myFunc.push_back(functionLinear); @@ -1520,8 +1521,8 @@ bool multipleDetrending(std::vector &myPoints, Cr setFittingParameters(myCombination, mySettings, myFunc, parametersMin, parametersMax, parametersDelta, parameters); // multiple non linear fitting - interpolation::bestFittingMarquardt_nDimension(&functionSum, myFunc, 500, 5, parametersMin, parametersMax, parameters, parametersDelta, - 100, 0.005, 0.01, predictors, predictands, false, weights); + interpolation::bestFittingMarquardt_nDimension(&functionSum, myFunc, 1000, 5, parametersMin, parametersMax, parameters, parametersDelta, + 100, 0.005, 0.01, predictors, predictands, true, weights); mySettings->setFittingFunction(myFunc); mySettings->setFittingParameters(parameters); diff --git a/mathFunctions/furtherMathFunctions.cpp b/mathFunctions/furtherMathFunctions.cpp index 08798fe7..e127d251 100644 --- a/mathFunctions/furtherMathFunctions.cpp +++ b/mathFunctions/furtherMathFunctions.cpp @@ -66,7 +66,7 @@ double lapseRateFrei(double x, std::vector & par) return y - 0.5*par[2]*(1 + cos(PI*(x-par[3])/(par[4]-par[3]))); } -double lapseRatePiecewise(double x, std::vector & par) +double lapseRatePiecewise_three(double x, std::vector & 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 @@ -94,6 +94,25 @@ double lapseRatePiecewise(double x, std::vector & par) } } +double lapseRatePiecewise_two(double x, std::vector & par) +{ + // the piecewise line is parameterized as follows + // the line passes through A(par[0];par[1]). par[2] is the slope of the first line, par[3] the slope of the second + // "y = mx + q" piecewise function; + if (x < par[0]) + { + //m = par[2]; + //q = -par[2]*par[0]+par[1]; + return par[2]*(x-par[0])+par[1]; + } + else if (x >= par[0]) + { + //m = par[3]: + //q = -par[3]*par[0]+par[1]; + return par[3]*(x-par[0])+par[1]; + } +} + double functionSum(std::vector&)>>& functions, std::vector& x, std::vector >& par) { double result = 0.0; diff --git a/mathFunctions/furtherMathFunctions.h b/mathFunctions/furtherMathFunctions.h index dce8dcf9..7f640b29 100644 --- a/mathFunctions/furtherMathFunctions.h +++ b/mathFunctions/furtherMathFunctions.h @@ -47,7 +47,8 @@ enum estimatedFunction {FUNCTION_CODE_SPHERICAL, FUNCTION_CODE_LINEAR, FUNCTION_ float gaussianFunction(float x, float mean, float devStd); double functionSum(std::vector &)> > &functions, std::vector& x, std::vector >& par); double functionLinear(double x, std::vector & par); - double lapseRatePiecewise(double x, std::vector & par); + double lapseRatePiecewise_three(double x, std::vector & par); + double lapseRatePiecewise_two(double x, std::vector & par); double lapseRateFrei(double x, std::vector & par); double lapseRateRotatedSigmoid(double x, std::vector par); diff --git a/project/project.cpp b/project/project.cpp index c53697d9..b0599c23 100644 --- a/project/project.cpp +++ b/project/project.cpp @@ -684,7 +684,7 @@ bool Project::loadParameters(QString parametersFileName) unsigned int nrParameters; if (getProxyPragaName(name_.toStdString()) == height) - nrParameters = 5; + nrParameters = 4; else nrParameters = 1; From 3dae230cdcefe4fdce040a38a93942cb484cb473 Mon Sep 17 00:00:00 2001 From: ftomei Date: Tue, 19 Mar 2024 19:10:51 +0100 Subject: [PATCH 39/72] fix window size --- project/dialogSelectionMeteoPoint.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/project/dialogSelectionMeteoPoint.cpp b/project/dialogSelectionMeteoPoint.cpp index bf620387..edccf2f0 100644 --- a/project/dialogSelectionMeteoPoint.cpp +++ b/project/dialogSelectionMeteoPoint.cpp @@ -10,6 +10,7 @@ DialogSelectionMeteoPoint::DialogSelectionMeteoPoint(bool active, Crit3DMeteoPoi datasetList = meteoPointsDbHandler->getDatasetList(); setWindowTitle("Select"); + setMinimumWidth(400); QVBoxLayout mainLayout; QHBoxLayout selectionLayout; QHBoxLayout buttonLayout; From 559e161b49b78c2390f9fc7b43fc8462391c15fe Mon Sep 17 00:00:00 2001 From: cate-to Date: Wed, 20 Mar 2024 12:25:22 +0100 Subject: [PATCH 40/72] change in weights management --- interpolation/interpolation.cpp | 5 +- mathFunctions/furtherMathFunctions.cpp | 358 ++++++++++++++++++++++++- mathFunctions/furtherMathFunctions.h | 8 +- 3 files changed, 357 insertions(+), 14 deletions(-) diff --git a/interpolation/interpolation.cpp b/interpolation/interpolation.cpp index 82acf60e..95301f4e 100644 --- a/interpolation/interpolation.cpp +++ b/interpolation/interpolation.cpp @@ -1027,7 +1027,7 @@ void localSelection(vector &inputPoints, vector < inputPoints[i].distance = gis::computeDistance(x, y, float((inputPoints[i]).point->utm.x), float((inputPoints[i]).point->utm.y)); unsigned int nrValid = 0; - float stepRadius = 10000; // [m] + float stepRadius = 5000; // [m] float r0 = 0; // [m] float r1 = stepRadius; // [m] unsigned int i; @@ -1046,6 +1046,7 @@ void localSelection(vector &inputPoints, vector < for (i=0; i < selectedPoints.size(); i++) selectedPoints[i].regressionWeight = (1 - selectedPoints[i].distance / r1); + //selectedPoints[i].regressionWeight = 1; mySettings.setLocalRadius(r1); } @@ -1522,7 +1523,7 @@ bool multipleDetrending(std::vector &myPoints, Cr // multiple non linear fitting interpolation::bestFittingMarquardt_nDimension(&functionSum, myFunc, 1000, 5, parametersMin, parametersMax, parameters, parametersDelta, - 100, 0.005, 0.01, predictors, predictands, true, weights); + 100, 0.005, 0.01, predictors, predictands, weights); mySettings->setFittingFunction(myFunc); mySettings->setFittingParameters(parameters); diff --git a/mathFunctions/furtherMathFunctions.cpp b/mathFunctions/furtherMathFunctions.cpp index e127d251..e2984028 100644 --- a/mathFunctions/furtherMathFunctions.cpp +++ b/mathFunctions/furtherMathFunctions.cpp @@ -105,7 +105,7 @@ double lapseRatePiecewise_two(double x, std::vector & par) //q = -par[2]*par[0]+par[1]; return par[2]*(x-par[0])+par[1]; } - else if (x >= par[0]) + else { //m = par[3]: //q = -par[3]*par[0]+par[1]; @@ -1050,7 +1050,7 @@ namespace interpolation std::vector >& parameters, std::vector >& parametersDelta, int maxIterationsNr, double myEpsilon, double deltaR2, std::vector >& x ,std::vector& y, - bool isWeighted, std::vector& weights) + std::vector& weights) { int i,j; int nrPredictors = int(parameters.size()); @@ -1106,15 +1106,12 @@ namespace interpolation } fittingMarquardt_nDimension(func,myFunc,parametersMin, parametersMax, parameters, parametersDelta,correspondenceTag, maxIterationsNr, - myEpsilon, x, y, isWeighted, weights); + myEpsilon, x, y, weights); for (i=0;i (bestR2-deltaR2)) { @@ -1156,6 +1153,351 @@ namespace interpolation } + bool fittingMarquardt_nDimension(double (*func)(std::vector&)>>&, std::vector& , std::vector >&), + std::vector &)> >& myFunc, + std::vector > ¶metersMin, std::vector > ¶metersMax, + std::vector > ¶meters, std::vector > ¶metersDelta, std::vector > &correspondenceParametersTag, + int maxIterationsNr, double myEpsilon, + std::vector >& x, std::vector& y, + std::vector& weights) + { + int i,j; + int nrPredictors = int(parameters.size()); + double mySSE, diffSSE, newSSE; + static double VFACTOR = 10; + std::vector nrParameters(nrPredictors); + std::vector > paramChange(nrPredictors); + std::vector > newParameters(nrPredictors); + std::vector > lambda(nrPredictors); + + for (i=0; i parametersMax[i][j]) && (lambda[i][j] < 1000)) + { + newParameters[i][j] = parametersMax[i][j]; + if (lambda[i][j] < 1000) + lambda[i][j] *= VFACTOR; + } + if (newParameters[i][j] < parametersMin[i][j]) + { + newParameters[i][j] = parametersMin[i][j]; + if (lambda[i][j] < 1000) + lambda[i][j] *= VFACTOR; + } + } + } + newSSE = normGeneric_nDimension(func, myFunc, newParameters, x, y, weights); + + if (newSSE == NODATA) + return false; + + diffSSE = mySSE - newSSE ; + + if (diffSSE > 0) + { + mySSE = newSSE; + for (i=0; i myEpsilon && iterationNr <= maxIterationsNr); + return (fabs(diffSSE) <= myEpsilon); + } + + + void leastSquares_nDimension(double (*func)(std::vector &)> > &, std::vector &, std::vector >&), + std::vector &)> > myFunc, + std::vector >& parameters, std::vector >& parametersDelta, std::vector >& correspondenceParametersTag, + std::vector >& x, std::vector& y, std::vector >& lambda, + std::vector >& parametersChange, std::vector& weights) + { + int i,j,k; + double pivot, mult, top; + int nrPredictors = int(parameters.size()); + int nrParametersTotal = 0; + int nrData = int(y.size()); + std::vector nrParameters(nrPredictors); + for (int i=0; i g(nrParametersTotal);// = (double *) calloc(nrParametersTotal, sizeof(double)); + std::vector z(nrParametersTotal); + std::vector firstEst(nrData); + std::vector> a(nrParametersTotal, std::vector(nrParametersTotal)); + std::vector> P(nrParametersTotal, std::vector(nrData)); + // matrix P corresponds to the Jacobian + // first set of estimates + for (i = 0; i < nrData; i++) + { + firstEst[i] = func(myFunc,x[i], parameters); + } + + // change parameters and compute derivatives + int counterDim = 0; + //double newEst; + for (i = 0; i < nrPredictors; i++) + { + for (k=0;k= 0; i--) + { + top = g[i]; + for (k = i + 1; k < nrParametersTotal; k++) + { + top -= a[i][k] * parametersChange[correspondenceParametersTag[0][k]][correspondenceParametersTag[1][k]]; + } + parametersChange[correspondenceParametersTag[0][i]][correspondenceParametersTag[1][i]] = top / a[i][i]; + } + counterDim = 0; + for (i = 0; i < nrPredictors; i++) + { + for (k=0;k&)>>&, std::vector&, std::vector >&), + std::vector&)>> myFunc, + std::vector > ¶meters,std::vector >& x, + std::vector& y, std::vector& weights ) + { + double error; + double norm = 0; + + for (int i = 0; i < y.size(); i++) + { + error = y[i] - func(myFunc,x[i], parameters); + norm += error * error * weights[i] * weights[i]; + } + return norm; + } + + /*int bestFittingMarquardt_nDimension(double (*func)(std::vector&)>>&, std::vector& , std::vector >&), + std::vector&)>>& myFunc, + int nrTrials, int nrMinima, + std::vector >& parametersMin, std::vector >& parametersMax, + std::vector >& parameters, std::vector >& parametersDelta, + int maxIterationsNr, double myEpsilon, double deltaR2, + std::vector >& x ,std::vector& y, + bool isWeighted, std::vector& weights) + { + int i,j; + int nrPredictors = int(parameters.size()); + int nrData = int(y.size()); + std::vector nrParameters(nrPredictors); + int nrParametersTotal = 0; + for (i=0; i> bestParameters(nrPredictors); + std::vector > correspondenceTag(2,std::vector(nrParametersTotal)); + int counterTag = 0; + for (i=0; i R2Previous(nrMinima,NODATA); + std::vector ySim(nrData); + + //int iRandom = 0; + int counter = 0; + //srand (unsigned(time(nullptr))); + std::random_device rd; + std::mt19937 gen(rd()); + //std::uniform_real_distribution dis(0.0, 1.0); + std::normal_distribution normal_dis(0.5, 0.2); + double truncNormal; + do + { + for (i=0; i= 1.0); + parameters[i][j] = parametersMin[i][j] + (truncNormal)*(parametersMax[i][j]-parametersMin[i][j]); + } + } + fittingMarquardt_nDimension(func,myFunc,parametersMin, parametersMax, + parameters, parametersDelta,correspondenceTag, maxIterationsNr, + myEpsilon, x, y, isWeighted, weights); + for (i=0;i (bestR2-deltaR2)) + { + for (j=0;j (bestR2)) + { + for (i=0;i deltaR2) ); + + for (i=0;i&)>>&, std::vector& , std::vector >&), std::vector &)> >& myFunc, std::vector > ¶metersMin, std::vector > ¶metersMax, @@ -1400,7 +1742,7 @@ namespace interpolation norm += error * error; } return norm; - } + }*/ } diff --git a/mathFunctions/furtherMathFunctions.h b/mathFunctions/furtherMathFunctions.h index 7f640b29..a324c6ec 100644 --- a/mathFunctions/furtherMathFunctions.h +++ b/mathFunctions/furtherMathFunctions.h @@ -100,25 +100,25 @@ enum estimatedFunction {FUNCTION_CODE_SPHERICAL, FUNCTION_CODE_LINEAR, FUNCTION_ std::vector > ¶metersMin, std::vector > ¶metersMax, std::vector > ¶meters, std::vector > ¶metersDelta, int maxIterationsNr, double myEpsilon, double deltaR2, - std::vector >& x , std::vector& y, bool isWeighted, std::vector& weights); + std::vector >& x , std::vector& y, std::vector& weights); bool fittingMarquardt_nDimension(double (*func)(std::vector &)> > &, std::vector &, std::vector >&), std::vector &)> > &myFunc, std::vector >& parametersMin, std::vector >& parametersMax, std::vector >& parameters, std::vector >& parametersDelta, std::vector >& correspondenceParametersTag, int maxIterationsNr, double myEpsilon, - std::vector >& x, std::vector& y, bool isWeighted, std::vector& weights); + std::vector >& x, std::vector& y, std::vector& weights); double normGeneric_nDimension(double (*func)(std::vector &)>> &, std::vector &, std::vector >&), std::vector &)> > myFunc, - std::vector > ¶meters, std::vector >& x, std::vector& y); + std::vector > ¶meters, std::vector >& x, std::vector& y, std::vector& weights); void leastSquares_nDimension(double (*func)(std::vector&)>>&, std::vector& , std::vector >&), std::vector &)> > myFunc, std::vector >& parameters, std::vector >& parametersDelta, std::vector >& correspondenceParametersTag, std::vector >& x, std::vector& y, std::vector >& lambda, - std::vector >& parametersChange,bool isWeighted, std::vector& weights); + std::vector >& parametersChange, std::vector& weights); } namespace matricial From f732f4479a74d910f758856a8d280173acc68b70 Mon Sep 17 00:00:00 2001 From: lauracosta Date: Wed, 20 Mar 2024 15:22:34 +0100 Subject: [PATCH 41/72] monthly button --- meteoWidget/meteoWidget.cpp | 72 ++++++++++++++++++++++++++++++++++--- meteoWidget/meteoWidget.h | 2 ++ 2 files changed, 70 insertions(+), 4 deletions(-) diff --git a/meteoWidget/meteoWidget.cpp b/meteoWidget/meteoWidget.cpp index 50151d45..b8beb807 100644 --- a/meteoWidget/meteoWidget.cpp +++ b/meteoWidget/meteoWidget.cpp @@ -253,6 +253,7 @@ Crit3DMeteoWidget::Crit3DMeteoWidget(bool isGrid_, QString projectPath, Crit3DMe dailyButton = new QPushButton(tr("daily")); hourlyButton = new QPushButton(tr("hourly")); + monthlyButton = new QPushButton(tr("monthly")); addVarButton = new QPushButton(tr("+/- var")); tableButton = new QPushButton(tr("view table")); redrawButton = new QPushButton(tr("redraw")); @@ -264,6 +265,7 @@ Crit3DMeteoWidget::Crit3DMeteoWidget(bool isGrid_, QString projectPath, Crit3DMe lastDate = new QDateTimeEdit(currentDate); dailyButton->setMaximumWidth(100); hourlyButton->setMaximumWidth(100); + monthlyButton->setMaximumWidth(100); addVarButton->setMaximumWidth(100); tableButton->setMaximumWidth(100); redrawButton->setMaximumWidth(100); @@ -283,13 +285,22 @@ Crit3DMeteoWidget::Crit3DMeteoWidget(bool isGrid_, QString projectPath, Crit3DMe { dailyButton->setEnabled(false); hourlyButton->setEnabled(true); + monthlyButton->setEnabled(true); } - else + else if (currentFreq == hourly) { - dailyButton->setEnabled(true); hourlyButton->setEnabled(false); + dailyButton->setEnabled(true); + monthlyButton->setEnabled(true); + } + else if (currentFreq == monthly) + { + monthlyButton->setEnabled(false); + dailyButton->setEnabled(true); + hourlyButton->setEnabled(true); } + buttonLayout->addWidget(monthlyButton); buttonLayout->addWidget(dailyButton); buttonLayout->addWidget(hourlyButton); buttonLayout->addWidget(addVarButton); @@ -363,6 +374,7 @@ Crit3DMeteoWidget::Crit3DMeteoWidget(bool isGrid_, QString projectPath, Crit3DMe viewMenu->addAction(dataSum); connect(addVarButton, &QPushButton::clicked, [=](){ showVar(); }); + connect(monthlyButton, &QPushButton::clicked, [=](){ showMonthlyGraph(); }); connect(dailyButton, &QPushButton::clicked, [=](){ showDailyGraph(); }); connect(hourlyButton, &QPushButton::clicked, [=](){ showHourlyGraph(); }); connect(tableButton, &QPushButton::clicked, [=](){ showTable(); }); @@ -1484,14 +1496,18 @@ void Crit3DMeteoWidget::showVar() if (currentFreq == noFrequency) { - if (!dailyButton->isEnabled()) // dailyButton is pressed + if (dailyButton->isChecked()) // dailyButton is pressed { currentFreq = daily; } - else + else if (hourlyButton->isChecked()) { currentFreq = hourly; } + else if (monthlyButton->isChecked()) + { + currentFreq = monthly; + } } QList allKeys = MapCSVStyles.keys(); QList selectedVar = currentVariables; @@ -1512,6 +1528,13 @@ void Crit3DMeteoWidget::showVar() allVar.append(allKeys[i]); } } + else if (currentFreq == monthly) + { + if (!allKeys[i].contains("MONTHLY") && !selectedVar.contains(allKeys[i])) + { + allVar.append(allKeys[i]); + } + } } DialogSelectVar selectDialog(allVar, selectedVar); if (selectDialog.result() == QDialog::Accepted) @@ -1524,6 +1547,45 @@ void Crit3DMeteoWidget::showVar() } } +void Crit3DMeteoWidget::showMonthlyGraph() +{ + if (! isInitialized) return; + + currentFreq = monthly; + + dailyButton->setEnabled(true); + hourlyButton->setEnabled(true); + monthlyButton->setEnabled(false); + + // TO DO +/* + QList currentMonthlyVar = currentVariables; + currentVariables.clear(); + + for (int i = 0; isetEnabled(false); hourlyButton->setEnabled(true); + monthlyButton->setEnabled(true); QList currentHourlyVar = currentVariables; currentVariables.clear(); @@ -1569,6 +1632,7 @@ void Crit3DMeteoWidget::showHourlyGraph() hourlyButton->setEnabled(false); dailyButton->setEnabled(true); + monthlyButton->setEnabled(true); QList currentDailyVar = currentVariables; currentVariables.clear(); diff --git a/meteoWidget/meteoWidget.h b/meteoWidget/meteoWidget.h index 497df9b3..ca258679 100644 --- a/meteoWidget/meteoWidget.h +++ b/meteoWidget/meteoWidget.h @@ -35,6 +35,7 @@ void drawDailyVar(); void drawEnsembleDailyVar(); void drawHourlyVar(); + void showMonthlyGraph(); void showDailyGraph(); void showHourlyGraph(); void updateSeries(); @@ -81,6 +82,7 @@ QPushButton *addVarButton; QPushButton *dailyButton; QPushButton *hourlyButton; + QPushButton *monthlyButton; QPushButton *tableButton; QPushButton *redrawButton; QPushButton *shiftPreviousButton; From c3568cafaf0a4d34617d066d57481e651aa0035d Mon Sep 17 00:00:00 2001 From: ftomei Date: Wed, 20 Mar 2024 16:38:15 +0100 Subject: [PATCH 42/72] update proxy settings --- interpolation/interpolation.cpp | 25 ++++++------ interpolation/interpolationSettings.cpp | 51 ++++++------------------- interpolation/interpolationSettings.h | 22 ++++++----- project/dialogInterpolation.cpp | 2 +- project/project.cpp | 8 ++-- 5 files changed, 43 insertions(+), 65 deletions(-) diff --git a/interpolation/interpolation.cpp b/interpolation/interpolation.cpp index 95301f4e..d1b16481 100644 --- a/interpolation/interpolation.cpp +++ b/interpolation/interpolation.cpp @@ -38,6 +38,8 @@ #include "spatialControl.h" #include "interpolationPoint.h" #include "interpolation.h" +#include "interpolationSettings.h" + #include @@ -1188,7 +1190,7 @@ float retrend(meteoVariable myVar, vector myProxyValues, Crit3DInterpola { myProxy = mySettings->getProxy(pos); - if (myCombination.getValue(pos) && myProxy->getIsSignificant()) + if (myCombination.isProxyActive(pos) && myProxy->getIsSignificant()) { myProxyValue = mySettings->getProxyValue(pos, myProxyValues); @@ -1256,7 +1258,7 @@ void detrending(std::vector &myPoints, for (int pos=0; pos < int(mySettings->getProxyNr()); pos++) { - if (myCombination.getValue(pos)) + if (myCombination.isProxyActive(pos)) { myProxy = mySettings->getProxy(pos); myProxy->setIsSignificant(false); @@ -1327,7 +1329,7 @@ bool setFittingParameters(Crit3DProxyCombination myCombination, Crit3DInterpolat { const double RATIO_DELTA = 1000; - for (unsigned i=0; igetProxy(i)->getIsSignificant()) { if (getProxyPragaName(mySettings->getProxy(i)->getName()) == height) @@ -1369,8 +1371,8 @@ std::vector getfittingParameters(Crit3DProxyCombination myCombination, unsigned i,j,index; index=0; - for (i=0; igetProxy(i)->getName()) == height) { @@ -1401,9 +1403,10 @@ bool multipleDetrending(std::vector &myPoints, Cr unsigned nrPredictors = 0; std::vector proxyIndex; Crit3DProxy* myProxy; - for (int pos=0; pos < int(mySettings->getProxyNr()); pos++) + int proxyNr = int(mySettings->getProxyNr()); + for (int pos=0; pos < proxyNr; pos++) { - if (myCombination.getValue(pos)) + if (myCombination.isProxyActive(pos)) { myProxy = mySettings->getProxy(pos); myProxy->setIsSignificant(false); @@ -1422,7 +1425,7 @@ bool multipleDetrending(std::vector &myPoints, Cr for (pos=0; pos < int(mySettings->getProxyNr()); pos++) { - if (myCombination.getValue(pos) && proxyValidity(myPoints, pos, mySettings->getProxy(pos)->getStdDevThreshold(), &avg, &stdDev)) + if (myCombination.isProxyActive(pos) && proxyValidity(myPoints, pos, mySettings->getProxy(pos)->getStdDevThreshold(), &avg, &stdDev)) { mySettings->getProxy(pos)->setIsSignificant(true); validNr++; @@ -1468,7 +1471,7 @@ bool multipleDetrending(std::vector &myPoints, Cr validNr = 0; for (pos=0; pos < int(mySettings->getProxyNr()); pos++) { - if (myCombination.getValue(pos) && proxyValidity(myPoints, pos, mySettings->getProxy(pos)->getStdDevThreshold(), &avg, &stdDev)) + if (myCombination.isProxyActive(pos) && proxyValidity(myPoints, pos, mySettings->getProxy(pos)->getStdDevThreshold(), &avg, &stdDev)) { avgs.push_back(avg); stdDevs.push_back(stdDev); @@ -1744,7 +1747,7 @@ bool getActiveProxyValues(Crit3DInterpolationSettings *mySettings, const std::ve bool isComplete = true; for (unsigned int i=0; i < mySettings->getProxyNr(); i++) - if (myCombination.getValue(i) && mySettings->getProxy(i)->getIsSignificant()) + if (myCombination.isProxyActive(i) && mySettings->getProxy(i)->getIsSignificant()) { activeProxyValues.push_back(allProxyValues[i]); if (allProxyValues[i] == NODATA) @@ -1766,7 +1769,7 @@ void getProxyValuesXY(float x, float y, Crit3DInterpolationSettings* mySettings, { myValues[i] = NODATA; - if (myCombination.getValue(i)) + if (myCombination.isProxyActive(i)) { proxyGrid = mySettings->getProxy(i)->getGrid(); if (proxyGrid != nullptr && proxyGrid->isLoaded) diff --git a/interpolation/interpolationSettings.cpp b/interpolation/interpolationSettings.cpp index 387d087f..5d5ca9c5 100644 --- a/interpolation/interpolationSettings.cpp +++ b/interpolation/interpolationSettings.cpp @@ -141,7 +141,7 @@ void Crit3DInterpolationSettings::setSelectedCombination(const Crit3DProxyCombin void Crit3DInterpolationSettings::setValueSelectedCombination(unsigned int index, bool isActive) { - selectedCombination.setValue(index, isActive); + selectedCombination.setProxyActive(index, isActive); } unsigned Crit3DInterpolationSettings::getIndexHeight() const @@ -666,8 +666,8 @@ void Crit3DInterpolationSettings::addProxy(Crit3DProxy myProxy, bool isActive_) if (getProxyPragaName(myProxy.getName()) == height) setIndexHeight(int(currentProxy.size())-1); - selectedCombination.addValue(isActive_); - optimalCombination.addValue(isActive_); + selectedCombination.addProxyActive(isActive_); + optimalCombination.addProxyActive(isActive_); } std::string Crit3DInterpolationSettings::getProxyName(unsigned pos) @@ -681,50 +681,19 @@ double Crit3DInterpolationSettings::getProxyValue(unsigned pos, std::vector Crit3DProxyCombination::getIsActive() const -{ - return isActive; -} - -void Crit3DProxyCombination::setIsActive(const std::deque &value) -{ - isActive = value; -} Crit3DProxyCombination::Crit3DProxyCombination() { - setUseThermalInversion(false); -} - -void Crit3DProxyCombination::clear() -{ - isActive.clear(); -} - -void Crit3DProxyCombination::addValue(bool isActive_) -{ - isActive.push_back(isActive_); + clear(); } -void Crit3DProxyCombination::setValue(unsigned index, bool isActive_) -{ - isActive[index] = isActive_; -} - -bool Crit3DProxyCombination::getValue(unsigned index) -{ - return isActive[index]; -} -bool Crit3DProxyCombination::getUseThermalInversion() const +void Crit3DProxyCombination::clear() { - return useThermalInversion; + _isActiveList.clear(); + _useThermalInversion = false; } -void Crit3DProxyCombination::setUseThermalInversion(bool value) -{ - useThermalInversion = value; -} bool Crit3DInterpolationSettings::getCombination(int combinationInteger, Crit3DProxyCombination &outCombination) { @@ -735,11 +704,15 @@ bool Crit3DInterpolationSettings::getCombination(int combinationInteger, Crit3DP // avoid combinations with inversion (last index) and without orography if (combinationInteger % 2 == 1) + { if (indexHeight == NODATA || binaryString[indexHeight] == '0') return false; + } for (unsigned int i=0; i < binaryString.length()-1; i++) - outCombination.setValue(i, binaryString[i] == '1' && selectedCombination.getValue(i)); + { + outCombination.setProxyActive(i, (binaryString[i] == '1' && selectedCombination.isProxyActive(i)) ); + } outCombination.setUseThermalInversion(binaryString[binaryString.length()-1] == '1' && selectedCombination.getUseThermalInversion()); diff --git a/interpolation/interpolationSettings.h b/interpolation/interpolationSettings.h index aadf87cd..90fed278 100644 --- a/interpolation/interpolationSettings.h +++ b/interpolation/interpolationSettings.h @@ -98,26 +98,28 @@ void setFittingParametersRange(const std::vector &newFittingParametersRange); }; + class Crit3DProxyCombination { private: - std::deque isActive; - bool useThermalInversion; - + std::vector _isActiveList; + bool _useThermalInversion; public: Crit3DProxyCombination(); void clear(); - bool getUseThermalInversion() const; - void setUseThermalInversion(bool value); - void addValue(bool isActive_); - void setValue(unsigned index, bool isActive_); - bool getValue(unsigned index); - std::deque getIsActive() const; - void setIsActive(const std::deque &value); + void addProxyActive(bool value) { _isActiveList.push_back(value); } + void setProxyActive(unsigned index, bool value) { _isActiveList[index] = value; } + bool isProxyActive(unsigned index) { return _isActiveList[index]; } + + unsigned int getProxySize() const { return unsigned(_isActiveList.size()); } + + bool getUseThermalInversion() const { return _useThermalInversion; } + void setUseThermalInversion(bool value) { _useThermalInversion = value; } }; + class Crit3DInterpolationSettings { private: diff --git a/project/dialogInterpolation.cpp b/project/dialogInterpolation.cpp index f424ed62..071eb911 100644 --- a/project/dialogInterpolation.cpp +++ b/project/dialogInterpolation.cpp @@ -218,7 +218,7 @@ void DialogInterpolation::redrawProxies() Crit3DProxy* myProxy = _interpolationSettings->getProxy(i); QListWidgetItem *chkProxy = new QListWidgetItem(QString::fromStdString(myProxy->getName()), proxyListCheck); chkProxy->setFlags(chkProxy->flags() | Qt::ItemIsUserCheckable); - if (_interpolationSettings->getSelectedCombination().getValue(i)) + if (_interpolationSettings->getSelectedCombination().isProxyActive(i)) chkProxy->setCheckState(Qt::Checked); else chkProxy->setCheckState(Qt::Unchecked); diff --git a/project/project.cpp b/project/project.cpp index b0599c23..72decfb8 100644 --- a/project/project.cpp +++ b/project/project.cpp @@ -2489,7 +2489,7 @@ bool Project::meteoGridAggregateProxy(std::vector &myGr for (unsigned int i=0; i < interpolationSettings.getProxyNr(); i++) { - if (interpolationSettings.getCurrentCombination().getValue(i)) + if (interpolationSettings.getCurrentCombination().isProxyActive(i)) { gis::Crit3DRasterGrid* myGrid = new gis::Crit3DRasterGrid(); @@ -2571,7 +2571,7 @@ bool Project::interpolationGrid(meteoVariable myVar, const Crit3DTime& myTime) { proxyValues[i] = NODATA; - if (myCombination.getValue(i)) + if (myCombination.isProxyActive(i)) { if (proxyIndex < meteoGridProxies.size()) { @@ -2898,7 +2898,7 @@ void Project::saveProxies() myProxy = interpolationSettings.getProxy(i); parameters->beginGroup("proxy_" + QString::fromStdString(myProxy->getName())); parameters->setValue("order", i+1); - parameters->setValue("active", interpolationSettings.getSelectedCombination().getValue(i)); + parameters->setValue("active", interpolationSettings.getSelectedCombination().isProxyActive(i)); parameters->setValue("use_for_spatial_quality_control", myProxy->getForQualityControl()); if (myProxy->getProxyTable() != "") parameters->setValue("table", QString::fromStdString(myProxy->getProxyTable())); if (myProxy->getProxyField() != "") parameters->setValue("field", QString::fromStdString(myProxy->getProxyField())); @@ -3353,7 +3353,7 @@ void Project::showMeteoWidgetGrid(std::string idCell, bool isAppend) meteoWidgetGrid->setCurrentDate(currentDate); meteoWidgetGridList.append(meteoWidgetGrid); - QObject::connect(meteoWidgetGrid, SIGNAL(closeWidgetGrid(int)), this, SLOT(deleteMeteoWidgetGrid(int))); + //QObject::connect(meteoWidgetGrid, SIGNAL(closeWidgetGrid(int)), this, SLOT(deleteMeteoWidgetGrid(int))); logInfoGUI("Loading data..."); From e4a8e48d045496ba8397a02a54265cc5abcd18ef Mon Sep 17 00:00:00 2001 From: ftomei Date: Wed, 20 Mar 2024 16:39:51 +0100 Subject: [PATCH 43/72] update --- project/project.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project/project.cpp b/project/project.cpp index 72decfb8..54dc8772 100644 --- a/project/project.cpp +++ b/project/project.cpp @@ -3353,7 +3353,7 @@ void Project::showMeteoWidgetGrid(std::string idCell, bool isAppend) meteoWidgetGrid->setCurrentDate(currentDate); meteoWidgetGridList.append(meteoWidgetGrid); - //QObject::connect(meteoWidgetGrid, SIGNAL(closeWidgetGrid(int)), this, SLOT(deleteMeteoWidgetGrid(int))); + QObject::connect(meteoWidgetGrid, SIGNAL(closeWidgetGrid(int)), this, SLOT(deleteMeteoWidgetGrid(int))); logInfoGUI("Loading data..."); From 0d92b94f0d91e9b4c5cb7f24d994b11b64beb36b Mon Sep 17 00:00:00 2001 From: ftomei Date: Wed, 20 Mar 2024 18:01:51 +0100 Subject: [PATCH 44/72] update --- interpolation/interpolation.cpp | 37 ++++++++++++++++++--------------- interpolation/interpolation.h | 3 +++ 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/interpolation/interpolation.cpp b/interpolation/interpolation.cpp index d1b16481..20aa53e2 100644 --- a/interpolation/interpolation.cpp +++ b/interpolation/interpolation.cpp @@ -1283,21 +1283,21 @@ void detrending(std::vector &myPoints, } } -bool proxyValidity(std::vector &myPoints, int proxyPos, float stdDevThreshold, float* avg, float* stdDev) + +bool proxyValidity(std::vector &myPoints, int proxyPos, float stdDevThreshold, double &avg, double &stdDev) { - std::vector proxyValues; - float myValue, sum = 0; + std::vector proxyValues; const int MIN_NR = 10; - unsigned i; - *avg = NODATA; - *stdDev = NODATA; + avg = NODATA; + stdDev = NODATA; - for (i = 0; i < myPoints.size(); i++) + double sum = 0; + for (unsigned i = 0; i < myPoints.size(); i++) { if (myPoints[i].isActive) { - myValue = myPoints[i].getProxyValue(proxyPos); + double myValue = myPoints[i].getProxyValue(proxyPos); if (myValue != NODATA) { proxyValues.push_back(myValue); @@ -1308,20 +1308,23 @@ bool proxyValidity(std::vector &myPoints, int pro if (proxyValues.size() < MIN_NR) return false; - *avg = sum / proxyValues.size(); + avg = sum / proxyValues.size(); sum = 0; - for (i=0; i < proxyValues.size(); i++) - sum += (proxyValues[i] - *avg) * (proxyValues[i] - *avg); + for (unsigned i = 0; i < proxyValues.size(); i++) + { + sum += (proxyValues[i] - avg) * (proxyValues[i] - avg); + } - *stdDev = float(sqrt(sum / (proxyValues.size() - 1))); + stdDev = sqrt(sum / (proxyValues.size() - 1)); if (stdDevThreshold != NODATA) - return (*stdDev > stdDevThreshold); + return (stdDev > stdDevThreshold); else return true; } + bool setFittingParameters(Crit3DProxyCombination myCombination, Crit3DInterpolationSettings* mySettings, std::vector&)>>& myFunc, std::vector > & paramMin, std::vector > & paramMax, @@ -1418,14 +1421,14 @@ bool multipleDetrending(std::vector &myPoints, Cr if (nrPredictors == 0) return false; // proxy spatial variability (1st step) - float avg, stdDev; + double avg, stdDev; unsigned validNr; unsigned pos; validNr = 0; for (pos=0; pos < int(mySettings->getProxyNr()); pos++) { - if (myCombination.isProxyActive(pos) && proxyValidity(myPoints, pos, mySettings->getProxy(pos)->getStdDevThreshold(), &avg, &stdDev)) + if (myCombination.isProxyActive(pos) && proxyValidity(myPoints, pos, mySettings->getProxy(pos)->getStdDevThreshold(), avg, stdDev)) { mySettings->getProxy(pos)->setIsSignificant(true); validNr++; @@ -1471,7 +1474,7 @@ bool multipleDetrending(std::vector &myPoints, Cr validNr = 0; for (pos=0; pos < int(mySettings->getProxyNr()); pos++) { - if (myCombination.isProxyActive(pos) && proxyValidity(myPoints, pos, mySettings->getProxy(pos)->getStdDevThreshold(), &avg, &stdDev)) + if (myCombination.isProxyActive(pos) && proxyValidity(myPoints, pos, mySettings->getProxy(pos)->getStdDevThreshold(), avg, stdDev)) { avgs.push_back(avg); stdDevs.push_back(stdDev); @@ -1520,8 +1523,8 @@ bool multipleDetrending(std::vector &myPoints, Cr std::vector > parametersMax; std::vector > parametersDelta; std::vector > parameters; - std::vector&)>> myFunc; + setFittingParameters(myCombination, mySettings, myFunc, parametersMin, parametersMax, parametersDelta, parameters); // multiple non linear fitting diff --git a/interpolation/interpolation.h b/interpolation/interpolation.h index 4d1f9097..10b15d67 100644 --- a/interpolation/interpolation.h +++ b/interpolation/interpolation.h @@ -90,5 +90,8 @@ std::vector &selectedPoints, float x, float y, Crit3DInterpolationSettings &mySettings); + bool proxyValidity(std::vector &myPoints, int proxyPos, + float stdDevThreshold, double &avg, double &stdDev); + #endif // INTERPOLATION_H From 051c4f2b19741ff8a118e5fcd6f2891dbf2767cd Mon Sep 17 00:00:00 2001 From: ftomei Date: Wed, 20 Mar 2024 19:23:15 +0100 Subject: [PATCH 45/72] fix set fitting parameters --- interpolation/interpolation.cpp | 55 +++++++++----- interpolation/interpolation.h | 12 +++- interpolation/spatialControl.cpp | 46 +++++++++--- interpolation/spatialControl.h | 11 ++- project/project.cpp | 79 +++++++++++++++------ proxyWidget/proxyWidget.cpp | 9 ++- synchronicityWidget/synchronicityWidget.cpp | 8 ++- 7 files changed, 159 insertions(+), 61 deletions(-) diff --git a/interpolation/interpolation.cpp b/interpolation/interpolation.cpp index 20aa53e2..b6f6ae97 100644 --- a/interpolation/interpolation.cpp +++ b/interpolation/interpolation.cpp @@ -1286,7 +1286,7 @@ void detrending(std::vector &myPoints, bool proxyValidity(std::vector &myPoints, int proxyPos, float stdDevThreshold, double &avg, double &stdDev) { - std::vector proxyValues; + std::vector proxyValues; const int MIN_NR = 10; avg = NODATA; @@ -1297,7 +1297,7 @@ bool proxyValidity(std::vector &myPoints, int pro { if (myPoints[i].isActive) { - double myValue = myPoints[i].getProxyValue(proxyPos); + float myValue = myPoints[i].getProxyValue(proxyPos); if (myValue != NODATA) { proxyValues.push_back(myValue); @@ -1325,10 +1325,11 @@ bool proxyValidity(std::vector &myPoints, int pro } -bool setFittingParameters(Crit3DProxyCombination myCombination, Crit3DInterpolationSettings* mySettings, +bool setAllFittingParameters(Crit3DProxyCombination myCombination, Crit3DInterpolationSettings* mySettings, std::vector&)>>& myFunc, - std::vector > & paramMin, std::vector > & paramMax, - std::vector > & paramDelta, std::vector > & paramFirstGuess) + std::vector > ¶mMin, std::vector > ¶mMax, + std::vector > ¶mDelta, std::vector > ¶mFirstGuess, + std::string &errorStr) { const double RATIO_DELTA = 1000; @@ -1343,6 +1344,12 @@ bool setFittingParameters(Crit3DProxyCombination myCombination, Crit3DInterpolat std::vector 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 proxyParamMin; std::vector proxyParamMax; @@ -1396,13 +1403,14 @@ std::vector getfittingParameters(Crit3DProxyCombination myCombination, } -bool multipleDetrending(std::vector &myPoints, Crit3DInterpolationSettings* mySettings, meteoVariable myVar) +bool multipleDetrending(std::vector &myPoints, + Crit3DInterpolationSettings* mySettings, meteoVariable myVar, std::string &errorStr) { if (! getUseDetrendingVar(myVar)) return false; Crit3DProxyCombination myCombination = mySettings->getSelectedCombination(); - // verify predictors number and if elevation is active + // verify predictors number unsigned nrPredictors = 0; std::vector proxyIndex; Crit3DProxy* myProxy; @@ -1423,10 +1431,9 @@ bool multipleDetrending(std::vector &myPoints, Cr // proxy spatial variability (1st step) double avg, stdDev; unsigned validNr; - unsigned pos; validNr = 0; - for (pos=0; pos < int(mySettings->getProxyNr()); pos++) + for (int pos=0; pos < proxyNr; pos++) { if (myCombination.isProxyActive(pos) && proxyValidity(myPoints, pos, mySettings->getProxy(pos)->getStdDevThreshold(), avg, stdDev)) { @@ -1435,7 +1442,11 @@ bool multipleDetrending(std::vector &myPoints, Cr } } - if (validNr == 0) return false; + if (validNr == 0) + { + errorStr = "No proxy"; + return false; + } // exclude points with incomplete proxies unsigned i; @@ -1447,7 +1458,7 @@ bool multipleDetrending(std::vector &myPoints, Cr while (it != myPoints.end()) { isValid = true; - for (pos=0; pos < mySettings->getProxyNr(); pos++) + for (int pos=0; pos < proxyNr; pos++) if (mySettings->getProxy(pos)->getIsSignificant()) { proxyValue = it->getProxyValue(pos); @@ -1472,7 +1483,7 @@ bool multipleDetrending(std::vector &myPoints, Cr std::vector stdDevs; validNr = 0; - for (pos=0; pos < int(mySettings->getProxyNr()); pos++) + for (int pos=0; pos < proxyNr; pos++) { if (myCombination.isProxyActive(pos) && proxyValidity(myPoints, pos, mySettings->getProxy(pos)->getStdDevThreshold(), avg, stdDev)) { @@ -1497,7 +1508,7 @@ bool multipleDetrending(std::vector &myPoints, Cr for (i=0; i < myPoints.size(); i++) { rowPredictors.clear(); - for (pos=0; pos < mySettings->getProxyNr(); pos++) + for (int pos=0; pos < proxyNr; pos++) if ((mySettings->getProxy(pos)->getIsSignificant())) { proxyValue = myPoints[i].getProxyValue(pos); @@ -1513,9 +1524,10 @@ bool multipleDetrending(std::vector &myPoints, Cr if (myPoints.size() < mySettings->getMinPointsLocalDetrending()) { - for (pos = 0; pos < mySettings->getProxyNr(); pos++) + for (int pos = 0; pos < proxyNr; pos++) mySettings->getProxy(pos)->setIsSignificant(false); + errorStr = "Not enough points for detrending."; return false; } @@ -1525,7 +1537,11 @@ bool multipleDetrending(std::vector &myPoints, Cr std::vector > parameters; std::vector&)>> myFunc; - setFittingParameters(myCombination, mySettings, myFunc, parametersMin, parametersMax, parametersDelta, parameters); + if (! setAllFittingParameters(myCombination, mySettings, myFunc, parametersMin, parametersMax, + parametersDelta, parameters, errorStr)) + { + return false; + } // multiple non linear fitting interpolation::bestFittingMarquardt_nDimension(&functionSum, myFunc, 1000, 5, parametersMin, parametersMax, parameters, parametersDelta, @@ -1540,7 +1556,7 @@ bool multipleDetrending(std::vector &myPoints, Cr float detrendValue; for (i = 0; i < myPoints.size(); i++) { - for (pos=0; pos < mySettings->getProxyNr(); pos++) + for (int pos=0; pos < proxyNr; pos++) { if ((mySettings->getProxy(pos)->getIsSignificant())) { @@ -1647,7 +1663,7 @@ void optimalDetrending(meteoVariable myVar, Crit3DMeteoPoint* &myMeteoPoints, in bool preInterpolation(std::vector &myPoints, Crit3DInterpolationSettings* mySettings, Crit3DMeteoSettings* meteoSettings, Crit3DClimateParameters* myClimate, Crit3DMeteoPoint* myMeteoPoints, int nrMeteoPoints, - meteoVariable myVar, Crit3DTime myTime) + meteoVariable myVar, Crit3DTime myTime, std::string &errorStr) { if (myVar == precipitation || myVar == dailyPrecipitation) { @@ -1666,7 +1682,10 @@ bool preInterpolation(std::vector &myPoints, Crit if (mySettings->getUseMultipleDetrending()) { mySettings->setCurrentCombination(mySettings->getSelectedCombination()); - multipleDetrending(myPoints, mySettings, myVar); + if (! multipleDetrending(myPoints, mySettings, myVar, errorStr)) + { + return false; + } } else { diff --git a/interpolation/interpolation.h b/interpolation/interpolation.h index 10b15d67..a48a9d26 100644 --- a/interpolation/interpolation.h +++ b/interpolation/interpolation.h @@ -47,7 +47,7 @@ float getProxyMaxValue(std::vector &myPoints, unsigned pos); bool preInterpolation(std::vector &myPoints, Crit3DInterpolationSettings *mySettings, Crit3DMeteoSettings *meteoSettings, Crit3DClimateParameters* myClimate, - Crit3DMeteoPoint *myMeteoPoints, int nrMeteoPoints, meteoVariable myVar, Crit3DTime myTime); + Crit3DMeteoPoint *myMeteoPoints, int nrMeteoPoints, meteoVariable myVar, Crit3DTime myTime, std::string &errorStr); bool krigingEstimateVariogram(float *myDist, float *mySemiVar,int sizeMyVar, int nrMyPoints,float myMaxDistance, double *mySill, double *myNugget, double *myRange, double *mySlope, TkrigingMode *myMode, int nrPointData); bool krigLinearPrep(double *mySlope, double *myNugget, int nrPointData); @@ -66,7 +66,9 @@ void detrending(std::vector &myPoints, Crit3DProxyCombination myCombination, Crit3DInterpolationSettings *mySettings, Crit3DClimateParameters *myClimate, meteoVariable myVar, Crit3DTime myTime); - bool multipleDetrending(std::vector &myPoints, Crit3DInterpolationSettings* mySettings, meteoVariable myVar); + + bool multipleDetrending(std::vector &myPoints, Crit3DInterpolationSettings* mySettings, + meteoVariable myVar, std::string &errorStr); bool getUseDetrendingVar(meteoVariable myVar); bool isThermal(meteoVariable myVar); @@ -93,5 +95,11 @@ bool proxyValidity(std::vector &myPoints, int proxyPos, float stdDevThreshold, double &avg, double &stdDev); + bool setAllFittingParameters(Crit3DProxyCombination myCombination, Crit3DInterpolationSettings* mySettings, + std::vector&)>>& myFunc, + std::vector > ¶mMin, std::vector > ¶mMax, + std::vector > ¶mDelta, std::vector > ¶mFirstGuess, + std::string &errorStr); + #endif // INTERPOLATION_H diff --git a/interpolation/spatialControl.cpp b/interpolation/spatialControl.cpp index 3b55e3a9..f7834caf 100644 --- a/interpolation/spatialControl.cpp +++ b/interpolation/spatialControl.cpp @@ -155,10 +155,11 @@ float computeErrorCrossValidation(meteoVariable myVar, Crit3DMeteoPoint* myPoint else return NODATA; } -void spatialQualityControl(meteoVariable myVar, Crit3DMeteoPoint* meteoPoints, int nrMeteoPoints, - Crit3DInterpolationSettings *settings, Crit3DMeteoSettings* meteoSettings, Crit3DClimateParameters* myClimate, Crit3DTime myTime) + +bool spatialQualityControl(meteoVariable myVar, Crit3DMeteoPoint* meteoPoints, int nrMeteoPoints, + Crit3DInterpolationSettings *settings, Crit3DMeteoSettings* meteoSettings, + Crit3DClimateParameters* myClimate, Crit3DTime myTime, std::string &errorStr) { - int i; float stdDev, avgDeltaZ, minDist, myValue, myResidual; std::vector listIndex; std::vector listResiduals; @@ -167,13 +168,20 @@ void spatialQualityControl(meteoVariable myVar, Crit3DMeteoPoint* meteoPoints, i if (passDataToInterpolation(meteoPoints, nrMeteoPoints, myInterpolationPoints, settings)) { // detrend - if (! preInterpolation(myInterpolationPoints, settings, meteoSettings, myClimate, meteoPoints, nrMeteoPoints, myVar, myTime)) - return; + if (! preInterpolation(myInterpolationPoints, settings, meteoSettings, myClimate, + meteoPoints, nrMeteoPoints, myVar, myTime, errorStr)) + { + return false; + } // compute residuals if (! computeResiduals(myVar, meteoPoints, nrMeteoPoints, myInterpolationPoints, settings, meteoSettings, false, false)) - return; + { + errorStr = "Error in compute residuals."; + return false; + } + int i; for (i = 0; i < nrMeteoPoints; i++) { if (meteoPoints[i].quality == quality::accepted) @@ -198,7 +206,11 @@ void spatialQualityControl(meteoVariable myVar, Crit3DMeteoPoint* meteoPoints, i { if (passDataToInterpolation(meteoPoints, nrMeteoPoints, myInterpolationPoints, settings)) { - preInterpolation(myInterpolationPoints, settings, meteoSettings, myClimate, meteoPoints, nrMeteoPoints, myVar, myTime); + if (! preInterpolation(myInterpolationPoints, settings, meteoSettings, myClimate, + meteoPoints, nrMeteoPoints, myVar, myTime, errorStr)) + { + return false; + } float interpolatedValue; for (i=0; i < int(listIndex.size()); i++) @@ -237,11 +249,14 @@ void spatialQualityControl(meteoVariable myVar, Crit3DMeteoPoint* meteoPoints, i } } } + + return true; } + bool checkData(Crit3DQuality* myQuality, meteoVariable myVar, Crit3DMeteoPoint* meteoPoints, int nrMeteoPoints, Crit3DTime myTime, Crit3DInterpolationSettings* spatialQualityInterpolationSettings, - Crit3DMeteoSettings* meteoSettings, Crit3DClimateParameters* myClimate, bool checkSpatial) + Crit3DMeteoSettings* meteoSettings, Crit3DClimateParameters* myClimate, bool checkSpatial, std::string &errorStr) { if (nrMeteoPoints == 0) return false; @@ -284,13 +299,18 @@ bool checkData(Crit3DQuality* myQuality, meteoVariable myVar, Crit3DMeteoPoint* && myVar != windVectorX && myVar != windVectorY && myVar != windVectorDirection && myVar != dailyWindVectorDirectionPrevailing) { - spatialQualityControl(myVar, meteoPoints, nrMeteoPoints, spatialQualityInterpolationSettings, meteoSettings, myClimate, myTime); + if (! spatialQualityControl(myVar, meteoPoints, nrMeteoPoints, spatialQualityInterpolationSettings, + meteoSettings, myClimate, myTime, errorStr)) + { + return false; + } } } return true; } + // check quality and pass good data to interpolation bool checkAndPassDataToInterpolation(Crit3DQuality* myQuality, meteoVariable myVar, Crit3DMeteoPoint* meteoPoints, int nrMeteoPoints, @@ -298,9 +318,13 @@ bool checkAndPassDataToInterpolation(Crit3DQuality* myQuality, meteoVariable myV Crit3DInterpolationSettings* interpolationSettings, Crit3DMeteoSettings* meteoSettings, Crit3DClimateParameters* myClimate, std::vector &myInterpolationPoints, - bool checkSpatial) + bool checkSpatial, std::string errorStr) { - if (! checkData(myQuality, myVar, meteoPoints, nrMeteoPoints, myTime, SQinterpolationSettings, meteoSettings, myClimate, checkSpatial)) return false; + if (! checkData(myQuality, myVar, meteoPoints, nrMeteoPoints, myTime, SQinterpolationSettings, + meteoSettings, myClimate, checkSpatial, errorStr)) + { + return false; + } // return true if at least one valid data return passDataToInterpolation(meteoPoints, nrMeteoPoints, myInterpolationPoints, interpolationSettings); diff --git a/interpolation/spatialControl.h b/interpolation/spatialControl.h index b8e8b6f5..1cb2d7e9 100644 --- a/interpolation/spatialControl.h +++ b/interpolation/spatialControl.h @@ -15,13 +15,15 @@ #endif bool checkData(Crit3DQuality* myQuality, meteoVariable myVar, Crit3DMeteoPoint* meteoPoints, int nrMeteoPoints, Crit3DTime myTime, - Crit3DInterpolationSettings* spatialQualityInterpolationSettings, Crit3DMeteoSettings *meteoSettings, Crit3DClimateParameters *myClimate, bool checkSpatial); + Crit3DInterpolationSettings* spatialQualityInterpolationSettings, Crit3DMeteoSettings *meteoSettings, + Crit3DClimateParameters *myClimate, bool checkSpatial, std::string &errorStr); bool checkAndPassDataToInterpolation(Crit3DQuality* myQuality, meteoVariable myVar, Crit3DMeteoPoint* meteoPoints, int nrMeteoPoints, Crit3DTime myTime, Crit3DInterpolationSettings *SQinterpolationSettings, - Crit3DInterpolationSettings* interpolationSettings, Crit3DMeteoSettings *meteoSettings, Crit3DClimateParameters *myClimate, + Crit3DInterpolationSettings* interpolationSettings, Crit3DMeteoSettings *meteoSettings, + Crit3DClimateParameters *myClimate, std::vector &myInterpolationPoints, - bool checkSpatial); + bool checkSpatial, std::string errorStr); bool passDataToInterpolation(Crit3DMeteoPoint* meteoPoints, int nrMeteoPoints, std::vector &myInterpolationPoints, Crit3DInterpolationSettings* mySettings); @@ -31,5 +33,8 @@ float computeErrorCrossValidation(meteoVariable myVar, Crit3DMeteoPoint *myPoints, int nrMeteoPoints, const Crit3DTime& myTime, Crit3DMeteoSettings *meteoSettings); + bool spatialQualityControl(meteoVariable myVar, Crit3DMeteoPoint* meteoPoints, int nrMeteoPoints, + Crit3DInterpolationSettings *settings, Crit3DMeteoSettings* meteoSettings, + Crit3DClimateParameters* myClimate, Crit3DTime myTime, std::string &errorStr); #endif // SPATIALCONTROL_H diff --git a/project/project.cpp b/project/project.cpp index 54dc8772..7eda4923 100644 --- a/project/project.cpp +++ b/project/project.cpp @@ -2181,19 +2181,22 @@ bool Project::interpolationCv(meteoVariable myVar, const Crit3DTime& myTime, cro } std::vector interpolationPoints; + std::string errorStdStr; // check quality and pass data to interpolation if (!checkAndPassDataToInterpolation(quality, myVar, meteoPoints, nrMeteoPoints, myTime, - &qualityInterpolationSettings, &interpolationSettings, meteoSettings, &climateParameters, interpolationPoints, - checkSpatialQuality)) + &qualityInterpolationSettings, &interpolationSettings, meteoSettings, + &climateParameters, interpolationPoints, + checkSpatialQuality, errorStdStr)) { - logError("No data available: " + QString::fromStdString(getVariableString(myVar))); + logError("No data available: " + QString::fromStdString(getVariableString(myVar)) + "\n" + QString::fromStdString(errorStdStr)); return false; } - if (! preInterpolation(interpolationPoints, &interpolationSettings, meteoSettings, &climateParameters, meteoPoints, nrMeteoPoints, myVar, myTime)) + if (! preInterpolation(interpolationPoints, &interpolationSettings, meteoSettings, &climateParameters, + meteoPoints, nrMeteoPoints, myVar, myTime, errorStdStr)) { - logError("Interpolation: error in function preInterpolation"); + logError("Error in function preInterpolation:\n" + QString::fromStdString(errorStdStr)); return false; } @@ -2210,21 +2213,23 @@ bool Project::interpolationCv(meteoVariable myVar, const Crit3DTime& myTime, cro bool Project::interpolationDem(meteoVariable myVar, const Crit3DTime& myTime, gis::Crit3DRasterGrid *myRaster) { std::vector interpolationPoints; + std::string errorStdStr; // check quality and pass data to interpolation - if (!checkAndPassDataToInterpolation(quality, myVar, meteoPoints, nrMeteoPoints, myTime, + if (! checkAndPassDataToInterpolation(quality, myVar, meteoPoints, nrMeteoPoints, myTime, &qualityInterpolationSettings, &interpolationSettings, meteoSettings, &climateParameters, interpolationPoints, - checkSpatialQuality)) + checkSpatialQuality, errorStdStr)) { - errorString = "No data available: " + QString::fromStdString(getVariableString(myVar)); + errorString = "No data available: " + QString::fromStdString(getVariableString(myVar)) + + "\n" + QString::fromStdString(errorStdStr); return false; } // detrending, checking precipitation and optimizing td parameters if (! preInterpolation(interpolationPoints, &interpolationSettings, meteoSettings, - &climateParameters, meteoPoints, nrMeteoPoints, myVar, myTime)) + &climateParameters, meteoPoints, nrMeteoPoints, myVar, myTime, errorStdStr)) { - errorString = "Error in function preInterpolation."; + errorString = "Error in function preInterpolation:\n" + QString::fromStdString(errorStdStr); return false; } @@ -2257,11 +2262,14 @@ bool Project::interpolationDemLocalDetrending(meteoVariable myVar, const Crit3DT // pass data to interpolation std::vector interpolationPoints; + std::string errorStdStr; + if (!checkAndPassDataToInterpolation(quality, myVar, meteoPoints, nrMeteoPoints, myTime, &qualityInterpolationSettings, &interpolationSettings, meteoSettings, &climateParameters, interpolationPoints, - checkSpatialQuality)) + checkSpatialQuality, errorStdStr)) { - logError("No data available: " + QString::fromStdString(getVariableString(myVar))); + errorString = "No data available: " + QString::fromStdString(getVariableString(myVar)) + + "\n" + QString::fromStdString(errorStdStr); return false; } @@ -2286,7 +2294,13 @@ bool Project::interpolationDemLocalDetrending(meteoVariable myVar, const Crit3DT { std::vector subsetInterpolationPoints; localSelection(interpolationPoints, subsetInterpolationPoints, x, y, interpolationSettings); - preInterpolation(subsetInterpolationPoints, &interpolationSettings, meteoSettings, &climateParameters, meteoPoints, nrMeteoPoints, myVar, myTime); + if (! preInterpolation(subsetInterpolationPoints, &interpolationSettings, meteoSettings, &climateParameters, + meteoPoints, nrMeteoPoints, myVar, myTime, errorStdStr)) + { + errorString = "Error in function preInterpolation:\n" + QString::fromStdString(errorStdStr); + return false; + } + getProxyValuesXY(x, y, &interpolationSettings, proxyValues); outputPoints[i].currentValue = interpolate(subsetInterpolationPoints, &interpolationSettings, meteoSettings, myVar, x, y, outputPoints[i].z, proxyValues, true); @@ -2312,7 +2326,13 @@ bool Project::interpolationDemLocalDetrending(meteoVariable myVar, const Crit3DT std::vector subsetInterpolationPoints; localSelection(interpolationPoints, subsetInterpolationPoints, x, y, interpolationSettings); - preInterpolation(subsetInterpolationPoints, &interpolationSettings, meteoSettings, &climateParameters, meteoPoints, nrMeteoPoints, myVar, myTime); + if (! preInterpolation(subsetInterpolationPoints, &interpolationSettings, meteoSettings, &climateParameters, + meteoPoints, nrMeteoPoints, myVar, myTime, errorStdStr)) + { + errorString = "Error in function preInterpolation:\n" + QString::fromStdString(errorStdStr); + return false; + } + getProxyValuesXY(x, y, &interpolationSettings, proxyValues); myRaster->value[row][col] = interpolate(subsetInterpolationPoints, &interpolationSettings, meteoSettings, myVar, x, y, z, proxyValues, true); @@ -2360,17 +2380,24 @@ bool Project::interpolateDemRadiation(const Crit3DTime& myTime, gis::Crit3DRaste } bool result; + std::string errorStdStr; + result = checkAndPassDataToInterpolation(quality, atmTransmissivity, meteoPoints, nrMeteoPoints, myTime, &qualityInterpolationSettings, &interpolationSettings, - meteoSettings, &climateParameters, interpolationPoints, checkSpatialQuality); + meteoSettings, &climateParameters, + interpolationPoints, checkSpatialQuality, errorStdStr); if (! result) { logError("Error in function interpolateDemRadiation: not enough transmissivity data."); return false; } - preInterpolation(interpolationPoints, &interpolationSettings, meteoSettings, &climateParameters, - meteoPoints, nrMeteoPoints, atmTransmissivity, myTime); + if (! preInterpolation(interpolationPoints, &interpolationSettings, meteoSettings, &climateParameters, + meteoPoints, nrMeteoPoints, atmTransmissivity, myTime, errorStdStr)) + { + logError("Error in function preInterpolation:\n" + QString::fromStdString(errorStdStr)); + return false; + } // interpolate transmissivity if (getComputeOnlyPoints()) @@ -2511,11 +2538,12 @@ bool Project::interpolationGrid(meteoVariable myVar, const Crit3DTime& myTime) return false; std::vector interpolationPoints; + std::string errorStdStr; // check quality and pass data to interpolation - if (!checkAndPassDataToInterpolation(quality, myVar, meteoPoints, nrMeteoPoints, myTime, + if (! checkAndPassDataToInterpolation(quality, myVar, meteoPoints, nrMeteoPoints, myTime, &qualityInterpolationSettings, &interpolationSettings, meteoSettings, &climateParameters, interpolationPoints, - checkSpatialQuality)) + checkSpatialQuality, errorStdStr)) { logError("No data available: " + QString::fromStdString(getVariableString(myVar))); return false; @@ -2526,9 +2554,9 @@ bool Project::interpolationGrid(meteoVariable myVar, const Crit3DTime& myTime) if (! interpolationSettings.getUseLocalDetrending()) { if (! preInterpolation(interpolationPoints, &interpolationSettings, meteoSettings, - &climateParameters, meteoPoints, nrMeteoPoints, myVar, myTime)) + &climateParameters, meteoPoints, nrMeteoPoints, myVar, myTime, errorStdStr)) { - logError("Interpolation: error in function preInterpolation"); + logError("Error in function preInterpolation:\n" + QString::fromStdString(errorStdStr)); return false; } myCombination = interpolationSettings.getCurrentCombination(); @@ -2588,7 +2616,14 @@ bool Project::interpolationGrid(meteoVariable myVar, const Crit3DTime& myTime) { std::vector subsetInterpolationPoints; localSelection(interpolationPoints, subsetInterpolationPoints, myX, myY, interpolationSettings); - preInterpolation(subsetInterpolationPoints, &interpolationSettings, meteoSettings, &climateParameters, meteoPoints, nrMeteoPoints, myVar, myTime); + + if (! preInterpolation(subsetInterpolationPoints, &interpolationSettings, meteoSettings, + &climateParameters, meteoPoints, nrMeteoPoints, myVar, myTime, errorStdStr)) + { + logError("Error in function preInterpolation:\n" + QString::fromStdString(errorStdStr)); + return false; + } + interpolatedValue = interpolate(subsetInterpolationPoints, &interpolationSettings, meteoSettings, myVar, myX, myY, myZ, proxyValues, true); } else diff --git a/proxyWidget/proxyWidget.cpp b/proxyWidget/proxyWidget.cpp index 5025c88c..16989497 100644 --- a/proxyWidget/proxyWidget.cpp +++ b/proxyWidget/proxyWidget.cpp @@ -285,17 +285,22 @@ void Crit3DProxyWidget::plot() chartView->cleanScatterSeries(); outInterpolationPoints.clear(); + std::string errorStdStr; if (detrended.isChecked()) { outInterpolationPoints.clear(); + checkAndPassDataToInterpolation(quality, myVar, meteoPoints, nrMeteoPoints, getCurrentTime(), SQinterpolationSettings, - interpolationSettings, meteoSettings, climateParam, outInterpolationPoints, checkSpatialQuality); + interpolationSettings, meteoSettings, climateParam, + outInterpolationPoints, checkSpatialQuality, errorStdStr); + detrending(outInterpolationPoints, interpolationSettings->getSelectedCombination(), interpolationSettings, climateParam, myVar, getCurrentTime()); } else { checkAndPassDataToInterpolation(quality, myVar, meteoPoints, nrMeteoPoints, getCurrentTime(), SQinterpolationSettings, - interpolationSettings, meteoSettings, climateParam, outInterpolationPoints, checkSpatialQuality); + interpolationSettings, meteoSettings, climateParam, + outInterpolationPoints, checkSpatialQuality, errorStdStr); } QList pointListPrimary, pointListSecondary, pointListSupplemental, pointListMarked; QMap< QString, QPointF > idPointMap1; diff --git a/synchronicityWidget/synchronicityWidget.cpp b/synchronicityWidget/synchronicityWidget.cpp index ad044a5c..eb5485ce 100644 --- a/synchronicityWidget/synchronicityWidget.cpp +++ b/synchronicityWidget/synchronicityWidget.cpp @@ -285,21 +285,23 @@ void Crit3DSynchronicityWidget::addInterpolationGraph() progress.setValue(i+1); progress.close(); + std::string errorStdStr; for (QDate currentDate = interpolationStartDate; currentDate <= myEndDate; currentDate = currentDate.addDays(1)) { float myValue1 = dailyValues[firstDaily.daysTo(currentDate)+myLag]; // check quality and pass data to interpolation if (!checkAndPassDataToInterpolation(quality, myVar, meteoPoints, nrMeteoPoints, getCrit3DTime(currentDate, 1), &qualityInterpolationSettings, &interpolationSettings, meteoSettings, climateParameters, interpolationPoints, - checkSpatialQuality)) + checkSpatialQuality, errorStdStr)) { QMessageBox::critical(nullptr, "Error", "No data available"); return; } - if (! preInterpolation(interpolationPoints, &interpolationSettings, meteoSettings, climateParameters, meteoPoints, nrMeteoPoints, myVar, getCrit3DTime(currentDate, 1))) + if (! preInterpolation(interpolationPoints, &interpolationSettings, meteoSettings, climateParameters, + meteoPoints, nrMeteoPoints, myVar, getCrit3DTime(currentDate, 1), errorStdStr)) { - QMessageBox::critical(nullptr, "Error", "Interpolation: error in function preInterpolation"); + QMessageBox::critical(nullptr, "Error", "Error in function preInterpolation: " + QString::fromStdString(errorStdStr)); return; } float interpolatedValue = interpolate(interpolationPoints, &interpolationSettings, meteoSettings, myVar, From 2c922d893b2218b39626c7e628327b63c9e58d8a Mon Sep 17 00:00:00 2001 From: ftomei Date: Thu, 21 Mar 2024 14:21:49 +0100 Subject: [PATCH 46/72] fix proxy --- interpolation/interpolation.cpp | 11 ++++++----- interpolation/interpolationConstants.h | 20 ++++++++++---------- interpolation/interpolationSettings.cpp | 2 +- project/project.cpp | 10 +++++----- 4 files changed, 22 insertions(+), 21 deletions(-) diff --git a/interpolation/interpolation.cpp b/interpolation/interpolation.cpp index b6f6ae97..044ce502 100644 --- a/interpolation/interpolation.cpp +++ b/interpolation/interpolation.cpp @@ -1132,7 +1132,7 @@ void detrendPoints(std::vector &myPoints, Crit3DI proxyValue = myPoint->getProxyValue(pos); - if (getProxyPragaName(myProxy->getName()) == height) + if (getProxyPragaName(myProxy->getName()) == proxyHeight) { if (proxyValue != NODATA) { @@ -1198,7 +1198,7 @@ float retrend(meteoVariable myVar, vector myProxyValues, Crit3DInterpola { proxySlope = myProxy->getRegressionSlope(); - if (getProxyPragaName(myProxy->getName()) == height) + if (getProxyPragaName(myProxy->getName()) == proxyHeight) { if (mySettings->getUseThermalInversion() && myProxy->getInversionIsSignificative()) { @@ -1263,7 +1263,7 @@ void detrending(std::vector &myPoints, myProxy = mySettings->getProxy(pos); myProxy->setIsSignificant(false); - if (getProxyPragaName(myProxy->getName()) == height) + if (getProxyPragaName(myProxy->getName()) == proxyHeight) { if (regressionOrography(myPoints, myCombination, mySettings, myClimate, myTime, myVar, pos)) { @@ -1336,7 +1336,7 @@ bool setAllFittingParameters(Crit3DProxyCombination myCombination, Crit3DInterpo for (unsigned i=0; i < myCombination.getProxySize(); i++) if (mySettings->getProxy(i)->getIsSignificant()) { - if (getProxyPragaName(mySettings->getProxy(i)->getName()) == height) + if (getProxyPragaName(mySettings->getProxy(i)->getName()) == proxyHeight) myFunc.push_back(lapseRatePiecewise_two); else myFunc.push_back(functionLinear); @@ -1375,6 +1375,7 @@ bool setAllFittingParameters(Crit3DProxyCombination myCombination, Crit3DInterpo return myFunc.size() > 0; } + std::vector getfittingParameters(Crit3DProxyCombination myCombination, Crit3DInterpolationSettings* mySettings, std::vector paramOut, unsigned pos) { std::vector myParam; @@ -1384,7 +1385,7 @@ std::vector getfittingParameters(Crit3DProxyCombination myCombination, for (i=0; i < myCombination.getProxySize(); i++) if (myCombination.isProxyActive(i)) { - if (getProxyPragaName(mySettings->getProxy(i)->getName()) == height) + if (getProxyPragaName(mySettings->getProxy(i)->getName()) == proxyHeight) { if (i == pos) for (j=0; j<5; j++) diff --git a/interpolation/interpolationConstants.h b/interpolation/interpolationConstants.h index 76155481..e2d72a34 100644 --- a/interpolation/interpolationConstants.h +++ b/interpolation/interpolationConstants.h @@ -23,18 +23,18 @@ { "shepard_modified", shepard_modified } }; - enum TProxyVar { height, heightInversion, urbanFraction, orogIndex, seaDistance, aspect, slope, waterIndex, noProxy }; + enum TProxyVar { proxyHeight, proxyHeightInversion, proxyUrbanFraction, proxyOrogIndex, proxySeaDistance, proxyAspect, proxySlope, proxyWaterIndex, noProxy }; const std::map ProxyVarNames = { - { "elevation", height }, - { "altitude", height }, - { "orography", height }, - { "orogIndex", orogIndex }, - { "urbanFraction", urbanFraction }, - { "seaDistance", seaDistance }, - { "aspect", aspect }, - { "slope", slope }, - { "water_index", waterIndex} + { "elevation", proxyHeight }, + { "altitude", proxyHeight }, + { "orography", proxyHeight }, + { "orogIndex", proxyOrogIndex }, + { "urbanFraction", proxyUrbanFraction }, + { "seaDistance", proxySeaDistance }, + { "aspect", proxyAspect }, + { "slope", proxySlope }, + { "water_index", proxyWaterIndex} }; diff --git a/interpolation/interpolationSettings.cpp b/interpolation/interpolationSettings.cpp index 5d5ca9c5..e1c83853 100644 --- a/interpolation/interpolationSettings.cpp +++ b/interpolation/interpolationSettings.cpp @@ -663,7 +663,7 @@ void Crit3DInterpolationSettings::addProxy(Crit3DProxy myProxy, bool isActive_) { currentProxy.push_back(myProxy); - if (getProxyPragaName(myProxy.getName()) == height) + if (getProxyPragaName(myProxy.getName()) == proxyHeight) setIndexHeight(int(currentProxy.size())-1); selectedCombination.addProxyActive(isActive_); diff --git a/project/project.cpp b/project/project.cpp index 7eda4923..8af12e84 100644 --- a/project/project.cpp +++ b/project/project.cpp @@ -204,7 +204,7 @@ bool Project::checkProxy(const Crit3DProxy &myProxy, QString* error) return false; } - bool isHeight = (getProxyPragaName(name_) == height); + bool isHeight = (getProxyPragaName(name_) == proxyHeight); if (!isHeight && (myProxy.getGridName() == "") && (myProxy.getProxyTable() == "" && myProxy.getProxyField() == "")) { @@ -241,7 +241,7 @@ bool Project::addProxyToProject(std::vector proxyList, std::deque } for (i=0; i < interpolationSettings.getProxyNr(); i++) - if (getProxyPragaName(interpolationSettings.getProxy(i)->getName()) == height) setProxyDEM(); + if (getProxyPragaName(interpolationSettings.getProxy(i)->getName()) == proxyHeight) setProxyDEM(); return true; } @@ -683,15 +683,15 @@ bool Project::loadParameters(QString parametersFileName) { unsigned int nrParameters; - if (getProxyPragaName(name_.toStdString()) == height) - nrParameters = 4; + if (getProxyPragaName(name_.toStdString()) == proxyHeight) + nrParameters = 5; else nrParameters = 1; myList = parameters->value("fitting_parameters").toStringList(); if (myList.size() != nrParameters*2) { - errorString = "Incomplete fitting parameters for proxy " + name_; + errorString = "Wrong nr. of fitting parameters for proxy: " + name_; return false; } From b3ad1ff2ce8ba14930e92d3dd60420f9e07fdfe0 Mon Sep 17 00:00:00 2001 From: ftomei Date: Thu, 21 Mar 2024 14:37:45 +0100 Subject: [PATCH 47/72] clean proxy --- interpolation/interpolationConstants.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interpolation/interpolationConstants.h b/interpolation/interpolationConstants.h index e2d72a34..89d2a334 100644 --- a/interpolation/interpolationConstants.h +++ b/interpolation/interpolationConstants.h @@ -23,7 +23,7 @@ { "shepard_modified", shepard_modified } }; - enum TProxyVar { proxyHeight, proxyHeightInversion, proxyUrbanFraction, proxyOrogIndex, proxySeaDistance, proxyAspect, proxySlope, proxyWaterIndex, noProxy }; + enum TProxyVar { proxyHeight, proxyUrbanFraction, proxyOrogIndex, proxySeaDistance, proxyAspect, proxySlope, proxyWaterIndex, noProxy }; const std::map ProxyVarNames = { { "elevation", proxyHeight }, From 62932ef8a190143a2f924d023404cbd171be879c Mon Sep 17 00:00:00 2001 From: ftomei Date: Thu, 21 Mar 2024 15:24:20 +0100 Subject: [PATCH 48/72] fix gridding --- pragaProject/pragaProject.cpp | 2 +- pragaProject/pragaShell.cpp | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/pragaProject/pragaProject.cpp b/pragaProject/pragaProject.cpp index 7e870568..b1eb1355 100644 --- a/pragaProject/pragaProject.cpp +++ b/pragaProject/pragaProject.cpp @@ -2590,7 +2590,7 @@ bool PragaProject::interpolationMeteoGridPeriod(QDate dateIni, QDate dateFin, QL } } - if (countDaysSaving == nrDaysSaving || myDate == dateFin) + if (countDaysSaving == nrDaysSaving || myDate == dateFin || myDate == loadDateFin) { if (aggrVariables.count() > 0) { diff --git a/pragaProject/pragaShell.cpp b/pragaProject/pragaShell.cpp index 3ae30e3f..c626b131 100644 --- a/pragaProject/pragaShell.cpp +++ b/pragaProject/pragaShell.cpp @@ -20,6 +20,7 @@ QList getPragaCommandList() cmdList.append("CleanClimate | CleanClimate"); cmdList.append("Drought | ComputeDroughtIndexGrid"); cmdList.append("DroughtPoint | ComputeDroughtIndexPoint"); + cmdList.append("Gridding | InterpolationGridPeriod"); cmdList.append("GridAggr | GridAggregation"); cmdList.append("GridDerVar | GridDerivedVariables"); cmdList.append("GridMonthlyInt | GridMonthlyIntegrationVariables"); @@ -283,7 +284,7 @@ int cmdInterpolationGridPeriod(PragaProject* myProject, QList argumentL QDate dateIni, dateFin; bool saveRasters = false; - QList varString, aggrVarString; + QList varString; QList variables, aggrVariables; QString var; meteoVariable meteoVar; From 24f3afbb8e1b7a5e7576924b7cf742c4b37eac54 Mon Sep 17 00:00:00 2001 From: ftomei Date: Fri, 22 Mar 2024 14:30:18 +0100 Subject: [PATCH 49/72] update gridding cmd --- pragaProject/pragaProject.cpp | 23 ++++++++++------------- pragaProject/pragaShell.cpp | 4 +--- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/pragaProject/pragaProject.cpp b/pragaProject/pragaProject.cpp index b1eb1355..87fb1dda 100644 --- a/pragaProject/pragaProject.cpp +++ b/pragaProject/pragaProject.cpp @@ -2380,9 +2380,6 @@ bool PragaProject::interpolationMeteoGridPeriod(QDate dateIni, QDate dateFin, QL bool isDaily = false, isHourly = false; QList varToSave; int countDaysSaving = 0; - QDate loadDateFin; - QDate saveDateIni; - QString error; if (pragaDailyMaps == nullptr) pragaDailyMaps = new Crit3DDailyMeteoMaps(DEM); if (pragaHourlyMaps == nullptr) pragaHourlyMaps = new PragaHourlyMeteoMaps(DEM); @@ -2444,7 +2441,7 @@ bool PragaProject::interpolationMeteoGridPeriod(QDate dateIni, QDate dateFin, QL varToSave.push_back(myVar); int currentYear = NODATA; - saveDateIni = dateIni; + QDate saveDateIni = dateIni; if (nrDaysLoading == NODATA) nrDaysLoading = dateIni.daysTo(dateFin)+1; @@ -2452,6 +2449,8 @@ bool PragaProject::interpolationMeteoGridPeriod(QDate dateIni, QDate dateFin, QL if (nrDaysSaving == NODATA || nrDaysSaving > nrDaysLoading) nrDaysSaving = nrDaysLoading; + QDate loadDateFin = QDate(1800, 1, 1); + while (myDate <= dateFin) { countDaysSaving++; @@ -2475,16 +2474,14 @@ bool PragaProject::interpolationMeteoGridPeriod(QDate dateIni, QDate dateFin, QL if (useProxies && currentYear != myDate.year()) { logInfoGUI("Interpolating proxy grid series..."); - if (checkProxyGridSeries(&interpolationSettings, DEM, proxyGridSeries, myDate, &error)) - { - if (! readProxyValues()) return false; - currentYear = myDate.year(); - } - else - { - errorString = error; + + if (! checkProxyGridSeries(&interpolationSettings, DEM, proxyGridSeries, myDate, &errorString)) return false; - } + + if (! readProxyValues()) + return false; + + currentYear = myDate.year(); } if (isHourly) diff --git a/pragaProject/pragaShell.cpp b/pragaProject/pragaShell.cpp index c626b131..cc9dafc6 100644 --- a/pragaProject/pragaShell.cpp +++ b/pragaProject/pragaShell.cpp @@ -860,9 +860,7 @@ int pragaShell(PragaProject* myProject) int result = executeCommand(argumentList, myProject); if (result != 0) { - myProject->logError("Praga shell error code: " + QString::number(result)); - - //return result; + myProject->logError("Praga shell error code: " + QString::number(result) + "\n" + myProject->errorString); } } } From 32cc886e197e5b6758660d271ef775fa1391453d Mon Sep 17 00:00:00 2001 From: ftomei Date: Fri, 22 Mar 2024 18:10:09 +0100 Subject: [PATCH 50/72] add save criteria3d var output points --- meteo/meteo.cpp | 17 ++++++ meteo/meteo.h | 27 ++++++++- outputPoints/dbOutputPointsHandler.cpp | 82 ++++++++++++++++++++++++-- outputPoints/dbOutputPointsHandler.h | 6 ++ 4 files changed, 126 insertions(+), 6 deletions(-) diff --git a/meteo/meteo.cpp b/meteo/meteo.cpp index 9a6e6605..98ea76ad 100644 --- a/meteo/meteo.cpp +++ b/meteo/meteo.cpp @@ -1037,6 +1037,7 @@ meteoVariable getMeteoVar(std::string varString) return noMeteoVar; } + std::string getMeteoVarName(meteoVariable var) { auto search = MapDailyMeteoVarToString.find(var); @@ -1052,6 +1053,22 @@ std::string getMeteoVarName(meteoVariable var) return ""; } + +std::string getCriteria3DVarName(criteria3DVariable var) +{ + auto search = MapCriteria3DVarToString.find(var); + + if (search != MapCriteria3DVarToString.end()) + { + return search->second; + } + else + { + return ""; + } +} + + std::string getLapseRateCodeName(lapseRateCodeType code) { auto search = MapLapseRateCodeToString.find(code); diff --git a/meteo/meteo.h b/meteo/meteo.h index edd95cfa..648778fa 100644 --- a/meteo/meteo.h +++ b/meteo/meteo.h @@ -205,6 +205,7 @@ { "ACTUAL_EVAPO", actualEvaporation } }; + const std::map MapHourlyMeteoVarToString = { { airTemperature, "TAVG" }, { precipitation, "PREC" }, @@ -282,6 +283,25 @@ }; + const std::map MapCriteria3DVarToString = { + { volumetricWaterContent , "VOL_WC" }, + { waterTotalPotential , "TOT_WP" }, + { waterMatricPotential , "WP" }, + { availableWaterContent , "AWC" }, + { degreeOfSaturation , "SATDEG" }, + { factorOfSafety, "FOS" } + }; + + const std::map MapCriteria3DVar = { + { "VOL_WC", volumetricWaterContent }, + { "TOT_WP", waterTotalPotential }, + { "WP", waterMatricPotential }, + { "AWC", availableWaterContent }, + { "SATDEG", degreeOfSaturation }, + { "FOS", factorOfSafety } + }; + + enum frequencyType {hourly, daily, monthly, noFrequency}; enum surfaceType {SurfaceTypeWater, SurfaceTypeSoil, SurfaceTypeCrop}; @@ -345,13 +365,18 @@ std::string getKeyStringMeteoMap(std::map map, meteoVariable value); meteoVariable getKeyMeteoVarMeteoMap(std::map map, const std::string &value); meteoVariable getKeyMeteoVarMeteoMapWithoutUnderscore(std::map map, const std::string& value); + meteoVariable getMeteoVar(std::string varString); meteoVariable getHourlyMeteoVar(std::string varString); std::string getMeteoVarName(meteoVariable var); - std::string getLapseRateCodeName(lapseRateCodeType code); + std::string getCriteria3DVarName(criteria3DVariable var); + + std::string getLapseRateCodeName(lapseRateCodeType code); bool checkLapseRateCode(lapseRateCodeType myType, bool useLapseRateCode, bool useSupplemental); + meteoVariable getDailyMeteoVarFromHourly(meteoVariable myVar, aggregationMethod myAggregation); + meteoVariable updateMeteoVariable(meteoVariable myVar, frequencyType myFreq); diff --git a/outputPoints/dbOutputPointsHandler.cpp b/outputPoints/dbOutputPointsHandler.cpp index 4e8c9b04..9f47ce5f 100644 --- a/outputPoints/dbOutputPointsHandler.cpp +++ b/outputPoints/dbOutputPointsHandler.cpp @@ -104,15 +104,17 @@ bool Crit3DOutputPointsDbHandler::addColumn(QString tableName, meteoVariable myV // depth [cm] bool Crit3DOutputPointsDbHandler::addCriteria3DColumn(const QString &tableName, criteria3DVariable myVar, int depth, QString& errorStr) { - // column name - /* - QString newField = QString::fromStdString(getMeteoVarName(myVar)); - if (newField == "") + // variable name + QString variableString = QString::fromStdString(getCriteria3DVarName(myVar)); + if (variableString == "") { errorStr = "Missing variable name."; return false; } + // column name + QString newField = variableString + "_" + QString::number(depth); + // column exists already QList fieldList = getFields(&_db, tableName); if (fieldList.contains(newField)) @@ -130,7 +132,7 @@ bool Crit3DOutputPointsDbHandler::addCriteria3DColumn(const QString &tableName, errorStr = "Error in add column: " + newField + "\n" + myQuery.lastError().text(); return false; } -*/ + return true; } @@ -191,3 +193,73 @@ bool Crit3DOutputPointsDbHandler::saveHourlyMeteoData(QString tableName, const Q return true; } + +// layerDepth [m] +bool Crit3DOutputPointsDbHandler::saveHourlyCriteria3D_Data(QString tableName, const QDateTime& myTime, + const std::vector& varList, + const std::vector& values, + const std::vector & layerDepth, + QString& errorStr) +{ + int nrSoilLayers = int(layerDepth.size()) - 1; + if (nrSoilLayers <= 0) + { + errorStr = "Error saving values: missing soil layers."; + return false; + } + + int nrValues = varList.size() * nrSoilLayers; + if (nrValues != values.size()) + { + errorStr = "Error saving values: number of values is not as expected."; + return false; + } + + // TODO delete data (date, hour) se questo è l'unico salvataggio + QString timeStr = myTime.toString("yyyy-MM-dd HH:mm:ss"); + + // field list + QString fieldList = ""; + for (unsigned int i = 0; i < varList.size(); i++) + { + QString variableString = QString::fromStdString(getCriteria3DVarName(varList[i])); + if (variableString == "") + { + errorStr = "Missing variable name."; + return false; + } + + for (int layer = 1; layer <= nrSoilLayers; layer++) + { + int depth = round(layerDepth[layer] * 100); // [cm] + + QString newField = variableString + "_" + QString::number(depth); + fieldList += "'" + newField + "'"; + if (i < nrSoilLayers) + fieldList += ","; + } + } + + // values list + QString valuesList = ""; + for (unsigned int i = 0; i < varList.size(); i++) + { + for (int layer = 1; layer <= nrSoilLayers; layer++) + { + valuesList += QString::number(values[i], 'f', 2); + if (i < nrSoilLayers) + valuesList += ","; + } + } + + QSqlQuery qry(_db); + QString queryString = QString("INSERT INTO '%1' (%2) VALUES (%3) WHERE DATE_TIME ='%4'").arg(tableName, fieldList, valuesList, timeStr); + if (! qry.exec(queryString)) + { + errorStr = QString("Error in query: " + queryString + "\n" + qry.lastError().text()); + return false; + } + + return true; +} + diff --git a/outputPoints/dbOutputPointsHandler.h b/outputPoints/dbOutputPointsHandler.h index 467da87b..0c97883b 100644 --- a/outputPoints/dbOutputPointsHandler.h +++ b/outputPoints/dbOutputPointsHandler.h @@ -28,6 +28,12 @@ const std::vector &varList, const std::vector &values, QString& errorStr); + bool saveHourlyCriteria3D_Data(QString tableName, const QDateTime& myTime, + const std::vector& varList, + const std::vector& values, + const std::vector & layerDepth, + QString& errorStr); + private: QSqlDatabase _db; From e74c1068e3ea74d42f1f253da456dc58868215cf Mon Sep 17 00:00:00 2001 From: ftomei Date: Fri, 22 Mar 2024 18:34:20 +0100 Subject: [PATCH 51/72] add save criteria3d var output points --- outputPoints/dbOutputPointsHandler.cpp | 28 +++++++++----------------- 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/outputPoints/dbOutputPointsHandler.cpp b/outputPoints/dbOutputPointsHandler.cpp index 9f47ce5f..07a18484 100644 --- a/outputPoints/dbOutputPointsHandler.cpp +++ b/outputPoints/dbOutputPointsHandler.cpp @@ -215,11 +215,10 @@ bool Crit3DOutputPointsDbHandler::saveHourlyCriteria3D_Data(QString tableName, c return false; } - // TODO delete data (date, hour) se questo è l'unico salvataggio QString timeStr = myTime.toString("yyyy-MM-dd HH:mm:ss"); // field list - QString fieldList = ""; + QString setList = ""; for (unsigned int i = 0; i < varList.size(); i++) { QString variableString = QString::fromStdString(getCriteria3DVarName(varList[i])); @@ -233,27 +232,20 @@ bool Crit3DOutputPointsDbHandler::saveHourlyCriteria3D_Data(QString tableName, c { int depth = round(layerDepth[layer] * 100); // [cm] - QString newField = variableString + "_" + QString::number(depth); - fieldList += "'" + newField + "'"; - if (i < nrSoilLayers) - fieldList += ","; - } - } + QString fieldName = variableString + "_" + QString::number(depth); + setList += "'" + fieldName + "'="; - // values list - QString valuesList = ""; - for (unsigned int i = 0; i < varList.size(); i++) - { - for (int layer = 1; layer <= nrSoilLayers; layer++) - { - valuesList += QString::number(values[i], 'f', 2); - if (i < nrSoilLayers) - valuesList += ","; + int index = i * nrSoilLayers + layer - 1; + QString valueStr = QString::number(values[index], 'f', 2); + setList += valueStr; + + if (index < (nrValues - 1)) + setList += ","; } } QSqlQuery qry(_db); - QString queryString = QString("INSERT INTO '%1' (%2) VALUES (%3) WHERE DATE_TIME ='%4'").arg(tableName, fieldList, valuesList, timeStr); + QString queryString = QString("UPDATE '%1' SET %2 WHERE DATE_TIME ='%3'").arg(tableName, setList, timeStr); if (! qry.exec(queryString)) { errorStr = QString("Error in query: " + queryString + "\n" + qry.lastError().text()); From b08310cb4742f82860aec3c6a152fe7e95305a61 Mon Sep 17 00:00:00 2001 From: ftomei Date: Fri, 22 Mar 2024 19:27:08 +0100 Subject: [PATCH 52/72] update output points --- outputPoints/dbOutputPointsHandler.cpp | 36 ++++++--------------- outputPoints/dbOutputPointsHandler.h | 43 ++++++++++++++------------ outputPoints/dialogNewPoint.cpp | 32 ++++--------------- outputPoints/dialogNewPoint.h | 22 ++++++------- outputPoints/outputPoints.cpp | 13 ++++---- outputPoints/outputPoints.h | 10 +++--- 6 files changed, 63 insertions(+), 93 deletions(-) diff --git a/outputPoints/dbOutputPointsHandler.cpp b/outputPoints/dbOutputPointsHandler.cpp index 07a18484..08a7cd47 100644 --- a/outputPoints/dbOutputPointsHandler.cpp +++ b/outputPoints/dbOutputPointsHandler.cpp @@ -36,23 +36,7 @@ Crit3DOutputPointsDbHandler::~Crit3DOutputPointsDbHandler() } -bool Crit3DOutputPointsDbHandler::isOpen() -{ - return _db.isOpen(); -} - -QString Crit3DOutputPointsDbHandler::getDbName() -{ - return _db.databaseName(); -} - -QString Crit3DOutputPointsDbHandler::getErrorString() -{ - return errorString; -} - - -bool Crit3DOutputPointsDbHandler::createTable(QString tableName, QString& errorStr) +bool Crit3DOutputPointsDbHandler::createTable(const QString& tableName, QString& errorStr) { QString queryString = "CREATE TABLE IF NOT EXISTS '" + tableName + "'"; queryString += " (DATE_TIME TEXT, PRIMARY KEY(DATE_TIME))"; @@ -69,7 +53,7 @@ bool Crit3DOutputPointsDbHandler::createTable(QString tableName, QString& errorS } -bool Crit3DOutputPointsDbHandler::addColumn(QString tableName, meteoVariable myVar, QString& errorStr) +bool Crit3DOutputPointsDbHandler::addColumn(const QString &tableName, meteoVariable myVar, QString& errorStr) { // column name QString newField = QString::fromStdString(getMeteoVarName(myVar)); @@ -117,7 +101,7 @@ bool Crit3DOutputPointsDbHandler::addCriteria3DColumn(const QString &tableName, // column exists already QList fieldList = getFields(&_db, tableName); - if (fieldList.contains(newField)) + if ( fieldList.contains(newField) ) { return true; } @@ -137,10 +121,10 @@ bool Crit3DOutputPointsDbHandler::addCriteria3DColumn(const QString &tableName, } -bool Crit3DOutputPointsDbHandler::saveHourlyMeteoData(QString tableName, const QDateTime& myTime, - const std::vector& varList, - const std::vector& values, - QString& errorStr) +bool Crit3DOutputPointsDbHandler::saveHourlyMeteoData(const QString &tableName, const QDateTime &myTime, + const std::vector &varList, + const std::vector &values, + QString &errorStr) { if (varList.size() != values.size()) { @@ -195,11 +179,11 @@ bool Crit3DOutputPointsDbHandler::saveHourlyMeteoData(QString tableName, const Q // layerDepth [m] -bool Crit3DOutputPointsDbHandler::saveHourlyCriteria3D_Data(QString tableName, const QDateTime& myTime, +bool Crit3DOutputPointsDbHandler::saveHourlyCriteria3D_Data(const QString &tableName, const QDateTime& myTime, const std::vector& varList, const std::vector& values, const std::vector & layerDepth, - QString& errorStr) + QString &errorStr) { int nrSoilLayers = int(layerDepth.size()) - 1; if (nrSoilLayers <= 0) @@ -208,7 +192,7 @@ bool Crit3DOutputPointsDbHandler::saveHourlyCriteria3D_Data(QString tableName, c return false; } - int nrValues = varList.size() * nrSoilLayers; + int nrValues = int(varList.size()) * nrSoilLayers; if (nrValues != values.size()) { errorStr = "Error saving values: number of values is not as expected."; diff --git a/outputPoints/dbOutputPointsHandler.h b/outputPoints/dbOutputPointsHandler.h index 0c97883b..00742d1f 100644 --- a/outputPoints/dbOutputPointsHandler.h +++ b/outputPoints/dbOutputPointsHandler.h @@ -14,28 +14,31 @@ explicit Crit3DOutputPointsDbHandler(QString dbname_); ~Crit3DOutputPointsDbHandler(); - void closeDatabase(); - QSqlDatabase getDb() const; - QString getDbName(); - QString getErrorString(); - bool isOpen(); - - bool createTable(QString tableName, QString &errorStr); - bool addColumn(QString tableName, meteoVariable myVar, QString &errorString); - bool addCriteria3DColumn(const QString &tableName, criteria3DVariable myVar, int depth, QString& errorStr); - - bool saveHourlyMeteoData(QString tableName, const QDateTime &myTime, - const std::vector &varList, - const std::vector &values, QString& errorStr); - - bool saveHourlyCriteria3D_Data(QString tableName, const QDateTime& myTime, - const std::vector& varList, - const std::vector& values, - const std::vector & layerDepth, - QString& errorStr); + QString getDbName() { + return _db.databaseName(); } - private: + QString getErrorString() { + return errorString; } + + bool isOpen() { + return _db.isOpen(); } + + bool createTable(const QString &tableName, QString &errorStr); + + bool addColumn(const QString &tableName, meteoVariable myVar, QString &errorString); + bool addCriteria3DColumn(const QString &tableName, criteria3DVariable myVar, int depth, QString &errorStr); + + bool saveHourlyMeteoData(const QString &tableName, const QDateTime &myTime, + const std::vector &varList, + const std::vector &values, QString &errorStr); + + bool saveHourlyCriteria3D_Data(const QString &tableName, const QDateTime &myTime, + const std::vector &varList, + const std::vector &values, + const std::vector &layerDepth, QString &errorStr); + + private: QSqlDatabase _db; QString errorString; }; diff --git a/outputPoints/dialogNewPoint.cpp b/outputPoints/dialogNewPoint.cpp index bae3ebc8..f44c2eab 100644 --- a/outputPoints/dialogNewPoint.cpp +++ b/outputPoints/dialogNewPoint.cpp @@ -1,9 +1,10 @@ #include "dialogNewPoint.h" +#include "basicMath.h" + DialogNewPoint::DialogNewPoint(const QList& _idList, const gis::Crit3DGisSettings& _gisSettings, gis::Crit3DRasterGrid* _DEMptr) :idList(_idList), gisSettings(_gisSettings), DEMpointer(_DEMptr) { - setWindowTitle("New point"); this->resize(300, 180); this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); @@ -101,11 +102,9 @@ DialogNewPoint::~DialogNewPoint() void DialogNewPoint::computeUTM() { if (utmx.text().isEmpty() || utmy.text().isEmpty()) - { return; - } - double myLat; - double myLon; + + double myLat, myLon; gis::getLatLonFromUtm(gisSettings, utmx.text().toDouble(), utmy.text().toDouble(), &myLat, &myLon); lat.setText(QString::number(myLat)); lon.setText(QString::number(myLon)); @@ -121,6 +120,7 @@ void DialogNewPoint::getFromDEM() QMessageBox::information(nullptr, "DEM not loaded", "Load DEM"); return; } + float demValue; if (utmx.text().isEmpty() || utmy.text().isEmpty()) { @@ -139,7 +139,7 @@ void DialogNewPoint::getFromDEM() demValue = gis::getValueFromXY(*DEMpointer, utmx.text().toDouble(), utmy.text().toDouble()); } - if (demValue != DEMpointer->header->flag) + if (! isEqual(demValue, DEMpointer->header->flag)) { height.setText(QString::number(demValue)); } @@ -225,23 +225,3 @@ void DialogNewPoint::done(int res) return; } } - -QString DialogNewPoint::getId() -{ - return id.text(); -} - -double DialogNewPoint::getLat() -{ - return lat.text().toDouble(); -} - -double DialogNewPoint::getLon() -{ - return lon.text().toDouble(); -} - -double DialogNewPoint::getHeight() -{ - return height.text().toDouble(); -} diff --git a/outputPoints/dialogNewPoint.h b/outputPoints/dialogNewPoint.h index 75a07906..50ed8ff4 100644 --- a/outputPoints/dialogNewPoint.h +++ b/outputPoints/dialogNewPoint.h @@ -12,26 +12,26 @@ class DialogNewPoint : public QDialog DialogNewPoint(const QList& _idList, const gis::Crit3DGisSettings& _gisSettings, gis::Crit3DRasterGrid* _DEMptr); ~DialogNewPoint(); - void done(int res); + QString getId() { return id.text(); } + double getLat() { return lat.text().toDouble(); } + double getLon() { return lon.text().toDouble(); } + double getHeight() { return height.text().toDouble(); } void setDEM(); void computeUTM(); void getFromDEM(); - QString getId(); - double getLat(); - double getLon(); - double getHeight(); + + void done(int res); private: QList idList; + gis::Crit3DGisSettings gisSettings; gis::Crit3DRasterGrid* DEMpointer; - QLineEdit id; - QLineEdit utmx; - QLineEdit utmy; - QLineEdit lat; - QLineEdit lon; - QLineEdit height; + + QLineEdit id, utmx, utmy; + QLineEdit lat, lon, height; + QPushButton computeUTMButton; QPushButton getFromDEMButton; }; diff --git a/outputPoints/outputPoints.cpp b/outputPoints/outputPoints.cpp index e828bfb2..613686e0 100644 --- a/outputPoints/outputPoints.cpp +++ b/outputPoints/outputPoints.cpp @@ -7,11 +7,11 @@ -bool loadOutputPointListCsv(QString csvFileName, std::vector &outputPointList, - int utmZone, QString &errorString) +bool loadOutputPointListCsv(const QString &csvFileName, std::vector &outputPointList, + int utmZone, QString &errorString) { QList> data; - if (!importOutputPointsCsv(csvFileName, data, errorString)) + if (! importPointPropertiesCsv(csvFileName, data, errorString)) return false; for (int i = 0; i < data.size(); i++) @@ -32,7 +32,7 @@ bool loadOutputPointListCsv(QString csvFileName, std::vector &outputPointList, QString &errorString) +bool writeOutputPointListCsv(const QString &csvFileName, std::vector &outputPointList, QString &errorString) { errorString.clear(); if (csvFileName == "") @@ -84,7 +84,7 @@ bool writeOutputPointListCsv(QString csvFileName, std::vector> &data, QString &errorString) +bool importPointPropertiesCsv(const QString &csvFileName, QList> &pointsProperties, QString &errorString) { errorString.clear(); if (csvFileName == "") @@ -178,7 +178,8 @@ bool importOutputPointsCsv(QString csvFileName, QList> &data, QSt myFile.close(); return false; } - data.append(line); + + pointsProperties.append(line); } myFile.close(); diff --git a/outputPoints/outputPoints.h b/outputPoints/outputPoints.h index 79b2f636..6988283d 100644 --- a/outputPoints/outputPoints.h +++ b/outputPoints/outputPoints.h @@ -6,12 +6,14 @@ #endif #include - bool importOutputPointsCsv(QString csvFileName, QList> &data, QString &errorString); + bool importPointPropertiesCsv(const QString &csvFileName, QList> &pointsProperties, + QString &errorString); - bool loadOutputPointListCsv(QString csvFileName, std::vector &outputPointList, - int utmZone, QString &errorString); + bool loadOutputPointListCsv(const QString &csvFileName, std::vector &outputPointList, + int utmZone, QString &errorString); - bool writeOutputPointListCsv(QString csvFileName, std::vector &outputPointList, QString &errorString); + bool writeOutputPointListCsv(const QString &csvFileName, std::vector &outputPointList, + QString &errorString); #endif // OUTPUTPOINTS_H From 794871508edfcba1dae5b9800e88c3f55616e5ec Mon Sep 17 00:00:00 2001 From: lauracosta Date: Mon, 25 Mar 2024 10:16:39 +0100 Subject: [PATCH 53/72] isMonthly --- dbMeteoGrid/dbMeteoGrid.cpp | 13 ++++++++++++- dbMeteoGrid/dbMeteoGrid.h | 3 ++- project/project.cpp | 19 +++++++++++++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/dbMeteoGrid/dbMeteoGrid.cpp b/dbMeteoGrid/dbMeteoGrid.cpp index e52e77cb..b06d3439 100644 --- a/dbMeteoGrid/dbMeteoGrid.cpp +++ b/dbMeteoGrid/dbMeteoGrid.cpp @@ -3682,6 +3682,17 @@ bool Crit3DMeteoGridDbHandler::isHourly() return true; } +bool Crit3DMeteoGridDbHandler::isMonthly() +{ + if ( ! _firstMonthlyDate.isValid() || _firstMonthlyDate.year() == 1800 + || ! _lastMonthlyDate.isValid() || _lastMonthlyDate.year() == 1800 ) + { + return false; + } + + return true; +} + QDate Crit3DMeteoGridDbHandler::getFirstDailyDate() const { @@ -3719,7 +3730,7 @@ QDate Crit3DMeteoGridDbHandler::getLastHourlyDate() const return _lastHourlyDate; } -QDate Crit3DMeteoGridDbHandler::getFirsMonthlytDate() const +QDate Crit3DMeteoGridDbHandler::getFirstMonthlytDate() const { if (_firstMonthlyDate.year() == 1800) { diff --git a/dbMeteoGrid/dbMeteoGrid.h b/dbMeteoGrid/dbMeteoGrid.h index da8305e5..94977657 100644 --- a/dbMeteoGrid/dbMeteoGrid.h +++ b/dbMeteoGrid/dbMeteoGrid.h @@ -168,11 +168,12 @@ QDate getLastDailyDate() const; QDate getFirstHourlyDate() const; QDate getLastHourlyDate() const; - QDate getFirsMonthlytDate() const; + QDate getFirstMonthlytDate() const; QDate getLastMonthlyDate() const; bool isDaily(); bool isHourly(); + bool isMonthly(); bool saveLogProcedures(QString *myError, QString nameProc, QDate date); diff --git a/project/project.cpp b/project/project.cpp index 8af12e84..94a613cf 100644 --- a/project/project.cpp +++ b/project/project.cpp @@ -3306,6 +3306,9 @@ void Project::showMeteoWidgetGrid(std::string idCell, bool isAppend) { QDate firstDate = meteoGridDbHandler->firstDate(); QDate lastDate = meteoGridDbHandler->lastDate(); + QDate firstMonthlyDate = meteoGridDbHandler->getFirstMonthlytDate(); + QDate lastMonthlyDate = meteoGridDbHandler->getFirstMonthlytDate(); + QDateTime firstDateTime, lastDateTime; if (meteoGridDbHandler->getFirstHourlyDate().isValid()) @@ -3343,6 +3346,10 @@ void Project::showMeteoWidgetGrid(std::string idCell, bool isAppend) { meteoGridDbHandler->loadGridHourlyData(errorString, QString::fromStdString(idCell), firstDateTime, lastDateTime); } + if (meteoGridDbHandler->isMonthly()) + { + meteoGridDbHandler->loadGridMonthlyData(errorString, QString::fromStdString(idCell), firstMonthlyDate, lastMonthlyDate); + } } else { @@ -3354,6 +3361,10 @@ void Project::showMeteoWidgetGrid(std::string idCell, bool isAppend) { meteoGridDbHandler->loadGridHourlyDataFixedFields(errorString, QString::fromStdString(idCell), firstDateTime, lastDateTime); } + if (meteoGridDbHandler->isMonthly()) + { + meteoGridDbHandler->loadGridMonthlyData(errorString, QString::fromStdString(idCell), firstMonthlyDate, lastMonthlyDate); + } } closeLogInfo(); @@ -3436,6 +3447,10 @@ void Project::showMeteoWidgetGrid(std::string idCell, bool isAppend) { meteoGridDbHandler->loadGridHourlyData(errorString, QString::fromStdString(idCell), firstDateTime, lastDateTime); } + if (meteoGridDbHandler->isMonthly()) + { + meteoGridDbHandler->loadGridMonthlyData(errorString, QString::fromStdString(idCell), firstMonthlyDate, lastMonthlyDate); + } } else { @@ -3447,6 +3462,10 @@ void Project::showMeteoWidgetGrid(std::string idCell, bool isAppend) { meteoGridDbHandler->loadGridHourlyDataFixedFields(errorString, QString::fromStdString(idCell), firstDateTime, lastDateTime); } + if (meteoGridDbHandler->isMonthly()) + { + meteoGridDbHandler->loadGridMonthlyData(errorString, QString::fromStdString(idCell), firstMonthlyDate, lastMonthlyDate); + } } closeLogInfo(); From e7d1005aa68dddd36f31f8081705f285214ea90c Mon Sep 17 00:00:00 2001 From: lauracosta Date: Mon, 25 Mar 2024 10:39:47 +0100 Subject: [PATCH 54/72] getFirstMonthlyDate --- meteoWidget/meteoWidget.cpp | 106 ++++++++++++++++++++++++++---------- 1 file changed, 78 insertions(+), 28 deletions(-) diff --git a/meteoWidget/meteoWidget.cpp b/meteoWidget/meteoWidget.cpp index b8beb807..a951730a 100644 --- a/meteoWidget/meteoWidget.cpp +++ b/meteoWidget/meteoWidget.cpp @@ -1590,30 +1590,55 @@ void Crit3DMeteoWidget::showMonthlyGraph() void Crit3DMeteoWidget::showDailyGraph() { if (! isInitialized) return; - + frequencyType prevFreq = currentFreq; currentFreq = daily; dailyButton->setEnabled(false); hourlyButton->setEnabled(true); monthlyButton->setEnabled(true); - QList currentHourlyVar = currentVariables; - currentVariables.clear(); - - for (int i = 0; i currentHourlyVar = currentVariables; + currentVariables.clear(); + for (int i = 0; i currentMonthlyVar = currentVariables; + currentVariables.clear(); + for (int i = 0; isetEnabled(false); dailyButton->setEnabled(true); monthlyButton->setEnabled(true); - QList currentDailyVar = currentVariables; - currentVariables.clear(); - - for (int i = 0; i < currentDailyVar.size(); i++) + if (prevFreq == daily) { - QString name = currentDailyVar[i]; - auto searchDaily = MapDailyMeteoVar.find(name.toStdString()); - if (searchDaily != MapDailyMeteoVar.end()) + QList currentDailyVar = currentVariables; + currentVariables.clear(); + for (int i = 0; i < currentDailyVar.size(); i++) { - meteoVariable dailyVar = getMeteoVar(name.toStdString()); - meteoVariable hourlyVar= updateMeteoVariable(dailyVar, hourly); - if (hourlyVar != noMeteoVar) + QString name = currentDailyVar[i]; + auto searchDaily = MapDailyMeteoVar.find(name.toStdString()); + if (searchDaily != MapDailyMeteoVar.end()) { - QString varString = QString::fromStdString(MapHourlyMeteoVarToString.at(hourlyVar)); - if (!currentVariables.contains(varString)) + meteoVariable dailyVar = getMeteoVar(name.toStdString()); + meteoVariable hourlyVar= updateMeteoVariable(dailyVar, hourly); + if (hourlyVar != noMeteoVar) { - currentVariables.append(varString); + QString varString = QString::fromStdString(MapHourlyMeteoVarToString.at(hourlyVar)); + if (!currentVariables.contains(varString)) + { + currentVariables.append(varString); + } + } + } + } + } + else if (prevFreq == monthly) + { + QList currentMonthlyVar = currentVariables; + currentVariables.clear(); + for (int i = 0; i Date: Mon, 25 Mar 2024 12:50:12 +0100 Subject: [PATCH 55/72] monthly var in Crit3DPlotStyles.csv --- meteo/meteo.cpp | 9 ++++- meteoWidget/meteoWidget.cpp | 74 ++++++++++++++++++++++++------------- 2 files changed, 57 insertions(+), 26 deletions(-) diff --git a/meteo/meteo.cpp b/meteo/meteo.cpp index 98ea76ad..53c327c1 100644 --- a/meteo/meteo.cpp +++ b/meteo/meteo.cpp @@ -1047,7 +1047,14 @@ std::string getMeteoVarName(meteoVariable var) else { search = MapHourlyMeteoVarToString.find(var); - if (search != MapHourlyMeteoVarToString.end()) return search->second; + if (search != MapHourlyMeteoVarToString.end()) + return search->second; + else + { + search = MapMonthlyMeteoVarToString.find(var); + if (search != MapMonthlyMeteoVarToString.end()) + return search->second; + } } return ""; diff --git a/meteoWidget/meteoWidget.cpp b/meteoWidget/meteoWidget.cpp index a951730a..f4602839 100644 --- a/meteoWidget/meteoWidget.cpp +++ b/meteoWidget/meteoWidget.cpp @@ -1550,40 +1550,64 @@ void Crit3DMeteoWidget::showVar() void Crit3DMeteoWidget::showMonthlyGraph() { if (! isInitialized) return; - + frequencyType prevFreq = currentFreq; currentFreq = monthly; dailyButton->setEnabled(true); hourlyButton->setEnabled(true); monthlyButton->setEnabled(false); - // TO DO -/* - QList currentMonthlyVar = currentVariables; - currentVariables.clear(); - - for (int i = 0; i currentDailyVar = currentVariables; + currentVariables.clear(); + for (int i = 0; i < currentDailyVar.size(); i++) { - meteoVariable monthlyVar = MapMonthlyMeteoVar.at(name.toStdString()); - meteoVariable dailyVar = updateMeteoVariable(monthlyVar, daily); - if (dailyVar != noMeteoVar) + QString name = currentDailyVar[i]; + auto searchDaily = MapDailyMeteoVar.find(name.toStdString()); + if (searchDaily != MapDailyMeteoVar.end()) { - QString varString = QString::fromStdString(MapDailyMeteoVarToString.at(dailyVar)); - if (!currentVariables.contains(varString)) + meteoVariable dailyVar = getMeteoVar(name.toStdString()); + meteoVariable monthlyVar= updateMeteoVariable(dailyVar, monthly); + if (monthlyVar != noMeteoVar) { - currentVariables.append(varString); + QString varString = QString::fromStdString(getMeteoVarName(monthlyVar)); + if (!varString.isEmpty() && !currentVariables.contains(varString)) + { + currentVariables.append(varString); + } } } } } - + else if (prevFreq == hourly) + { + QList currentHourlyVar = currentVariables; + currentVariables.clear(); + for (int i = 0; i Date: Mon, 25 Mar 2024 15:13:39 +0100 Subject: [PATCH 56/72] fix showVar --- meteoWidget/meteoWidget.cpp | 305 +++++++++++++++++++++++++++++++++++- meteoWidget/meteoWidget.h | 1 + 2 files changed, 304 insertions(+), 2 deletions(-) diff --git a/meteoWidget/meteoWidget.cpp b/meteoWidget/meteoWidget.cpp index f4602839..7bd0e307 100644 --- a/meteoWidget/meteoWidget.cpp +++ b/meteoWidget/meteoWidget.cpp @@ -1489,6 +1489,296 @@ void Crit3DMeteoWidget::drawHourlyVar() } +void Crit3DMeteoWidget::drawMonthlyVar() +{ + if (! isInitialized) return; + + FormInfo formInfo; + formInfo.showInfo("Draw monthly data..."); + + firstDate->blockSignals(true); + lastDate->blockSignals(true); +/* + Crit3DDate myDate; + int nDays = 0; + double maxBar = -1; + double maxLine = NODATA; + double minLine = -NODATA; + + Crit3DDate firstCrit3DDate = getCrit3DDate(firstDate->date()); + Crit3DDate lastCrit3DDate = getCrit3DDate(lastDate->date()); + nDays = firstCrit3DDate.daysTo(lastCrit3DDate)+1; + + categories.clear(); + categoriesVirtual.clear(); + m_tooltip = new Callout(chart); + m_tooltip->hide(); + + // virtual x axis + int nrIntervals; + if (nDays <= 12) + { + nrIntervals = nDays; + } + else if (nDays <= 45) + { + nrIntervals = nDays/3; + } + else + { + nrIntervals = 12; + } + double step = double(nDays) / double(nrIntervals); + double nextIndex = step / 2 - 0.5; + for (int day = 0; day < nDays; day++) + { + myDate = firstCrit3DDate.addDays(day); + if (day == round(nextIndex)) + { + categoriesVirtual.append(getQDate(myDate).toString("MMM dd
yyyy")); + nextIndex += step; + } + } + + int nMeteoPoints = meteoPoints.size(); + for (int day = 0; day < nDays; day++) + { + myDate = firstCrit3DDate.addDays(day); + categories.append(QString::number(day)); + + for (int mp=0; mpappend(day, value); + if (value > maxLine) + { + maxLine = value; + } + if (value < minLine) + { + minLine = value; + } + } + else + { + if (meteoPoints[mp].isDateLoadedD(myDate)) + { + lineSeries[mp][i]->append(day, value); // nodata days are not drawed if they are the first of the last day of the serie + } + } + } + } + if (isBar) + { + for (int j = 0; j < nameBar.size(); j++) + { + meteoVariable meteoVar = getMeteoVar(nameBar[j].toStdString()); + if (meteoVar == noMeteoVar) + { + continue; + } + double value = meteoPoints[mp].getMeteoPointValueD(myDate, meteoVar, meteoSettings); + if (value != NODATA) + { + *setVector[mp][j] << value; + if (value > maxBar) + { + maxBar = value; + } + } + else + { + *setVector[mp][j] << 0; + } + } + } + } + } + + if (isBar) + { + for (int mp = 0; mp < nMeteoPoints; mp++) + { + QBarSeries* barMpSeries = new QBarSeries(); + for (int i = 0; i < nameBar.size(); i++) + { + barMpSeries->append(setVector[mp][i]); + } + barSeries.append(barMpSeries); + } + + for (int mp = 0; mp < nMeteoPoints; mp++) + { + connect(barSeries[mp], &QBarSeries::hovered, this, &Crit3DMeteoWidget::tooltipBar); + if (nameBar.size() != 0) + { + chart->addSeries(barSeries[mp]); + barSeries[mp]->attachAxis(axisX); + barSeries[mp]->attachAxis(axisYdx); + } + } + if (maxEnsembleBar == -1 && maxBar == -1) + { + axisYdx->setVisible(false); + } + else + { + axisYdx->setVisible(true); + if (maxEnsembleBar > maxBar) + { + axisYdx->setRange(0,maxEnsembleBar); + } + else + { + axisYdx->setRange(0,maxBar); + } + if (axisYdx->max() == axisYdx->min()) + { + axisYdx->setRange(0,1); + } + } + } + else + { + axisYdx->setVisible(false); + } + + if (isLine) + { + for (int mp=0; mpaddSeries(lineSeries[mp][i]); + lineSeries[mp][i]->attachAxis(axisX); + lineSeries[mp][i]->attachAxis(axisY); + connect(lineSeries[mp][i], &QLineSeries::hovered, this, &Crit3DMeteoWidget::tooltipLineSeries); + } + } + } + if (maxLine == NODATA && minLine == -NODATA && maxEnsembleLine == NODATA && minEnsembleLine == -NODATA) + { + axisY->setVisible(false); + } + else + { + axisY->setVisible(true); + if (maxEnsembleLine > maxLine) + { + axisY->setMax(maxEnsembleLine); + } + else + { + axisY->setMax(maxLine); + } + + if (minEnsembleLine < minLine) + { + axisY->setMin(minEnsembleLine); + } + else + { + axisY->setMin(minLine); + } + if (axisY->max() == axisY->min()) + { + axisY->setRange(axisY->min()-axisY->min()/100, axisY->max()+axisY->max()/100); + } + } + } + else + { + axisY->setVisible(false); + } + + // add minimimum values required + if (nDays==1) + { + categories.append(QString::number(1)); + categoriesVirtual.append(firstDate->date().addDays(1).toString("MMM dd
yyyy")); + for (int mp=0; mpappend(1, NODATA); + } + } + + if (isBar) + { + for (int j = 0; j < nameBar.size(); j++) + { + *setVector[mp][j] << 0; + } + } + } + } + + for (int mp=0; mpsetColor(QColor("transparent")); + } + else + { + QColor barColor = colorBar[j]; + if (meteoPointsEnsemble.size() == 0) + { + if (nMeteoPoints == 1) + { + barColor.setAlpha(255); + } + else + { + barColor.setAlpha( 255-(mp*(150/(nMeteoPoints-1))) ); + } + setVector[mp][j]->setColor(barColor); + } + else + { + setVector[mp][j]->setColor(Qt::transparent); + } + setVector[mp][j]->setBorderColor(barColor); + } + } + } + + axisX->setCategories(categories); + axisXvirtual->setCategories(categoriesVirtual); + axisXvirtual->setGridLineVisible(false); + + firstDate->blockSignals(false); + lastDate->blockSignals(false); + + foreach(QLegendMarker* marker, chart->legend()->markers()) + { + marker->setVisible(true); + marker->series()->setVisible(true); + QObject::connect(marker, &QLegendMarker::clicked, this, &Crit3DMeteoWidget::handleMarkerClicked); + } + + formInfo.close(); +*/ +} + void Crit3DMeteoWidget::showVar() { @@ -1523,14 +1813,14 @@ void Crit3DMeteoWidget::showVar() } else if (currentFreq == hourly) { - if (!allKeys[i].contains("DAILY") && !selectedVar.contains(allKeys[i])) + if (!allKeys[i].contains("DAILY") && !allKeys[i].contains("MONTHLY") && !selectedVar.contains(allKeys[i])) { allVar.append(allKeys[i]); } } else if (currentFreq == monthly) { - if (!allKeys[i].contains("MONTHLY") && !selectedVar.contains(allKeys[i])) + if (allKeys[i].contains("MONTHLY") && !selectedVar.contains(allKeys[i])) { allVar.append(allKeys[i]); } @@ -1814,6 +2104,17 @@ void Crit3DMeteoWidget::redraw() drawHourlyVar(); } } + else if (currentFreq == monthly) + { + if (isEnsemble || meteoPointsEnsemble.size() != 0) + { + // TO DO + } + if(!isEnsemble) + { + drawMonthlyVar(); + } + } } diff --git a/meteoWidget/meteoWidget.h b/meteoWidget/meteoWidget.h index ca258679..8a84e8e9 100644 --- a/meteoWidget/meteoWidget.h +++ b/meteoWidget/meteoWidget.h @@ -35,6 +35,7 @@ void drawDailyVar(); void drawEnsembleDailyVar(); void drawHourlyVar(); + void drawMonthlyVar(); void showMonthlyGraph(); void showDailyGraph(); void showHourlyGraph(); From 28cabe912a5b65658ca28cad6287f7719b751dd3 Mon Sep 17 00:00:00 2001 From: lauracosta Date: Tue, 26 Mar 2024 12:12:36 +0100 Subject: [PATCH 57/72] showMonthly TBC --- meteoWidget/meteoWidget.cpp | 50 ++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 28 deletions(-) diff --git a/meteoWidget/meteoWidget.cpp b/meteoWidget/meteoWidget.cpp index 7bd0e307..396e0a60 100644 --- a/meteoWidget/meteoWidget.cpp +++ b/meteoWidget/meteoWidget.cpp @@ -1498,16 +1498,13 @@ void Crit3DMeteoWidget::drawMonthlyVar() firstDate->blockSignals(true); lastDate->blockSignals(true); -/* + Crit3DDate myDate; - int nDays = 0; double maxBar = -1; double maxLine = NODATA; double minLine = -NODATA; - Crit3DDate firstCrit3DDate = getCrit3DDate(firstDate->date()); - Crit3DDate lastCrit3DDate = getCrit3DDate(lastDate->date()); - nDays = firstCrit3DDate.daysTo(lastCrit3DDate)+1; + int numberOfMonths = (lastDate->date().year()- firstDate->date().year())*12 + lastDate->date().month() - (firstDate->date().month()-1); categories.clear(); categoriesVirtual.clear(); @@ -1516,35 +1513,35 @@ void Crit3DMeteoWidget::drawMonthlyVar() // virtual x axis int nrIntervals; - if (nDays <= 12) + if (numberOfMonths <= 12) { - nrIntervals = nDays; + nrIntervals = numberOfMonths; } - else if (nDays <= 45) + else if (numberOfMonths <= 45) { - nrIntervals = nDays/3; + nrIntervals = numberOfMonths/3; } else { nrIntervals = 12; } - double step = double(nDays) / double(nrIntervals); + double step = double(numberOfMonths) / double(nrIntervals); double nextIndex = step / 2 - 0.5; - for (int day = 0; day < nDays; day++) + for (int month = 0; month < numberOfMonths; month++) { - myDate = firstCrit3DDate.addDays(day); - if (day == round(nextIndex)) + myDate = getCrit3DDate(firstDate->date().addMonths(month)); + if (month == round(nextIndex)) { - categoriesVirtual.append(getQDate(myDate).toString("MMM dd
yyyy")); + categoriesVirtual.append(getQDate(myDate).toString("MMM
yyyy")); nextIndex += step; } } int nMeteoPoints = meteoPoints.size(); - for (int day = 0; day < nDays; day++) + for (int month = 0; month < numberOfMonths; month++) { - myDate = firstCrit3DDate.addDays(day); - categories.append(QString::number(day)); + myDate = getCrit3DDate(firstDate->date().addMonths(month)); + categories.append(QString::number(month)); for (int mp=0; mpappend(day, value); + lineSeries[mp][i]->append(month, value); if (value > maxLine) { maxLine = value; @@ -1574,7 +1571,7 @@ void Crit3DMeteoWidget::drawMonthlyVar() { if (meteoPoints[mp].isDateLoadedD(myDate)) { - lineSeries[mp][i]->append(day, value); // nodata days are not drawed if they are the first of the last day of the serie + lineSeries[mp][i]->append(month, value); // nodata days are not drawed if they are the first of the last day of the serie } } } @@ -1588,7 +1585,7 @@ void Crit3DMeteoWidget::drawMonthlyVar() { continue; } - double value = meteoPoints[mp].getMeteoPointValueD(myDate, meteoVar, meteoSettings); + double value = meteoPoints[mp].getMeteoPointValueM(myDate, meteoVar); if (value != NODATA) { *setVector[mp][j] << value; @@ -1705,10 +1702,10 @@ void Crit3DMeteoWidget::drawMonthlyVar() } // add minimimum values required - if (nDays==1) + if (numberOfMonths==1) { categories.append(QString::number(1)); - categoriesVirtual.append(firstDate->date().addDays(1).toString("MMM dd
yyyy")); + categoriesVirtual.append(firstDate->date().addDays(1).toString("MMM
yyyy")); for (int mp=0; mpsetColor(QColor("transparent")); } @@ -1776,7 +1773,6 @@ void Crit3DMeteoWidget::drawMonthlyVar() } formInfo.close(); -*/ } @@ -1893,11 +1889,9 @@ void Crit3DMeteoWidget::showMonthlyGraph() } } } -/* + updateSeries(); redraw(); -*/ - } From 1b704a02b56be39aeee20dbe54800d81e3be6760 Mon Sep 17 00:00:00 2001 From: lauracosta Date: Tue, 26 Mar 2024 13:44:13 +0100 Subject: [PATCH 58/72] fix getLastMonthlyDate --- meteoWidget/dialogMeteoTable.cpp | 20 ++++++++++++++++++-- meteoWidget/meteoWidget.cpp | 32 ++++++++++++++++++++++++++++---- project/project.cpp | 2 +- 3 files changed, 47 insertions(+), 7 deletions(-) diff --git a/meteoWidget/dialogMeteoTable.cpp b/meteoWidget/dialogMeteoTable.cpp index a4ee7322..cfc30f94 100644 --- a/meteoWidget/dialogMeteoTable.cpp +++ b/meteoWidget/dialogMeteoTable.cpp @@ -46,12 +46,14 @@ DialogMeteoTable::DialogMeteoTable(Crit3DMeteoSettings *meteoSettings_, QVector< { rowNumber = (firstDate.daysTo(lastDate)+1)*24; // naVlues = nDays * 24 hours } + else if (currentFreq == monthly) + { + rowNumber = (lastDate.year()- firstDate.year())*12 + lastDate.month() - (firstDate.month()-1); + } meteoTable->setRowCount(rowNumber); meteoTable->setColumnCount(colNumber); - std::string nameField; - labels.clear(); meteoTableHeader.clear(); meteoTableHeader << "Date"; @@ -89,6 +91,11 @@ DialogMeteoTable::DialogMeteoTable(Crit3DMeteoSettings *meteoSettings_, QVector< myDateTime = firstDateTime.addSecs(row * 3600); meteoTable->setItem(row, col, new QTableWidgetItem(myDateTime.toString("yyyy-MM-dd hh:mm"))); } + else if (currentFreq == monthly) + { + myDate = firstDate.addMonths(row); + meteoTable->setItem(row, col, new QTableWidgetItem(myDate.toString("yyyy-MM"))); + } } else { @@ -120,6 +127,15 @@ DialogMeteoTable::DialogMeteoTable(Crit3DMeteoSettings *meteoSettings_, QVector< meteoTable->setItem(row, col, new QTableWidgetItem( QString::number(value))); } } + else if (currentFreq == monthly) + { + meteoVariable meteoVar = MapMonthlyMeteoVar.at(currentVariables[varPos].toStdString()); + double value = meteoPoints[mpPos].getMeteoPointValueM(getCrit3DDate(myDate), meteoVar); + if (value != NODATA) + { + meteoTable->setItem(row, col, new QTableWidgetItem( QString::number(value))); + } + } } } diff --git a/meteoWidget/meteoWidget.cpp b/meteoWidget/meteoWidget.cpp index 396e0a60..56fc66e5 100644 --- a/meteoWidget/meteoWidget.cpp +++ b/meteoWidget/meteoWidget.cpp @@ -1569,7 +1569,7 @@ void Crit3DMeteoWidget::drawMonthlyVar() } else { - if (meteoPoints[mp].isDateLoadedD(myDate)) + if (meteoPoints[mp].isDateLoadedM(myDate)) { lineSeries[mp][i]->append(month, value); // nodata days are not drawed if they are the first of the last day of the serie } @@ -2222,12 +2222,17 @@ bool Crit3DMeteoWidget::computeTooltipLineSeries(QLineSeries *series, QPointF po QDate xDate = firstDate->date().addDays(doy); m_tooltip->setText(QString("%1 \n%2 nan ").arg(series->name()).arg(xDate.toString("MMM dd yyyy"))); } - if (currentFreq == hourly) + else if (currentFreq == hourly) { QDateTime xDate(firstDate->date(), QTime(0,0,0), Qt::UTC); xDate = xDate.addSecs(3600*doy); m_tooltip->setText(QString("%1 \n%2 nan ").arg(series->name()).arg(xDate.toString("MMM dd yyyy hh:mm"))); } + else if (currentFreq == monthly) + { + QDate xDate = firstDate->date().addMonths(doy); + m_tooltip->setText(QString("%1 \n%2 nan ").arg(series->name()).arg(xDate.toString("MMM yyyy"))); + } m_tooltip->setSeries(series); m_tooltip->setAnchor(point); m_tooltip->setZValue(11); @@ -2357,7 +2362,7 @@ bool Crit3DMeteoWidget::computeTooltipLineSeries(QLineSeries *series, QPointF po double value = series->at(doyRelative).y(); m_tooltip->setText(QString("%1 \n%2 %3 ").arg(series->name()).arg(xDate.toString("MMM dd yyyy")).arg(value, 0, 'f', 1)); } - if (currentFreq == hourly) + else if (currentFreq == hourly) { QDateTime xDate(firstDate->date(), QTime(0,0,0), Qt::UTC); xDate = xDate.addSecs(3600*doy); @@ -2372,6 +2377,20 @@ bool Crit3DMeteoWidget::computeTooltipLineSeries(QLineSeries *series, QPointF po double value = series->at(doyRelative).y(); m_tooltip->setText(QString("%1 \n%2 %3 ").arg(series->name()).arg(xDate.toString("MMM dd yyyy hh:mm")).arg(value, 0, 'f', 1)); } + else if (currentFreq == monthly) + { + QDate xDate = firstDate->date().addMonths(doy); + for(int i = 0; i < series->count(); i++) + { + if (series->at(i).x() == doy) + { + doyRelative = i; + break; + } + } + double value = series->at(doyRelative).y(); + m_tooltip->setText(QString("%1 \n%2 %3 ").arg(series->name()).arg(xDate.toString("MMM yyyy")).arg(value, 0, 'f', 1)); + } m_tooltip->setSeries(series); m_tooltip->setAnchor(point); m_tooltip->setZValue(11); @@ -2424,13 +2443,18 @@ void Crit3DMeteoWidget::tooltipBar(bool state, int index, QBarSet *barset) QDate xDate = firstDate->date().addDays(index); valueStr = QString("%1 \n%2 %3 ").arg(xDate.toString("MMM dd yyyy")).arg(barset->label()).arg(barset->at(index), 0, 'f', 1); } - if (currentFreq == hourly) + else if (currentFreq == hourly) { QDateTime xDate(firstDate->date(), QTime(0,0,0), Qt::UTC); xDate = xDate.addSecs(3600*index); valueStr = QString("%1 \n%2 %3 ").arg(xDate.toString("MMM dd yyyy hh:mm")).arg(barset->label()).arg(barset->at(index), 0, 'f', 1); } + else if (currentFreq == monthly) + { + QDate xDate = firstDate->date().addMonths(index); + valueStr = QString("%1 \n%2 %3 ").arg(xDate.toString("MMM yyyy")).arg(barset->label()).arg(barset->at(index), 0, 'f', 1); + } m_tooltip->setSeries(series); m_tooltip->setText(valueStr); diff --git a/project/project.cpp b/project/project.cpp index 94a613cf..3ead3555 100644 --- a/project/project.cpp +++ b/project/project.cpp @@ -3307,7 +3307,7 @@ void Project::showMeteoWidgetGrid(std::string idCell, bool isAppend) QDate firstDate = meteoGridDbHandler->firstDate(); QDate lastDate = meteoGridDbHandler->lastDate(); QDate firstMonthlyDate = meteoGridDbHandler->getFirstMonthlytDate(); - QDate lastMonthlyDate = meteoGridDbHandler->getFirstMonthlytDate(); + QDate lastMonthlyDate = meteoGridDbHandler->getLastMonthlyDate(); QDateTime firstDateTime, lastDateTime; From 4471c2fb1238b9ce74678c1f78cfcc10e2e58147 Mon Sep 17 00:00:00 2001 From: lauracosta Date: Tue, 26 Mar 2024 15:42:27 +0100 Subject: [PATCH 59/72] add monthly case to shift prev or follow --- meteoWidget/meteoWidget.cpp | 49 ++++++++++++++++++++++++++++++++++++- meteoWidget/meteoWidget.h | 3 +++ project/project.cpp | 4 +++ 3 files changed, 55 insertions(+), 1 deletion(-) diff --git a/meteoWidget/meteoWidget.cpp b/meteoWidget/meteoWidget.cpp index 56fc66e5..6d3d279c 100644 --- a/meteoWidget/meteoWidget.cpp +++ b/meteoWidget/meteoWidget.cpp @@ -64,8 +64,10 @@ Crit3DMeteoWidget::Crit3DMeteoWidget(bool isGrid_, QString projectPath, Crit3DMe currentDate = noDate; firstDailyDate = noDate; firstHourlyDate = noDate; + firstMonthlyDate = noDate; lastDailyDate = noDate; lastHourlyDate = noDate; + lastMonthlyDate = noDate; isLine = false; isBar = false; @@ -421,6 +423,12 @@ void Crit3DMeteoWidget::setDateIntervalHourly(QDate firstDate, QDate lastDate) lastHourlyDate = lastDate; } +void Crit3DMeteoWidget::setDateIntervalMonthly(QDate firstDate, QDate lastDate) +{ + firstMonthlyDate = firstDate; + lastMonthlyDate = lastDate; +} + // search bigger data interval to show between meteoPoints void Crit3DMeteoWidget::updateTimeRange() @@ -462,6 +470,24 @@ void Crit3DMeteoWidget::updateTimeRange() { lastHourlyDate = myHourlyDateLast; } + + QDate myMonthlyDateFirst; + myMonthlyDateFirst.setDate(meteoPoints[i].obsDataM[0]._year, + meteoPoints[i].obsDataM[0]._month, + 1); + QDate myMonthlyDateLast = myMonthlyDateFirst.addMonths(meteoPoints[i].nrObsDataDaysM-1); + + // updates monthly range + if (myMonthlyDateFirst.isValid() && + (! firstMonthlyDate.isValid() || firstMonthlyDate.year() == 1800 || myMonthlyDateFirst < firstMonthlyDate)) + { + firstMonthlyDate = myMonthlyDateFirst; + } + if (myMonthlyDateLast.isValid() && + (! lastMonthlyDate.isValid() || lastMonthlyDate.year() == 1800 || myMonthlyDateLast > lastMonthlyDate)) + { + lastMonthlyDate = myMonthlyDateLast; + } } } @@ -2125,13 +2151,20 @@ void Crit3DMeteoWidget::shiftPrevious() firstValidDate = firstDailyDate; } - else + else if (currentFreq == hourly) { if (! firstHourlyDate.isValid() || firstHourlyDate.year() == 1800) return; firstValidDate = firstHourlyDate; } + else if (currentFreq == monthly) + { + if (! firstMonthlyDate.isValid() || firstMonthlyDate.year() == 1800) + return; + + firstValidDate = firstMonthlyDate; + } if (firstValidDate < firstDate->date().addDays(-nDays-1)) { @@ -2712,6 +2745,20 @@ void Crit3DMeteoWidget::on_actionDataAvailability() vbox->addWidget(hourlyTextEdit); } + if (!firstMonthlyDate.isNull() && firstMonthlyDate.year() != 1800) + { + QLabel* labelMonthly = new QLabel("Monthly Data:"); + vbox->addWidget(labelMonthly); + + QString monthlyInfo = QString("%1 - %2").arg(firstMonthlyDate.toString("yyyy/MM"), lastMonthlyDate.toString("yyyy/MM")); + QTextEdit* monthlyTextEdit = new QTextEdit(monthlyInfo); + + monthlyTextEdit->setMaximumHeight(QFontMetrics(monthlyTextEdit->font()).height() + 10); + monthlyTextEdit->setReadOnly(true); + + vbox->addWidget(monthlyTextEdit); + } + groupBox->setLayout(vbox); layout->addWidget(groupBox); } diff --git a/meteoWidget/meteoWidget.h b/meteoWidget/meteoWidget.h index 8a84e8e9..d587658c 100644 --- a/meteoWidget/meteoWidget.h +++ b/meteoWidget/meteoWidget.h @@ -23,6 +23,7 @@ void setCurrentDate(QDate myDate); void setDateIntervalDaily(QDate firstDate, QDate lastDate); void setDateIntervalHourly(QDate firstDate, QDate lastDate); + void setDateIntervalMonthly(QDate firstDate, QDate lastDate); void addMeteoPointsEnsemble(Crit3DMeteoPoint mp); @@ -78,6 +79,8 @@ QDate lastDailyDate; QDate firstHourlyDate; QDate lastHourlyDate; + QDate firstMonthlyDate; + QDate lastMonthlyDate; QDate currentDate; QPushButton *addVarButton; diff --git a/project/project.cpp b/project/project.cpp index 3ead3555..a2ec5829 100644 --- a/project/project.cpp +++ b/project/project.cpp @@ -3480,6 +3480,10 @@ void Project::showMeteoWidgetGrid(std::string idCell, bool isAppend) { meteoWidgetGrid->setDateIntervalHourly(firstDateTime.date(), lastDateTime.date()); } + if (meteoGridDbHandler->isMonthly()) + { + meteoWidgetGrid->setDateIntervalMonthly(firstMonthlyDate, lastMonthlyDate); + } meteoWidgetGrid->drawMeteoPoint(meteoGridDbHandler->meteoGrid()->meteoPoint(row,col), isAppend); } From f01a03011c525cb3727e442722382de3882117ab Mon Sep 17 00:00:00 2001 From: ftomei Date: Tue, 26 Mar 2024 18:27:56 +0100 Subject: [PATCH 60/72] update whc --- criteria1DWidget/criteria1DWidget.cpp | 3 +- criteriaModel/criteria1DProject.cpp | 79 ++++++++++++++++++--------- 2 files changed, 56 insertions(+), 26 deletions(-) diff --git a/criteria1DWidget/criteria1DWidget.cpp b/criteria1DWidget/criteria1DWidget.cpp index 5ff30fb6..b27dc0c2 100644 --- a/criteria1DWidget/criteria1DWidget.cpp +++ b/criteria1DWidget/criteria1DWidget.cpp @@ -36,6 +36,7 @@ #include "criteria1DMeteo.h" #include "utilities.h" #include "basicMath.h" +#include "root.h" #include #include @@ -1026,7 +1027,7 @@ void Criteria1DWidget::on_actionExecuteCase() return; } - if (!myProject.computeUnit(myProject.myCase.unit)) + if (! myProject.computeUnit(myProject.myCase.unit)) { QMessageBox::critical(nullptr, "Error!", myProject.projectError); } diff --git a/criteriaModel/criteria1DProject.cpp b/criteriaModel/criteria1DProject.cpp index a858122c..8692406e 100644 --- a/criteriaModel/criteria1DProject.cpp +++ b/criteriaModel/criteria1DProject.cpp @@ -113,9 +113,13 @@ bool Crit1DProject::readSettings() dbMeteoName = projectSettings->value("db_meteo","").toString(); if (dbMeteoName.left(1) == ".") - dbMeteoName = path + dbMeteoName; - if (dbMeteoName.right(3) == "xml") + { + dbMeteoName = QDir::cleanPath(path + dbMeteoName); + } + if (dbMeteoName.right(3).toUpper() == "XML") + { isXmlMeteoGrid = true; + } dbForecastName = projectSettings->value("db_forecast","").toString(); if (dbForecastName.left(1) == ".") @@ -146,6 +150,10 @@ bool Crit1DProject::readSettings() { firstSimulationDate = projectSettings->value("firstDate",0).toDate(); if (! firstSimulationDate.isValid()) + { + firstSimulationDate = projectSettings->value("first_date",0).toDate(); + } + if (! firstSimulationDate.isValid()) { firstSimulationDate = QDate(1800,1,1); } @@ -155,6 +163,10 @@ bool Crit1DProject::readSettings() { lastSimulationDate = projectSettings->value("lastDate",0).toDate(); if (! lastSimulationDate.isValid()) + { + lastSimulationDate = projectSettings->value("last_date",0).toDate(); + } + if (! lastSimulationDate.isValid()) { lastSimulationDate = QDate(1800,1,1); } @@ -358,7 +370,7 @@ int Crit1DProject::initializeProject(QString settingsFileName) return ERROR_SETTINGS_WRONGFILENAME; } - if (!readSettings()) + if (! readSettings()) return ERROR_SETTINGS_MISSINGDATA; logger.setLog(path, projectName, addDateTimeLogFile); @@ -468,18 +480,30 @@ bool Crit1DProject::setSoil(QString soilCode, QString &errorStr) bool Crit1DProject::setMeteoXmlGrid(QString idMeteo, QString idForecast, unsigned int memberNr) { - unsigned row, col; + // check date + QDate NODATE = QDate(1800, 1, 1); + if (! firstSimulationDate.isValid() || firstSimulationDate == NODATE ) + { + projectError = "Missing first simulation date."; + return false; + } + if (! lastSimulationDate.isValid() || lastSimulationDate == NODATE ) + { + projectError = "Missing last simulation date."; + return false; + } unsigned nrDays = unsigned(firstSimulationDate.daysTo(lastSimulationDate)) + 1; - if (!observedMeteoGrid->meteoGrid()->findMeteoPointFromId(&row, &col, idMeteo.toStdString()) ) + unsigned row, col; + if (! observedMeteoGrid->meteoGrid()->findMeteoPointFromId(&row, &col, idMeteo.toStdString()) ) { projectError = "Missing observed meteo cell: " + idMeteo; return false; } - if (!observedMeteoGrid->gridStructure().isFixedFields()) + if (! observedMeteoGrid->gridStructure().isFixedFields()) { - if (!observedMeteoGrid->loadGridDailyData(projectError, idMeteo, firstSimulationDate, lastSimulationDate)) + if (! observedMeteoGrid->loadGridDailyData(projectError, idMeteo, firstSimulationDate, lastSimulationDate)) { projectError = "Missing observed data: " + idMeteo; return false; @@ -487,7 +511,7 @@ bool Crit1DProject::setMeteoXmlGrid(QString idMeteo, QString idForecast, unsigne } else { - if (!observedMeteoGrid->loadGridDailyDataFixedFields(projectError, idMeteo, firstSimulationDate, lastSimulationDate)) + if (! observedMeteoGrid->loadGridDailyDataFixedFields(projectError, idMeteo, firstSimulationDate, lastSimulationDate)) { if (projectError == "Missing MeteoPoint id") { @@ -501,11 +525,12 @@ bool Crit1DProject::setMeteoXmlGrid(QString idMeteo, QString idForecast, unsigne } } - if (this->isShortTermForecast) + if (isShortTermForecast) { - if (!this->forecastMeteoGrid->gridStructure().isFixedFields()) + if (! forecastMeteoGrid->gridStructure().isFixedFields()) { - if (!this->forecastMeteoGrid->loadGridDailyData(projectError, idForecast, lastSimulationDate.addDays(1), lastSimulationDate.addDays(daysOfForecast))) + if (! forecastMeteoGrid->loadGridDailyData(projectError, idForecast, lastSimulationDate.addDays(1), + lastSimulationDate.addDays(daysOfForecast))) { if (projectError == "Missing MeteoPoint id") { @@ -520,7 +545,8 @@ bool Crit1DProject::setMeteoXmlGrid(QString idMeteo, QString idForecast, unsigne } else { - if (!this->forecastMeteoGrid->loadGridDailyDataFixedFields(projectError, idForecast, lastSimulationDate.addDays(1), lastSimulationDate.addDays(daysOfForecast))) + if (! forecastMeteoGrid->loadGridDailyDataFixedFields(projectError, idForecast, + lastSimulationDate.addDays(1), lastSimulationDate.addDays(daysOfForecast))) { if (projectError == "Missing MeteoPoint id") { @@ -536,16 +562,17 @@ bool Crit1DProject::setMeteoXmlGrid(QString idMeteo, QString idForecast, unsigne nrDays += unsigned(daysOfForecast); } - if (this->isEnsembleForecast) + if (isEnsembleForecast) { - if (this->forecastMeteoGrid->gridStructure().isFixedFields()) + if (forecastMeteoGrid->gridStructure().isFixedFields()) { projectError = "DB grid fixed fields: not available"; return false; } else { - if (!this->forecastMeteoGrid->loadGridDailyDataEnsemble(projectError, idForecast, int(memberNr), lastSimulationDate.addDays(1), lastSimulationDate.addDays(daysOfForecast))) + if (! forecastMeteoGrid->loadGridDailyDataEnsemble(projectError, idForecast, int(memberNr), + lastSimulationDate.addDays(1), lastSimulationDate.addDays(daysOfForecast))) { if (projectError == "Missing MeteoPoint id") { @@ -561,8 +588,8 @@ bool Crit1DProject::setMeteoXmlGrid(QString idMeteo, QString idForecast, unsigne nrDays += unsigned(daysOfForecast); } - myCase.meteoPoint.latitude = this->observedMeteoGrid->meteoGrid()->meteoPointPointer(row, col)->latitude; - myCase.meteoPoint.longitude = this->observedMeteoGrid->meteoGrid()->meteoPointPointer(row, col)->longitude; + myCase.meteoPoint.latitude = observedMeteoGrid->meteoGrid()->meteoPointPointer(row, col)->latitude; + myCase.meteoPoint.longitude = observedMeteoGrid->meteoGrid()->meteoPointPointer(row, col)->longitude; myCase.meteoPoint.initializeObsDataD(nrDays, getCrit3DDate(firstSimulationDate)); float tmin, tmax, tavg, prec; @@ -570,22 +597,23 @@ bool Crit1DProject::setMeteoXmlGrid(QString idMeteo, QString idForecast, unsigne for (int i = 0; i < lastIndex; i++) { Crit3DDate myDate = getCrit3DDate(firstSimulationDate.addDays(i)); - tmin = this->observedMeteoGrid->meteoGrid()->meteoPointPointer(row, col)->getMeteoPointValueD(myDate, dailyAirTemperatureMin); + tmin = observedMeteoGrid->meteoGrid()->meteoPointPointer(row, col)->getMeteoPointValueD(myDate, dailyAirTemperatureMin); myCase.meteoPoint.setMeteoPointValueD(myDate, dailyAirTemperatureMin, tmin); - tmax = this->observedMeteoGrid->meteoGrid()->meteoPointPointer(row, col)->getMeteoPointValueD(myDate, dailyAirTemperatureMax); + tmax = observedMeteoGrid->meteoGrid()->meteoPointPointer(row, col)->getMeteoPointValueD(myDate, dailyAirTemperatureMax); myCase.meteoPoint.setMeteoPointValueD(myDate, dailyAirTemperatureMax, tmax); - tavg = this->observedMeteoGrid->meteoGrid()->meteoPointPointer(row, col)->getMeteoPointValueD(myDate, dailyAirTemperatureAvg); + tavg = observedMeteoGrid->meteoGrid()->meteoPointPointer(row, col)->getMeteoPointValueD(myDate, dailyAirTemperatureAvg); if (int(tavg) == int(NODATA)) { tavg = (tmax + tmin)/2; } myCase.meteoPoint.setMeteoPointValueD(myDate, dailyAirTemperatureAvg, tavg); - prec = this->observedMeteoGrid->meteoGrid()->meteoPointPointer(row, col)->getMeteoPointValueD(myDate, dailyPrecipitation); + prec = observedMeteoGrid->meteoGrid()->meteoPointPointer(row, col)->getMeteoPointValueD(myDate, dailyPrecipitation); myCase.meteoPoint.setMeteoPointValueD(myDate, dailyPrecipitation, prec); } + if (isShortTermForecast || isEnsembleForecast) { QDate start = lastSimulationDate.addDays(1); @@ -593,23 +621,24 @@ bool Crit1DProject::setMeteoXmlGrid(QString idMeteo, QString idForecast, unsigne for (int i = 0; i< start.daysTo(end)+1; i++) { Crit3DDate myDate = getCrit3DDate(start.addDays(i)); - tmin = this->forecastMeteoGrid->meteoGrid()->meteoPointPointer(row, col)->getMeteoPointValueD(myDate, dailyAirTemperatureMin); + tmin = forecastMeteoGrid->meteoGrid()->meteoPointPointer(row, col)->getMeteoPointValueD(myDate, dailyAirTemperatureMin); myCase.meteoPoint.setMeteoPointValueD(myDate, dailyAirTemperatureMin, tmin); - tmax = this->forecastMeteoGrid->meteoGrid()->meteoPointPointer(row, col)->getMeteoPointValueD(myDate, dailyAirTemperatureMax); + tmax = forecastMeteoGrid->meteoGrid()->meteoPointPointer(row, col)->getMeteoPointValueD(myDate, dailyAirTemperatureMax); myCase.meteoPoint.setMeteoPointValueD(myDate, dailyAirTemperatureMax, tmax); - tavg = this->forecastMeteoGrid->meteoGrid()->meteoPointPointer(row, col)->getMeteoPointValueD(myDate, dailyAirTemperatureAvg); + tavg = forecastMeteoGrid->meteoGrid()->meteoPointPointer(row, col)->getMeteoPointValueD(myDate, dailyAirTemperatureAvg); if (int(tavg) == int(NODATA)) { tavg = (tmax + tmin)/2; } myCase.meteoPoint.setMeteoPointValueD(myDate, dailyAirTemperatureAvg, tavg); - prec = this->forecastMeteoGrid->meteoGrid()->meteoPointPointer(row, col)->getMeteoPointValueD(myDate, dailyPrecipitation); + prec = forecastMeteoGrid->meteoGrid()->meteoPointPointer(row, col)->getMeteoPointValueD(myDate, dailyPrecipitation); myCase.meteoPoint.setMeteoPointValueD(myDate, dailyPrecipitation, prec); } } + return true; } From 3e4a14c51800c56e6d5a12222c4042c83ba804c9 Mon Sep 17 00:00:00 2001 From: lauracosta Date: Wed, 27 Mar 2024 11:56:10 +0100 Subject: [PATCH 61/72] check obsDataM size --- meteoWidget/meteoWidget.cpp | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/meteoWidget/meteoWidget.cpp b/meteoWidget/meteoWidget.cpp index 6d3d279c..4a11ae96 100644 --- a/meteoWidget/meteoWidget.cpp +++ b/meteoWidget/meteoWidget.cpp @@ -436,11 +436,14 @@ void Crit3DMeteoWidget::updateTimeRange() for (int i = 0; i < meteoPoints.size(); i++) { QDate myDailyDateFirst; - myDailyDateFirst.setDate(meteoPoints[i].obsDataD[0].date.year, - meteoPoints[i].obsDataD[0].date.month, - meteoPoints[i].obsDataD[0].date.day); - QDate myDailyDateLast = myDailyDateFirst.addDays(meteoPoints[i].nrObsDataDaysD-1); - + QDate myDailyDateLast; + if (meteoPoints[i].obsDataD.size() != 0) + { + myDailyDateFirst.setDate(meteoPoints[i].obsDataD[0].date.year, + meteoPoints[i].obsDataD[0].date.month, + meteoPoints[i].obsDataD[0].date.day); + myDailyDateLast = myDailyDateFirst.addDays(meteoPoints[i].nrObsDataDaysD-1); + } // updates daily range if (myDailyDateFirst.isValid() && (! firstDailyDate.isValid() || firstDailyDate.year() == 1800 || myDailyDateFirst < firstDailyDate)) @@ -455,10 +458,9 @@ void Crit3DMeteoWidget::updateTimeRange() QDate myHourlyDateFirst; myHourlyDateFirst.setDate(meteoPoints[i].getMeteoPointHourlyValuesDate(0).year, - meteoPoints[i].getMeteoPointHourlyValuesDate(0).month, - meteoPoints[i].getMeteoPointHourlyValuesDate(0).day); + meteoPoints[i].getMeteoPointHourlyValuesDate(0).month, + meteoPoints[i].getMeteoPointHourlyValuesDate(0).day); QDate myHourlyDateLast = myHourlyDateFirst.addDays(meteoPoints[i].nrObsDataDaysH-1); - // updates hourly range if (myHourlyDateFirst.isValid() && (! firstHourlyDate.isValid() || firstHourlyDate.year() == 1800 || myHourlyDateFirst < firstHourlyDate)) @@ -472,11 +474,14 @@ void Crit3DMeteoWidget::updateTimeRange() } QDate myMonthlyDateFirst; - myMonthlyDateFirst.setDate(meteoPoints[i].obsDataM[0]._year, - meteoPoints[i].obsDataM[0]._month, - 1); - QDate myMonthlyDateLast = myMonthlyDateFirst.addMonths(meteoPoints[i].nrObsDataDaysM-1); - + QDate myMonthlyDateLast; + if (meteoPoints[i].obsDataM.size() != 0) + { + myMonthlyDateFirst.setDate(meteoPoints[i].obsDataM[0]._year, + meteoPoints[i].obsDataM[0]._month, + 1); + myMonthlyDateLast = myMonthlyDateFirst.addMonths(meteoPoints[i].nrObsDataDaysM-1); + } // updates monthly range if (myMonthlyDateFirst.isValid() && (! firstMonthlyDate.isValid() || firstMonthlyDate.year() == 1800 || myMonthlyDateFirst < firstMonthlyDate)) From 5f329679bbdc1ce173bb068debf236b4a3c11b56 Mon Sep 17 00:00:00 2001 From: ftomei Date: Wed, 27 Mar 2024 15:44:17 +0100 Subject: [PATCH 62/72] update --- gdalHandler/gdalRasterFunctions.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/gdalHandler/gdalRasterFunctions.cpp b/gdalHandler/gdalRasterFunctions.cpp index 79fb6a07..13a03faa 100644 --- a/gdalHandler/gdalRasterFunctions.cpp +++ b/gdalHandler/gdalRasterFunctions.cpp @@ -55,8 +55,7 @@ bool convertGdalRaster(GDALDataset* dataset, gis::Crit3DRasterGrid* myRaster, in // projection OGRSpatialReference* spatialReference; - QString prjString = QString::fromStdString(dataset->GetProjectionRef()); - if (prjString != "") + if (dataset->GetProjectionRef() != "") { qDebug() << "Projection =" << dataset->GetProjectionRef(); spatialReference = new OGRSpatialReference(dataset->GetProjectionRef()); @@ -72,7 +71,7 @@ bool convertGdalRaster(GDALDataset* dataset, gis::Crit3DRasterGrid* myRaster, in // UTM zone utmZone = spatialReference->GetUTMZone(); - qDebug() << "UTM zone =" << spatialReference->GetUTMZone(); + qDebug() << "UTM zone = " << spatialReference->GetUTMZone(); } else { @@ -133,8 +132,10 @@ bool convertGdalRaster(GDALDataset* dataset, gis::Crit3DRasterGrid* myRaster, in qDebug() << "Nodata =" << QString::number(nodataValue); // initialize raster - myRaster->header->nrCols = dataset->GetRasterXSize(); - myRaster->header->nrRows = dataset->GetRasterYSize(); + int xSize = dataset->GetRasterXSize(); + int ySize = dataset->GetRasterYSize(); + myRaster->header->nrCols = xSize; + myRaster->header->nrRows = ySize; myRaster->header->cellSize = adfGeoTransform[1]; myRaster->header->llCorner.x = adfGeoTransform[0]; myRaster->header->llCorner.y = adfGeoTransform[3] - myRaster->header->cellSize * myRaster->header->nrRows; @@ -147,8 +148,6 @@ bool convertGdalRaster(GDALDataset* dataset, gis::Crit3DRasterGrid* myRaster, in } // read data - int xSize = band->GetXSize(); - int ySize = band->GetYSize(); float* data = (float *) CPLMalloc(sizeof(float) * xSize * ySize); CPLErr errGdal = band->RasterIO(GF_Read, 0, 0, xSize, ySize, data, xSize, ySize, GDT_Float32, 0, 0); From eaadeb8cecbb05dd0f9399f0f93e63ecfb56cd3b Mon Sep 17 00:00:00 2001 From: ftomei Date: Wed, 27 Mar 2024 16:13:30 +0100 Subject: [PATCH 63/72] update --- shapeUtilities/shapeToRaster.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/shapeUtilities/shapeToRaster.cpp b/shapeUtilities/shapeToRaster.cpp index a6f6c3d2..c657b70d 100644 --- a/shapeUtilities/shapeToRaster.cpp +++ b/shapeUtilities/shapeToRaster.cpp @@ -35,13 +35,13 @@ bool initializeRasterFromShape(Crit3DShapeHandler &shape, gis::Crit3DRasterGrid xmax = MAXVALUE(xmax, bounds.xmax); } - xmin = floor(xmin); - ymin = floor(ymin); + xmin = round(xmin * 10.) * 0.1; + ymin = round(ymin * 10.) * 0.1; header.cellSize = cellSize; header.llCorner.x = xmin; header.llCorner.y = ymin; - header.nrRows = int(floor((ymax - ymin) / cellSize))+1; - header.nrCols = int(floor((xmax - xmin) / cellSize))+1; + header.nrRows = int(floor((ymax - ymin) / cellSize)) + 1; + header.nrCols = int(floor((xmax - xmin) / cellSize)) + 1; header.flag = NODATA; return raster.initializeGrid(header); From 811e7a53a5f9c750e14f6ab94f602ca94f84ca76 Mon Sep 17 00:00:00 2001 From: ftomei Date: Wed, 27 Mar 2024 16:43:04 +0100 Subject: [PATCH 64/72] fix UTM raster --- graphics/mapGraphicsRasterUtm.cpp | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/graphics/mapGraphicsRasterUtm.cpp b/graphics/mapGraphicsRasterUtm.cpp index 73d23b47..95f487b9 100644 --- a/graphics/mapGraphicsRasterUtm.cpp +++ b/graphics/mapGraphicsRasterUtm.cpp @@ -87,10 +87,12 @@ bool RasterUtmObject::initialize(gis::Crit3DRasterGrid* rasterPtr, const gis::Cr gis::getGeoExtentsFromUTMHeader(gisSettings, _rasterPointer->header, &_latLonHeader); gis::Crit3DRasterHeader utmHeader = *_rasterPointer->header; - // lat/lon raster have one extra cell + + // latlon raster have one extra cell gis::Crit3DRasterHeader extHeader = utmHeader; extHeader.nrCols++; extHeader.nrRows++; + _latRaster.initializeGrid(extHeader); _lonRaster.initializeGrid(extHeader); @@ -100,17 +102,13 @@ bool RasterUtmObject::initialize(gis::Crit3DRasterGrid* rasterPtr, const gis::Cr for (int col = 0; col < extHeader.nrCols; col++) { gis::getUtmXYFromRowCol(utmHeader, row, col, &x, &y); - // move to top left of the cell, except the last row/column (bottom right) - if (row < extHeader.nrRows -1) - y += utmHeader.cellSize * 0.5; - else - y -= utmHeader.cellSize * 0.5; - if (col < extHeader.nrCols -1) - x -= utmHeader.cellSize * 0.5; - else - x += utmHeader.cellSize * 0.5; + + // move to top left of the cell + y += utmHeader.cellSize * 0.5; + x -= utmHeader.cellSize * 0.5; gis::getLatLonFromUtm(gisSettings, x, y, &lat, &lon); + _latRaster.value[row][col] = lat; _lonRaster.value[row][col] = lon; } @@ -347,11 +345,19 @@ bool RasterUtmObject::drawRaster(QPainter* painter) { int row2 = std::min(row1 + step, _rasterPointer->header->nrRows-1); int rowCenter = floor((row1 + row2) * 0.5); + if (row2 == row1) + { + row2++; + } for (int col1 = rasterWindow.v[0].col; col1 <= rasterWindow.v[1].col; col1 += step) { int col2 = std::min(col1 + step, _rasterPointer->header->nrCols-1); int colCenter = floor((col1 + col2) * 0.5); + if (col2 == col1) + { + col2++; + } // raster value float value = _rasterPointer->value[rowCenter][colCenter]; From 8cf9a13663b328eaf781a3399f1fff608828e8b5 Mon Sep 17 00:00:00 2001 From: Gabriele Antolini Date: Wed, 27 Mar 2024 16:59:55 +0100 Subject: [PATCH 65/72] removed error checks --- interpolation/interpolation.cpp | 15 ++++----------- project/project.cpp | 2 +- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/interpolation/interpolation.cpp b/interpolation/interpolation.cpp index 044ce502..6f0c2a54 100644 --- a/interpolation/interpolation.cpp +++ b/interpolation/interpolation.cpp @@ -1443,11 +1443,7 @@ bool multipleDetrending(std::vector &myPoints, } } - if (validNr == 0) - { - errorStr = "No proxy"; - return false; - } + if (validNr == 0) return false; // exclude points with incomplete proxies unsigned i; @@ -1545,8 +1541,8 @@ bool multipleDetrending(std::vector &myPoints, } // multiple non linear fitting - interpolation::bestFittingMarquardt_nDimension(&functionSum, myFunc, 1000, 5, parametersMin, parametersMax, parameters, parametersDelta, - 100, 0.005, 0.01, predictors, predictands, weights); + interpolation::bestFittingMarquardt_nDimension(&functionSum, myFunc, 500, 3, parametersMin, parametersMax, parameters, parametersDelta, + 50, 0.005, 0.05, predictors, predictands, weights); mySettings->setFittingFunction(myFunc); mySettings->setFittingParameters(parameters); @@ -1683,10 +1679,7 @@ bool preInterpolation(std::vector &myPoints, Crit if (mySettings->getUseMultipleDetrending()) { mySettings->setCurrentCombination(mySettings->getSelectedCombination()); - if (! multipleDetrending(myPoints, mySettings, myVar, errorStr)) - { - return false; - } + multipleDetrending(myPoints, mySettings, myVar, errorStr); } else { diff --git a/project/project.cpp b/project/project.cpp index a2ec5829..fd9f5f0b 100644 --- a/project/project.cpp +++ b/project/project.cpp @@ -684,7 +684,7 @@ bool Project::loadParameters(QString parametersFileName) unsigned int nrParameters; if (getProxyPragaName(name_.toStdString()) == proxyHeight) - nrParameters = 5; + nrParameters = 4; else nrParameters = 1; From 92fcaab7893ba8b1944546760b58b3654aec7230 Mon Sep 17 00:00:00 2001 From: ftomei Date: Wed, 27 Mar 2024 17:24:27 +0100 Subject: [PATCH 66/72] update --- gis/gis.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/gis/gis.cpp b/gis/gis.cpp index b229f805..9748648c 100644 --- a/gis/gis.cpp +++ b/gis/gis.cpp @@ -713,7 +713,6 @@ namespace gis */ void latLonToUtm(double lat, double lon, double *utmEasting, double *utmNorthing, int *zoneNumber) { - static double ellipsoidK0 = 0.9996; double eccSquared, lonOrigin, eccPrimeSquared, ae, a, n; double t, c,m,lonTemp, latRad,lonRad,lonOriginRad; @@ -774,17 +773,18 @@ namespace gis if (lat < 0) (*utmNorthing) += 10000000.; } + void getUtmFromLatLon(int zoneNumber, const Crit3DGeoPoint& geoPoint, Crit3DUtmPoint* utmPoint) { latLonToUtmForceZone(zoneNumber, geoPoint.latitude, geoPoint.longitude, &(utmPoint->x), &(utmPoint->y)); } + + /*! + \brief equivalent to latLonToUtm forcing UTM zone. + */ void latLonToUtmForceZone(int zoneNumber, double lat, double lon, double *utmEasting, double *utmNorthing) { - - /*! - equivalent to LatLonToUTM forcing UTM zone. - */ double eccSquared, lonOrigin, eccPrimeSquared, ae, a, n , t, c,m,lonTemp, latRad,lonRad,lonOriginRad; static double ellipsoidK0 = 0.9996; From 5050b8687d0eb45ba1a24c569375a44259b02d69 Mon Sep 17 00:00:00 2001 From: lauracosta Date: Thu, 28 Mar 2024 11:21:45 +0100 Subject: [PATCH 67/72] add checkable menu --- meteoWidget/dialogVariableToSum.cpp | 8 ++++++-- meteoWidget/dialogVariableToSum.h | 3 ++- meteoWidget/meteoWidget.cpp | 15 ++++++++++++--- meteoWidget/meteoWidget.h | 2 ++ 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/meteoWidget/dialogVariableToSum.cpp b/meteoWidget/dialogVariableToSum.cpp index 78e09dee..107fddc2 100644 --- a/meteoWidget/dialogVariableToSum.cpp +++ b/meteoWidget/dialogVariableToSum.cpp @@ -1,7 +1,7 @@ #include "dialogVariableToSum.h" -DialogVariableToSum::DialogVariableToSum(QList variableList) -: variableList(variableList) +DialogVariableToSum::DialogVariableToSum(QList variableList, QList varAlreadyChecked) +: variableList(variableList), varAlreadyChecked(varAlreadyChecked) { setWindowTitle("Choose variable to sum"); this->resize(400, 200); @@ -15,6 +15,10 @@ DialogVariableToSum::DialogVariableToSum(QList variableList) { QCheckBox* checkbox = new QCheckBox(variableList[i], this); checkList.append(checkbox); + if (varAlreadyChecked.contains(checkbox->text())) + { + checkbox->setChecked(true); + } variableLayout->addWidget(checkbox); } diff --git a/meteoWidget/dialogVariableToSum.h b/meteoWidget/dialogVariableToSum.h index fc230045..2e8c5dbd 100644 --- a/meteoWidget/dialogVariableToSum.h +++ b/meteoWidget/dialogVariableToSum.h @@ -10,10 +10,11 @@ class DialogVariableToSum : public QDialog private: QList variableList; QList selectedVariable; + QList varAlreadyChecked; QList checkList; public: - DialogVariableToSum(QList variableList); + DialogVariableToSum(QList variableList, QList varAlreadyChecked); QList getSelectedVariable(); void done(bool res); }; diff --git a/meteoWidget/meteoWidget.cpp b/meteoWidget/meteoWidget.cpp index 4a11ae96..7a13cbf5 100644 --- a/meteoWidget/meteoWidget.cpp +++ b/meteoWidget/meteoWidget.cpp @@ -369,7 +369,8 @@ Crit3DMeteoWidget::Crit3DMeteoWidget(bool isGrid_, QString projectPath, Crit3DMe QAction* infoPoint = new QAction(tr("&Info meteo point"), this); QAction* dataAvailability = new QAction(tr("&Data availability"), this); - QAction* dataSum = new QAction(tr("&Sum"), this); + dataSum = new QAction(tr("&Sum"), this); + dataSum->setCheckable(true); viewMenu->addAction(infoPoint); viewMenu->addAction(dataAvailability); @@ -2819,20 +2820,28 @@ void Crit3DMeteoWidget::on_actionDataAvailability() void Crit3DMeteoWidget::on_actionDataSum() { - DialogVariableToSum varToSum(currentVariables); - QList varToSumList; + DialogVariableToSum varToSum(currentVariables, varToSumList); if (varToSum.result() == QDialog::Accepted) { varToSumList = varToSum.getSelectedVariable(); } else { + if (varToSumList.isEmpty()) + { + dataSum->setChecked(false); + } return; } if (!varToSumList.isEmpty()) { + dataSum->setChecked(true); drawSum(varToSumList); } + else + { + dataSum->setChecked(false); + } } void Crit3DMeteoWidget::drawSum(QList varToSumList) diff --git a/meteoWidget/meteoWidget.h b/meteoWidget/meteoWidget.h index d587658c..c73f5300 100644 --- a/meteoWidget/meteoWidget.h +++ b/meteoWidget/meteoWidget.h @@ -83,6 +83,7 @@ QDate lastMonthlyDate; QDate currentDate; + QAction* dataSum; QPushButton *addVarButton; QPushButton *dailyButton; QPushButton *hourlyButton; @@ -116,6 +117,7 @@ QVector> setVector; QList categories; QList categoriesVirtual; + QList varToSumList; bool isLine; bool isBar; From a6a182a681cb400635f6971243100921a565c9f7 Mon Sep 17 00:00:00 2001 From: lauracosta Date: Thu, 28 Mar 2024 11:39:49 +0100 Subject: [PATCH 68/72] save var to sum --- meteoWidget/meteoWidget.cpp | 16 ++++++++++++++-- meteoWidget/meteoWidget.h | 2 +- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/meteoWidget/meteoWidget.cpp b/meteoWidget/meteoWidget.cpp index 7a13cbf5..ca24f0bf 100644 --- a/meteoWidget/meteoWidget.cpp +++ b/meteoWidget/meteoWidget.cpp @@ -2117,6 +2117,10 @@ void Crit3DMeteoWidget::redraw() if(! isEnsemble) { drawDailyVar(); + if (varToSumList.size() != 0) + { + drawSum(); + } } } else if (currentFreq == hourly) @@ -2128,6 +2132,10 @@ void Crit3DMeteoWidget::redraw() if(!isEnsemble) { drawHourlyVar(); + if (varToSumList.size() != 0) + { + drawSum(); + } } } else if (currentFreq == monthly) @@ -2139,6 +2147,10 @@ void Crit3DMeteoWidget::redraw() if(!isEnsemble) { drawMonthlyVar(); + if (varToSumList.size() != 0) + { + drawSum(); + } } } @@ -2836,7 +2848,7 @@ void Crit3DMeteoWidget::on_actionDataSum() if (!varToSumList.isEmpty()) { dataSum->setChecked(true); - drawSum(varToSumList); + drawSum(); } else { @@ -2844,7 +2856,7 @@ void Crit3DMeteoWidget::on_actionDataSum() } } -void Crit3DMeteoWidget::drawSum(QList varToSumList) +void Crit3DMeteoWidget::drawSum() { int nMeteoPoints = meteoPoints.size(); for (int i = 0; i < varToSumList.size(); i++) diff --git a/meteoWidget/meteoWidget.h b/meteoWidget/meteoWidget.h index c73f5300..f52d9e0d 100644 --- a/meteoWidget/meteoWidget.h +++ b/meteoWidget/meteoWidget.h @@ -61,7 +61,7 @@ void on_actionInfoPoint(); void on_actionDataAvailability(); void on_actionDataSum(); - void drawSum(QList varToSumList); + void drawSum(); private: int meteoWidgetID; From 9f96a90652aaf661da952e8addab30669cdb39ce Mon Sep 17 00:00:00 2001 From: Gabriele Antolini Date: Thu, 28 Mar 2024 13:16:49 +0100 Subject: [PATCH 69/72] return values in multipleDetrending --- interpolation/interpolation.cpp | 23 +++++++---------------- project/project.cpp | 3 +++ 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/interpolation/interpolation.cpp b/interpolation/interpolation.cpp index 6f0c2a54..9c25d76a 100644 --- a/interpolation/interpolation.cpp +++ b/interpolation/interpolation.cpp @@ -1407,7 +1407,7 @@ std::vector getfittingParameters(Crit3DProxyCombination myCombination, bool multipleDetrending(std::vector &myPoints, Crit3DInterpolationSettings* mySettings, meteoVariable myVar, std::string &errorStr) { - if (! getUseDetrendingVar(myVar)) return false; + if (! getUseDetrendingVar(myVar)) return true; Crit3DProxyCombination myCombination = mySettings->getSelectedCombination(); @@ -1427,7 +1427,7 @@ bool multipleDetrending(std::vector &myPoints, } } - if (nrPredictors == 0) return false; + if (nrPredictors == 0) return true; // proxy spatial variability (1st step) double avg, stdDev; @@ -1443,11 +1443,10 @@ bool multipleDetrending(std::vector &myPoints, } } - if (validNr == 0) return false; + if (validNr == 0) return true; // exclude points with incomplete proxies unsigned i; - //std::vector finalPoints; bool isValid; float proxyValue; vector::iterator it = myPoints.begin(); @@ -1476,16 +1475,11 @@ bool multipleDetrending(std::vector &myPoints, } // proxy spatial variability (2nd step) - std::vector avgs; - std::vector stdDevs; - validNr = 0; for (int pos=0; pos < proxyNr; pos++) { if (myCombination.isProxyActive(pos) && proxyValidity(myPoints, pos, mySettings->getProxy(pos)->getStdDevThreshold(), avg, stdDev)) { - avgs.push_back(avg); - stdDevs.push_back(stdDev); mySettings->getProxy(pos)->setIsSignificant(true); validNr++; } @@ -1493,11 +1487,10 @@ bool multipleDetrending(std::vector &myPoints, mySettings->getProxy(pos)->setIsSignificant(false); } - if (validNr == 0) return false; + if (validNr == 0) return true; - // z-score normalization + // filling vectors std::vector rowPredictors; - //std::vector > predictorsNorm; std::vector > predictors; std::vector predictands; std::vector weights; @@ -1509,11 +1502,9 @@ bool multipleDetrending(std::vector &myPoints, if ((mySettings->getProxy(pos)->getIsSignificant())) { proxyValue = myPoints[i].getProxyValue(pos); - //rowPredictors.push_back((proxyValue - avgs[index]) / stdDevs[index]); rowPredictors.push_back(proxyValue); } - //predictorsNorm.push_back(rowPredictors); predictors.push_back(rowPredictors); predictands.push_back(myPoints[i].value); weights.push_back(myPoints[i].regressionWeight); @@ -1525,7 +1516,7 @@ bool multipleDetrending(std::vector &myPoints, mySettings->getProxy(pos)->setIsSignificant(false); errorStr = "Not enough points for detrending."; - return false; + return true; } std::vector > parametersMin; @@ -1679,7 +1670,7 @@ bool preInterpolation(std::vector &myPoints, Crit if (mySettings->getUseMultipleDetrending()) { mySettings->setCurrentCombination(mySettings->getSelectedCombination()); - multipleDetrending(myPoints, mySettings, myVar, errorStr); + if (! multipleDetrending(myPoints, mySettings, myVar, errorStr)) return false; } else { diff --git a/project/project.cpp b/project/project.cpp index fd9f5f0b..4c25336e 100644 --- a/project/project.cpp +++ b/project/project.cpp @@ -2585,6 +2585,9 @@ bool Project::interpolationGrid(meteoVariable myVar, const Crit3DTime& myTime) { for (unsigned row = 0; row < unsigned(meteoGridDbHandler->meteoGrid()->gridStructure().header().nrRows); row++) { + if (meteoGridDbHandler->meteoGrid()->meteoPoints()[row][col]->id == "002565") + int a = 0; + if (meteoGridDbHandler->meteoGrid()->meteoPoints()[row][col]->active) { myX = meteoGridDbHandler->meteoGrid()->meteoPoints()[row][col]->point.utm.x; From 91dda10586110ec5d6989088d96b30a0fe142562 Mon Sep 17 00:00:00 2001 From: lauracosta Date: Thu, 28 Mar 2024 14:13:20 +0100 Subject: [PATCH 70/72] redraw if varToSum has been changed --- meteoWidget/meteoWidget.cpp | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/meteoWidget/meteoWidget.cpp b/meteoWidget/meteoWidget.cpp index ca24f0bf..c155ee7b 100644 --- a/meteoWidget/meteoWidget.cpp +++ b/meteoWidget/meteoWidget.cpp @@ -1871,6 +1871,10 @@ void Crit3DMeteoWidget::showMonthlyGraph() frequencyType prevFreq = currentFreq; currentFreq = monthly; + // change freq, reset sum data settings + varToSumList.clear(); + dataSum->setChecked(false); + dailyButton->setEnabled(true); hourlyButton->setEnabled(true); monthlyButton->setEnabled(false); @@ -1933,6 +1937,10 @@ void Crit3DMeteoWidget::showDailyGraph() frequencyType prevFreq = currentFreq; currentFreq = daily; + // change freq, reset sum data settings + varToSumList.clear(); + dataSum->setChecked(false); + dailyButton->setEnabled(false); hourlyButton->setEnabled(true); monthlyButton->setEnabled(true); @@ -1995,6 +2003,10 @@ void Crit3DMeteoWidget::showHourlyGraph() frequencyType prevFreq = currentFreq; currentFreq = hourly; + // change freq, reset sum data settings + varToSumList.clear(); + dataSum->setChecked(false); + hourlyButton->setEnabled(false); dailyButton->setEnabled(true); monthlyButton->setEnabled(true); @@ -2833,6 +2845,7 @@ void Crit3DMeteoWidget::on_actionDataAvailability() void Crit3DMeteoWidget::on_actionDataSum() { DialogVariableToSum varToSum(currentVariables, varToSumList); + QList varToSumListPrev = varToSumList; if (varToSum.result() == QDialog::Accepted) { varToSumList = varToSum.getSelectedVariable(); @@ -2843,17 +2856,24 @@ void Crit3DMeteoWidget::on_actionDataSum() { dataSum->setChecked(false); } + else + { + dataSum->setChecked(true); + } return; } if (!varToSumList.isEmpty()) { dataSum->setChecked(true); - drawSum(); } else { dataSum->setChecked(false); } + if (varToSumListPrev != varToSumList) //something is changed + { + redraw(); + } } void Crit3DMeteoWidget::drawSum() From 04236b5f895122059eccd240cae36c2adeea6321 Mon Sep 17 00:00:00 2001 From: lauracosta Date: Thu, 28 Mar 2024 14:13:20 +0100 Subject: [PATCH 71/72] redraw if varToSum has been changed --- meteoWidget/meteoWidget.cpp | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/meteoWidget/meteoWidget.cpp b/meteoWidget/meteoWidget.cpp index ca24f0bf..c155ee7b 100644 --- a/meteoWidget/meteoWidget.cpp +++ b/meteoWidget/meteoWidget.cpp @@ -1871,6 +1871,10 @@ void Crit3DMeteoWidget::showMonthlyGraph() frequencyType prevFreq = currentFreq; currentFreq = monthly; + // change freq, reset sum data settings + varToSumList.clear(); + dataSum->setChecked(false); + dailyButton->setEnabled(true); hourlyButton->setEnabled(true); monthlyButton->setEnabled(false); @@ -1933,6 +1937,10 @@ void Crit3DMeteoWidget::showDailyGraph() frequencyType prevFreq = currentFreq; currentFreq = daily; + // change freq, reset sum data settings + varToSumList.clear(); + dataSum->setChecked(false); + dailyButton->setEnabled(false); hourlyButton->setEnabled(true); monthlyButton->setEnabled(true); @@ -1995,6 +2003,10 @@ void Crit3DMeteoWidget::showHourlyGraph() frequencyType prevFreq = currentFreq; currentFreq = hourly; + // change freq, reset sum data settings + varToSumList.clear(); + dataSum->setChecked(false); + hourlyButton->setEnabled(false); dailyButton->setEnabled(true); monthlyButton->setEnabled(true); @@ -2833,6 +2845,7 @@ void Crit3DMeteoWidget::on_actionDataAvailability() void Crit3DMeteoWidget::on_actionDataSum() { DialogVariableToSum varToSum(currentVariables, varToSumList); + QList varToSumListPrev = varToSumList; if (varToSum.result() == QDialog::Accepted) { varToSumList = varToSum.getSelectedVariable(); @@ -2843,17 +2856,24 @@ void Crit3DMeteoWidget::on_actionDataSum() { dataSum->setChecked(false); } + else + { + dataSum->setChecked(true); + } return; } if (!varToSumList.isEmpty()) { dataSum->setChecked(true); - drawSum(); } else { dataSum->setChecked(false); } + if (varToSumListPrev != varToSumList) //something is changed + { + redraw(); + } } void Crit3DMeteoWidget::drawSum() From 1939ae2811c4c7f47f9c50da363dee07765a4321 Mon Sep 17 00:00:00 2001 From: lauracosta Date: Thu, 28 Mar 2024 15:09:33 +0100 Subject: [PATCH 72/72] checkExistingData --- meteoWidget/meteoWidget.cpp | 32 +++++++++++++++++++++++++++++++- meteoWidget/meteoWidget.h | 1 + 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/meteoWidget/meteoWidget.cpp b/meteoWidget/meteoWidget.cpp index c155ee7b..df17f08e 100644 --- a/meteoWidget/meteoWidget.cpp +++ b/meteoWidget/meteoWidget.cpp @@ -495,6 +495,36 @@ void Crit3DMeteoWidget::updateTimeRange() lastMonthlyDate = myMonthlyDateLast; } } + checkExistingData(); +} + +void Crit3DMeteoWidget::checkExistingData() +{ + // set enable/disable buttons if daily/hourly/monthly data are available + if ( (!firstDailyDate.isValid() || firstDailyDate.year() == 1800) && (!lastDailyDate.isValid() || lastDailyDate.year() == 1800) ) + { + dailyButton->setVisible(false); + } + else + { + dailyButton->setVisible(true); + } + if ( (!firstHourlyDate.isValid() || firstHourlyDate.year() == 1800) && (!lastHourlyDate.isValid() || lastHourlyDate.year() == 1800) ) + { + hourlyButton->setVisible(false); + } + else + { + hourlyButton->setVisible(true); + } + if ( (!firstMonthlyDate.isValid() || firstMonthlyDate.year() == 1800) && (!lastMonthlyDate.isValid() || lastMonthlyDate.year() == 1800) ) + { + monthlyButton->setVisible(false); + } + else + { + monthlyButton->setVisible(true); + } } @@ -1875,9 +1905,9 @@ void Crit3DMeteoWidget::showMonthlyGraph() varToSumList.clear(); dataSum->setChecked(false); + monthlyButton->setEnabled(false); dailyButton->setEnabled(true); hourlyButton->setEnabled(true); - monthlyButton->setEnabled(false); if (prevFreq == daily) { diff --git a/meteoWidget/meteoWidget.h b/meteoWidget/meteoWidget.h index f52d9e0d..ca328824 100644 --- a/meteoWidget/meteoWidget.h +++ b/meteoWidget/meteoWidget.h @@ -62,6 +62,7 @@ void on_actionDataAvailability(); void on_actionDataSum(); void drawSum(); + void checkExistingData(); private: int meteoWidgetID;