Skip to content

Commit 3f96b89

Browse files
committed
convert get_airmassabsolute to get_airmass. add a bunch of failing stub tests
1 parent fe5d021 commit 3f96b89

File tree

6 files changed

+122
-23
lines changed

6 files changed

+122
-23
lines changed

docs/sphinx/source/package_overview.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,12 +202,12 @@ object to accomplish our modeling goal:
202202
wind_speed, temp_air)
203203
aoi = localized_system.get_aoi(solar_position['apparent_zenith'],
204204
solar_position['azimuth'])
205-
am_rel = pvlib.atmosphere.relativeairmass(solar_position['apparent_zenith'])
206-
am_abs = localized_system.get_absoluteairmass(am_rel)
205+
airmass = localized_system.get_airmass(solar_position=solar_position)
207206
dc = localized_system.sapm(total_irrad['poa_direct'],
208207
total_irrad['poa_diffuse'],
209208
temps['temp_cell'],
210-
am_abs, aoi)
209+
airmass['airmass_absolute'],
210+
aoi)
211211
ac = localized_system.snlinverter(dc['v_mp'], dc['p_mp'])
212212
annual_energy = ac.sum()
213213
energies[name] = annual_energy

pvlib/location.py

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,55 @@ def get_clearsky(self, times, model='ineichen', **kwargs):
191191
raise ValueError('%s is not a valid clear sky model', model)
192192

193193
return cs
194+
195+
196+
def get_airmass(self, times=None, solar_position=None,
197+
model='kastenyoung1998'):
198+
"""
199+
Calculate the relative and absolute airmass.
200+
201+
Function will calculate the solar zenith and apparent zenith angles,
202+
and choose the appropriate one.
203+
204+
Parameters
205+
----------
206+
times : None or DatetimeIndex
207+
Only used if solar_position is not provided.
208+
solar_position : None or DataFrame
209+
DataFrame with with columns 'apparent_zenith', 'zenith'.
210+
model : str
211+
Relative airmass model
212+
213+
Returns
214+
-------
215+
airmass : DataFrame
216+
Columns are 'airmass_relative', 'airmass_absolute'
217+
"""
194218

219+
if solar_position is None:
220+
solar_position = self.get_solarposition(times)
221+
222+
apparents = ['simple', 'kasten1966', 'kastenyoung1989',
223+
'gueymard1993', 'pickering2002']
224+
225+
trues = ['youngirvine1967', 'young1994']
226+
227+
if model in apparents:
228+
zenith = solar_position['apparent_zenith']
229+
elif model in trues:
230+
zenith = solar_position['zenith']
231+
else
232+
raise ValueError('invalid model %s', model)
233+
234+
airmass_relative = atmosphere.relativeairmass(zenith, model)
195235

196-
def get_absoluteairmass(self, airmass_relative):
197-
198236
pressure = atmosphere.alt2pres(self.altitude)
199-
am = atmosphere.absoluteairmass(airmass_relative, pressure)
200-
201-
return am
237+
airmass_absolute = atmosphere.absoluteairmass(airmass_relative,
238+
pressure)
239+
240+
airmass = pd.DataFrame()
241+
airmass['airmass_relative'] = airmass_relative
242+
airmass['airmass_absolute'] = airmass_absolute
202243

244+
return airmass
203245

