From a5d88aece235142625ce8ce3b8dc25f1b0f00321 Mon Sep 17 00:00:00 2001 From: ftomei Date: Fri, 27 Oct 2023 17:32:57 +0200 Subject: [PATCH] add daily update crop --- DATA/PROJECT/Montue/DATA/crop_Montue.db | Bin 13312 -> 13312 bytes agrolib/crop/crop.cpp | 10 ++++- agrolib/crop/crop.h | 2 +- bin/CRITERIA3D/criteria3DProject.cpp | 51 +++++++++++++++++++++++- bin/CRITERIA3D/criteria3DProject.h | 1 + bin/CRITERIA3D/mainwindow.cpp | 2 +- 6 files changed, 61 insertions(+), 5 deletions(-) diff --git a/DATA/PROJECT/Montue/DATA/crop_Montue.db b/DATA/PROJECT/Montue/DATA/crop_Montue.db index 83345401a18d6bd166a42a72a64447213fc3127b..61d3d9085c85dab0a77b9bde84a29016f342ce48 100644 GIT binary patch delta 111 zcmZq3Xvml#&FDK(#+lJ~W5Ob7o_GdkW(@{r4d#8!lQs+TNHI^=kT+*xU|=wwoGh^3ZPL@}a kT=|EAfx%o>S5n@BiGxvA*Ah%h$}>(rF0Zh8pS+U@07JPFm;e9( diff --git a/agrolib/crop/crop.cpp b/agrolib/crop/crop.cpp index 5dd70b5bc..6d3b37bc1 100644 --- a/agrolib/crop/crop.cpp +++ b/agrolib/crop/crop.cpp @@ -152,11 +152,17 @@ void Crit3DCrop::initialize(double latitude, unsigned int nrLayers, double total } -double Crit3DCrop::getDailyDegreeIncrease(double tmin, double tmax) +double Crit3DCrop::getDailyDegreeIncrease(double tmin, double tmax, int doy) { if (isEqual(tmin, NODATA) || isEqual(tmax, NODATA)) return NODATA; + // check crop cycle + if (isSowingCrop() && ! isInsideTypicalCycle(doy)) + { + return 0; + } + double tmed = (tmin + MINVALUE(tmax, upperThermalThreshold)) * 0.5; return MAXVALUE(tmed - thermalThreshold, 0); } @@ -297,7 +303,7 @@ int Crit3DCrop::getDaysFromCurrentSowing(int myDoy) const bool Crit3DCrop::isInsideTypicalCycle(int myDoy) const { - return (myDoy >= sowingDoy && getDaysFromTypicalSowing(myDoy) < plantCycle); + return (getDaysFromTypicalSowing(myDoy) < plantCycle); } diff --git a/agrolib/crop/crop.h b/agrolib/crop/crop.h index 0301d45a1..1d4561e53 100644 --- a/agrolib/crop/crop.h +++ b/agrolib/crop/crop.h @@ -81,7 +81,7 @@ bool isSowingCrop() const; bool isRootStatic() const; - double getDailyDegreeIncrease(double tmin, double tmax); + double getDailyDegreeIncrease(double tmin, double tmax, int doy); void initialize(double latitude, unsigned int nrLayers, double totalSoilDepth, int currentDoy); bool needReset(Crit3DDate myDate, double latitude, double waterTableDepth); diff --git a/bin/CRITERIA3D/criteria3DProject.cpp b/bin/CRITERIA3D/criteria3DProject.cpp index 56a3b32c8..235bc0e4c 100644 --- a/bin/CRITERIA3D/criteria3DProject.cpp +++ b/bin/CRITERIA3D/criteria3DProject.cpp @@ -166,7 +166,7 @@ void Crit3DProject::initializeCrop() float tmax = climateParameters.getClimateVar(dailyAirTemperatureMax, myDate.month, height, quality->getReferenceHeight()); - double currentDD = cropList[index].getDailyDegreeIncrease(tmin, tmax); + double currentDD = cropList[index].getDailyDegreeIncrease(tmin, tmax, currentDoy); if (! isEqual(currentDD, NODATA)) { degreeDays += currentDD; @@ -183,6 +183,50 @@ void Crit3DProject::initializeCrop() } +void Crit3DProject::dailyUpdateCrop() +{ + for (int row = 0; row < DEM.header->nrRows; row++) + { + for (int col = 0; col < DEM.header->nrCols; col++) + { + float height = DEM.value[row][col]; + if (! isEqual(height, DEM.header->flag)) + { + // is crop + int index = getLandUnitIndexRowCol(row, col); + if (index != NODATA && landUnitList[index].idCrop != "") + { + float tmin = dailyTminMap.value[row][col]; + float tmax = dailyTminMap.value[row][col]; + if (! isEqual(tmin, dailyTminMap.header->flag) && ! isEqual(tmax, dailyTmaxMap.header->flag)) + { + double dailyDD = cropList[index].getDailyDegreeIncrease(tmin, tmax, currentDate.dayOfYear()); + if (! isEqual(dailyDD, NODATA)) + { + if (isEqual(degreeDaysMap.value[row][col], degreeDaysMap.header->flag)) + { + degreeDaysMap.value[row][col] = float(dailyDD); + } + else + { + degreeDaysMap.value[row][col] += float(dailyDD); + } + + laiMap.value[row][col] = cropList[index].computeSimpleLAI(degreeDaysMap.value[row][col], + gisSettings.startLocation.latitude, currentDate.dayOfYear()); + } + } + } + } + } + } + + // clean daily temp maps + dailyTminMap.emptyGrid(); + dailyTmaxMap.emptyGrid(); +} + + bool Crit3DProject::runModels(QDateTime firstTime, QDateTime lastTime) { // initialize meteo @@ -216,6 +260,11 @@ bool Crit3DProject::runModels(QDateTime firstTime, QDateTime lastTime) { setCurrentDate(myDate); + if (processes.computeCrop) + { + dailyUpdateCrop(); + } + if (isSaveOutputRaster()) { // create directory for hourly raster output diff --git a/bin/CRITERIA3D/criteria3DProject.h b/bin/CRITERIA3D/criteria3DProject.h index 54fd3ed74..5b4a7ba9c 100644 --- a/bin/CRITERIA3D/criteria3DProject.h +++ b/bin/CRITERIA3D/criteria3DProject.h @@ -70,6 +70,7 @@ bool initializeCriteria3DModel(); void initializeCrop(); + void dailyUpdateCrop(); bool runModels(QDateTime firstTime, QDateTime lastTime); diff --git a/bin/CRITERIA3D/mainwindow.cpp b/bin/CRITERIA3D/mainwindow.cpp index 779aad81d..e64c11b9e 100644 --- a/bin/CRITERIA3D/mainwindow.cpp +++ b/bin/CRITERIA3D/mainwindow.cpp @@ -2236,7 +2236,7 @@ void MainWindow::on_actionCriteria3D_run_models_triggered() myProject.processes.initialize(); myProject.processes.computeMeteo = true; myProject.processes.computeRadiation = true; - myProject.processes.computeWater = true; + myProject.processes.computeWater = false; myProject.processes.computeCrop = true; startModels(firstTime, lastTime);