Skip to content

Commit a1d763c

Browse files
committed
* Change for permitting the creation of location object from epw metadata with function from_epw
1 parent ee6d951 commit a1d763c

File tree

2 files changed

+49
-3
lines changed

2 files changed

+49
-3
lines changed

pvlib/location.py

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,42 @@ def from_tmy(cls, tmy_metadata, tmy_data=None, **kwargs):
124124

125125
# not sure if this should be assigned regardless of input.
126126
if tmy_data is not None:
127-
new_object.tmy_data = tmy_data
127+
new_object.weather_data = tmy_data
128+
129+
return new_object
130+
131+
@classmethod
132+
def from_epw(cls, epw_metadata, epw_data=None, **kwargs):
133+
"""
134+
Create a Location object based on a metadata
135+
dictionary from epw data readers.
136+
137+
Parameters
138+
----------
139+
epw_metadata : dict
140+
Returned from epw.read_epw
141+
epw_data : None or DataFrame, default None
142+
Optionally attach the epw data to this object.
143+
144+
Returns
145+
-------
146+
Location object (or the child class of Location that you
147+
called this method from).
148+
"""
149+
150+
latitude = epw_metadata['latitude']
151+
longitude = epw_metadata['longitude']
152+
153+
name = epw_metadata['city']
154+
155+
tz = epw_metadata['TZ']
156+
altitude = epw_metadata['altitude']
157+
158+
new_object = cls(latitude, longitude, tz=tz, altitude=altitude,
159+
name=name, **kwargs)
160+
161+
if epw_data is not None:
162+
new_object.weather_data = epw_data
128163

129164
return new_object
130165

pvlib/test/test_location.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ def test_from_tmy_3():
218218
assert loc.name is not None
219219
assert loc.altitude != 0
220220
assert loc.tz != 'UTC'
221-
assert_frame_equal(loc.tmy_data, data)
221+
assert_frame_equal(loc.weather_data, data)
222222

223223

224224
def test_from_tmy_2():
@@ -229,7 +229,18 @@ def test_from_tmy_2():
229229
assert loc.name is not None
230230
assert loc.altitude != 0
231231
assert loc.tz != 'UTC'
232-
assert_frame_equal(loc.tmy_data, data)
232+
assert_frame_equal(loc.weather_data, data)
233+
234+
235+
def test_from_epw():
236+
from test_epw import epw_testfile
237+
from pvlib.iotools import read_epw
238+
data, meta = read_epw(epw_testfile)
239+
loc = Location.from_epw(meta, data)
240+
assert loc.name is not None
241+
assert loc.altitude != 0
242+
assert loc.tz != 'UTC'
243+
assert_frame_equal(loc.weather_data, data)
233244

234245

235246
def test_get_solarposition(expected_solpos, golden_mst):

0 commit comments

Comments
 (0)