pvlib/modelchain.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
Stub documentation for the module.
33
"""
44

5-
from pvlib import atmosphere
6-
75
class ModelChain(object):
86
"""
97
A class that represents all of the modeling steps necessary for
@@ -108,40 +106,42 @@ def run_model(self, times=None, irradiance=None, weather=None):
108106
"""
109107
solar_position = self.location.get_solarposition(times)
110108

109+
airmass = self.location.get_airmass(solar_position=solar_position,
110+
model=self.airmass_model)
111+
111112
if irradiance is None:
112113
irradiance = self.location.get_clearsky(solar_position.index,
113-
self.clearsky_model)
114+
self.clearsky_model,
115+
zenith_data=solar_position['apparent_zenith'],
116+
airmass_data=airmass['airmass_absolute'])
114117

115118
total_irrad = self.system.get_irradiance(solar_position['apparent_zenith'],
116119
solar_position['azimuth'],
117120
irradiance['dni'],
118121
irradiance['ghi'],
119122
irradiance['dhi'],
120123
model=self.transposition_model)
121-
124+
122125
if weather is None:
123126
weather = {'wind_speed': 0, 'temp_air': 20}
124127

125128
temps = self.system.sapm_celltemp(total_irrad['poa_global'],
126129
weather['wind_speed'],
127130
weather['temp_air'])
128-
131+
129132
aoi = self.system.get_aoi(solar_position['apparent_zenith'],
130133
solar_position['azimuth'])
131134

132-
am_rel = atmosphere.relativeairmass(solar_position['apparent_zenith'],
133-
self.airmass_model)
134-
am_abs = self.location.get_absoluteairmass(am_rel)
135-
136135
dc = self.system.sapm(total_irrad['poa_direct'],
137136
total_irrad['poa_diffuse'],
138137
temps['temp_cell'],
139-
am_abs, aoi)
138+
airmass['airmass_absolute'],
139+
aoi)
140140

141141
ac = self.system.snlinverter(dc['v_mp'], dc['p_mp'])
142142

143143
return dc, ac
144-
144+
145145

146146
def model_system(self):
147147
"""

pvlib/test/test_location.py

Lines changed: 12 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 pytz
52
from nose.tools import raises
63
from pytz.exceptions import UnknownTimeZoneError
@@ -35,3 +32,15 @@ def test_location_print_pytz():
3532
tus = Location(32.2, -111, aztz, 700, 'Tucson')
3633
expected_str = 'Tucson: latitude=32.2, longitude=-111, tz=US/Arizona, altitude=700'
3734
assert tus.__str__() == expected_str
35+
36+
def test_get_clearsky():
37+
raise Exception('test me')
38+
39+
def test_from_tmy():
40+
raise Exception('test me')
41+
42+
def test_get_solarposition():
43+
raise Exception('test me')
44+
45+
def test_get_airmass():
46+
raise Exception('test me')

pvlib/test/test_modelchain.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
3+
from pvlib import modelchain
4+
5+
6+
def test_ModelChain_creation():
7+
raise Exception('test me')
8+
9+
10+
def test_orientation_strategy():
11+
# test for None, 'None', 'south_at_latitude_tilt', 'flat', ValueError
12+
raise Exception('test me')
13+
14+
15+
def test_run_model():
16+
raise Exception('test me')
17+
18+
19+
def test_run_model_with_irradiance():
20+
raise Exception('test me')
21+
22+
23+
def test_run_model_with_weather():
24+
raise Exception('test me')

pvlib/test/test_pvsystem.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,32 @@ def test_PVSystem_creation():
222222
pv_system = pvsystem.PVSystem(module='blah', inverter='blarg')
223223

224224

225+
def test_PVSystem_get_aoi():
226+
raise Exception('test me')
227+
228+
229+
def test_PVSystem_get_irradiance():
230+
raise Exception('test me')
231+
232+
233+
def test_PVSystem_localize_with_location():
234+
raise Exception('test me')
235+
236+
237+
def test_PVSystem_localize_with_latlon():
238+
raise Exception('test me')
239+
240+
241+
# in principle, we should be retesting each of the models tested above
242+
# when they are attached to PVSystem
243+
244+
225245
def test_LocalizedPVSystem_creation():
226246
localized_pv_system = pvsystem.LocalizedPVSystem(latitude=30,
227247
longitude=-110,
228248
module='blah',
229-
inverter='blarg')
249+
inverter='blarg')
250+
251+
252+
def test_LocalizedPVSystem_do_stuff():
253+
raise Exception('test me')

0 commit comments

Comments
 (0)