Skip to content

Commit

Permalink
bare soil
Browse files Browse the repository at this point in the history
  • Loading branch information
ftomei committed Jun 13, 2024
1 parent ccfb37f commit 1b38c94
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 43 deletions.
Binary file modified DATA/PROJECT/test/data/comp_units.db
Binary file not shown.
Binary file modified DATA/PROJECT/test/data/crop.db
Binary file not shown.
Binary file modified DATA/TEMPLATE/crop_default.db
Binary file not shown.
12 changes: 9 additions & 3 deletions agrolib/criteria1DWidget/criteria1DWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,7 @@ void Criteria1DWidget::on_actionOpenProject()
this->lastYearListComboBox.blockSignals(false);

openComputationUnitsDB(myProject.dbComputationUnitsName);

viewMenu->setEnabled(true);
if (soilListComboBox.count() == 0)
{
Expand Down Expand Up @@ -1053,15 +1054,20 @@ void Criteria1DWidget::on_actionChooseCase()
// METEO
meteoListComboBox.setCurrentText(myProject.myCase.unit.idMeteo);

// CROP
// CROP ID
myProject.myCase.unit.idCrop = getIdCropFromClass(myProject.dbCrop, "crop_class", "id_class", myProject.myCase.unit.idCropClass, errorStr);
if (myProject.myCase.unit.idCrop != "")
if (myProject.myCase.unit.idCrop == "")
{
// it is a single crop, not a crop class
myProject.myCase.unit.idCrop = myProject.myCase.unit.idCropClass;
}
if ( cropListComboBox.findText(myProject.myCase.unit.idCrop) != -1 )
{
cropListComboBox.setCurrentText(myProject.myCase.unit.idCrop);
}
else
{
QMessageBox::critical(nullptr, "Error!", "Missing crop class: " + myProject.myCase.unit.idCropClass + "\n" + errorStr);
QMessageBox::critical(nullptr, "Error!", "Missing crop: " + myProject.myCase.unit.idCropClass + "\n" + errorStr);
}

// SOIL
Expand Down
19 changes: 9 additions & 10 deletions agrolib/criteriaModel/criteria1DProject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1095,7 +1095,11 @@ int Crit1DProject::computeAllUnits()
}
}

int infoStep = std::max(1, int(compUnitList.size() / 20));
int infoStep = compUnitList.size();
if (compUnitList.size() >= 20)
{
infoStep = int(compUnitList.size() / 20);
}
logger.writeInfo("COMPUTE...");

try
Expand All @@ -1108,25 +1112,20 @@ int Crit1DProject::computeAllUnits()
logger.writeInfo(compUnitList[i].idCase + " - numerical computation...");
}

// CROP
// check if it is crop class
compUnitList[i].idCrop = getIdCropFromClass(dbCrop, "crop_class", "id_class",
compUnitList[i].idCropClass, projectError);
if (compUnitList[i].idCrop == "")
{
logger.writeInfo("Unit " + compUnitList[i].idCase + " " + compUnitList[i].idCropClass + " ***** missing CROP *****");
isErrorCrop = true;
continue;
compUnitList[i].idCrop = compUnitList[i].idCropClass;
}

// IRRI_RATIO
float irriRatio = getIrriRatioFromCropClass(dbCrop, "crop_class", "id_class",
compUnitList[i].idCropClass, projectError);

if ((isYearlyStatistics || isMonthlyStatistics || isSeasonalForecast || isEnsembleForecast || isShortTermForecast)
&& (int(irriRatio) == int(NODATA)))
if (isEqual(irriRatio, NODATA))
{
logger.writeInfo("Unit " + compUnitList[i].idCase + " " + compUnitList[i].idCropClass + " ***** missing IRRIGATION RATIO *****");
continue;
irriRatio = 1;
}

