1+ """
2+ This test is for bug testing
3+ """
4+ import os
5+ os .environ ['DEVELOPMENT' ] = 'True'
6+ import unittest
7+
8+ from aquacrop import AquaCropModel , Soil , Crop , InitialWaterContent , GroundWater
9+ from aquacrop .utils import prepare_weather , get_filepath
10+
11+
12+
13+
14+ class TestModelExceptions (unittest .TestCase ):
15+ """
16+ Test of what happens if the model does not run.
17+ """
18+
19+ _weather_file_path = get_filepath ("tunis_climate.txt" )
20+
21+ _weather_data = prepare_weather (_weather_file_path )
22+
23+ _weather_data ["Precipitation" ] = (
24+ _weather_data ["Precipitation" ] / 10
25+ ) # too much rain for ground water effect in the original
26+
27+ # create a custom soil that has a layer with penetrability = 0
28+ soil_custom3 = Soil (soil_type = 'custom' , cn = 46 , rew = 7 )
29+ soil_custom3 .add_layer (thickness = .1 * 3 ,thWP = 0.24 ,
30+ thFC = 0.40 ,thS = 0.50 ,Ksat = 155 ,
31+ penetrability = 100 )
32+ soil_custom3 .add_layer (thickness = .1 * 3 ,thWP = 0.24 ,
33+ thFC = 0.40 ,thS = 0.50 ,Ksat = 155 ,
34+ penetrability = 100 )
35+ soil_custom3 .add_layer (thickness = .1 * 3 ,thWP = 0.24 ,
36+ thFC = 0.40 ,thS = 0.50 ,Ksat = 155 ,
37+ penetrability = 100 )
38+ soil_custom3 .add_layer (thickness = .1 * 3 ,thWP = 0.24 ,
39+ thFC = 0.40 ,thS = 0.50 ,Ksat = 155 ,
40+ penetrability = 0 )
41+ #print(soil_custom3.profile)
42+ _wheat = Crop ("Wheat" , planting_date = "10/01" )
43+ _initial_water_content = InitialWaterContent (value = ["FC" ])
44+ _model_os = AquaCropModel (
45+ sim_start_time = f"{ 1979 } /10/01" ,
46+ sim_end_time = f"{ 1980 } /05/30" ,
47+ weather_df = _weather_data ,
48+ soil = soil_custom3 ,
49+ crop = _wheat ,
50+ initial_water_content = _initial_water_content ,
51+ groundwater = GroundWater (
52+ water_table = "Y" , dates = [f"{ 1979 } /10/01" ], values = [2.66 ]
53+ ),
54+ )
55+ _model_os .run_model (till_termination = True )
56+
57+ def test_minimum_root_depth (self ):
58+ """
59+ Test that minimum root depth is not below 0.3.
60+ """
61+ harvest_time_step = self ._model_os ._outputs .final_stats ['Harvest Date (Step)' ].values [0 ]
62+ crop_growth = self ._model_os ._outputs .crop_growth
63+ root_depth = crop_growth ["z_root" ][0 :harvest_time_step ]
64+
65+ min_rooting_depth_expected = 0.3
66+ min_rooting_depth_returned = round (root_depth .min (), 1 )
67+ self .assertEqual (min_rooting_depth_expected , min_rooting_depth_returned )
68+
69+ def test_maximum_root_depth (self ):
70+ """
71+ Test that maximum root depth is not greater than the depth where penetrability = 0.
72+ """
73+ harvest_time_step = self ._model_os ._outputs .final_stats ['Harvest Date (Step)' ].values [0 ]
74+ crop_growth = self ._model_os ._outputs .crop_growth [self ._model_os ._outputs .crop_growth ['time_step_counter' ] <= harvest_time_step ]
75+ root_depth = crop_growth ["z_root" ][0 :harvest_time_step ]
76+
77+ max_rooting_depth_expected = 0.9
78+ max_rooting_depth_returned = round (root_depth .max (), 1 )
79+ self .assertEqual (max_rooting_depth_expected , max_rooting_depth_returned )
80+
81+ def test_root_depth (self ):
82+ """
83+ Test that root depth does not decrease through time.
84+ """
85+ harvest_time_step = self ._model_os ._outputs .final_stats ['Harvest Date (Step)' ].values [0 ]
86+ crop_growth = self ._model_os ._outputs .crop_growth [self ._model_os ._outputs .crop_growth ['time_step_counter' ] <= harvest_time_step ]
87+ root_depth = crop_growth ["z_root" ][0 :harvest_time_step ]
88+
89+ for earlier ,later in zip (root_depth , root_depth [1 :]):
90+ self .assertGreaterEqual (later , earlier , "Root depth decreased through time" )
91+
92+ if __name__ == "__main__" :
93+ unittest .main ()
0 commit comments