Skip to content

Commit a318d4b

Browse files
committed
Merge branch 'main' into alias-system
2 parents 1f41808 + 56541e8 commit a318d4b

31 files changed

+179
-76
lines changed

.github/workflows/ci_tests.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ jobs:
142142
pytest-doctestplus
143143
pytest-mpl
144144
pytest-rerunfailures
145-
pytest-xdist
146145
147146
# Download cached remote files (artifacts) from GitHub
148147
- name: Download remote data from GitHub
@@ -165,7 +164,7 @@ jobs:
165164

166165
# Run the regular tests
167166
- name: Run tests
168-
run: make test PYTEST_EXTRA="-r P -n auto --reruns 2"
167+
run: make test PYTEST_EXTRA="-r P --reruns 2"
169168

170169
# Upload diff images on test failure
171170
- name: Upload diff images if any test fails

.github/workflows/ci_tests_dev.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ jobs:
153153
--extra-index https://pypi.anaconda.org/scientific-python-nightly-wheels/simple \
154154
numpy pandas xarray netCDF4 packaging \
155155
build contextily dvc geopandas ipython pyarrow rioxarray \
156-
pytest pytest-cov pytest-doctestplus pytest-mpl pytest-rerunfailures pytest-xdist\
156+
pytest pytest-cov pytest-doctestplus pytest-mpl pytest-rerunfailures \
157157
sphinx-gallery
158158
159159
# Show installed pkg information for postmortem diagnostic
@@ -181,7 +181,7 @@ jobs:
181181

182182
# Run the tests
183183
- name: Test with pytest
184-
run: make test PYTEST_EXTRA="-r P -n auto --reruns 2"
184+
run: make test PYTEST_EXTRA="-r P --reruns 2"
185185
env:
186186
GMT_LIBRARY_PATH: ${{ runner.temp }}/gmt-install-dir/lib
187187

doc/Makefile

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,5 @@ server:
5555
clean:
5656
rm -rf $(BUILDDIR)
5757
rm -rf api/generated
58-
rm -rf intro
59-
rm -rf tutorials
60-
rm -rf gallery
61-
rm -rf projections
58+
rm -rf intro tutorials gallery projections
59+
rm -rf sg_execution_times.rst

