Skip to content

Commit

Permalink
update 3D
Browse files Browse the repository at this point in the history
  • Loading branch information
ftomei committed Jul 24, 2024
1 parent f8c0501 commit e29b314
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 88 deletions.
4 changes: 0 additions & 4 deletions DATA/PROJECT/Ravone/Ravone.ini
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ is_utc=true
name=Ravone
dem=../../DEM/DEM_Ravone.flt
meteo_points=../../METEOPOINT/ER_June2018_hourly.db
soil_map=../../SOIL/soilMap_ER_2002.flt
db_soil=../../SOIL/soil_ER_2002.db
meteo_grid=
load_grid_data_at_start=false

[settings]
parameters_file=./SETTINGS/parameters.ini
Expand Down
2 changes: 2 additions & 0 deletions DATA/PROJECT/Ravone/SETTINGS/parameters.ini
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ order=1
stddev_threshold=50
table=point_properties
use_for_spatial_quality_control=true
fitting_parameters=-200, -24, 300, 0.002, -0.01, -0.01, 5000, 44, 1000, 0.007, 0.0015, 0.0015
fitting_function=free_triple_piecewise

[quality]
delta_temperature_suspect=26
Expand Down
Binary file modified DATA/PROJECT/VINE3D_test/SOIL/test_soil.db
Binary file not shown.
23 changes: 0 additions & 23 deletions bin/CRITERIA3D/criteria3DProject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -624,29 +624,6 @@ bool Crit3DProject::writeCriteria3DParameters()
}


bool Crit3DProject::loadLandUseMap(QString fileName)
{
if (fileName == "")
{
logError("Missing land use map filename");
return false;
}

landUseMapFileName = fileName;
fileName = getCompleteFileName(fileName, PATH_GEO);

std::string errorStr;
if (! gis::openRaster(fileName.toStdString(), &landUseMap, gisSettings.utmZone, errorStr))
{
logError("Load land use map failed: " + fileName + "\n" + QString::fromStdString(errorStr));
return false;
}

logInfo("Land use map = " + fileName);
return true;
}


bool Crit3DProject::check3DProject()
{
if (!DEM.isLoaded || !meteoPointsLoaded)
Expand Down
2 changes: 0 additions & 2 deletions bin/CRITERIA3D/criteria3DProject.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@
bool loadCriteria3DParameters();
bool writeCriteria3DParameters();

bool loadLandUseMap(QString fileName);

double getSoilVar(int soilIndex, int layerIndex, soil::soilVariable myVar);
double* getSoilVarProfile(int row, int col, soil::soilVariable myVar);

Expand Down
59 changes: 40 additions & 19 deletions bin/CRITERIA3D/shared/project3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ bool Project3D::initialize3DModel()
// set computation depth
if (waterFluxesParameters.computeOnlySurface)
{
computationSoilDepth = 0;
computationSoilDepth = 0.;
}
else
{
Expand Down Expand Up @@ -393,26 +393,47 @@ bool Project3D::initialize3DModel()
}


bool Project3D::loadSoilMap(QString fileName)
bool Project3D::loadLandUseMap(const QString &fileName)
{
if (fileName == "")
{
logError("Missing land use map filename");
return false;
}

landUseMapFileName = getCompleteFileName(fileName, PATH_GEO);

std::string errorStr;
if (! gis::openRaster(landUseMapFileName.toStdString(), &landUseMap, gisSettings.utmZone, errorStr))
{
logError("Load land use map failed: " + landUseMapFileName + "\n" + QString::fromStdString(errorStr));
return false;
}

logInfo("Land use map = " + landUseMapFileName);
return true;
}


bool Project3D::loadSoilMap(const QString &fileName)
{
if (fileName.isEmpty())
{
logError("Missing soil map");
return false;
}

fileName = getCompleteFileName(fileName, PATH_GEO);
soilMapFileName = getCompleteFileName(fileName, PATH_GEO);

std::string errorStr;
if (! gis::openRaster(fileName.toStdString(), &soilMap, gisSettings.utmZone, errorStr))
if (! gis::openRaster(soilMapFileName.toStdString(), &soilMap, gisSettings.utmZone, errorStr))
{
logError("Loading soil map failed: " + fileName + "\n" + QString::fromStdString(errorStr));
logError("Loading soil map failed: " + soilMapFileName + "\n" + QString::fromStdString(errorStr));
return false;
}

gis::updateMinMaxRasterGrid(&(soilMap));

soilMapFileName = fileName;
logInfo("Soil map = " + soilMapFileName);

return true;
Expand All @@ -437,6 +458,8 @@ bool Project3D::setSoilIndexMap()
return false;
}

logInfo("Set soil index...");

double x, y;
soilIndexMap.initializeGrid(*(DEM.header));
soilIndexList.clear();
Expand Down Expand Up @@ -970,22 +993,21 @@ void Project3D::runModel(double totalTimeStep, bool isRestart)

// ----------------------------------------- CROP and LAND USE -----------------------------------

bool Project3D::loadCropDatabase(QString fileName)
bool Project3D::loadCropDatabase(const QString &fileName)
{
if (fileName == "")
{
logError("Missing Crop DB filename");
logError("Missing Crop DB fileName");
return false;
}

cropDbFileName = fileName;
fileName = getCompleteFileName(fileName, PATH_SOIL);
cropDbFileName = getCompleteFileName(fileName, PATH_SOIL);

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

if (!dbCrop.open())
if (! dbCrop.open())
{
logError("Connection with crop database fail");
return false;
Expand All @@ -1012,7 +1034,7 @@ bool Project3D::loadCropDatabase(QString fileName)
}
}

logInfo("Crop/landUse database = " + fileName);
logInfo("Crop/landUse database = " + cropDbFileName);
return true;
}

