Skip to content

Commit

Permalink
Merge pull request #121 from chris-s-bowden/v7-improvements
Browse files Browse the repository at this point in the history
v3.0.1
  • Loading branch information
chris-s-bowden authored Jan 16, 2024
2 parents 2c80879 + 0fd639f commit 4a7a615
Show file tree
Hide file tree
Showing 7 changed files with 225 additions and 0 deletions.
70 changes: 70 additions & 0 deletions aquacrop/entities/crops/crop_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,76 @@
'p_up2': 0.75,
'p_up3': 0.75,
'p_up4': 0.85},
'Default': {'Aer': 5.0,
'CCx': 0.80,
'CDC': -9.0,
'CDC_CD': 0.12750,
'CGC': -9.0,
'CGC_CD': 0.15000,
'CalendarType': 1,
'CropType': 3,
'Determinant': 1.0,
'ETadj': 1.0,
'Emergence': -9.0,
'EmergenceCD': 5.0,
'Flowering': -9.0,
'FloweringCD': 10.0,
'GDD_lo': 0,
'GDD_up': 11.1,
'GDDmethod': 3,
'HI0': 0.5,
'HIstart': -9.0,
'HIstartCD': 70.0,
'Kcb': 1.10,
'Maturity': -9.0,
'MaturityCD': 125.0,
'MaxRooting': -9.0,
'MaxRootingCD': 100.0,
'Name': 'Default',
'PlantMethod': 1.0,
'PlantPop': 185000.0,
'PolColdStress': 1,
'PolHeatStress': 1,
'SeedSize': 6.5,
'Senescence': -9.0,
'SenescenceCD': 110.0,
'SwitchGDD': 0,
'SxBotQ': 0.012,
'SxTopQ': 0.048,
'Tbase': 5.5,
'Tmax_lo': 45.0,
'Tmax_up': 40.0,
'Tmin_lo': 3.0,
'Tmin_up': 8.0,
'TrColdStress': 1,
'Tupp': 30.0,
'WP': 17.0,
'WPy': 100.0,
'YldForm': -9.0,
'YldFormCD': 50.0,
'YldWC': 25,
'Zmax': 1.0,
'Zmin': 0.3,
'a_HI': 10.0,
'b_HI': 8.0,
'dHI0': 10.0,
'dHI_pre': 5.0,
'exc': 50.0,
'fage': 0.15,
'fshape_r': 1.5,
'fshape_w1': 3.0,
'fshape_w2': 3.0,
'fshape_w3': 3.0,
'fshape_w4': 1,
'fsink': 1,
'p_lo1': 0.60,
'p_lo2': 1,
'p_lo3': 1,
'p_lo4': 1,
'p_up1': 0.25,
'p_up2': 0.5,
'p_up3': 0.85,
'p_up4': 0.90},
'DryBean': {'Aer': 5.0,
'CCx': 0.99,
'CDC': -9.0,
Expand Down
7 changes: 7 additions & 0 deletions aquacrop/entities/soil.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@ def __init__(
self.create_df(dz)
self.add_layer(sum(dz), 0.23, 0.39, 0.5, 125, 100)

elif soil_type == 'Default':
self.cn = 61
self.calc_cn = 0
self.rew = 9
self.create_df(dz)
self.add_layer(sum(dz), 0.1, 0.3, 0.5, 500, 100)

elif soil_type == "Loam":
self.cn = 61
self.calc_cn = 0
Expand Down
148 changes: 148 additions & 0 deletions tests/custom_crop_testing.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"c:\\Users\\s10034cb\\Dropbox (The University of Manchester)\\Manchester Postdoc\\aquacrop\\aquacrop\\solution\\root_zone_water.py:4: NumbaPendingDeprecationWarning: \u001b[1mThe 'pycc' module is pending deprecation. Replacement technology is being developed.\n",
"\n",
"Pending Deprecation in Numba 0.57.0. For more information please see: https://numba.readthedocs.io/en/stable/reference/deprecation.html#deprecation-of-the-numba-pycc-module\u001b[0m\n",
" from numba.pycc import CC\n"
]
}
],
"source": [
"#source:https://urldefense.com/v3/__https://colab.research.google.com/github/aquacropos/aquacrop/blob/master/docs/notebooks/AquaCrop_OSPy_Notebook_1.ipynb*scrollTo=3PvQ5QYR49tG__;Iw!!PDiH4ENfjr2_Jw!D_pEP_KWqfA5MRPYdLgFgi8qQKsms7Wr4zR9ze88aSc-2dJmvQiGEntY6mcl2r3gO1Zn3I_nWrYtAqj8O_tcyzhIyvM8tAPZSmc3$ [colab[.]research[.]google[.]com]\n",
"\n",
"from aquacrop import AquaCropModel, Soil, Crop, InitialWaterContent, IrrigationManagement\n",
"from aquacrop.utils import prepare_weather, get_filepath\n",
"\n",
"import pandas as pd\n",
"import matplotlib.pyplot as plt\n"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"ename": "AttributeError",
"evalue": "'Crop' object has no attribute 'SxTopQ'",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mAttributeError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[1;32mIn[4], line 9\u001b[0m\n\u001b[0;32m 7\u001b[0m sandy_loam \u001b[38;5;241m=\u001b[39m Soil(soil_type\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mSandyLoam\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[0;32m 8\u001b[0m wheat \u001b[38;5;241m=\u001b[39m Crop(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mWheat\u001b[39m\u001b[38;5;124m'\u001b[39m, planting_date\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m09/28\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[1;32m----> 9\u001b[0m test_crop_basic \u001b[38;5;241m=\u001b[39m \u001b[43mCrop\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mcustom\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43m10/01\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mPlantPop\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;241;43m1000\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mSeedSize\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;241;43m5\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[0;32m 10\u001b[0m test_crop \u001b[38;5;241m=\u001b[39m Crop(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mcustom\u001b[39m\u001b[38;5;124m'\u001b[39m,\n\u001b[0;32m 11\u001b[0m planting_date\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m09/28\u001b[39m\u001b[38;5;124m'\u001b[39m,\n\u001b[0;32m 12\u001b[0m \u001b[38;5;66;03m#harvest_date='08/28',\u001b[39;00m\n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 49\u001b[0m YldWC \u001b[38;5;241m=\u001b[39m \u001b[38;5;241m85\u001b[39m\n\u001b[0;32m 50\u001b[0m )\n\u001b[0;32m 52\u001b[0m InitWC \u001b[38;5;241m=\u001b[39m InitialWaterContent(value\u001b[38;5;241m=\u001b[39m[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mFC\u001b[39m\u001b[38;5;124m'\u001b[39m])\n",
"File \u001b[1;32mc:\\Users\\s10034cb\\Dropbox (The University of Manchester)\\Manchester Postdoc\\aquacrop\\aquacrop\\entities\\crop.py:184\u001b[0m, in \u001b[0;36mCrop.__init__\u001b[1;34m(self, c_name, planting_date, harvest_date, **kwargs)\u001b[0m\n\u001b[0;32m 92\u001b[0m allowed_keys \u001b[38;5;241m=\u001b[39m {\n\u001b[0;32m 93\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mfshape_b\u001b[39m\u001b[38;5;124m\"\u001b[39m,\n\u001b[0;32m 94\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mPctZmin\u001b[39m\u001b[38;5;124m\"\u001b[39m,\n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 177\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mYldFormCD\u001b[39m\u001b[38;5;124m\"\u001b[39m,\n\u001b[0;32m 178\u001b[0m }\n\u001b[0;32m 180\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m\u001b[38;5;18m__dict__\u001b[39m\u001b[38;5;241m.\u001b[39mupdate(\n\u001b[0;32m 181\u001b[0m (k, v) \u001b[38;5;28;01mfor\u001b[39;00m k, v \u001b[38;5;129;01min\u001b[39;00m kwargs\u001b[38;5;241m.\u001b[39mitems() \u001b[38;5;28;01mif\u001b[39;00m k \u001b[38;5;129;01min\u001b[39;00m allowed_keys\n\u001b[0;32m 182\u001b[0m )\n\u001b[1;32m--> 184\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcalculate_additional_params\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n",
"File \u001b[1;32mc:\\Users\\s10034cb\\Dropbox (The University of Manchester)\\Manchester Postdoc\\aquacrop\\aquacrop\\entities\\crop.py:196\u001b[0m, in \u001b[0;36mCrop.calculate_additional_params\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 194\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mCC0 \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mPlantPop \u001b[38;5;241m*\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mSeedSize \u001b[38;5;241m*\u001b[39m \u001b[38;5;241m1e-8\u001b[39m\n\u001b[0;32m 195\u001b[0m \u001b[38;5;66;03m# Root extraction terms\u001b[39;00m\n\u001b[1;32m--> 196\u001b[0m SxTopQ \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mSxTopQ\u001b[49m\n\u001b[0;32m 197\u001b[0m SxBotQ \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mSxBotQ\n\u001b[0;32m 198\u001b[0m S1 \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mSxTopQ\n",
"\u001b[1;31mAttributeError\u001b[0m: 'Crop' object has no attribute 'SxTopQ'"
]
}
],
"source": [
"\n",
"# locate built in weather file\n",
"filepath=get_filepath('tunis_climate.txt')\n",
"\n",
"weather_data = prepare_weather(filepath)\n",
"# print (weather_data)\n",
"\n",
"sandy_loam = Soil(soil_type='SandyLoam')\n",
"wheat = Crop('Wheat', planting_date='09/28')\n",
"test_crop_basic = Crop('custom', '10/01', PlantPop=1000, SeedSize=5)\n",
"test_crop = Crop('custom',\n",
" planting_date='09/28',\n",
" #harvest_date='08/28',\n",
" CropType=3,#\n",
" # plantMethod=0,#\n",
" PlantMethod=0,\n",
" CalendarType=1,#\n",
" p_up1=-9,#\n",
" p_lo1=-9,#\n",
" fshape_w1=0,#\n",
" p_up2=-9,#\n",
" fshape_w2=-9,#\n",
" p_up3=-9,#\n",
" fshape_w3=0,#\n",
" p_up4=-9,#\n",
" Zmax=0.5,#\n",
" SxTopQ=0.048,#\n",
" SxBotQ=0.012,#\n",
" PlantPop=100,#\n",
" CCx=1,#\n",
" CDC_CD=0.01,#\n",
" Determinant=1,#\n",
" WP=-9,#\n",
" HI0=50,#\n",
" fsink=-9,#\n",
" HIstartCD=1460,#\n",
" FloweringCD=120,#\n",
" EmergenceCD=0,#\n",
" CGC_CD=-9,#\n",
" YldFormCD=186,#\n",
" MaxRootingCD=548,#\n",
" SenescenceCD=1095,#\n",
" MaturityCD=1281,#\n",
" SwitchGDD=0,#\n",
" p_lo2=-9,#\n",
" p_lo3=-9,#\n",
" p_lo4=-9,#\n",
" fshape_w4=-9,#\n",
" SeedSize=2.8,#\n",
" YldWC = 85\n",
" )\n",
"\n",
"InitWC = InitialWaterContent(value=['FC'])\n",
"\n",
"# combine into aquacrop model and specify start and end simulation date\n",
"model = AquaCropModel(sim_start_time=f'{1980}/09/28',\n",
" sim_end_time=f'{1982}/10/10',\n",
" weather_df=prepare_weather(filepath),\n",
" soil=Soil(soil_type='SandyLoam'),\n",
" # crop=test_crop,\n",
" crop = test_crop_basic,\n",
" # crop=Crop('Wheat', planting_date='10/01'),\n",
" initial_water_content=InitWC,\n",
" irrigation_management=IrrigationManagement(irrigation_method=0)\n",
" )\n",
"\n",
"model.run_model(till_termination=True)\n",
"\n",
"#print(model._outputs.final_stats.head())\n",
"#print(model._outputs.water_flux.head())\n",
"#print(model._outputs.water_storage.head())\n",
"#print(model._outputs.crop_growth.head())\n",
"\n",
"x=model._outputs.crop_growth\n",
"print (x)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "aq_test",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.13"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 4a7a615

Please sign in to comment.