diff --git a/pygmt/src/psconvert.py b/pygmt/src/psconvert.py index 383376909ab..cd562c10887 100644 --- a/pygmt/src/psconvert.py +++ b/pygmt/src/psconvert.py @@ -2,28 +2,25 @@ psconvert - Convert [E]PS file(s) to other formats using Ghostscript. """ +from collections.abc import Sequence from pathlib import Path +from pygmt.alias import Alias, AliasSystem from pygmt.clib import Session from pygmt.exceptions import GMTValueError -from pygmt.helpers import build_arg_list, fmt_docstring, kwargs_to_strings, use_alias +from pygmt.helpers import build_arg_list, fmt_docstring, use_alias @fmt_docstring -@use_alias( - A="crop", - C="gs_option", - E="dpi", - F="prefix", - G="gs_path", - I="resize", - N="bb_style", - T="fmt", - Q="anti_aliasing", - V="verbose", -) -@kwargs_to_strings() -def psconvert(self, **kwargs): +@use_alias(A="crop", I="resize", N="bb_style", T="fmt", Q="anti_aliasing", V="verbose") +def psconvert( + self, + prefix: str | None = None, + dpi: int | None = None, + gs_option: str | Sequence[str] | None = None, + gs_path: str | None = None, + **kwargs, +): r""" Convert [E]PS file(s) to other formats using Ghostscript. @@ -37,6 +34,10 @@ def psconvert(self, **kwargs): Full GMT docs at :gmt-docs:`psconvert.html`. {aliases} + - C = gs_option + - E = dpi + - F = prefix + - G = gs_path Parameters ---------- @@ -49,19 +50,20 @@ def psconvert(self, **kwargs): creating very small images where the difference of one pixel might matter. If ``verbose`` is used we also report the dimensions of the final illustration. - gs_path : str + gs_path Full path to the Ghostscript executable. - gs_option : str - Specify a single, custom option that will be passed on to - Ghostscript as is. - dpi : int - Set raster resolution in dpi. Default is 720 for PDF, 300 for - others. - prefix : str - Force the output file name. By default output names are constructed - using the input names as base, which are appended with an - appropriate extension. Use this option to provide a different name, - but without extension. Extension is still determined automatically. + gs_option + Specify one or a list of custom options that will be passed on to Ghostscript + as is. + dpi + Set raster resolution in dpi [Default is 720 for PDF, 300 for others]. **Note**: + Ghostscript limits the final width and height pixel dimensions of a raster file + to be less than or equal to 65536. + prefix + Force the output file name. By default output names are constructed using the + input names as base, which are appended with an appropriate extension. Use this + parameter to provide a different name, but without extension. Extension is still + determined automatically. resize : str [**+m**\ *margins*][**+s**\ [**m**]\ *width*\ [/\ *height*]][**+S**\ *scale*]. @@ -113,7 +115,6 @@ def psconvert(self, **kwargs): if kwargs.get("A") is None: kwargs["A"] = "" - prefix = kwargs.get("F") if prefix in {"", None, False, True}: raise GMTValueError( prefix, @@ -122,10 +123,17 @@ def psconvert(self, **kwargs): ) # Check if the parent directory exists - prefix_path = Path(prefix).parent + prefix_path = Path(prefix).parent # type: ignore[arg-type] if not prefix_path.exists(): - msg = f"No such directory: '{prefix_path}', please create it first." + msg = f"No such directory: {prefix_path!r}, please create it first." raise FileNotFoundError(msg) + aliasdict = AliasSystem( + C=Alias(gs_option, name="gs_option"), + E=Alias(dpi, name="dpi"), + F=Alias(prefix, name="prefix"), + G=Alias(gs_path, name="gs_path"), + ).merge(kwargs) + with Session() as lib: - lib.call_module(module="psconvert", args=build_arg_list(kwargs)) + lib.call_module(module="psconvert", args=build_arg_list(aliasdict))