Skip to content

Commit

Permalink
Merge commit 'c39da3cf4e4154d3a0046ceca85e22bfdf46f183'
Browse files Browse the repository at this point in the history
  • Loading branch information
ftomei committed Jan 4, 2024
2 parents d6c664e + c39da3c commit d1faca3
Show file tree
Hide file tree
Showing 12 changed files with 344 additions and 204 deletions.
12 changes: 5 additions & 7 deletions agrolib/climate/climate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1835,12 +1835,11 @@ bool elaborateDailyAggrVarFromDailyFromStartDate(meteoVariable myVar, Crit3DMete
return true;
else
return false;

}


bool aggregatedHourlyToDaily(meteoVariable myVar, Crit3DMeteoPoint* meteoPoint, Crit3DDate dateIni, Crit3DDate dateFin, Crit3DMeteoSettings *meteoSettings)
{

Crit3DDate date;
std::vector <float> values;
float value, dailyValue;
Expand Down Expand Up @@ -4974,6 +4973,7 @@ bool monthlyAggregateDataGrid(Crit3DMeteoGridDbHandler* meteoGridDbHandler, QDat
meteoPointTemp->initializeObsDataM(nrMonths, firstDate.month(), firstDate.year());
// copy id to MPTemp
meteoPointTemp->id = meteoGridDbHandler->meteoGrid()->meteoPointPointer(row,col)->id;
meteoPointTemp->latitude = meteoGridDbHandler->meteoGrid()->meteoPointPointer(row,col)->latitude;
// meteoPointTemp should be init
meteoPointTemp->nrObsDataDaysH = 0;
meteoPointTemp->nrObsDataDaysD = 0;
Expand Down Expand Up @@ -5008,13 +5008,12 @@ bool monthlyAggregateDataGrid(Crit3DMeteoGridDbHandler* meteoGridDbHandler, QDat
return dataSaved;
}


int computeAnnualSeriesOnPointFromDaily(QString *myError, Crit3DMeteoPointsDbHandler* meteoPointsDbHandler, Crit3DMeteoGridDbHandler* meteoGridDbHandler,
Crit3DMeteoPoint* meteoPointTemp, Crit3DClimate* clima, bool isMeteoGrid, bool isAnomaly, Crit3DMeteoSettings* meteoSettings,
std::vector<float> &outputValues, bool dataAlreadyLoaded)
{
int validYears = 0;
meteoComputation elabMeteoComp = getMeteoCompFromString(MapMeteoComputation, clima->elab1().toStdString());

if (clima->param1IsClimate())
{
clima->param1();
Expand Down Expand Up @@ -5288,11 +5287,10 @@ void computeClimateOnDailyData(Crit3DMeteoPoint meteoPoint, meteoVariable var, Q
}
}


void setMpValues(Crit3DMeteoPoint meteoPointGet, Crit3DMeteoPoint* meteoPointSet, QDate myDate, meteoVariable myVar, Crit3DMeteoSettings* meteoSettings)
{

bool automaticETP = meteoSettings->getAutomaticET0HS();
bool automaticTmed = meteoSettings->getAutomaticTavg();
Crit3DQuality qualityCheck;

switch(myVar)
Expand Down Expand Up @@ -5406,9 +5404,9 @@ void setMpValues(Crit3DMeteoPoint meteoPointGet, Crit3DMeteoPoint* meteoPointSet
break;
}
}

}


meteoComputation getMeteoCompFromString(std::map<std::string, meteoComputation> map, std::string value)
{

Expand Down
7 changes: 5 additions & 2 deletions agrolib/criteriaOutput/criteriaAggregationVariable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ bool CriteriaAggregationVariable::parserAggregationVariable(QString fileName, QS
error = "missing output variable";
return false;
}

// remove whitespace
outputVarName.push_back(items[pos].toUpper().trimmed());
if (outputVarName.isEmpty())
Expand All @@ -58,9 +59,10 @@ bool CriteriaAggregationVariable::parserAggregationVariable(QString fileName, QS
error = "missing input field (shape)";
return false;
}

// remove whitespace
inputField.push_back(items[pos].toUpper().trimmed());
if (inputField.isEmpty())
inputFieldName.push_back(items[pos].toUpper().trimmed());
if (inputFieldName.isEmpty())
{
error = "missing input field";
return false;
Expand All @@ -72,6 +74,7 @@ bool CriteriaAggregationVariable::parserAggregationVariable(QString fileName, QS
error = "missing computation";
return false;
}

// remove whitespace
aggregationType.push_back(items[pos].toUpper().trimmed());
if (aggregationType.isEmpty())
Expand Down
2 changes: 1 addition & 1 deletion agrolib/criteriaOutput/criteriaAggregationVariable.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
{
public:
QList<QString> outputVarName;
QList<QString> inputField;
QList<QString> inputFieldName;
QList<QString> aggregationType;

CriteriaAggregationVariable();
Expand Down
8 changes: 4 additions & 4 deletions agrolib/criteriaOutput/criteriaOutputElaboration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ int writeCsvOutputUnit(QString idCase, QString idCropClass, QSqlDatabase& dbData
resultVector.clear();
QString varName = outputVariable.varName[i];
QString computation = outputVariable.computation[i];
if (!computation.isEmpty())
if (! computation.isEmpty())
{
// nrDays is required, because the computation should be done between values into interval referenceDate+-nrDays
if (outputVariable.nrDays[i].isEmpty())
Expand Down Expand Up @@ -506,10 +506,9 @@ int writeCsvOutputUnit(QString idCase, QString idCropClass, QSqlDatabase& dbData
previousFirstDate, previousLastDate, irriRatio, resultVector, errorStr);
if (queryResult == ERROR_DB_INCOMPLETE_DATA)
{
// only first year can be incomplete, otherwise the comparison is not valid and can be terminated
if (year != climateFirstDate.year())
// only first and last years can be incomplete, otherwise the comparison is not valid and can be terminated
if (year != climateFirstDate.year() && year != climateLastDate.year())
{
result = NODATA;
skip = true;
break;
}
Expand All @@ -526,6 +525,7 @@ int writeCsvOutputUnit(QString idCase, QString idCropClass, QSqlDatabase& dbData
}
year = year+1;
}

resultVector.clear();
if (skip)
{
Expand Down
76 changes: 49 additions & 27 deletions agrolib/criteriaOutput/criteriaOutputProject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ int CriteriaOutputProject::precomputeDtx()
logger.writeInfo("Compute dtx...");

QString idCase;
int step = compUnitList.size() * 0.01;
int step = MAXVALUE(compUnitList.size() * 0.01, 1);

for (unsigned int i=0; i < compUnitList.size(); i++)
{
Expand Down Expand Up @@ -611,8 +611,8 @@ int CriteriaOutputProject::createMaps()
logger.writeInfo("MAPS");

// parser csv file mapListFileName
QList<QString> inputField;
QList<QString> outputName;
QList<QString> inputFieldName;
QList<QString> outputFileName;
QList<QString> paletteFileName;
QFile mapList(mapListFileName);
if ( !mapList.open(QFile::ReadOnly | QFile::Text) )
Expand All @@ -623,66 +623,88 @@ int CriteriaOutputProject::createMaps()
else
{
QTextStream in(&mapList);
//skip header
// skip header
QString line = in.readLine();

while (!in.atEnd())
while (! in.atEnd())
{
line = in.readLine();
QList<QString> items = line.split(",");
if (items.size() < REQUIREDMAPLISTCSVINFO)

if (! mapPalettePath.isEmpty())
{
projectError = "invalid line in map list:\n" + line + "\n"
+ "Required input field, output file name, palette file name.";
return ERROR_SETTINGS_MISSINGDATA;
if (items.size() < 3)
{
projectError = "invalid line in map list:\n" + line + "\n"
+ "Required: input field name, output file name, palette file name.";
return ERROR_SETTINGS_MISSINGDATA;
}
}
else
{
if (items.size() < 2)
{
projectError = "invalid line in map list:\n" + line + "\n"
+ "Required: input field name, output file name.";
return ERROR_SETTINGS_MISSINGDATA;
}
}

// input field (remove whitespace)
inputField.push_back(items[0].toUpper().trimmed());
if (inputField.last().isEmpty())
inputFieldName.push_back(items[0].toUpper().trimmed());
if ( inputFieldName.last().isEmpty() )
{
projectError = "missing shape input field in line:\n" + line;
return ERROR_SETTINGS_MISSINGDATA;
}

// output file name (remove whitespace)
outputName.push_back(items[1].toUpper().trimmed());
if (outputName.last().isEmpty())
// output file (remove whitespace)
outputFileName.push_back(items[1].toUpper().trimmed());
if ( outputFileName.last().isEmpty() )
{
projectError = "missing output map name in line:\n" + line;
return ERROR_SETTINGS_MISSINGDATA;
}

// palette file name (remove whitespace)
paletteFileName.push_back(items[2].toUpper().trimmed());
if (paletteFileName.last().isEmpty())
if (! mapPalettePath.isEmpty())
{
projectError = "missing palette file name in line:\n" + line;
return ERROR_SETTINGS_MISSINGDATA;
// palette file name (remove whitespace)
paletteFileName.push_back(items[2].toUpper().trimmed());
if ( paletteFileName.last().isEmpty() )
{
projectError = "missing palette file name in line:\n" + line;
return ERROR_SETTINGS_MISSINGDATA;
}
}
}
}

int rasterOK = 0;

for (int i=0; i < inputField.size(); i++)
for (int i=0; i < inputFieldName.size(); i++)
{
QString mapName = outputShapeFilePath + "/" + outputName[i]+ "." + mapFormat;
QString paletteName = mapPalettePath + "/" + paletteFileName[i];
QString mapName = outputShapeFilePath + "/" + outputFileName[i]+ "." + mapFormat;

QString paletteName = "";
if (! mapPalettePath.isEmpty())
{
paletteName = mapPalettePath + "/" + paletteFileName[i];
}

logger.writeInfo("Write map: " + mapName);
if (shapeToRaster(outputShapeFileName, inputField[i], mapCellSize, mapProjection, mapName, paletteName, projectError))
if (shapeToRaster(outputShapeFileName, inputFieldName[i], mapCellSize, mapProjection, mapName, paletteName, projectError))
{
rasterOK = rasterOK + 1;
}
}

if (rasterOK == inputField.size())
if (rasterOK == inputFieldName.size())
{
return CRIT1D_OK;
}
else
{
int nRasterError = inputField.size() - rasterOK;
int nRasterError = inputFieldName.size() - rasterOK;
projectError = QString::number(nRasterError) + " invalid raster - " + projectError;
return ERROR_MAPS;
}
Expand Down Expand Up @@ -828,13 +850,13 @@ int CriteriaOutputProject::createAggregationFile()
if (aggregationVariable.aggregationType[i] == "MAJORITY")
{
isOk = zonalStatisticsShapeMajority(shapeRef, shapeVal, matrix, vectorNull,
aggregationVariable.inputField[i].toStdString(),
aggregationVariable.inputFieldName[i].toStdString(),
aggregationVariable.outputVarName[i].toStdString(),
threshold, error);
}
else
{
isOk = zonalStatisticsShape(shapeRef, shapeVal, matrix, vectorNull, aggregationVariable.inputField[i].toStdString(),
isOk = zonalStatisticsShape(shapeRef, shapeVal, matrix, vectorNull, aggregationVariable.inputFieldName[i].toStdString(),
aggregationVariable.outputVarName[i].toStdString(),
aggregationVariable.aggregationType[i].toStdString(),
threshold, error);
Expand Down
2 changes: 0 additions & 2 deletions agrolib/criteriaOutput/criteriaOutputProject.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
#include "shapeHandler.h"
#include "crit3dDate.h"

#define REQUIREDMAPLISTCSVINFO 3

#define ERROR_MISSINGPARAMETERS -900
#define ERROR_WRONGPARAMETER -901

Expand Down
Loading

0 comments on commit d1faca3

Please sign in to comment.