-
Notifications
You must be signed in to change notification settings - Fork 1.1k
sunrise and sunset from pyephem #588
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
Changes from 3 commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
90ea2e0
Initial commit for ephem_next_rise_set
cwhanse 0b9df18
Stickler issues
cwhanse 86cdfa7
Change test result and rounding to nearest minute
cwhanse 06aef3f
Edit test condition, round not floor
cwhanse a22d846
Change explicit rounding to pandas .round('min')
cwhanse 719009d
More test fixes
cwhanse aa4f1d6
Fix sec keyword
cwhanse c08d213
Add test for transit
cwhanse f192547
Fix del statement
cwhanse 377658b
Fix column order
cwhanse f338781
Change reference solution to NREL SPA website
cwhanse a3bedc0
Adjust pressure and temp for pyephem
cwhanse 17564dd
Add horizon kwarg for pyephem
cwhanse c29ed06
Separate rise, set test for spa and pyephem
cwhanse a3d143d
Add horizon kwarg to pyephem, fix test condition for spa
cwhanse 99a75a0
Add horizon kwarg to calc_time
cwhanse 95187d5
Extend tests for next_rise_set_ephem
cwhanse e318bad
Remove dtype from expected...spa
cwhanse a88a5b6
Add previous rise/set capability
cwhanse 2121aa0
style fixes
cwhanse c75b10e
Fix expected result
cwhanse f85a46a
Fix timezone test
cwhanse 6238321
Documentation updates
cwhanse 3618022
Fix spacing
cwhanse 36bf3cc
Add transit, change golden to fixture, add horizon kwarg and error tests
cwhanse 39956cc
style fixes
cwhanse c0ae1c5
Merge branch 'master' into ephem_rise_set
cwhanse f615f12
Fix references to fixture golden_mst, golden
cwhanse 47c95c5
Add transit output to rise_set_transit_ephem
cwhanse bef44f6
Fix transit conflict
cwhanse c9b5348
Fix column order
cwhanse 92e0677
Minor test adjustments
cwhanse db08f8d
Add handling of utcoffset
cwhanse c05bae7
Inline comment
cwhanse da2a0e2
Merge branch 'master' into ephem_rise_set
wholmgren File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ | |
|
||
tol = 5 | ||
|
||
|
||
@pytest.fixture() | ||
def expected_solpos(): | ||
return pd.DataFrame({'elevation': 39.872046, | ||
|
@@ -37,6 +38,7 @@ def expected_solpos(): | |
'apparent_elevation': 39.888378}, | ||
index=['2003-10-17T12:30:30Z']) | ||
|
||
|
||
@pytest.fixture() | ||
def expected_solpos_multi(): | ||
return pd.DataFrame({'elevation': [39.872046, 39.505196], | ||
|
@@ -45,6 +47,22 @@ def expected_solpos_multi(): | |
'apparent_elevation': [39.888378, 39.521740]}, | ||
index=[['2003-10-17T12:30:30Z', '2003-10-18T12:30:30Z']]) | ||
|
||
|
||
@pytest.fixture() | ||
cwhanse marked this conversation as resolved.
Show resolved
Hide resolved
|
||
def expected_rise_set(): | ||
# for Golden, CO, from USNO website | ||
times = pd.DatetimeIndex([datetime.datetime(2015, 1, 2), | ||
datetime.datetime(2015, 8, 2), | ||
cwhanse marked this conversation as resolved.
Show resolved
Hide resolved
|
||
]).tz_localize('MST') | ||
sunrise = pd.DatetimeIndex([datetime.datetime(2015, 1, 2, 7, 22, 0), | ||
datetime.datetime(2015, 8, 2, 5, 1, 0) | ||
]).tz_localize('MST').tolist() | ||
sunset = pd.DatetimeIndex([datetime.datetime(2015, 1, 2, 16, 48, 0), | ||
datetime.datetime(2015, 8, 2, 19, 13, 0) | ||
]).tz_localize('MST').tolist() | ||
return pd.DataFrame({'sunrise': sunrise, 'sunset': sunset}, index=times) | ||
|
||
|
||
# the physical tests are run at the same time as the NREL SPA test. | ||
# pyephem reproduces the NREL result to 2 decimal places. | ||
# this doesn't mean that one code is better than the other. | ||
|
@@ -125,7 +143,7 @@ def test_spa_python_numba_physical_dst(expected_solpos): | |
|
||
|
||
@needs_pandas_0_17 | ||
def test_get_sun_rise_set_transit(): | ||
def test_get_sun_rise_set_transit(expected_rise_set): | ||
south = Location(-35.0, 0.0, tz='UTC') | ||
times = pd.DatetimeIndex([datetime.datetime(1996, 7, 5, 0), | ||
datetime.datetime(2004, 12, 4, 0)] | ||
|
@@ -136,10 +154,11 @@ def test_get_sun_rise_set_transit(): | |
sunset = pd.DatetimeIndex([datetime.datetime(1996, 7, 5, 17, 1, 4), | ||
datetime.datetime(2004, 12, 4, 19, 2, 2)] | ||
).tz_localize('UTC').tolist() | ||
frame = pd.DataFrame({'sunrise':sunrise, 'sunset':sunset}, index=times) | ||
cwhanse marked this conversation as resolved.
Show resolved
Hide resolved
cwhanse marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
result = solarposition.get_sun_rise_set_transit(times, south.latitude, | ||
south.longitude, | ||
delta_t=64.0) | ||
frame = pd.DataFrame({'sunrise':sunrise, 'sunset':sunset}, index=times) | ||
result_rounded = pd.DataFrame(index=result.index) | ||
# need to iterate because to_datetime does not accept 2D data | ||
# the rounding fails on pandas < 0.17 | ||
|
@@ -150,33 +169,42 @@ def test_get_sun_rise_set_transit(): | |
del result_rounded['transit'] | ||
assert_frame_equal(frame, result_rounded) | ||
|
||
|
||
# tests from USNO | ||
# Golden | ||
golden = Location(39.0, -105.0, tz='MST') | ||
times = pd.DatetimeIndex([datetime.datetime(2015, 1, 2), | ||
datetime.datetime(2015, 8, 2),] | ||
).tz_localize('MST') | ||
sunrise = pd.DatetimeIndex([datetime.datetime(2015, 1, 2, 7, 19, 2), | ||
datetime.datetime(2015, 8, 2, 5, 1, 26) | ||
]).tz_localize('MST').tolist() | ||
sunset = pd.DatetimeIndex([datetime.datetime(2015, 1, 2, 16, 49, 10), | ||
datetime.datetime(2015, 8, 2, 19, 11, 31) | ||
]).tz_localize('MST').tolist() | ||
result = solarposition.get_sun_rise_set_transit(times, golden.latitude, | ||
# test for Golden, CO compare to USNO | ||
result = solarposition.get_sun_rise_set_transit(expected_rise_set.index, | ||
golden.latitude, | ||
golden.longitude, | ||
delta_t=64.0) | ||
frame = pd.DataFrame({'sunrise':sunrise, 'sunset':sunset}, index=times) | ||
|
||
# round to nearest minute | ||
result_rounded = pd.DataFrame(index=result.index) | ||
# need to iterate because to_datetime does not accept 2D data | ||
# the rounding fails on pandas < 0.17 | ||
for col, data in result.iteritems(): | ||
result_rounded[col] = (pd.to_datetime( | ||
np.floor(data.values.astype(np.int64) / 1e9)*1e9, utc=True) | ||
np.floor(data.values.astype(np.int64) / 60e9)*60e9, utc=True) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. E226 missing whitespace around arithmetic operator |
||
.tz_convert('MST')) | ||
|
||
del result_rounded['transit'] | ||
assert_frame_equal(frame, result_rounded) | ||
assert_frame_equal(expected_rise_set, result_rounded) | ||
|
||
|
||
@requires_ephem | ||
def test_ephem_next_rise_set(expected_rise_set): | ||
# test for Golden, CO compare to USNO | ||
result = solarposition.ephem_next_rise_set(expected_rise_set.index, | ||
golden.latitude, | ||
golden.longitude, | ||
golden.altitude, | ||
pressure=101325, | ||
temperature=12) | ||
# round to nearest minute | ||
result_rounded = pd.DataFrame(index=result.index) | ||
for col, data in result.iteritems(): | ||
result_rounded[col] = (pd.to_datetime( | ||
np.floor(data.values.astype(np.int64) / 60e9)*60e9, utc=True) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. E226 missing whitespace around arithmetic operator |
||
.tz_convert('MST')) | ||
|
||
assert_frame_equal(expected_rise_set, result_rounded) | ||
|
||
|
||
@requires_ephem | ||
|
@@ -190,6 +218,7 @@ def test_pyephem_physical(expected_solpos): | |
assert_frame_equal(expected_solpos.round(2), | ||
ephem_data[expected_solpos.columns].round(2)) | ||
|
||
|
||
@requires_ephem | ||
def test_pyephem_physical_dst(expected_solpos): | ||
times = pd.date_range(datetime.datetime(2003,10,17,13,30,30), periods=1, | ||
|
@@ -201,6 +230,7 @@ def test_pyephem_physical_dst(expected_solpos): | |
assert_frame_equal(expected_solpos.round(2), | ||
ephem_data[expected_solpos.columns].round(2)) | ||
|
||
|
||
@requires_ephem | ||
def test_calc_time(): | ||
import pytz | ||
|
@@ -227,6 +257,7 @@ def test_calc_time(): | |
assert_allclose((az.replace(second=0, microsecond=0) - | ||
epoch_dt).total_seconds(), actual_timestamp) | ||
|
||
|
||
@requires_ephem | ||
def test_earthsun_distance(): | ||
times = pd.date_range(datetime.datetime(2003,10,17,13,30,30), | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would
next_sun_rise_set_pyephem
be more consistent with your preferred naming scheme?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I'll change. I have in mind
Location.get_next_sunrise
,Location.get_previous_sunrise
as wrapper methods.