// SOIL
Expand Down
2 changes: 1 addition & 1 deletion agrolib/crop/crop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
\file crop.cpp
\abstract
Crop class functions
Crop development (Crit3DCrop class)
\authors
Fausto Tomei ftomei@arpae.it
Expand Down
125 changes: 96 additions & 29 deletions agrolib/crop/cropDbTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,31 +163,69 @@ bool updateCropLAIparam(QSqlDatabase &dbCrop, const Crit3DCrop &myCrop, QString
"lai_curve_factor_a = :lai_curve_factor_a, lai_curve_factor_b = :lai_curve_factor_b, "
"kc_max = :kc_max WHERE id_crop = :id_crop");

if (myCrop.sowingDoy != NODATA)
if (myCrop.isBareSoil())
{
qry.bindValue(":sowing_doy", myCrop.sowingDoy);
qry.bindValue(":max_cycle", myCrop.plantCycle);
qry.bindValue(":sowing_doy", "");
qry.bindValue(":max_cycle", "");
qry.bindValue(":lai_grass", "");
qry.bindValue(":lai_min", "");
qry.bindValue(":lai_max", "");
qry.bindValue(":thermal_threshold", "");
qry.bindValue(":upper_thermal_threshold", "");
qry.bindValue(":degree_days_lai_increase", "");
qry.bindValue(":degree_days_lai_decrease", "");
qry.bindValue(":lai_curve_factor_a", "");
qry.bindValue(":lai_curve_factor_b", "");
qry.bindValue(":kc_max", "");
}
else
{
qry.bindValue(":sowing_doy", "");
qry.bindValue(":max_cycle", 365);
if (myCrop.sowingDoy != NODATA)
{
qry.bindValue(":sowing_doy", myCrop.sowingDoy);
qry.bindValue(":max_cycle", myCrop.plantCycle);
}
else
{
qry.bindValue(":sowing_doy", "");
qry.bindValue(":max_cycle", 365);
}

if (myCrop.LAIgrass != NODATA)
{
qry.bindValue(":lai_grass", myCrop.LAIgrass);
}
else
{
qry.bindValue(":lai_grass", "");
}

if (myCrop.degreeDaysEmergence != 0 && myCrop.degreeDaysEmergence != NODATA)
{
qry.bindValue(":degree_days_emergence", myCrop.degreeDaysEmergence);
}
else
{
qry.bindValue(":degree_days_emergence", "");
}

qry.bindValue(":lai_min", myCrop.LAImin);
qry.bindValue(":lai_max", myCrop.LAImax);

qry.bindValue(":thermal_threshold", myCrop.thermalThreshold);
qry.bindValue(":upper_thermal_threshold", myCrop.upperThermalThreshold);

qry.bindValue(":degree_days_lai_increase", myCrop.degreeDaysIncrease);
qry.bindValue(":degree_days_lai_decrease", myCrop.degreeDaysDecrease);

qry.bindValue(":lai_curve_factor_a", myCrop.LAIcurve_a);
qry.bindValue(":lai_curve_factor_b", myCrop.LAIcurve_b);
qry.bindValue(":kc_max", myCrop.kcMax);
}
qry.bindValue(":lai_min", myCrop.LAImin);
qry.bindValue(":lai_max", myCrop.LAImax);
qry.bindValue(":lai_grass", myCrop.LAIgrass);
qry.bindValue(":thermal_threshold", myCrop.thermalThreshold);
qry.bindValue(":upper_thermal_threshold", myCrop.upperThermalThreshold);
qry.bindValue(":degree_days_emergence", myCrop.degreeDaysEmergence);
qry.bindValue(":degree_days_lai_increase", myCrop.degreeDaysIncrease);
qry.bindValue(":degree_days_lai_decrease", myCrop.degreeDaysDecrease);
qry.bindValue(":lai_curve_factor_a", myCrop.LAIcurve_a);
qry.bindValue(":lai_curve_factor_b", myCrop.LAIcurve_b);
qry.bindValue(":kc_max", myCrop.kcMax);

qry.bindValue(":id_crop", QString::fromStdString(myCrop.idCrop));

