Code Monkey home page Code Monkey logo

aquacrop's People

Contributors

arongergely avatar chris-s-bowden avatar pacs27 avatar rbavery avatar samaranin avatar tfoster88 avatar thomasdkelly avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

aquacrop's Issues

where is the calculate function?

I can't find out how the parameters Tr and TrPot in the biomass_accumulation function are calculated, and where is the calculation position?
@cc.export("biomass_accumulation", (CropStructNT_type_sig,i8,i8,f8,f8,f8,f8,f8,f8,f8,b1))
def biomass_accumulation(
Crop: NamedTuple,
NewCond_DAP: int,
NewCond_DelayedCDs: int,
NewCond_HIref: float,
NewCond_PctLagPhase: float,
NewCond_B: float,
NewCond_B_NS: float,
Tr: float,
TrPot: float,
et0: float,
growing_season: bool,
) -> Tuple[float, float]:
....
where is the tr value from and how calculate?

changes from nbdev framework

The nbdev framework was a really useful template when starting this library from scratch, however there are certain changes we would like to make (e.g., ahead of time compling) that cannot currently be incorperated into the 'notebooks -->.py' workflow.

  • Currently the module code is wriiten in the /nbs/ folder which is exported to the /aquacrop/ folder. Changes should now be made to the .py files themselves making the /nbs/ folder redundant
  • The /nbs/ folder could instead be used for tests
  • The docs are currently generated from the notebooks so this will have to be changed (maybe using https://squidfunk.github.io/mkdocs-material/)

update docstrings within solution.py

After the many changes that have been made to function within solution.py, doctrings will have to be updated. The format needs to also be altered slightly to create better outputs within mkdocs

KeyError when updating season_counter

I've got KeyError when trying to run a simulation on my data.
Simulation code and weather data can be found here -> WeTransfer <- and below.

My code and initial parameters for simulation:

from aquacrop import AquaCropModel, Soil, Crop, InitialWaterContent, IrrigationManagement
import pandas as pd

if __name__ == "__main__":
    weather_data = pd.read_csv("./key_error_example_data.csv")
    weather_data["Date"] = pd.to_datetime(weather_data["Date"])
    model_os = AquaCropModel(
                sim_start_time=f"2015/05/15",
                sim_end_time=f"2016/03/10",
                weather_df=weather_data,
                soil=Soil(soil_type='SiltClayLoam'),
                crop=Crop('Wheat', planting_date='05/15'),
                initial_water_content=InitialWaterContent(),
                irrigation_management=IrrigationManagement(irrigation_method=1, SMT=[70] * 4)
            )
    model_os.run_model(till_termination=True)
    model_results = model_os.get_simulation_results().head()
    print(model_results)

And the error (just the main part of it)

File "/home/boiko/Projects/original-aquacrop/aquacrop/timestep/update_time.py", line 58, in update_time
    clock_struct.time_step_counter = clock_struct.time_span.get_loc(
  File "/home/boiko/Projects/original-aquacrop/venv/lib/python3.10/site-packages/pandas/core/indexes/datetimes.py", line 698, in get_loc
    raise KeyError(orig_key) from err
KeyError: Timestamp('2016-05-15 00:00:00')

I assume that this error appears when the simulation tries to switch to another season but clock_struct.time_span does not contain dates for this period (the next planting date is after the last available date in clock_struct.time_span).
I've fixed this with a quick fix inside aquacrop/timestep/update_time.py from line 58:

# ***********************************************************************
# Added this code to avoid the situation when left no weather data but simulation is trying to run further
# there was just commented code below
# clock_struct.time_step_counter = clock_struct.time_span.get_loc(
#     clock_struct.planting_dates[clock_struct.season_counter]
# )

# if the last date in available dates in time span is less than the planting date in next season
# we will finish the model and stop the simulation
if clock_struct.time_span[-1] < clock_struct.planting_dates[clock_struct.season_counter]:
    clock_struct.model_is_finished = True
    return clock_struct, init_cond, param_struct
# otherwise we are using original code and extracting data for the new planting date
else:
    clock_struct.time_step_counter = clock_struct.time_span.get_loc(
        clock_struct.planting_dates[clock_struct.season_counter]
    )
# ***********************************************************************

But I think that it needs to be fixed on a higher level.
Maybe someone will have an idea of how or where this can be fixed.

UPDATE:
I think this should be fixed in aquacrop/initialize/read_model_parameters.py from line 130, where the number of planting years is calculated because the number of seasons depends on this value. In cases similar to my should be only 1 planting year.

Multiple custom soil layers result different yield estimation compared with that of the original application

I was trying to use custom soil in yield estimation, but got a quite different result.
I then used a uniform soil parameters set with multiple layers and single layer, followed are the different result.
The single layer outputs the same result with the original application.
But with the same soil parameters, multiple layers output a much lower yield, could you please help with this issue?
Sinle layer & yield estimation

(WS) hzhao@r740-2:~/sample$ python yieldEstimate.py 
    Comp  Layer    dz  dzsum  zBot  zTop   zMid  th_dry  th_wp  th_fc  th_s   Ksat  penetrability   tau    
0      0    1.0  0.05   0.05  0.05  0.00  0.025  0.0705  0.141   0.26  0.41  586.7            100  0.81  
1      1    1.0  0.05   0.10  0.10  0.05  0.075  0.0705  0.141   0.26  0.41  586.7            100  0.81  
2      2    1.0  0.05   0.15  0.15  0.10  0.125  0.0705  0.141   0.26  0.41  586.7            100  0.81
3      3    1.0  0.05   0.20  0.20  0.15  0.175  0.0705  0.141   0.26  0.41  586.7            100  0.81
4      4    1.0  0.05   0.25  0.25  0.20  0.225  0.0705  0.141   0.26  0.41  586.7            100  0.81
5      5    1.0  0.05   0.30  0.30  0.25  0.275  0.0705  0.141   0.26  0.41  586.7            100  0.81
6      6    1.0  0.05   0.35  0.35  0.30  0.325  0.0705  0.141   0.26  0.41  586.7            100  0.81
7      7    1.0  0.05   0.40  0.40  0.35  0.375  0.0705  0.141   0.26  0.41  586.7            100  0.81
8      8    1.0  0.05   0.45  0.45  0.40  0.425  0.0705  0.141   0.26  0.41  586.7            100  0.81
9      9    1.0  0.05   0.50  0.50  0.45  0.475  0.0705  0.141   0.26  0.41  586.7            100  0.81
10    10    1.0  0.90   1.40  1.40  0.50  0.950  0.0705  0.141   0.26  0.41  586.7            100  0.81
11    11    1.0  0.90   2.30  2.30  1.40  1.850  0.0705  0.141   0.26  0.41  586.7            100  0.81
   Season Crop Type Harvest Date (YYYY/MM/DD)  Harvest Date (Step)  Yield (tonne/ha)  Seasonal irrigation (mm)
0       0     Maize                2019-09-04                  131         13.458998                         0

Multiple layers & yield estimation

(WS) hzhao@r740-2:~/sample$ python yieldEstimate.py 
    Comp  Layer    dz  dzsum  zBot  zTop   zMid  th_dry  th_wp  th_fc  th_s   Ksat  penetrability   tau
0      0    1.0  0.05   0.05  0.05  0.00  0.025  0.0705  0.141   0.26  0.41  586.7          100.0  0.81
1      1    1.0  0.05   0.10  0.10  0.05  0.075  0.0705  0.141   0.26  0.41  586.7          100.0  0.81
2      2    1.0  0.05   0.15  0.15  0.10  0.125  0.0705  0.141   0.26  0.41  586.7          100.0  0.81
3      3    1.0  0.05   0.20  0.20  0.15  0.175  0.0705  0.141   0.26  0.41  586.7          100.0  0.81
4      4    1.0  0.05   0.25  0.25  0.20  0.225  0.0705  0.141   0.26  0.41  586.7          100.0  0.81
5      5    2.0  0.05   0.30  0.30  0.25  0.275  0.0705  0.141   0.26  0.41  586.7          100.0  0.81
6      6    2.0  0.05   0.35  0.35  0.30  0.325  0.0705  0.141   0.26  0.41  586.7          100.0  0.81
7      7    2.0  0.05   0.40  0.40  0.35  0.375  0.0705  0.141   0.26  0.41  586.7          100.0  0.81
8      8    2.0  0.05   0.45  0.45  0.40  0.425  0.0705  0.141   0.26  0.41  586.7          100.0  0.81
9      9    2.0  0.05   0.50  0.50  0.45  0.475  0.0705  0.141   0.26  0.41  586.7          100.0  0.81
10    10    2.0  0.90   1.40  1.40  0.50  0.950  0.0705  0.141   0.26  0.41  586.7          100.0  0.81
11    11    2.0  0.90   2.30  2.30  1.40  1.850  0.0705  0.141   0.26  0.41  586.7          100.0  0.81
   Season Crop Type Harvest Date (YYYY/MM/DD)  Harvest Date (Step)  Yield (tonne/ha)  Seasonal irrigation (mm)
0       0     Maize                2019-09-04                  131          3.413355                         0

Code I used to set custom soil:

 custom_soil = SoilClass('custom', CN=46, REW=7, dz=[0.05]*10+[0.9]*2)
custom_soil.add_layer(thickness=0.25,thWP=0.141,
                 thFC=0.26,thS=0.41,Ksat=586.7,
                 penetrability=100)
# custom_soil.add_layer(thickness=0.25,thWP=0.141,
#                  thFC=0.273,thS=0.41,Ksat=518.4,
#                  penetrability=100)
# custom_soil.add_layer(thickness=1.80,thWP=0.141,
#                  thFC=0.268,thS=0.41,Ksat=518.4,
#                  penetrability=100)
custom_soil.add_layer(thickness=2.05,thWP=0.141,
                 thFC=0.26,thS=0.41,Ksat=586.7,
                 penetrability=100)

FutureWarning regarding Pandas loc/iloc in soil.py

Getting the following FutureWarning:

C:\Users\...\miniconda3\lib\site-packages\aquacrop\entities\soil.py:333: FutureWarning: 
In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array.
To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`

Seems like it concerns lines 321-338 and 348-350 in soil.py
Will have a look if I can fix it, seems like a simple patch.

data structures/ namedtuples / structrefs

Some more of the python classess (e.g. FieldMngtClass) still need to be changed into namedtuples.

numba structref currently does not support getting or mutating attributes inside purely python code. This is neccessary for the NewCond data structure as this needs to be accessed and mutated inside both python and AOT compiled code.

Feature Idea: Spatial Extension of aquacrop

Similar to the original GIS extension the idea is to :

  • extend this package to run a high number of simulations in parallel
  • define schema for spatial inputs that are easy on the user
    • this feature could also facilitate the download and preprocessing of reanalysis, remote sensing, or field measurements that spatially resolve aquacrop inputs (air temperature, soil moisture, CO2, water table level, )
  • output crop yield and other results in geospatial formats (.geotiff) and/or in a format that can also store arbitrary N-d metadata, such as date (netcdf)

@kcaylor and I are curious if something like this is already on the roadmap of the original authors/maintainers of this module. The @ecohydro lab is interested in contributing to and using a feature like this and excited to build on top of this impressive implementation!

Custom Crop Creation

Hi Tom,

The problem with Custom Crop creation while mentioning the Planting and Harvest Dates is not resolved yet.
Please look into the issue. Hoping for a quick fix.

Thanks
Divya Dey

In_built_crop
custom_crop

_root_zone_water being called inside functions

Through the line_profile test we can see a good chunk of time is being spend in the transpiration, canopy_cover, harvest index functions. These functions all call inner functions such as _root_zone_water which prevents us from AOT compiling them (#33 ). From a quick glance it appears as though _root_zone_water could instead be called just before these functions are called, with the _root_zone_water return arguments then being passed on to the transpiration/canopy cover function.

questions about developer setup, improvements

Hi @thomasdkelly,

First I would like to take a moment to appreciate your effort here. Great initiative to create a FOSS AquaCrop implementation!

I am a freelance GIS developer, looking at spending substantial amount of time using your aquacrop module this year. (See more explanation in the bottom 👇)

Do you welcome PRs and ideas about fixes/improvements (performance, code architecture)?
If yes what would be the 'right' developer setup as of now? Before the holidays I did a dev. setup on my machine (via nbdev) , but as I understand from #16 you are moving away from it now?

_I got hired for a project within the context of analysis ready GIS/EO data for the CEE region.
As part of a 'showcase', we would build a crop modelling solution that takes EO/GIS derived inputs from a data platform of ESA, and run the model. The goal is to make the process of model setup quicker and easier, but also to provide some optimization features.

update notebooks

Have just experienced an issue where google colab cannot find the latest version of aquacrop==2.1, despite everything uploading correctly. So will add an extra cell to the notebooks that allows people to install direct from github
!pip install git+https://github.com/aquacropos/aquacrop

Also will add a cell that allows people to run in pure python rather than have to compile the modules.

import os
os.environ['DEVELOPMENT'] = 'True'

Im not sure how many people will find it useful but is worth adding in.

attempt to compile AOT function fails

When I run the aquacrop-streamlit app, I get this error

RuntimeError: Attempted to compile AOT function without the compiler used by `numpy.distutils` present. If using conda try: #> conda install gcc_linux-64 gxx_linux-64

I'm setting up dependencies in a venv and not using conda. This may mean we need to add the gcc compiler dependency for a specific architecture family to the aquacrop dependencies: https://numba.pydata.org/numba-doc/dev/user/pycc.html

There is no output yield difference between two soil types!

I expected to have a significant difference when you compare the yield results between the Loam and Sand soil types. However, when I'm running the model the median yield of two soil types is very close. Here is the output:
Screenshot from 2021-07-02 19-28-26

I have used the code from Notbook1.ipynb

numpy version requirement

A recent merge changed the numpy requirement to numpy>=1.21.

As of wiriting the current version is 1.22.1 so our requirement is quite stringent. Not sure if this is completely necessary.

numpy=1.21 also requires python=3.8 so this has caused me an error when trying to run setup.py within aquacrop.

ModuleNotFoundError: No module named 'aquacrop.solution.solution_root_zone_water'

  • Using Python v3.10.
  • Created virtual environment
  • pip install aquacrop
  • Created test.py using aquacrop's suggested initial example
  • python test.py
  • Received the subject error message, there appears to be a missing module

No module named aquacrop.scripts.initiate_library
Traceback (most recent call last):
File "", line 1027, in _find_and_load
File "", line 1006, in _find_and_load_unlocked
File "", line 688, in _load_unlocked
File "", line 883, in exec_module
File "", line 241, in call_with_frames_removed
File "D:\NewIrrigationExperiment\AquaCrop-Python\venv\lib\site-packages\aquacrop_init
.py", line 3, in
from .core import AquaCropModel
File "D:\NewIrrigationExperiment\AquaCrop-Python\venv\lib\site-packages\aquacrop\core.py", line 48, in
from .timestep.run_single_timestep import solution_single_time_step
File "D:\NewIrrigationExperiment\AquaCrop-Python\venv\lib\site-packages\aquacrop\timestep\run_single_timestep.py", line 12, in
from ..solution.irrigation import irrigation
File "D:\NewIrrigationExperiment\AquaCrop-Python\venv\lib\site-packages\aquacrop\solution\irrigation.py", line 7, in
from .solution_root_zone_water import root_zone_water
ModuleNotFoundError: No module named 'aquacrop.solution.solution_root_zone_water'

importerror (outdated PyPi?)

steps to reproduce:

virtualenv venv
source venv/bin/activate
pip install aquacrop
python
>>> from aquacrop import AquaCropModel
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name 'AquaCropModel' from 'aquacrop' (/media/fee/data/Git/aquacrop-xs/venv/lib/python3.10/site-packages/aquacrop/__init__.py)
>>> from aquacrop.core import AquaCropModel
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/media/fee/data/Git/aquacrop-xs/venv/lib/python3.10/site-packages/aquacrop/core.py", line 12, in <module>
    from .timestep import *
  File "/media/fee/data/Git/aquacrop-xs/venv/lib/python3.10/site-packages/aquacrop/timestep.py", line 4, in <module>
    from .solution import *
  File "/media/fee/data/Git/aquacrop-xs/venv/lib/python3.10/site-packages/aquacrop/solution.py", line 44, in <module>
    from .solution_aot import (
ModuleNotFoundError: No module named 'aquacrop.solution_aot'

However, if I clone the repo and install from there, it works:

virtualenv venv
source venv/bin/activate
pip install git+https://github.com/aquacropos/aquacrop@master
python
>>> from aquacrop import AquaCropModel
 Compiling modules... This could take some time.
 Note: The compilation is only necessary the first time that the library is used.

I think this has to do with the PyPi being outdated?

Correction to Notebook 2

In the tutorial at https://colab.research.google.com/github/aquacropos/aquacrop/blob/master/docs/notebooks/AquaCrop_OSPy_Notebook_2.ipynb#scrollTo=w4OIG8Y1VSXx, Notebook 2, Irrigation Management:

It appears as if the use of IrrigationManagment within AquaCropModel requires the importation of IrrigationManagement from aquacrop. It was necessary to modify the first import line to: from aquacrop import AquaCropModel, Soil, Crop, InitialWaterContent, IrrigationManagement, rather than only what was done in Notebook 1.

remove pathlib

Currently pathlib is only used once in initialize.py and isnt really neccesarry as it adds another dependency

Compilation inside Docker: ModuleNotFoundError: No module named 'aquacrop.solution.solution_root_zone_water'

Hello,

I have problems compiling the library. I am trying to create a django API around it.

Any ideas?

Thanks in advance!

api_1  | Exception in thread django-main-thread:
api_1  | Traceback (most recent call last):
api_1  |   File "/usr/local/lib/python3.10/threading.py", line 1016, in _bootstrap_inner
api_1  |     self.run()
api_1  |   File "/usr/local/lib/python3.10/threading.py", line 953, in run
api_1  |     self._target(*self._args, **self._kwargs)
api_1  |   File "/usr/local/lib/python3.10/site-packages/django/utils/autoreload.py", line 64, in wrapper
api_1  |     fn(*args, **kwargs)
api_1  |   File "/usr/local/lib/python3.10/site-packages/django/core/management/commands/runserver.py", line 134, in inner_run
api_1  |     self.check(display_num_errors=True)
api_1  |   File "/usr/local/lib/python3.10/site-packages/django/core/management/base.py", line 487, in check
api_1  |     all_issues = checks.run_checks(
api_1  |   File "/usr/local/lib/python3.10/site-packages/django/core/checks/registry.py", line 88, in run_checks
api_1  |     new_errors = check(app_configs=app_configs, databases=databases)
api_1  |   File "/usr/local/lib/python3.10/site-packages/django/core/checks/urls.py", line 14, in check_url_config
api_1  |     return check_resolver(resolver)
api_1  |   File "/usr/local/lib/python3.10/site-packages/django/core/checks/urls.py", line 24, in check_resolver
api_1  |     return check_method()
api_1  |   File "/usr/local/lib/python3.10/site-packages/django/urls/resolvers.py", line 480, in check
api_1  |     for pattern in self.url_patterns:
api_1  |   File "/usr/local/lib/python3.10/site-packages/django/utils/functional.py", line 49, in __get__
api_1  |     res = instance.__dict__[self.name] = self.func(instance)
api_1  |   File "/usr/local/lib/python3.10/site-packages/django/urls/resolvers.py", line 696, in url_patterns
api_1  |     patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
api_1  |   File "/usr/local/lib/python3.10/site-packages/django/utils/functional.py", line 49, in __get__
api_1  |     res = instance.__dict__[self.name] = self.func(instance)
api_1  |   File "/usr/local/lib/python3.10/site-packages/django/urls/resolvers.py", line 689, in urlconf_module
api_1  |     return import_module(self.urlconf_name)
api_1  |   File "/usr/local/lib/python3.10/importlib/__init__.py", line 126, in import_module
api_1  |     return _bootstrap._gcd_import(name[level:], package, level)
api_1  |   File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
api_1  |   File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
api_1  |   File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
api_1  |   File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
api_1  |   File "<frozen importlib._bootstrap_external>", line 883, in exec_module
api_1  |   File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
api_1  |   File "/code/backend/urls.py", line 20, in <module>
api_1  |     path("api/v1/", include("webapi.urls")),
api_1  |   File "/usr/local/lib/python3.10/site-packages/django/urls/conf.py", line 38, in include
api_1  |     urlconf_module = import_module(urlconf_module)
api_1  |   File "/usr/local/lib/python3.10/importlib/__init__.py", line 126, in import_module
api_1  |     return _bootstrap._gcd_import(name[level:], package, level)
api_1  |   File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
api_1  |   File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
api_1  |   File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
api_1  |   File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
api_1  |   File "<frozen importlib._bootstrap_external>", line 883, in exec_module
api_1  |   File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
api_1  |   File "/code/webapi/urls.py", line 3, in <module>
api_1  |     from webapi import views
api_1  |   File "/code/webapi/views.py", line 5, in <module>
api_1  |     from simulations.aquacrop import AquacropSimulationSerializer
api_1  |   File "/code/simulations/aquacrop/__init__.py", line 2, in <module>
api_1  |     from .simulation.serializer import AquacropSimulationSerializer
api_1  |   File "/code/simulations/aquacrop/simulation/serializer.py", line 6, in <module>
api_1  |     from ..crops import crops_map
api_1  |   File "/code/simulations/aquacrop/crops/__init__.py", line 1, in <module>
api_1  |     from .barley import BarleyRainfed
api_1  |   File "/code/simulations/aquacrop/crops/barley.py", line 1, in <module>
api_1  |     from aquacrop import Crop
api_1  |   File "/usr/local/lib/python3.10/site-packages/aquacrop/__init__.py", line 3, in <module>
api_1  |     from .core import AquaCropModel
api_1  |   File "/usr/local/lib/python3.10/site-packages/aquacrop/core.py", line 48, in <module>
api_1  |     from .timestep.run_single_timestep import solution_single_time_step
api_1  |   File "/usr/local/lib/python3.10/site-packages/aquacrop/timestep/run_single_timestep.py", line 12, in <module>
api_1  |     from ..solution.irrigation import irrigation
api_1  |   File "/usr/local/lib/python3.10/site-packages/aquacrop/solution/irrigation.py", line 7, in <module>
api_1  |     from .solution_root_zone_water import root_zone_water
api_1  | ModuleNotFoundError: No module named 'aquacrop.solution.solution_root_zone_water'

Effect from ground water table depth seems unstable

Hi, I'm playing around with the groundwater effect and getting unexpected results. Here is a plot of the AquaCrop_OSPy_Notebook_1.ipynb notebook example case, first season, with reduced precipitation, and running it with different constant water table levels. Any idea what is going on here? Is it a feature of the model or maybe something with the implementation?

image

Code to reproduce with the AquaCrop_OSPy_Notebook_1.ipynb notebook example:

import numpy as np

depths = np.linspace(1.0,5.0)
df_result = pd.DataFrame()
weather_data2 = weather_data.copy()
weather_data2['Precipitation'] = weather_data2['Precipitation']/10 # too much rain for ground water effect in the original
for d in depths:
    gw_model = AquaCropModel(SimStartTime=f'{1979}/10/01',
                      SimEndTime=f'{1980}/04/30',
                      wdf=weather_data2,
                      Soil=sandy_loam,
                      Crop=wheat,
                      InitWC=InitWC,
                      Groundwater=GwClass(WaterTable='Y',
                                       dates=[f'{1979}/10/01'],
                                       values=[d])
                    )
    gw_model.initialize()
    gw_model.step(till_termination=True)
    gw_model.Outputs.Final['water_table'] = d

    df_result = pd.concat([df_result, gw_model.Outputs.Final])

plt.plot(df_result['water_table'], df_result['Yield (tonne/ha)'])
plt.xlabel('water_table')
plt.ylabel('yield')

Maybe related, If I pick a depth of 2.142857 , (low yield case), one soil layer seems 'empty' from the start.
image

IndexError when model's end date falls on planting date

Happens when sim_end_time's MM/DD is the same as planting_date.

E.g. if I run:

soil = Soil('SandyLoam')
crop = Crop('Maize', planting_date='05/03')  #Same MM/DD as in sim_end_time
init_wc = InitialWaterContent(value=['FC'])
wdf = prepare_weather(get_filepath('tunis_climate.txt'))

model = AquaCropModel(
    sim_start_time='1981/05/02',
    sim_end_time='1982/05/03',
    weather_df=wdf,
    soil=soil,
    crop=crop,
    initial_water_content=init_wc
)

model.run_model(till_termination=True)

I get the error:

Traceback (most recent call last):
  File "/home/aron/dev/cropom/aquacrop/aron.py", line 26, in <module>
    model.run_model(till_termination=True)
  File "/home/aron/dev/cropom/aquacrop/aquacrop/core.py", line 285, in run_model
    ) = self._perform_timestep()
  File "/home/aron/dev/cropom/aquacrop/aquacrop/core.py", line 351, in _perform_timestep
    clock_struct, _init_cond, param_struct = update_time(
  File "/home/aron/dev/cropom/aquacrop/aquacrop/timestep/update_time.py", line 66, in update_time
    clock_struct.step_end_time = clock_struct.time_span[
  File "/home/aron/dev/cropom/aquacrop/venv/lib/python3.10/site-packages/pandas/core/indexes/base.py", line 5363, in __getitem__
    return getitem(key)
  File "/home/aron/dev/cropom/aquacrop/venv/lib/python3.10/site-packages/pandas/core/arrays/datetimelike.py", line 358, in __getitem__
    "Union[DatetimeLikeArrayT, DTScalarOrNaT]", super().__getitem__(key)
  File "/home/aron/dev/cropom/aquacrop/venv/lib/python3.10/site-packages/pandas/core/arrays/_mixins.py", line 289, in __getitem__
    result = self._ndarray[key]
IndexError: index 367 is out of bounds for axis 0 with size 367

Process finished with exit code 1

Tested on up to date master branch

change net irrigation requirement to RAW

AquaCrop windows specifies the net irrigation thresholds as a %RAW (readily available water) instead of TAW (total available water). These are slightly different quantites and make it hard to compare python-windows versions.

So just need to add the ability to set the threshold as a %RAW

biomass_accumulation doesn't handle Et0=0.0

When running the brussels_climate.txt included dataset, there is a datapoint with ET=0 on 16/12/1980: 16 12 1980 1.7 6.9 0.2 0.0 .

This raises a ZeroDivisionError when running model.step on biomass_accumulation. We believe it's because of the Et0 denominator on https://github.com/thomasdkelly/aquacrop/blob/f4c489dcb5073096047e09d60aac7658ec1f2bd0/aquacrop/solution.py#L3732-L3734 , and we could either try/catch, or use numpy to cast the floats and ensure we get NaN/Inf for such cases (https://stackoverflow.com/questions/10011707/how-to-get-nan-when-i-divide-by-zero).

tested using the collab Notebook 1, only switching the dataset. stack trace from %xmode Verbose

---------------------------------------------------------------------------
ZeroDivisionError                         Traceback (most recent call last)
<ipython-input-113-6829cdd20957> in <module>()
      2 model.initialize()
      3 # run model till termination
----> 4 model.step(till_termination=True)
        global model.step = <bound method AquaCropModel.step of <aquacrop.core.AquaCropModel object at 0x7ff2733f5ba8>>
        global till_termination = undefined

2 frames
/usr/local/lib/python3.6/dist-packages/aquacrop/timestep.py in solution(InitCond=<numba.experimental.jitclass.boxing.InitCondClass object>, ParamStruct=<aquacrop.classes.ParamStructClass object>, ClockStruct=<aquacrop.classes.ClockStructClass object>, weather_step=array([1.7, 6.9, 0.2, 0.0, Timestamp('1980-12-16 00:00:00')], dtype=object), Outputs=<aquacrop.classes.OutputClass object>)
    194 
    195     # 16. Biomass accumulation
--> 196     NewCond = biomass_accumulation(Crop,NewCond,Tr,TrPot_NS,Et0,GrowingSeason)
        NewCond = <numba.experimental.jitclass.boxing.InitCondClass object at 0x7ff26c0e8390>
        global biomass_accumulation = CPUDispatcher(<function biomass_accumulation at 0x7ff27eafb730>)
        Crop = <numba.experimental.jitclass.boxing.CropStruct object at 0x7ff26c0e8670>
        Tr = 0.0
        TrPot_NS = 0.0
        Et0 = 0.0
        GrowingSeason = True
    197 
    198 

Don't have the silt stress

The last version aquacrop v2.2.3 don't have the stress of silt, howerver, this is not fit in most of act soil.
if i want to add the silt stress, we must put in the soil class、crop class、and so many place to add. so can someone give advices about how to add silt stress.

Use aquacrop-eto in lars functions

The evapotranspiration equations need updating within the lars module. This module may end up not staying anyway but if it does we can use the new aquacrop-eto package

Groundwater table never change

I have groundwater depth observations and I put them into aquacrop as follows,

# initialize the model    
 model_os = AquaCropModel(
              sim_start_time=plantingDate[0].strftime('%Y/%m/%d'),
              sim_end_time=harvestDate[-1].strftime('%Y/%m/%d'),
              weather_df=weather_df,
              soil=soil,
              crop=cropObj,
              initial_water_content=InitialWaterContent(value=['FC']),
              groundwater = GroundWater(water_table="Y", method="Variable", dates=GWT_dates, values=GWT),
              irrigation_management=irr)

the GWT_dates is a datetime list and the GWT is the corresponding groundwater depth (m)
image
image
However, the z_gw in the output just never change and it keeps the initial value of the observed GWT.
image
I've done a little bit tracking I found the variable “NewCond.z_gw” seems like never been updated. Did I miss anything?

minor edits to the compilation code

  • use tqdm.auto so that the progress bar can be seen in notebooks
  • replace python with sys.executable in the compile command (as I have found errors when using remote servers)
    subprocess.run([f"{sys.executable}", "-m", mod])
    call(["python", "-m", mod])

change tutorial notebook links

After the recent docs and organizational changes, the links to the tutorial notebooks need to be changed to their new locations

time to import package

Congratulation for the afford to do the Aquacrop available in Python. I am try to use it and I have two questions:

  1. Why it take too long time to import aquacrop:
import time

start = time.time()
import aquacrop
print(time.time() - start)

It is taken ~33 s in my computer. I am using the IDE Pycharm Community, but it is the first time I have this issue.

  1. When I run the code:

import matplotlib.pyplot as plt
import time
# from aquacrop.classes import *
# from aquacrop.core import *

start = time.time()
import aquacrop
print(time.time() - start)

filepath = './Weather.txt'

weather_data = aquacrop.prepare_weather(filepath)
weather_data

sandy_loam = aquacrop.SoilClass(soilType='SandyLoam')
wheat = aquacrop.CropClass('Wheat', PlantingDate='09/01')

InitWC = aquacrop.InitWCClass(value=['FC'])
model = aquacrop.AquaCropModel(SimStartTime=f'{1980}/01/01',
                      SimEndTime=f'{2123}/12/30',
                      wdf=weather_data,
                      Soil=sandy_loam,
                      Crop=wheat,
                      InitWC=InitWC)

# initilize model
start = time.time()
model.initialize()
# run model till termination
model.step(till_termination=True)
print(time.time() - start)
model.Outputs.Final.head() # this is not working 

In the Python console, whatever I do in the prompt line (ex: >>> 1+1) it will return the result and some garbage, as bellow:

>>> 1+1
2
Name: SandyLoam
zSoil: 1.6
nComp: 12
nLayer: 1
AdjREW: 1
REW: 7
CalcCN: 0
CN: 46
zRes: -999
EvapZsurf: 0.04
EvapZmin: 0.15
EvapZmax: 0.3
Kex: 1.1
fevap: 4
fWrelExp: 0.4
fwcc: 50
zCN: 0.3
zGerm: 0.3
AdjCN: 1
fshape_cr: 16
zTop: 0.1
Hydrology:        Comp  zBot  zTop  zMid  ...  penetrability  tau  th_fc_Adj   dz
Layer                          ...                                    
1       5.5  0.65  0.55   0.6  ...          100.0  1.0       0.22  1.6
[1 rows x 13 columns]
Profile: <numba.experimental.jitclass.boxing.SoilProfileClass object at 0x7f665dbfb340>

Thanks.

create script to read in windows AquaCrop input files and convert into python inputs

Currently creating and comparing new crops from the Windows version is a long and tedious job. This could be made slightly easier by creating a function to read in AquaCrop input files and convert to python params.

This sadly cannot be done for all the relevant parameters as some can only be found within the GUI interface, however this should help massively.

Further, creating a notebook to accompany this (which produces outputs similar to in comparison.ipynb) which guides users to quickly converting their own crops from windows to python versions.

This will be a really important feature in getting people who are familiar with AquaCrop windows to try the python version, as well as alowing us to quickly expand the number of built in crops.

Seperating out crop paramaters into seperate crop_config.py file will likely also help later down the road

multi layer custom soil bug

Will fully detail the bug over the next few days but the summary is:

  • Creating a custom soil profile with one layer works as expected.
  • Creating an identical soil profile but using multiple layers results in crop failure under stressed/non irrigated conditions

forum down

The forum went down a yesterday so am using this as an excuse to pivot away from having a seperate forum and just keeping all discussion on this github repo. PLease direct all comments and discussion to the Discussions section above, or by creating issues and PRs

Change irrigation mode

Dear teachers:
When I try to use Predefined irrigation schedule (IrrMethod=3) and Input different schedules,but running IrrigationManagement(irrigation_method=3,schedule=schedule),the schedule all will become empty,and then runing the model core the schedule all will become zero,in model._outputs ,the Seasonal irrigation all is zero. I hope teachers can help me solve this problem。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.