From e2c68bbfc752f05fccc7fe7380e8baaa0c42c941 Mon Sep 17 00:00:00 2001 From: lauracosta Date: Mon, 19 Feb 2024 14:30:25 +0100 Subject: [PATCH 1/5] added comment MapVarUnit --- meteo/meteo.h | 1 + 1 file changed, 1 insertion(+) diff --git a/meteo/meteo.h b/meteo/meteo.h index 77167b52f..c8615f6c9 100644 --- a/meteo/meteo.h +++ b/meteo/meteo.h @@ -249,6 +249,7 @@ { monthlyGlobalRadiation, "MONTHLY_RAD" } }; + // se cambiano le unità di misura, controlalre procedure che generano i netcdf e ne controllano la unit, come quelle di mapping const std::map, std::string> MapVarUnit = { { {dailyAirTemperatureMin,airTemperature,monthlyAirTemperatureMin}, "C"} , { {dailyAirTemperatureMax,monthlyAirTemperatureMax}, "C"} , From 12d81cbab5423a30b672db43ef376d00d5bb4bc3 Mon Sep 17 00:00:00 2001 From: ftomei Date: Mon, 19 Feb 2024 15:14:32 +0100 Subject: [PATCH 2/5] update download --- mathFunctions/commonConstants.h | 18 ++++++++++-------- pragaProject/pragaProject.cpp | 25 +++++++++---------------- 2 files changed, 19 insertions(+), 24 deletions(-) diff --git a/mathFunctions/commonConstants.h b/mathFunctions/commonConstants.h index aeadd36e1..f7997c073 100644 --- a/mathFunctions/commonConstants.h +++ b/mathFunctions/commonConstants.h @@ -54,6 +54,16 @@ #define PATH_STATES "STATES/" #define PATH_NETCDF "NETCDF/" + // --------------- PRAGA constants ---------------- + #define PRAGA_OK 0 + #define PRAGA_ERROR 100 + #define PRAGA_INVALID_COMMAND 101 + #define PRAGA_MISSING_FILE 102 + #define PRAGA_ENV_ERROR 103 + #define NO_ACTIVE -8888 + #define MAXDAYS_DOWNLOAD_DAILY 180 + #define MAXDAYS_DOWNLOAD_HOURLY 10 + // --------------- soilFluxes3D ---------------- #define NOLINK -1 @@ -75,14 +85,6 @@ #define CRIT1D_OK 0 #define CRIT3D_OK 1 - // --------------- PRAGA constants ---------------- - #define PRAGA_OK 0 - #define PRAGA_ERROR 100 - #define PRAGA_INVALID_COMMAND 101 - #define PRAGA_MISSING_FILE 102 - #define PRAGA_ENV_ERROR 103 - #define NO_ACTIVE -8888 - #define VANGENUCHTEN 0 #define MODIFIEDVANGENUCHTEN 1 #define CAMPBELL 2 diff --git a/pragaProject/pragaProject.cpp b/pragaProject/pragaProject.cpp index 5336073ae..fe1f19361 100644 --- a/pragaProject/pragaProject.cpp +++ b/pragaProject/pragaProject.cpp @@ -1,3 +1,4 @@ +#include "commonConstants.h" #include "basicMath.h" #include "climate.h" #include "crit3dElabList.h" @@ -1281,8 +1282,6 @@ bool PragaProject::downloadDailyDataArkimet(QList variables, bool prec0 return false; } - const int MAXDAYS = 30; - QString id, dataset; QList datasetList; QList> idList; @@ -1344,14 +1343,11 @@ bool PragaProject::downloadDailyDataArkimet(QList variables, bool prec0 { if (showInfo) { - setProgressBar("Download data from: " + startDate.toString("yyyy-MM-dd") + " to: " + endDate.toString("yyyy-MM-dd") + " dataset:" + datasetList[i], nrDays); + setProgressBar("Download daily data from: " + startDate.toString("yyyy-MM-dd") + " to: " + endDate.toString("yyyy-MM-dd") + " dataset:" + datasetList[i], nrDays); } - int nrStations = idList[i].size(); - int stepDays = std::max(MAXDAYS, 360 / nrStations); - QDate date1 = startDate; - QDate date2 = std::min(date1.addDays(stepDays), endDate); + QDate date2 = std::min(date1.addDays(MAXDAYS_DOWNLOAD_DAILY), endDate); while (date1 <= endDate) { @@ -1359,17 +1355,16 @@ bool PragaProject::downloadDailyDataArkimet(QList variables, bool prec0 if (showInfo) { - updateProgressBar(startDate.daysTo(date2)+1); + updateProgressBar(startDate.daysTo(date2) + 1); } date1 = date2.addDays(1); - date2 = std::min(date1.addDays(stepDays), endDate); + date2 = std::min(date1.addDays(MAXDAYS_DOWNLOAD_DAILY), endDate); } if (showInfo) closeProgressBar(); } - delete myDownload; return true; } @@ -1377,8 +1372,6 @@ bool PragaProject::downloadDailyDataArkimet(QList variables, bool prec0 bool PragaProject::downloadHourlyDataArkimet(QList variables, QDate startDate, QDate endDate, bool showInfo) { - const int MAXDAYS = 7; - QList arkIdVar; Download* myDownload = new Download(meteoPointsDbHandler->getDbName()); @@ -1427,24 +1420,24 @@ bool PragaProject::downloadHourlyDataArkimet(QList variables, QDate sta for( int i=0; i < datasetList.size(); i++ ) { QDate date1 = startDate; - QDate date2 = std::min(date1.addDays(MAXDAYS-1), endDate); + QDate date2 = std::min(date1.addDays(MAXDAYS_DOWNLOAD_HOURLY), endDate); if (showInfo) { - setProgressBar("Download data from: " + startDate.toString("yyyy-MM-dd") + " to:" + endDate.toString("yyyy-MM-dd") + " dataset:" + datasetList[i], nrDays); + setProgressBar("Download hourly data from: " + startDate.toString("yyyy-MM-dd") + " to:" + endDate.toString("yyyy-MM-dd") + " dataset:" + datasetList[i], nrDays); } while (date1 <= endDate) { if (showInfo) { - updateProgressBar(int(startDate.daysTo(date2)+1)); + updateProgressBar(startDate.daysTo(date2) + 1); } if (! myDownload->downloadHourlyData(date1, date2, datasetList[i], idList[i], arkIdVar)) updateProgressBarText("NO DATA"); date1 = date2.addDays(1); - date2 = std::min(date1.addDays(MAXDAYS-1), endDate); + date2 = std::min(date1.addDays(MAXDAYS_DOWNLOAD_HOURLY), endDate); } if (showInfo) { From f080225d5cbc49a2ee7a9fdd202f8dfdbe9df172 Mon Sep 17 00:00:00 2001 From: ftomei Date: Mon, 19 Feb 2024 15:17:47 +0100 Subject: [PATCH 3/5] fix comment --- meteo/meteo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meteo/meteo.h b/meteo/meteo.h index c8615f6c9..d640a1720 100644 --- a/meteo/meteo.h +++ b/meteo/meteo.h @@ -249,7 +249,7 @@ { monthlyGlobalRadiation, "MONTHLY_RAD" } }; - // se cambiano le unità di misura, controlalre procedure che generano i netcdf e ne controllano la unit, come quelle di mapping + // se cambiano le unità di misura, controllare le procedure che generano i netcdf e ne controllano la unit, come quelle di mapping const std::map, std::string> MapVarUnit = { { {dailyAirTemperatureMin,airTemperature,monthlyAirTemperatureMin}, "C"} , { {dailyAirTemperatureMax,monthlyAirTemperatureMax}, "C"} , From 32307b795a79745500be306dffa2f2e15a125020 Mon Sep 17 00:00:00 2001 From: ftomei Date: Mon, 19 Feb 2024 18:47:44 +0100 Subject: [PATCH 4/5] add isClimateOutput --- criteriaModel/criteria1DProject.cpp | 63 +++++++++++++++++++++++++++-- criteriaModel/criteria1DProject.h | 1 + 2 files changed, 60 insertions(+), 4 deletions(-) diff --git a/criteriaModel/criteria1DProject.cpp b/criteriaModel/criteria1DProject.cpp index 8148c6bac..5c4d54943 100644 --- a/criteriaModel/criteria1DProject.cpp +++ b/criteriaModel/criteria1DProject.cpp @@ -65,6 +65,7 @@ void Crit1DProject::initialize() outputString = ""; // specific outputs + isClimateOutput = false; waterDeficitDepth.clear(); waterContentDepth.clear(); degreeOfSaturationDepth.clear(); @@ -253,60 +254,80 @@ bool Crit1DProject::readSettings() // OUTPUT variables (optional) QList depthList; projectSettings->beginGroup("output"); + + isClimateOutput = projectSettings->value("isClimateOutput", false).toBool(); + depthList = projectSettings->value("waterContent").toStringList(); if (! setVariableDepth(depthList, waterContentDepth)) { projectError = "Wrong water content depth in " + configFileName; return false; } + depthList = projectSettings->value("degreeOfSaturation").toStringList(); if (! setVariableDepth(depthList, degreeOfSaturationDepth)) { projectError = "Wrong degree of saturation depth in " + configFileName; return false; } + depthList = projectSettings->value("waterPotential").toStringList(); if (! setVariableDepth(depthList, waterPotentialDepth)) { projectError = "Wrong water potential depth in " + configFileName; return false; } + depthList = projectSettings->value("waterDeficit").toStringList(); if (! setVariableDepth(depthList, waterDeficitDepth)) { projectError = "Wrong water deficit depth in " + configFileName; return false; } + depthList = projectSettings->value("awc").toStringList(); if (! setVariableDepth(depthList, awcDepth)) { projectError = "Wrong available water capacity depth in " + configFileName; return false; } + depthList = projectSettings->value("availableWater").toStringList(); if (depthList.size() == 0) + { + // alternative field name depthList = projectSettings->value("aw").toStringList(); + } if (! setVariableDepth(depthList, availableWaterDepth)) { projectError = "Wrong available water depth in " + configFileName; return false; } + depthList = projectSettings->value("fractionAvailableWater").toStringList(); if (depthList.size() == 0) + { + // alternative field name depthList = projectSettings->value("faw").toStringList(); + } if (! setVariableDepth(depthList, fractionAvailableWaterDepth)) { projectError = "Wrong fraction available water depth in " + configFileName; return false; } + depthList = projectSettings->value("factorOfSafety").toStringList(); if (depthList.size() == 0) - depthList = projectSettings->value("factorOfSafety").toStringList(); + { + // alternative field name + depthList = projectSettings->value("fos").toStringList(); + } if (! setVariableDepth(depthList, factorOfSafetyDepth)) { projectError = "Wrong slope stability depth in " + configFileName; return false; } + projectSettings->endGroup(); return true; @@ -1542,12 +1563,22 @@ bool Crit1DProject::createOutputTable(QString &myError) QString queryString = "DROP TABLE '" + myCase.unit.idCase + "'"; QSqlQuery myQuery = this->dbOutput.exec(queryString); - queryString = "CREATE TABLE '" + myCase.unit.idCase + "'" + if (isClimateOutput) + { + queryString = "CREATE TABLE '" + myCase.unit.idCase + "'" + + " ( DATE TEXT, PREC REAL, IRRIGATION REAL," + + " AVAILABLE_WATER REAL, FRACTION_AW REAL," + + " TRANSP_MAX, TRANSP REAL"; + } + else + { + queryString = "CREATE TABLE '" + myCase.unit.idCase + "'" + " ( DATE TEXT, PREC REAL, IRRIGATION REAL, WATER_CONTENT REAL, SURFACE_WC REAL, " + " AVAILABLE_WATER REAL, READILY_AW REAL, FRACTION_AW REAL, " + " RUNOFF REAL, DRAINAGE REAL, LATERAL_DRAINAGE REAL, CAPILLARY_RISE REAL, " + " ET0 REAL, TRANSP_MAX, TRANSP REAL, EVAP_MAX REAL, EVAP REAL, " + " LAI REAL, ROOT_DEPTH REAL, BALANCE REAL"; + } // specific depth variables for (unsigned int i = 0; i < waterContentDepth.size(); i++) @@ -1591,6 +1622,7 @@ bool Crit1DProject::createOutputTable(QString &myError) queryString += ", " + fieldName + " REAL"; } + // close query queryString += ")"; myQuery = this->dbOutput.exec(queryString); @@ -1608,11 +1640,21 @@ void Crit1DProject::updateOutput(Crit3DDate myDate, bool isFirst) { if (isFirst) { - outputString = "INSERT INTO '" + myCase.unit.idCase + "'" + if (isClimateOutput) + { + outputString = "INSERT INTO '" + myCase.unit.idCase + "'" + + " (DATE, PREC, IRRIGATION," + + " AVAILABLE_WATER, FRACTION_AW," + + " TRANSP_MAX, TRANSP"; + } + else + { + outputString = "INSERT INTO '" + myCase.unit.idCase + "'" + " (DATE, PREC, IRRIGATION, WATER_CONTENT, SURFACE_WC, " + " AVAILABLE_WATER, READILY_AW, FRACTION_AW, " + " RUNOFF, DRAINAGE, LATERAL_DRAINAGE, CAPILLARY_RISE, ET0, " + " TRANSP_MAX, TRANSP, EVAP_MAX, EVAP, LAI, ROOT_DEPTH, BALANCE"; + } // specific depth variables for (unsigned int i = 0; i < waterContentDepth.size(); i++) @@ -1663,7 +1705,19 @@ void Crit1DProject::updateOutput(Crit3DDate myDate, bool isFirst) outputString += ","; } - outputString += "('" + QString::fromStdString(myDate.toStdString()) + "'" + if (isClimateOutput) + { + outputString += "('" + QString::fromStdString(myDate.toStdString()) + "'" + + "," + QString::number(myCase.output.dailyPrec) + + "," + QString::number(myCase.output.dailyIrrigation) + + "," + QString::number(myCase.output.dailyAvailableWater, 'g', 4) + + "," + QString::number(myCase.output.dailyFractionAW, 'g', 3) + + "," + QString::number(myCase.output.dailyMaxTranspiration, 'g', 3) + + "," + QString::number(myCase.output.dailyTranspiration, 'g', 3); + } + else + { + outputString += "('" + QString::fromStdString(myDate.toStdString()) + "'" + "," + QString::number(myCase.output.dailyPrec) + "," + QString::number(myCase.output.dailyIrrigation) + "," + QString::number(myCase.output.dailySoilWaterContent, 'g', 4) @@ -1683,6 +1737,7 @@ void Crit1DProject::updateOutput(Crit3DDate myDate, bool isFirst) + "," + getOutputStringNullZero(myCase.crop.LAI) + "," + getOutputStringNullZero(myCase.crop.roots.rootDepth) + "," + QString::number(myCase.output.dailyBalance, 'g', 3); + } // specific depth variables for (unsigned int i = 0; i < waterContentDepth.size(); i++) diff --git a/criteriaModel/criteria1DProject.h b/criteriaModel/criteria1DProject.h index 29c5775ed..d033b595c 100644 --- a/criteriaModel/criteria1DProject.h +++ b/criteriaModel/criteria1DProject.h @@ -90,6 +90,7 @@ bool addDateTimeLogFile; // specific output + bool isClimateOutput; std::vector waterContentDepth; std::vector degreeOfSaturationDepth; std::vector waterPotentialDepth; From 0eb53a4661e71f10829df4de63531d7b1122570e Mon Sep 17 00:00:00 2001 From: ftomei Date: Mon, 19 Feb 2024 19:03:18 +0100 Subject: [PATCH 5/5] add isClimateOutput --- criteriaModel/criteria1DProject.cpp | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/criteriaModel/criteria1DProject.cpp b/criteriaModel/criteria1DProject.cpp index 5c4d54943..a858122cd 100644 --- a/criteriaModel/criteria1DProject.cpp +++ b/criteriaModel/criteria1DProject.cpp @@ -1566,8 +1566,7 @@ bool Crit1DProject::createOutputTable(QString &myError) if (isClimateOutput) { queryString = "CREATE TABLE '" + myCase.unit.idCase + "'" - + " ( DATE TEXT, PREC REAL, IRRIGATION REAL," - + " AVAILABLE_WATER REAL, FRACTION_AW REAL," + + " ( DATE TEXT, AVAILABLE_WATER REAL," + " TRANSP_MAX, TRANSP REAL"; } else @@ -1643,8 +1642,7 @@ void Crit1DProject::updateOutput(Crit3DDate myDate, bool isFirst) if (isClimateOutput) { outputString = "INSERT INTO '" + myCase.unit.idCase + "'" - + " (DATE, PREC, IRRIGATION," - + " AVAILABLE_WATER, FRACTION_AW," + + " (DATE, AVAILABLE_WATER," + " TRANSP_MAX, TRANSP"; } else @@ -1708,10 +1706,7 @@ void Crit1DProject::updateOutput(Crit3DDate myDate, bool isFirst) if (isClimateOutput) { outputString += "('" + QString::fromStdString(myDate.toStdString()) + "'" - + "," + QString::number(myCase.output.dailyPrec) - + "," + QString::number(myCase.output.dailyIrrigation) + "," + QString::number(myCase.output.dailyAvailableWater, 'g', 4) - + "," + QString::number(myCase.output.dailyFractionAW, 'g', 3) + "," + QString::number(myCase.output.dailyMaxTranspiration, 'g', 3) + "," + QString::number(myCase.output.dailyTranspiration, 'g', 3); }