-
Notifications
You must be signed in to change notification settings - Fork 228
Wrap solar #804
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
seisman
merged 136 commits into
GenericMappingTools:master
from
willschlitzer:wrap-solar
Mar 25, 2021
Merged
Wrap solar #804
Changes from all commits
Commits
Show all changes
136 commits
Select commit
Hold shift + click to select a range
27f5d20
Add cyl_transverse_mercator.py
willschlitzer d64983f
Add cyl_universal_transverse_mercator.py
willschlitzer 6ba8185
Changing land color to red in cyl_mercator.py to match GMT docs examp…
willschlitzer 76850ee
Merge branch 'master' into cylindrical-projections
willschlitzer 48431db
Merge branch 'master' of https://github.com/GenericMappingTools/pygmt
willschlitzer 01052d2
Merge branch 'master' of https://github.com/GenericMappingTools/pygmt
willschlitzer c710988
Merge remote-tracking branch 'origin/master'
willschlitzer b94e0a2
Merge branch 'master' of https://github.com/GenericMappingTools/pygmt
willschlitzer 413fec1
Merge branch 'master' of https://github.com/GenericMappingTools/pygmt
willschlitzer be51e2c
Merge branch 'master' of https://github.com/GenericMappingTools/pygmt
willschlitzer bc05e5b
Initial add of solar function to base_plotting.py
willschlitzer 219ba77
Add fill and day_night parameter doc string
willschlitzer 83417d7
Add additional parameters
willschlitzer a68f21d
Add terminator doc strings
willschlitzer 43b75c8
Add timestamp to doc string
willschlitzer 7b65d42
Add test_solar to test_solar.py
willschlitzer 58add00
Add test_solar_coast to test_solar.py
willschlitzer a5e808b
Add test_solar_pen to test_solar.py
willschlitzer 9cd30db
Add test_solar_civil_twighlight and test_solar_nautical_twighlight to…
willschlitzer 9c1221e
Add test_solar_astronomical_twighlight to test_solar.py
willschlitzer de414f7
Add test_solar_fill_transparency to test_solar.py
willschlitzer 8887811
Add 5 tests to test_solar.py
willschlitzer cc02480
Update solar doc string in base_plotting.py
willschlitzer 62c43d7
Add solar to api/index.rst
willschlitzer 01d0a9b
Removing time zone mention until fixed in upstream GMT
willschlitzer 74b7bcb
Remove solar_coast
willschlitzer c7935a1
Remove solar_fill and solar_fill_transparency
willschlitzer 1ea53b8
Remove solar_pen
willschlitzer 25544a9
Remove solar_xy_shift
willschlitzer 6391dea
Remove solar_perspective
willschlitzer 001c76a
Remove unused imports in test_solar.py
willschlitzer 18610a7
Correcting "twighlight" to "twilight"
willschlitzer 0af2d2f
Merge branch 'master' into wrap-solar
willschlitzer c327c08
Add solar.py gallery example
willschlitzer 2d1a05d
Merge branch 'master' into wrap-solar
willschlitzer a722ca5
Move solar function from base_plotting.py to solar.py
willschlitzer cea2f8f
Remove dummy_context unused import
willschlitzer 0085853
change order of modules in __init__.py
willschlitzer 2f46f92
Merge branch 'master' into wrap-solar
willschlitzer 3f960b4
Update pygmt/src/solar.py
willschlitzer bf0e2d5
Update first line of solar doc string
willschlitzer afead71
Merge remote-tracking branch 'origin/wrap-solar' into wrap-solar
willschlitzer 0a7a341
Apply suggestions from code review
willschlitzer 04ee236
Merge branch 'master' into wrap-solar
willschlitzer 0ed4478
Update solar gallery example
willschlitzer b95b404
Update examples/gallery/plot/solar.py
willschlitzer e172457
Apply suggestions from code review
willschlitzer 7ed7684
Add comments to self for datetime parsing
willschlitzer b41e469
Manual merge of master branch into wrap-solar
willschlitzer fe3b9c0
Run make format
willschlitzer d99a384
Merge updates
willschlitzer ace6880
Fix import statements
willschlitzer 0b3b4d8
Style fix
willschlitzer 43db5ad
Style fix
willschlitzer 338cb4f
Allow solar to accept terminator types and datetime objects
willschlitzer 5cc7993
Merge branch 'master' into wrap-solar
willschlitzer 0427019
Format fixes; add type of error to except statement
willschlitzer 9cc19ed
Change error raising
willschlitzer cd64f39
Update date string building format
willschlitzer d8090fe
Remove old parameters, delete invalid tests
willschlitzer 87097aa
Make suggested refactors for get_terminator_type and get_datetime_string
willschlitzer b2a0142
Move all funtions into solar function
willschlitzer 672c04d
Update tests, change gallery example
willschlitzer c065e8f
Merge branch 'master' into wrap-solar
willschlitzer d2acbfa
Naming fix
willschlitzer d835de4
Update documentation for solar
willschlitzer 7580b2e
Formatting fixes
willschlitzer 857194a
Apply suggestions from code review
willschlitzer 7596ab0
Merge branch 'master' into wrap-solar
willschlitzer eb49c79
Update pygmt/src/solar.py
willschlitzer 3316a36
Remove term_string variable from solar.py
willschlitzer 766c4eb
Apply suggestions from code review
willschlitzer 0e8fb1c
Run make format
willschlitzer 16811ca
Change test to use non-default terminator type
willschlitzer b7b5c81
[format-command] fixes
actions-bot 034aca8
Update pygmt/src/solar.py
willschlitzer 2290874
Merge branch 'master' into wrap-solar
willschlitzer 8950aaa
Merge branch 'master' into wrap-solar
willschlitzer 8e8700d
Merge branch 'master' into wrap-solar
seisman 5f69372
Merge branch 'master' into wrap-solar
willschlitzer 06332bb
Apply suggestions from code review
willschlitzer 13228e5
Merge branch 'master' into wrap-solar
willschlitzer 79c4182
run make format
willschlitzer e6ae4c0
Merge branch 'master' into wrap-solar
willschlitzer e367ea8
Update testing in test_solar.py
willschlitzer b2092e4
Add dvc file
willschlitzer aadca32
replace short aliases with long aliases
willschlitzer b545fb9
Update test_solar.py tests
willschlitzer 33b67de
Add test_solar_set_terminator_datetime_object.png.dvc and test_solar_…
willschlitzer b161432
remove unused import
willschlitzer 0e5b65f
remove if statement for testing if T is in kwargs
willschlitzer 386ea48
move solar gallery example to embellishments
willschlitzer ac63d8a
add if statement for T being passed
willschlitzer e4f8c19
add test for raising GMTInvalidInput when T is passed
willschlitzer 02c77fa
Update pygmt/src/solar.py
willschlitzer 14265f4
Apply suggestions from code review
willschlitzer e60ce74
formatting fix
willschlitzer f1ace0c
add TODO
willschlitzer 990bc65
update pen width
willschlitzer 2e5e151
update teminator_datetime docstring
willschlitzer 631b24d
update default time in docstring
willschlitzer d7afb77
run make format
willschlitzer 0a3350d
Apply suggestions from code review
willschlitzer 2a30f5f
Merge branch 'master' into wrap-solar
willschlitzer 05f804d
Apply suggestions from code review
willschlitzer c0502ee
Merge branch 'master' into wrap-solar
willschlitzer 7124ad1
run make format
willschlitzer b52a12a
Apply suggestions from code review
willschlitzer 06d7d7b
Apply suggestions from code review
willschlitzer d3baca7
remove TODO
willschlitzer a085624
Merge branch 'master' into wrap-solar
willschlitzer 8ebe008
[format-command] fixes
actions-bot b662a77
Update pygmt/src/solar.py
willschlitzer 8719002
fix line length
willschlitzer 886c15f
update tests
willschlitzer 5789b26
run make format
willschlitzer c037a96
style fix
willschlitzer df5ca90
Merge branch 'master' into wrap-solar
willschlitzer f497e99
Update pygmt/tests/test_solar.py
willschlitzer c4f4dbc
update test_solar.py
willschlitzer 760a9a3
Merge remote-tracking branch 'origin/wrap-solar' into wrap-solar
willschlitzer 5185699
update test_solar.py
willschlitzer d6b0111
Merge branch 'master' into wrap-solar
willschlitzer 1159209
Update pygmt/tests/test_solar.py
willschlitzer 2cad810
changing order of tests in test_solar.py
willschlitzer 6403535
Merge remote-tracking branch 'origin/wrap-solar' into wrap-solar
willschlitzer 2490763
removing unnecessary dvc file
willschlitzer a231632
Update pygmt/tests/test_solar.py
willschlitzer 3739063
Apply suggestions from code review
willschlitzer 6d96015
update dvc
willschlitzer d03808b
Merge branch 'master' into wrap-solar
willschlitzer 3c7db18
Merge branch 'master' into wrap-solar
willschlitzer ca28e15
Add a 'T' for the datetime to avoid space in filename
weiji14 b8edbdc
Merge branch 'master' into wrap-solar
weiji14 c222ce9
Set a pytest.param id to avoid spaces and colons in filename
weiji14 bab37d3
Update pytest.param id
seisman 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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
""" | ||
Day-night terminator line and twilights | ||
--------------------------------------- | ||
|
||
Use :meth:`pygmt.Figure.solar` to show the different transition stages between daytime | ||
and nightime. The parameter ``terminator`` is used to set the twilight stage, and can be | ||
either 'day-night' (brightest), 'civil', 'nautical', or 'astronomical' (darkest). Refer | ||
to https://en.wikipedia.org/wiki/Twilight for more information. | ||
""" | ||
import datetime | ||
|
||
import pygmt | ||
|
||
fig = pygmt.Figure() | ||
# Create a figure showing the global region on a Mollweide projection | ||
# Land color is set to dark green and water color is set to light blue | ||
fig.coast(region="d", projection="W0/15c", land="darkgreen", water="lightblue") | ||
# Set a time for the day-night terminator and twilights, 1700 UTC on January 1, 2000 | ||
terminator_datetime = datetime.datetime( | ||
year=2000, month=1, day=1, hour=17, minute=0, second=0 | ||
) | ||
# Set the pen line to be 0.5p thick | ||
# Set the fill for the night area to be navy blue at different transparency levels | ||
fig.solar( | ||
terminator="day_night", | ||
terminator_datetime=terminator_datetime, | ||
fill="navyblue@95", | ||
pen="0.5p", | ||
) | ||
fig.solar( | ||
terminator="civil", | ||
terminator_datetime=terminator_datetime, | ||
fill="navyblue@85", | ||
pen="0.5p", | ||
) | ||
fig.solar( | ||
terminator="nautical", | ||
terminator_datetime=terminator_datetime, | ||
fill="navyblue@80", | ||
pen="0.5p", | ||
) | ||
fig.solar( | ||
terminator="astronomical", | ||
terminator_datetime=terminator_datetime, | ||
fill="navyblue@80", | ||
pen="0.5p", | ||
) | ||
fig.show() |
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 |
---|---|---|
|
@@ -391,6 +391,7 @@ def _repr_html_(self): | |
plot, | ||
plot3d, | ||
set_panel, | ||
solar, | ||
subplot, | ||
text, | ||
) |
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 |
---|---|---|
@@ -0,0 +1,97 @@ | ||
""" | ||
solar - Plot day-night terminators and twilight. | ||
""" | ||
import pandas as pd | ||
from pygmt.clib import Session | ||
from pygmt.exceptions import GMTInvalidInput | ||
from pygmt.helpers import build_arg_string, fmt_docstring, kwargs_to_strings, use_alias | ||
|
||
|
||
@fmt_docstring | ||
@use_alias( | ||
B="frame", | ||
G="fill", | ||
J="projection", | ||
R="region", | ||
U="timestamp", | ||
V="verbose", | ||
W="pen", | ||
X="xshift", | ||
Y="yshift", | ||
c="panel", | ||
p="perspective", | ||
t="transparency", | ||
) | ||
@kwargs_to_strings(R="sequence", c="sequence_comma", p="sequence") | ||
def solar(self, terminator="d", terminator_datetime=None, **kwargs): | ||
r""" | ||
Plot day-light terminators or twilights. | ||
|
||
This function plots the day-night terminator. Alternatively, it can plot | ||
the terminators for civil twilight, nautical twilight, or astronomical | ||
twilight. | ||
|
||
Full parameter list at :gmt-docs:`solar.html` | ||
|
||
willschlitzer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{aliases} | ||
|
||
Parameters | ||
---------- | ||
terminator : str | ||
Set the type of terminator displayed. Valid arguments are | ||
**day_night**, **civil**, **nautical**, and **astronomical**, which | ||
can be set with either the full name or the first letter of the name. | ||
[Default is **day_night**] | ||
willschlitzer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Refer to https://en.wikipedia.org/wiki/Twilight for the definitions of | ||
different types of twilight. | ||
terminator_datetime : str or datetime object | ||
Set the UTC date and time of the displayed terminator. It can be | ||
passed as a string or Python datetime object. | ||
[Default is the current UTC date and time] | ||
{R} | ||
{J} | ||
{B} | ||
fill : str | ||
Color or pattern for filling of terminators. | ||
pen : str | ||
Set pen attributes for lines. The default pen | ||
is ``default,black,solid``. | ||
{U} | ||
{V} | ||
{XY} | ||
{c} | ||
{p} | ||
{t} | ||
""" | ||
seisman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
kwargs = self._preprocess(**kwargs) # pylint: disable=protected-access | ||
if "T" in kwargs: | ||
raise GMTInvalidInput( | ||
"Use 'terminator' and 'terminator_datetime' instead of 'T'." | ||
) | ||
if terminator not in [ | ||
"day_night", | ||
"civil", | ||
"nautical", | ||
"astronomical", | ||
"d", | ||
"c", | ||
"n", | ||
"a", | ||
]: | ||
raise GMTInvalidInput( | ||
f"Unrecognized solar terminator type '{terminator}'. Valid values " | ||
"are 'day_night', 'civil', 'nautical', and 'astronomical'." | ||
) | ||
kwargs["T"] = terminator[0] | ||
if terminator_datetime: | ||
try: | ||
datetime_string = pd.to_datetime(terminator_datetime).strftime( | ||
"%Y-%m-%dT%H:%M:%S.%f" | ||
) | ||
except ValueError as verr: | ||
raise GMTInvalidInput("Unrecognized datetime format.") from verr | ||
kwargs["T"] += f"+d{datetime_string}" | ||
with Session() as lib: | ||
lib.call_module("solar", build_arg_string(kwargs)) |
4 changes: 4 additions & 0 deletions
4
pygmt/tests/baseline/test_solar_set_terminator_datetime.png.dvc
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
outs: | ||
- md5: 0a7f4959b500b6fa3a560a6368db0f90 | ||
size: 25982 | ||
path: test_solar_set_terminator_datetime.png |
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
outs: | ||
- md5: 54c92bea64e0fc76c62601cb6131f22e | ||
size: 44160 | ||
path: test_solar_terminators.png |
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 |
---|---|---|
@@ -0,0 +1,120 @@ | ||
""" | ||
willschlitzer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Tests for solar. | ||
""" | ||
import datetime | ||
|
||
import pytest | ||
from pygmt import Figure | ||
from pygmt.exceptions import GMTInvalidInput | ||
|
||
|
||
@pytest.mark.mpl_image_compare | ||
willschlitzer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
def test_solar_terminators(): | ||
""" | ||
Test passing the solar argument with a time string and no terminator type | ||
to confirm the default terminator type. | ||
""" | ||
fig = Figure() | ||
fig.basemap(region="d", projection="W0/15c", frame="a") | ||
fig.solar( | ||
terminator="d", | ||
pen="1p,blue", | ||
terminator_datetime="1990-02-17 04:25:00", | ||
) | ||
fig.solar( | ||
terminator="a", | ||
pen="1p,red", | ||
terminator_datetime="1990-02-17 04:25:00", | ||
) | ||
fig.solar( | ||
terminator="c", | ||
pen="1p,green", | ||
terminator_datetime="1990-02-17 04:25:00", | ||
) | ||
fig.solar( | ||
terminator="n", | ||
pen="1p,yellow", | ||
terminator_datetime="1990-02-17 04:25:00", | ||
) | ||
return fig | ||
|
||
|
||
@pytest.mark.mpl_image_compare(filename="test_solar_set_terminator_datetime.png") | ||
@pytest.mark.parametrize( | ||
"terminator_datetime", | ||
[ | ||
pytest.param("1990-02-17 04:25:00", id="terminator_datetime_string"), | ||
datetime.datetime(year=1990, month=2, day=17, hour=4, minute=25, second=0), | ||
], | ||
) | ||
def test_solar_set_terminator_datetime(terminator_datetime): | ||
""" | ||
Test passing the solar argument with the day_night terminator and a | ||
datetime string. | ||
""" | ||
fig = Figure() | ||
fig.solar( | ||
region="d", | ||
projection="W0/15c", | ||
frame="a", | ||
terminator="day_night", | ||
terminator_datetime=terminator_datetime, | ||
) | ||
return fig | ||
|
||
|
||
def test_invalid_terminator_type(): | ||
""" | ||
Test if solar fails when it receives an invalid terminator type. | ||
""" | ||
fig = Figure() | ||
with pytest.raises(GMTInvalidInput): | ||
fig.solar( | ||
region="d", | ||
projection="W0/15c", | ||
frame="a", | ||
terminator="invalid", | ||
) | ||
|
||
|
||
def test_invalid_parameter(): | ||
""" | ||
Test if solar fails when it receives a GMT argument for 'T' instead of the | ||
PyGMT arguments for 'terminator' and 'terminator_datetime'. | ||
""" | ||
fig = Figure() | ||
with pytest.raises(GMTInvalidInput): | ||
# Use single-letter option 'T' for testing | ||
fig.solar( | ||
region="d", projection="W0/15c", frame="a", T="d+d1990-02-17T04:25:00" | ||
willschlitzer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) | ||
|
||
|
||
def test_invalid_datetime(): | ||
""" | ||
Test if solar fails when it receives an invalid datetime string. | ||
""" | ||
fig = Figure() | ||
with pytest.raises(GMTInvalidInput): | ||
fig.solar( | ||
region="d", | ||
projection="W0/15c", | ||
frame="a", | ||
terminator_datetime="199A-02-17 04:25:00", | ||
) | ||
|
||
|
||
@pytest.mark.mpl_image_compare(filename="test_solar_set_terminator_datetime.png") | ||
def test_solar_default_terminator(): | ||
""" | ||
Test passing the solar argument with a time string and no terminator type | ||
to confirm the default terminator type. | ||
""" | ||
fig = Figure() | ||
fig.solar( | ||
region="d", | ||
projection="W0/15c", | ||
frame="a", | ||
terminator_datetime="1990-02-17 04:25:00", | ||
) | ||
return fig |
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.
Uh oh!
There was an error while loading. Please reload this page.