From 27f5d20b85cd1bbfd237ef8e7e0455d07a6efb4d Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Fri, 11 Dec 2020 09:59:50 +0000 Subject: [PATCH 001/103] Add cyl_transverse_mercator.py --- .../cyl/cyl_transverse_mercator.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 examples/projections/cyl/cyl_transverse_mercator.py diff --git a/examples/projections/cyl/cyl_transverse_mercator.py b/examples/projections/cyl/cyl_transverse_mercator.py new file mode 100644 index 00000000000..fc8bb2198b9 --- /dev/null +++ b/examples/projections/cyl/cyl_transverse_mercator.py @@ -0,0 +1,19 @@ +""" +Transverse Mercator +=================== + +``T[lon0/][lat0/]width``: Give central meridian ``lon0``, the latitude of the +origin ``lat0`` (optional), and the figure width. +""" +import pygmt + +fig = pygmt.Figure() +fig.coast( + region=[20, 50, 30, 45], + projection="T35/12c", + land="lightbrown", + water="seashell", + shorelines="thinnest", + frame="afg", +) +fig.show() From d64983ff1ae3e046ba76697f8980e12c4600475c Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Fri, 11 Dec 2020 10:40:06 +0000 Subject: [PATCH 002/103] Add cyl_universal_transverse_mercator.py --- .../cyl/cyl_universal_transverse_mercator.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 examples/projections/cyl/cyl_universal_transverse_mercator.py diff --git a/examples/projections/cyl/cyl_universal_transverse_mercator.py b/examples/projections/cyl/cyl_universal_transverse_mercator.py new file mode 100644 index 00000000000..47259c5bd6c --- /dev/null +++ b/examples/projections/cyl/cyl_universal_transverse_mercator.py @@ -0,0 +1,19 @@ +""" +Universal Transverse Mercator +============================= + +``U[UTM Zone/][lat0/]width``: Give UTM Zone ``UTM Zone``, and the figure width. +""" +import pygmt + +fig = pygmt.Figure() +# UTM Zone is set to 52R +fig.coast( + region=[127.5, 128.5, 26, 27], + projection="U52R/12c", + land="lightgreen", + water="lightblue", + shorelines="thinnest", + frame="afg", +) +fig.show() From 6ba8185f68bc7dbc76a2787540083287204a7ea4 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Fri, 11 Dec 2020 10:48:29 +0000 Subject: [PATCH 003/103] Changing land color to red in cyl_mercator.py to match GMT docs example; changing units from US to SI --- examples/projections/cyl/cyl_mercator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/projections/cyl/cyl_mercator.py b/examples/projections/cyl/cyl_mercator.py index d2e54886e6f..bfe22ba87a9 100644 --- a/examples/projections/cyl/cyl_mercator.py +++ b/examples/projections/cyl/cyl_mercator.py @@ -8,5 +8,5 @@ import pygmt fig = pygmt.Figure() -fig.coast(region=[0, 360, -80, 80], frame="afg", land="gray", projection="M0/0/8i") +fig.coast(region=[0, 360, -80, 80], frame="afg", land="red", projection="M0/0/12c") fig.show() From bc05e5b23e4a3c6abffad67f20fae04613790039 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Sat, 23 Jan 2021 22:36:43 +0000 Subject: [PATCH 004/103] Initial add of solar function to base_plotting.py --- pygmt/base_plotting.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/pygmt/base_plotting.py b/pygmt/base_plotting.py index bac311f24f6..7724f9c01c9 100644 --- a/pygmt/base_plotting.py +++ b/pygmt/base_plotting.py @@ -1983,3 +1983,30 @@ def update_pointers(data_pointers): with file_context as fname: arg_str = " ".join([fname, build_arg_string(kwargs)]) lib.call_module("meca", arg_str) + + @fmt_docstring + @use_alias( + R="region", + J="projection", + G="fill", + N="inverse", + B="frame", + Td="terminator", + Tc="civil_twighlight", + Tn="nautical_twighlight", + Ta="astronomical_twighlight", + W="pen", + U="timestamp", + V="verbose", + X="xshift", + Y="yshift", + p="perspective", + ) + @kwargs_to_strings(R="sequence", p="sequence") + def solar(self, **kwargs): + r""" + Wrap solar + """ + kwargs = self._preprocess(**kwargs) + with Session() as lib: + lib.call_module("solar", build_arg_string(kwargs)) From 219ba776514f0d6244a856c69267d5616cd3f7b7 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Sun, 24 Jan 2021 11:19:20 +0000 Subject: [PATCH 005/103] Add fill and day_night parameter doc string --- pygmt/base_plotting.py | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/pygmt/base_plotting.py b/pygmt/base_plotting.py index 7724f9c01c9..da97f6efd31 100644 --- a/pygmt/base_plotting.py +++ b/pygmt/base_plotting.py @@ -1989,9 +1989,9 @@ def update_pointers(data_pointers): R="region", J="projection", G="fill", - N="inverse", + #N="inverse", B="frame", - Td="terminator", + Td="day_night", Tc="civil_twighlight", Tn="nautical_twighlight", Ta="astronomical_twighlight", @@ -2005,7 +2005,29 @@ def update_pointers(data_pointers): @kwargs_to_strings(R="sequence", p="sequence") def solar(self, **kwargs): r""" - Wrap solar + Plots the day-night terminator. + + {aliases} + + Parameters + ---------- + {R} + {J} + {B} + fill : str + *fill color*\ [**@**\ *transparency*] + The fill color for the night-area plotted. The optional + transparency parameter can be appended after the color + using **@** after the color. + day_night : bool or str + [**+d**\ *date*\ ][**+z**\ *time zone*\ ] + Plots the day/night terminator. If the argument is ``True``, the + current day-night terminator is plotted. Optionally, **+d** can be + added, along with the date and time, to see the day/night + terminator at a specific time. The date is added in ISO format, + e.g. 12:15 UTC on April 25, 2000 is ``2000-04-25T12:15:00``. To + use a timezone other than UTC, append **+z** followed by + the *time zone*\ . """ kwargs = self._preprocess(**kwargs) with Session() as lib: From 83417d79e9b98d259d7b74756d9973151398602e Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Sun, 24 Jan 2021 11:45:16 +0000 Subject: [PATCH 006/103] Add additional parameters --- pygmt/base_plotting.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pygmt/base_plotting.py b/pygmt/base_plotting.py index da97f6efd31..9554280ddf5 100644 --- a/pygmt/base_plotting.py +++ b/pygmt/base_plotting.py @@ -1989,7 +1989,6 @@ def update_pointers(data_pointers): R="region", J="projection", G="fill", - #N="inverse", B="frame", Td="day_night", Tc="civil_twighlight", @@ -2028,6 +2027,12 @@ def solar(self, **kwargs): e.g. 12:15 UTC on April 25, 2000 is ``2000-04-25T12:15:00``. To use a timezone other than UTC, append **+z** followed by the *time zone*\ . + pen : str + Set pen attributes for lines or the outline of symbols + [Defaults: width = default, color = black, style = solid]. + {XY} + {p} + {V} """ kwargs = self._preprocess(**kwargs) with Session() as lib: From a68f21d8d51d4e01ff07b047c7978545b33940e2 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Sun, 24 Jan 2021 11:48:59 +0000 Subject: [PATCH 007/103] Add terminator doc strings --- pygmt/base_plotting.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/pygmt/base_plotting.py b/pygmt/base_plotting.py index 9554280ddf5..20aef9c86f1 100644 --- a/pygmt/base_plotting.py +++ b/pygmt/base_plotting.py @@ -2027,6 +2027,37 @@ def solar(self, **kwargs): e.g. 12:15 UTC on April 25, 2000 is ``2000-04-25T12:15:00``. To use a timezone other than UTC, append **+z** followed by the *time zone*\ . + civil_twighlight" : bool or str + [**+d**\ *date*\ ][**+z**\ *time zone*\ ] + Plots the civil twighlight terminator. If the argument is + ``True``, the current civil twighlight terminator is plotted. + Optionally, **+d** can be added, along with the date and time, to + see the day/night terminator at a specific time. The date is added + in ISO format, + e.g. 12:15 UTC on April 25, 2000 is ``2000-04-25T12:15:00``. To + use a timezone other than UTC, append **+z** followed by + the *time zone*\ . + nautical_twighlight : bool or str + [**+d**\ *date*\ ][**+z**\ *time zone*\ ] + Plots the nautical twighlight terminator. If the argument is + ``True``, the current nautical twighlight terminator is plotted. + Optionally, **+d** can be added, along with the date and time, to + see the day/night terminator at a specific time. The date is added + in ISO format, + e.g. 12:15 UTC on April 25, 2000 is ``2000-04-25T12:15:00``. To + use a timezone other than UTC, append **+z** followed by + the *time zone*\ . + astronomical_twighlight : bool or str + [**+d**\ *date*\ ][**+z**\ *time zone*\ ] + Plots the astronomical twighlight terminator. If the argument is + ``True``, the current astronomical twighlight terminator is + plotted. Optionally, **+d** can be added, along with the date and + time, to see the day/night terminator at a specific time. The date + is added in ISO format, + e.g. 12:15 UTC on April 25, 2000 is ``2000-04-25T12:15:00``. To + use a timezone other than UTC, append **+z** followed by + the *time zone*\ . + pen : str Set pen attributes for lines or the outline of symbols [Defaults: width = default, color = black, style = solid]. From 43b75c868711514a6809b946976220bc01ba4044 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Sun, 24 Jan 2021 11:50:06 +0000 Subject: [PATCH 008/103] Add timestamp to doc string --- pygmt/base_plotting.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygmt/base_plotting.py b/pygmt/base_plotting.py index 20aef9c86f1..cb1b8f9f6e7 100644 --- a/pygmt/base_plotting.py +++ b/pygmt/base_plotting.py @@ -2057,12 +2057,12 @@ def solar(self, **kwargs): e.g. 12:15 UTC on April 25, 2000 is ``2000-04-25T12:15:00``. To use a timezone other than UTC, append **+z** followed by the *time zone*\ . - pen : str Set pen attributes for lines or the outline of symbols [Defaults: width = default, color = black, style = solid]. {XY} {p} + {U} {V} """ kwargs = self._preprocess(**kwargs) From 7b65d425337dfb03536a1a78971f888a7fca2880 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Sun, 24 Jan 2021 15:21:37 +0000 Subject: [PATCH 009/103] Add test_solar to test_solar.py --- pygmt/tests/test_solar.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 pygmt/tests/test_solar.py diff --git a/pygmt/tests/test_solar.py b/pygmt/tests/test_solar.py new file mode 100644 index 00000000000..b0cfa6f1382 --- /dev/null +++ b/pygmt/tests/test_solar.py @@ -0,0 +1,19 @@ +""" +Tests for solar. +""" +import pytest +from pygmt import Figure +from pygmt.exceptions import GMTInvalidInput +from pygmt.helpers.testing import check_figures_equal + + +@check_figures_equal() +def test_solar(): + """ + Test passing only the solar argument. + """ + fig_ref, fig_test = Figure(), Figure() + # Use single-character arguments for the reference image + fig_ref.solar(R="d", J="W0/15c", Td="+d1990-02-17T04:25:00") + fig_test.solar(region="d", projection="W0/15c", day_night="+d1990-02-17T04:25:00") + return fig_ref, fig_test From 58add00af655aa23e2e52aaded592af6b18ba3a3 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Sun, 24 Jan 2021 15:25:13 +0000 Subject: [PATCH 010/103] Add test_solar_coast to test_solar.py --- pygmt/tests/test_solar.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/pygmt/tests/test_solar.py b/pygmt/tests/test_solar.py index b0cfa6f1382..c3e37d84f4c 100644 --- a/pygmt/tests/test_solar.py +++ b/pygmt/tests/test_solar.py @@ -17,3 +17,17 @@ def test_solar(): fig_ref.solar(R="d", J="W0/15c", Td="+d1990-02-17T04:25:00") fig_test.solar(region="d", projection="W0/15c", day_night="+d1990-02-17T04:25:00") return fig_ref, fig_test + + +@check_figures_equal() +def test_solar_coast(): + """ + Test plotting solar terminator on top of a coast figure. + """ + fig_ref, fig_test = Figure(), Figure() + # Use single-character arguments for the reference image + fig_ref.coast(R="d", J="W0/15c", G="darkgreen", S="lightblue") + fig_ref.solar(Td="+d1990-02-17T04:27:00") + fig_test.coast(region="d", projection="W0/15c", land="darkgreen", water="lightblue") + fig_test.solar(day_night="+d1990-02-17T04:27:00") + return fig_ref, fig_test From a5e808b6285e4cd31e8631bdc994b02695635e4d Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Sun, 24 Jan 2021 16:06:35 +0000 Subject: [PATCH 011/103] Add test_solar_pen to test_solar.py --- pygmt/tests/test_solar.py | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/pygmt/tests/test_solar.py b/pygmt/tests/test_solar.py index c3e37d84f4c..35d3265d842 100644 --- a/pygmt/tests/test_solar.py +++ b/pygmt/tests/test_solar.py @@ -14,8 +14,10 @@ def test_solar(): """ fig_ref, fig_test = Figure(), Figure() # Use single-character arguments for the reference image - fig_ref.solar(R="d", J="W0/15c", Td="+d1990-02-17T04:25:00") - fig_test.solar(region="d", projection="W0/15c", day_night="+d1990-02-17T04:25:00") + fig_ref.solar(R="d", J="W0/15c", B="a", Td="+d1990-02-17T04:25:00") + fig_test.solar( + region="d", projection="W0/15c", frame="a", day_night="+d1990-02-17T04:25:00" + ) return fig_ref, fig_test @@ -31,3 +33,32 @@ def test_solar_coast(): fig_test.coast(region="d", projection="W0/15c", land="darkgreen", water="lightblue") fig_test.solar(day_night="+d1990-02-17T04:27:00") return fig_ref, fig_test + + +@check_figures_equal() +def test_solar_fill(): + """ + Test plotting solar terminator and night-area fill on top of a coast + figure. + """ + fig_ref, fig_test = Figure(), Figure() + # Use single-character arguments for the reference image + fig_ref.coast(R="d", J="W0/15c", G="darkgreen", S="lightblue") + fig_ref.solar(Td="+d1990-02-17T04:27:00", G="navyblue") + fig_test.coast(region="d", projection="W0/15c", land="darkgreen", water="lightblue") + fig_test.solar(day_night="+d1990-02-17T04:27:00", fill="navyblue") + return fig_ref, fig_test + + +@check_figures_equal() +def test_solar_pen(): + """ + Test plotting solar terminator and setting a pen on top of a coast figure. + """ + fig_ref, fig_test = Figure(), Figure() + # Use single-character arguments for the reference image + fig_ref.coast(R="d", J="W0/15c", G="darkgreen", S="lightblue") + fig_ref.solar(Td="+d1990-02-17T04:27:00", W="1p,red,-.-") + fig_test.coast(region="d", projection="W0/15c", land="darkgreen", water="lightblue") + fig_test.solar(day_night="+d1990-02-17T04:27:00", pen="1p,red,-.-") + return fig_ref, fig_test From 9cd30dba3e7630f18f99ca5e65d66c6b28abf782 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Sun, 24 Jan 2021 16:10:42 +0000 Subject: [PATCH 012/103] Add test_solar_civil_twighlight and test_solar_nautical_twighlight to test_solar.py --- pygmt/tests/test_solar.py | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/pygmt/tests/test_solar.py b/pygmt/tests/test_solar.py index 35d3265d842..30d61bd76f5 100644 --- a/pygmt/tests/test_solar.py +++ b/pygmt/tests/test_solar.py @@ -8,9 +8,9 @@ @check_figures_equal() -def test_solar(): +def test_solar_day_night(): """ - Test passing only the solar argument. + Test passing the solar argument with the day_night argument. """ fig_ref, fig_test = Figure(), Figure() # Use single-character arguments for the reference image @@ -21,6 +21,40 @@ def test_solar(): return fig_ref, fig_test +@check_figures_equal() +def test_solar_civil_twighlight(): + """ + Test passing the solar argument with the civil_twighlight argument. + """ + fig_ref, fig_test = Figure(), Figure() + # Use single-character arguments for the reference image + fig_ref.solar(R="d", J="W0/15c", B="a", Tc="+d1990-02-17T04:25:00") + fig_test.solar( + region="d", + projection="W0/15c", + frame="a", + civil_twighlight="+d1990-02-17T04:25:00", + ) + return fig_ref, fig_test + + +@check_figures_equal() +def test_solar_nautical_twighlight(): + """ + Test passing the solar argument with the nautical_twighlight argument. + """ + fig_ref, fig_test = Figure(), Figure() + # Use single-character arguments for the reference image + fig_ref.solar(R="d", J="W0/15c", B="a", Tn="+d1990-02-17T04:25:00") + fig_test.solar( + region="d", + projection="W0/15c", + frame="a", + nautical_twighlight="+d1990-02-17T04:25:00", + ) + return fig_ref, fig_test + + @check_figures_equal() def test_solar_coast(): """ From 9c1221e4770ce86d94620ce4d2c34ca142935e38 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Sun, 24 Jan 2021 16:12:02 +0000 Subject: [PATCH 013/103] Add test_solar_astronomical_twighlight to test_solar.py --- pygmt/tests/test_solar.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/pygmt/tests/test_solar.py b/pygmt/tests/test_solar.py index 30d61bd76f5..9f3a81727eb 100644 --- a/pygmt/tests/test_solar.py +++ b/pygmt/tests/test_solar.py @@ -38,6 +38,23 @@ def test_solar_civil_twighlight(): return fig_ref, fig_test +@check_figures_equal() +def test_solar_astronomical_twighlight(): + """ + Test passing the solar argument with the astronomical_twighlight argument. + """ + fig_ref, fig_test = Figure(), Figure() + # Use single-character arguments for the reference image + fig_ref.solar(R="d", J="W0/15c", B="a", Ta="+d1990-02-17T04:25:00") + fig_test.solar( + region="d", + projection="W0/15c", + frame="a", + astronomical_twighlight="+d1990-02-17T04:25:00", + ) + return fig_ref, fig_test + + @check_figures_equal() def test_solar_nautical_twighlight(): """ From de414f7143a99dfc117036d5c557afc84ffa2525 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Sun, 24 Jan 2021 16:13:45 +0000 Subject: [PATCH 014/103] Add test_solar_fill_transparency to test_solar.py --- pygmt/tests/test_solar.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/pygmt/tests/test_solar.py b/pygmt/tests/test_solar.py index 9f3a81727eb..295b8520aeb 100644 --- a/pygmt/tests/test_solar.py +++ b/pygmt/tests/test_solar.py @@ -101,6 +101,21 @@ def test_solar_fill(): return fig_ref, fig_test +@check_figures_equal() +def test_solar_fill_transparency(): + """ + Test plotting solar terminator and night-area fill with a transparency + modifier on top of a coast figure. + """ + fig_ref, fig_test = Figure(), Figure() + # Use single-character arguments for the reference image + fig_ref.coast(R="d", J="W0/15c", G="darkgreen", S="lightblue") + fig_ref.solar(Td="+d1990-02-17T04:27:00", G="navyblue@75") + fig_test.coast(region="d", projection="W0/15c", land="darkgreen", water="lightblue") + fig_test.solar(day_night="+d1990-02-17T04:27:00", fill="navyblue@75") + return fig_ref, fig_test + + @check_figures_equal() def test_solar_pen(): """ From 8887811b9bb330de1f0345ec0f2b058111e3a1c5 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Sun, 24 Jan 2021 16:28:40 +0000 Subject: [PATCH 015/103] Add 5 tests to test_solar.py --- pygmt/tests/test_solar.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/pygmt/tests/test_solar.py b/pygmt/tests/test_solar.py index 295b8520aeb..a8de7ebd0cc 100644 --- a/pygmt/tests/test_solar.py +++ b/pygmt/tests/test_solar.py @@ -128,3 +128,30 @@ def test_solar_pen(): fig_test.coast(region="d", projection="W0/15c", land="darkgreen", water="lightblue") fig_test.solar(day_night="+d1990-02-17T04:27:00", pen="1p,red,-.-") return fig_ref, fig_test + + +@check_figures_equal() +def test_solar_xy_shift(): + """ + Test plotting solar terminator with an x-y shift on top of a coast figure. + """ + fig_ref, fig_test = Figure(), Figure() + # Use single-character arguments for the reference image + fig_ref.coast(R="d", J="W0/15c", G="darkgreen", S="lightblue") + fig_ref.solar(Td="+d1990-02-17T04:27:00", X=3, Y=5) + fig_test.coast(region="d", projection="W0/15c", land="darkgreen", water="lightblue") + fig_test.solar(day_night="+d1990-02-17T04:27:00", xshift=3, yshift=5) + return fig_ref, fig_test + +@check_figures_equal() +def test_solar_perspective(): + """ + Test plotting solar terminator with a perspective shift on top of a coast figure. + """ + fig_ref, fig_test = Figure(), Figure() + # Use single-character arguments for the reference image + fig_ref.coast(R="d", J="W0/15c", G="darkgreen", S="lightblue") + fig_ref.solar(Td="+d1990-02-17T04:27:00", p="135/45") + fig_test.coast(region="d", projection="W0/15c", land="darkgreen", water="lightblue") + fig_test.solar(day_night="+d1990-02-17T04:27:00", perspective=[135, 45]) + return fig_ref, fig_test From cc024802ea4c5b1f4611724bb03f593710377ccf Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Sun, 24 Jan 2021 16:31:29 +0000 Subject: [PATCH 016/103] Update solar doc string in base_plotting.py --- pygmt/base_plotting.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pygmt/base_plotting.py b/pygmt/base_plotting.py index cb1b8f9f6e7..94d65693659 100644 --- a/pygmt/base_plotting.py +++ b/pygmt/base_plotting.py @@ -2004,7 +2004,9 @@ def update_pointers(data_pointers): @kwargs_to_strings(R="sequence", p="sequence") def solar(self, **kwargs): r""" - Plots the day-night terminator. + A plotting function the day-night terminator. Additionally, it can + plot the terminators for civil twighlight, nautical twighlight, and + astronomical twighlight. {aliases} From 62c43d764fc4bcda2ee8f55bfe9a892b829844bd Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Sun, 24 Jan 2021 16:39:30 +0000 Subject: [PATCH 017/103] Add solar to api/index.rst --- doc/api/index.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/api/index.rst b/doc/api/index.rst index 0598fd103f8..ce5c2f10bc3 100644 --- a/doc/api/index.rst +++ b/doc/api/index.rst @@ -37,6 +37,7 @@ Plotting data and laying out the map: Figure.shift_origin Figure.text Figure.meca + Figure.solar Color palette table generation: From 01d0a9bedf338eaae99a0113198a2b143fc7e70e Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Sun, 24 Jan 2021 19:14:33 +0000 Subject: [PATCH 018/103] Removing time zone mention until fixed in upstream GMT --- pygmt/base_plotting.py | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/pygmt/base_plotting.py b/pygmt/base_plotting.py index 94d65693659..e229a2fe26e 100644 --- a/pygmt/base_plotting.py +++ b/pygmt/base_plotting.py @@ -2021,44 +2021,36 @@ def solar(self, **kwargs): transparency parameter can be appended after the color using **@** after the color. day_night : bool or str - [**+d**\ *date*\ ][**+z**\ *time zone*\ ] + [**+d**\ *date*\ ] Plots the day/night terminator. If the argument is ``True``, the current day-night terminator is plotted. Optionally, **+d** can be added, along with the date and time, to see the day/night terminator at a specific time. The date is added in ISO format, - e.g. 12:15 UTC on April 25, 2000 is ``2000-04-25T12:15:00``. To - use a timezone other than UTC, append **+z** followed by - the *time zone*\ . + e.g. 12:15 UTC on April 25, 2000 is ``2000-04-25T12:15:00``. civil_twighlight" : bool or str - [**+d**\ *date*\ ][**+z**\ *time zone*\ ] + [**+d**\ *date*\ ] Plots the civil twighlight terminator. If the argument is ``True``, the current civil twighlight terminator is plotted. Optionally, **+d** can be added, along with the date and time, to see the day/night terminator at a specific time. The date is added in ISO format, - e.g. 12:15 UTC on April 25, 2000 is ``2000-04-25T12:15:00``. To - use a timezone other than UTC, append **+z** followed by - the *time zone*\ . + e.g. 12:15 UTC on April 25, 2000 is ``2000-04-25T12:15:00``. nautical_twighlight : bool or str - [**+d**\ *date*\ ][**+z**\ *time zone*\ ] + [**+d**\ *date*\ ] Plots the nautical twighlight terminator. If the argument is ``True``, the current nautical twighlight terminator is plotted. Optionally, **+d** can be added, along with the date and time, to see the day/night terminator at a specific time. The date is added in ISO format, - e.g. 12:15 UTC on April 25, 2000 is ``2000-04-25T12:15:00``. To - use a timezone other than UTC, append **+z** followed by - the *time zone*\ . + e.g. 12:15 UTC on April 25, 2000 is ``2000-04-25T12:15:00``. astronomical_twighlight : bool or str - [**+d**\ *date*\ ][**+z**\ *time zone*\ ] + [**+d**\ *date*\ ] Plots the astronomical twighlight terminator. If the argument is ``True``, the current astronomical twighlight terminator is plotted. Optionally, **+d** can be added, along with the date and time, to see the day/night terminator at a specific time. The date is added in ISO format, - e.g. 12:15 UTC on April 25, 2000 is ``2000-04-25T12:15:00``. To - use a timezone other than UTC, append **+z** followed by - the *time zone*\ . + e.g. 12:15 UTC on April 25, 2000 is ``2000-04-25T12:15:00``. pen : str Set pen attributes for lines or the outline of symbols [Defaults: width = default, color = black, style = solid]. From 74b7bcb311efd8dcc0220664a75a275220cdba6f Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Tue, 26 Jan 2021 07:10:28 +0000 Subject: [PATCH 019/103] Remove solar_coast --- pygmt/tests/test_solar.py | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/pygmt/tests/test_solar.py b/pygmt/tests/test_solar.py index a8de7ebd0cc..2641f8d2161 100644 --- a/pygmt/tests/test_solar.py +++ b/pygmt/tests/test_solar.py @@ -72,20 +72,6 @@ def test_solar_nautical_twighlight(): return fig_ref, fig_test -@check_figures_equal() -def test_solar_coast(): - """ - Test plotting solar terminator on top of a coast figure. - """ - fig_ref, fig_test = Figure(), Figure() - # Use single-character arguments for the reference image - fig_ref.coast(R="d", J="W0/15c", G="darkgreen", S="lightblue") - fig_ref.solar(Td="+d1990-02-17T04:27:00") - fig_test.coast(region="d", projection="W0/15c", land="darkgreen", water="lightblue") - fig_test.solar(day_night="+d1990-02-17T04:27:00") - return fig_ref, fig_test - - @check_figures_equal() def test_solar_fill(): """ From c7935a1666ccb7760aa7ca40d512560eb243c427 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Tue, 26 Jan 2021 07:11:12 +0000 Subject: [PATCH 020/103] Remove solar_fill and solar_fill_transparency --- pygmt/tests/test_solar.py | 33 ++------------------------------- 1 file changed, 2 insertions(+), 31 deletions(-) diff --git a/pygmt/tests/test_solar.py b/pygmt/tests/test_solar.py index 2641f8d2161..7cb25b0a102 100644 --- a/pygmt/tests/test_solar.py +++ b/pygmt/tests/test_solar.py @@ -14,9 +14,9 @@ def test_solar_day_night(): """ fig_ref, fig_test = Figure(), Figure() # Use single-character arguments for the reference image - fig_ref.solar(R="d", J="W0/15c", B="a", Td="+d1990-02-17T04:25:00") + fig_ref.solar(R="d", J="W0/15c", B="a", Td="+d1990-02-17T04:25:00", G="navyblue@75") fig_test.solar( - region="d", projection="W0/15c", frame="a", day_night="+d1990-02-17T04:25:00" + region="d", projection="W0/15c", frame="a", day_night="+d1990-02-17T04:25:00", fill="navyblue@75" ) return fig_ref, fig_test @@ -72,35 +72,6 @@ def test_solar_nautical_twighlight(): return fig_ref, fig_test -@check_figures_equal() -def test_solar_fill(): - """ - Test plotting solar terminator and night-area fill on top of a coast - figure. - """ - fig_ref, fig_test = Figure(), Figure() - # Use single-character arguments for the reference image - fig_ref.coast(R="d", J="W0/15c", G="darkgreen", S="lightblue") - fig_ref.solar(Td="+d1990-02-17T04:27:00", G="navyblue") - fig_test.coast(region="d", projection="W0/15c", land="darkgreen", water="lightblue") - fig_test.solar(day_night="+d1990-02-17T04:27:00", fill="navyblue") - return fig_ref, fig_test - - -@check_figures_equal() -def test_solar_fill_transparency(): - """ - Test plotting solar terminator and night-area fill with a transparency - modifier on top of a coast figure. - """ - fig_ref, fig_test = Figure(), Figure() - # Use single-character arguments for the reference image - fig_ref.coast(R="d", J="W0/15c", G="darkgreen", S="lightblue") - fig_ref.solar(Td="+d1990-02-17T04:27:00", G="navyblue@75") - fig_test.coast(region="d", projection="W0/15c", land="darkgreen", water="lightblue") - fig_test.solar(day_night="+d1990-02-17T04:27:00", fill="navyblue@75") - return fig_ref, fig_test - @check_figures_equal() def test_solar_pen(): From 1ea53b8486165a754bf1c295e781a5161ab38cee Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Tue, 26 Jan 2021 07:11:40 +0000 Subject: [PATCH 021/103] Remove solar_pen --- pygmt/tests/test_solar.py | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/pygmt/tests/test_solar.py b/pygmt/tests/test_solar.py index 7cb25b0a102..cc9ef5115c7 100644 --- a/pygmt/tests/test_solar.py +++ b/pygmt/tests/test_solar.py @@ -14,9 +14,9 @@ def test_solar_day_night(): """ fig_ref, fig_test = Figure(), Figure() # Use single-character arguments for the reference image - fig_ref.solar(R="d", J="W0/15c", B="a", Td="+d1990-02-17T04:25:00", G="navyblue@75") + fig_ref.solar(R="d", J="W0/15c", B="a", Td="+d1990-02-17T04:25:00", G="navyblue@75", W="1p,red,-.-") fig_test.solar( - region="d", projection="W0/15c", frame="a", day_night="+d1990-02-17T04:25:00", fill="navyblue@75" + region="d", projection="W0/15c", frame="a", day_night="+d1990-02-17T04:25:00", fill="navyblue@75", pen="1p,red,-.-" ) return fig_ref, fig_test @@ -72,21 +72,6 @@ def test_solar_nautical_twighlight(): return fig_ref, fig_test - -@check_figures_equal() -def test_solar_pen(): - """ - Test plotting solar terminator and setting a pen on top of a coast figure. - """ - fig_ref, fig_test = Figure(), Figure() - # Use single-character arguments for the reference image - fig_ref.coast(R="d", J="W0/15c", G="darkgreen", S="lightblue") - fig_ref.solar(Td="+d1990-02-17T04:27:00", W="1p,red,-.-") - fig_test.coast(region="d", projection="W0/15c", land="darkgreen", water="lightblue") - fig_test.solar(day_night="+d1990-02-17T04:27:00", pen="1p,red,-.-") - return fig_ref, fig_test - - @check_figures_equal() def test_solar_xy_shift(): """ From 25544a95a8e96d060a019e4d2b7ac74b2a922c4b Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Tue, 26 Jan 2021 07:12:27 +0000 Subject: [PATCH 022/103] Remove solar_xy_shift --- pygmt/tests/test_solar.py | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/pygmt/tests/test_solar.py b/pygmt/tests/test_solar.py index cc9ef5115c7..46b0b79302e 100644 --- a/pygmt/tests/test_solar.py +++ b/pygmt/tests/test_solar.py @@ -14,9 +14,9 @@ def test_solar_day_night(): """ fig_ref, fig_test = Figure(), Figure() # Use single-character arguments for the reference image - fig_ref.solar(R="d", J="W0/15c", B="a", Td="+d1990-02-17T04:25:00", G="navyblue@75", W="1p,red,-.-") + fig_ref.solar(R="d", J="W0/15c", B="a", Td="+d1990-02-17T04:25:00", G="navyblue@75", W="1p,red,-.-", X=3, Y=5) fig_test.solar( - region="d", projection="W0/15c", frame="a", day_night="+d1990-02-17T04:25:00", fill="navyblue@75", pen="1p,red,-.-" + region="d", projection="W0/15c", frame="a", day_night="+d1990-02-17T04:25:00", fill="navyblue@75", pen="1p,red,-.-", xshift=3, yshift=5 ) return fig_ref, fig_test @@ -72,19 +72,6 @@ def test_solar_nautical_twighlight(): return fig_ref, fig_test -@check_figures_equal() -def test_solar_xy_shift(): - """ - Test plotting solar terminator with an x-y shift on top of a coast figure. - """ - fig_ref, fig_test = Figure(), Figure() - # Use single-character arguments for the reference image - fig_ref.coast(R="d", J="W0/15c", G="darkgreen", S="lightblue") - fig_ref.solar(Td="+d1990-02-17T04:27:00", X=3, Y=5) - fig_test.coast(region="d", projection="W0/15c", land="darkgreen", water="lightblue") - fig_test.solar(day_night="+d1990-02-17T04:27:00", xshift=3, yshift=5) - return fig_ref, fig_test - @check_figures_equal() def test_solar_perspective(): """ From 6391dea8cc34a08120fcbe6e31cc791c76cac5d9 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Tue, 26 Jan 2021 07:15:08 +0000 Subject: [PATCH 023/103] Remove solar_perspective --- pygmt/tests/test_solar.py | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/pygmt/tests/test_solar.py b/pygmt/tests/test_solar.py index 46b0b79302e..047fa0c8503 100644 --- a/pygmt/tests/test_solar.py +++ b/pygmt/tests/test_solar.py @@ -10,13 +10,32 @@ @check_figures_equal() def test_solar_day_night(): """ - Test passing the solar argument with the day_night argument. + Test passing the solar argument with the day_night argument and confirm the + working aliases for the solar function. """ fig_ref, fig_test = Figure(), Figure() # Use single-character arguments for the reference image - fig_ref.solar(R="d", J="W0/15c", B="a", Td="+d1990-02-17T04:25:00", G="navyblue@75", W="1p,red,-.-", X=3, Y=5) + fig_ref.solar( + R="d", + J="W0/15c", + B="a", + Td="+d1990-02-17T04:25:00", + G="navyblue@75", + W="1p,red,-.-", + X=3, + Y=5, + p="135/45", + ) fig_test.solar( - region="d", projection="W0/15c", frame="a", day_night="+d1990-02-17T04:25:00", fill="navyblue@75", pen="1p,red,-.-", xshift=3, yshift=5 + region="d", + projection="W0/15c", + frame="a", + day_night="+d1990-02-17T04:25:00", + fill="navyblue@75", + pen="1p,red,-.-", + xshift=3, + yshift=5, + perspective=[135, 45], ) return fig_ref, fig_test @@ -70,17 +89,3 @@ def test_solar_nautical_twighlight(): nautical_twighlight="+d1990-02-17T04:25:00", ) return fig_ref, fig_test - - -@check_figures_equal() -def test_solar_perspective(): - """ - Test plotting solar terminator with a perspective shift on top of a coast figure. - """ - fig_ref, fig_test = Figure(), Figure() - # Use single-character arguments for the reference image - fig_ref.coast(R="d", J="W0/15c", G="darkgreen", S="lightblue") - fig_ref.solar(Td="+d1990-02-17T04:27:00", p="135/45") - fig_test.coast(region="d", projection="W0/15c", land="darkgreen", water="lightblue") - fig_test.solar(day_night="+d1990-02-17T04:27:00", perspective=[135, 45]) - return fig_ref, fig_test From 001c76a32ed0c46f823795a92be8276ff55a94dc Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Tue, 26 Jan 2021 07:17:57 +0000 Subject: [PATCH 024/103] Remove unused imports in test_solar.py --- pygmt/tests/test_solar.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/pygmt/tests/test_solar.py b/pygmt/tests/test_solar.py index 047fa0c8503..b3c57ea3f06 100644 --- a/pygmt/tests/test_solar.py +++ b/pygmt/tests/test_solar.py @@ -1,9 +1,7 @@ """ Tests for solar. """ -import pytest from pygmt import Figure -from pygmt.exceptions import GMTInvalidInput from pygmt.helpers.testing import check_figures_equal From 18610a7181a50eeb56394dd69a7ab4aad2d61517 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Tue, 26 Jan 2021 07:50:21 +0000 Subject: [PATCH 025/103] Correcting "twighlight" to "twilight" --- pygmt/base_plotting.py | 28 ++++++++++++++-------------- pygmt/tests/test_solar.py | 18 +++++++++--------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/pygmt/base_plotting.py b/pygmt/base_plotting.py index e229a2fe26e..12a24803c3c 100644 --- a/pygmt/base_plotting.py +++ b/pygmt/base_plotting.py @@ -1991,9 +1991,9 @@ def update_pointers(data_pointers): G="fill", B="frame", Td="day_night", - Tc="civil_twighlight", - Tn="nautical_twighlight", - Ta="astronomical_twighlight", + Tc="civil_twilight", + Tn="nautical_twilight", + Ta="astronomical_twilight", W="pen", U="timestamp", V="verbose", @@ -2005,8 +2005,8 @@ def update_pointers(data_pointers): def solar(self, **kwargs): r""" A plotting function the day-night terminator. Additionally, it can - plot the terminators for civil twighlight, nautical twighlight, and - astronomical twighlight. + plot the terminators for civil twilight, nautical twilight, and + astronomical twilight. {aliases} @@ -2027,26 +2027,26 @@ def solar(self, **kwargs): added, along with the date and time, to see the day/night terminator at a specific time. The date is added in ISO format, e.g. 12:15 UTC on April 25, 2000 is ``2000-04-25T12:15:00``. - civil_twighlight" : bool or str + civil_twilight" : bool or str [**+d**\ *date*\ ] - Plots the civil twighlight terminator. If the argument is - ``True``, the current civil twighlight terminator is plotted. + Plots the civil twilight terminator. If the argument is + ``True``, the current civil twilight terminator is plotted. Optionally, **+d** can be added, along with the date and time, to see the day/night terminator at a specific time. The date is added in ISO format, e.g. 12:15 UTC on April 25, 2000 is ``2000-04-25T12:15:00``. - nautical_twighlight : bool or str + nautical_twilight : bool or str [**+d**\ *date*\ ] - Plots the nautical twighlight terminator. If the argument is - ``True``, the current nautical twighlight terminator is plotted. + Plots the nautical twilight terminator. If the argument is + ``True``, the current nautical twilight terminator is plotted. Optionally, **+d** can be added, along with the date and time, to see the day/night terminator at a specific time. The date is added in ISO format, e.g. 12:15 UTC on April 25, 2000 is ``2000-04-25T12:15:00``. - astronomical_twighlight : bool or str + astronomical_twilight : bool or str [**+d**\ *date*\ ] - Plots the astronomical twighlight terminator. If the argument is - ``True``, the current astronomical twighlight terminator is + Plots the astronomical twilight terminator. If the argument is + ``True``, the current astronomical twilight terminator is plotted. Optionally, **+d** can be added, along with the date and time, to see the day/night terminator at a specific time. The date is added in ISO format, diff --git a/pygmt/tests/test_solar.py b/pygmt/tests/test_solar.py index b3c57ea3f06..e9959f2ce77 100644 --- a/pygmt/tests/test_solar.py +++ b/pygmt/tests/test_solar.py @@ -39,9 +39,9 @@ def test_solar_day_night(): @check_figures_equal() -def test_solar_civil_twighlight(): +def test_solar_civil_twilight(): """ - Test passing the solar argument with the civil_twighlight argument. + Test passing the solar argument with the civil_twilight argument. """ fig_ref, fig_test = Figure(), Figure() # Use single-character arguments for the reference image @@ -50,15 +50,15 @@ def test_solar_civil_twighlight(): region="d", projection="W0/15c", frame="a", - civil_twighlight="+d1990-02-17T04:25:00", + civil_twilight="+d1990-02-17T04:25:00", ) return fig_ref, fig_test @check_figures_equal() -def test_solar_astronomical_twighlight(): +def test_solar_astronomical_twilight(): """ - Test passing the solar argument with the astronomical_twighlight argument. + Test passing the solar argument with the astronomical_twilight argument. """ fig_ref, fig_test = Figure(), Figure() # Use single-character arguments for the reference image @@ -67,15 +67,15 @@ def test_solar_astronomical_twighlight(): region="d", projection="W0/15c", frame="a", - astronomical_twighlight="+d1990-02-17T04:25:00", + astronomical_twilight="+d1990-02-17T04:25:00", ) return fig_ref, fig_test @check_figures_equal() -def test_solar_nautical_twighlight(): +def test_solar_nautical_twilight(): """ - Test passing the solar argument with the nautical_twighlight argument. + Test passing the solar argument with the nautical_twilight argument. """ fig_ref, fig_test = Figure(), Figure() # Use single-character arguments for the reference image @@ -84,6 +84,6 @@ def test_solar_nautical_twighlight(): region="d", projection="W0/15c", frame="a", - nautical_twighlight="+d1990-02-17T04:25:00", + nautical_twilight="+d1990-02-17T04:25:00", ) return fig_ref, fig_test From c327c08f2c59e8d225feb4a43cf06092cec28507 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Tue, 26 Jan 2021 08:04:13 +0000 Subject: [PATCH 026/103] Add solar.py gallery example --- examples/gallery/plot/solar.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 examples/gallery/plot/solar.py diff --git a/examples/gallery/plot/solar.py b/examples/gallery/plot/solar.py new file mode 100644 index 00000000000..f0e5d0504f3 --- /dev/null +++ b/examples/gallery/plot/solar.py @@ -0,0 +1,17 @@ +""" +Solar +----- + +Use :meth:`pygmt.Figure.solar` to plot the day-night terminator line. +""" +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, 1700 UTC on January 1, 2000 +# Set the pen line to be 1p thick +# Set the fill for the night area to be navy blue at 80% transparency +fig.solar(Td="+d2000-01-01T17:00:00+", fill="navyblue@80", pen="1p") +fig.show() From a722ca5a40a9cbf9b570967bf2b35e925fcac98b Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Wed, 27 Jan 2021 12:28:08 +0000 Subject: [PATCH 027/103] Move solar function from base_plotting.py to solar.py --- pygmt/base_plotting.py | 81 +------------------------------------ pygmt/src/__init__.py | 6 ++- pygmt/src/solar.py | 92 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 99 insertions(+), 80 deletions(-) create mode 100644 pygmt/src/solar.py diff --git a/pygmt/base_plotting.py b/pygmt/base_plotting.py index 5ef11901abc..c22ae46786c 100644 --- a/pygmt/base_plotting.py +++ b/pygmt/base_plotting.py @@ -1642,84 +1642,7 @@ def text( arg_str = " ".join([fname, build_arg_string(kwargs)]) lib.call_module("text", arg_str) - @fmt_docstring - @use_alias( - R="region", - J="projection", - G="fill", - B="frame", - Td="day_night", - Tc="civil_twilight", - Tn="nautical_twilight", - Ta="astronomical_twilight", - W="pen", - U="timestamp", - V="verbose", - X="xshift", - Y="yshift", - p="perspective", - ) - @kwargs_to_strings(R="sequence", p="sequence") - def solar(self, **kwargs): - r""" - A plotting function the day-night terminator. Additionally, it can - plot the terminators for civil twilight, nautical twilight, and - astronomical twilight. - - {aliases} - - Parameters - ---------- - {R} - {J} - {B} - fill : str - *fill color*\ [**@**\ *transparency*] - The fill color for the night-area plotted. The optional - transparency parameter can be appended after the color - using **@** after the color. - day_night : bool or str - [**+d**\ *date*\ ] - Plots the day/night terminator. If the argument is ``True``, the - current day-night terminator is plotted. Optionally, **+d** can be - added, along with the date and time, to see the day/night - terminator at a specific time. The date is added in ISO format, - e.g. 12:15 UTC on April 25, 2000 is ``2000-04-25T12:15:00``. - civil_twilight" : bool or str - [**+d**\ *date*\ ] - Plots the civil twilight terminator. If the argument is - ``True``, the current civil twilight terminator is plotted. - Optionally, **+d** can be added, along with the date and time, to - see the day/night terminator at a specific time. The date is added - in ISO format, - e.g. 12:15 UTC on April 25, 2000 is ``2000-04-25T12:15:00``. - nautical_twilight : bool or str - [**+d**\ *date*\ ] - Plots the nautical twilight terminator. If the argument is - ``True``, the current nautical twilight terminator is plotted. - Optionally, **+d** can be added, along with the date and time, to - see the day/night terminator at a specific time. The date is added - in ISO format, - e.g. 12:15 UTC on April 25, 2000 is ``2000-04-25T12:15:00``. - astronomical_twilight : bool or str - [**+d**\ *date*\ ] - Plots the astronomical twilight terminator. If the argument is - ``True``, the current astronomical twilight terminator is - plotted. Optionally, **+d** can be added, along with the date and - time, to see the day/night terminator at a specific time. The date - is added in ISO format, - e.g. 12:15 UTC on April 25, 2000 is ``2000-04-25T12:15:00``. - pen : str - Set pen attributes for lines or the outline of symbols - [Defaults: width = default, color = black, style = solid]. - {XY} - {p} - {U} - {V} - """ - kwargs = self._preprocess(**kwargs) - with Session() as lib: - lib.call_module("solar", build_arg_string(kwargs)) - + # GMT Primary modules # GMT Supplementary modules from pygmt.src import meca # pylint: disable=import-outside-toplevel + from pygmt.src import solar # pylint: disable=import-outside-toplevel diff --git a/pygmt/src/__init__.py b/pygmt/src/__init__.py index cdbabf1468a..b10c8751d7b 100644 --- a/pygmt/src/__init__.py +++ b/pygmt/src/__init__.py @@ -1,5 +1,9 @@ """ Source code for PyGMT modules. """ -# pylint: disable=import-outside-toplevel +# GMT Supplementary modules from pygmt.src.meca import meca + +# pylint: disable=import-outside-toplevel +# GMT Primary modules +from pygmt.src.solar import solar diff --git a/pygmt/src/solar.py b/pygmt/src/solar.py new file mode 100644 index 00000000000..a970e532949 --- /dev/null +++ b/pygmt/src/solar.py @@ -0,0 +1,92 @@ +""" +solar - Plot day-night terminators. +""" + +from pygmt.clib import Session +from pygmt.helpers import ( + build_arg_string, + dummy_context, + fmt_docstring, + kwargs_to_strings, + use_alias, +) + + +@fmt_docstring +@use_alias( + R="region", + J="projection", + G="fill", + B="frame", + Td="day_night", + Tc="civil_twilight", + Tn="nautical_twilight", + Ta="astronomical_twilight", + W="pen", + U="timestamp", + V="verbose", + X="xshift", + Y="yshift", + p="perspective", +) +@kwargs_to_strings(R="sequence", p="sequence") +def solar(self, **kwargs): + r""" + A plotting function the day-night terminator. Additionally, it can + plot the terminators for civil twilight, nautical twilight, and + astronomical twilight. + + {aliases} + + Parameters + ---------- + {R} + {J} + {B} + fill : str + *fill color*\ [**@**\ *transparency*] + The fill color for the night-area plotted. The optional + transparency parameter can be appended after the color + using **@** after the color. + day_night : bool or str + [**+d**\ *date*\ ] + Plots the day/night terminator. If the argument is ``True``, the + current day-night terminator is plotted. Optionally, **+d** can be + added, along with the date and time, to see the day/night + terminator at a specific time. The date is added in ISO format, + e.g. 12:15 UTC on April 25, 2000 is ``2000-04-25T12:15:00``. + civil_twilight" : bool or str + [**+d**\ *date*\ ] + Plots the civil twilight terminator. If the argument is + ``True``, the current civil twilight terminator is plotted. + Optionally, **+d** can be added, along with the date and time, to + see the day/night terminator at a specific time. The date is added + in ISO format, + e.g. 12:15 UTC on April 25, 2000 is ``2000-04-25T12:15:00``. + nautical_twilight : bool or str + [**+d**\ *date*\ ] + Plots the nautical twilight terminator. If the argument is + ``True``, the current nautical twilight terminator is plotted. + Optionally, **+d** can be added, along with the date and time, to + see the day/night terminator at a specific time. The date is added + in ISO format, + e.g. 12:15 UTC on April 25, 2000 is ``2000-04-25T12:15:00``. + astronomical_twilight : bool or str + [**+d**\ *date*\ ] + Plots the astronomical twilight terminator. If the argument is + ``True``, the current astronomical twilight terminator is + plotted. Optionally, **+d** can be added, along with the date and + time, to see the day/night terminator at a specific time. The date + is added in ISO format, + e.g. 12:15 UTC on April 25, 2000 is ``2000-04-25T12:15:00``. + pen : str + Set pen attributes for lines or the outline of symbols + [Defaults: width = default, color = black, style = solid]. + {XY} + {p} + {U} + {V} + """ + kwargs = self._preprocess(**kwargs) + with Session() as lib: + lib.call_module("solar", build_arg_string(kwargs)) From cea2f8f40ddb9336a93411f23da854887e1b8945 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Wed, 27 Jan 2021 12:29:53 +0000 Subject: [PATCH 028/103] Remove dummy_context unused import --- pygmt/src/solar.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pygmt/src/solar.py b/pygmt/src/solar.py index a970e532949..4ada7b34227 100644 --- a/pygmt/src/solar.py +++ b/pygmt/src/solar.py @@ -5,7 +5,6 @@ from pygmt.clib import Session from pygmt.helpers import ( build_arg_string, - dummy_context, fmt_docstring, kwargs_to_strings, use_alias, From 0085853106bac30c7543728ab1e608529d2f1afb Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Wed, 27 Jan 2021 14:06:30 +0000 Subject: [PATCH 029/103] change order of modules in __init__.py --- pygmt/src/__init__.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pygmt/src/__init__.py b/pygmt/src/__init__.py index b10c8751d7b..1cdbba23ac7 100644 --- a/pygmt/src/__init__.py +++ b/pygmt/src/__init__.py @@ -1,9 +1,11 @@ """ Source code for PyGMT modules. """ -# GMT Supplementary modules -from pygmt.src.meca import meca - # pylint: disable=import-outside-toplevel + # GMT Primary modules from pygmt.src.solar import solar + +# GMT Supplementary modules +from pygmt.src.meca import meca + From 3f960b460436a6fcf02dfaec39ab9739399d7f03 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Sat, 30 Jan 2021 10:55:19 +0000 Subject: [PATCH 030/103] Update pygmt/src/solar.py Co-authored-by: Dongdong Tian --- pygmt/src/solar.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygmt/src/solar.py b/pygmt/src/solar.py index 4ada7b34227..be03d07ebd6 100644 --- a/pygmt/src/solar.py +++ b/pygmt/src/solar.py @@ -54,7 +54,7 @@ def solar(self, **kwargs): added, along with the date and time, to see the day/night terminator at a specific time. The date is added in ISO format, e.g. 12:15 UTC on April 25, 2000 is ``2000-04-25T12:15:00``. - civil_twilight" : bool or str + civil_twilight : bool or str [**+d**\ *date*\ ] Plots the civil twilight terminator. If the argument is ``True``, the current civil twilight terminator is plotted. From bf0e2d55528f51a4b05f713d116df1d0d281112a Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Sat, 30 Jan 2021 10:56:52 +0000 Subject: [PATCH 031/103] Update first line of solar doc string --- pygmt/src/solar.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygmt/src/solar.py b/pygmt/src/solar.py index 4ada7b34227..0c5382083d7 100644 --- a/pygmt/src/solar.py +++ b/pygmt/src/solar.py @@ -31,7 +31,7 @@ @kwargs_to_strings(R="sequence", p="sequence") def solar(self, **kwargs): r""" - A plotting function the day-night terminator. Additionally, it can + A function that plots the day-night terminator. Additionally, it can plot the terminators for civil twilight, nautical twilight, and astronomical twilight. From 0a7a341205836cd018fb8e2592b1711d0e4b1124 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Wed, 3 Feb 2021 18:20:42 +0000 Subject: [PATCH 032/103] Apply suggestions from code review Co-authored-by: Dongdong Tian --- pygmt/base_plotting.py | 7 ++++--- pygmt/src/__init__.py | 5 ++--- pygmt/src/solar.py | 20 +++++++++----------- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/pygmt/base_plotting.py b/pygmt/base_plotting.py index c22ae46786c..71af536fcc3 100644 --- a/pygmt/base_plotting.py +++ b/pygmt/base_plotting.py @@ -1642,7 +1642,8 @@ def text( arg_str = " ".join([fname, build_arg_string(kwargs)]) lib.call_module("text", arg_str) - # GMT Primary modules - # GMT Supplementary modules - from pygmt.src import meca # pylint: disable=import-outside-toplevel + # GMT core modules from pygmt.src import solar # pylint: disable=import-outside-toplevel + + # GMT supplementary modules + from pygmt.src import meca # pylint: disable=import-outside-toplevel diff --git a/pygmt/src/__init__.py b/pygmt/src/__init__.py index 1cdbba23ac7..93e5c43e276 100644 --- a/pygmt/src/__init__.py +++ b/pygmt/src/__init__.py @@ -3,9 +3,8 @@ """ # pylint: disable=import-outside-toplevel -# GMT Primary modules +# GMT core modules from pygmt.src.solar import solar -# GMT Supplementary modules +# GMT supplementary modules from pygmt.src.meca import meca - diff --git a/pygmt/src/solar.py b/pygmt/src/solar.py index 77fe516a553..7764c587696 100644 --- a/pygmt/src/solar.py +++ b/pygmt/src/solar.py @@ -31,7 +31,9 @@ @kwargs_to_strings(R="sequence", p="sequence") def solar(self, **kwargs): r""" - A function that plots the day-night terminator. Additionally, it can + Plot day-light terminators. + + This function plots the day-night terminator. Additionally, it can plot the terminators for civil twilight, nautical twilight, and astronomical twilight. @@ -43,19 +45,16 @@ def solar(self, **kwargs): {J} {B} fill : str - *fill color*\ [**@**\ *transparency*] - The fill color for the night-area plotted. The optional - transparency parameter can be appended after the color - using **@** after the color. + Color or pattern for filling of terminators. day_night : bool or str - [**+d**\ *date*\ ] + [**+d**\ *date*]. Plots the day/night terminator. If the argument is ``True``, the current day-night terminator is plotted. Optionally, **+d** can be added, along with the date and time, to see the day/night terminator at a specific time. The date is added in ISO format, e.g. 12:15 UTC on April 25, 2000 is ``2000-04-25T12:15:00``. civil_twilight : bool or str - [**+d**\ *date*\ ] + [**+d**\ *date*]. Plots the civil twilight terminator. If the argument is ``True``, the current civil twilight terminator is plotted. Optionally, **+d** can be added, along with the date and time, to @@ -63,7 +62,7 @@ def solar(self, **kwargs): in ISO format, e.g. 12:15 UTC on April 25, 2000 is ``2000-04-25T12:15:00``. nautical_twilight : bool or str - [**+d**\ *date*\ ] + [**+d**\ *date*]. Plots the nautical twilight terminator. If the argument is ``True``, the current nautical twilight terminator is plotted. Optionally, **+d** can be added, along with the date and time, to @@ -71,7 +70,7 @@ def solar(self, **kwargs): in ISO format, e.g. 12:15 UTC on April 25, 2000 is ``2000-04-25T12:15:00``. astronomical_twilight : bool or str - [**+d**\ *date*\ ] + [**+d**\ *date*]. Plots the astronomical twilight terminator. If the argument is ``True``, the current astronomical twilight terminator is plotted. Optionally, **+d** can be added, along with the date and @@ -79,8 +78,7 @@ def solar(self, **kwargs): is added in ISO format, e.g. 12:15 UTC on April 25, 2000 is ``2000-04-25T12:15:00``. pen : str - Set pen attributes for lines or the outline of symbols - [Defaults: width = default, color = black, style = solid]. + Set pen attributes for lines. The default pen is ``default,black,solid``. {XY} {p} {U} From 0ed447838157196c46d2f600f91d582bc17510bc Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Wed, 3 Feb 2021 18:26:59 +0000 Subject: [PATCH 033/103] Update solar gallery example --- examples/gallery/plot/solar.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/examples/gallery/plot/solar.py b/examples/gallery/plot/solar.py index f0e5d0504f3..2c9fda62751 100644 --- a/examples/gallery/plot/solar.py +++ b/examples/gallery/plot/solar.py @@ -13,5 +13,8 @@ # Set a time for the day-night terminator, 1700 UTC on January 1, 2000 # Set the pen line to be 1p thick # Set the fill for the night area to be navy blue at 80% transparency -fig.solar(Td="+d2000-01-01T17:00:00+", fill="navyblue@80", pen="1p") +fig.solar(Td="+d2000-01-01T17:00:00+", fill="navyblue@95", pen="1p") +fig.solar(Tc="+d2000-01-01T17:00:00+", fill="navyblue@85", pen="1p") +fig.solar(Tn="+d2000-01-01T17:00:00+", fill="navyblue@80", pen="1p") +fig.solar(Ta="+d2000-01-01T17:00:00+", fill="navyblue@80", pen="1p") fig.show() From b95b4042970d29fdbeeba94653afadf6d1b7b1c4 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Thu, 4 Feb 2021 05:53:47 +0000 Subject: [PATCH 034/103] Update examples/gallery/plot/solar.py Co-authored-by: Dongdong Tian --- examples/gallery/plot/solar.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/gallery/plot/solar.py b/examples/gallery/plot/solar.py index 2c9fda62751..24e5d3e121d 100644 --- a/examples/gallery/plot/solar.py +++ b/examples/gallery/plot/solar.py @@ -13,8 +13,8 @@ # Set a time for the day-night terminator, 1700 UTC on January 1, 2000 # Set the pen line to be 1p thick # Set the fill for the night area to be navy blue at 80% transparency -fig.solar(Td="+d2000-01-01T17:00:00+", fill="navyblue@95", pen="1p") -fig.solar(Tc="+d2000-01-01T17:00:00+", fill="navyblue@85", pen="1p") -fig.solar(Tn="+d2000-01-01T17:00:00+", fill="navyblue@80", pen="1p") -fig.solar(Ta="+d2000-01-01T17:00:00+", fill="navyblue@80", pen="1p") +fig.solar(day_night="+d2000-01-01T17:00:00", fill="navyblue@95", pen="1p") +fig.solar(civil_twilight="+d2000-01-01T17:00:00", fill="navyblue@85", pen="1p") +fig.solar(nautical_twilight="+d2000-01-01T17:00:00", fill="navyblue@80", pen="1p") +fig.solar(astronomical_twilight="+d2000-01-01T17:00:00", fill="navyblue@80", pen="1p") fig.show() From e172457ff289b7252e2e38db1fac40036ece484b Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Thu, 4 Feb 2021 06:18:10 +0000 Subject: [PATCH 035/103] Apply suggestions from code review Co-authored-by: Dongdong Tian --- examples/gallery/plot/solar.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/examples/gallery/plot/solar.py b/examples/gallery/plot/solar.py index 24e5d3e121d..9ed5260491c 100644 --- a/examples/gallery/plot/solar.py +++ b/examples/gallery/plot/solar.py @@ -2,7 +2,8 @@ Solar ----- -Use :meth:`pygmt.Figure.solar` to plot the day-night terminator line. +Use :meth:`pygmt.Figure.solar` to plot the day-night terminator line, +and civil, nautical, astronomical twilights. """ import pygmt @@ -10,7 +11,7 @@ # 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, 1700 UTC on January 1, 2000 +# Set a time for the day-night terminator and twilights, 1700 UTC on January 1, 2000 # Set the pen line to be 1p thick # Set the fill for the night area to be navy blue at 80% transparency fig.solar(day_night="+d2000-01-01T17:00:00", fill="navyblue@95", pen="1p") From 7ed7684436fe43a4caf2cdb247180ae5af6156ea Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Fri, 5 Feb 2021 06:21:42 +0000 Subject: [PATCH 036/103] Add comments to self for datetime parsing --- pygmt/src/solar.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pygmt/src/solar.py b/pygmt/src/solar.py index 7764c587696..6138bf1a04b 100644 --- a/pygmt/src/solar.py +++ b/pygmt/src/solar.py @@ -84,6 +84,12 @@ def solar(self, **kwargs): {U} {V} """ + # if statement to determine if type is datetime object or string + # if string: + # try to parse date to datetime object + # if not recognizable + # raise error + # function to pass datetime object to return datetime string to pass to GMT API kwargs = self._preprocess(**kwargs) with Session() as lib: lib.call_module("solar", build_arg_string(kwargs)) From fe3b9c0a6ea49a961ed79267636ea393066ef150 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Sun, 7 Feb 2021 10:34:04 +0000 Subject: [PATCH 037/103] Run make format --- pygmt/figure.py | 2 +- pygmt/src/__init__.py | 2 +- pygmt/src/solar.py | 15 +++++---------- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/pygmt/figure.py b/pygmt/figure.py index 823f8a4c8c4..bb2e217a24a 100644 --- a/pygmt/figure.py +++ b/pygmt/figure.py @@ -387,6 +387,6 @@ def _repr_html_(self): meca, plot, plot3d, - text, solar, + text, ) diff --git a/pygmt/src/__init__.py b/pygmt/src/__init__.py index 7db60254976..9d85e578ec1 100644 --- a/pygmt/src/__init__.py +++ b/pygmt/src/__init__.py @@ -4,7 +4,6 @@ # pylint: disable=import-outside-toplevel -from pygmt.src.solar import solar from pygmt.src.basemap import basemap from pygmt.src.blockmedian import blockmedian from pygmt.src.coast import coast @@ -25,6 +24,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.surface import surface from pygmt.src.text import text_ as text # "text" is an argument within "text_" from pygmt.src.which import which diff --git a/pygmt/src/solar.py b/pygmt/src/solar.py index 6138bf1a04b..8e4ec9a8188 100644 --- a/pygmt/src/solar.py +++ b/pygmt/src/solar.py @@ -3,12 +3,7 @@ """ from pygmt.clib import Session -from pygmt.helpers import ( - build_arg_string, - fmt_docstring, - kwargs_to_strings, - use_alias, -) +from pygmt.helpers import build_arg_string, fmt_docstring, kwargs_to_strings, use_alias @fmt_docstring @@ -32,7 +27,7 @@ def solar(self, **kwargs): r""" Plot day-light terminators. - + This function plots the day-night terminator. Additionally, it can plot the terminators for civil twilight, nautical twilight, and astronomical twilight. @@ -78,7 +73,7 @@ def solar(self, **kwargs): is added in ISO format, e.g. 12:15 UTC on April 25, 2000 is ``2000-04-25T12:15:00``. pen : str - Set pen attributes for lines. The default pen is ``default,black,solid``. + Set pen attributes for lines. The default pen is ``default,black,solid``. {XY} {p} {U} @@ -86,9 +81,9 @@ def solar(self, **kwargs): """ # if statement to determine if type is datetime object or string # if string: - # try to parse date to datetime object + # try to parse date to datetime object # if not recognizable - # raise error + # raise error # function to pass datetime object to return datetime string to pass to GMT API kwargs = self._preprocess(**kwargs) with Session() as lib: From ace68803c5d5b5815d3b434890a04679b7e614d8 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Fri, 19 Feb 2021 18:26:08 +0000 Subject: [PATCH 038/103] Fix import statements --- pygmt/src/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pygmt/src/__init__.py b/pygmt/src/__init__.py index 3ef9af36070..7b3d8c3f396 100644 --- a/pygmt/src/__init__.py +++ b/pygmt/src/__init__.py @@ -24,6 +24,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_" From 0b3b4d895f2dc8f180fdb9ec9f951be450d0f9dc Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Sat, 20 Feb 2021 07:14:17 +0000 Subject: [PATCH 039/103] Style fix --- pygmt/figure.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygmt/figure.py b/pygmt/figure.py index edd6546b824..f33166741fb 100644 --- a/pygmt/figure.py +++ b/pygmt/figure.py @@ -390,8 +390,8 @@ def _repr_html_(self): meca, plot, plot3d, - solar, set_panel, + solar, subplot, text, ) From 43db5ad05390a7d2d5658ac777bb1f03e7c60963 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Sat, 20 Feb 2021 07:19:57 +0000 Subject: [PATCH 040/103] Style fix --- pygmt/src/solar.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pygmt/src/solar.py b/pygmt/src/solar.py index 8e4ec9a8188..90f85088319 100644 --- a/pygmt/src/solar.py +++ b/pygmt/src/solar.py @@ -73,7 +73,8 @@ def solar(self, **kwargs): is added in ISO format, e.g. 12:15 UTC on April 25, 2000 is ``2000-04-25T12:15:00``. pen : str - Set pen attributes for lines. The default pen is ``default,black,solid``. + Set pen attributes for lines. The default pen + is ``default,black,solid``. {XY} {p} {U} @@ -84,7 +85,8 @@ def solar(self, **kwargs): # try to parse date to datetime object # if not recognizable # raise error - # function to pass datetime object to return datetime string to pass to GMT API + # function to pass datetime object to return datetime string to pass to + # GMT API kwargs = self._preprocess(**kwargs) with Session() as lib: lib.call_module("solar", build_arg_string(kwargs)) From 338cb4f170a15cc05d84369b710718dee83fca59 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Sat, 20 Feb 2021 08:39:04 +0000 Subject: [PATCH 041/103] Allow solar to accept terminator types and datetime objects --- pygmt/src/solar.py | 57 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 48 insertions(+), 9 deletions(-) diff --git a/pygmt/src/solar.py b/pygmt/src/solar.py index 90f85088319..e7ae9e1c2a5 100644 --- a/pygmt/src/solar.py +++ b/pygmt/src/solar.py @@ -2,8 +2,18 @@ solar - Plot day-night terminators. """ +import datetime + +import pandas as pd from pygmt.clib import Session -from pygmt.helpers import build_arg_string, fmt_docstring, kwargs_to_strings, use_alias +from pygmt.exceptions import GMTInvalidInput +from pygmt.helpers import ( + args_in_kwargs, + build_arg_string, + fmt_docstring, + kwargs_to_strings, + use_alias, +) @fmt_docstring @@ -24,7 +34,7 @@ p="perspective", ) @kwargs_to_strings(R="sequence", p="sequence") -def solar(self, **kwargs): +def solar(self, terminator="d", terminator_datetime="", **kwargs): r""" Plot day-light terminators. @@ -80,13 +90,42 @@ def solar(self, **kwargs): {U} {V} """ - # if statement to determine if type is datetime object or string - # if string: - # try to parse date to datetime object - # if not recognizable - # raise error - # function to pass datetime object to return datetime string to pass to - # GMT API + kwargs = self._preprocess(**kwargs) + if not args_in_kwargs(args=["Td", "Tn", "Tc", "Ta"], kwargs=kwargs): + term_string = get_terminator_type(terminator=terminator) + if not terminator_datetime: + terminator_datetime = datetime.datetime.now() + datetime_string = get_datetime_string(terminator_datetime=terminator_datetime) + kwargs["T"] = term_string + datetime_string with Session() as lib: lib.call_module("solar", build_arg_string(kwargs)) + + +def get_terminator_type(terminator): + if terminator in ["day_night", "d"]: + return "d" + elif terminator in ["nautical", "n"]: + return "n" + elif terminator in ["civil", "c"]: + return "c" + elif terminator in ["astro", "a", "astronomical"]: + return "a" + else: + raise GMTInvalidInput("""Unrecognized solar terminator type.""") + + +def get_datetime_string(terminator_datetime): + if type(terminator_datetime) == datetime.datetime: + return terminator_datetime.strftime("%Y-%m-%dT%H-%M-%S") + elif type(terminator_datetime) == str: + try: + terminator_timestamp = pd.to_datetime(terminator_datetime) + return terminator_timestamp.strftime("%Y-%m-%dT%H-%M-%S") + except: + raise GMTInvalidInput("""Unrecognized datetime format.""") + else: + raise GMTInvalidInput( + """Accepted types for terminator_datetime are + string and datetime object.""" + ) From 0427019d6178a55117225c921e40ed8e68519d45 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Sat, 20 Feb 2021 08:57:27 +0000 Subject: [PATCH 042/103] Format fixes; add type of error to except statement --- pygmt/src/solar.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pygmt/src/solar.py b/pygmt/src/solar.py index e7ae9e1c2a5..3e3c72cd6a5 100644 --- a/pygmt/src/solar.py +++ b/pygmt/src/solar.py @@ -122,10 +122,9 @@ def get_datetime_string(terminator_datetime): try: terminator_timestamp = pd.to_datetime(terminator_datetime) return terminator_timestamp.strftime("%Y-%m-%dT%H-%M-%S") - except: + except ParserError: raise GMTInvalidInput("""Unrecognized datetime format.""") else: raise GMTInvalidInput( - """Accepted types for terminator_datetime are - string and datetime object.""" + """Accepted types for terminator_datetime are string and datetime object.""" ) From 9cc19ed4543549fe63a4565022bbb89649bd4655 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Sat, 20 Feb 2021 13:39:10 +0000 Subject: [PATCH 043/103] Change error raising --- pygmt/src/solar.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygmt/src/solar.py b/pygmt/src/solar.py index 3e3c72cd6a5..acec0f1e737 100644 --- a/pygmt/src/solar.py +++ b/pygmt/src/solar.py @@ -123,7 +123,7 @@ def get_datetime_string(terminator_datetime): terminator_timestamp = pd.to_datetime(terminator_datetime) return terminator_timestamp.strftime("%Y-%m-%dT%H-%M-%S") except ParserError: - raise GMTInvalidInput("""Unrecognized datetime format.""") + raise GMTInvalidInput("""Unrecognized datetime string format.""") else: raise GMTInvalidInput( """Accepted types for terminator_datetime are string and datetime object.""" From cd64f391cf556b9d95278e16dc8281ae263f4721 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Sat, 20 Feb 2021 13:44:10 +0000 Subject: [PATCH 044/103] Update date string building format --- pygmt/src/solar.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygmt/src/solar.py b/pygmt/src/solar.py index acec0f1e737..c24af54a0cf 100644 --- a/pygmt/src/solar.py +++ b/pygmt/src/solar.py @@ -97,7 +97,7 @@ def solar(self, terminator="d", terminator_datetime="", **kwargs): if not terminator_datetime: terminator_datetime = datetime.datetime.now() datetime_string = get_datetime_string(terminator_datetime=terminator_datetime) - kwargs["T"] = term_string + datetime_string + kwargs["T"] = term_string + "+d" + datetime_string with Session() as lib: lib.call_module("solar", build_arg_string(kwargs)) From d8090fe9eda1bbc185c9963f2517b11294640087 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Sat, 20 Feb 2021 15:07:13 +0000 Subject: [PATCH 045/103] Remove old parameters, delete invalid tests --- pygmt/src/solar.py | 44 +++------------------- pygmt/tests/test_solar.py | 78 +++------------------------------------ 2 files changed, 10 insertions(+), 112 deletions(-) diff --git a/pygmt/src/solar.py b/pygmt/src/solar.py index c24af54a0cf..edec2197b8d 100644 --- a/pygmt/src/solar.py +++ b/pygmt/src/solar.py @@ -22,10 +22,6 @@ J="projection", G="fill", B="frame", - Td="day_night", - Tc="civil_twilight", - Tn="nautical_twilight", - Ta="astronomical_twilight", W="pen", U="timestamp", V="verbose", @@ -51,37 +47,6 @@ def solar(self, terminator="d", terminator_datetime="", **kwargs): {B} fill : str Color or pattern for filling of terminators. - day_night : bool or str - [**+d**\ *date*]. - Plots the day/night terminator. If the argument is ``True``, the - current day-night terminator is plotted. Optionally, **+d** can be - added, along with the date and time, to see the day/night - terminator at a specific time. The date is added in ISO format, - e.g. 12:15 UTC on April 25, 2000 is ``2000-04-25T12:15:00``. - civil_twilight : bool or str - [**+d**\ *date*]. - Plots the civil twilight terminator. If the argument is - ``True``, the current civil twilight terminator is plotted. - Optionally, **+d** can be added, along with the date and time, to - see the day/night terminator at a specific time. The date is added - in ISO format, - e.g. 12:15 UTC on April 25, 2000 is ``2000-04-25T12:15:00``. - nautical_twilight : bool or str - [**+d**\ *date*]. - Plots the nautical twilight terminator. If the argument is - ``True``, the current nautical twilight terminator is plotted. - Optionally, **+d** can be added, along with the date and time, to - see the day/night terminator at a specific time. The date is added - in ISO format, - e.g. 12:15 UTC on April 25, 2000 is ``2000-04-25T12:15:00``. - astronomical_twilight : bool or str - [**+d**\ *date*]. - Plots the astronomical twilight terminator. If the argument is - ``True``, the current astronomical twilight terminator is - plotted. Optionally, **+d** can be added, along with the date and - time, to see the day/night terminator at a specific time. The date - is added in ISO format, - e.g. 12:15 UTC on April 25, 2000 is ``2000-04-25T12:15:00``. pen : str Set pen attributes for lines. The default pen is ``default,black,solid``. @@ -92,12 +57,13 @@ def solar(self, terminator="d", terminator_datetime="", **kwargs): """ kwargs = self._preprocess(**kwargs) - if not args_in_kwargs(args=["Td", "Tn", "Tc", "Ta"], kwargs=kwargs): + if "T" not in kwargs: term_string = get_terminator_type(terminator=terminator) if not terminator_datetime: terminator_datetime = datetime.datetime.now() datetime_string = get_datetime_string(terminator_datetime=terminator_datetime) kwargs["T"] = term_string + "+d" + datetime_string + print(kwargs["T"]) with Session() as lib: lib.call_module("solar", build_arg_string(kwargs)) @@ -117,12 +83,12 @@ def get_terminator_type(terminator): def get_datetime_string(terminator_datetime): if type(terminator_datetime) == datetime.datetime: - return terminator_datetime.strftime("%Y-%m-%dT%H-%M-%S") + return terminator_datetime.strftime("%Y-%m-%dT%H:%M:%S") elif type(terminator_datetime) == str: try: terminator_timestamp = pd.to_datetime(terminator_datetime) - return terminator_timestamp.strftime("%Y-%m-%dT%H-%M-%S") - except ParserError: + return terminator_timestamp.strftime("%Y-%m-%dT%H:%M:%S") + except ValueError: raise GMTInvalidInput("""Unrecognized datetime string format.""") else: raise GMTInvalidInput( diff --git a/pygmt/tests/test_solar.py b/pygmt/tests/test_solar.py index e9959f2ce77..9ca951f0850 100644 --- a/pygmt/tests/test_solar.py +++ b/pygmt/tests/test_solar.py @@ -1,89 +1,21 @@ """ Tests for solar. """ +import datetime + from pygmt import Figure from pygmt.helpers.testing import check_figures_equal @check_figures_equal() -def test_solar_day_night(): +def test_solar_default_terminator_string_datetime(): """ Test passing the solar argument with the day_night argument and confirm the working aliases for the solar function. """ fig_ref, fig_test = Figure(), Figure() # Use single-character arguments for the reference image - fig_ref.solar( - R="d", - J="W0/15c", - B="a", - Td="+d1990-02-17T04:25:00", - G="navyblue@75", - W="1p,red,-.-", - X=3, - Y=5, - p="135/45", - ) - fig_test.solar( - region="d", - projection="W0/15c", - frame="a", - day_night="+d1990-02-17T04:25:00", - fill="navyblue@75", - pen="1p,red,-.-", - xshift=3, - yshift=5, - perspective=[135, 45], - ) - return fig_ref, fig_test - - -@check_figures_equal() -def test_solar_civil_twilight(): - """ - Test passing the solar argument with the civil_twilight argument. - """ - fig_ref, fig_test = Figure(), Figure() - # Use single-character arguments for the reference image - fig_ref.solar(R="d", J="W0/15c", B="a", Tc="+d1990-02-17T04:25:00") - fig_test.solar( - region="d", - projection="W0/15c", - frame="a", - civil_twilight="+d1990-02-17T04:25:00", - ) - return fig_ref, fig_test - - -@check_figures_equal() -def test_solar_astronomical_twilight(): - """ - Test passing the solar argument with the astronomical_twilight argument. - """ - fig_ref, fig_test = Figure(), Figure() - # Use single-character arguments for the reference image - fig_ref.solar(R="d", J="W0/15c", B="a", Ta="+d1990-02-17T04:25:00") - fig_test.solar( - region="d", - projection="W0/15c", - frame="a", - astronomical_twilight="+d1990-02-17T04:25:00", - ) + fig_ref.solar(R="d", J="W0/15c", B="a", T="d+d1990-02-17T04:25:00") + fig_test.solar(R="d", J="W0/15c", B="a", terminator_datetime="1990-02-17 04:25:00") return fig_ref, fig_test - -@check_figures_equal() -def test_solar_nautical_twilight(): - """ - Test passing the solar argument with the nautical_twilight argument. - """ - fig_ref, fig_test = Figure(), Figure() - # Use single-character arguments for the reference image - fig_ref.solar(R="d", J="W0/15c", B="a", Tn="+d1990-02-17T04:25:00") - fig_test.solar( - region="d", - projection="W0/15c", - frame="a", - nautical_twilight="+d1990-02-17T04:25:00", - ) - return fig_ref, fig_test From 87097aa38faac44638905a90f21d4b1f887c2b2d Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Sun, 21 Feb 2021 16:10:25 +0000 Subject: [PATCH 046/103] Make suggested refactors for get_terminator_type and get_datetime_string --- pygmt/src/solar.py | 38 +++++++++++++++++--------------------- pygmt/tests/test_solar.py | 1 - 2 files changed, 17 insertions(+), 22 deletions(-) diff --git a/pygmt/src/solar.py b/pygmt/src/solar.py index edec2197b8d..026c07a7c4a 100644 --- a/pygmt/src/solar.py +++ b/pygmt/src/solar.py @@ -69,28 +69,24 @@ def solar(self, terminator="d", terminator_datetime="", **kwargs): def get_terminator_type(terminator): - if terminator in ["day_night", "d"]: - return "d" - elif terminator in ["nautical", "n"]: - return "n" - elif terminator in ["civil", "c"]: - return "c" - elif terminator in ["astro", "a", "astronomical"]: - return "a" - else: + if terminator not in [ + "day_night", + "nautical", + "civil", + "astronomical", + "astro", + "d", + "n", + "c", + "a", + ]: raise GMTInvalidInput("""Unrecognized solar terminator type.""") + return terminator[0] def get_datetime_string(terminator_datetime): - if type(terminator_datetime) == datetime.datetime: - return terminator_datetime.strftime("%Y-%m-%dT%H:%M:%S") - elif type(terminator_datetime) == str: - try: - terminator_timestamp = pd.to_datetime(terminator_datetime) - return terminator_timestamp.strftime("%Y-%m-%dT%H:%M:%S") - except ValueError: - raise GMTInvalidInput("""Unrecognized datetime string format.""") - else: - raise GMTInvalidInput( - """Accepted types for terminator_datetime are string and datetime object.""" - ) + try: + terminator_timestamp = pd.to_datetime(terminator_datetime) + return terminator_timestamp.strftime("%Y-%m-%dT%H:%M:%S") + except ValueError: + raise GMTInvalidInput("""Unrecognized datetime string format.""") diff --git a/pygmt/tests/test_solar.py b/pygmt/tests/test_solar.py index 9ca951f0850..3e9b32b6d3d 100644 --- a/pygmt/tests/test_solar.py +++ b/pygmt/tests/test_solar.py @@ -18,4 +18,3 @@ def test_solar_default_terminator_string_datetime(): fig_ref.solar(R="d", J="W0/15c", B="a", T="d+d1990-02-17T04:25:00") fig_test.solar(R="d", J="W0/15c", B="a", terminator_datetime="1990-02-17 04:25:00") return fig_ref, fig_test - From b2a0142f46f5af9b85be29b9a8a5c48801ddfea1 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Sun, 21 Feb 2021 16:16:42 +0000 Subject: [PATCH 047/103] Move all funtions into solar function --- pygmt/src/solar.py | 44 ++++++++++++++++++-------------------------- 1 file changed, 18 insertions(+), 26 deletions(-) diff --git a/pygmt/src/solar.py b/pygmt/src/solar.py index 026c07a7c4a..ec22d1d9c84 100644 --- a/pygmt/src/solar.py +++ b/pygmt/src/solar.py @@ -58,35 +58,27 @@ def solar(self, terminator="d", terminator_datetime="", **kwargs): kwargs = self._preprocess(**kwargs) if "T" not in kwargs: - term_string = get_terminator_type(terminator=terminator) + if terminator not in [ + "day_night", + "nautical", + "civil", + "astronomical", + "astro", + "d", + "n", + "c", + "a", + ]: + raise GMTInvalidInput("""Unrecognized solar terminator type.""") + term_string = terminator[0] if not terminator_datetime: terminator_datetime = datetime.datetime.now() - datetime_string = get_datetime_string(terminator_datetime=terminator_datetime) + try: + terminator_timestamp = pd.to_datetime(terminator_datetime) + datetime_string = terminator_timestamp.strftime("%Y-%m-%dT%H:%M:%S") + except ValueError: + raise GMTInvalidInput("""Unrecognized datetime format.""") kwargs["T"] = term_string + "+d" + datetime_string print(kwargs["T"]) with Session() as lib: lib.call_module("solar", build_arg_string(kwargs)) - - -def get_terminator_type(terminator): - if terminator not in [ - "day_night", - "nautical", - "civil", - "astronomical", - "astro", - "d", - "n", - "c", - "a", - ]: - raise GMTInvalidInput("""Unrecognized solar terminator type.""") - return terminator[0] - - -def get_datetime_string(terminator_datetime): - try: - terminator_timestamp = pd.to_datetime(terminator_datetime) - return terminator_timestamp.strftime("%Y-%m-%dT%H:%M:%S") - except ValueError: - raise GMTInvalidInput("""Unrecognized datetime string format.""") From 672c04d61fbd13051c538409a5dc85967f6c46c5 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Sun, 21 Feb 2021 16:46:10 +0000 Subject: [PATCH 048/103] Update tests, change gallery example --- examples/gallery/plot/solar.py | 34 ++++++++++++++-- pygmt/src/solar.py | 2 +- pygmt/tests/test_solar.py | 72 ++++++++++++++++++++++++++++++++-- 3 files changed, 100 insertions(+), 8 deletions(-) diff --git a/examples/gallery/plot/solar.py b/examples/gallery/plot/solar.py index 9ed5260491c..2ecf3aac1ed 100644 --- a/examples/gallery/plot/solar.py +++ b/examples/gallery/plot/solar.py @@ -5,6 +5,8 @@ Use :meth:`pygmt.Figure.solar` to plot the day-night terminator line, and civil, nautical, astronomical twilights. """ +import datetime + import pygmt fig = pygmt.Figure() @@ -12,10 +14,34 @@ # 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 1p thick # Set the fill for the night area to be navy blue at 80% transparency -fig.solar(day_night="+d2000-01-01T17:00:00", fill="navyblue@95", pen="1p") -fig.solar(civil_twilight="+d2000-01-01T17:00:00", fill="navyblue@85", pen="1p") -fig.solar(nautical_twilight="+d2000-01-01T17:00:00", fill="navyblue@80", pen="1p") -fig.solar(astronomical_twilight="+d2000-01-01T17:00:00", fill="navyblue@80", pen="1p") + +fig.solar( + terminator="day_night", + terminator_datetime=terminator_datetime, + fill="navyblue@95", + pen="1p", +) +fig.solar( + terminator="civil", + terminator_datetime=terminator_datetime, + fill="navyblue@85", + pen="1p", +) +fig.solar( + terminator="nautical", + terminator_datetime=terminator_datetime, + fill="navyblue@80", + pen="1p", +) +fig.solar( + terminator="astronomical", + terminator_datetime=terminator_datetime, + fill="navyblue@80", + pen="1p", +) fig.show() diff --git a/pygmt/src/solar.py b/pygmt/src/solar.py index ec22d1d9c84..69133ca5373 100644 --- a/pygmt/src/solar.py +++ b/pygmt/src/solar.py @@ -69,6 +69,7 @@ def solar(self, terminator="d", terminator_datetime="", **kwargs): "c", "a", ]: + print(kwargs) raise GMTInvalidInput("""Unrecognized solar terminator type.""") term_string = terminator[0] if not terminator_datetime: @@ -79,6 +80,5 @@ def solar(self, terminator="d", terminator_datetime="", **kwargs): except ValueError: raise GMTInvalidInput("""Unrecognized datetime format.""") kwargs["T"] = term_string + "+d" + datetime_string - print(kwargs["T"]) with Session() as lib: lib.call_module("solar", build_arg_string(kwargs)) diff --git a/pygmt/tests/test_solar.py b/pygmt/tests/test_solar.py index 3e9b32b6d3d..6a0d4f53792 100644 --- a/pygmt/tests/test_solar.py +++ b/pygmt/tests/test_solar.py @@ -3,18 +3,84 @@ """ import datetime +import pytest from pygmt import Figure +from pygmt.exceptions import GMTInvalidInput from pygmt.helpers.testing import check_figures_equal @check_figures_equal() -def test_solar_default_terminator_string_datetime(): +def test_solar_set_terminator_string_datetime(): """ - Test passing the solar argument with the day_night argument and confirm the - working aliases for the solar function. + Test passing the solar argument with the day_night terminator and a + datetime string. + """ + fig_ref, fig_test = Figure(), Figure() + # Use single-character arguments for the reference image + fig_ref.solar(R="d", J="W0/15c", B="a", T="d+d1990-02-17T04:25:00") + fig_test.solar( + R="d", + J="W0/15c", + B="a", + termiantor="day_night", + terminator_datetime="1990-02-17 04:25:00", + ) + return fig_ref, fig_test + + +@check_figures_equal() +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_ref, fig_test = Figure(), Figure() # Use single-character arguments for the reference image fig_ref.solar(R="d", J="W0/15c", B="a", T="d+d1990-02-17T04:25:00") fig_test.solar(R="d", J="W0/15c", B="a", terminator_datetime="1990-02-17 04:25:00") return fig_ref, fig_test + + +@check_figures_equal() +def test_solar_set_terminator_string_datetime(): + """ + Test passing the solar argument with the day_night terminator and a + datetime string. + """ + fig_ref, fig_test = Figure(), Figure() + # Use single-character arguments for the reference image + fig_ref.solar(R="d", J="W0/15c", B="a", T="d+d1990-02-17T04:25:00") + terminator_datetime = datetime.datetime( + year=1990, month=2, day=17, hour=4, minute=25, second=0 + ) + fig_test.solar( + R="d", + J="W0/15c", + B="a", + termiantor="day_night", + terminator_datetime=terminator_datetime, + ) + return fig_ref, fig_test + + +def test_invalid_terminator_type(): + """ + Test if fig.solar fails when it receives an invalid terminator type. + """ + fig = Figure() + with pytest.raises(GMTInvalidInput): + fig.solar( + R="d", + J="W0/15c", + B="a", + terminator="invalid", + ) + + +def test_invalid_datetime(): + """ + Test if fig.solar fails when it receives an invalid datetime string. + """ + fig = Figure() + with pytest.raises(GMTInvalidInput): + fig.solar(R="d", J="W0/15c", B="a", terminator_datetime="199A-02-17 04:25:00") From d2acbfa1220cd7b5cf86cb1f8a7aba6cb98cd440 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Sun, 21 Feb 2021 16:50:25 +0000 Subject: [PATCH 049/103] Naming fix --- pygmt/tests/test_solar.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pygmt/tests/test_solar.py b/pygmt/tests/test_solar.py index 6a0d4f53792..09ecadc13cc 100644 --- a/pygmt/tests/test_solar.py +++ b/pygmt/tests/test_solar.py @@ -10,7 +10,7 @@ @check_figures_equal() -def test_solar_set_terminator_string_datetime(): +def test_solar_set_terminator_datetime_string(): """ Test passing the solar argument with the day_night terminator and a datetime string. @@ -42,7 +42,7 @@ def test_solar_default_terminator(): @check_figures_equal() -def test_solar_set_terminator_string_datetime(): +def test_solar_set_terminator_datetime_object(): """ Test passing the solar argument with the day_night terminator and a datetime string. From d835de41268da3fd59df9c38dc424956ac728bd5 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Sun, 21 Feb 2021 17:05:45 +0000 Subject: [PATCH 050/103] Update documentation for solar --- pygmt/src/solar.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/pygmt/src/solar.py b/pygmt/src/solar.py index 69133ca5373..fc953555b6b 100644 --- a/pygmt/src/solar.py +++ b/pygmt/src/solar.py @@ -7,13 +7,7 @@ import pandas as pd from pygmt.clib import Session from pygmt.exceptions import GMTInvalidInput -from pygmt.helpers import ( - args_in_kwargs, - build_arg_string, - fmt_docstring, - kwargs_to_strings, - use_alias, -) +from pygmt.helpers import build_arg_string, fmt_docstring, kwargs_to_strings, use_alias @fmt_docstring @@ -42,6 +36,17 @@ def solar(self, terminator="d", terminator_datetime="", **kwargs): Parameters ---------- + terminator : str + Set the type of terminator displayed. The parameters 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``] + terminator_datetime : str or datetime object + Set the UTC date and time of the displayed terminator. It can be + passed as a string, using the format *YYYY-MM-DD*\ **T**\ *HH:MM:SS* + (e.g. 0600 on January 1, 2000 would be ``2000-01-01T06:00:00``). A + datetime object can be passed as well. + [Default is the current date and time]. {R} {J} {B} From 7580b2efaa721a4db1253e24066cb6bbebbd40de Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Sun, 21 Feb 2021 21:23:19 +0000 Subject: [PATCH 051/103] Formatting fixes --- pygmt/src/solar.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pygmt/src/solar.py b/pygmt/src/solar.py index fc953555b6b..7d09f94705c 100644 --- a/pygmt/src/solar.py +++ b/pygmt/src/solar.py @@ -43,10 +43,10 @@ def solar(self, terminator="d", terminator_datetime="", **kwargs): [Default is ``day_night``] terminator_datetime : str or datetime object Set the UTC date and time of the displayed terminator. It can be - passed as a string, using the format *YYYY-MM-DD*\ **T**\ *HH:MM:SS* - (e.g. 0600 on January 1, 2000 would be ``2000-01-01T06:00:00``). A + passed as a string, using the format *YYYY-MM-DD HH:MM:SS* + (e.g. 0600 on January 1, 2000 would be ``2000-01-01 06:00:00``). A datetime object can be passed as well. - [Default is the current date and time]. + [Default is the current date and time] {R} {J} {B} From 857194ae8f94d0776ef2f46dce08a642230dee8a Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Mon, 22 Feb 2021 07:30:22 +0000 Subject: [PATCH 052/103] Apply suggestions from code review Co-authored-by: Dongdong Tian --- pygmt/src/solar.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygmt/src/solar.py b/pygmt/src/solar.py index 7d09f94705c..0797d7de1ab 100644 --- a/pygmt/src/solar.py +++ b/pygmt/src/solar.py @@ -61,7 +61,7 @@ def solar(self, terminator="d", terminator_datetime="", **kwargs): {V} """ - kwargs = self._preprocess(**kwargs) + kwargs = self._preprocess(**kwargs) # pylint: disable=protected-access if "T" not in kwargs: if terminator not in [ "day_night", From eb49c79f1b4d84c8b5fd3ea16402fb657cb6c249 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Mon, 22 Feb 2021 07:42:49 +0000 Subject: [PATCH 053/103] Update pygmt/src/solar.py Co-authored-by: Wei Ji <23487320+weiji14@users.noreply.github.com> --- pygmt/src/solar.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pygmt/src/solar.py b/pygmt/src/solar.py index 0797d7de1ab..e53ca63d39f 100644 --- a/pygmt/src/solar.py +++ b/pygmt/src/solar.py @@ -82,8 +82,8 @@ def solar(self, terminator="d", terminator_datetime="", **kwargs): try: terminator_timestamp = pd.to_datetime(terminator_datetime) datetime_string = terminator_timestamp.strftime("%Y-%m-%dT%H:%M:%S") - except ValueError: - raise GMTInvalidInput("""Unrecognized datetime format.""") + except ValueError as verr: + raise GMTInvalidInput("Unrecognized datetime format.") from verr kwargs["T"] = term_string + "+d" + datetime_string with Session() as lib: lib.call_module("solar", build_arg_string(kwargs)) From 3316a36346d4ba51ef95dbe43020bcfe4558819a Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Mon, 22 Feb 2021 07:46:01 +0000 Subject: [PATCH 054/103] Remove term_string variable from solar.py --- pygmt/src/solar.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pygmt/src/solar.py b/pygmt/src/solar.py index e53ca63d39f..158ea9bb108 100644 --- a/pygmt/src/solar.py +++ b/pygmt/src/solar.py @@ -76,7 +76,6 @@ def solar(self, terminator="d", terminator_datetime="", **kwargs): ]: print(kwargs) raise GMTInvalidInput("""Unrecognized solar terminator type.""") - term_string = terminator[0] if not terminator_datetime: terminator_datetime = datetime.datetime.now() try: @@ -84,6 +83,6 @@ def solar(self, terminator="d", terminator_datetime="", **kwargs): datetime_string = terminator_timestamp.strftime("%Y-%m-%dT%H:%M:%S") except ValueError as verr: raise GMTInvalidInput("Unrecognized datetime format.") from verr - kwargs["T"] = term_string + "+d" + datetime_string + kwargs["T"] = terminator[0] + "+d" + datetime_string with Session() as lib: lib.call_module("solar", build_arg_string(kwargs)) From 766c4ebb5492cc7fd5572f277fd895395185bc58 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Mon, 22 Feb 2021 08:01:59 +0000 Subject: [PATCH 055/103] Apply suggestions from code review Co-authored-by: Wei Ji <23487320+weiji14@users.noreply.github.com> --- pygmt/src/solar.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/pygmt/src/solar.py b/pygmt/src/solar.py index 158ea9bb108..e344d28fa7a 100644 --- a/pygmt/src/solar.py +++ b/pygmt/src/solar.py @@ -37,8 +37,8 @@ def solar(self, terminator="d", terminator_datetime="", **kwargs): Parameters ---------- terminator : str - Set the type of terminator displayed. The parameters are - ``day_night``, ``civil``, ``nautical``, and ``astronomical``, which + 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``] terminator_datetime : str or datetime object @@ -55,10 +55,12 @@ def solar(self, terminator="d", terminator_datetime="", **kwargs): pen : str Set pen attributes for lines. The default pen is ``default,black,solid``. - {XY} - {p} {U} {V} + {XY} + {c} + {p} + {t} """ kwargs = self._preprocess(**kwargs) # pylint: disable=protected-access @@ -74,8 +76,10 @@ def solar(self, terminator="d", terminator_datetime="", **kwargs): "c", "a", ]: - print(kwargs) - raise GMTInvalidInput("""Unrecognized solar terminator type.""") + raise GMTInvalidInput( + f"Unrecognized solar terminator type '{terminator}'. Valid values " + "are 'day_night', 'civil', 'nautical', and 'astronomical'." + ) if not terminator_datetime: terminator_datetime = datetime.datetime.now() try: From 0e8fb1c67d469f903bd1ff15372a76af8fbca4c2 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Mon, 22 Feb 2021 08:03:58 +0000 Subject: [PATCH 056/103] Run make format --- pygmt/src/solar.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pygmt/src/solar.py b/pygmt/src/solar.py index e344d28fa7a..2db47cb3743 100644 --- a/pygmt/src/solar.py +++ b/pygmt/src/solar.py @@ -77,8 +77,8 @@ def solar(self, terminator="d", terminator_datetime="", **kwargs): "a", ]: raise GMTInvalidInput( - f"Unrecognized solar terminator type '{terminator}'. Valid values " - "are 'day_night', 'civil', 'nautical', and 'astronomical'." + f"Unrecognized solar terminator type '{terminator}'. Valid values " + "are 'day_night', 'civil', 'nautical', and 'astronomical'." ) if not terminator_datetime: terminator_datetime = datetime.datetime.now() From 16811ca190bce618cb1845915b1c57a02cbdba65 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Mon, 22 Feb 2021 11:50:42 +0000 Subject: [PATCH 057/103] Change test to use non-default terminator type --- pygmt/tests/test_solar.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pygmt/tests/test_solar.py b/pygmt/tests/test_solar.py index 09ecadc13cc..6116df8a8f1 100644 --- a/pygmt/tests/test_solar.py +++ b/pygmt/tests/test_solar.py @@ -12,17 +12,17 @@ @check_figures_equal() def test_solar_set_terminator_datetime_string(): """ - Test passing the solar argument with the day_night terminator and a + Test passing the solar argument with the civil terminator and a datetime string. """ fig_ref, fig_test = Figure(), Figure() # Use single-character arguments for the reference image - fig_ref.solar(R="d", J="W0/15c", B="a", T="d+d1990-02-17T04:25:00") + fig_ref.solar(R="d", J="W0/15c", B="a", T="c+d1990-02-17T04:25:00") fig_test.solar( R="d", J="W0/15c", B="a", - termiantor="day_night", + terminator="civil", terminator_datetime="1990-02-17 04:25:00", ) return fig_ref, fig_test From b7b5c81cd1519da720268157bc86c41e3c9f769e Mon Sep 17 00:00:00 2001 From: actions-bot <58130806+actions-bot@users.noreply.github.com> Date: Mon, 22 Feb 2021 11:54:01 +0000 Subject: [PATCH 058/103] [format-command] fixes --- pygmt/tests/test_solar.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pygmt/tests/test_solar.py b/pygmt/tests/test_solar.py index 6116df8a8f1..b6e36050cd2 100644 --- a/pygmt/tests/test_solar.py +++ b/pygmt/tests/test_solar.py @@ -12,8 +12,8 @@ @check_figures_equal() def test_solar_set_terminator_datetime_string(): """ - Test passing the solar argument with the civil terminator and a - datetime string. + Test passing the solar argument with the civil terminator and a datetime + string. """ fig_ref, fig_test = Figure(), Figure() # Use single-character arguments for the reference image From 034aca824f92172f4634bba03d8ef004e5a3b27d Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Tue, 23 Feb 2021 04:48:54 +0000 Subject: [PATCH 059/103] Update pygmt/src/solar.py Co-authored-by: Dongdong Tian --- pygmt/src/solar.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygmt/src/solar.py b/pygmt/src/solar.py index 2db47cb3743..29cf2faaa1a 100644 --- a/pygmt/src/solar.py +++ b/pygmt/src/solar.py @@ -24,7 +24,7 @@ p="perspective", ) @kwargs_to_strings(R="sequence", p="sequence") -def solar(self, terminator="d", terminator_datetime="", **kwargs): +def solar(self, terminator="d", terminator_datetime=None, **kwargs): r""" Plot day-light terminators. From 06332bb83c9a6c65a18c2e4edd70ed917b11cdfd Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Sun, 28 Feb 2021 08:36:48 +0000 Subject: [PATCH 060/103] Apply suggestions from code review Co-authored-by: Dongdong Tian Co-authored-by: Wei Ji <23487320+weiji14@users.noreply.github.com> --- examples/gallery/plot/solar.py | 3 +-- pygmt/src/solar.py | 5 +++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/gallery/plot/solar.py b/examples/gallery/plot/solar.py index 2ecf3aac1ed..322e7eba9da 100644 --- a/examples/gallery/plot/solar.py +++ b/examples/gallery/plot/solar.py @@ -18,8 +18,7 @@ year=2000, month=1, day=1, hour=17, minute=0, second=0 ) # Set the pen line to be 1p thick -# Set the fill for the night area to be navy blue at 80% transparency - +# Set the fill for the night area to be navy blue at different transparency levels fig.solar( terminator="day_night", terminator_datetime=terminator_datetime, diff --git a/pygmt/src/solar.py b/pygmt/src/solar.py index 29cf2faaa1a..f965856a2ef 100644 --- a/pygmt/src/solar.py +++ b/pygmt/src/solar.py @@ -21,7 +21,9 @@ V="verbose", X="xshift", Y="yshift", + c="panel", p="perspective", + t="transparency", ) @kwargs_to_strings(R="sequence", p="sequence") def solar(self, terminator="d", terminator_datetime=None, **kwargs): @@ -83,8 +85,7 @@ def solar(self, terminator="d", terminator_datetime=None, **kwargs): if not terminator_datetime: terminator_datetime = datetime.datetime.now() try: - terminator_timestamp = pd.to_datetime(terminator_datetime) - datetime_string = terminator_timestamp.strftime("%Y-%m-%dT%H:%M:%S") + datetime_string = pd.to_datetime(terminator_datetime).strftime("%Y-%m-%dT%H:%M:%S") except ValueError as verr: raise GMTInvalidInput("Unrecognized datetime format.") from verr kwargs["T"] = terminator[0] + "+d" + datetime_string From 79c4182537f755f1b8ccea30b135b2241922df85 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Wed, 17 Mar 2021 20:23:06 +0000 Subject: [PATCH 061/103] run make format --- pygmt/src/solar.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pygmt/src/solar.py b/pygmt/src/solar.py index f965856a2ef..8dcb4e5d1a6 100644 --- a/pygmt/src/solar.py +++ b/pygmt/src/solar.py @@ -85,7 +85,9 @@ def solar(self, terminator="d", terminator_datetime=None, **kwargs): if not terminator_datetime: terminator_datetime = datetime.datetime.now() try: - datetime_string = pd.to_datetime(terminator_datetime).strftime("%Y-%m-%dT%H:%M:%S") + datetime_string = pd.to_datetime(terminator_datetime).strftime( + "%Y-%m-%dT%H:%M:%S" + ) except ValueError as verr: raise GMTInvalidInput("Unrecognized datetime format.") from verr kwargs["T"] = terminator[0] + "+d" + datetime_string From e367ea82d36cc5c4194160d0aa0fd7d4a85283b4 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Thu, 18 Mar 2021 20:17:59 +0000 Subject: [PATCH 062/103] Update testing in test_solar.py --- pygmt/tests/test_solar.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/pygmt/tests/test_solar.py b/pygmt/tests/test_solar.py index b6e36050cd2..1c39d681d4b 100644 --- a/pygmt/tests/test_solar.py +++ b/pygmt/tests/test_solar.py @@ -28,17 +28,15 @@ def test_solar_set_terminator_datetime_string(): return fig_ref, fig_test -@check_figures_equal() +@pytest.mark.mpl_image_compare 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_ref, fig_test = Figure(), Figure() - # Use single-character arguments for the reference image - fig_ref.solar(R="d", J="W0/15c", B="a", T="d+d1990-02-17T04:25:00") - fig_test.solar(R="d", J="W0/15c", B="a", terminator_datetime="1990-02-17 04:25:00") - return fig_ref, fig_test + fig = Figure() + fig.solar(R="d", J="W0/15c", B="a", terminator_datetime="1990-02-17 04:25:00") + return fig @check_figures_equal() From b2092e4d48ef395d53b0ad56a5648e42277cfe21 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Thu, 18 Mar 2021 20:18:10 +0000 Subject: [PATCH 063/103] Add dvc file --- pygmt/tests/baseline/test_solar_default_terminator.png.dvc | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 pygmt/tests/baseline/test_solar_default_terminator.png.dvc diff --git a/pygmt/tests/baseline/test_solar_default_terminator.png.dvc b/pygmt/tests/baseline/test_solar_default_terminator.png.dvc new file mode 100644 index 00000000000..6bc9e740fff --- /dev/null +++ b/pygmt/tests/baseline/test_solar_default_terminator.png.dvc @@ -0,0 +1,4 @@ +outs: +- md5: 0a7f4959b500b6fa3a560a6368db0f90 + size: 25982 + path: test_solar_default_terminator.png From aadca323d7540e4ac2c728db6f5406a3351d6df6 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Thu, 18 Mar 2021 20:35:33 +0000 Subject: [PATCH 064/103] replace short aliases with long aliases --- pygmt/tests/test_solar.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/pygmt/tests/test_solar.py b/pygmt/tests/test_solar.py index 1c39d681d4b..b8ef46b40b5 100644 --- a/pygmt/tests/test_solar.py +++ b/pygmt/tests/test_solar.py @@ -35,7 +35,12 @@ def test_solar_default_terminator(): to confirm the default terminator type. """ fig = Figure() - fig.solar(R="d", J="W0/15c", B="a", terminator_datetime="1990-02-17 04:25:00") + fig.solar( + region="d", + projection="W0/15c", + frame="a", + terminator_datetime="1990-02-17 04:25:00", + ) return fig @@ -68,9 +73,9 @@ def test_invalid_terminator_type(): fig = Figure() with pytest.raises(GMTInvalidInput): fig.solar( - R="d", - J="W0/15c", - B="a", + region="d", + projection="W0/15c", + frame="a", terminator="invalid", ) @@ -81,4 +86,9 @@ def test_invalid_datetime(): """ fig = Figure() with pytest.raises(GMTInvalidInput): - fig.solar(R="d", J="W0/15c", B="a", terminator_datetime="199A-02-17 04:25:00") + fig.solar( + region="d", + projection="W0/15c", + frame="a", + terminator_datetime="199A-02-17 04:25:00", + ) From b545fb99dc19a700f69638cd1612731f36654a7c Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Thu, 18 Mar 2021 20:48:58 +0000 Subject: [PATCH 065/103] Update test_solar.py tests --- pygmt/tests/test_solar.py | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/pygmt/tests/test_solar.py b/pygmt/tests/test_solar.py index b8ef46b40b5..72ed3e266f3 100644 --- a/pygmt/tests/test_solar.py +++ b/pygmt/tests/test_solar.py @@ -9,23 +9,21 @@ from pygmt.helpers.testing import check_figures_equal -@check_figures_equal() +@pytest.mark.mpl_image_compare def test_solar_set_terminator_datetime_string(): """ Test passing the solar argument with the civil terminator and a datetime string. """ - fig_ref, fig_test = Figure(), Figure() - # Use single-character arguments for the reference image - fig_ref.solar(R="d", J="W0/15c", B="a", T="c+d1990-02-17T04:25:00") - fig_test.solar( - R="d", - J="W0/15c", - B="a", + fig = Figure() + fig.solar( + region="d", + projection="W0/15c", + frame="a", terminator="civil", terminator_datetime="1990-02-17 04:25:00", ) - return fig_ref, fig_test + return fig @pytest.mark.mpl_image_compare @@ -44,26 +42,24 @@ def test_solar_default_terminator(): return fig -@check_figures_equal() +@pytest.mark.mpl_image_compare def test_solar_set_terminator_datetime_object(): """ Test passing the solar argument with the day_night terminator and a datetime string. """ - fig_ref, fig_test = Figure(), Figure() - # Use single-character arguments for the reference image - fig_ref.solar(R="d", J="W0/15c", B="a", T="d+d1990-02-17T04:25:00") + fig = Figure() terminator_datetime = datetime.datetime( year=1990, month=2, day=17, hour=4, minute=25, second=0 ) - fig_test.solar( + fig.solar( R="d", J="W0/15c", B="a", termiantor="day_night", terminator_datetime=terminator_datetime, ) - return fig_ref, fig_test + return fig def test_invalid_terminator_type(): From 33b67dec6e652b39442d25ceeb466bd2ad70fff4 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Thu, 18 Mar 2021 20:50:02 +0000 Subject: [PATCH 066/103] Add test_solar_set_terminator_datetime_object.png.dvc and test_solar_set_terminator_datetime_string.png.dvc into DVC --- .../test_solar_set_terminator_datetime_object.png.dvc | 4 ++++ .../test_solar_set_terminator_datetime_string.png.dvc | 4 ++++ 2 files changed, 8 insertions(+) create mode 100644 pygmt/tests/baseline/test_solar_set_terminator_datetime_object.png.dvc create mode 100644 pygmt/tests/baseline/test_solar_set_terminator_datetime_string.png.dvc diff --git a/pygmt/tests/baseline/test_solar_set_terminator_datetime_object.png.dvc b/pygmt/tests/baseline/test_solar_set_terminator_datetime_object.png.dvc new file mode 100644 index 00000000000..61b633b93ca --- /dev/null +++ b/pygmt/tests/baseline/test_solar_set_terminator_datetime_object.png.dvc @@ -0,0 +1,4 @@ +outs: +- md5: 0a7f4959b500b6fa3a560a6368db0f90 + size: 25982 + path: test_solar_set_terminator_datetime_object.png diff --git a/pygmt/tests/baseline/test_solar_set_terminator_datetime_string.png.dvc b/pygmt/tests/baseline/test_solar_set_terminator_datetime_string.png.dvc new file mode 100644 index 00000000000..a35368bbb45 --- /dev/null +++ b/pygmt/tests/baseline/test_solar_set_terminator_datetime_string.png.dvc @@ -0,0 +1,4 @@ +outs: +- md5: 9437b5fd846526c7cac12ab327a4d78f + size: 26501 + path: test_solar_set_terminator_datetime_string.png From b161432a86b206cf428f383ca5c125b4fe3ad4a8 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Thu, 18 Mar 2021 20:51:51 +0000 Subject: [PATCH 067/103] remove unused import --- pygmt/tests/test_solar.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pygmt/tests/test_solar.py b/pygmt/tests/test_solar.py index 72ed3e266f3..420bfee1193 100644 --- a/pygmt/tests/test_solar.py +++ b/pygmt/tests/test_solar.py @@ -6,7 +6,6 @@ import pytest from pygmt import Figure from pygmt.exceptions import GMTInvalidInput -from pygmt.helpers.testing import check_figures_equal @pytest.mark.mpl_image_compare From 0e5b65f7b918f40334075762f7c7b0d89729459b Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Fri, 19 Mar 2021 06:47:28 +0000 Subject: [PATCH 068/103] remove if statement for testing if T is in kwargs --- pygmt/src/solar.py | 49 +++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/pygmt/src/solar.py b/pygmt/src/solar.py index 8dcb4e5d1a6..8d8cc861694 100644 --- a/pygmt/src/solar.py +++ b/pygmt/src/solar.py @@ -66,30 +66,29 @@ def solar(self, terminator="d", terminator_datetime=None, **kwargs): """ kwargs = self._preprocess(**kwargs) # pylint: disable=protected-access - if "T" not in kwargs: - if terminator not in [ - "day_night", - "nautical", - "civil", - "astronomical", - "astro", - "d", - "n", - "c", - "a", - ]: - raise GMTInvalidInput( - f"Unrecognized solar terminator type '{terminator}'. Valid values " - "are 'day_night', 'civil', 'nautical', and 'astronomical'." - ) - if not terminator_datetime: - terminator_datetime = datetime.datetime.now() - try: - datetime_string = pd.to_datetime(terminator_datetime).strftime( - "%Y-%m-%dT%H:%M:%S" - ) - except ValueError as verr: - raise GMTInvalidInput("Unrecognized datetime format.") from verr - kwargs["T"] = terminator[0] + "+d" + datetime_string + if terminator not in [ + "day_night", + "nautical", + "civil", + "astronomical", + "astro", + "d", + "n", + "c", + "a", + ]: + raise GMTInvalidInput( + f"Unrecognized solar terminator type '{terminator}'. Valid values " + "are 'day_night', 'civil', 'nautical', and 'astronomical'." + ) + if not terminator_datetime: + terminator_datetime = datetime.datetime.now() + try: + datetime_string = pd.to_datetime(terminator_datetime).strftime( + "%Y-%m-%dT%H:%M:%S" + ) + except ValueError as verr: + raise GMTInvalidInput("Unrecognized datetime format.") from verr + kwargs["T"] = terminator[0] + "+d" + datetime_string with Session() as lib: lib.call_module("solar", build_arg_string(kwargs)) From 386ea48323f2d4462221d475ffab0f15c903c2af Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Fri, 19 Mar 2021 06:48:18 +0000 Subject: [PATCH 069/103] move solar gallery example to embellishments --- examples/gallery/{plot => embellishments}/solar.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename examples/gallery/{plot => embellishments}/solar.py (100%) diff --git a/examples/gallery/plot/solar.py b/examples/gallery/embellishments/solar.py similarity index 100% rename from examples/gallery/plot/solar.py rename to examples/gallery/embellishments/solar.py From ac63d8aa852dcf91cdc1da85bb8b7da958307cef Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Fri, 19 Mar 2021 06:52:19 +0000 Subject: [PATCH 070/103] add if statement for T being passed --- pygmt/src/solar.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pygmt/src/solar.py b/pygmt/src/solar.py index 8d8cc861694..e891a35b5e3 100644 --- a/pygmt/src/solar.py +++ b/pygmt/src/solar.py @@ -66,6 +66,10 @@ def solar(self, terminator="d", terminator_datetime=None, **kwargs): """ 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", "nautical", From e4f8c19038a2843ef70aa936ae535f3a33046122 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Fri, 19 Mar 2021 06:57:30 +0000 Subject: [PATCH 071/103] add test for raising GMTInvalidInput when T is passed --- pygmt/src/solar.py | 2 +- pygmt/tests/test_solar.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/pygmt/src/solar.py b/pygmt/src/solar.py index e891a35b5e3..d0b5e87123e 100644 --- a/pygmt/src/solar.py +++ b/pygmt/src/solar.py @@ -68,7 +68,7 @@ def solar(self, terminator="d", terminator_datetime=None, **kwargs): kwargs = self._preprocess(**kwargs) # pylint: disable=protected-access if "T" in kwargs: raise GMTInvalidInput( - "Use 'terminator' and 'terminator_datetime' instead of 'T'," + "Use 'terminator' and 'terminator_datetime' instead of 'T'." ) if terminator not in [ "day_night", diff --git a/pygmt/tests/test_solar.py b/pygmt/tests/test_solar.py index 420bfee1193..30ec9710554 100644 --- a/pygmt/tests/test_solar.py +++ b/pygmt/tests/test_solar.py @@ -75,6 +75,21 @@ def test_invalid_terminator_type(): ) +def test_invalid_T_parameter(): + """ + Test if fig.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): + fig.solar( + region="d", + projection="W0/15c", + frame="a", + T="d+d1990-02-17T04:25:00" + ) + + def test_invalid_datetime(): """ Test if fig.solar fails when it receives an invalid datetime string. From 02c77fafaad52d76ad06d6d4f35fa4f6e4643368 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Fri, 19 Mar 2021 13:52:23 +0000 Subject: [PATCH 072/103] Update pygmt/src/solar.py Co-authored-by: Dongdong Tian --- pygmt/src/solar.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/pygmt/src/solar.py b/pygmt/src/solar.py index d0b5e87123e..3a975a23909 100644 --- a/pygmt/src/solar.py +++ b/pygmt/src/solar.py @@ -85,14 +85,14 @@ def solar(self, terminator="d", terminator_datetime=None, **kwargs): f"Unrecognized solar terminator type '{terminator}'. Valid values " "are 'day_night', 'civil', 'nautical', and 'astronomical'." ) - if not terminator_datetime: - terminator_datetime = datetime.datetime.now() - try: - datetime_string = pd.to_datetime(terminator_datetime).strftime( - "%Y-%m-%dT%H:%M:%S" - ) - except ValueError as verr: - raise GMTInvalidInput("Unrecognized datetime format.") from verr - kwargs["T"] = terminator[0] + "+d" + datetime_string + kwargs["T"] = terminator[0] + if terminator_datetime: + try: + datetime_string = pd.to_datetime(terminator_datetime).strftime( + "%Y-%m-%dT%H:%M:%S" + ) + 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)) From 14265f42f2e5d389bc076b64765ce3465da530e0 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Fri, 19 Mar 2021 20:27:25 +0000 Subject: [PATCH 073/103] Apply suggestions from code review Co-authored-by: Dongdong Tian --- examples/gallery/embellishments/solar.py | 4 ++-- pygmt/src/solar.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/gallery/embellishments/solar.py b/examples/gallery/embellishments/solar.py index 322e7eba9da..3bd1edaf8e8 100644 --- a/examples/gallery/embellishments/solar.py +++ b/examples/gallery/embellishments/solar.py @@ -1,6 +1,6 @@ """ -Solar ------ +Day-night terminator line and twilights +--------------------------------------- Use :meth:`pygmt.Figure.solar` to plot the day-night terminator line, and civil, nautical, astronomical twilights. diff --git a/pygmt/src/solar.py b/pygmt/src/solar.py index 3a975a23909..35a18658f4f 100644 --- a/pygmt/src/solar.py +++ b/pygmt/src/solar.py @@ -89,7 +89,7 @@ def solar(self, terminator="d", terminator_datetime=None, **kwargs): if terminator_datetime: try: datetime_string = pd.to_datetime(terminator_datetime).strftime( - "%Y-%m-%dT%H:%M:%S" + "%Y-%m-%dT%H:%M:%S.%f" ) except ValueError as verr: raise GMTInvalidInput("Unrecognized datetime format.") from verr From e60ce748939e176fdbdb2ec55b65d72f91a0dd72 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Fri, 19 Mar 2021 20:34:28 +0000 Subject: [PATCH 074/103] formatting fix --- pygmt/src/solar.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygmt/src/solar.py b/pygmt/src/solar.py index 35a18658f4f..12eb7f07323 100644 --- a/pygmt/src/solar.py +++ b/pygmt/src/solar.py @@ -42,7 +42,7 @@ def solar(self, terminator="d", terminator_datetime=None, **kwargs): 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``] + [Default is **day_night**\ ] terminator_datetime : str or datetime object Set the UTC date and time of the displayed terminator. It can be passed as a string, using the format *YYYY-MM-DD HH:MM:SS* From f1ace0ce9b50e79b42c493d844e414c15cf59e53 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Fri, 19 Mar 2021 20:35:59 +0000 Subject: [PATCH 075/103] add TODO --- pygmt/src/solar.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pygmt/src/solar.py b/pygmt/src/solar.py index 12eb7f07323..cd91e87218d 100644 --- a/pygmt/src/solar.py +++ b/pygmt/src/solar.py @@ -64,6 +64,7 @@ def solar(self, terminator="d", terminator_datetime=None, **kwargs): {p} {t} """ + # TODO: Incorporate "-T+zTZ" kwargs = self._preprocess(**kwargs) # pylint: disable=protected-access if "T" in kwargs: From 990bc6503f24da31b972373bde6388666737f1b4 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Fri, 19 Mar 2021 20:40:52 +0000 Subject: [PATCH 076/103] update pen width --- examples/gallery/embellishments/solar.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/gallery/embellishments/solar.py b/examples/gallery/embellishments/solar.py index 3bd1edaf8e8..fdfb335630b 100644 --- a/examples/gallery/embellishments/solar.py +++ b/examples/gallery/embellishments/solar.py @@ -23,24 +23,24 @@ terminator="day_night", terminator_datetime=terminator_datetime, fill="navyblue@95", - pen="1p", + pen="0.5p", ) fig.solar( terminator="civil", terminator_datetime=terminator_datetime, fill="navyblue@85", - pen="1p", + pen="0.5p", ) fig.solar( terminator="nautical", terminator_datetime=terminator_datetime, fill="navyblue@80", - pen="1p", + pen="0.5p", ) fig.solar( terminator="astronomical", terminator_datetime=terminator_datetime, fill="navyblue@80", - pen="1p", + pen="0.5p", ) fig.show() From 2e5e15164293e740bb4457d8938b46c82a07cee7 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Fri, 19 Mar 2021 21:50:27 +0000 Subject: [PATCH 077/103] update teminator_datetime docstring --- pygmt/src/solar.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pygmt/src/solar.py b/pygmt/src/solar.py index cd91e87218d..55629b30a7c 100644 --- a/pygmt/src/solar.py +++ b/pygmt/src/solar.py @@ -45,9 +45,7 @@ def solar(self, terminator="d", terminator_datetime=None, **kwargs): [Default is **day_night**\ ] terminator_datetime : str or datetime object Set the UTC date and time of the displayed terminator. It can be - passed as a string, using the format *YYYY-MM-DD HH:MM:SS* - (e.g. 0600 on January 1, 2000 would be ``2000-01-01 06:00:00``). A - datetime object can be passed as well. + passed as a string or a datetime object. [Default is the current date and time] {R} {J} From 631b24d2a3fd7bfd94e7372730fb78833aaeb111 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Fri, 19 Mar 2021 21:50:50 +0000 Subject: [PATCH 078/103] update default time in docstring --- pygmt/src/solar.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygmt/src/solar.py b/pygmt/src/solar.py index 55629b30a7c..199d86e9394 100644 --- a/pygmt/src/solar.py +++ b/pygmt/src/solar.py @@ -46,7 +46,7 @@ def solar(self, terminator="d", terminator_datetime=None, **kwargs): terminator_datetime : str or datetime object Set the UTC date and time of the displayed terminator. It can be passed as a string or a datetime object. - [Default is the current date and time] + [Default is the current UTC date and time] {R} {J} {B} From d7afb77a5afff2f60bd2d17379fcf16242c71293 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Fri, 19 Mar 2021 21:52:22 +0000 Subject: [PATCH 079/103] run make format --- pygmt/src/solar.py | 2 +- pygmt/tests/test_solar.py | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/pygmt/src/solar.py b/pygmt/src/solar.py index 199d86e9394..f9b3e5e1d35 100644 --- a/pygmt/src/solar.py +++ b/pygmt/src/solar.py @@ -92,6 +92,6 @@ def solar(self, terminator="d", terminator_datetime=None, **kwargs): ) except ValueError as verr: raise GMTInvalidInput("Unrecognized datetime format.") from verr - kwargs["T"] += f"+d{datetime_string}" + kwargs["T"] += f"+d{datetime_string}" with Session() as lib: lib.call_module("solar", build_arg_string(kwargs)) diff --git a/pygmt/tests/test_solar.py b/pygmt/tests/test_solar.py index 30ec9710554..8d42541f3b8 100644 --- a/pygmt/tests/test_solar.py +++ b/pygmt/tests/test_solar.py @@ -83,10 +83,7 @@ def test_invalid_T_parameter(): fig = Figure() with pytest.raises(GMTInvalidInput): fig.solar( - region="d", - projection="W0/15c", - frame="a", - T="d+d1990-02-17T04:25:00" + region="d", projection="W0/15c", frame="a", T="d+d1990-02-17T04:25:00" ) From 0a3350d1f856c098538071f4e5d282f707c598c8 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Sun, 21 Mar 2021 00:40:57 +0000 Subject: [PATCH 080/103] Apply suggestions from code review Co-authored-by: Wei Ji <23487320+weiji14@users.noreply.github.com> Co-authored-by: Dongdong Tian --- pygmt/src/solar.py | 14 ++++++++------ pygmt/tests/test_solar.py | 16 ++++++++-------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/pygmt/src/solar.py b/pygmt/src/solar.py index f9b3e5e1d35..3acc2f2de12 100644 --- a/pygmt/src/solar.py +++ b/pygmt/src/solar.py @@ -12,20 +12,20 @@ @fmt_docstring @use_alias( - R="region", - J="projection", - G="fill", B="frame", - W="pen", + 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", p="sequence") +@kwargs_to_strings(R="sequence", c="sequence_comma", p="sequence") def solar(self, terminator="d", terminator_datetime=None, **kwargs): r""" Plot day-light terminators. @@ -34,6 +34,8 @@ def solar(self, terminator="d", terminator_datetime=None, **kwargs): plot the terminators for civil twilight, nautical twilight, and astronomical twilight. + Full parameter list at :gmt-docs:`solar.html` + {aliases} Parameters @@ -42,7 +44,7 @@ def solar(self, terminator="d", terminator_datetime=None, **kwargs): 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**\ ] + [Default is **day_night**] terminator_datetime : str or datetime object Set the UTC date and time of the displayed terminator. It can be passed as a string or a datetime object. diff --git a/pygmt/tests/test_solar.py b/pygmt/tests/test_solar.py index 8d42541f3b8..ec43fa30176 100644 --- a/pygmt/tests/test_solar.py +++ b/pygmt/tests/test_solar.py @@ -52,10 +52,10 @@ def test_solar_set_terminator_datetime_object(): year=1990, month=2, day=17, hour=4, minute=25, second=0 ) fig.solar( - R="d", - J="W0/15c", - B="a", - termiantor="day_night", + region="d", + projection="W0/15c", + frame="a", + terminator="day_night", terminator_datetime=terminator_datetime, ) return fig @@ -63,7 +63,7 @@ def test_solar_set_terminator_datetime_object(): def test_invalid_terminator_type(): """ - Test if fig.solar fails when it receives an invalid terminator type. + Test if solar fails when it receives an invalid terminator type. """ fig = Figure() with pytest.raises(GMTInvalidInput): @@ -77,19 +77,19 @@ def test_invalid_terminator_type(): def test_invalid_T_parameter(): """ - Test if fig.solar fails when it receives a GMT argument for 'T' instead of + 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): fig.solar( - region="d", projection="W0/15c", frame="a", T="d+d1990-02-17T04:25:00" + region="d", projection="W0/15c", frame="a", terminator="d+d1990-02-17T04:25:00" ) def test_invalid_datetime(): """ - Test if fig.solar fails when it receives an invalid datetime string. + Test if solar fails when it receives an invalid datetime string. """ fig = Figure() with pytest.raises(GMTInvalidInput): From 05f804d4763ab9fdc9583101bd5b33e323b09a5d Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Mon, 22 Mar 2021 09:55:04 +0000 Subject: [PATCH 081/103] Apply suggestions from code review Co-authored-by: Dongdong Tian --- pygmt/tests/test_solar.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pygmt/tests/test_solar.py b/pygmt/tests/test_solar.py index ec43fa30176..7b59ef8fcc6 100644 --- a/pygmt/tests/test_solar.py +++ b/pygmt/tests/test_solar.py @@ -82,8 +82,9 @@ def test_invalid_T_parameter(): """ fig = Figure() with pytest.raises(GMTInvalidInput): + # Use single-letter option 'T' for testing fig.solar( - region="d", projection="W0/15c", frame="a", terminator="d+d1990-02-17T04:25:00" + region="d", projection="W0/15c", frame="a", T="d+d1990-02-17T04:25:00" ) From 7124ad1dddfd30a04568ecd81255ab322ef52ded Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Mon, 22 Mar 2021 20:42:15 +0000 Subject: [PATCH 082/103] run make format --- pygmt/src/solar.py | 2 +- pygmt/tests/test_solar.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pygmt/src/solar.py b/pygmt/src/solar.py index 3acc2f2de12..aa621abc6f6 100644 --- a/pygmt/src/solar.py +++ b/pygmt/src/solar.py @@ -35,7 +35,7 @@ def solar(self, terminator="d", terminator_datetime=None, **kwargs): astronomical twilight. Full parameter list at :gmt-docs:`solar.html` - + {aliases} Parameters diff --git a/pygmt/tests/test_solar.py b/pygmt/tests/test_solar.py index 7b59ef8fcc6..adc2eb649a8 100644 --- a/pygmt/tests/test_solar.py +++ b/pygmt/tests/test_solar.py @@ -77,8 +77,8 @@ def test_invalid_terminator_type(): def test_invalid_T_parameter(): """ - Test if solar fails when it receives a GMT argument for 'T' instead of - the PyGMT arguments for 'terminator' and 'terminator_datetime'. + 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): From b52a12ae884b5a9d4aefb629f96d4405aeaa4495 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Tue, 23 Mar 2021 07:03:41 +0000 Subject: [PATCH 083/103] Apply suggestions from code review Co-authored-by: Dongdong Tian --- examples/gallery/embellishments/solar.py | 2 +- pygmt/src/solar.py | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/examples/gallery/embellishments/solar.py b/examples/gallery/embellishments/solar.py index fdfb335630b..72d857965c3 100644 --- a/examples/gallery/embellishments/solar.py +++ b/examples/gallery/embellishments/solar.py @@ -17,7 +17,7 @@ terminator_datetime = datetime.datetime( year=2000, month=1, day=1, hour=17, minute=0, second=0 ) -# Set the pen line to be 1p thick +# 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", diff --git a/pygmt/src/solar.py b/pygmt/src/solar.py index aa621abc6f6..fecb34fd65c 100644 --- a/pygmt/src/solar.py +++ b/pygmt/src/solar.py @@ -1,5 +1,5 @@ """ -solar - Plot day-night terminators. +solar - Plot day-night terminators and twilight. """ import datetime @@ -28,7 +28,7 @@ @kwargs_to_strings(R="sequence", c="sequence_comma", p="sequence") def solar(self, terminator="d", terminator_datetime=None, **kwargs): r""" - Plot day-light terminators. + Plot day-light terminators and twilights. This function plots the day-night terminator. Additionally, it can plot the terminators for civil twilight, nautical twilight, and @@ -45,6 +45,8 @@ def solar(self, terminator="d", terminator_datetime=None, **kwargs): **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**] + + Refer to https://en.wikipedia.org/wiki/Twilight for definitions of different twilights. terminator_datetime : str or datetime object Set the UTC date and time of the displayed terminator. It can be passed as a string or a datetime object. From 06d7d7bdf9ab2ef32a77339f6b8384d38c356786 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Tue, 23 Mar 2021 10:30:10 +0000 Subject: [PATCH 084/103] Apply suggestions from code review Co-authored-by: Wei Ji <23487320+weiji14@users.noreply.github.com> --- examples/gallery/embellishments/solar.py | 6 ++++-- pygmt/src/solar.py | 3 --- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/examples/gallery/embellishments/solar.py b/examples/gallery/embellishments/solar.py index 72d857965c3..e8cc01a9850 100644 --- a/examples/gallery/embellishments/solar.py +++ b/examples/gallery/embellishments/solar.py @@ -2,8 +2,10 @@ Day-night terminator line and twilights --------------------------------------- -Use :meth:`pygmt.Figure.solar` to plot the day-night terminator line, -and civil, nautical, astronomical 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 diff --git a/pygmt/src/solar.py b/pygmt/src/solar.py index fecb34fd65c..fbc3bff418f 100644 --- a/pygmt/src/solar.py +++ b/pygmt/src/solar.py @@ -1,9 +1,6 @@ """ solar - Plot day-night terminators and twilight. """ - -import datetime - import pandas as pd from pygmt.clib import Session from pygmt.exceptions import GMTInvalidInput From d3baca7ea6026e0e5d3f7551329c9e8887238b3a Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Tue, 23 Mar 2021 10:57:02 +0000 Subject: [PATCH 085/103] remove TODO --- pygmt/src/solar.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pygmt/src/solar.py b/pygmt/src/solar.py index fbc3bff418f..40096e23f17 100644 --- a/pygmt/src/solar.py +++ b/pygmt/src/solar.py @@ -63,7 +63,6 @@ def solar(self, terminator="d", terminator_datetime=None, **kwargs): {p} {t} """ - # TODO: Incorporate "-T+zTZ" kwargs = self._preprocess(**kwargs) # pylint: disable=protected-access if "T" in kwargs: From 8ebe008085333605764e338b0fec7913aa805e8f Mon Sep 17 00:00:00 2001 From: actions-bot <58130806+actions-bot@users.noreply.github.com> Date: Tue, 23 Mar 2021 11:04:05 +0000 Subject: [PATCH 086/103] [format-command] fixes --- pygmt/src/solar.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygmt/src/solar.py b/pygmt/src/solar.py index 40096e23f17..c9826a0aefb 100644 --- a/pygmt/src/solar.py +++ b/pygmt/src/solar.py @@ -42,7 +42,7 @@ def solar(self, terminator="d", terminator_datetime=None, **kwargs): **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**] - + Refer to https://en.wikipedia.org/wiki/Twilight for definitions of different twilights. terminator_datetime : str or datetime object Set the UTC date and time of the displayed terminator. It can be From b662a77ac21ef41fec261dc430a75825f69722d2 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Tue, 23 Mar 2021 15:50:38 +0000 Subject: [PATCH 087/103] Update pygmt/src/solar.py Co-authored-by: Dongdong Tian --- pygmt/src/solar.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pygmt/src/solar.py b/pygmt/src/solar.py index c9826a0aefb..e223322666f 100644 --- a/pygmt/src/solar.py +++ b/pygmt/src/solar.py @@ -74,7 +74,6 @@ def solar(self, terminator="d", terminator_datetime=None, **kwargs): "nautical", "civil", "astronomical", - "astro", "d", "n", "c", From 87190022f363817c26bcda491103c2364ed1fe36 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Tue, 23 Mar 2021 19:00:52 +0000 Subject: [PATCH 088/103] fix line length --- pygmt/src/solar.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pygmt/src/solar.py b/pygmt/src/solar.py index e223322666f..15c15d162b0 100644 --- a/pygmt/src/solar.py +++ b/pygmt/src/solar.py @@ -43,7 +43,8 @@ def solar(self, terminator="d", terminator_datetime=None, **kwargs): can be set with either the full name or the first letter of the name. [Default is **day_night**] - Refer to https://en.wikipedia.org/wiki/Twilight for definitions of different twilights. + Refer to https://en.wikipedia.org/wiki/Twilight for definitions of + different twilights. terminator_datetime : str or datetime object Set the UTC date and time of the displayed terminator. It can be passed as a string or a datetime object. From 886c15faa9cb9c8d7e068e6fb1e7aef3a719c4c0 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Tue, 23 Mar 2021 19:20:19 +0000 Subject: [PATCH 089/103] update tests --- ...est_solar_set_terminator_datetime.png.dvc} | 2 +- ...lar_set_terminator_datetime_string.png.dvc | 4 -- .../baseline/test_solar_terminators.png.dvc | 4 ++ pygmt/tests/test_solar.py | 51 ++++++++++++++----- 4 files changed, 44 insertions(+), 17 deletions(-) rename pygmt/tests/baseline/{test_solar_set_terminator_datetime_object.png.dvc => test_solar_set_terminator_datetime.png.dvc} (52%) delete mode 100644 pygmt/tests/baseline/test_solar_set_terminator_datetime_string.png.dvc create mode 100644 pygmt/tests/baseline/test_solar_terminators.png.dvc diff --git a/pygmt/tests/baseline/test_solar_set_terminator_datetime_object.png.dvc b/pygmt/tests/baseline/test_solar_set_terminator_datetime.png.dvc similarity index 52% rename from pygmt/tests/baseline/test_solar_set_terminator_datetime_object.png.dvc rename to pygmt/tests/baseline/test_solar_set_terminator_datetime.png.dvc index 61b633b93ca..caaab7eedce 100644 --- a/pygmt/tests/baseline/test_solar_set_terminator_datetime_object.png.dvc +++ b/pygmt/tests/baseline/test_solar_set_terminator_datetime.png.dvc @@ -1,4 +1,4 @@ outs: - md5: 0a7f4959b500b6fa3a560a6368db0f90 size: 25982 - path: test_solar_set_terminator_datetime_object.png + path: test_solar_set_terminator_datetime.png diff --git a/pygmt/tests/baseline/test_solar_set_terminator_datetime_string.png.dvc b/pygmt/tests/baseline/test_solar_set_terminator_datetime_string.png.dvc deleted file mode 100644 index a35368bbb45..00000000000 --- a/pygmt/tests/baseline/test_solar_set_terminator_datetime_string.png.dvc +++ /dev/null @@ -1,4 +0,0 @@ -outs: -- md5: 9437b5fd846526c7cac12ab327a4d78f - size: 26501 - path: test_solar_set_terminator_datetime_string.png diff --git a/pygmt/tests/baseline/test_solar_terminators.png.dvc b/pygmt/tests/baseline/test_solar_terminators.png.dvc new file mode 100644 index 00000000000..e59bf478437 --- /dev/null +++ b/pygmt/tests/baseline/test_solar_terminators.png.dvc @@ -0,0 +1,4 @@ +outs: +- md5: 3be007944a9963c1f7058af98b4183ed + size: 43698 + path: test_solar_terminators.png diff --git a/pygmt/tests/test_solar.py b/pygmt/tests/test_solar.py index adc2eb649a8..9e64252e29d 100644 --- a/pygmt/tests/test_solar.py +++ b/pygmt/tests/test_solar.py @@ -9,24 +9,22 @@ @pytest.mark.mpl_image_compare -def test_solar_set_terminator_datetime_string(): +def test_solar_default_terminator(): """ - Test passing the solar argument with the civil terminator and a datetime - string. + 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="civil", terminator_datetime="1990-02-17 04:25:00", ) return fig - @pytest.mark.mpl_image_compare -def test_solar_default_terminator(): +def test_solar_terminators(): """ Test passing the solar argument with a time string and no terminator type to confirm the default terminator type. @@ -36,21 +34,50 @@ def test_solar_default_terminator(): region="d", projection="W0/15c", frame="a", + terminator="d", + pen="1/blue", + terminator_datetime="1990-02-17 04:25:00", + ) + fig.solar( + region="d", + projection="W0/15c", + frame="a", + terminator="a", + pen="1/red", + terminator_datetime="1990-02-17 04:25:00", + ) + fig.solar( + region="d", + projection="W0/15c", + frame="a", + terminator="c", + pen="1/green", + terminator_datetime="1990-02-17 04:25:00", + ) + fig.solar( + region="d", + projection="W0/15c", + frame="a", + terminator="n", + pen="1/yellow", terminator_datetime="1990-02-17 04:25:00", ) return fig - -@pytest.mark.mpl_image_compare -def test_solar_set_terminator_datetime_object(): +@pytest.mark.mpl_image_compare(filename="test_solar_set_terminator_datetime.png") +@pytest.mark.parametrize( + "terminator_datetime", + [ + "1990-02-17 04:25:00", + 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() - terminator_datetime = datetime.datetime( - year=1990, month=2, day=17, hour=4, minute=25, second=0 - ) fig.solar( region="d", projection="W0/15c", From 5789b2637dd285605577f0bf3f93da0abd0b14b9 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Tue, 23 Mar 2021 19:22:16 +0000 Subject: [PATCH 090/103] run make format --- pygmt/tests/test_solar.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pygmt/tests/test_solar.py b/pygmt/tests/test_solar.py index 9e64252e29d..12822ba244e 100644 --- a/pygmt/tests/test_solar.py +++ b/pygmt/tests/test_solar.py @@ -23,6 +23,7 @@ def test_solar_default_terminator(): ) return fig + @pytest.mark.mpl_image_compare def test_solar_terminators(): """ @@ -64,6 +65,7 @@ def test_solar_terminators(): ) return fig + @pytest.mark.mpl_image_compare(filename="test_solar_set_terminator_datetime.png") @pytest.mark.parametrize( "terminator_datetime", From c037a96b4a934c0343fc0f643ea82d0c5d94d657 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Tue, 23 Mar 2021 19:24:56 +0000 Subject: [PATCH 091/103] style fix --- pygmt/tests/test_solar.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygmt/tests/test_solar.py b/pygmt/tests/test_solar.py index 12822ba244e..edf767be524 100644 --- a/pygmt/tests/test_solar.py +++ b/pygmt/tests/test_solar.py @@ -104,7 +104,7 @@ def test_invalid_terminator_type(): ) -def test_invalid_T_parameter(): +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'. From f497e9970e46f2f79f6fcbfada3949635e1178c9 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Tue, 23 Mar 2021 20:01:40 +0000 Subject: [PATCH 092/103] Update pygmt/tests/test_solar.py Co-authored-by: Dongdong Tian --- pygmt/tests/test_solar.py | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/pygmt/tests/test_solar.py b/pygmt/tests/test_solar.py index edf767be524..4388da4da75 100644 --- a/pygmt/tests/test_solar.py +++ b/pygmt/tests/test_solar.py @@ -31,36 +31,25 @@ def test_solar_terminators(): to confirm the default terminator type. """ fig = Figure() + fig.basemap(region="d", projection="W0/15c", frame="a") fig.solar( - region="d", - projection="W0/15c", - frame="a", terminator="d", - pen="1/blue", + pen="1p,blue", terminator_datetime="1990-02-17 04:25:00", ) fig.solar( - region="d", - projection="W0/15c", - frame="a", terminator="a", - pen="1/red", + pen="1p,red", terminator_datetime="1990-02-17 04:25:00", ) fig.solar( - region="d", - projection="W0/15c", - frame="a", terminator="c", - pen="1/green", + pen="1p,green", terminator_datetime="1990-02-17 04:25:00", ) fig.solar( - region="d", - projection="W0/15c", - frame="a", terminator="n", - pen="1/yellow", + pen="1p,yellow", terminator_datetime="1990-02-17 04:25:00", ) return fig From c4f4dbcab8371e06b2fcac2ab7bf3aab748b25ac Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Tue, 23 Mar 2021 20:03:42 +0000 Subject: [PATCH 093/103] update test_solar.py --- pygmt/tests/test_solar.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/pygmt/tests/test_solar.py b/pygmt/tests/test_solar.py index edf767be524..6393d644a87 100644 --- a/pygmt/tests/test_solar.py +++ b/pygmt/tests/test_solar.py @@ -9,7 +9,7 @@ @pytest.mark.mpl_image_compare -def test_solar_default_terminator(): +def test_solar_default_terminator(filename="test_solar_set_terminator_datetime.png"): """ Test passing the solar argument with a time string and no terminator type to confirm the default terminator type. @@ -31,36 +31,33 @@ def test_solar_terminators(): to confirm the default terminator type. """ fig = Figure() + fig.basemap(frame="a") fig.solar( region="d", projection="W0/15c", - frame="a", terminator="d", - pen="1/blue", + pen="1,blue", terminator_datetime="1990-02-17 04:25:00", ) fig.solar( region="d", projection="W0/15c", - frame="a", terminator="a", - pen="1/red", + pen="1,red", terminator_datetime="1990-02-17 04:25:00", ) fig.solar( region="d", projection="W0/15c", - frame="a", terminator="c", - pen="1/green", + pen="1,green", terminator_datetime="1990-02-17 04:25:00", ) fig.solar( region="d", projection="W0/15c", - frame="a", terminator="n", - pen="1/yellow", + pen="1,yellow", terminator_datetime="1990-02-17 04:25:00", ) return fig From 5185699ad604f8e720044731f8a16f4af8857e25 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Tue, 23 Mar 2021 20:04:24 +0000 Subject: [PATCH 094/103] update test_solar.py --- pygmt/tests/test_solar.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygmt/tests/test_solar.py b/pygmt/tests/test_solar.py index 4388da4da75..7d0c579c959 100644 --- a/pygmt/tests/test_solar.py +++ b/pygmt/tests/test_solar.py @@ -9,7 +9,7 @@ @pytest.mark.mpl_image_compare -def test_solar_default_terminator(): +def test_solar_default_terminator(filename="test_solar_set_terminator_datetime.png"): """ Test passing the solar argument with a time string and no terminator type to confirm the default terminator type. From 1159209ec28661e37ef0c1c948c933b5913c4e3c Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Tue, 23 Mar 2021 20:13:59 +0000 Subject: [PATCH 095/103] Update pygmt/tests/test_solar.py Co-authored-by: Dongdong Tian --- pygmt/tests/test_solar.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pygmt/tests/test_solar.py b/pygmt/tests/test_solar.py index 7d0c579c959..862654a1f18 100644 --- a/pygmt/tests/test_solar.py +++ b/pygmt/tests/test_solar.py @@ -8,8 +8,8 @@ from pygmt.exceptions import GMTInvalidInput -@pytest.mark.mpl_image_compare -def test_solar_default_terminator(filename="test_solar_set_terminator_datetime.png"): +@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. From 2cad81091f979986683a22e9d20a6e3ce84a8172 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Tue, 23 Mar 2021 20:14:25 +0000 Subject: [PATCH 096/103] changing order of tests in test_solar.py --- pygmt/tests/test_solar.py | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/pygmt/tests/test_solar.py b/pygmt/tests/test_solar.py index 7d0c579c959..9c8c2c1aa71 100644 --- a/pygmt/tests/test_solar.py +++ b/pygmt/tests/test_solar.py @@ -8,22 +8,6 @@ from pygmt.exceptions import GMTInvalidInput -@pytest.mark.mpl_image_compare -def test_solar_default_terminator(filename="test_solar_set_terminator_datetime.png"): - """ - 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 - - @pytest.mark.mpl_image_compare def test_solar_terminators(): """ @@ -118,3 +102,19 @@ def test_invalid_datetime(): frame="a", terminator_datetime="199A-02-17 04:25:00", ) + + +@pytest.mark.mpl_image_compare +def test_solar_default_terminator(filename="test_solar_set_terminator_datetime.png"): + """ + 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 From 2490763d7d735498ee3467b99ff47c3b359a68dd Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Tue, 23 Mar 2021 20:18:14 +0000 Subject: [PATCH 097/103] removing unnecessary dvc file --- pygmt/tests/baseline/test_solar_default_terminator.png.dvc | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 pygmt/tests/baseline/test_solar_default_terminator.png.dvc diff --git a/pygmt/tests/baseline/test_solar_default_terminator.png.dvc b/pygmt/tests/baseline/test_solar_default_terminator.png.dvc deleted file mode 100644 index 6bc9e740fff..00000000000 --- a/pygmt/tests/baseline/test_solar_default_terminator.png.dvc +++ /dev/null @@ -1,4 +0,0 @@ -outs: -- md5: 0a7f4959b500b6fa3a560a6368db0f90 - size: 25982 - path: test_solar_default_terminator.png From a231632904eef6d7337322c19b1dde6738258bb1 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Tue, 23 Mar 2021 20:23:17 +0000 Subject: [PATCH 098/103] Update pygmt/tests/test_solar.py Co-authored-by: Dongdong Tian --- pygmt/tests/test_solar.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pygmt/tests/test_solar.py b/pygmt/tests/test_solar.py index 9c8c2c1aa71..4c796bbb35d 100644 --- a/pygmt/tests/test_solar.py +++ b/pygmt/tests/test_solar.py @@ -104,8 +104,8 @@ def test_invalid_datetime(): ) -@pytest.mark.mpl_image_compare -def test_solar_default_terminator(filename="test_solar_set_terminator_datetime.png"): +@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. From 3739063d4fa1e5f38a5b2c97794cc583a97da144 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Tue, 23 Mar 2021 20:49:35 +0000 Subject: [PATCH 099/103] Apply suggestions from code review Co-authored-by: Wei Ji <23487320+weiji14@users.noreply.github.com> --- pygmt/src/solar.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/pygmt/src/solar.py b/pygmt/src/solar.py index 15c15d162b0..20bcfe6dfd7 100644 --- a/pygmt/src/solar.py +++ b/pygmt/src/solar.py @@ -25,11 +25,11 @@ @kwargs_to_strings(R="sequence", c="sequence_comma", p="sequence") def solar(self, terminator="d", terminator_datetime=None, **kwargs): r""" - Plot day-light terminators and twilights. + Plot day-light terminators or twilights. - This function plots the day-night terminator. Additionally, it can - plot the terminators for civil twilight, nautical twilight, and - astronomical twilight. + 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` @@ -43,11 +43,11 @@ def solar(self, terminator="d", terminator_datetime=None, **kwargs): can be set with either the full name or the first letter of the name. [Default is **day_night**] - Refer to https://en.wikipedia.org/wiki/Twilight for definitions of - different twilights. + 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 a datetime object. + passed as a string or Python datetime object. [Default is the current UTC date and time] {R} {J} @@ -72,12 +72,12 @@ def solar(self, terminator="d", terminator_datetime=None, **kwargs): ) if terminator not in [ "day_night", - "nautical", "civil", + "nautical", "astronomical", "d", - "n", "c", + "n", "a", ]: raise GMTInvalidInput( From 6d96015466783791c034da08bb939999afe1a615 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Tue, 23 Mar 2021 21:35:22 +0000 Subject: [PATCH 100/103] update dvc --- pygmt/tests/baseline/test_solar_terminators.png.dvc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pygmt/tests/baseline/test_solar_terminators.png.dvc b/pygmt/tests/baseline/test_solar_terminators.png.dvc index e59bf478437..c7f3b4f2516 100644 --- a/pygmt/tests/baseline/test_solar_terminators.png.dvc +++ b/pygmt/tests/baseline/test_solar_terminators.png.dvc @@ -1,4 +1,4 @@ outs: -- md5: 3be007944a9963c1f7058af98b4183ed - size: 43698 +- md5: 54c92bea64e0fc76c62601cb6131f22e + size: 44160 path: test_solar_terminators.png From ca28e155bfb7a565f1ebf081ffd8a9770636c4c3 Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Thu, 25 Mar 2021 13:07:38 +1300 Subject: [PATCH 101/103] Add a 'T' for the datetime to avoid space in filename --- pygmt/tests/test_solar.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygmt/tests/test_solar.py b/pygmt/tests/test_solar.py index 4c796bbb35d..c28a3a121c3 100644 --- a/pygmt/tests/test_solar.py +++ b/pygmt/tests/test_solar.py @@ -43,7 +43,7 @@ def test_solar_terminators(): @pytest.mark.parametrize( "terminator_datetime", [ - "1990-02-17 04:25:00", + "1990-02-17T04:25:00", datetime.datetime(year=1990, month=2, day=17, hour=4, minute=25, second=0), ], ) From c222ce98574314953d1f2b58d6b9909d00fea937 Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Thu, 25 Mar 2021 13:51:51 +1300 Subject: [PATCH 102/103] Set a pytest.param id to avoid spaces and colons in filename --- pygmt/tests/test_solar.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygmt/tests/test_solar.py b/pygmt/tests/test_solar.py index c28a3a121c3..b60b37d7dbb 100644 --- a/pygmt/tests/test_solar.py +++ b/pygmt/tests/test_solar.py @@ -43,7 +43,7 @@ def test_solar_terminators(): @pytest.mark.parametrize( "terminator_datetime", [ - "1990-02-17T04:25:00", + pytest.param("1990-02-17 04:25:00", id="terminator_datetime0"), datetime.datetime(year=1990, month=2, day=17, hour=4, minute=25, second=0), ], ) From bab37d3eae088eb0511aedf4e55af9d2457f1697 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Wed, 24 Mar 2021 21:49:28 -0400 Subject: [PATCH 103/103] Update pytest.param id --- pygmt/tests/test_solar.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygmt/tests/test_solar.py b/pygmt/tests/test_solar.py index b60b37d7dbb..d487dc30fc3 100644 --- a/pygmt/tests/test_solar.py +++ b/pygmt/tests/test_solar.py @@ -43,7 +43,7 @@ def test_solar_terminators(): @pytest.mark.parametrize( "terminator_datetime", [ - pytest.param("1990-02-17 04:25:00", id="terminator_datetime0"), + 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), ], )