Skip to content

Commit

Permalink
Merge commit 'a8be0927229a9a06804fc841d68e522a6545c838'
Browse files Browse the repository at this point in the history
  • Loading branch information
ftomei committed Jan 22, 2025
2 parents f030e79 + a8be092 commit da6f78d
Show file tree
Hide file tree
Showing 23 changed files with 468 additions and 95 deletions.
16 changes: 14 additions & 2 deletions agrolib/commonDialogs/formSelectionSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ FormSelectionSource::FormSelectionSource()

gridButton = new QRadioButton(tr("Meteo Grid"));
pointButton =new QRadioButton(tr("Meteo Points"));
interpolationButton =new QRadioButton(tr("Interpolation Raster"));

QHBoxLayout *sourceLayout = new QHBoxLayout;
sourceLayout->addWidget(gridButton);
sourceLayout->addWidget(pointButton);
sourceLayout->addWidget(interpolationButton);


QGroupBox *sourceGroupBox = new QGroupBox("Source");
sourceGroupBox->setLayout(sourceLayout);
Expand All @@ -39,7 +42,7 @@ void FormSelectionSource::done(int res)
{
if (res == QDialog::Accepted) // ok
{
if (!pointButton->isChecked() && !gridButton->isChecked())
if (!pointButton->isChecked() && !gridButton->isChecked() && !interpolationButton->isChecked())
{
QMessageBox::information(nullptr, "Missing source selection.", "Please choose a data source.");
return;
Expand All @@ -54,6 +57,12 @@ void FormSelectionSource::done(int res)
}
}

void FormSelectionSource::disableRadioButtons(bool pointDisable, bool gridDisable, bool interpolationDisable)
{
pointButton->setCheckable(!pointDisable);
gridButton->setCheckable(!gridDisable);
interpolationButton->setCheckable(!interpolationDisable);
}

int FormSelectionSource::getSourceSelectionId()
{
Expand All @@ -65,9 +74,12 @@ int FormSelectionSource::getSourceSelectionId()
{
return 2;
}
else if (interpolationButton->isChecked())
{
return 3;
}
else
{
return NODATA;
}
}

2 changes: 2 additions & 0 deletions agrolib/commonDialogs/formSelectionSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@
FormSelectionSource();

int getSourceSelectionId();
void disableRadioButtons(bool pointDisable, bool gridDisable, bool interpolationDisable);

private:
QRadioButton* pointButton;
QRadioButton* gridButton;
QRadioButton* interpolationButton;

void done(int res);
};
Expand Down
16 changes: 12 additions & 4 deletions agrolib/dbMeteoGrid/dbMeteoGrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3427,7 +3427,9 @@ bool Crit3DMeteoGridDbHandler::saveGridData(QString *errorStr, QDateTime firstTi
if (lastTime.time().hour() == 0) lastDate = lastDate.addDays(-1);

for (int row = 0; row < gridStructure().header().nrRows; row++)
{
for (int col = 0; col < gridStructure().header().nrCols; col++)
{
if (meteoGrid()->getMeteoPointActiveId(row, col, &id))
{
if (! gridStructure().isFixedFields())
Expand All @@ -3441,6 +3443,8 @@ bool Crit3DMeteoGridDbHandler::saveGridData(QString *errorStr, QDateTime firstTi
if (isDaily) saveCellGridDailyDataFF(errorStr, QString::fromStdString(id), row, col, firstTime.date(), lastDate, meteoSettings);
}
}
}
}

return true;
}
Expand Down Expand Up @@ -3506,7 +3510,7 @@ bool Crit3DMeteoGridDbHandler::saveCellGridHourlyData(QString *errorStr, QString
QString statement = QString("CREATE TABLE IF NOT EXISTS `%1` "
"(`%2` datetime, VariableCode tinyint(3) UNSIGNED, Value float(6,1), PRIMARY KEY(`%2`,VariableCode))").arg(tableH, _tableHourly.fieldTime);

if( !qry.exec(statement) )
if(! qry.exec(statement) )
{
*errorStr = qry.lastError().text();
return false;
Expand All @@ -3516,6 +3520,7 @@ bool Crit3DMeteoGridDbHandler::saveCellGridHourlyData(QString *errorStr, QString
statement = QString(("REPLACE INTO `%1` VALUES")).arg(tableH);

foreach (meteoVariable meteoVar, meteoVariableList)
{
if (getVarFrequency(meteoVar) == hourly)
{
for (QDateTime myTime = firstTime; myTime <= lastTime; myTime = myTime.addSecs(3600))
Expand All @@ -3528,10 +3533,11 @@ bool Crit3DMeteoGridDbHandler::saveCellGridHourlyData(QString *errorStr, QString
statement += QString(" ('%1','%2',%3),").arg(myTime.toString("yyyy-MM-dd hh:mm")).arg(varCode).arg(valueS);
}
}
}

statement = statement.left(statement.length() - 1);

if( !qry.exec(statement) )
if(! qry.exec(statement))
{
*errorStr = qry.lastError().text();
return false;
Expand Down Expand Up @@ -3562,6 +3568,7 @@ bool Crit3DMeteoGridDbHandler::saveCellGridHourlyDataEnsemble(QString *errorStr,
statement = QString(("REPLACE INTO `%1` (%2, VariableCode, Value, MemberNr) VALUES ")).arg(tableH, _tableHourly.fieldTime);

foreach (meteoVariable meteoVar, meteoVariableList)
{
if (getVarFrequency(meteoVar) == hourly)
{
for (QDateTime myTime = firstTime; myTime <= lastTime; myTime = myTime.addSecs(3600))
Expand All @@ -3574,10 +3581,11 @@ bool Crit3DMeteoGridDbHandler::saveCellGridHourlyDataEnsemble(QString *errorStr,
statement += QString(" ('%1','%2',%3,'%4'),").arg(myTime.toString("yyyy-MM-dd hh:mm")).arg(varCode).arg(valueS).arg(memberNr);
}
}
}

statement = statement.left(statement.length() - 1);

if( !qry.exec(statement) )
if(! qry.exec(statement))
{
*errorStr = qry.lastError().text();
return false;
Expand All @@ -3587,13 +3595,13 @@ bool Crit3DMeteoGridDbHandler::saveCellGridHourlyDataEnsemble(QString *errorStr,
return true;
}


bool Crit3DMeteoGridDbHandler::saveCellGridHourlyDataFF(QString *errorStr, QString meteoPointID, int row, int col, QDateTime firstTime, QDateTime lastTime)
{
QSqlQuery qry(_db);
QString tableH = _tableHourly.prefix + meteoPointID + _tableHourly.postFix;
QString tableFields;


for (unsigned int i=0; i < _tableHourly.varcode.size(); i++)
{
QString var = _tableHourly.varcode[i].varPragaName;
Expand Down
24 changes: 5 additions & 19 deletions agrolib/gis/color.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ bool Crit3DColorScale::classify()
nrIntervals = MAXVALUE(_nrKeyColors -1, 1);
nrStep = _nrColors / nrIntervals;

_nrColors = nrStep * nrIntervals;
color.resize(_nrColors);

for (i = 0; i < nrIntervals; i++)
{
dRed = float(keyColor[i+1].red - keyColor[i].red) / float(nrStep);
Expand All @@ -120,24 +123,7 @@ bool Crit3DColorScale::classify()

Crit3DColor* Crit3DColorScale::getColor(float value)
{
unsigned int index = 0;

if (value <= _minimum)
{
index = 0;
}
else if (value >= _maximum)
{
index = _nrColors-1;
}
else
{
if (_classification == classificationMethod::EqualInterval)
{
index = unsigned(float(_nrColors-1) * ((value - _minimum) / (_maximum - _minimum)));
}
}

unsigned int index = getColorIndex(value);
return &color[index];
}

Expand Down Expand Up @@ -237,7 +223,7 @@ bool setAnomalyScale(Crit3DColorScale* myScale)

bool setPrecipitationScale(Crit3DColorScale* myScale)
{
myScale->initialize(6, 252);
myScale->initialize(6, 256);

myScale->keyColor[0] = Crit3DColor(255, 255, 255); /*!< white */
myScale->keyColor[1] = Crit3DColor(0, 0, 255); /*!< blue */
Expand Down
2 changes: 1 addition & 1 deletion agrolib/grapevine/grapevine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ bool Vine3D_Grapevine::compute(bool computeDaily, int secondsPerStep, Crit3DMode
{
simulationStepInSeconds = double(secondsPerStep);
isAmphystomatic = true;
myLeafWidth = 0.2; // [m]
myLeafWidth = 0.2; // [cm]
// Stomatal conductance Adjust stom conductance-photosynth ratio for soil water (Pa)
alphaLeuning = modelCase->cultivar->parameterWangLeuning.alpha;
getFixSimulationParameters();
Expand Down
2 changes: 1 addition & 1 deletion agrolib/graphics/mapGraphicsRasterUtm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ bool RasterUtmObject::drawRaster(QPainter* painter)
// check outliers (transparent)
if (_rasterPointer->colorScale->isHideOutliers())
{
if (value <= _rasterPointer->colorScale->minimum() || value > _rasterPointer->colorScale->maximum())
if (isEqual(value, 0) || value <= _rasterPointer->colorScale->minimum() || value > _rasterPointer->colorScale->maximum())
continue;
}

Expand Down
71 changes: 71 additions & 0 deletions agrolib/hydrall/hydrall.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*!
\name hydrall.cpp
\brief
\authors Antonio Volta, Caterina Toscano
*/


//#include <stdio.h>
#include <math.h>
#include "crit3dDate.h"
#include "commonConstants.h"
#include "hydrall.h"


bool computeHydrall(Crit3DDate myDate, double myTemperature, double myElevation, int secondPerStep)
{
getCO2(myDate, myTemperature, myElevation);
double actualLAI = getLAI();
/* necessaria per ogni specie:
* il contenuto di clorofilla (g cm-2) il default è 500
* lo spessore della foglia 0.2 cm default
* un booleano che indichi se la specie è anfistomatica oppure no
* parametro alpha del modello di Leuning
*
*/
// la temperatura del mese precedente arriva da fuori



return true;
}

double getCO2(Crit3DDate myDate, double myTemperature, double myElevation)
{
double atmCO2 ; //https://www.eea.europa.eu/data-and-maps/daviz/atmospheric-concentration-of-carbon-dioxide-5/download.table
double year[24] = {1750,1800,1850,1900,1910,1920,1930,1940,1950,1960,1970,1980,1990,2000,2010,2020,2030,2040,2050,2060,2070,2080,2090,2100};
double valueCO2[24] = {278,283,285,296,300,303,307,310,311,317,325,339,354,369,389,413,443,473,503,530,550,565,570,575};

// exponential fitting Mauna Loa
if (myDate.year < 1990)
{
atmCO2= 280 * exp(0.0014876*(myDate.year -1840));//exponential change in CO2 concentration (ppm)
}
else
{
atmCO2= 353 * exp(0.00630*(myDate.year - 1990));
}
atmCO2 += 3*cos(2*PI*getDoyFromDate(myDate)/365.0); // to consider the seasonal effects
return atmCO2*getPressureFromElevation(myTemperature, myElevation)/1000000 ; // [Pa] in +- ppm/10
}

double getPressureFromElevation(double myTemperature, double myElevation)
{
return SEA_LEVEL_PRESSURE * exp((- GRAVITY * M_AIR * myElevation) / (R_GAS * myTemperature));
}

double getLAI()
{
// TODO
return 4;
}
/*
double meanLastMonthTemperature(double previousLastMonthTemp, double simulationStepInSeconds, double myInstantTemp)
{
double newTemperature;
double monthFraction;
monthFraction = simulationStepInSeconds/(2592000.0); // seconds of 30 days
newTemperature = previousLastMonthTemp * (1 - monthFraction) + myInstantTemp * monthFraction ;
return newTemperature;
}*/
33 changes: 33 additions & 0 deletions agrolib/hydrall/hydrall.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#ifndef HYDRALL_H
#define HYDRALL_H

#ifndef COMMONCONSTANTS_H
#include "commonConstants.h"
#endif
#ifndef CRIT3DDATE_H
#include "crit3dDate.h"
#endif

#define UPSCALINGFUNC(z,LAI) ((1.0 - exp(-(z)*(LAI))) / (z))

// Tree-plant properties
#define FORM 0.5 // stem form factor
#define RHOF 0.1 // [KgDM m-3] foliage density
#define RHOS 750 // [KgDM m-3] wood-stem density

// Hydraulic properties
#define H50 0.4 // height for 50% maturation of xylem cells (m) [not relevant]
#define KR 4.0E-7 // root specific conductance (m3 MPa-1 s-1 kg-1) [not relevant]
#define KSMAX 2.5E-3 // max. sapwood specific conductivity (m2 MPa-1 s-1) [not relevant]
#define PSITHR -2.5 // water potential threshold for cavitation (MPa) [not relevant]


#define NOT_INITIALIZED_VINE -1

bool computeHydrall(Crit3DDate myDate, double myTemperature, double myElevation, int secondPerStep);
double getCO2(Crit3DDate myDate, double myTemperature, double myElevation);
double getPressureFromElevation(double myTemperature, double myElevation);
double getLAI();
double meanLastMonthTemperature(double previousLastMonthTemp, double simulationStepInSeconds, double myInstantTemp);

#endif // HYDRALL_H
36 changes: 36 additions & 0 deletions agrolib/hydrall/hydrall.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#---------------------------------------------------
#
# hydrall library
# This project is part of CRITERIA3D distribution
#
#---------------------------------------------------

QT -= core gui

TEMPLATE = lib
CONFIG += staticlib

CONFIG += debug_and_release
CONFIG += c++11 c++14 c++17

#DEFINES += _CRT_SECURE_NO_WARNINGS


unix:{
CONFIG(debug, debug|release) {
TARGET = debug/hydrall
} else {
TARGET = release/hydrall
}
}
win32:{
TARGET = hydrall
}

INCLUDEPATH += ../crit3dDate ../mathFunctions ../soil ../crop

SOURCES += hydrall.cpp


HEADERS += hydrall.h

5 changes: 4 additions & 1 deletion agrolib/mathFunctions/commonConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@
#define BOUNDARY_SOLUTEFLUX 30
#define BOUNDARY_NONE 99

#define RELAXATION 1
#define GAUSS_SEIDEL 1
#define JACOBI 2

// --------------- heat model -----------------
#define SAVE_HEATFLUXES_NONE 0
Expand Down Expand Up @@ -159,6 +160,8 @@
#define MO2 0.032
// [kg mol-1] mass of molecular nitrogen (N2)
#define MN2 0.028
// [kg mol-1] mass of air
#define M_AIR 0.029
// [K] zero Celsius
#define ZEROCELSIUS 273.15
// [] ratio molecular weight of water vapour/dry air
Expand Down
2 changes: 1 addition & 1 deletion agrolib/meteo/meteo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,7 @@ bool setColorScale(meteoVariable variable, Crit3DColorScale *colorScale)
case snowFall: case snowWaterEquivalent: case snowLiquidWaterContent: case snowMelt:
case dailyWaterTableDepth:
setPrecipitationScale(colorScale);
if (variable == snowFall || variable == snowWaterEquivalent
if (variable == precipitation || variable == snowFall || variable == snowWaterEquivalent
|| variable == snowLiquidWaterContent || variable == snowMelt)
{
colorScale->setHideOutliers(true);
Expand Down
Loading

0 comments on commit da6f78d

Please sign in to comment.