Skip to content

Commit 31e323d

Browse files
committed
add altitude and pressure kwargs to basic_chain
1 parent 67d45f8 commit 31e323d

File tree

2 files changed

+35
-9
lines changed

2 files changed

+35
-9
lines changed

pvlib/modelchain.py

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ def basic_chain(times, latitude, longitude,
2020
transposition_model='haydavies',
2121
solar_position_method='nrel_numpy',
2222
airmass_model='kastenyoung1989',
23+
altitude=None, pressure=None,
2324
**kwargs):
2425
"""
2526
An experimental function that computes all of the modeling steps
@@ -79,9 +80,23 @@ def basic_chain(times, latitude, longitude,
7980
airmass_model : str
8081
Passed to location.get_airmass.
8182
83+
altitude : None or float
84+
If None, computed from pressure. Assumed to be 0 m
85+
if pressure is also None.
86+
87+
pressure : None or float
88+
If None, computed from altitude. Assumed to be 101325 Pa
89+
if altitude is also None.
90+
8291
**kwargs
8392
Arbitrary keyword arguments.
8493
See code for details.
94+
95+
Returns
96+
-------
97+
output : (dc, ac)
98+
Tuple of DC power (with SAPM parameters) (DataFrame) and AC
99+
power (Series).
85100
"""
86101

87102
# use surface_tilt and surface_azimuth if provided,
@@ -97,14 +112,24 @@ def basic_chain(times, latitude, longitude,
97112

98113
times = times
99114

115+
if altitude is None and pressure is None:
116+
altitude = 0.
117+
pressure = 101325.
118+
elif altitude is None:
119+
altitude = atmosphere.pres2alt(pressure)
120+
elif pressure is None:
121+
pressure = atmosphere.alt2pres(altitude)
122+
100123
solar_position = solarposition.get_solarposition(times, latitude,
101-
longitude, **kwargs)
124+
longitude,
125+
altitude=altitude,
126+
pressure=pressure,
127+
**kwargs)
102128

103129
# possible error with using apparent zenith with some models
104130
airmass = atmosphere.relativeairmass(solar_position['apparent_zenith'],
105131
model=airmass_model)
106-
airmass = atmosphere.absoluteairmass(airmass,
107-
kwargs.get('pressure', 101325.))
132+
airmass = atmosphere.absoluteairmass(airmass, pressure)
108133
dni_extra = pvlib.irradiance.extraradiation(solar_position.index)
109134
dni_extra = pd.Series(dni_extra, index=solar_position.index)
110135

@@ -118,7 +143,8 @@ def basic_chain(times, latitude, longitude,
118143
latitude,
119144
longitude,
120145
zenith_data=solar_position['apparent_zenith'],
121-
airmass_data=airmass)
146+
airmass_data=airmass,
147+
altitude=altitude)
122148

123149
total_irrad = pvlib.irradiance.total_irrad(
124150
surface_tilt,
@@ -272,9 +298,9 @@ def run_model(self, times, irradiance=None, weather=None):
272298
273299
Returns
274300
-------
275-
output : (ac, dc)
276-
Tuple of AC power (Series) and DC power with SAPM parameters
277-
(DataFrame).
301+
output : (dc, ac)
302+
Tuple of DC power (with SAPM parameters) (DataFrame) and AC
303+
power (Series).
278304
279305
Assigns attributes: times, solar_position, airmass, irradiance,
280306
total_irrad, weather, temps, aoi, dc, ac

pvlib/test/test_modelchain.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def test_basic_chain_alt_az():
131131
surface_azimuth=surface_azimuth,
132132
altitude=altitude)
133133

134-
expected = pd.Series(np.array([ 1.14484467e+02, -2.00000000e-02]),
134+
expected = pd.Series(np.array([ 1.15771428788e+02, -2.00000000e-02]),
135135
index=times)
136136
assert_series_equal(ac, expected)
137137

@@ -151,6 +151,6 @@ def test_basic_chain_strategy():
151151
orientation_strategy='south_at_latitude_tilt',
152152
altitude=altitude)
153153

154-
expected = pd.Series(np.array([ 1.79622788e+02, -2.00000000e-02]),
154+
expected = pd.Series(np.array([ 1.82033563543e+02, -2.00000000e-02]),
155155
index=times)
156156
assert_series_equal(ac, expected)

0 commit comments

Comments
 (0)