Skip to content

Commit

Permalink
clean VINE3D
Browse files Browse the repository at this point in the history
  • Loading branch information
ftomei committed Jul 15, 2024
1 parent d392493 commit 5ccfef7
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 149 deletions.
15 changes: 2 additions & 13 deletions agrolib/grapevine/grapevine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,6 @@ void Vine3D_Grapevine::resetLayers()
{
for (int i=0 ; i < nrMaxLayers ; i++)
{
//psiSoilProfile[i] = NODATA ;
//soilWaterContentProfile[i]= NODATA ;
//soilWaterContentProfileFC[i]= NODATA;
//soilWaterContentProfileWP[i]= NODATA;
//soilFieldCapacity[i] = NODATA;
fractionTranspirableSoilWaterProfile[i]= NODATA;
stressCoefficientProfile[i] = NODATA;
transpirationInstantLayer[i] = NODATA;
Expand All @@ -126,15 +121,10 @@ void Vine3D_Grapevine::resetLayers()
}
}

bool Vine3D_Grapevine::initializeLayers(int myMaxLayers)
void Vine3D_Grapevine::initializeLayers(int myMaxLayers)
{
nrMaxLayers = myMaxLayers;

//psiSoilProfile = (double *) calloc(nrLayers, sizeof(double));
//soilWaterContentProfile = (double *) calloc(nrLayers, sizeof(double));
//soilWaterContentProfileFC = (double *) calloc(nrLayers, sizeof(double));
//soilWaterContentProfileWP = (double *) calloc(nrLayers, sizeof(double));
//soilFieldCapacity = (double *) calloc (nrLayers, sizeof(double));
fractionTranspirableSoilWaterProfile = static_cast<double*> (calloc(size_t(nrMaxLayers), sizeof(double)));
stressCoefficientProfile = static_cast<double*> (calloc(size_t(nrMaxLayers), sizeof(double)));
transpirationInstantLayer = static_cast<double*> (calloc(size_t(nrMaxLayers), sizeof(double)));
Expand All @@ -143,10 +133,9 @@ bool Vine3D_Grapevine::initializeLayers(int myMaxLayers)
currentProfile = static_cast<double*> (calloc(size_t(nrMaxLayers), sizeof(double)));

resetLayers();

return true;
}


