Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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, epw_metadata, epw_data=None, **kwargs):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In retrospect, I wish the from_tmy method signature used metadata and data instead of tmy_metadata and tmy_data. Then both methods would have the signature cls, metadata, data, **kwargs. Adding tmy_ or epw_ to the argument names is redundant and makes it harder to reuse.

"""
Create a Location object based on a metadata
dictionary from epw data readers.

Parameters
----------
epw_metadata : dict
Returned from epw.read_epw
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 = epw_metadata['latitude']
longitude = epw_metadata['longitude']

name = epw_metadata['city']

tz = epw_metadata['TZ']
altitude = epw_metadata['altitude']

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

if epw_data is not None:
new_object.weather = epw_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