From 6c46248059bad4a04c9215ae6ecebd420dd60042 Mon Sep 17 00:00:00 2001 From: Gabriele Antolini Date: Fri, 6 Sep 2024 11:55:08 +0200 Subject: [PATCH] revised errors in shell --- pragaProject/pragaProject.cpp | 108 +++++++++++++------------------- pragaProject/pragaShell.cpp | 113 +++++++++++++++++----------------- project/shell.cpp | 9 +-- 3 files changed, 102 insertions(+), 128 deletions(-) diff --git a/pragaProject/pragaProject.cpp b/pragaProject/pragaProject.cpp index 2e5352fc9..de122b7fd 100644 --- a/pragaProject/pragaProject.cpp +++ b/pragaProject/pragaProject.cpp @@ -2026,21 +2026,21 @@ bool PragaProject::timeAggregateGrid(QDate dateIni, QDate dateFin, QList dateFin) { - logError("Wrong period"); + errorString = "Wrong period"; return false; } @@ -2072,14 +2072,14 @@ bool PragaProject::hourlyDerivedVariablesGrid(QDate first, QDate last, bool load // check meteo grid if (! meteoGridLoaded) { - logError("No meteo grid"); + errorString = "No meteo grid"; return false; } // check dates if (first.isNull() || last.isNull() || first > last) { - logError("Wrong period"); + errorString = "Wrong period"; return false; } @@ -2366,28 +2366,28 @@ bool PragaProject::interpolationMeteoGridPeriod(QDate dateIni, QDate dateFin, QL // check variables if (variables.size() == 0) { - logError("No variable"); + errorString = "No variable"; return false; } // check meteo point if (! meteoPointsLoaded || nrMeteoPoints == 0) { - logError("No meteo points"); + errorString = "No meteo points"; return false; } // check meteo grid if (! meteoGridLoaded) { - logError("No meteo grid"); + errorString = "No meteo grid"; return false; } // check dates if (dateIni.isNull() || dateFin.isNull() || dateIni > dateFin) { - logError("Wrong period"); + errorString = "Wrong period"; return false; } @@ -2413,7 +2413,7 @@ bool PragaProject::interpolationMeteoGridPeriod(QDate dateIni, QDate dateFin, QL if (freq == noFrequency) { - logError("Unknown variable: " + QString::fromStdString(getMeteoVarName(myVar))); + errorString = "Unknown variable: " + QString::fromStdString(getMeteoVarName(myVar)); return false; } else if (freq == hourly) @@ -2651,14 +2651,23 @@ bool PragaProject::interpolationCrossValidationPeriod(QDate dateIni, QDate dateF // check meteo point if (! meteoPointsLoaded || nrMeteoPoints == 0) { - logError("No meteo points"); + errorString = "No meteo points"; return false; } // check dates if (dateIni.isNull() || dateFin.isNull() || dateIni > dateFin) { - logError("Wrong period"); + errorString = "Wrong period"; + return false; + } + + // available variables for cv + if ((myVar == airRelHumidity && interpolationSettings.getUseDewPoint()) || + myVar == windVectorDirection || + myVar == windVectorIntensity) + { + errorString = "Cross validation not available for variable: " + QString::fromStdString(getVariableString(myVar)); return false; } @@ -2669,7 +2678,7 @@ bool PragaProject::interpolationCrossValidationPeriod(QDate dateIni, QDate dateF QDate myDate = dateIni; frequencyType myFreq = getVarFrequency(myVar); - if (getUseTdVar(myVar)) + if (interpolationSettings.getUseTD()) { logInfoGUI("Loading topographic distance maps..."); if (! loadTopographicDistanceMaps(true, false)) @@ -2693,10 +2702,13 @@ bool PragaProject::interpolationCrossValidationPeriod(QDate dateIni, QDate dateF Crit3DTime myTime; QTextStream cvOutput(&file); - cvOutput << "Time,MAE,MBE,RMSE,CRE,R2"; + cvOutput << "Time,MAE,MBE,RMSE,CRE,R2" << '\n'; + logInfoGUI("Cross validating " + QString::fromStdString(getMeteoVarName(myVar)) + " from " + dateIni.toString("yyyy-MM-dd") + " to " + dateFin.toString("yyyy-MM-dd")); while (myDate <= dateFin) { + logInfoGUI(myDate.toString("yyyy-MM-dd")); + if (getVarFrequency(myVar) == hourly) { for (myHour = 1; myHour <= 24; myHour++) @@ -2705,63 +2717,27 @@ bool PragaProject::interpolationCrossValidationPeriod(QDate dateIni, QDate dateF if (interpolationCv(myVar, myTime, &stats)) { - cvOutput << getQDateTime(myTime).toString() << '\n'; - cvOutput << stats.getMeanAbsoluteError() << '\n'; - cvOutput << stats.getMeanBiasError() << '\n'; - cvOutput << stats.getRootMeanSquareError() << '\n'; - cvOutput << stats.getCompoundRelativeError() << '\n'; - cvOutput << stats.getR2() << '\n'; + cvOutput << getQDateTime(myTime).toString(); + cvOutput << "," << stats.getMeanAbsoluteError(); + cvOutput << "," << stats.getMeanBiasError(); + cvOutput << "," << stats.getRootMeanSquareError(); + cvOutput << "," << stats.getCompoundRelativeError(); + cvOutput << "," << stats.getR2() << '\n'; } } - - - - - - /*if (myVar == airRelHumidity && interpolationSettings.getUseDewPoint()) - { - if (interpolationSettings.getUseInterpolatedTForRH()) - passInterpolatedTemperatureToHumidityPoints(getCrit3DTime(myDate, myHour), meteoSettings); - if (! interpolationDemMain(airDewTemperature, getCrit3DTime(myDate, myHour), hourlyMeteoMaps->mapHourlyTdew)) return false; - hourlyMeteoMaps->computeRelativeHumidityMap(hourlyMeteoMaps->mapHourlyRelHum); - } - else if (myVar == windVectorDirection || myVar == windVectorIntensity) { - if (! interpolationDemMain(windVectorX, getCrit3DTime(myDate, myHour), getPragaMapFromVar(windVectorX))) return false; - if (! interpolationDemMain(windVectorY, getCrit3DTime(myDate, myHour), getPragaMapFromVar(windVectorY))) return false; - if (! pragaHourlyMaps->computeWindVector()) return false; - } - else if (myVar == leafWetness) { - hourlyMeteoMaps->computeLeafWetnessMap() ; - } - else if (myVar == referenceEvapotranspiration) { - hourlyMeteoMaps->computeET0PMMap(DEM, radiationMaps); - } - else { - if (! interpolationDemMain(myVar, getCrit3DTime(myDate, myHour), getPragaMapFromVar(myVar))) return false; - } - - if (myVar == windVectorDirection || myVar == windVectorIntensity) - { - meteoGridDbHandler->meteoGrid()->spatialAggregateMeteoGrid(windVectorX, hourly, getCrit3DDate(myDate), myHour, 0, &DEM, getPragaMapFromVar(windVectorX), interpolationSettings.getMeteoGridAggrMethod()); - meteoGridDbHandler->meteoGrid()->spatialAggregateMeteoGrid(windVectorY, hourly, getCrit3DDate(myDate), myHour, 0, &DEM, getPragaMapFromVar(windVectorY), interpolationSettings.getMeteoGridAggrMethod()); - meteoGridDbHandler->meteoGrid()->computeWindVectorHourly(getCrit3DDate(myDate), myHour); - } - else - meteoGridDbHandler->meteoGrid()->spatialAggregateMeteoGrid(myVar, hourly, getCrit3DDate(myDate), myHour, 0, &DEM, myGrid, interpolationSettings.getMeteoGridAggrMethod()); - - */ - } else { + myTime = getCrit3DTime(myDate, 0); + if (interpolationCv(myVar, myTime, &stats)) { - cvOutput << getQDateTime(myTime).date().toString() << '\n'; - cvOutput << stats.getMeanAbsoluteError() << '\n'; - cvOutput << stats.getMeanBiasError() << '\n'; - cvOutput << stats.getRootMeanSquareError() << '\n'; - cvOutput << stats.getCompoundRelativeError() << '\n'; - cvOutput << stats.getR2() << '\n'; + cvOutput << getQDateTime(myTime).date().toString(); + cvOutput << "," << stats.getMeanAbsoluteError(); + cvOutput << "," << stats.getMeanBiasError(); + cvOutput << "," << stats.getRootMeanSquareError(); + cvOutput << "," << stats.getCompoundRelativeError(); + cvOutput << "," << stats.getR2() << '\n'; } } @@ -3996,14 +3972,14 @@ bool PragaProject::monthlyAggregateVariablesGrid(const QDate &firstDate, const Q // check meteo grid if (! meteoGridLoaded) { - logError("No meteo grid"); + errorString = "No meteo grid"; return false; } // check dates if (firstDate.isNull() || lastDate.isNull() || firstDate > lastDate) { - logError("Wrong period"); + errorString = "Wrong period"; return false; } diff --git a/pragaProject/pragaShell.cpp b/pragaProject/pragaShell.cpp index 7caaa563d..6b995d6a6 100644 --- a/pragaProject/pragaShell.cpp +++ b/pragaProject/pragaShell.cpp @@ -162,7 +162,7 @@ int cmdOpenPragaProject(PragaProject* myProject, QList argumentList) { if (argumentList.size() < 2) { - myProject->logError("Missing project name"); + myProject->errorString = "Missing project name"; return PRAGA_INVALID_COMMAND; } @@ -184,10 +184,7 @@ int cmdOpenPragaProject(PragaProject* myProject, QList argumentList) QString projectName = myProject->getCompleteFileName(filename, myProject->projectPragaFolder); if (! myProject->loadPragaProject(projectName)) - { - myProject->logError(); return PRAGA_ERROR; - } return PRAGA_OK; } @@ -196,7 +193,7 @@ int cmdDownload(PragaProject* myProject, QList argumentList) { if (argumentList.size() < 2) { - myProject->logError("Missing parameters for download"); + myProject->errorString = "Missing parameters for download"; return PRAGA_INVALID_COMMAND; } @@ -218,7 +215,7 @@ int cmdDownload(PragaProject* myProject, QList argumentList) meteoVar = getMeteoVar(var.toStdString()); if (meteoVar == noMeteoVar) { - myProject->logError("Unknown variable: " + var); + myProject->errorString = "Unknown variable: " + var; return PRAGA_ERROR; } else @@ -226,7 +223,7 @@ int cmdDownload(PragaProject* myProject, QList argumentList) myFreq = getVarFrequency(meteoVar); if (myFreq == noFrequency) { - myProject->logError("Unknown frequency for variable : " + var); + myProject->errorString = "Unknown frequency for variable : " + var; return PRAGA_ERROR; } else if (myFreq == daily) @@ -258,13 +255,13 @@ int cmdDownload(PragaProject* myProject, QList argumentList) if (! dateIni.isValid()) { - myProject->logError("Wrong initial date"); + myProject->errorString ="Wrong initial date"; return PRAGA_INVALID_COMMAND; } if (! dateFin.isValid()) { - myProject->logError("Wrong final date"); + myProject->errorString = "Wrong final date"; return PRAGA_INVALID_COMMAND; } @@ -284,7 +281,7 @@ int cmdInterpolationGridPeriod(PragaProject* myProject, QList argumentL { if (argumentList.size() < 2) { - myProject->logError("Missing parameters for gridding"); + myProject->errorString = "Missing parameters for gridding"; return PRAGA_INVALID_COMMAND; } @@ -308,7 +305,7 @@ int cmdInterpolationGridPeriod(PragaProject* myProject, QList argumentL { meteoVar = getMeteoVar(var.toStdString()); if (meteoVar == noMeteoVar) { - myProject->logError("Unknown variable: " + var); + myProject->errorString = "Unknown variable: " + var; return PRAGA_INVALID_COMMAND; } @@ -323,7 +320,7 @@ int cmdInterpolationGridPeriod(PragaProject* myProject, QList argumentL meteoVar = getMeteoVar(var.toStdString()); if (meteoVar == noMeteoVar) { - myProject->logError("Unknown variable: " + var); + myProject->errorString = "Unknown variable: " + var; return PRAGA_INVALID_COMMAND; } @@ -355,25 +352,25 @@ int cmdInterpolationGridPeriod(PragaProject* myProject, QList argumentL if (! dateIni.isValid()) { - myProject->logError("Wrong initial date"); + myProject->errorString = "Wrong initial date"; return PRAGA_INVALID_COMMAND; } if (! dateFin.isValid()) { - myProject->logError("Wrong final date"); + myProject->errorString = "Wrong final date"; return PRAGA_INVALID_COMMAND; } if (saveInterval == NODATA || ! parseSaveInterval) { - myProject->logError("Wrong saving interval number"); + myProject->errorString = "Wrong saving interval number"; return PRAGA_INVALID_COMMAND; } if (! parseLoadInterval) { - myProject->logError("Wrong loading interval number"); + myProject->errorString = "Wrong loading interval number"; return PRAGA_INVALID_COMMAND; } @@ -387,7 +384,7 @@ int cmdAggregationGridPeriod(PragaProject* myProject, QList argumentLis { if (argumentList.size() < 2) { - myProject->logError("Missing parameters for aggregation"); + myProject->errorString = "Missing parameters for aggregation"; return PRAGA_INVALID_COMMAND; } @@ -426,13 +423,13 @@ int cmdAggregationGridPeriod(PragaProject* myProject, QList argumentLis if (! dateIni.isValid()) { - myProject->logError("Wrong initial date"); + myProject->errorString = "Wrong initial date"; return PRAGA_INVALID_COMMAND; } if (! dateFin.isValid()) { - myProject->logError("Wrong final date"); + myProject->errorString = "Wrong final date"; return PRAGA_INVALID_COMMAND; } @@ -466,13 +463,13 @@ int cmdHourlyDerivedVariablesGrid(PragaProject* myProject, QList argume if (! first.isValid()) { - myProject->logError("Wrong initial date"); + myProject->errorString = "Wrong initial date"; return PRAGA_INVALID_COMMAND; } if (! last.isValid()) { - myProject->logError("Wrong final date"); + myProject->errorString = "Wrong final date"; return PRAGA_INVALID_COMMAND; } @@ -519,19 +516,19 @@ int cmdMonthlyIntegrationVariablesGrid(PragaProject* myProject, QList a if (! first.isValid()) { - myProject->logError("Wrong initial date"); + myProject->errorString = "Wrong initial date"; return PRAGA_INVALID_COMMAND; } if (variables.isEmpty()) { - myProject->logError("Wrong variable"); + myProject->errorString ="Wrong variable"; return PRAGA_INVALID_COMMAND; } if (! last.isValid()) { - myProject->logError("Wrong final date"); + myProject->errorString = "Wrong final date"; return PRAGA_INVALID_COMMAND; } @@ -546,9 +543,9 @@ int cmdMonthlyIntegrationVariablesGrid(PragaProject* myProject, QList a int cmdInterpolationCrossValidation(PragaProject* myProject, QList argumentList) { - if (argumentList.size() < 2) + if (argumentList.size() < 4) { - myProject->logError("Missing parameters for cross validation"); + myProject->errorString = "Missing parameters for cross validation"; return PRAGA_INVALID_COMMAND; } @@ -563,11 +560,6 @@ int cmdInterpolationCrossValidation(PragaProject* myProject, QList argu { varString = argumentList[i].right(argumentList[i].length()-3).toStdString(); meteoVar = getMeteoVar(varString); - if (meteoVar == noMeteoVar) - { - myProject->logError("Unknown variable: " + QString::fromStdString(varString)); - return PRAGA_INVALID_COMMAND; - } } else if (argumentList.at(i).left(3) == "-o:") { @@ -589,22 +581,27 @@ int cmdInterpolationCrossValidation(PragaProject* myProject, QList argu } } + if (meteoVar == noMeteoVar) + { + myProject->errorString = "Unknown variable: " + QString::fromStdString(varString); + return PRAGA_INVALID_COMMAND; + } if (! QDir(QFileInfo(fileName).absolutePath()).exists()) { - myProject->logError("Unable to save to directory: " + QFileInfo(fileName).absolutePath()); + myProject->errorString = "Unable to save to directory: " + QFileInfo(fileName).absolutePath(); return PRAGA_INVALID_COMMAND; } if (! dateIni.isValid()) { - myProject->logError("Wrong initial date"); + myProject->errorString = "Wrong initial date"; return PRAGA_INVALID_COMMAND; } if (! dateFin.isValid()) { - myProject->logError("Wrong final date"); + myProject->errorString = "Wrong final date"; return PRAGA_INVALID_COMMAND; } @@ -661,7 +658,7 @@ int cmdExportDailyGridToRaster(PragaProject* myProject, QList argumentL if (meteoVar == noMeteoVar) { - myProject->logError("Wrong variable"); + myProject->errorString = "Wrong variable"; return PRAGA_INVALID_COMMAND; } @@ -672,24 +669,24 @@ int cmdExportDailyGridToRaster(PragaProject* myProject, QList argumentL } else if (dateIniStr == "" || ! dateIni.isValid()) { - myProject->logError("Wrong initial date"); + myProject->errorString = "Wrong initial date"; return PRAGA_INVALID_COMMAND; } else if (dateIniStr == "" || ! dateFin.isValid()) { - myProject->logError("Wrong final date"); + myProject->errorString = "Wrong final date"; return PRAGA_INVALID_COMMAND; } if (path_ == "") { - myProject->logError("Wrong path"); + myProject->errorString = "Wrong path"; return PRAGA_INVALID_COMMAND; } if (! parseCellsize) { - myProject->logError("Wrong cell size"); + myProject->errorString = "Wrong cell size"; return PRAGA_INVALID_COMMAND; } @@ -704,7 +701,7 @@ int cmdExportDailyGridToRaster(PragaProject* myProject, QList argumentL { if (argumentList.size() < 2) { - myProject->logError("Missing xml name"); + myProject->errorString = "Missing xml name"; return PRAGA_INVALID_COMMAND; } @@ -722,7 +719,7 @@ int cmdGridAggregationOnZones(PragaProject* myProject, QList argumentLi { if (argumentList.size() < 4) { - myProject->logError("Missing parameters for aggregation on zones"); + myProject->errorString = "Missing parameters for aggregation on zones"; return PRAGA_INVALID_COMMAND; } @@ -787,25 +784,25 @@ int cmdGridAggregationOnZones(PragaProject* myProject, QList argumentLi } if (variables.isEmpty()) { - myProject->logError("Wrong variable"); + myProject->errorString = "Wrong variable"; return PRAGA_INVALID_COMMAND; } if (aggregationList.isEmpty()) { - myProject->logError("Wrong aggregation"); + myProject->errorString = "Wrong aggregation"; return PRAGA_INVALID_COMMAND; } if (! first.isValid()) { - myProject->logError("Wrong initial date"); + myProject->errorString = "Wrong initial date"; return PRAGA_INVALID_COMMAND; } if (! last.isValid()) { - myProject->logError("Wrong final date"); + myProject->errorString = "Wrong final date"; return PRAGA_INVALID_COMMAND; } @@ -817,7 +814,7 @@ int cmdGridAggregationOnZones(PragaProject* myProject, QList argumentLi QString rasterName; if (!myProject->aggregationDbHandler->getRasterName(&rasterName)) { - myProject->logError("Missing Raster Name inside aggregation db."); + myProject->errorString = "Missing Raster Name inside aggregation db."; return PRAGA_ERROR; } @@ -827,7 +824,7 @@ int cmdGridAggregationOnZones(PragaProject* myProject, QList argumentLi std::string myError = ""; if (! gis::readEsriGrid(fnWithoutExt.toStdString(), myRaster, myError)) { - myProject->logError("Load raster failed: " + QString::fromStdString(myError)); + myProject->errorString = "Load raster failed: " + QString::fromStdString(myError); delete myRaster; return PRAGA_ERROR; } @@ -899,7 +896,7 @@ int pragaBatch(PragaProject* myProject, QString scriptFileName) cmdLine = scriptFile.readLine(); QList argumentList = getArgumentList(cmdLine); result = executeCommand(argumentList, myProject) ; - if (result != 0) + if (result != PRAGA_OK) { myProject->logError("Praga batch error code: " + QString::number(result) + "\n" + myProject->errorString); return result; @@ -934,7 +931,7 @@ int pragaShell(PragaProject* myProject) { QList argumentList = getArgumentList(commandLine); int result = executeCommand(argumentList, myProject); - if (result != 0) + if (result != PRAGA_OK) { myProject->logError("Praga shell error code: " + QString::number(result) + "\n" + myProject->errorString); } @@ -951,7 +948,7 @@ int pragaShell(PragaProject* myProject) { if (argumentList.size() < 2) { - myProject->logError("Missing netcdf name"); + myProject->errorString = "Missing netcdf name"; return PRAGA_INVALID_COMMAND; } @@ -972,7 +969,7 @@ int pragaShell(PragaProject* myProject) { if (argumentList.size() < 2) { - myProject->logError("Missing xml name"); + myProject->errorString = "Missing xml name"; return PRAGA_INVALID_COMMAND; } @@ -1028,7 +1025,7 @@ int pragaShell(PragaProject* myProject) { if (argumentList.size() < 2) { - myProject->logError("Missing xml name"); + myProject->errorString = "Missing xml name"; return PRAGA_INVALID_COMMAND; } @@ -1056,7 +1053,7 @@ int pragaShell(PragaProject* myProject) { if (argumentList.size() < 5) { - myProject->logError("Missing parameters for computing drought index point"); + myProject->errorString = "Missing parameters for computing drought index point"; return PRAGA_INVALID_COMMAND; } @@ -1085,7 +1082,7 @@ int pragaShell(PragaProject* myProject) } else { - myProject->logError("Wrong index: -i:"); + myProject->errorString = "Wrong index: -i:"; return PRAGA_INVALID_COMMAND; } } @@ -1094,7 +1091,7 @@ int pragaShell(PragaProject* myProject) timescale = argumentList[i].right(argumentList[i].length()-3).toInt(&ok); if (!ok) { - myProject->logError("Wrong timescale: -t:"); + myProject->errorString = "Wrong timescale: -t:"; return PRAGA_INVALID_COMMAND; } } @@ -1103,7 +1100,7 @@ int pragaShell(PragaProject* myProject) ry1 = argumentList[i].right(argumentList[i].length()-5).toInt(&ok); if (!ok) { - myProject->logError("Wrong reference start year: -ry1:"); + myProject->errorString = "Wrong reference start year: -ry1:"; return PRAGA_INVALID_COMMAND; } } @@ -1112,7 +1109,7 @@ int pragaShell(PragaProject* myProject) ry2 = argumentList[i].right(argumentList[i].length()-5).toInt(&ok); if (!ok) { - myProject->logError("Wrong reference end year: -ry2:"); + myProject->errorString = "Wrong reference end year: -ry2:"; return PRAGA_INVALID_COMMAND; } } @@ -1131,7 +1128,7 @@ int pragaShell(PragaProject* myProject) { if (argumentList.size() < 3) { - myProject->logError("Missing procedure name or date to save"); + myProject->errorString = "Missing procedure name or date to save"; return PRAGA_INVALID_COMMAND; } diff --git a/project/shell.cpp b/project/shell.cpp index 9230ddcc4..f8a4d927d 100644 --- a/project/shell.cpp +++ b/project/shell.cpp @@ -198,7 +198,7 @@ int cmdLoadDEM(Project* myProject, QList argumentList) { if (argumentList.size() < 2) { - myProject->logError("Missing DEM file name."); + myProject->errorString = "Missing DEM file name."; // TODO: USAGE return PRAGA_MISSING_FILE; } @@ -219,7 +219,7 @@ int cmdOpenDbPoint(Project* myProject, QList argumentList) { if (argumentList.size() < 2) { - myProject->logError("Missing db point name"); + myProject->errorString = "Missing db point name"; return PRAGA_INVALID_COMMAND; } @@ -238,7 +238,7 @@ int cmdLoadMeteoGrid(Project* myProject, QList argumentList) { if (argumentList.size() < 2) { - myProject->logError("Missing Grid file name."); + myProject->errorString = "Missing grid file name"; // TODO: USAGE return PRAGA_MISSING_FILE; } @@ -261,7 +261,7 @@ int cmdSetLogFile(Project* myProject, QList argumentList) { if (argumentList.size() < 2) { - myProject->logError("Missing Log file name."); + myProject->errorString = "Missing log file name"; // TODO: USAGE return PRAGA_INVALID_COMMAND; } @@ -281,6 +281,7 @@ int cmdSetLogFile(Project* myProject, QList argumentList) int cmdExportDailyDataCsv(Project* myProject, QList argumentList) { + // GA questa funzione scrive degli errori ed esce, ma ritorna sempre PRAGA_OK. e' giusto? QString outputPath = myProject->getProjectPath() + PATH_OUTPUT; if (argumentList.size() < 2)