From 8818d5392f75bbeaf3a2d4eeaf33a7f2fbd66380 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Tue, 9 Sep 2025 20:34:13 +0800 Subject: [PATCH 1/8] Figure.image: Migrate the 'monochrome' parameter --- pygmt/src/image.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pygmt/src/image.py b/pygmt/src/image.py index f6fdfa71950..78d45a36580 100644 --- a/pygmt/src/image.py +++ b/pygmt/src/image.py @@ -12,13 +12,14 @@ @fmt_docstring -@use_alias(D="position", G="bitcolor", M="monochrome", R="region", p="perspective") +@use_alias(D="position", G="bitcolor", R="region", p="perspective") @kwargs_to_strings(R="sequence", p="sequence") def image( self, imagefile: PathLike, projection=None, box: Box | bool = False, + monochrome: bool = False, verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"] | bool = False, panel: int | tuple[int, int] | bool = False, @@ -36,6 +37,7 @@ def image( {aliases} - F = box - J = projection + - M = monochrome - V = verbose - c = panel - t = transparency @@ -68,7 +70,7 @@ def image( to make those pixels transparent. Can be repeated with different settings. Alternatively, for color images you can select a single *color* that should be made transparent instead (**+t**). - monochrome : bool + monochrome Convert color image to monochrome grayshades using the (television) YIQ-transformation. {verbose} @@ -80,6 +82,7 @@ def image( aliasdict = AliasSystem( F=Alias(box, name="box"), + M=Alias(monochrome, name="monochrome"), ).add_common( J=projection, V=verbose, From 2b99e41a06e29ab2dfc9d8093b85e706b4c3b019 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Mon, 15 Sep 2025 21:12:19 +0800 Subject: [PATCH 2/8] Update docstrings --- pygmt/src/image.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/pygmt/src/image.py b/pygmt/src/image.py index 78d45a36580..20aa1d18efa 100644 --- a/pygmt/src/image.py +++ b/pygmt/src/image.py @@ -31,6 +31,18 @@ def image( Reads an Encapsulated PostScript file or a raster image file and plots it on a map. + Reads an Encapsulated PostScript (EPS) file or a raster image file and plots it. The + image can be scaled arbitrarily, and 1-bit raster images can be + + - inverted, i.e., black pixels (on) becomes white (off) and vice versa + - colorized, by assigning different foreground and background colors + - made transparent where one of back- or foreground is painted only. + + As an option, the user may choose to convert colored raster images to grayscale + using TV's YIQ-transformation. For raster files, the user can select which color to + be made transparent. The user may also choose to replicate the image which, when + preceded by appropriate clip paths, may allow larger custom-designed fill patterns + to be implemented. Full GMT docs at :gmt-docs:`image.html`. @@ -44,12 +56,10 @@ def image( Parameters ---------- - imagefile : str - This must be an Encapsulated PostScript (EPS) file or a raster - image. An EPS file must contain an appropriate BoundingBox. A - raster file can have a depth of 1, 8, 24, or 32 bits and is read - via GDAL. **Note**: If GDAL was not configured during GMT installation - then only EPS files are supported. + imagefile + An Encapsulated PostScript (EPS) file or a raster image file. An EPS file must + contain an appropriate BoundingBox. A raster file can have a depth of 1, 8, 24, + or 32 bits and is read via GDAL. {projection} {region} position : str From e7ae9334137e54b3e030f45679bc5678713e504e Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Wed, 17 Sep 2025 12:38:21 +0800 Subject: [PATCH 3/8] Update pygmt/src/image.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- pygmt/src/image.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygmt/src/image.py b/pygmt/src/image.py index 20aa1d18efa..37419acc83a 100644 --- a/pygmt/src/image.py +++ b/pygmt/src/image.py @@ -32,7 +32,7 @@ def image( Reads an Encapsulated PostScript file or a raster image file and plots it on a map. Reads an Encapsulated PostScript (EPS) file or a raster image file and plots it. The - image can be scaled arbitrarily, and 1-bit raster images can be + image can be scaled arbitrarily, and 1-bit raster images can be: - inverted, i.e., black pixels (on) becomes white (off) and vice versa - colorized, by assigning different foreground and background colors From 99e2b75ff3311d9298239d8917975248eb34c1a9 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Thu, 18 Sep 2025 19:57:04 +0800 Subject: [PATCH 4/8] Fix copy&paste errors 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/image.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/pygmt/src/image.py b/pygmt/src/image.py index 37419acc83a..7924e5f7fdc 100644 --- a/pygmt/src/image.py +++ b/pygmt/src/image.py @@ -29,8 +29,6 @@ def image( r""" Plot raster or EPS images. - Reads an Encapsulated PostScript file or a raster image file and plots - it on a map. Reads an Encapsulated PostScript (EPS) file or a raster image file and plots it. The image can be scaled arbitrarily, and 1-bit raster images can be: From 35c1a69c0a70787a7849666323208e6ad567f709 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Sat, 20 Sep 2025 13:41:19 +0800 Subject: [PATCH 5/8] Update grdimage and tilemap --- pygmt/src/grdimage.py | 15 +++++++++------ pygmt/src/tilemap.py | 7 ++++--- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/pygmt/src/grdimage.py b/pygmt/src/grdimage.py index 376091976f1..be6d10bc6f4 100644 --- a/pygmt/src/grdimage.py +++ b/pygmt/src/grdimage.py @@ -6,7 +6,7 @@ import xarray as xr from pygmt._typing import PathLike -from pygmt.alias import AliasSystem +from pygmt.alias import Alias, AliasSystem from pygmt.clib import Session from pygmt.helpers import build_arg_list, fmt_docstring, kwargs_to_strings, use_alias @@ -21,7 +21,6 @@ E="dpi", G="bitcolor", I="shading", - M="monochrome", N="no_clip", Q="nan_transparent", R="region", @@ -34,6 +33,7 @@ def grdimage( self, grid: PathLike | xr.DataArray, + monochrome: bool = False, projection=None, verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"] | bool = False, @@ -76,6 +76,7 @@ def grdimage( {aliases} - J = projection + - M = monochrome - V = verbose - c = panel - t = transparency @@ -127,9 +128,9 @@ def grdimage( input data represent an *image* then an *intensfile* or constant *intensity* must be provided. {projection} - monochrome : bool - Force conversion to monochrome image using the (television) YIQ - transformation. Cannot be used with ``nan_transparent``. + monochrome + Force conversion to monochrome image using the (television) YIQ transformation. + Cannot be used with ``nan_transparent``. no_clip : bool Do **not** clip the image at the frame boundaries (only relevant for non-rectangular maps) [Default is ``False``]. @@ -172,7 +173,9 @@ def grdimage( ) raise NotImplementedError(msg) - aliasdict = AliasSystem().add_common( + aliasdict = AliasSystem( + M=Alias(monochrome, name="monochrome"), + ).add_common( J=projection, V=verbose, c=panel, diff --git a/pygmt/src/tilemap.py b/pygmt/src/tilemap.py index f1b0b549221..5d013c2e13c 100644 --- a/pygmt/src/tilemap.py +++ b/pygmt/src/tilemap.py @@ -4,7 +4,7 @@ from typing import Literal -from pygmt.alias import AliasSystem +from pygmt.alias import Alias, AliasSystem from pygmt.clib import Session from pygmt.datasets.tile_map import load_tile_map from pygmt.enums import GridType @@ -21,7 +21,6 @@ B="frame", E="dpi", I="shading", - M="monochrome", N="no_clip", Q="nan_transparent", # R="region", @@ -37,6 +36,7 @@ def tilemap( # noqa: PLR0913 wait: int = 0, max_retries: int = 2, zoom_adjust: int | None = None, + monochrome: bool = False, projection=None, verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"] | bool = False, @@ -59,6 +59,7 @@ def tilemap( # noqa: PLR0913 {aliases} - J = projection + - M = monochrome - V = verbose - c = panel - t = transparency @@ -131,7 +132,7 @@ def tilemap( # noqa: PLR0913 if kwargs.get("N") in {None, False}: kwargs["R"] = "/".join(str(coordinate) for coordinate in region) - aliasdict = AliasSystem().add_common( + aliasdict = AliasSystem(M=Alias(monochrome, name="monochrome")).add_common( J=projection, V=verbose, c=panel, From 299820b60af7036a8da62c7d6ae820bdfb9fa8a8 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Sun, 21 Sep 2025 00:14:44 +0800 Subject: [PATCH 6/8] Apply suggestions from code review 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/image.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pygmt/src/image.py b/pygmt/src/image.py index 7924e5f7fdc..e366df96e0a 100644 --- a/pygmt/src/image.py +++ b/pygmt/src/image.py @@ -29,16 +29,16 @@ def image( r""" Plot raster or EPS images. - Reads an Encapsulated PostScript (EPS) file or a raster image file and plots it. The + Reads Encapsulated PostScript (EPS) or raster image files and plots them. The image can be scaled arbitrarily, and 1-bit raster images can be: - inverted, i.e., black pixels (on) becomes white (off) and vice versa - colorized, by assigning different foreground and background colors - - made transparent where one of back- or foreground is painted only. + - made transparent where either the back- or foreground is painted. As an option, the user may choose to convert colored raster images to grayscale - using TV's YIQ-transformation. For raster files, the user can select which color to - be made transparent. The user may also choose to replicate the image which, when + using TV's YIQ-transformation. For raster files, the user can select which color is + made transparent. The user may also choose to replicate the image which, when preceded by appropriate clip paths, may allow larger custom-designed fill patterns to be implemented. From 7730b80ec699cf920e64454982eb4b121cc58681 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Sun, 21 Sep 2025 00:16:06 +0800 Subject: [PATCH 7/8] Reformat tilemap --- pygmt/src/tilemap.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pygmt/src/tilemap.py b/pygmt/src/tilemap.py index 5d013c2e13c..95cab7a8c50 100644 --- a/pygmt/src/tilemap.py +++ b/pygmt/src/tilemap.py @@ -132,7 +132,9 @@ def tilemap( # noqa: PLR0913 if kwargs.get("N") in {None, False}: kwargs["R"] = "/".join(str(coordinate) for coordinate in region) - aliasdict = AliasSystem(M=Alias(monochrome, name="monochrome")).add_common( + aliasdict = AliasSystem( + M=Alias(monochrome, name="monochrome"), + ).add_common( J=projection, V=verbose, c=panel, From bff057f060ad8c0722bc4ec80ccedb0338cfd117 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Thu, 25 Sep 2025 17:45:01 +0800 Subject: [PATCH 8/8] Update pygmt/src/image.py [skip ci] 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/image.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pygmt/src/image.py b/pygmt/src/image.py index e366df96e0a..db35c1af5c7 100644 --- a/pygmt/src/image.py +++ b/pygmt/src/image.py @@ -32,8 +32,8 @@ def image( Reads Encapsulated PostScript (EPS) or raster image files and plots them. The image can be scaled arbitrarily, and 1-bit raster images can be: - - inverted, i.e., black pixels (on) becomes white (off) and vice versa - - colorized, by assigning different foreground and background colors + - inverted, i.e., black pixels (on) becomes white (off) and vice versa. + - colorized, by assigning different foreground and background colors. - made transparent where either the back- or foreground is painted. As an option, the user may choose to convert colored raster images to grayscale