examples/tutorials/basics/polygons.py

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
"""
2+
Plotting polygons
3+
=================
4+
5+
Plotting polygons is handled by the :meth:`pygmt.Figure.plot` method.
6+
7+
This tutorial focuses on input data given as NumPy arrays. Besides NumPy arrays,
8+
array-like objects are supported. Here, a polygon is a closed shape defined by a series
9+
of data points with x and y coordinates, connected by line segments, with the start and
10+
end points being identical. For plotting a :class:`geopandas.GeoDataFrame` object with
11+
polygon geometries, e.g., to create a choropleth map, see the gallery example
12+
:doc:`Choropleth map </gallery/maps/choropleth_map>`.
13+
"""
14+
15+
# %%
16+
import numpy as np
17+
import pygmt
18+
19+
# %%
20+
# Plot polygons
21+
# -------------
22+
#
23+
# Set up sample data points as NumPy arrays for the x and y values.
24+
25+
x = np.array([-2, 1, 3, 0, -4, -2])
26+
y = np.array([-3, -1, 1, 3, 2, -3])
27+
28+
# %%
29+
# Create a Cartesian plot via the :meth:`pygmt.Figure.basemap` method. Pass arrays to
30+
# the ``x`` and ``y`` parameters of the :meth:`pygmt.Figure.plot` method. Without
31+
# further adjustments, lines are drawn between the data points. By default, the lines
32+
# are 0.25-points thick, black, and solid. In this example, the data points are chosen
33+
# to make the lines form a polygon.
34+
35+
fig = pygmt.Figure()
36+
fig.basemap(region=[-5, 5, -5, 5], projection="X5c", frame=True)
37+
fig.plot(x=x, y=y)
38+
fig.show()
39+
40+
# %%
41+
# The ``pen`` parameter can be used to adjust the lines or outline of the polygon. The
42+
# argument passed to ``pen`` is one string with the comma-separated optional values
43+
# *width*,\ *color*,\ *style*.
44+
45+
fig = pygmt.Figure()
46+
fig.basemap(region=[-5, 5, -5, 5], projection="X5c", frame=True)
47+
# Use a 2-points thick, darkred, dashed outline
48+
fig.plot(x=x, y=y, pen="2p,darkred,dashed")
49+
fig.show()
50+
51+
# %%
52+
# Use the ``fill`` parameter to fill the polygon with a color or
53+
# :doc:`pattern </techref/patterns>`. Note, that there are no lines drawn between the
54+
# data points by default if ``fill`` is used. Use the ``pen`` parameter to add an
55+
# outline around the polygon.
56+
57+
fig = pygmt.Figure()
58+
fig.basemap(region=[-5, 5, -5, 5], projection="X5c", frame=True)
59+
# Fill the polygon with color "orange"
60+
fig.plot(x=x, y=y, fill="orange")
61+
fig.show()
62+
63+
64+
# %%
65+
# Close polygons
66+
# --------------
67+
#
68+
# Set up sample data points as NumPy array for the x and y values. Now, the data points
69+
# do not form a polygon.
70+
71+
x = np.array([-2, 1, 3, 0, -4])
72+
y = np.array([-3, -1, 1, 3, 2])
73+
74+
# %%
75+
# The ``close`` parameter can be used to force the polygon to be closed.
76+
77+
fig = pygmt.Figure()
78+
fig.basemap(region=[-5, 5, -5, 5], projection="X5c", frame=True)
79+
fig.plot(x=x, y=y, pen=True)
80+
81+
fig.shift_origin(xshift="w+1c")
82+
83+
fig.basemap(region=[-5, 5, -5, 5], projection="X5c", frame=True)
84+
fig.plot(x=x, y=y, pen=True, close=True)
85+
fig.show()
86+
87+
# %%
88+
# When using the ``fill`` parameter, the polygon is automatically closed.
89+
90+
fig = pygmt.Figure()
91+
fig.basemap(region=[-5, 5, -5, 5], projection="X5c", frame=True)
92+
fig.plot(x=x, y=y, pen=True)
93+
94+
fig.shift_origin(xshift="w+1c")
95+
96+
fig.basemap(region=[-5, 5, -5, 5], projection="X5c", frame=True)
97+
fig.plot(x=x, y=y, pen=True, fill="orange")
98+
fig.show()
99+
100+
# sphinx_gallery_thumbnail_number = 5

pygmt/helpers/utils.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import time
1313
import webbrowser
1414
from collections.abc import Iterable, Mapping, Sequence
15+
from pathlib import Path
1516
from typing import Any, Literal
1617

1718
import xarray as xr
@@ -187,7 +188,8 @@ def _check_encoding(argstr: str) -> Encoding:
187188
charset["ZapfDingbats"].values()
188189
)
189190
for encoding in ["ISOLatin1+"] + [f"ISO-8859-{i}" for i in range(1, 17) if i != 12]:
190-
if all(c in (set(charset[encoding].values()) | adobe_chars) for c in argstr):
191+
chars = set(charset[encoding].values()) | adobe_chars
192+
if all(c in chars for c in argstr):
191193
return encoding # type: ignore[return-value]
192194
# Return the "ISOLatin1+" encoding if the string contains characters from multiple
193195
# charset encodings or contains characters that are not in any charset encoding.
@@ -580,7 +582,7 @@ def launch_external_viewer(fname: str, waiting: float = 0):
580582
case "win32": # Windows
581583
os.startfile(fname) # type:ignore[attr-defined] # noqa: S606
582584
case _: # Fall back to the browser if can't recognize the operating system.
583-
webbrowser.open_new_tab(f"file://{fname}")
585+
webbrowser.open_new_tab(f"file://{Path(fname).resolve()}")
584586
if waiting > 0:
585587
# Preview images will be deleted when a GMT modern-mode session ends, but the
586588
# external viewer program may take a few seconds to open the images.

