Skip to content

Commit

Permalink
Merge pull request #117 from chris-s-bowden/v7-improvements
Browse files Browse the repository at this point in the history
v3.0 update
  • Loading branch information
chris-s-bowden authored Jan 11, 2024
2 parents ecd985d + 5fc2e4c commit 2c80879
Show file tree
Hide file tree
Showing 23 changed files with 1,763 additions and 2,724 deletions.
52 changes: 26 additions & 26 deletions .github/workflows/unittest.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
name: Test library with unittest.
on:
push:
branches:
- master
pull_request:
branches:
- master
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
python-version: [3.7, 3.8, 3.9, '3.10']
os: [ubuntu-latest, windows-latest, macOS-latest]
steps:
- uses: actions/checkout@v3
- name: Set up all python version
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
architecture: x64
- name: Install dependencies
run: pip install -r requirements.txt
- name: Run Test
run: python -m unittest
name: Test library with unittest.
on:
push:
branches:
- master
pull_request:
branches:
- master
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
python-version: [3.8, 3.9, '3.10']
os: [ubuntu-latest]
steps:
- uses: actions/checkout@v3
- name: Set up all python version
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
architecture: x64
- name: Install dependencies
run: pip install -r requirements.txt
- name: Run Test
run: python -m unittest
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -571,3 +571,5 @@ v7_final_tidying.pptx
*.xlsx

outputs/

