8000 add pressure, temperature to get_solarposition. make from_tmy work · dacoex/pvlib-python@3391abf · GitHub
[go: up one dir, main page]

Skip to 8000 content

Commit 3391abf

Browse files
committed
add pressure, temperature to get_solarposition. make from_tmy work
1 parent cf1c1f3 commit 3391abf

File tree

1 file changed

+32
-23
lines changed

1 file changed

+32
-23
lines changed

pvlib/location.py

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,12 @@ class Location(object):
4040
Positive is east of the prime meridian.
4141
Use decimal degrees notation.
4242
43-
tz : string or pytz.timezone.
43+
tz : str, int, float, or pytz.timezone.
4444
See
4545
http://en.wikipedia.org/wiki/List_of_tz_database_time_zones
4646
for a list of valid time zones.
4747
pytz.timezone objects will be converted to strings.
48+
ints and floats must be in hours from UTC.
4849
4950
alitude : float.
5051
Altitude from sea level in meters.
@@ -73,6 +74,9 @@ def __init__(self, latitude, longitude, tz='UTC', altitude=0,
7374
elif isinstance(tz, datetime.tzinfo):
7475
self.tz = tz.zone
7576
self.pytz = tz
77+
elif isinstance(tz, (int, float)):
78+
self.tz = tz
79+
self.pytz = pytz.FixedOffset(tz*60)
7680
else:
7781
raise TypeError('Invalid tz specification')
7882

@@ -114,21 +118,21 @@ def from_tmy(cls, tmy_metadata, tmy_data=None, **kwargs):
114118
# might need code to handle the difference between tmy2 and tmy3
115119

116120
# determine if we're dealing with TMY2 or TMY3 data
117-
tmy2 = tmy_metadata.get('StationName', False)
121+
tmy2 = tmy_metadata.get('City', False)
118122

119123
latitude = tmy_metadata['latitude']
120124
longitude = tmy_metadata['longitude']
121125

122126
if tmy2:
123-
altitude = tmy_metadata['SiteElevation']
124-
name = tmy_metadata['StationName']
125-
tz = tmy_metadata['SiteTimeZone']
126-
else:
127-
altitude = tmy_metadata['alititude']
127+
name = tmy_metadata['City']
128+
else:
128129
name = tmy_metadata['Name']
129-
tz = tmy_metadata['TZ']
130-
131-
new_object = cls(latitude, longitude, tz, altitude, name, **kwargs)
130+
131+
tz = tmy_metadata['TZ']
132+
altitude = tmy_metadata['altitude']
133+
134+
new_object = cls(latitude, longitude, tz=tz, altitude=altitude,
135+
name=name, **kwargs)
132136

133137
# not sure if this should be assigned regardless of input.
134138
if tmy_data is not None:
@@ -137,26 +141,36 @@ def from_tmy(cls, tmy_metadata, tmy_data=None, **kwargs):
137141
return new_object
138142

139143

140-
def get_solarposition(self, times, **kwargs):
144+
def get_solarposition(self, times, pressure=None, temperature=12,
145+
**kwargs):
141146
"""
142-
Uses the :func:`solarposition.get_solarposition` function
147+
Uses the :py:func:`solarposition.get_solarposition` function
143148
to calculate the solar zenith, azimuth, etc. at this location.
144149
145150
Parameters
146151
----------
147152
times : DatetimeIndex
148-
149-
kwargs passed to :func:`solarposition.get_solarposition`
153+
pressure : None, float, or array-like
154+
If None, pressure will be calculated using
155+
:py:func:`atmosphere.alt2pres` and ``self.altitude``.
156+
temperature : None, float, or array-like
157+
158+
kwargs passed to :py:func:`solarposition.get_solarposition`
150159
151160
Returns
152161
-------
153-
solarposition : DataFrame
162+
solar_position : DataFrame
154163
Columns depend on the ``method`` kwarg, but always include
155-
``zenith`` and ``azimuth``.
164+
``zenith`` and ``azimuth``.
156165
"""
166+
if pressure is None:
167+
pressure = atmosphere.alt2pres(self.altitude)
168+
157169
return solarposition.get_solarposition(times, latitude=self.latitude,
158170
longitude=self.longitude,
159171
altitude=self.altitude,
172+
pressure=pressure,
173+
temperature=temperature,
160174
**kwargs)
161175

162176

@@ -221,14 +235,9 @@ def get_airmass(self, times=None, solar_position=None,
221235
if solar_position is None:
222236
solar_position = self.get_solarposition(times)
223237

224-
apparents = ['simple', 'kasten1966', 'kastenyoung1989',
225-
'gueymard1993', 'pickering2002']
226-
227-
trues = ['youngirvine1967', 'young1994']
228-
229-
if model in apparents:
238+
if model in atmosphere.APPARENT_ZENITH_MODELS:
230239
zenith = solar_position['apparent_zenith']
231-
elif model in trues:
240+
elif model in atmosphere.TRUE_ZENITH_MODELS:
232241
zenith = solar_position['zenith']
233242
else:
234243
raise ValueError('{} is not a valid airmass model'.format(model))

0 commit comments

Comments
 (0)
0