Expand Down Expand Up @@ -1067,18 +1089,17 @@ int Project3D::getLandUnitIndexRowCol(int row, int col)

// ------------------------------------ SOIL --------------------------------------

bool Project3D::loadSoilDatabase(QString fileName)
bool Project3D::loadSoilDatabase(const QString &fileName)
{
if (fileName == "")
{
errorString = "Missing Soil DB filename";
errorString = "Missing Soil DB fileName";
return false;
}

soilDbFileName = fileName;
fileName = getCompleteFileName(fileName, PATH_SOIL);
soilDbFileName = getCompleteFileName(fileName, PATH_SOIL);

if (! loadAllSoils(fileName, soilList, texturalClassList, geotechnicsClassList, fittingOptions, errorString))
if (! loadAllSoils(soilDbFileName, soilList, texturalClassList, geotechnicsClassList, fittingOptions, errorString))
{
return false;
}
Expand All @@ -1088,7 +1109,7 @@ bool Project3D::loadSoilDatabase(QString fileName)
}
nrSoils = unsigned(soilList.size());

logInfo("Soil database = " + fileName);
logInfo("Soil database = " + soilDbFileName);
return true;
}

Expand Down
7 changes: 4 additions & 3 deletions bin/CRITERIA3D/shared/project3D.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,10 @@
bool setSoilIndexMap();
bool initialize3DModel();

bool loadSoilDatabase(QString dbName);
bool loadCropDatabase(QString dbName);
bool loadSoilMap(QString fileName);
bool loadLandUseMap(const QString &fileName);
bool loadSoilDatabase(const QString &dbName);
bool loadCropDatabase(const QString &dbName);
bool loadSoilMap(const QString &fileName);

void setProgressionFactor();

Expand Down
2 changes: 1 addition & 1 deletion bin/VINE3D/mainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ void MainWindow::on_actionShow_boundary_triggered()

