Skip to content
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

Wrap solar #804

Merged
merged 136 commits into from
Mar 25, 2021
Merged
Show file tree
Hide file tree
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 Dec 11, 2020
d64983f
Add cyl_universal_transverse_mercator.py
willschlitzer Dec 11, 2020
6ba8185
Changing land color to red in cyl_mercator.py to match GMT docs examp…
willschlitzer Dec 11, 2020
76850ee
Merge branch 'master' into cylindrical-projections
willschlitzer Dec 13, 2020
48431db
Merge branch 'master' of https://github.com/GenericMappingTools/pygmt
willschlitzer Jan 12, 2021
01052d2
Merge branch 'master' of https://github.com/GenericMappingTools/pygmt
willschlitzer Jan 18, 2021
c710988
Merge remote-tracking branch 'origin/master'
willschlitzer Jan 21, 2021
b94e0a2
Merge branch 'master' of https://github.com/GenericMappingTools/pygmt
willschlitzer Jan 21, 2021
413fec1
Merge branch 'master' of https://github.com/GenericMappingTools/pygmt
willschlitzer Jan 22, 2021
be51e2c
Merge branch 'master' of https://github.com/GenericMappingTools/pygmt
willschlitzer Jan 22, 2021
bc05e5b
Initial add of solar function to base_plotting.py
willschlitzer Jan 23, 2021
219ba77
Add fill and day_night parameter doc string
willschlitzer Jan 24, 2021
83417d7
Add additional parameters
willschlitzer Jan 24, 2021
a68f21d
Add terminator doc strings
willschlitzer Jan 24, 2021
43b75c8
Add timestamp to doc string
willschlitzer Jan 24, 2021
7b65d42
Add test_solar to test_solar.py
willschlitzer Jan 24, 2021
58add00
Add test_solar_coast to test_solar.py
willschlitzer Jan 24, 2021
a5e808b
Add test_solar_pen to test_solar.py
willschlitzer Jan 24, 2021
9cd30db
Add test_solar_civil_twighlight and test_solar_nautical_twighlight to…
willschlitzer Jan 24, 2021
9c1221e
Add test_solar_astronomical_twighlight to test_solar.py
willschlitzer Jan 24, 2021
de414f7
Add test_solar_fill_transparency to test_solar.py
willschlitzer Jan 24, 2021
8887811
Add 5 tests to test_solar.py
willschlitzer Jan 24, 2021
cc02480
Update solar doc string in base_plotting.py
willschlitzer Jan 24, 2021
62c43d7
Add solar to api/index.rst
willschlitzer Jan 24, 2021
01d0a9b
Removing time zone mention until fixed in upstream GMT
willschlitzer Jan 24, 2021
74b7bcb
Remove solar_coast
willschlitzer Jan 26, 2021
c7935a1
Remove solar_fill and solar_fill_transparency
willschlitzer Jan 26, 2021
1ea53b8
Remove solar_pen
willschlitzer Jan 26, 2021
25544a9
Remove solar_xy_shift
willschlitzer Jan 26, 2021
6391dea
Remove solar_perspective
willschlitzer Jan 26, 2021
001c76a
Remove unused imports in test_solar.py
willschlitzer Jan 26, 2021
18610a7
Correcting "twighlight" to "twilight"
willschlitzer Jan 26, 2021
0af2d2f
Merge branch 'master' into wrap-solar
willschlitzer Jan 26, 2021
c327c08
Add solar.py gallery example
willschlitzer Jan 26, 2021
2d1a05d
Merge branch 'master' into wrap-solar
willschlitzer Jan 27, 2021
a722ca5
Move solar function from base_plotting.py to solar.py
willschlitzer Jan 27, 2021
cea2f8f
Remove dummy_context unused import
willschlitzer Jan 27, 2021
0085853
change order of modules in __init__.py
willschlitzer Jan 27, 2021
2f46f92
Merge branch 'master' into wrap-solar
willschlitzer Jan 30, 2021
3f960b4
Update pygmt/src/solar.py
willschlitzer Jan 30, 2021
bf0e2d5
Update first line of solar doc string
willschlitzer Jan 30, 2021
afead71
Merge remote-tracking branch 'origin/wrap-solar' into wrap-solar
willschlitzer Jan 30, 2021
0a7a341
Apply suggestions from code review
willschlitzer Feb 3, 2021
04ee236
Merge branch 'master' into wrap-solar
willschlitzer Feb 3, 2021
0ed4478
Update solar gallery example
willschlitzer Feb 3, 2021
b95b404
Update examples/gallery/plot/solar.py
willschlitzer Feb 4, 2021
e172457
Apply suggestions from code review
willschlitzer Feb 4, 2021
7ed7684
Add comments to self for datetime parsing
willschlitzer Feb 5, 2021
b41e469
Manual merge of master branch into wrap-solar
willschlitzer Feb 7, 2021
fe3b9c0
Run make format
willschlitzer Feb 7, 2021
d99a384
Merge updates
willschlitzer Feb 19, 2021
ace6880
Fix import statements
willschlitzer Feb 19, 2021
0b3b4d8
Style fix
willschlitzer Feb 20, 2021
43db5ad
Style fix
willschlitzer Feb 20, 2021
338cb4f
Allow solar to accept terminator types and datetime objects
willschlitzer Feb 20, 2021
5cc7993
Merge branch 'master' into wrap-solar
willschlitzer Feb 20, 2021
0427019
Format fixes; add type of error to except statement
willschlitzer Feb 20, 2021
9cc19ed
Change error raising
willschlitzer Feb 20, 2021
cd64f39
Update date string building format
willschlitzer Feb 20, 2021
d8090fe
Remove old parameters, delete invalid tests
willschlitzer Feb 20, 2021
87097aa
Make suggested refactors for get_terminator_type and get_datetime_string
willschlitzer Feb 21, 2021
b2a0142
Move all funtions into solar function
willschlitzer Feb 21, 2021
672c04d
Update tests, change gallery example
willschlitzer Feb 21, 2021
c065e8f
Merge branch 'master' into wrap-solar
willschlitzer Feb 21, 2021
d2acbfa
Naming fix
willschlitzer Feb 21, 2021
d835de4
Update documentation for solar
willschlitzer Feb 21, 2021
7580b2e
Formatting fixes
willschlitzer Feb 21, 2021
857194a
Apply suggestions from code review
willschlitzer Feb 22, 2021
7596ab0
Merge branch 'master' into wrap-solar
willschlitzer Feb 22, 2021
eb49c79
Update pygmt/src/solar.py
willschlitzer Feb 22, 2021
3316a36
Remove term_string variable from solar.py
willschlitzer Feb 22, 2021
766c4eb
Apply suggestions from code review
willschlitzer Feb 22, 2021
0e8fb1c
Run make format
willschlitzer Feb 22, 2021
16811ca
Change test to use non-default terminator type
willschlitzer Feb 22, 2021
b7b5c81
[format-command] fixes
actions-bot Feb 22, 2021
034aca8
Update pygmt/src/solar.py
willschlitzer Feb 23, 2021
2290874
Merge branch 'master' into wrap-solar
willschlitzer Feb 25, 2021
8950aaa
Merge branch 'master' into wrap-solar
willschlitzer Feb 26, 2021
8e8700d
Merge branch 'master' into wrap-solar
seisman Feb 26, 2021
5f69372
Merge branch 'master' into wrap-solar
willschlitzer Feb 27, 2021
06332bb
Apply suggestions from code review
willschlitzer Feb 28, 2021
13228e5
Merge branch 'master' into wrap-solar
willschlitzer Mar 17, 2021
79c4182
run make format
willschlitzer Mar 17, 2021
e6ae4c0
Merge branch 'master' into wrap-solar
willschlitzer Mar 18, 2021
e367ea8
Update testing in test_solar.py
willschlitzer Mar 18, 2021
b2092e4
Add dvc file
willschlitzer Mar 18, 2021
aadca32
replace short aliases with long aliases
willschlitzer Mar 18, 2021
b545fb9
Update test_solar.py tests
willschlitzer Mar 18, 2021
33b67de
Add test_solar_set_terminator_datetime_object.png.dvc and test_solar_…
willschlitzer Mar 18, 2021
b161432
remove unused import
willschlitzer Mar 18, 2021
0e5b65f
remove if statement for testing if T is in kwargs
willschlitzer Mar 19, 2021
386ea48
move solar gallery example to embellishments
willschlitzer Mar 19, 2021
ac63d8a
add if statement for T being passed
willschlitzer Mar 19, 2021
e4f8c19
add test for raising GMTInvalidInput when T is passed
willschlitzer Mar 19, 2021
02c77fa
Update pygmt/src/solar.py
willschlitzer Mar 19, 2021
14265f4
Apply suggestions from code review
willschlitzer Mar 19, 2021
e60ce74
formatting fix
willschlitzer Mar 19, 2021
f1ace0c
add TODO
willschlitzer Mar 19, 2021
990bc65
update pen width
willschlitzer Mar 19, 2021
2e5e151
update teminator_datetime docstring
willschlitzer Mar 19, 2021
631b24d
update default time in docstring
willschlitzer Mar 19, 2021
d7afb77
run make format
willschlitzer Mar 19, 2021
0a3350d
Apply suggestions from code review
willschlitzer Mar 21, 2021
2a30f5f
Merge branch 'master' into wrap-solar
willschlitzer Mar 21, 2021
05f804d
Apply suggestions from code review
willschlitzer Mar 22, 2021
c0502ee
Merge branch 'master' into wrap-solar
willschlitzer Mar 22, 2021
7124ad1
run make format
willschlitzer Mar 22, 2021
b52a12a
Apply suggestions from code review
willschlitzer Mar 23, 2021
06d7d7b
Apply suggestions from code review
willschlitzer Mar 23, 2021
d3baca7
remove TODO
willschlitzer Mar 23, 2021
a085624
Merge branch 'master' into wrap-solar
willschlitzer Mar 23, 2021
8ebe008
[format-command] fixes
actions-bot Mar 23, 2021
b662a77
Update pygmt/src/solar.py
willschlitzer Mar 23, 2021
8719002
fix line length
willschlitzer Mar 23, 2021
886c15f
update tests
willschlitzer Mar 23, 2021
5789b26
run make format
willschlitzer Mar 23, 2021
c037a96
style fix
willschlitzer Mar 23, 2021
df5ca90
Merge branch 'master' into wrap-solar
willschlitzer Mar 23, 2021
f497e99
Update pygmt/tests/test_solar.py
willschlitzer Mar 23, 2021
c4f4dbc
update test_solar.py
willschlitzer Mar 23, 2021
760a9a3
Merge remote-tracking branch 'origin/wrap-solar' into wrap-solar
willschlitzer Mar 23, 2021
5185699
update test_solar.py
willschlitzer Mar 23, 2021
d6b0111
Merge branch 'master' into wrap-solar
willschlitzer Mar 23, 2021
1159209
Update pygmt/tests/test_solar.py
willschlitzer Mar 23, 2021
2cad810
changing order of tests in test_solar.py
willschlitzer Mar 23, 2021
6403535
Merge remote-tracking branch 'origin/wrap-solar' into wrap-solar
willschlitzer Mar 23, 2021
2490763
removing unnecessary dvc file
willschlitzer Mar 23, 2021
a231632
Update pygmt/tests/test_solar.py
willschlitzer Mar 23, 2021
3739063
Apply suggestions from code review
willschlitzer Mar 23, 2021
6d96015
update dvc
willschlitzer Mar 23, 2021
d03808b
Merge branch 'master' into wrap-solar
willschlitzer Mar 23, 2021
3c7db18
Merge branch 'master' into wrap-solar
willschlitzer Mar 23, 2021
ca28e15
Add a 'T' for the datetime to avoid space in filename
weiji14 Mar 25, 2021
b8edbdc
Merge branch 'master' into wrap-solar
weiji14 Mar 25, 2021
c222ce9
Set a pytest.param id to avoid spaces and colons in filename
weiji14 Mar 25, 2021
bab37d3
Update pytest.param id
seisman Mar 25, 2021
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 doc/api/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Plotting data and laying out the map:
Figure.plot3d
Figure.set_panel
Figure.shift_origin
Figure.solar
Figure.subplot
Figure.text

Expand Down
48 changes: 48 additions & 0 deletions examples/gallery/embellishments/solar.py
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()
1 change: 1 addition & 0 deletions pygmt/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ def _repr_html_(self):
plot,
plot3d,
set_panel,
solar,
subplot,
text,
)
1 change: 1 addition & 0 deletions pygmt/src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from pygmt.src.meca import meca
from pygmt.src.plot import plot
from pygmt.src.plot3d import plot3d
from pygmt.src.solar import solar
from pygmt.src.subplot import set_panel, subplot
from pygmt.src.surface import surface
from pygmt.src.text import text_ as text # "text" is an argument within "text_"
Expand Down
97 changes: 97 additions & 0 deletions pygmt/src/solar.py
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",
willschlitzer marked this conversation as resolved.
Show resolved Hide resolved
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))
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
4 changes: 4 additions & 0 deletions pygmt/tests/baseline/test_solar_terminators.png.dvc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
outs:
- md5: 54c92bea64e0fc76c62601cb6131f22e
size: 44160
path: test_solar_terminators.png
120 changes: 120 additions & 0 deletions pygmt/tests/test_solar.py
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