if( !qry.exec() )
if( ! qry.exec() )
{
errorStr = qry.lastError().text();
return false;
Expand All @@ -207,11 +245,30 @@ bool updateCropRootparam(QSqlDatabase &dbCrop, const Crit3DCrop &myCrop, QString
" degree_days_root_increase = :degree_days_root_increase"
" WHERE id_crop = :id_crop");

qry.bindValue(":root_shape", root::getRootDistributionNumber(myCrop.roots.rootShape));
qry.bindValue(":root_depth_zero", myCrop.roots.rootDepthMin);
qry.bindValue(":root_depth_max", myCrop.roots.rootDepthMax);
qry.bindValue(":root_shape_deformation", myCrop.roots.shapeDeformation);
qry.bindValue(":degree_days_root_increase", myCrop.roots.degreeDaysRootGrowth);
if (myCrop.isBareSoil())
{
qry.bindValue(":root_shape", "");
qry.bindValue(":root_depth_zero", "");
qry.bindValue(":root_depth_max", "");
qry.bindValue(":root_shape_deformation", "");
qry.bindValue(":degree_days_root_increase", "");
}
else
{
qry.bindValue(":root_shape", root::getRootDistributionNumber(myCrop.roots.rootShape));
qry.bindValue(":root_depth_zero", myCrop.roots.rootDepthMin);
qry.bindValue(":root_depth_max", myCrop.roots.rootDepthMax);
qry.bindValue(":root_shape_deformation", myCrop.roots.shapeDeformation);

if (myCrop.roots.degreeDaysRootGrowth != NODATA)
{
qry.bindValue(":degree_days_root_increase", myCrop.roots.degreeDaysRootGrowth);
}
else
{
qry.bindValue(":degree_days_root_increase", "");
}
}

qry.bindValue(":id_crop", QString::fromStdString(myCrop.idCrop));

Expand All @@ -220,6 +277,7 @@ bool updateCropRootparam(QSqlDatabase &dbCrop, const Crit3DCrop &myCrop, QString
errorStr = qry.lastError().text();
return false;
}

return true;
}

Expand All @@ -233,12 +291,12 @@ bool updateCropIrrigationparam(QSqlDatabase &dbCrop, const Crit3DCrop &myCrop, Q
"psi_leaf = :psi_leaf, raw_fraction = :raw_fraction, stress_tolerance = :stress_tolerance"
" WHERE id_crop = :id_crop");

if (myCrop.irrigationVolume == 0)
if (myCrop.irrigationVolume == 0 || myCrop.isBareSoil())
{
qry.bindValue(":irrigation_shift", QVariant(QVariant::String));
qry.bindValue(":irrigation_shift", "");
qry.bindValue(":irrigation_volume", 0);
qry.bindValue(":degree_days_start_irrigation", QVariant(QVariant::String));
qry.bindValue(":degree_days_end_irrigation", QVariant(QVariant::String));
qry.bindValue(":degree_days_start_irrigation", "");
qry.bindValue(":degree_days_end_irrigation", "");
}
else
{
Expand All @@ -248,9 +306,18 @@ bool updateCropIrrigationparam(QSqlDatabase &dbCrop, const Crit3DCrop &myCrop, Q
qry.bindValue(":degree_days_end_irrigation", myCrop.degreeDaysEndIrrigation);
}

qry.bindValue(":psi_leaf", myCrop.psiLeaf);
qry.bindValue(":raw_fraction", myCrop.fRAW);
qry.bindValue(":stress_tolerance", myCrop.stressTolerance);
if (myCrop.isBareSoil() )
{
qry.bindValue(":psi_leaf", "");
qry.bindValue(":raw_fraction", "");
qry.bindValue(":stress_tolerance", "");
}
else
{
qry.bindValue(":psi_leaf", myCrop.psiLeaf);
qry.bindValue(":raw_fraction", myCrop.fRAW);
qry.bindValue(":stress_tolerance", myCrop.stressTolerance);
}

qry.bindValue(":id_crop", QString::fromStdString(myCrop.idCrop));

Expand Down

0 comments on commit 1b38c94

Please sign in to comment.