Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/ARPA-SIMC/CRITERIA1D
Browse files Browse the repository at this point in the history
  • Loading branch information
EfthyC committed Dec 11, 2024
2 parents a289951 + 2291a06 commit b622751
Show file tree
Hide file tree
Showing 16 changed files with 237 additions and 137 deletions.
Binary file added DOC/CRITERIA1D_article.pdf
Binary file not shown.
2 changes: 1 addition & 1 deletion agrolib/commonDialogs/formSelection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ FormSelection::FormSelection(QList<QString> stringList_, QString title)

this->setWindowTitle(title);
QVBoxLayout* mainLayout = new QVBoxLayout;
this->resize(250, 100);
this->resize(300, 100);

QHBoxLayout *layoutOk = new QHBoxLayout;
QHBoxLayout *datasetLayout = new QHBoxLayout;
Expand Down
13 changes: 12 additions & 1 deletion agrolib/crop/landUnit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Crit3DLandUnit::Crit3DLandUnit()
description = "Default land use";
idCrop = "FALLOW";
idLandUse = "FALLOW";
landUseType = LANDUSE_FALLOW;

roughness = 0.05;
pond = 0.002;
Expand Down Expand Up @@ -48,7 +49,17 @@ bool loadLandUnitList(const QSqlDatabase &dbCrop, std::vector<Crit3DLandUnit> &l
landUnitList[i].name = query.value("name").toString();
landUnitList[i].description = query.value("description").toString();
landUnitList[i].idCrop = query.value("id_crop").toString();
landUnitList[i].idLandUse = query.value("id_landuse").toString();
landUnitList[i].idLandUse = query.value("id_landuse").toString().toUpper();

try
{
landUnitList[i].landUseType = MapLandUseFromString.at(landUnitList[i].idLandUse.toStdString());
}
catch (const std::out_of_range& outOfErrorStr)
{
errorStr = QString("%1 is not a valid landUse type" ).arg(landUnitList[i].idLandUse);
landUnitList[i].landUseType = LANDUSE_FALLOW;
}

landUnitList[i].roughness = query.value("roughness").toDouble();
landUnitList[i].pond = query.value("pond").toDouble();
Expand Down
19 changes: 19 additions & 0 deletions agrolib/crop/landUnit.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,26 @@

#include <QString>
#include <vector>
#include <map>

class QSqlDatabase;

enum landUseTypeList {LANDUSE_BARESOIL, LANDUSE_FALLOW, LANDUSE_HERBACEOUS, LANDUSE_HORTICULTURAL, LANDUSE_GRASS,
LANDUSE_ORCHARD, LANDUSE_FOREST, LANDUSE_URBAN, LANDUSE_ROAD, LANDUSE_WATERBODIES };

const std::map<std::string, landUseTypeList> MapLandUseFromString = {
{ "BARE", LANDUSE_BARESOIL },
{ "FALLOW", LANDUSE_FALLOW },
{ "HERBACEOUS", LANDUSE_HERBACEOUS },
{ "HORTI", LANDUSE_HORTICULTURAL },
{ "GRASS", LANDUSE_GRASS },
{ "ORCHARD", LANDUSE_ORCHARD },
{ "FOREST", LANDUSE_FOREST },
{ "URBAN", LANDUSE_URBAN },
{ "ROAD", LANDUSE_ROAD },
{ "WATER", LANDUSE_WATERBODIES },
};

class Crit3DLandUnit
{
public:
Expand All @@ -14,6 +32,7 @@
QString description;
QString idCrop;
QString idLandUse;
int landUseType;

double roughness; // Gauckler–Manning roughness coefficient [s m-1/3]
double pond; // surface pond (immobilized water) [m]
Expand Down
18 changes: 14 additions & 4 deletions agrolib/dbMeteoPoints/download.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -503,14 +503,18 @@ bool Download::downloadDailyData(const QDate &startDate, const QDate &endDate, c

if (idPoint != "" && flag.left(1) != "1" && flag.left(3) != "054")
{
value = NODATA;
if (flag.left(1) == "2")
value = fields[4].toDouble();
else
value = fields[3].toDouble();

idArkimet = fields[2].toInt();

if (idArkimet == PREC_ID)
if ((prec0024 && fields[0].mid(8,2) != "00") || (!prec0024 && fields[0].mid(8,2) != "08"))
continue;

value = fields[3].toDouble();

// conversion from average daily radiation to integral radiation
if (idArkimet == RAD_ID)
{
Expand Down Expand Up @@ -638,7 +642,7 @@ bool Download::downloadHourlyData(const QDate &startDate, const QDate &endDate,
_dbMeteo->queryString = "";

QString line, dateTime, idPoint, flag, varName;
QString idVariable, value, frequency;
QString idVariable, value, secondValue, frequency;
QList<QString> fields;
int i, idVarArkimet;

Expand Down Expand Up @@ -679,14 +683,20 @@ bool Download::downloadHourlyData(const QDate &startDate, const QDate &endDate,
if (isVarOk && fields[3] != "")
{
value = fields[3];
secondValue = fields[4];

// flag
flag = fields[6];
if (flag.left(1) != "1" && flag.left(3) != "054")
if (flag.left(1) != "1" && flag.left(1) != "2" && flag.left(3) != "054")
{
_dbMeteo->appendQueryHourly(dateTime, idPoint, idVariable, value, isFirstData);
isFirstData = false;
}
else if(flag.left(1) == "2")
{
_dbMeteo->appendQueryHourly(dateTime, idPoint, idVariable, secondValue, isFirstData);
isFirstData = false;
}
}
}
}
Expand Down
49 changes: 28 additions & 21 deletions agrolib/gis/gis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1520,7 +1520,7 @@ namespace gis

double resampleFactor = newGrid->header->cellSize / oldGrid.header->cellSize;

int row, col, tmpRow, tmpCol, nrValues, maxValues;
int row, col, tmpRow, tmpCol, nrValues;
gis::Crit3DPoint myLL, myUR;
std::vector<float> values;

Expand All @@ -1529,62 +1529,69 @@ namespace gis
for (row = 0; row < newGrid->header->nrRows; row++)
for (col = 0; col < newGrid->header->nrCols; col++)
{
// initialize
newGrid->value[row][col] = newGrid->header->flag;

float value = NODATA;

if (resampleFactor <= 1. || elab == aggrCenter)
{
double x, y;
newGrid->getXY(row, col, x, y);
oldGrid.getRowCol(x, y, tmpRow, tmpCol);
if (! gis::isOutOfGridRowCol(tmpRow, tmpCol, oldGrid))
{
value = oldGrid.value[tmpRow][tmpCol];
float tmpValue = oldGrid.value[tmpRow][tmpCol];
if (! isEqual(tmpValue, oldGrid.header->flag))
value = tmpValue;
}
}
else
{
double step = oldGrid.header->cellSize * 0.5;
int nrStep = floor(resampleFactor) + 1;
double step = newGrid->header->cellSize / nrStep;
double halfStep = step * 0.5;

double x0, y0;
newGrid->getXY(row, col, x0, y0);
myLL.utm.x = x0 - (newGrid->header->cellSize / 2) + step;
myLL.utm.y = y0 - (newGrid->header->cellSize / 2) + step;
myUR.utm.x = x0 + (newGrid->header->cellSize / 2) - step;
myUR.utm.y = y0 + (newGrid->header->cellSize / 2) - step;
myLL.utm.x = x0 - (newGrid->header->cellSize / 2) + halfStep;
myLL.utm.y = y0 - (newGrid->header->cellSize / 2) + halfStep;
myUR.utm.x = x0 + (newGrid->header->cellSize / 2) - halfStep;
myUR.utm.y = y0 + (newGrid->header->cellSize / 2) - halfStep;

values.clear();
maxValues = 0;

double x = myLL.utm.x;
while(x <= myUR.utm.x)
int maxNrValues = 0;
for (int i = 0; i < nrStep; i++)
{
double y = myLL.utm.y;
while(y <= myUR.utm.y)
double x = myLL.utm.x + step * i;
for (int j = 0; j < nrStep; j++)
{
maxValues++;
double y = myLL.utm.y + step * j;
float tmpValue = gis::getValueFromXY(oldGrid, x, y);
if (! isEqual(tmpValue, oldGrid.header->flag))
{
values.push_back(tmpValue);
}

y += step;
maxNrValues++;
}
x += step;
}
nrValues = int(values.size());

if (maxValues > 0)
if (maxNrValues > 0)
{
if ((float(nrValues) / float(maxValues)) > nodataRatioThreshold)
if ((float(nrValues) / float(maxNrValues)) > nodataRatioThreshold)
{
if (elab == aggrAverage)
value = statistics::mean(values);
else if (elab == aggrMedian)
value = sorting::percentile(values, nrValues, 50, true);
else if (elab == aggrPrevailing)
value = prevailingValue(values);
{
int nrMissing = maxNrValues - nrValues;
if (nrMissing < nrValues)
{
value = prevailingValue(values);
}
}
}
}
}
Expand Down
Loading

0 comments on commit b622751

Please sign in to comment.