Skip to content

Commit

Permalink
Merge commit 'bd241202c9daf787fe8c4bfdb990e43ace95c765'
Browse files Browse the repository at this point in the history
  • Loading branch information
ftomei committed Jan 10, 2025
2 parents f0fc990 + bd24120 commit f030e79
Show file tree
Hide file tree
Showing 44 changed files with 1,041 additions and 976 deletions.
13 changes: 8 additions & 5 deletions agrolib/climate/climate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -897,6 +897,7 @@ float loadHourlyVarSeries_SaveOutput(Crit3DMeteoPointsDbHandler *meteoPointsDbHa
int nrValidValues = 0;

// fills the missing initial output data
firstDateTimeDB.setTimeSpec(Qt::UTC);
int nrMissingHours = firstTime.secsTo(firstDateTimeDB) / 3600;
for (int i = 1; i <= nrMissingHours; i++)
{
Expand All @@ -919,7 +920,8 @@ float loadHourlyVarSeries_SaveOutput(Crit3DMeteoPointsDbHandler *meteoPointsDbHa
}

// fills the missing final output data
QDateTime lastDateTimeDB = firstDateTimeDB.addSecs(hourlyValues.size() * 3600);
int nrDataHours = int(hourlyValues.size()) -1;
QDateTime lastDateTimeDB = firstDateTimeDB.addSecs(nrDataHours * 3600);
nrMissingHours = lastDateTimeDB.secsTo(lastTime) / 3600;
for (int i = 1; i <= nrMissingHours; i++)
{
Expand Down Expand Up @@ -1074,6 +1076,7 @@ float loadHourlyVarSeries(Crit3DMeteoPointsDbHandler* meteoPointsDbHandler,
}

QDateTime currentDateTime = firstDateTimeDB;
currentDateTime.setTimeSpec(Qt::UTC);
for (unsigned int i = 0; i < hourlyValues.size(); i++)
{
quality::qualityType qualityT = qualityCheck.syntacticQualitySingleValue(variable, hourlyValues[i]);
Expand Down Expand Up @@ -2198,8 +2201,8 @@ bool preElaboration(Crit3DMeteoPointsDbHandler* meteoPointsDbHandler, Crit3DMete
case dailyLeafWetness:
{
if (loadHourlyVarSeries(meteoPointsDbHandler, meteoGridDbHandler, meteoPoint, isMeteoGrid, leafWetness,
QDateTime(startDate,QTime(1,0,0),Qt::UTC),
QDateTime(endDate.addDays(1),QTime(0,0,0),Qt::UTC), myError) > 0)
QDateTime(startDate, QTime(1,0,0), Qt::UTC),
QDateTime(endDate.addDays(1), QTime(0,0,0), Qt::UTC), myError) > 0)
{
myResult = elaborateDailyAggregatedVar(dailyLeafWetness, *meteoPoint, outputValues, percValue, meteoSettings);
}
Expand All @@ -2208,8 +2211,8 @@ bool preElaboration(Crit3DMeteoPointsDbHandler* meteoPointsDbHandler, Crit3DMete
case dailyTemperatureHoursAbove:
{
if (loadHourlyVarSeries(meteoPointsDbHandler, meteoGridDbHandler, meteoPoint, isMeteoGrid, airTemperature,
QDateTime(startDate,QTime(1,0,0),Qt::UTC),
QDateTime(endDate.addDays(1),QTime(0,0,0),Qt::UTC), myError) > 0)
QDateTime(startDate, QTime(1,0,0), Qt::UTC),
QDateTime(endDate.addDays(1), QTime(0,0,0), Qt::UTC), myError) > 0)
{
myResult = elaborateDailyAggregatedVar(dailyTemperatureHoursAbove, *meteoPoint, outputValues, percValue, meteoSettings);
}
Expand Down
2 changes: 1 addition & 1 deletion agrolib/climate/crit3dElabList.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include <QString>
#include <QDate>
#include <QDebug>

#include "crit3dElabList.h"
#include "commonConstants.h"
#include "climate.h"


Crit3DElabList::Crit3DElabList()
Expand Down
4 changes: 1 addition & 3 deletions agrolib/crit3dDate/crit3dDate.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#ifndef CRIT3DDATE_H
#define CRIT3DDATE_H

#ifndef _STRING_
#include <string>
#endif
#include <string>

#ifndef HOUR_SECONDS
#define HOUR_SECONDS 3600
Expand Down
11 changes: 7 additions & 4 deletions agrolib/crop/root.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,12 +261,13 @@ namespace root
lunetteDensity.resize(nrLayersWithRoot*2);

double sinAlfa, cosAlfa, alfa;
double halfPI = PI / 2.;
for (i = 0; i < nrLayersWithRoot; i++)
{
sinAlfa = 1 - double(i+1) / double(nrLayersWithRoot);
cosAlfa = MAXVALUE(sqrt(1 - pow(sinAlfa,2)), 0.0001);
cosAlfa = MAXVALUE(sqrt(1 - pow(sinAlfa, 2)), 0.0001);
alfa = atan(sinAlfa/cosAlfa);
lunette[i] = ((PI/2) - alfa - sinAlfa*cosAlfa) / PI;
lunette[i] = (halfPI - alfa - sinAlfa*cosAlfa) / PI;
}

lunetteDensity[0] = lunette[0];
Expand All @@ -282,19 +283,21 @@ namespace root
LiMin = -log(0.2) / nrLayersWithRoot;
Limax = -log(0.05) / nrLayersWithRoot;

// TODO verify
k = LiMin + (Limax - LiMin) * (shapeFactor-1);
k = LiMin + (Limax - LiMin) * (shapeFactor-1); // TODO verify

rootDensitySum = 0 ;
for (i = 0; i < (2*nrLayersWithRoot); i++)
{
lunetteDensity[i] *= exp(-k*(i+0.5));
rootDensitySum += lunetteDensity[i];
}

// normalize
for (i = 0; i < (2*nrLayersWithRoot); i++)
{
lunetteDensity[i] /= rootDensitySum;
}

for (i = 0; i < totalLayers; i++)
{
densityThinLayers[i] = 0;
Expand Down
81 changes: 40 additions & 41 deletions agrolib/dbMeteoGrid/dbMeteoGrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2445,7 +2445,7 @@ std::vector<float> Crit3DMeteoGridDbHandler::loadGridDailyVar(const QString &met
int varCode = getDailyVarCode(variable);
if (varCode == NODATA)
{
errorStr = "Variable not existing";
errorStr = "The variable does not exist in this meteo grid";
return dailyVarList;
}

Expand Down Expand Up @@ -2529,7 +2529,7 @@ std::vector<float> Crit3DMeteoGridDbHandler::exportAllDataVar(QString *errorStr,
idVar = getDailyVarCode(variable);
if (idVar == NODATA)
{
*errorStr = "Variable not existing";
*errorStr = "The variable does not exist in this meteo grid";
return allDataVarList;
}
tableName = _tableDaily.prefix + id + _tableDaily.postFix;
Expand All @@ -2543,7 +2543,7 @@ std::vector<float> Crit3DMeteoGridDbHandler::exportAllDataVar(QString *errorStr,
idVar = getHourlyVarCode(variable);
if (idVar == NODATA)
{
*errorStr = "Variable not existing";
*errorStr = "The variable does not exist in this meteo grid";
return allDataVarList;
}
tableName = _tableHourly.prefix + id + _tableHourly.postFix;
Expand Down Expand Up @@ -2615,7 +2615,7 @@ std::vector<float> Crit3DMeteoGridDbHandler::loadGridDailyVarFixedFields(const Q

if (varCode == NODATA)
{
errorStr = "Variable not existing";
errorStr = "The variable does not exist in this meteo grid";
return dailyVarList;
}

Expand Down Expand Up @@ -2700,7 +2700,7 @@ std::vector<float> Crit3DMeteoGridDbHandler::loadGridHourlyVar(meteoVariable var
int varCode = getHourlyVarCode(variable);
if (varCode == NODATA)
{
errorStr = "Variable not existing";
errorStr = "The variable does not exist in this meteo grid";
return hourlyVarList;
}

Expand All @@ -2711,54 +2711,53 @@ std::vector<float> Crit3DMeteoGridDbHandler::loadGridHourlyVar(meteoVariable var
}

QString statement = QString("SELECT * FROM `%1` WHERE VariableCode = '%2' AND `%3` >= '%4' AND `%3` <= '%5' ORDER BY `%3`")
.arg(tableH).arg(varCode).arg(_tableHourly.fieldTime,
firstTime.toString("yyyy-MM-dd hh:mm"), lastTime.toString("yyyy-MM-dd hh:mm"));
.arg(tableH).arg(varCode)
.arg(_tableHourly.fieldTime, firstTime.toString("yyyy-MM-dd hh:mm"), lastTime.toString("yyyy-MM-dd hh:mm"));
if(! qry.exec(statement) )
{
errorStr = qry.lastError().text();
return hourlyVarList;
}
else

while (qry.next())
{
while (qry.next())
if (firstRow)
{
if (firstRow)
if (! getValue(qry.value(_tableHourly.fieldTime), &firstDateTimeDB))
{
if (! getValue(qry.value(_tableHourly.fieldTime), &firstDateTimeDB))
{
errorStr = "Missing fieldTime";
return hourlyVarList;
}
errorStr = "Missing fieldTime";
return hourlyVarList;
}

if (! getValue(qry.value("Value"), &value))
{
errorStr = "Missing Value";
}
hourlyVarList.push_back(value);
previousDateTime = firstDateTimeDB;
firstRow = false;
if (! getValue(qry.value("Value"), &value))
{
errorStr = "Missing Value";
}
else
hourlyVarList.push_back(value);
previousDateTime = firstDateTimeDB;
firstRow = false;
}
else
{
if (! getValue(qry.value(_tableHourly.fieldTime), &dateTime))
{
if (! getValue(qry.value(_tableHourly.fieldTime), &dateTime))
{
errorStr = "Missing fieldTime";
return hourlyVarList;
}

int missingHours = previousDateTime.secsTo(dateTime) / 3600 - 1;
for (int i = 1; i <= missingHours; i++)
{
hourlyVarList.push_back(NODATA);
}
errorStr = "Missing fieldTime";
return hourlyVarList;
}

if (! getValue(qry.value("Value"), &value))
{
errorStr = "Missing Value";
}
int missingHours = previousDateTime.secsTo(dateTime) / 3600 - 1;
for (int i = 1; i <= missingHours; i++)
{
hourlyVarList.push_back(NODATA);
}

hourlyVarList.push_back(value);
previousDateTime = dateTime;
if (! getValue(qry.value("Value"), &value))
{
errorStr = "Missing Value";
}

hourlyVarList.push_back(value);
previousDateTime = dateTime;
}
}

Expand All @@ -2784,7 +2783,7 @@ std::vector<float> Crit3DMeteoGridDbHandler::loadGridHourlyVarFixedFields(meteoV

if (varCode == NODATA)
{
errorStr = "Variable not existing";
errorStr = "The variable does not exist in this meteo grid";
return hourlyVarList;
}

Expand Down
3 changes: 1 addition & 2 deletions agrolib/gis/geoMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@
*/


#include "commonConstants.h"
#include "geoMap.h"
#include "math.h"
#include <math.h>

namespace gis
{
Expand Down
12 changes: 6 additions & 6 deletions agrolib/gis/gis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -598,10 +598,10 @@ namespace gis
{
// è possibile sapere in quale cella (row,col) si trova la stazione?
std::vector<float> distance(stations.size());
for (int i=0;i<stations.size();i++)
for (int i=0; i < int(stations.size()); i++)
{
distance[i] = (float)(stations[i][0] - cells[0][0])*(stations[i][0] - cells[0][0])+(stations[i][1] - cells[0][1])*(stations[i][1] - cells[0][1]);
for (int j=1;j<cells[i].size();j++)
for (int j=1; j < int(cells[i].size()); j++)
{
distance[i] = MINVALUE(distance[i],(stations[i][0] - cells[j][0])*(stations[i][0] - cells[j][0])+(stations[i][1] - cells[j][1])*(stations[i][1] - cells[j][1]));
}
Expand All @@ -615,10 +615,10 @@ namespace gis
{
// è possibile sapere in quale cella (row,col) si trova la stazione?
std::vector<int> distance(stations.size());
for (int i=0; i<stations.size(); i++)
for (int i=0; i < int(stations.size()); i++)
{
distance[i] = abs(stations[i][0] - cells[0][0])+abs(stations[i][1] - cells[0][1]);
for (int j=1;j<cells[i].size();j++)
distance[i] = abs(stations[i][0] - cells[0][0]) + abs(stations[i][1] - cells[0][1]);
for (int j=1; j < int(cells[i].size()); j++)
{
distance[i] = MINVALUE(distance[i],abs(stations[i][0] - cells[j][0])+abs(stations[i][1] - cells[j][1]));
}
Expand Down Expand Up @@ -1547,7 +1547,7 @@ namespace gis
}
else
{
int nrStep = floor(resampleFactor) + 1;
int nrStep = int(floor(resampleFactor)) + 1;
double step = newGrid->header->cellSize / nrStep;
double halfStep = step * 0.5;

Expand Down
9 changes: 3 additions & 6 deletions agrolib/gis/gis.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
#ifndef GIS_H
#define GIS_H

#ifndef _VECTOR_
#include <vector>
#endif
#ifndef _STRING_
#include <string>
#endif
#include <vector>
#include <string>

#ifndef CRIT3DCOLOR_H
#include "color.h"
#endif
Expand Down
1 change: 0 additions & 1 deletion agrolib/gis/gisIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#include <sstream>
#include <fstream>
#include <math.h>
#include <algorithm>

#include "gis.h"

Expand Down
5 changes: 2 additions & 3 deletions agrolib/graphics/mapGraphicsRasterObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,9 @@ gis::Crit3DLatLonHeader RasterObject::getLatLonHeader() const
* \brief getRasterMaxSize
* \return max of raster width and height (decimal degree)
*/
float RasterObject::getRasterMaxSize()
double RasterObject::getRasterMaxSize()
{
return float(MAXVALUE(latLonHeader.nrRows * latLonHeader.dy,
latLonHeader.nrCols * latLonHeader.dx));
return MAXVALUE(latLonHeader.nrRows * latLonHeader.dy, latLonHeader.nrCols * latLonHeader.dx);
}


Expand Down
7 changes: 6 additions & 1 deletion agrolib/graphics/mapGraphicsRasterObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,12 @@
bool initializeUTM(gis::Crit3DRasterGrid* myRaster, const gis::Crit3DGisSettings& gisSettings, bool isGrid_);
bool initializeLatLon(gis::Crit3DRasterGrid* myRaster, const gis::Crit3DGisSettings& gisSettings,
const gis::Crit3DLatLonHeader& latLonHeader, bool isGrid_);
float getRasterMaxSize();

// degrees
double getRasterMaxSize();
double getSizeX() { return latLonHeader.nrCols * latLonHeader.dx; }
double getSizeY() { return latLonHeader.nrRows * latLonHeader.dy; }

gis::Crit3DGeoPoint* getRasterCenter();

void setRaster(gis::Crit3DRasterGrid* rasterPtr) { rasterPointer = rasterPtr; }
Expand Down
6 changes: 3 additions & 3 deletions agrolib/graphics/mapGraphicsRasterUtm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,13 +212,13 @@ Position RasterUtmObject::getRasterCenter()
* \brief getRasterMaxSize
* \return the maximum size of the raster in decimal degrees (width or height)
*/
float RasterUtmObject::getRasterMaxSize()
double RasterUtmObject::getRasterMaxSize()
{
return float(MAXVALUE(_latLonHeader.nrRows * _latLonHeader.dy,
_latLonHeader.nrCols * _latLonHeader.dx));
return MAXVALUE(_latLonHeader.nrRows * _latLonHeader.dy, _latLonHeader.nrCols * _latLonHeader.dx);
}



/*!
* \brief getCurrentWindow
* \return the currently displayed raster window (row, col)
Expand Down
15 changes: 10 additions & 5 deletions agrolib/graphics/mapGraphicsRasterUtm.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,22 @@
bool initialize(gis::Crit3DRasterGrid* rasterPtr, const gis::Crit3DGisSettings& gisSettings);

void setDrawing(bool value) {_isDrawing = value;}
void setColorLegend(ColorLegend* colorLegendPtr) {_colorLegendPointer = colorLegendPtr;}
void setRaster(gis::Crit3DRasterGrid* rasterPtr) {_rasterPointer = rasterPtr;}
void setColorLegend(ColorLegend* colorLegendPtr) { _colorLegendPointer = colorLegendPtr; }
void setRaster(gis::Crit3DRasterGrid* rasterPtr) { _rasterPointer = rasterPtr; }

gis::Crit3DRasterGrid* getRasterPointer() {return _rasterPointer;}
gis::Crit3DRasterGrid* getRasterPointer() { return _rasterPointer; }

float getValue(Position& pos);
float getRasterMaxSize();

Position getCurrentCenter();
Position getRasterCenter();
QPointF getPixel(const QPointF &geoPoint);
gis::Crit3DLatLonHeader getLatLonHeader() {return _latLonHeader;}
gis::Crit3DLatLonHeader getLatLonHeader() { return _latLonHeader; }

// degrees
double getRasterMaxSize();
double getSizeX() { return _latLonHeader.nrCols * _latLonHeader.dx; }
double getSizeY() { return _latLonHeader.nrRows * _latLonHeader.dy; }

void updateCenter();

Expand Down
Loading

0 comments on commit f030e79

Please sign in to comment.