Skip to content

Commit

Permalink
Merge commit '0eb53a4661e71f10829df4de63531d7b1122570e'
Browse files Browse the repository at this point in the history
  • Loading branch information
ftomei committed Feb 21, 2024
2 parents d526180 + 0eb53a4 commit 4b5468c
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 28 deletions.
58 changes: 54 additions & 4 deletions agrolib/criteriaModel/criteria1DProject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ void Crit1DProject::initialize()
outputString = "";

// specific outputs
isClimateOutput = false;
waterDeficitDepth.clear();
waterContentDepth.clear();
degreeOfSaturationDepth.clear();
Expand Down Expand Up @@ -253,60 +254,80 @@ bool Crit1DProject::readSettings()
// OUTPUT variables (optional)
QList<QString> 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;
Expand Down Expand Up @@ -1542,12 +1563,21 @@ 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, AVAILABLE_WATER 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++)
Expand Down Expand Up @@ -1591,6 +1621,7 @@ bool Crit1DProject::createOutputTable(QString &myError)
queryString += ", " + fieldName + " REAL";
}

// close query
queryString += ")";
myQuery = this->dbOutput.exec(queryString);

Expand All @@ -1608,11 +1639,20 @@ void Crit1DProject::updateOutput(Crit3DDate myDate, bool isFirst)
{
if (isFirst)
{
outputString = "INSERT INTO '" + myCase.unit.idCase + "'"
if (isClimateOutput)
{
outputString = "INSERT INTO '" + myCase.unit.idCase + "'"
+ " (DATE, AVAILABLE_WATER,"
+ " 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++)
Expand Down Expand Up @@ -1663,7 +1703,16 @@ void Crit1DProject::updateOutput(Crit3DDate myDate, bool isFirst)
outputString += ",";
}

outputString += "('" + QString::fromStdString(myDate.toStdString()) + "'"
if (isClimateOutput)
{
outputString += "('" + QString::fromStdString(myDate.toStdString()) + "'"
+ "," + QString::number(myCase.output.dailyAvailableWater, 'g', 4)
+ "," + 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)
Expand All @@ -1683,6 +1732,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++)
Expand Down
1 change: 1 addition & 0 deletions agrolib/criteriaModel/criteria1DProject.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
bool addDateTimeLogFile;

// specific output
bool isClimateOutput;
std::vector<int> waterContentDepth;
std::vector<int> degreeOfSaturationDepth;
std::vector<int> waterPotentialDepth;
Expand Down
18 changes: 10 additions & 8 deletions agrolib/mathFunctions/commonConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions agrolib/meteo/meteo.h
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@
{ monthlyGlobalRadiation, "MONTHLY_RAD" }
};

// 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::vector<meteoVariable>, std::string> MapVarUnit = {
{ {dailyAirTemperatureMin,airTemperature,monthlyAirTemperatureMin}, "C"} ,
{ {dailyAirTemperatureMax,monthlyAirTemperatureMax}, "C"} ,
Expand Down
25 changes: 9 additions & 16 deletions agrolib/pragaProject/pragaProject.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "commonConstants.h"
#include "basicMath.h"
#include "climate.h"
#include "crit3dElabList.h"
Expand Down Expand Up @@ -1281,8 +1282,6 @@ bool PragaProject::downloadDailyDataArkimet(QList<QString> variables, bool prec0
return false;
}

const int MAXDAYS = 30;

QString id, dataset;
QList<QString> datasetList;
QList<QList<QString>> idList;
Expand Down Expand Up @@ -1344,41 +1343,35 @@ bool PragaProject::downloadDailyDataArkimet(QList<QString> 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)
{
myDownload->downloadDailyData(date1, date2, datasetList[i], idList[i], arkIdVar, prec0024);

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;
}


bool PragaProject::downloadHourlyDataArkimet(QList<QString> variables, QDate startDate, QDate endDate, bool showInfo)
{
const int MAXDAYS = 7;

QList<int> arkIdVar;
Download* myDownload = new Download(meteoPointsDbHandler->getDbName());

Expand Down Expand Up @@ -1427,24 +1420,24 @@ bool PragaProject::downloadHourlyDataArkimet(QList<QString> 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)
{
Expand Down

0 comments on commit 4b5468c

Please sign in to comment.