void MainWindow::on_actionVine3D_InitializeWaterBalance_triggered()
{
if (myProject.initializeWaterBalance3D())
if (myProject.initialize3DModel())
{
myProject.outputWaterBalanceMaps = new Crit3DWaterBalanceMaps(myProject.DEM);
QMessageBox::information(nullptr, "", "3D water fluxes initialized.");
Expand Down
3 changes: 2 additions & 1 deletion bin/VINE3D/modelCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,8 @@ bool modelDailyCycle(bool isInitialState, Crit3DDate myDate, int nrHours,
return false;

// 3D soil water balance
myProject->computeWaterBalance3D(3600);
bool isRestart = false;
myProject->runModel(3600, isRestart);

if (myCurrentTime == myFirstTime)
{
Expand Down
57 changes: 23 additions & 34 deletions bin/VINE3D/vine3DProject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,20 +94,21 @@ bool Vine3DProject::openVine3DDatabase(QString fileName)
{
if (fileName == "")
{
errorString = "Missing VINE3D DataBase filename\nSet field 'db_vine3d' in the .ini settings file.";
errorString = "VINE3D database fileName missing.\nSet the 'db_vine3d' field in the .ini settings file.";
return false;
}

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

if (! dbVine3D.open())
{
errorString = "Connection with database fail";
errorString = "Connection with database fail.";
return false;
}

logInfo("VINE3D database = " + fileName);
logInfo("VINE3D database = " + dbVine3DFileName);
return true;
}

Expand Down Expand Up @@ -148,7 +149,15 @@ bool Vine3DProject::loadVine3DProject(QString projectFileName)
}

waterFluxesParameters.computeOnlySurface = false;
waterFluxesParameters.computeAllSoilDepth = true;
if (computationSoilDepth > 0)
{
waterFluxesParameters.imposedComputationDepth = computationSoilDepth;
waterFluxesParameters.computeAllSoilDepth = false;
}
else
{
waterFluxesParameters.computeAllSoilDepth = true;
}

// vine database
if (! openVine3DDatabase(dbVine3DFileName))
Expand All @@ -164,6 +173,9 @@ bool Vine3DProject::loadVine3DProject(QString projectFileName)
dbVine3D.close();
}

// crop DB is not mandatory
loadCropDatabase(cropDbFileName);

if (! loadSoilMap(soilMapFileName))
{
logError();
Expand All @@ -176,7 +188,7 @@ bool Vine3DProject::loadVine3DProject(QString projectFileName)
return false;
}

if (! loadFieldMap(landUseMapFileName))
if (! loadLandUseMap(landUseMapFileName))
{
logError();
return false;
Expand All @@ -188,7 +200,7 @@ bool Vine3DProject::loadVine3DProject(QString projectFileName)
return false;
}

if (! initializeWaterBalance3D())
if (! initialize3DModel())
{
logError();
return false;
Expand Down Expand Up @@ -441,9 +453,12 @@ bool Vine3DProject::setModelCasesMap()
return false;
}

logInfo ("Set the model case map...");

// set model cases
int nrModelCases = nrInputCases * nrSoils;
modelCases.resize(nrModelCases);

for (int i = 0; i < nrInputCases; i++)
{
for (int j = 0; j < nrSoils; j++)
Expand Down Expand Up @@ -479,33 +494,7 @@ bool Vine3DProject::setModelCasesMap()
}
}

return true;
}


bool Vine3DProject::loadFieldMap(QString mapFileName)
{
logInfo ("Read fields map...");

QString fileName = getCompleteFileName(mapFileName, PATH_GEO);

std::string fn = fileName.left(fileName.length()-4).toStdString();
gis::Crit3DRasterGrid inputGrid;

std::string errorStr;
if (! gis::readEsriGrid(fn, &(inputGrid), errorStr))
{
errorString = "Load fields map failed:\n" + mapFileName + "\n" + QString::fromStdString(errorStr);
logError();
return false;
}

// compute prevailing map
landUseMap.initializeGrid(DEM);
gis::prevailingMap(inputGrid, &(landUseMap));
gis::updateMinMaxRasterGrid(&(landUseMap));

logInfo ("Field map = " + mapFileName);
logInfo ("Nr of model cases: " + QString::number(nrModelCases));
return true;
}

Expand Down
1 change: 0 additions & 1 deletion bin/VINE3D/vine3DProject.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@
bool setModelCasesMap();

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

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

0 comments on commit e29b314

Please sign in to comment.