Skip to content

Commit

Permalink
Merge pull request #113 from Bowhaven/v7-improvements
Browse files Browse the repository at this point in the history
V2.3 update
  • Loading branch information
chris-s-bowden authored Jan 9, 2024
2 parents f8456ba + 82173ad commit f42ba14
Show file tree
Hide file tree
Showing 51 changed files with 30,306 additions and 1,813 deletions.
407 changes: 406 additions & 1 deletion .gitignore

Large diffs are not rendered by default.

11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,18 @@ A number of tutorials has been created (more to be added in future) to help user
3. <a href=https://colab.research.google.com/github/aquacropos/aquacrop/blob/master/docs/notebooks/AquaCrop_OSPy_Notebook_3.ipynb>Optimisation of irrigation management strategies</a>
4. <a href=https://colab.research.google.com/github/aquacropos/aquacrop/blob/master/docs/notebooks/AquaCrop_OSPy_Notebook_4.ipynb>Projection of climate change impacts</a>

## AquaPlan

The latest development is a streamlit-based web application AquaPlan, a powerful crop management tool that enables farmers, businesses, and governments to make more informed decisions about water management, irrigation investments, and climate risks.
## Installation troubleshooting
If you receive an error message such as "No module named aquacrop.scripts.initiate_library" or "ModuleNotFoundError: No module named 'aquacrop.solution.solution_root_zone_water'", please try the following troubleshooting steps:

