From f8d1edaafa2dda9129183fe0784572c57c182221 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Mon, 15 Jan 2024 18:55:40 +0800 Subject: [PATCH 1/6] Figure.timestamp: Deprecate parameter 'justification' to 'justify' (remove in v0.13.0) --- examples/gallery/embellishments/timestamp.py | 11 +++++------ pygmt/src/timestamp.py | 15 ++++++++------- pygmt/tests/test_timestamp.py | 6 +++--- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/examples/gallery/embellishments/timestamp.py b/examples/gallery/embellishments/timestamp.py index 9cda32b19f4..bbf429cafbe 100644 --- a/examples/gallery/embellishments/timestamp.py +++ b/examples/gallery/embellishments/timestamp.py @@ -2,11 +2,10 @@ Timestamp ========= -The :meth:`pygmt.Figure.timestamp` method can draw the GMT timestamp logo on -the plot. The timestamp will always be shown relative to the bottom-left corner -of the plot. By default, the ``offset`` and ``justification`` parameters are -set to ``("-54p", "-54p")`` (x, y directions) and ``"BL"`` (bottom-left), -respectively. +The :meth:`pygmt.Figure.timestamp` method can draw the GMT timestamp logo on the plot. +The timestamp will always be shown relative to the bottom-left corner of the plot. By +default, the ``offset`` and ``justify`` parameters are set to ``("-54p", "-54p")`` +(x, y directions) and ``"BL"`` (bottom-left), respectively. """ # %% @@ -30,7 +29,7 @@ fig.coast(region="d", projection="H10c", land="black", water="cornsilk", frame="afg") fig.timestamp( label="Powered by PyGMT", - justification="TL", + jusitfy="TL", font="Times-Bold", timefmt="%Y-%m-%dT%H:%M:%S%z", ) diff --git a/pygmt/src/timestamp.py b/pygmt/src/timestamp.py index 96c816a67d9..91fea438169 100644 --- a/pygmt/src/timestamp.py +++ b/pygmt/src/timestamp.py @@ -8,7 +8,7 @@ from packaging.version import Version from pygmt.clib import Session, __gmt_version__ -from pygmt.helpers import build_arg_string, kwargs_to_strings +from pygmt.helpers import build_arg_string, deprecate_parameter, kwargs_to_strings if TYPE_CHECKING: from collections.abc import Sequence @@ -17,16 +17,17 @@ __doctest_skip__ = ["timestamp"] +@deprecate_parameter("justification", "justify", "v0.11.0", remove_version="v0.13.0") @kwargs_to_strings(offset="sequence") def timestamp( self, text: str | None = None, label: str | None = None, - justification: str = "BL", + justify: str = "BL", offset: float | str | Sequence[float | str] = ("-54p", "-54p"), font: str = "Helvetica,black", timefmt: str = "%Y %b %d %H:%M:%S", -) -> None: +): r""" Plot the GMT timestamp logo. @@ -44,12 +45,12 @@ def timestamp( The text must be no longer than 64 characters. label The text string shown after the GMT timestamp logo. - justification + justify Justification of the timestamp box relative to the plot's bottom-left corner - (i.e., the plot origin). The *justification* is a two-character code that is a + (i.e., the plot origin). The *justify* is a two-character code that is a combination of a horizontal (**L**\ (eft), **C**\ (enter), or **R**\ (ight)) and a vertical (**T**\ (op), **M**\ (iddle), or **B**\ (ottom)) code. For example, - ``justification="TL"`` means choosing the **T**\ op **L**\ eft point of the + ``justify="TL"`` means choosing the **T**\ op **L**\ eft point of the timestamp as the anchor point. offset *offset* or (*offset_x*, *offset_y*). @@ -86,7 +87,7 @@ def timestamp( kwdict: dict = {"T": True, "U": ""} if label is not None: kwdict["U"] += f"{label}" - kwdict["U"] += f"+j{justification}" + kwdict["U"] += f"+j{justify}" if Version(__gmt_version__) <= Version("6.4.0") and "/" not in str(offset): # Giving a single offset doesn't work in GMT <= 6.4.0. diff --git a/pygmt/tests/test_timestamp.py b/pygmt/tests/test_timestamp.py index a22d68ce800..3a5e9506574 100644 --- a/pygmt/tests/test_timestamp.py +++ b/pygmt/tests/test_timestamp.py @@ -35,16 +35,16 @@ def test_timestamp_label(faketime): @pytest.mark.mpl_image_compare -def test_timestamp_justification(): +def test_timestamp_justify(): """ - Check if the "justification" parameter works. + Check if the "justify" parameter works. Only a subset of justification codes are tested to avoid overlapping timestamps. """ fig = Figure() fig.basemap(projection="X10c/5c", region=[0, 10, 0, 5], frame=0) for just in ["BL", "BR", "TL", "TR"]: - fig.timestamp(justification=just, timefmt=just) + fig.timestamp(justify=just, timefmt=just) return fig From 0e677edc998632ea6815e549dd2580691b49e7a7 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Mon, 15 Jan 2024 19:02:53 +0800 Subject: [PATCH 2/6] Rename the dvc file --- ...amp_justification.png.dvc => test_timestamp_justify.png.dvc} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename pygmt/tests/baseline/{test_timestamp_justification.png.dvc => test_timestamp_justify.png.dvc} (63%) diff --git a/pygmt/tests/baseline/test_timestamp_justification.png.dvc b/pygmt/tests/baseline/test_timestamp_justify.png.dvc similarity index 63% rename from pygmt/tests/baseline/test_timestamp_justification.png.dvc rename to pygmt/tests/baseline/test_timestamp_justify.png.dvc index d7fc8addad1..1dfddb31f0f 100644 --- a/pygmt/tests/baseline/test_timestamp_justification.png.dvc +++ b/pygmt/tests/baseline/test_timestamp_justify.png.dvc @@ -1,5 +1,5 @@ outs: - md5: fcf1511052ece6b0e2ed97b6ae5af772 size: 8828 - path: test_timestamp_justification.png + path: test_timestamp_justify.png hash: md5 From 09b9f18bca372bd948236c26f037bd42a2088f99 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Mon, 15 Jan 2024 19:12:53 +0800 Subject: [PATCH 3/6] Fix a typo --- examples/gallery/embellishments/timestamp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/gallery/embellishments/timestamp.py b/examples/gallery/embellishments/timestamp.py index bbf429cafbe..6ca64e67545 100644 --- a/examples/gallery/embellishments/timestamp.py +++ b/examples/gallery/embellishments/timestamp.py @@ -29,7 +29,7 @@ fig.coast(region="d", projection="H10c", land="black", water="cornsilk", frame="afg") fig.timestamp( label="Powered by PyGMT", - jusitfy="TL", + justify="TL", font="Times-Bold", timefmt="%Y-%m-%dT%H:%M:%S%z", ) From c6ad92139dd9c851d9afe738c06962c699427e0e Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Mon, 15 Jan 2024 20:05:33 +0800 Subject: [PATCH 4/6] Rewrap to 88 characters --- examples/gallery/embellishments/timestamp.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/examples/gallery/embellishments/timestamp.py b/examples/gallery/embellishments/timestamp.py index 6ca64e67545..41fa95a67db 100644 --- a/examples/gallery/embellishments/timestamp.py +++ b/examples/gallery/embellishments/timestamp.py @@ -19,9 +19,8 @@ fig.show() # %% -# Additionally, a custom label can be added via the ``label`` parameter. The -# font can be defined via the ``font`` parameter and the timestamp string -# format via ``timefmt``. +# Additionally, a custom label can be added via the ``label`` parameter. The font can be +# defined via the ``font`` parameter and the timestamp string format via ``timefmt``. os.environ["TZ"] = "Pacific/Honolulu" # optionally set the time zone From 3e582cb9e2894d5eb3058da8ae9b040da6781797 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Wed, 17 Jan 2024 10:45:50 +0800 Subject: [PATCH 5/6] Update pygmt/src/timestamp.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Yvonne Fröhlich <94163266+yvonnefroehlich@users.noreply.github.com> --- pygmt/src/timestamp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygmt/src/timestamp.py b/pygmt/src/timestamp.py index 91fea438169..8b91168684d 100644 --- a/pygmt/src/timestamp.py +++ b/pygmt/src/timestamp.py @@ -47,7 +47,7 @@ def timestamp( The text string shown after the GMT timestamp logo. justify Justification of the timestamp box relative to the plot's bottom-left corner - (i.e., the plot origin). The *justify* is a two-character code that is a + (i.e., the plot origin). Give a two-character code that is a combination of a horizontal (**L**\ (eft), **C**\ (enter), or **R**\ (ight)) and a vertical (**T**\ (op), **M**\ (iddle), or **B**\ (ottom)) code. For example, ``justify="TL"`` means choosing the **T**\ op **L**\ eft point of the From eed500a60ae0944f39dde94de4655f9daf86874a Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Wed, 17 Jan 2024 12:22:47 +0800 Subject: [PATCH 6/6] Rewrap --- pygmt/src/timestamp.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pygmt/src/timestamp.py b/pygmt/src/timestamp.py index 8b91168684d..84937a08a2f 100644 --- a/pygmt/src/timestamp.py +++ b/pygmt/src/timestamp.py @@ -47,11 +47,11 @@ def timestamp( The text string shown after the GMT timestamp logo. justify Justification of the timestamp box relative to the plot's bottom-left corner - (i.e., the plot origin). Give a two-character code that is a - combination of a horizontal (**L**\ (eft), **C**\ (enter), or **R**\ (ight)) and - a vertical (**T**\ (op), **M**\ (iddle), or **B**\ (ottom)) code. For example, - ``justify="TL"`` means choosing the **T**\ op **L**\ eft point of the - timestamp as the anchor point. + (i.e., the plot origin). Give a two-character code that is a combination of a + horizontal (**L**\ (eft), **C**\ (enter), or **R**\ (ight)) and a vertical + (**T**\ (op), **M**\ (iddle), or **B**\ (ottom)) code. For example, + ``justify="TL"`` means choosing the **T**\ op **L**\ eft point of the timestamp + as the anchor point. offset *offset* or (*offset_x*, *offset_y*). Offset the anchor point of the timestamp box by *offset_x* and *offset_y*. If a