Skip to content

Commit 49c670d

Browse files
committed
implement modelchain tests
1 parent ac6f710 commit 49c670d

File tree

3 files changed

+83
-13
lines changed

3 files changed

+83
-13
lines changed

pvlib/modelchain.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def orientation_strategy(self, strategy):
7575
self.system.surface_azimuth = 180
7676
self.system.surface_tilt = self.location.latitude
7777
elif strategy == 'flat':
78-
self.system.surface_azimuth = 0
78+
self.system.surface_azimuth = 180
7979
self.system.surface_tilt = 0
8080
else:
8181
raise ValueError('invalid orientation strategy. strategy must ' +
@@ -84,13 +84,13 @@ def orientation_strategy(self, strategy):
8484
self._orientation_strategy = strategy
8585

8686

87-
def run_model(self, times=None, irradiance=None, weather=None):
87+
def run_model(self, times, irradiance=None, weather=None):
8888
"""
8989
Run the model.
9090
9191
Parameters
9292
----------
93-
times : None or DatetimeIndex
93+
times : DatetimeIndex
9494
irradiance : None or DataFrame
9595
If None, calculates clear sky data.
9696
Columns must be 'dni', 'ghi', 'dhi'

pvlib/test/test_modelchain.py

Lines changed: 80 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,97 @@
1+
import numpy as np
2+
import pandas as pd
13

4+
from pvlib import modelchain, pvsystem
5+
from pvlib.modelchain import ModelChain
6+
from pvlib.pvsystem import PVSystem
7+
from pvlib.location import Location
28

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
438

539

640
def test_ModelChain_creation():
7-
raise Exception('test me')
41+
system, location = mc_setup()
42+
mc = ModelChain(system, location)
843

944

1045
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]
1362

1463

1564
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)
1773

1874

1975
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)
2186

2287

2388
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)

pvlib/test/test_pvsystem.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
import logging
2-
pvl_logger = logging.getLogger('pvlib')
3-
41
import inspect
52
import os
63
import datetime

0 commit comments

Comments
 (0)