void Vine3D_Grapevine::setDate (Crit3DTime myTime)
{
myDoy = getDoyFromDate(myTime.date);
Expand Down
6 changes: 3 additions & 3 deletions agrolib/grapevine/grapevine.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,13 @@
struct Crit3DModelCase {
int id;
Crit3DLanduse landuse;
//int soilIndex;
int soilIndex;

float shootsPerPlant;
float plantDensity;
float maxLAIGrass;
int trainingSystem;
float maxIrrigationRate; //[mm/h]
float maxIrrigationRate; // [mm h-1]

int soilLayersNr;
double soilTotalDepth;
Expand Down Expand Up @@ -393,7 +393,7 @@
Vine3D_Grapevine();

//void initializeGrapevineModel(TVineCultivar* cultivar, double secondsPerStep);
bool initializeLayers(int myMaxLayers);
void initializeLayers(int myMaxLayers);
bool initializeStatePlant(int doy, Crit3DModelCase *vineField);
void resetLayers();

Expand Down
3 changes: 0 additions & 3 deletions bin/VINE3D/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ int main(int argc, char *argv[])
if (! myProject.loadParameters("parameters.ini"))
return -1;

if (! myProject.loadVine3DSettings())
return -1;

if (myProject.modality == MODE_GUI)
{
QApplication::setOverrideCursor(Qt::ArrowCursor);
Expand Down
154 changes: 28 additions & 126 deletions bin/VINE3D/vine3DProject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,6 @@ void Vine3DProject::initializeVine3DProject()
}


bool Vine3DProject::loadVine3DSettings()
{
//eventually put Vine3D generic settings
return true;
}


void Vine3DProject::clearVine3DProject()
{
if (isProjectLoaded)
Expand All @@ -79,7 +72,8 @@ void Vine3DProject::clearVine3DProject()
}
}

bool Vine3DProject::loadVine3DProjectSettings()

void Vine3DProject::loadVine3DSettings()
{
projectSettings->beginGroup("project");

Expand All @@ -93,22 +87,21 @@ bool Vine3DProject::loadVine3DProjectSettings()
computeDiseases = projectSettings->value("compute_diseases").toBool();

projectSettings->endGroup();

return true;
}


bool Vine3DProject::openVine3DDatabase(QString fileName)
{
if (fileName == "")
{
logError("Missing VINE3D DB filename");
logError("Missing VINE3D db filename (field db_vine3d)");
return false;
}

dbVine3D = QSqlDatabase::addDatabase("QSQLITE", QUuid::createUuid().toString());
dbVine3D.setDatabaseName(getCompleteFileName(fileName, ""));

if (!dbVine3D.open())
if (! dbVine3D.open())
{
errorString = "Connection with database fail";
return false;
Expand All @@ -118,24 +111,25 @@ bool Vine3DProject::openVine3DDatabase(QString fileName)
return true;
}

bool Vine3DProject::loadVine3DProject(QString myFileName)

bool Vine3DProject::loadVine3DProject(QString projectFileName)
{
clearVine3DProject();

initializeProject();
initializeProject3D();
initializeVine3DProject();

if (myFileName == "") return(false);
if (projectFileName == "")
return false;

if (! loadProjectSettings(myFileName))
if (! loadProjectSettings(projectFileName))
return false;

if (! loadProject3DSettings())
return false;

if (! loadVine3DProjectSettings())
return false;
loadVine3DSettings();

if (dbVine3DFileName != "") openVine3DDatabase(dbVine3DFileName);

Expand All @@ -161,13 +155,15 @@ bool Vine3DProject::loadVine3DProject(QString myFileName)
return false;
}

if (! loadFieldShape())
QString fileName = getCompleteFileName(landUseMapFileName, PATH_GEO);
if (! loadFieldMap(fileName))
{
myFileName = getCompleteFileName(landUseMapFileName, PATH_GEO);
if (! loadFieldMap(myFileName)) return false;
logError();
return false;
}

if (! loadSoilMap(soilMapFileName))
fileName = getCompleteFileName(soilMapFileName, PATH_GEO);
if (! loadSoilMap(fileName))
{
logError();
return false;
Expand All @@ -184,6 +180,7 @@ bool Vine3DProject::loadVine3DProject(QString myFileName)
logError();
return false;
}

processes.setComputeWater(true);

outputWaterBalanceMaps = new Crit3DWaterBalanceMaps(DEM);
Expand Down Expand Up @@ -414,64 +411,6 @@ int Vine3DProject::queryFieldPoint(double x, double y)
}


bool Vine3DProject::loadFieldShape()
{
return false;
/* to be revised
this->logInfo ("Read Fields...");
int dim = 1;
int i, j, id;
double x0, y0;
std::vector <float> valuesList;
QString myQueryString = "SELECT id_field FROM fields_shp";
QSqlQuery myQuery;
myQuery = this->dbConnection.exec(myQueryString);
if (myQuery.size() == -1)
{
this->errorString = myQuery.lastError().text();
return(false);
}
myQuery.clear();
this->modelCaseIndexMap.initializeGrid(this->DEM);
double step = this->modelCaseIndexMap.header->cellSize / (2*dim+1);
for (long row = 0; row < this->modelCaseIndexMap.header->nrRows ; row++)
for (long col = 0; col < this->modelCaseIndexMap.header->nrCols; col++)
if (this->DEM.value[row][col] != this->DEM.header->flag)
{
//center
gis::getUtmXYFromRowCol(this->modelCaseIndexMap, row, col, &x0, &y0);
id = queryFieldPoint(x0, y0);
if (id != NODATA)
this->modelCaseIndexMap.value[row][col] = id;
else
{
valuesList.resize(0);
for (i = -dim; i <= dim; i++)
for (j = -dim; j <= dim; j++)
if ((i != 0)|| (j != 0))
{
id = queryFieldPoint(x0+(i*step), y0+(j*step));
if (id != NODATA)
valuesList.push_back(id);
}
if (valuesList.size() == 0)
this->modelCaseIndexMap.value[row][col] = this->modelCaseIndexMap.header->flag;
else
this->modelCaseIndexMap.value[row][col] = gis::prevailingValue(valuesList);
}
}
gis::updateMinMaxRasterGrid(&(this->modelCaseIndexMap));
this->nrModelCases = int(this->modelCaseIndexMap.maximum);
return true;
*/
}

int getCaseIndexFromId(int caseId, std::vector <Crit3DModelCase> modelCases)
{
if (modelCases.size() == 0)
Expand Down Expand Up @@ -1152,42 +1091,6 @@ float Vine3DProject::getTimeStep()
}


/*
bool Vine3DProject::loadObsDataFilled(QDateTime firstTime, QDateTime lastTime)
{
QDate d1 = firstTime.date().addDays(-30);
QDate d2 = lastTime.date().addDays(30);
if (! this->loadObsDataAllPoints(d1, d2, false)) return(false);
// Replace missing data
long nrReplacedData = 0;
Crit3DTime myTime = getCrit3DTime(firstTime);
long nrHours = firstTime.secsTo(lastTime) / 3600;
for (int i = 0; i <=nrHours; i++)
{
if (!checkLackOfData(this, airTemperature, myTime, &nrReplacedData)
|| !checkLackOfData(this, precipitation, myTime, &nrReplacedData)
|| !checkLackOfData(this, airRelHumidity, myTime, &nrReplacedData))
{
this->logError("Weather data missing: " + getQDateTime(myTime).toString("yyyyMMdd hh:mm"));
return(false);
}
checkLackOfData(this, windScalarIntensity, myTime, &nrReplacedData);
myTime = myTime.addSeconds(3600);
}
if(nrReplacedData > 0)
{
this->logInfo("\nWarning! "+ QString::number(nrReplacedData)+ " hourly data are missing.");
this->logInfo("They was replaced by mean values.\n");
}
return true;
}
*/


bool Vine3DProject::runModels(QDateTime firstTime, QDateTime lastTime, bool saveOutput)
{
if (! isProjectLoaded)
Expand All @@ -1196,7 +1099,6 @@ bool Vine3DProject::runModels(QDateTime firstTime, QDateTime lastTime, bool save
return false;
}

//if (!loadObsDataFilled(dateTime1, dateTime2))
logInfoGUI("Loading meteo data...");
if (! loadMeteoPointsData(firstTime.date().addDays(-1), lastTime.date().addDays(+1), true, false, false))
{
Expand Down Expand Up @@ -1589,26 +1491,26 @@ bool Vine3DProject::initializeGrapevine()
{
outputPlantMaps = new Crit3DOutputPlantMaps(DEM, nrLayers);

if (! grapevine.initializeLayers(nrLayers))
return false;
grapevine.initializeLayers(nrLayers);

int nrSoilLayersWithoutRoots = 2;
int soilLayerWithRoot;
double depthModeRootDensity; //[m] depth of mode of root density
double depthMeanRootDensity; //[m] depth of mean of root density
double depthModeRootDensity; // [m] depth of mode of root density
double depthMeanRootDensity; // [m] depth of mean of root density


for (int i = 0 ; i < modelCases.size(); i++)
for (int i = 0; i < modelCases.size(); i++)
{
// TODO
int soilIndex = 0;
int soilIndex = soilIndexList[0];
int nrHorizons = soilList[soilIndex].nrHorizons;
soil::Crit3DHorizon myHorizon = soilList[soilIndex].horizon[nrHorizons - 1];

unsigned int j=0;
while (j < nrLayers - 1 && layerDepth.at(size_t(j)) <= myHorizon.lowerDepth)
j++;
unsigned int layer=0;
while (layer < nrLayers - 1 && layerDepth.at(size_t(layer)) <= myHorizon.lowerDepth)
layer++;

modelCases[i].soilLayersNr = j;
modelCases[i].soilLayersNr = layer;
modelCases[i].soilTotalDepth = myHorizon.lowerDepth;

soilLayerWithRoot = modelCases[i].soilLayersNr - nrSoilLayersWithoutRoots;
Expand Down
6 changes: 2 additions & 4 deletions bin/VINE3D/vine3DProject.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@

Vine3DProject();

bool loadVine3DSettings();
bool loadVine3DProjectSettings();
void loadVine3DSettings();

bool loadFieldsProperties();
bool loadDBPoints();
Expand All @@ -102,13 +101,12 @@
void initializeVine3DProject();
void clearVine3DProject();

bool loadVine3DProject(QString myFileName);
bool loadVine3DProject(QString projectFileName);
bool openVine3DDatabase(QString fileName);

bool initializeGrapevine();

int queryFieldPoint(double x, double y);
bool loadFieldShape();
bool loadFieldMap(QString myFileName);

bool readFieldQuery(QSqlQuery &myQuery, int &idField, Crit3DLanduse &landuse, int &vineIndex, int &trainingIndex, float &maxLaiGrass, float &maxIrrigationRate);
Expand Down

0 comments on commit 5ccfef7

Please sign in to comment.