ajwdewit / pcse

Repository for the Python Crop Simulation Environment
Other
184 stars 125 forks source link

TypeError - Wofost80_NWLP_FD_beta #61

Closed iMarang closed 2 years ago

iMarang commented 2 years ago

Hi,

First of all, a huge thank you for the excellent documentation and example notebooks. I've used a bunch of different crop models and this is by far the most logically organised intro and layout I've seen. And the choice of using Python was enlightened, though I'm probably biased on this point.

Onto the issue ... I'm testing out WOFOST and have run into an error. I'd like to use this in nutrient and water limited scenarios so I've been trying out Wofost80 (although I realise this is a beta). I first encountered a KeyError: 'DVS' from the original pip installed version, which I fixed by installing the 'develop' branch, however, now I'm getting a TypeError.

My code amended from your User Guide is below and the (jury rigged) files are attached.

Wofost80_test.zip

as per PCSE User Guide on using 'custom input data'

import pcse from pcse.fileinput import CABOFileReader,YAMLAgroManagementReader from pcse.util import WOFOST80SiteDataProvider from pcse.base import ParameterProvider from pcse.db import NASAPowerWeatherDataProvider from pcse.models import Wofost80_NWLP_FD_beta

data_dir = r'~\Documents\PCSE_test_data'

crop params - modified from sugarbeet example with wheat params

cropfile = os.path.join(data_dir, 'wheat_manualUpdate.crop') cropdataTest = CABOFileReader(cropfile)

print(cropdata)

soil - params unchanged from ec3

soilfile = os.path.join(data_dir, 'Trangie.soil') soildataTest = CABOFileReader(soilfile)

site data - defaults with CO2 update

CO2 concentration from http://www.bom.gov.au/state-of-the-climate/greenhouse-gas-levels.shtml#:~:text=The%20annual%20average%20CO2,of%20278%20ppm%20in%201750.

sitedataTest = WOFOST80SiteDataProvider(WAV=90, CO2=400)

pack parameters together

parametersTest = ParameterProvider(cropdata=cropdataTest, soildata=soildataTest, sitedata=sitedataTest)

agromanagement - updated for 2022

agromanagement_file = os.path.join(data_dir, 'wheat_manualUpdate_calendar.agro') agromanagementTest = YAMLAgroManagementReader(agromanagement_file)

weather

wdp = NASAPowerWeatherDataProvider(latitude=-32, longitude=148)

test single run

wofsim = Wofost80_NWLP_FD_beta(parametersTest, wdp, agromanagementTest) wofsim.run_till_terminate()

And the error was:

TypeError Traceback (most recent call last) Input In [7], in <cell line: 36>() 34 # test single run 35 wofsim = Wofost80_NWLP_FD_beta(parametersTest, wdp, agromanagementTest) ---> 36 wofsim.run_till_terminate() 37 output = wofsim.get_output() 38 output

File ~\Anaconda3\envs\py3_pcse\lib\site-packages\pcse\engine.py:228, in Engine.run_till_terminate(self) 225 """Runs the system until a terminate signal is sent.""" 227 while self.flag_terminate is False: --> 228 self._run()

File ~\Anaconda3\envs\py3_pcse\lib\site-packages\pcse\engine.py:202, in Engine._run(self) 199 self.day, delt = self.timer() 201 # State integration --> 202 self.integrate(self.day, delt) 204 # Driving variables 205 self.drv = self._get_driving_variables(self.day)

File ~\Anaconda3\envs\py3_pcse\lib\site-packages\pcse\engine.py:185, in Engine.integrate(self, day, delt) 182 self.crop.integrate(day, delt) 184 if self.soil is not None: --> 185 self.soil.integrate(day, delt) 187 # Set all rate variables to zero 188 if settings.ZEROFY:

File ~\Anaconda3\envs\py3_pcse\lib\site-packages\pcse\soil\soil_wrappers.py:86, in SoilModuleWrapper_NPK_WLP_FD.integrate(self, day, delt) 84 def integrate(self, day, delt=1.0): 85 self.WaterbalanceFD.integrate(day, delt) ---> 86 self.NPK_Soil_Dynamics.integrate(day, delt)

File ~\Anaconda3\envs\py3_pcse\lib\site-packages\pcse\decorators.py:39, in descript.make_bound..wrapper(*args, *kwargs) 37 if attr is not None: 38 attr.unlock() ---> 39 ret = self.f(instance, args, **kwargs) 40 attr = getattr(instance, self.lockattr) 41 if attr is not None:

File ~\Anaconda3\envs\py3_pcse\lib\site-packages\pcse\soil\npk_soil_dynamics.py:247, in NPK_Soil_Dynamics.integrate(self, day, delt) 244 states.KSOIL += rates.RKSOIL delt 246 # total (soil + fertilizer) NPK amount in soil --> 247 states.NAVAIL += rates.RNAVAIL delt 248 states.PAVAIL += rates.RPAVAIL delt 249 states.KAVAIL += rates.RKAVAIL delt

TypeError: unsupported operand type(s) for +=: 'NoneType' and 'float'

Any advice? I'll give the Wofost72 a try model but am very interested in simulating the nutrient poor and moisture deficient soils of most Australian cropping regions so the newer model is better for me.

Thanks Ian

ajwdewit commented 2 years ago

Hi Ian,

Thanks for positive emarks and your willingness to try it out.

I will test it with your input data to see if I can reproduce the problem. The only thing is that I am very short on time for the coming two weeks. So it may take a while.

Allard

iMarang commented 2 years ago

Hi Allard,

I hope the next few weeks go smoothly and things settle down for you. Feels like the heart rate of the planet is racing and accelerating. Maybe it's just I've had too much coffee.

When you get back it would be useful to get clarity on a few of the inputs for WOFOST:

I'll keep pottering away to find data for the first two, and can calibrate the model run to find optimal values for each site (20+) if I have to, but its far from ideal. The last point is a bit of a corker though so if you could advise I'd appreciate it.

Thanks again, have a glorious day. Ian

ajwdewit commented 2 years ago

Dear Ian,

One thing I noticed is that your crop parameter file is not suited for WOFOST 8.0 because it is a 7.2 file that is missing a lot of parameters. Please use the crop parameters here: https://github.com/ajwdewit/wofost_crop_parameters and look at the readme on github on how to use them.

The simple waterbalance for WOFOST actually does not use the water retention curves. It only uses the parameters SM0, SMW, SMFCF, KSUB, K0 and RMDSOL. The values for KSUB and K0 represent the drainage rates of the soil, we usually set them at a high values (say 10 cm/day) assuming that the soil drains fast.

The ExcelWeatherDataProvider internally does the conversion to J/m2/day. This is global radiation at surface.

Allard

iMarang commented 2 years ago

Hi Allard, Magnifiek, bedankt! I've converted the code to use the version 8 files and it worked a treat. I'll use surface irradiance for the IRRAD values and calibrate those soil characteristics. Now I can proceed, I'll close the issue. If you were down at the pub I'd buy you a beer. Slainte! Have a great weekend. Ian