pygmt/src/binstats.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def binstats(
8080
Set the value assigned to empty nodes [Default is NaN].
8181
normalize : bool
8282
Normalize the resulting grid values by the area represented by the
83-
search *radius* [no normalization].
83+
search *radius* [Default is no normalization].
8484
search_radius : float or str
8585
Set the *search_radius* that determines which data points are
8686
considered close to a node. Append the distance unit.
@@ -106,7 +106,7 @@ def binstats(
106106
Return type depends on whether the ``outgrid`` parameter is set:
107107
108108
- :class:`xarray.DataArray` if ``outgrid`` is not set
109-
- None if ``outgrid`` is set (grid output will be stored in file set by
109+
- ``None`` if ``outgrid`` is set (grid output will be stored in the file set by
110110
``outgrid``)
111111
"""
112112
alias = AliasSystem(

pygmt/src/blockm.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ def blockmedian(
244244
ret
245245
Return type depends on ``outfile`` and ``output_type``:
246246
247-
- ``None`` if ``outfile`` is set (output will be stored in file set by
247+
- ``None`` if ``outfile`` is set (output will be stored in the file set by
248248
``outfile``)
249249
- :class:`pandas.DataFrame` or :class:`numpy.ndarray` if ``outfile`` is not set
250250
(depends on ``output_type``)
@@ -342,7 +342,7 @@ def blockmode(
342342
ret
343343
Return type depends on ``outfile`` and ``output_type``:
344344
345-
- ``None`` if ``outfile`` is set (output will be stored in file set by
345+
- ``None`` if ``outfile`` is set (output will be stored in the file set by
346346
``outfile``)
347347
- :class:`pandas.DataFrame` or :class:`numpy.ndarray` if ``outfile`` is not set
348348
(depends on ``output_type``)

pygmt/src/dimfilter.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,12 @@ def dimfilter(grid, outgrid: str | None = None, **kwargs) -> xr.DataArray | None
8888
spacing : str or list
8989
*x_inc* [and optionally *y_inc*] is the output increment. Append
9090
**m** to indicate minutes, or **c** to indicate seconds. If the new
91-
*x_inc*, *y_inc* are NOT integer multiples of the old ones (in the
91+
*x_inc*, *y_inc* are **not** integer multiples of the old ones (in the
9292
input data), filtering will be considerably slower. [Default is same
93-
as input.]
93+
as the input.]
9494
region : str or list
9595
[*xmin*, *xmax*, *ymin*, *ymax*].
96-
Define the region of the output points [Default is same as input].
96+
Define the region of the output points [Default is the same as the input].
9797
{verbose}
9898
9999
Returns
@@ -102,7 +102,7 @@ def dimfilter(grid, outgrid: str | None = None, **kwargs) -> xr.DataArray | None
102102
Return type depends on whether the ``outgrid`` parameter is set:
103103
104104
- :class:`xarray.DataArray` if ``outgrid`` is not set
105-
- None if ``outgrid`` is set (grid output will be stored in file set by
105+
- ``None`` if ``outgrid`` is set (grid output will be stored in the file set by
106106
``outgrid``)
107107
108108
Example

pygmt/src/filter1d.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ def filter1d(
105105
ret
106106
Return type depends on ``outfile`` and ``output_type``:
107107
108-
- None if ``outfile`` is set (output will be stored in file set by ``outfile``)
108+
- ``None`` if ``outfile`` is set (output will be stored in the file set by
109+
``outfile``)
109110
- :class:`pandas.DataFrame` or :class:`numpy.ndarray` if ``outfile`` is not set
110111
(depends on ``output_type``)
111112
"""

pygmt/src/grd2xyz.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ def grd2xyz(
121121
ret
122122
Return type depends on ``outfile`` and ``output_type``:
123123
124-
- None if ``outfile`` is set (output will be stored in file set by ``outfile``)
124+
- ``None`` if ``outfile`` is set (output will be stored in the file set by
125+
``outfile``)
125126
- :class:`pandas.DataFrame` or :class:`numpy.ndarray` if ``outfile`` is not set
126127
(depends on ``output_type``)
127128
@@ -133,7 +134,7 @@ def grd2xyz(
133134
>>> grid = pygmt.datasets.load_earth_relief(
134135
... resolution="30m", region=[10, 30, 15, 25]
135136
... )
136-
>>> # Create a pandas DataFrame with the xyz data from an input grid
137+
>>> # Create a pandas.DataFrame with the xyz data from an input grid
137138
>>> xyz_dataframe = pygmt.grd2xyz(grid=grid, output_type="pandas")
138139
>>> xyz_dataframe.head(n=2)
139140
lon lat z

0 commit comments

Comments
 (0)