Skip to content

Commit 274f76c

Browse files
committed
* function location.Location.from_epw added. It permits to create a Location object from metadata of a epw file, typically retrieved with epw.read_epw().
1 parent ee6d951 commit 274f76c

File tree

4 files changed

+52
-2
lines changed

4 files changed

+52
-2
lines changed

docs/sphinx/source/api.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,7 @@ in some files.
376376
:toctree: generated/
377377

378378
location.Location.from_tmy
379+
location.Location.from_epw
379380

380381

381382
TMY

docs/sphinx/source/whatsnew/v0.7.0.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ Enhancements
123123
* Add `timeout` to :py:func:`pvlib.iotools.get_psm3`.
124124
* Created one new incidence angle modifier (IAM) function for diffuse irradiance:
125125
:py:func:`pvlib.iam.martin_ruiz_diffuse`. (:issue:`751`)
126+
* Add :py:meth:`~pvlib.location.Location.from_epw`, a method to create a Location
127+
object from epw metadata, typically coming from `pvlib.iotools.epw.read_epw`.
126128

127129
Bug fixes
128130
~~~~~~~~~

pvlib/location.py

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

129165
return new_object
130166

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

234245

235246
def test_get_solarposition(expected_solpos, golden_mst):

0 commit comments

Comments
 (0)