You can access AquaPlan using the following link: https://tinyurl.com/aquaplan.
1. Run "python -m aquacrop.scripts.initiate_library" in your terminal, if this generates an error such as "RuntimeError: Attempted to compile AOT function without the compiler used by numpy.distutils present. Cannot find suitable msvc.", then you need to download and install an MSVC compiler such as the one included in Visual Studio build tools (see https://www.youtube.com/watch?v=p_R3tXSq0KI).

2. If Step 1 doesn't help, then you can run aquacrop in pure python (this will be slower) using: <br>
```import os```<br>
```os.environ['DEVELOPMENT'] = 'DEVELOPMENT'```

More information, including screenshots and gifs, can be found at The University of Manchester's [article](https://www.manchester.ac.uk/discover/news/manchester-scientists-launch-new-interactive-tool-for-agricultural-water-management-and-climate-risk-assessment/), Tim Foster's medium [post](https://medium.com/@agwater/aquaplan-a-new-interactive-tool-for-agricultural-water-management-and-climate-risk-assessment-82c50cb10144), or twitter [thread](https://twitter.com/tim_foster_88/status/1557728807758737408).

A seperate [category](https://github.com/aquacropos/aquacrop/discussions/categories/aquaplan) inside the AquaCrop-OSPy forum has been created to discuss
AquaPlan, including any issues, questions, or suggestions.

53 changes: 45 additions & 8 deletions aquacrop/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import datetime
import os
import logging
import warnings
from typing import Dict, Union, Optional, Tuple, TYPE_CHECKING
from .scripts.checkIfPackageIsCompiled import compile_all_AOT_files

Expand Down Expand Up @@ -37,7 +38,7 @@
from .entities.output import Output
from .initialize.compute_variables import compute_variables
from .initialize.create_soil_profile import create_soil_profile
from .initialize.read_clocks_parameters import read_clock_paramaters
from .initialize.read_clocks_parameters import read_clock_parameters
from .initialize.read_field_managment import read_field_management
from .initialize.read_groundwater_table import read_groundwater_table
from .initialize.read_irrigation_management import read_irrigation_management
Expand All @@ -49,7 +50,6 @@
from .timestep.update_time import update_time
from .timestep.outputs_when_model_is_finished import outputs_when_model_is_finished


class AquaCropModel:
"""
This is the main class of the AquaCrop-OSPy model.
Expand Down Expand Up @@ -81,6 +81,9 @@ class AquaCropModel:
co2_concentration: Defines CO2 concentrations
off_season: (True) simulate off-season or (False) skip ahead to start of
next growing season
"""

Expand Down Expand Up @@ -110,16 +113,30 @@ def __init__(
fallow_field_management: Optional["FieldMngt"] = None,
groundwater: Optional["GroundWater"] = None,
co2_concentration: Optional["CO2"] = None,
off_season: bool=False,
) -> None:

self.sim_start_time = sim_start_time
self.sim_end_time = sim_end_time
self.weather_df = weather_df
self.soil = soil
self.crop = crop
self.initial_water_content = initial_water_content
self.initial_water_content = initial_water_content
self.co2_concentration = co2_concentration

self.off_season = off_season

iwc_layers = len(initial_water_content.value)
soil_layers = self.soil.nLayer

########################### No longer believe the below check is required, I think that the number of layers in soil and initWC can be mismatched, they're separate.
# If number of layers in IWC do not match number of soil layers in soil profile, change them to match and warn user of changes made
# if check_iwc_soil_match(iwc_layers, soil_layers) is False:
# new_water_layers = ['FC'] * soil_layers
# new_water_depths = list(range(1, soil_layers+1,1))
# self.initial_water_content.value=new_water_layers
# self.initial_water_content.depth_layer=new_water_depths
# print(f"Initial water content layers ({iwc_layers}) do not match number of soil layers ({soil_layers}), initial water content layers now set to: {self.initial_water_content.value}")

self.irrigation_management = irrigation_management
self.field_management = field_management
self.fallow_field_management = fallow_field_management
Expand Down Expand Up @@ -198,8 +215,8 @@ def _initialize(self) -> None:
"""

# Initialize ClockStruct object
self._clock_struct = read_clock_paramaters(
self.sim_start_time, self.sim_end_time
self._clock_struct = read_clock_parameters(
self.sim_start_time, self.sim_end_time, self.off_season
)

# get _weather data
Expand Down Expand Up @@ -233,7 +250,7 @@ def _initialize(self) -> None:

# read, calculate inital conditions
self._param_struct, self._init_cond = read_model_initial_conditions(
self._param_struct, self._clock_struct, self.initial_water_content
self._param_struct, self._clock_struct, self.initial_water_content, self.crop
)

self._param_struct = create_soil_profile(self._param_struct)
Expand Down Expand Up @@ -349,7 +366,7 @@ def _perform_timestep(

# Update time step
clock_struct, _init_cond, param_struct = update_time(
clock_struct, new_cond, param_struct, self._weather
clock_struct, new_cond, param_struct, self._weather, self.crop
)

# Create _outputsdataframes when model is finished
Expand Down Expand Up @@ -442,6 +459,26 @@ def get_additional_information(self) -> Dict[str, Union[bool, float]]:
)


def check_iwc_soil_match(iwc_layers: int, soil_layers: int) -> bool:
"""
This function checks if the number of soil layers is equivalent between the user-specified soil profile and initial water content.
Arguments:
iwc_layers
soil_layers
Return:
boolean: True if number of layers match
"""
if(iwc_layers == soil_layers):
return True
else:
return False




def _sim_date_format_is_correct(date: str) -> bool:
"""
This function checks if the start or end date of the simulation is in the correct format.
Expand Down
147 changes: 63 additions & 84 deletions aquacrop/data/MaunaLoaCO2.txt
Original file line number Diff line number Diff line change
@@ -1,84 +1,63 @@
%% ----------- CO2 concentration at Mauna Loa for AquaCropOS ----------- %%
Year CO2(ppm)
1902 297.4
1905 298.2
1912 300.7
1915 301.3
1924 304.5
1926 305.0
1929 305.2
1932 307.8
1934 309.2
1936 307.9
1938 310.5
1939 310.1
1940 310.5
1944 309.7
1948 310.7
1953 311.9
1954 314.1
1958 315.29
1959 315.98
1960 316.91
1961 317.65
1962 318.45
1963 318.99
1964 319.61
1965 320.03
1966 321.37
1967 322.18
1968 323.05
1969 324.62
1970 325.68
1971 326.32
1972 327.46
1973 329.68
1974 330.17
1975 331.08
1976 332.06
1977 333.78
1978 335.40
1979 336.78
1980 338.70
1981 340.11
1982 341.22
1983 342.84
1984 344.40
1985 345.87
1986 347.19
1987 348.98
1988 351.45
1989 352.89
1990 354.16
1991 355.48
1992 356.27
1993 356.95
1994 358.63
1995 360.62
1996 362.37
1997 363.47
1998 366.50
1999 368.14
2000 369.41
2001 371.13
2002 373.22
2003 375.77
2004 377.49
2005 379.80
2006 381.90
2007 383.77
2008 385.59
2009 387.37
2010 389.85
2011 391.63
2012 393.82
2013 396.48
2014 398.55
2015 401.01
2016 404.41
2017 406.76
2018 408.72
2019 411.66
2020 414.24
2021 416.45
2099 597.77
%% ---- Manua Loa observations 1959-2009 & IPCC projections for A1B scenario with BERN model ---- %%
Year CO2(ppm)
1959 315.98
1960 316.91
1961 317.64
1962 318.45
1963 318.99
1964 319.62
1965 320.04
1966 321.38
1967 322.16
1968 323.04
1969 324.62
1970 325.68
1971 326.32
1972 327.45
1973 329.68
1974 330.17
1975 331.08
1976 332.05
1977 333.78
1978 335.41
1979 336.78
1980 338.68
1981 340.11
1982 341.22
1983 342.84
1984 344.41
1985 345.87
1986 347.19
1987 348.98
1988 351.45
1989 352.9
1990 354.16
1991 355.48
1992 356.27
1993 356.95
1994 358.64
1995 360.62
1996 362.36
1997 363.47
1998 366.5
1999 368.14
2000 369.4
2001 371.07
2002 373.17
2003 375.78
2004 377.52
2005 379.76
2006 381.85
2007 383.71
2008 385.57
2009 387.35
2010 388
2020 418
2030 447
2040 483
2050 522
2060 563
2070 601
2080 639
2090 674
2100 703
Loading

0 comments on commit f42ba14

Please sign in to comment.