Skip to content

Commit 6e70e8b

Browse files
michaelgrundweiji14seisman
authored
Figure.psconvert: Add new aliases and deprecate parameter "icc_gray" (remove in v0.8.0) (#1673)
Co-authored-by: Wei Ji <23487320+weiji14@users.noreply.github.com> Co-authored-by: Dongdong Tian <seisman.info@gmail.com>
1 parent 7fc0dc9 commit 6e70e8b

File tree

2 files changed

+61
-7
lines changed

2 files changed

+61
-7
lines changed

pygmt/figure.py

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"""
44
import base64
55
import os
6+
import warnings
67
from tempfile import TemporaryDirectory
78

89
try:
@@ -129,13 +130,14 @@ def region(self):
129130
C="gs_option",
130131
E="dpi",
131132
F="prefix",
132-
I="icc_gray",
133+
I="resize",
134+
N="bb_style",
133135
T="fmt",
134136
Q="anti_aliasing",
135137
V="verbose",
136138
)
137139
@kwargs_to_strings()
138-
def psconvert(self, **kwargs):
140+
def psconvert(self, icc_gray=False, **kwargs):
139141
r"""
140142
Convert [E]PS file(s) to other formats.
141143
@@ -153,9 +155,14 @@ def psconvert(self, **kwargs):
153155
Parameters
154156
----------
155157
crop : str or bool
156-
Adjust the BoundingBox and HiResBoundingBox to the minimum required
157-
by the image content. Append ``u`` to first remove any GMT-produced
158-
time-stamps. Default is True.
158+
Adjust the BoundingBox and HiResBoundingBox to the minimum
159+
required by the image content. Default is True. Append **+u** to
160+
first remove any GMT-produced time-stamps. Append **+r** to
161+
*round* the HighResBoundingBox instead of using the ``ceil``
162+
function. This is going against Adobe Law but can be useful when
163+
creating very small images where the difference of one pixel
164+
might matter. If ``verbose`` is used we also report the
165+
dimensions of the final illustration.
159166
gs_option : str
160167
Specify a single, custom option that will be passed on to
161168
GhostScript as is.
@@ -167,8 +174,33 @@ def psconvert(self, **kwargs):
167174
using the input names as base, which are appended with an
168175
appropriate extension. Use this option to provide a different name,
169176
but without extension. Extension is still determined automatically.
170-
icc_gray : bool
171-
Enforce gray-shades by using ICC profiles.
177+
resize : str
178+
[**+m**\ *margins*][**+s**\ [**m**]\ *width*\
179+
[/\ *height*]][**+S**\ *scale*] ].
180+
Adjust the BoundingBox and HiResBoundingBox by scaling and/or
181+
adding margins. Append **+m** to specify extra margins to extend
182+
the bounding box. Give either one (uniform), two (x and y) or four
183+
(individual sides) margins; append unit [Default is set by
184+
:term:`PROJ_LENGTH_UNIT`]. Append **+s**\ *width* to resize the
185+
output image to exactly *width* units. The default unit is set
186+
by :term:`PROJ_LENGTH_UNIT` but you can append a new unit and/or
187+
impose different width and height (**Note**: This may change the
188+
image aspect ratio). What happens here is that Ghostscript will do
189+
the re-interpolation work and the final image will retain the DPI
190+
resolution set by ``dpi``. Append **+sm** to set a maximum size
191+
and the new *width* is only imposed if the original figure width
192+
exceeds it. Append /\ *height* to also impose a maximum height in
193+
addition to the width. Alternatively, append **+S**\ *scale* to
194+
scale the image by a constant factor.
195+
bb_style : str
196+
Set optional BoundingBox fill color, fading, or draw the outline
197+
of the BoundingBox. Append **+f**\ *fade* to fade the entire plot
198+
towards black (100%) [no fading, 0]. Append **+g** \*paint* to
199+
paint the BoundingBox behind the illustration and append **+p**\
200+
[*pen*] to draw the BoundingBox outline (append a pen or accept
201+
the default pen of 0.25p,black). Note: If both **+g** and **+f**
202+
are used then we use paint as the fade color instead of black.
203+
Append **+i** to enforce gray-shades by using ICC profiles.
172204
anti_aliasing : str
173205
[**g**\|\ **p**\|\ **t**\][**1**\|\ **2**\|\ **4**].
174206
Set the anti-aliasing options for **g**\ raphics or **t**\ ext.
@@ -192,6 +224,17 @@ def psconvert(self, **kwargs):
192224
# Default cropping the figure to True
193225
if "A" not in kwargs:
194226
kwargs["A"] = ""
227+
228+
if icc_gray:
229+
msg = (
230+
"The 'icc_gray' parameter has been deprecated since v0.6.0"
231+
" and will be removed in v0.8.0."
232+
)
233+
warnings.warn(msg, category=FutureWarning, stacklevel=2)
234+
if "N" not in kwargs:
235+
kwargs["N"] = "+i"
236+
else:
237+
kwargs["N"] += "+i"
195238
# allow for spaces in figure name
196239
kwargs["F"] = f'"{kwargs.get("F")}"' if kwargs.get("F") else None
197240
with Session() as lib:

pygmt/tests/test_figure.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,3 +251,14 @@ def test_figure_set_display_invalid():
251251
"""
252252
with pytest.raises(GMTInvalidInput):
253253
set_display(method="invalid")
254+
255+
256+
def test_figure_icc_gray():
257+
"""
258+
Check if icc_gray parameter works correctly if used.
259+
"""
260+
fig = Figure()
261+
fig.basemap(region=[0, 1, 0, 1], projection="X1c/1c", frame=True)
262+
with pytest.warns(expected_warning=FutureWarning) as record:
263+
fig.psconvert(icc_gray=True, prefix="Test")
264+
assert len(record) == 1 # check that only one warning was raised

0 commit comments

Comments
 (0)