test_test.py
35 changes: 22 additions & 13 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
{
"python.linting.enabled": true,
"python.linting.flake8Enabled": false,
"python.linting.mypyEnabled": true,
"python.linting.flake8Args": [
"--max-line-length=200",
],
"python.linting.pylintEnabled": true,
"python.linting.pylintArgs": [
"--disable=used-before-assignment"
],
"python.formatting.provider": "black",

{
"python.linting.enabled": true,
"python.linting.flake8Enabled": false,
"python.linting.mypyEnabled": true,
"python.linting.flake8Args": [
"--max-line-length=200",
],
"python.linting.pylintEnabled": true,
"python.linting.pylintArgs": [
"--disable=used-before-assignment"
],
"python.formatting.provider": "black",
"python.testing.unittestArgs": [
"-v",
"-s",
"./tests",
"-p",
"test_*.py"
],
"python.testing.pytestEnabled": false,
"python.testing.unittestEnabled": true,

}
2 changes: 0 additions & 2 deletions aquacrop/solution/biomass_accumulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,6 @@ def biomass_accumulation(
else:
WPadj = Crop.WP

# print(WPadj)

# Adjust WP for CO2 effects
WPadj = WPadj * Crop.fCO2

Expand Down
4 changes: 0 additions & 4 deletions aquacrop/solution/capillary_rise.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,10 @@ def capillary_rise(
zBot = prof.dzsum[-1]
zBotMid = prof.zMid[-1]
prof = prof
# print(f'Cap rise L68, Ksat = {prof.Ksat[-1]}')
if (prof.Ksat[-1] > 0) and (z_gw > 0) and ((z_gw - zBotMid) < 4):
if zBotMid >= z_gw:
MaxCR = 99
else:
# print(f'Cap rise L73, aCR = {prof.aCR[-1]}, bCR = {prof.bCR[-1]}')
MaxCR = np.exp((np.log(z_gw - zBotMid) - prof.bCR[-1]) / prof.aCR[-1])
if MaxCR > 99:
MaxCR = 99
Expand Down Expand Up @@ -181,12 +179,10 @@ def capillary_rise(
if compi > -1:

zBotMid = zBot - (prof.dz[compi] / 2)
# print(f'Cap rise L182, Ksat = {prof.Ksat[compi]}')
if (prof.Ksat[compi] > 0) and (z_gw > 0) and ((z_gw - zBotMid) < 4):
if zBotMid >= z_gw:
LimCR = 99
else:
# print(f'Cap rise L187, aCR = {prof.aCR[compi]}, bCR = {prof.bCR[compi]}')
LimCR = np.exp((np.log(z_gw - zBotMid) - prof.bCR[compi]) / prof.aCR[compi])
if LimCR > 99:
LimCR = 99
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
100 changes: 50 additions & 50 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,50 +1,50 @@
[metadata]
name = aquacrop
version = 2.2.3
author = Thomas Kelly
author_email = thomas.kelly-2@manchester.ac.uk
description = Soil-Crop-Water model based on AquaCrop-OS.
long_description = file: README.md
long_description_content_type= text/markdown
keywords = aquacrop, aquacropos, aquacrop-ospy, python
url = https://github.com/aquacropos/aquacrop
project_urls =
Bug Tracker = https://github.com/aquacropos/aquacrop/issues
classifiers =
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
License :: OSI Approved :: MIT License
Operating System :: MacOS
Operating System :: Microsoft
Operating System :: POSIX :: Linux
Natural Language :: English

[options]
install_requires =
numba>=0.56.0
numpy>=1.18.0,<1.22.0
pandas>=1.3.5
tqdm>=4.64.0
cffi==1.15.0
setup_requires =
numba>=0.56.0
numpy>=1.18.0,<1.22.0
pandas>=1.3.5
tqdm>=4.64.0
cffi==1.15.0
include_package_data = True
packages = find:
python_requires = >=3.7

[options.packages.find]
exclude =
examples*
tools*
docs*
aquacrop.tests*
test*
scripts*
venv*

[metadata]
name = aquacrop
version = 3.0
author = Tim Foster
author_email = timothy.foster@manchester.ac.uk
description = Soil-Crop-Water model based on AquaCrop-OS.
long_description = file: README.md
long_description_content_type= text/markdown
keywords = aquacrop, aquacropos, aquacrop-ospy, python
url = https://github.com/aquacropos/aquacrop
project_urls =
Bug Tracker = https://github.com/aquacropos/aquacrop/issues
classifiers =
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
License :: OSI Approved :: MIT License
Operating System :: MacOS
Operating System :: Microsoft
Operating System :: POSIX :: Linux
Natural Language :: English

[options]
install_requires =
numba>=0.56.0
numpy==1.22.0
pandas>=1.3.5
tqdm>=4.64.0
cffi==1.15.0
setup_requires =
numba>=0.56.0
numpy==1.22.0
pandas>=1.3.5
tqdm>=4.64.0
cffi==1.15.0
include_package_data = True
packages = find:
python_requires = >=3.7

[options.packages.find]
exclude =
examples*
tools*
docs*
aquacrop.tests*
test*
scripts*
venv*

46 changes: 46 additions & 0 deletions tests/pytest_testing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import pandas as pd

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

from aquacrop import (
AquaCropModel,
Soil,
Crop,
InitialWaterContent,
IrrigationManagement,
)
from aquacrop.utils import prepare_weather, get_filepath


_sim_start = "1982/05/01"
_sim_end = "1983/10/30"

weather_file_path = get_filepath("champion_climate.txt")

_weather_data = prepare_weather(weather_file_path)

_sandy_loam = Soil(soil_type="SandyLoam")
_wheat = Crop("Maize", planting_date="05/01")
_initial_water_content = InitialWaterContent(value=["FC"])

irrigation = IrrigationManagement(irrigation_method=0)

model_os = AquaCropModel(
sim_start_time=_sim_start,
sim_end_time=_sim_end,
weather_df=_weather_data,
soil=_sandy_loam,
crop=_wheat,
initial_water_content=_initial_water_content,
irrigation_management=irrigation,
)
# run model till termination
model_os.run_model(till_termination=True)

final_statistics = model_os.get_simulation_results().head(10)
yield_expected = 10.78
yield_returned = round(final_statistics["Dry yield (tonne/ha)"][0], 2)

print(yield_expected)
print(yield_returned)
97 changes: 50 additions & 47 deletions tests/test_bug.py
Original file line number Diff line number Diff line change
@@ -1,47 +1,50 @@
"""
This test is for bug testing
"""
import unittest

from aquacrop import AquaCropModel, Soil, Crop, InitialWaterContent, GroundWater
from aquacrop.utils import prepare_weather, get_filepath


class TestModelExceptions(unittest.TestCase):
"""
Test of what happens if the model does not run.
"""

_weather_file_path = get_filepath("tunis_climate.txt")

_weather_data = prepare_weather(_weather_file_path)

_weather_data["Precipitation"] = (
_weather_data["Precipitation"] / 10
) # too much rain for ground water effect in the original

_sandy_loam = Soil(soil_type="SandyLoam")
_wheat = Crop("Wheat", planting_date="10/01")
_initial_water_content = InitialWaterContent(value=["FC"])
_model_os = AquaCropModel(
sim_start_time=f"{1979}/10/01",
sim_end_time=f"{1981}/05/30",
weather_df=_weather_data,
soil=_sandy_loam,
crop=_wheat,
initial_water_content=_initial_water_content,
groundwater=GroundWater(
water_table="Y", dates=[f"{1979}/10/01"], values=[2.66]
),
)
_model_os.run_model(till_termination=True)

def test_anything(self):
"""
Test any variable
"""
pass


if __name__ == "__main__":
unittest.main()
"""
This test is for bug testing
"""
import unittest

from aquacrop import AquaCropModel, Soil, Crop, InitialWaterContent, GroundWater
from aquacrop.utils import prepare_weather, get_filepath

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


class TestModelExceptions(unittest.TestCase):
"""
Test of what happens if the model does not run.
"""

_weather_file_path = get_filepath("tunis_climate.txt")

_weather_data = prepare_weather(_weather_file_path)

_weather_data["Precipitation"] = (
_weather_data["Precipitation"] / 10
) # too much rain for ground water effect in the original

_sandy_loam = Soil(soil_type="SandyLoam")
_wheat = Crop("Wheat", planting_date="10/01")
_initial_water_content = InitialWaterContent(value=["FC"])
_model_os = AquaCropModel(
sim_start_time=f"{1979}/10/01",
sim_end_time=f"{1981}/05/30",
weather_df=_weather_data,
soil=_sandy_loam,
crop=_wheat,
initial_water_content=_initial_water_content,
groundwater=GroundWater(
water_table="Y", dates=[f"{1979}/10/01"], values=[2.66]
),
)
_model_os.run_model(till_termination=True)

def test_anything(self):
"""
Test any variable
"""
pass


if __name__ == "__main__":
unittest.main()
Loading

0 comments on commit 2c80879

Please sign in to comment.