Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/sphinx/source/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ in some files.
:toctree: generated/

location.Location.from_tmy
location.Location.from_epw


TMY
Expand Down
2 changes: 2 additions & 0 deletions docs/sphinx/source/whatsnew/v0.7.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ Enhancements
* Add `timeout` to :py:func:`pvlib.iotools.get_psm3`.
* Created one new incidence angle modifier (IAM) function for diffuse irradiance:
:py:func:`pvlib.iam.martin_ruiz_diffuse`. (:issue:`751`)
* Add :py:meth:`~pvlib.location.Location.from_epw`, a method to create a Location
object from epw metadata, typically coming from `pvlib.iotools.epw.read_epw`.

Bug fixes
~~~~~~~~~
Expand Down
36 changes: 36 additions & 0 deletions pvlib/location.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,42 @@ def from_tmy(cls, tmy_metadata, tmy_data=None, **kwargs):
# not sure if this should be assigned regardless of input.
if tmy_data is not None:
new_object.tmy_data = tmy_data
new_object.weather = tmy_data

return new_object

@classmethod
def from_epw(cls, metadata, data=None, **kwargs):
"""
Create a Location object based on a metadata
dictionary from epw data readers.

Parameters
----------
metadata : dict
Returned from epw.read_epw
data : None or DataFrame, default None
Optionally attach the epw data to this object.

Returns
-------
Location object (or the child class of Location that you
called this method from).
"""

latitude = metadata['latitude']
longitude = metadata['longitude']

name = metadata['city']

tz = metadata['TZ']
altitude = metadata['altitude']

new_object = cls(latitude, longitude, tz=tz, altitude=altitude,
name=name, **kwargs)

if data is not None:
new_object.weather = data

return new_object

Expand Down
15 changes: 13 additions & 2 deletions pvlib/test/test_location.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def test_from_tmy_3():
assert loc.name is not None
assert loc.altitude != 0
assert loc.tz != 'UTC'
assert_frame_equal(loc.tmy_data, data)
assert_frame_equal(loc.weather, data)


def test_from_tmy_2():
Expand All @@ -229,7 +229,18 @@ def test_from_tmy_2():
assert loc.name is not None
assert loc.altitude != 0
assert loc.tz != 'UTC'
assert_frame_equal(loc.tmy_data, data)
assert_frame_equal(loc.weather, data)


def test_from_epw():
from test_epw import epw_testfile
from pvlib.iotools import read_epw
data, meta = read_epw(epw_testfile)
loc = Location.from_epw(meta, data)
assert loc.name is not None
assert loc.altitude != 0
assert loc.tz != 'UTC'
assert_frame_equal(loc.weather, data)


def test_get_solarposition(expected_solpos, golden_mst):
Expand Down