1
+ import numpy as np
2
+ import pandas as pd
1
3
4
+ from pvlib import modelchain , pvsystem
5
+ from pvlib .modelchain import ModelChain
6
+ from pvlib .pvsystem import PVSystem
7
+ from pvlib .location import Location
2
8
3
- from pvlib import modelchain
9
+ from pandas .util .testing import assert_series_equal , assert_frame_equal
10
+ from nose .tools import with_setup
11
+
12
+ # should store this test data locally, but for now...
13
+ sam_data = {}
14
+ def retrieve_sam_network ():
15
+ sam_data ['cecmod' ] = pvsystem .retrieve_sam ('cecmod' )
16
+ sam_data ['sandiamod' ] = pvsystem .retrieve_sam ('sandiamod' )
17
+ sam_data ['cecinverter' ] = pvsystem .retrieve_sam ('cecinverter' )
18
+
19
+
20
+ def mc_setup ():
21
+ # limit network usage
22
+ try :
23
+ modules = sam_data ['sandiamod' ]
24
+ except KeyError :
25
+ retrieve_sam_network ()
26
+ modules = sam_data ['sandiamod' ]
27
+
28
+ module = modules .Canadian_Solar_CS5P_220M___2009_ .copy ()
29
+ inverters = sam_data ['cecinverter' ]
30
+ inverter = inverters ['ABB__MICRO_0_25_I_OUTD_US_208_208V__CEC_2014_' ].copy ()
31
+
32
+ system = PVSystem (module_parameters = module ,
33
+ inverter_parameters = inverter )
34
+
35
+ location = Location (32.2 , - 111 , altitude = 700 )
36
+
37
+ return system , location
4
38
5
39
6
40
def test_ModelChain_creation ():
7
- raise Exception ('test me' )
41
+ system , location = mc_setup ()
42
+ mc = ModelChain (system , location )
8
43
9
44
10
45
def test_orientation_strategy ():
11
- # test for None, 'None', 'south_at_latitude_tilt', 'flat', ValueError
12
- raise Exception ('test me' )
46
+ strategies = {None : (0 , 180 ), 'None' : (0 , 180 ),
47
+ 'south_at_latitude_tilt' : (32.2 , 180 ),
48
+ 'flat' : (0 , 180 )}
49
+
50
+ for strategy , expected in strategies .items ():
51
+ yield run_orientation_strategy , strategy , expected
52
+
53
+
54
+ def run_orientation_strategy (strategy , expected ):
55
+ system = PVSystem ()
56
+ location = Location (32.2 , - 111 , altitude = 700 )
57
+
58
+ mc = ModelChain (system , location , orientation_strategy = strategy )
59
+
60
+ assert system .surface_tilt == expected [0 ]
61
+ assert system .surface_azimuth == expected [1 ]
13
62
14
63
15
64
def test_run_model ():
16
- raise Exception ('test me' )
65
+ system , location = mc_setup ()
66
+ mc = ModelChain (system , location )
67
+ times = pd .date_range ('20160101 1200-0700' , periods = 2 , freq = '6H' )
68
+ dc , ac = mc .run_model (times )
69
+
70
+ expected = pd .Series (np .array ([ 1.82033564e+02 , - 2.00000000e-02 ]),
71
+ index = times )
72
+ assert_series_equal (ac , expected )
17
73
18
74
19
75
def test_run_model_with_irradiance ():
20
- raise Exception ('test me' )
76
+ system , location = mc_setup ()
77
+ mc = ModelChain (system , location )
78
+ times = pd .date_range ('20160101 1200-0700' , periods = 2 , freq = '6H' )
79
+ irradiance = pd .DataFrame ({'dni' :900 , 'ghi' :600 , 'dhi' :150 },
80
+ index = times )
81
+ dc , ac = mc .run_model (times , irradiance = irradiance )
82
+
83
+ expected = pd .Series (np .array ([ 1.90054749e+02 , - 2.00000000e-02 ]),
84
+ index = times )
85
+ assert_series_equal (ac , expected )
21
86
22
87
23
88
def test_run_model_with_weather ():
24
- raise Exception ('test me' )
89
+ system , location = mc_setup ()
90
+ mc = ModelChain (system , location )
91
+ times = pd .date_range ('20160101 1200-0700' , periods = 2 , freq = '6H' )
92
+ weather = pd .DataFrame ({'wind_speed' :5 , 'temp_air' :10 }, index = times )
93
+ dc , ac = mc .run_model (times , weather = weather )
94
+
95
+ expected = pd .Series (np .array ([ 1.99952400e+02 , - 2.00000000e-02 ]),
96
+ index = times )
97
+ assert_series_equal (ac , expected )
0 commit comments