2
2
psconvert - Convert [E]PS file(s) to other formats using Ghostscript.
3
3
"""
4
4
5
+ from collections .abc import Sequence
5
6
from pathlib import Path
6
7
8
+ from pygmt .alias import Alias , AliasSystem
7
9
from pygmt .clib import Session
8
10
from pygmt .exceptions import GMTValueError
9
- from pygmt .helpers import build_arg_list , fmt_docstring , kwargs_to_strings , use_alias
11
+ from pygmt .helpers import build_arg_list , fmt_docstring , use_alias
10
12
11
13
12
14
@fmt_docstring
13
- @use_alias (
14
- A = "crop" ,
15
- C = "gs_option" ,
16
- E = "dpi" ,
17
- F = "prefix" ,
18
- G = "gs_path" ,
19
- I = "resize" ,
20
- N = "bb_style" ,
21
- T = "fmt" ,
22
- Q = "anti_aliasing" ,
23
- V = "verbose" ,
24
- )
25
- @kwargs_to_strings ()
26
- def psconvert (self , ** kwargs ):
15
+ @use_alias (A = "crop" , I = "resize" , N = "bb_style" , T = "fmt" , Q = "anti_aliasing" , V = "verbose" )
16
+ def psconvert (
17
+ self ,
18
+ prefix : str | None = None ,
19
+ dpi : int | None = None ,
20
+ gs_option : str | Sequence [str ] | None = None ,
21
+ gs_path : str | None = None ,
22
+ ** kwargs ,
23
+ ):
27
24
r"""
28
25
Convert [E]PS file(s) to other formats using Ghostscript.
29
26
@@ -37,6 +34,10 @@ def psconvert(self, **kwargs):
37
34
Full GMT docs at :gmt-docs:`psconvert.html`.
38
35
39
36
{aliases}
37
+ - C = gs_option
38
+ - E = dpi
39
+ - F = prefix
40
+ - G = gs_path
40
41
41
42
Parameters
42
43
----------
@@ -49,19 +50,20 @@ def psconvert(self, **kwargs):
49
50
creating very small images where the difference of one pixel
50
51
might matter. If ``verbose`` is used we also report the
51
52
dimensions of the final illustration.
52
- gs_path : str
53
+ gs_path
53
54
Full path to the Ghostscript executable.
54
- gs_option : str
55
- Specify a single, custom option that will be passed on to
56
- Ghostscript as is.
57
- dpi : int
58
- Set raster resolution in dpi. Default is 720 for PDF, 300 for
59
- others.
60
- prefix : str
61
- Force the output file name. By default output names are constructed
62
- using the input names as base, which are appended with an
63
- appropriate extension. Use this option to provide a different name,
64
- but without extension. Extension is still determined automatically.
55
+ gs_option
56
+ Specify one or a list of custom options that will be passed on to Ghostscript
57
+ as is.
58
+ dpi
59
+ Set raster resolution in dpi [Default is 720 for PDF, 300 for others]. **Note**:
60
+ Ghostscript limits the final width and height pixel dimensions of a raster file
61
+ to be less than or equal to 65536.
62
+ prefix
63
+ Force the output file name. By default output names are constructed using the
64
+ input names as base, which are appended with an appropriate extension. Use this
65
+ parameter to provide a different name, but without extension. Extension is still
66
+ determined automatically.
65
67
resize : str
66
68
[**+m**\ *margins*][**+s**\ [**m**]\ *width*\
67
69
[/\ *height*]][**+S**\ *scale*].
@@ -113,7 +115,6 @@ def psconvert(self, **kwargs):
113
115
if kwargs .get ("A" ) is None :
114
116
kwargs ["A" ] = ""
115
117
116
- prefix = kwargs .get ("F" )
117
118
if prefix in {"" , None , False , True }:
118
119
raise GMTValueError (
119
120
prefix ,
@@ -122,10 +123,17 @@ def psconvert(self, **kwargs):
122
123
)
123
124
124
125
# Check if the parent directory exists
125
- prefix_path = Path (prefix ).parent
126
+ prefix_path = Path (prefix ).parent # type: ignore[arg-type]
126
127
if not prefix_path .exists ():
127
- msg = f"No such directory: ' { prefix_path } ' , please create it first."
128
+ msg = f"No such directory: { prefix_path !r } , please create it first."
128
129
raise FileNotFoundError (msg )
129
130
131
+ aliasdict = AliasSystem (
132
+ C = Alias (gs_option , name = "gs_option" ),
133
+ E = Alias (dpi , name = "dpi" ),
134
+ F = Alias (prefix , name = "prefix" ),
135
+ G = Alias (gs_path , name = "gs_path" ),
136
+ ).merge (kwargs )
137
+
130
138
with Session () as lib :
131
- lib .call_module (module = "psconvert" , args = build_arg_list (kwargs ))
139
+ lib .call_module (module = "psconvert" , args = build_arg_list (aliasdict ))
0 commit comments