Skip to content

Location.get_rise_set_transit #606

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Oct 29, 2018
41 changes: 41 additions & 0 deletions pvlib/location.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,3 +276,44 @@ def get_airmass(self, times=None, solar_position=None,
airmass['airmass_absolute'] = airmass_absolute

return airmass

def get_sun_rise_set_transit(self, times, method='pyephem', **kwargs):
"""
Calculate sunrise, sunset and transit times.

Parameters
----------
times : DatetimeIndex
Must be localized to the Location
method : str, default 'pyephem'
'pyephem', 'spa', or 'geometric'

kwargs are passed to the relevant functions. See
solarposition.sun_rise_set_transit_<method> for details.

Returns
-------
result : DataFrame
Column names are: ``sunrise, sunset, transit``.
"""

if method == 'pyephem':
result = solarposition.sun_rise_set_transit_ephem(times,
self.latitude,
self.longitude,
**kwargs)
elif method == 'spa':
result = solarposition.sun_rise_set_transit_spa(times,
self.latitude,
self.longitude,
**kwargs)
elif method == 'geometric':
result = solarposition.sun_rise_set_transit_geometric(times,
self.latitude,
self.longitude,
**kwargs)
else:
raise ValueError('{} is not a valid method. Must be '
'one of pyephem, spa, geometric'
.format(method))
return result
7 changes: 7 additions & 0 deletions pvlib/test/test_location.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from pvlib.location import Location

from test_solarposition import expected_solpos, golden_mst
from test_solarposition import golden, expected_rise_set_ephem

from conftest import requires_scipy

Expand Down Expand Up @@ -311,3 +312,9 @@ def test_Location___repr__():
' tz: US/Arizona'
])
assert tus.__repr__() == expected


def test_get_sun_rise_set_transit(expected_rise_set_ephem):
result = golden.get_sun_rise_set_transit(expected_rise_set_ephem.index,
method='pyephem')
assert_frame_equal(expected_rise_set_ephem, result)