@@ -9,156 +9,176 @@ class TestModelChain:
99
1010 @classmethod
1111 def setup_class (self ):
12- self .weather = {'temp_air' : pd .Series (data = [267 , 268 ]),
13- 'temp_air_2' : pd .Series (data = [267 , 266 ]),
14- 'v_wind' : pd .Series (data = [5.0 , 6.5 ]),
15- 'v_wind_2' : pd .Series (data = [4.0 , 5.0 ]),
16- 'pressure' : pd .Series (data = [101125 , 101000 ]),
17- 'z0' : 0.15 }
18- self .weather_df = pd .DataFrame (data = {'temp_air' : [267 , 268 ],
19- 'temp_air_2' : [267 , 266 ],
20- 'v_wind' : [5.0 , 6.5 ],
21- 'v_wind_2' : [4.0 , 5.0 ],
22- 'pressure' : [101125 , 101000 ],
23- 'z0' : 0.15 },
24- index = [0 , 1 ])
25- self .data_height = {'temp_air' : 2 ,
26- 'temp_air_2' : 10 ,
27- 'v_wind' : 10 ,
28- 'v_wind_2' : 8 ,
29- 'pressure' : 0 }
3012 self .test_turbine = {'hub_height' : 100 ,
3113 'd_rotor' : 80 ,
3214 'turbine_name' : 'ENERCON E 126 7500' ,
33- 'fetch_curve' : 'P' }
34- self .test_wt = wt .WindTurbine (** self .test_turbine )
15+ 'fetch_curve' : 'p' }
3516 self .test_modelchain = {'wind_model' : 'hellman' ,
3617 'rho_model' : 'barometric' ,
3718 'temperature_model' : 'interpolation' ,
3819 'power_output_model' : 'p_values' ,
3920 'density_corr' : False }
40- self .test_mc = mc .ModelChain (self .test_wt , ** self .test_modelchain )
21+ self .test_mc = mc .ModelChain (wt .WindTurbine (** self .test_turbine ),
22+ ** self .test_modelchain )
4123
4224 def test_v_wind_hub (self ):
25+ weather = {'v_wind' : pd .Series (data = [5.0 , 6.5 ]),
26+ 'v_wind_2' : pd .Series (data = [4.0 , 5.0 ]),
27+ 'z0' : 0.15 }
28+ weather_df = pd .DataFrame (data = {'v_wind' : [5.0 , 6.5 ],
29+ 'v_wind_2' : [4.0 , 5.0 ],
30+ 'z0' : 0.15 },
31+ index = [0 , 1 ])
32+ data_height = {'v_wind' : 10 ,
33+ 'v_wind_2' : 8 }
34+
35+ # v_wind is closer to hub height than v_wind_2
36+ v_wind_exp = pd .Series (data = [7.12462 , 9.26201 ])
37+ assert_series_equal (self .test_mc .v_wind_hub (weather , data_height ),
38+ v_wind_exp )
4339 # v_wind is given at hub height
4440 v_wind_exp = pd .Series (data = [5.0 , 6.5 ])
45- self . data_height ['v_wind' ] = 100
41+ data_height ['v_wind' ] = 100
4642 assert_series_equal (
47- self .test_mc .v_wind_hub (self . weather , self . data_height ),
43+ self .test_mc .v_wind_hub (weather , data_height ),
4844 v_wind_exp )
49-
5045 # v_wind_2 is given at hub height
5146 v_wind_exp = pd .Series (data = [4.0 , 5.0 ])
52- self . data_height ['v_wind' ] = 10
53- self . data_height ['v_wind_2' ] = 100
47+ data_height ['v_wind' ] = 10
48+ data_height ['v_wind_2' ] = 100
5449 assert_series_equal (
55- self .test_mc .v_wind_hub (self . weather , self . data_height ),
50+ self .test_mc .v_wind_hub (weather , data_height ),
5651 v_wind_exp )
57-
58- # v_wind is closer to hub height than v_wind_2
59- v_wind_exp = pd .Series (data = [7.12462 , 9.26201 ])
60- self .data_height ['v_wind_2' ] = 8
61- assert_series_equal (self .test_mc .v_wind_hub (self .weather ,
62- self .data_height ),
63- v_wind_exp )
64-
6552 # Test DataFrame
66- assert_series_equal (self .test_mc .v_wind_hub (self . weather_df ,
67- self . data_height ),
53+ assert_series_equal (self .test_mc .v_wind_hub (weather_df ,
54+ data_height ),
6855 v_wind_exp )
6956
7057 def test_rho_hub (self ):
58+ weather = {'temp_air' : pd .Series (data = [267 , 268 ]),
59+ 'temp_air_2' : pd .Series (data = [267 , 266 ]),
60+ 'pressure' : pd .Series (data = [101125 , 101000 ])}
61+ weather_df = pd .DataFrame (data = {'temp_air' : [267 , 268 ],
62+ 'temp_air_2' : [267 , 266 ],
63+ 'pressure' : [101125 , 101000 ]},
64+ index = [0 , 1 ])
65+ data_height = {'temp_air' : 2 ,
66+ 'temp_air_2' : 10 ,
67+ 'pressure' : 0 }
68+ # Test with above conditions
69+ rho_exp = pd .Series (data = [1.30305 , 1.42702 ])
70+ assert_series_equal (self .test_mc .rho_hub (weather ,
71+ data_height ), rho_exp )
7172 # temp_air at hub height
7273 rho_exp = pd .Series (data = [1.30305 , 1.29657 ])
73- self .data_height ['temp_air' ] = 100
74- assert_series_equal (self .test_mc .rho_hub (self .weather ,
75- self .data_height ), rho_exp )
76-
74+ data_height ['temp_air' ] = 100
75+ assert_series_equal (self .test_mc .rho_hub (weather ,
76+ data_height ), rho_exp )
7777 # temp_air_2 at hub height
7878 rho_exp = pd .Series (data = [1.30305 , 1.30632 ])
79- self .data_height ['temp_air' ] = 2
80- self .data_height ['temp_air_2' ] = 100
81- assert_series_equal (self .test_mc .rho_hub (self .weather ,
82- self .data_height ), rho_exp )
83-
84- rho_exp = pd .Series (data = [1.30305 , 1.42702 ])
85- self .data_height ['temp_air_2' ] = 10
86- assert_series_equal (self .test_mc .rho_hub (self .weather ,
87- self .data_height ), rho_exp )
88- # Test DataFrame
89- assert_series_equal (self .test_mc .rho_hub (self .weather_df ,
90- self .data_height ),
79+ data_height ['temp_air' ] = 2
80+ data_height ['temp_air_2' ] = 100
81+ assert_series_equal (self .test_mc .rho_hub (weather ,
82+ data_height ), rho_exp )
83+ # Test weather as DataFrame
84+ assert_series_equal (self .test_mc .rho_hub (weather_df ,
85+ data_height ),
9186 rho_exp )
9287
9388 def test_run_model (self ):
89+ weather = {'temp_air' : pd .Series (data = [267 , 268 ]),
90+ 'temp_air_2' : pd .Series (data = [267 , 266 ]),
91+ 'v_wind' : pd .Series (data = [5.0 , 6.5 ]),
92+ 'v_wind_2' : pd .Series (data = [4.0 , 5.0 ]),
93+ 'pressure' : pd .Series (data = [101125 , 101000 ]),
94+ 'z0' : 0.15 }
95+ data_height = {'temp_air' : 2 ,
96+ 'temp_air_2' : 10 ,
97+ 'v_wind' : 10 ,
98+ 'v_wind_2' : 8 ,
99+ 'pressure' : 0 }
100+ test_turbine = {'hub_height' : 100 ,
101+ 'd_rotor' : 80 ,
102+ 'turbine_name' : 'ENERCON E 126 7500' ,
103+ 'fetch_curve' : 'P' }
104+ test_modelchain = {'wind_model' : 'hellman' ,
105+ 'rho_model' : 'barometric' ,
106+ 'temperature_model' : 'interpolation' ,
107+ 'power_output_model' : 'p_values' ,
108+ 'density_corr' : True }
109+
94110 # Test with default parameters of modelchain (p curve)
95111 power_output_exp = pd .Series (data = [1731887.39768 , 3820152.27489 ],
96112 name = 'feedin_wind_turbine' )
97- test_mc = mc .ModelChain (self . test_wt )
98- test_mc .run_model (self . weather , self . data_height )
113+ test_mc = mc .ModelChain (wt . WindTurbine ( ** test_turbine ) )
114+ test_mc .run_model (weather , data_height )
99115 assert_series_equal (test_mc .power_output , power_output_exp )
100116
101- def test_different_models (self ):
102117 # Test with density corrected power curve
103118 power_output_exp = pd .Series (data = [1430312.76771 , 3746075.21279 ],
104119 name = 'feedin_wind_turbine' )
105- self .test_modelchain ['density_corr' ] = True
106- test_wt = wt .WindTurbine (** self .test_turbine )
107- test_mc = mc .ModelChain (test_wt , ** self .test_modelchain )
108- test_mc .run_model (self .weather , self .data_height )
120+ test_mc = mc .ModelChain (wt .WindTurbine (** test_turbine ),
121+ ** test_modelchain )
122+ test_mc .run_model (weather , data_height )
109123 assert_series_equal (test_mc .power_output , power_output_exp )
110124
111125 # Test with power coefficient curve
112126 power_output_exp = pd .Series (data = [557835.45403 , 1363746.94496 ],
113127 name = 'feedin_wind_turbine' )
114- self . test_turbine ['fetch_curve' ] = 'cp'
115- self . test_modelchain ['power_output_model' ] = 'cp_values'
116- self . test_modelchain ['density_corr' ] = False
117- test_wt = wt .WindTurbine (** self . test_turbine )
118- test_mc = mc . ModelChain ( test_wt , ** self . test_modelchain )
119- test_mc .run_model (self . weather , self . data_height )
128+ test_turbine ['fetch_curve' ] = 'cp'
129+ test_modelchain ['power_output_model' ] = 'cp_values'
130+ test_modelchain ['density_corr' ] = False
131+ test_mc = mc . ModelChain ( wt .WindTurbine (** test_turbine ),
132+ ** test_modelchain )
133+ test_mc .run_model (weather , data_height )
120134 assert_series_equal (test_mc .power_output , power_output_exp )
121135
122136 # Ideal gas equation and density corrected power coefficient curve
123137 power_output_exp = pd .Series (data = [567683.92454 , 1485556.96435 ],
124138 name = 'feedin_wind_turbine' )
125- self .test_modelchain ['rho_model' ] = 'ideal_gas'
126- self .test_modelchain ['density_corr' ] = True
127- test_mc = mc .ModelChain (test_wt , ** self .test_modelchain )
128- test_mc .run_model (self .weather , self .data_height )
139+ test_modelchain ['rho_model' ] = 'ideal_gas'
140+ test_modelchain ['density_corr' ] = True
141+ test_mc = mc .ModelChain (wt .WindTurbine (** test_turbine ),
142+ ** test_modelchain )
143+ test_mc .run_model (weather , data_height )
129144 assert_series_equal (test_mc .power_output , power_output_exp )
130145
131146 # Raise ValueErrors due to wrong spelling of parameters
132147 with pytest .raises (ValueError ):
133- self .test_modelchain ['power_output_model' ] = 'wrong_spelling'
134- test_mc = mc .ModelChain (self .test_wt , ** self .test_modelchain )
135- test_mc .run_model (self .weather , self .data_height )
148+ test_modelchain ['power_output_model' ] = 'wrong_spelling'
149+ test_mc = mc .ModelChain (wt .WindTurbine (** test_turbine ),
150+ ** test_modelchain )
151+ test_mc .run_model (weather , data_height )
136152 with pytest .raises (ValueError ):
137- self .test_modelchain ['power_output_model' ] = 'cp_values'
138- self .test_modelchain ['wind_model' ] = 'wrong_spelling'
139- test_mc = mc .ModelChain (self .test_wt , ** self .test_modelchain )
140- test_mc .run_model (self .weather , self .data_height )
153+ test_modelchain ['power_output_model' ] = 'cp_values'
154+ test_modelchain ['wind_model' ] = 'wrong_spelling'
155+ test_mc = mc .ModelChain (wt .WindTurbine (** test_turbine ),
156+ ** test_modelchain )
157+ test_mc .run_model (weather , data_height )
141158 with pytest .raises (ValueError ):
142- self .test_modelchain ['wind_model' ] = 'hellman'
143- self .test_modelchain ['rho_model' ] = 'wrong_spelling'
144- test_mc = mc .ModelChain (self .test_wt , ** self .test_modelchain )
145- test_mc .run_model (self .weather , self .data_height )
159+ test_modelchain ['wind_model' ] = 'hellman'
160+ test_modelchain ['rho_model' ] = 'wrong_spelling'
161+ test_mc = mc .ModelChain (wt .WindTurbine (** test_turbine ),
162+ ** test_modelchain )
163+ test_mc .run_model (weather , data_height )
146164 with pytest .raises (ValueError ):
147- self .test_modelchain ['rho_model' ] = 'barometric'
148- self .test_modelchain ['temperature_model' ] = 'wrong_spelling'
149- test_mc = mc .ModelChain (self .test_wt , ** self .test_modelchain )
150- test_mc .run_model (self .weather , self .data_height )
165+ test_modelchain ['rho_model' ] = 'barometric'
166+ test_modelchain ['temperature_model' ] = 'wrong_spelling'
167+ test_mc = mc .ModelChain (wt .WindTurbine (** test_turbine ),
168+ ** test_modelchain )
169+ test_mc .run_model (weather , data_height )
151170
152171 # Raise TypeErrors due to wrong type of `density_corr`
153172 with pytest .raises (TypeError ):
154- self .test_modelchain ['temperature_model' ] = 'gradient'
155- self .test_modelchain ['density_corr' ] = 'wrong_type'
156- test_mc = mc .ModelChain (self .test_wt , ** self .test_modelchain )
157- test_mc .run_model (self .weather , self .data_height )
173+ test_modelchain ['temperature_model' ] = 'gradient'
174+ test_modelchain ['density_corr' ] = 'wrong_type'
175+ test_mc = mc .ModelChain (wt .WindTurbine (** test_turbine ),
176+ ** test_modelchain )
177+ test_mc .run_model (weather , data_height )
158178 # Raise TypeErrors due to missing cp- or p-values
159179 with pytest .raises (TypeError ):
160- self . test_modelchain ['power_output_model' ] = 'p_values'
161- self . test_turbine ['fetch_curve' ] = 'cp'
162- test_mc = mc .ModelChain (wt .WindTurbine (** self . test_turbine ),
163- ** self . test_modelchain )
164- test_mc .run_model (self . weather , self . data_height )
180+ test_modelchain ['power_output_model' ] = 'p_values'
181+ test_turbine ['fetch_curve' ] = 'cp'
182+ test_mc = mc .ModelChain (wt .WindTurbine (** test_turbine ),
183+ ** test_modelchain )
184+ test_mc .run_model (weather , data_height )
0 commit comments