Skip to content

Commit 2909662

Browse files
committed
Merge branch 'master' into stringio_input
2 parents d79a0c8 + 4856d64 commit 2909662

21 files changed

+224
-83
lines changed

.github/workflows/cache_data.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
# Install GMT
2424
- name: Install GMT
2525
shell: bash -l {0}
26-
run: conda install -c conda-forge gmt=6.1.0
26+
run: conda install -c conda-forge gmt=6.1.1
2727

2828
# Download remote files
2929
- name: Download remote data

.github/workflows/ci_tests.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,11 @@ jobs:
6565

6666
# Setup Miniconda
6767
- name: Setup Miniconda
68-
uses: goanpeca/setup-miniconda@v1.6.0
68+
uses: conda-incubator/setup-miniconda@v1.7.0
6969
with:
7070
python-version: ${{ matrix.python-version }}
7171
channels: conda-forge
72+
miniconda-version: "latest"
7273

7374
# Install GMT and other required dependencies from conda-forge
7475
- name: Install GMT and required dependencies
@@ -77,7 +78,7 @@ jobs:
7778
requirements_file=full-conda-requirements.txt
7879
cat requirements.txt requirements-dev.txt > $requirements_file
7980
cat << EOF >> $requirements_file
80-
gmt=6.1.0
81+
gmt=6.1.1
8182
make
8283
codecov
8384
EOF

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ env:
2626
# The file with the listed requirements to be installed by conda
2727
- CONDA_REQUIREMENTS=requirements.txt
2828
- CONDA_REQUIREMENTS_DEV=requirements-dev.txt
29-
- CONDA_INSTALL_EXTRA="codecov twine gmt=6.1.0"
29+
- CONDA_INSTALL_EXTRA="codecov twine gmt=6.1.1"
3030
# These variables control which actions are performed in a build
3131
- DEPLOY=false
3232

CONTRIBUTING.md

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,38 @@ Leave a comment in the PR and we'll help you out.
310310

311311
### Testing plots
312312

313-
We use the [pytest-mpl](https://github.com/matplotlib/pytest-mpl) plug-in to test plot
314-
generating code.
313+
Writing an image-based test is only slightly more difficult than a simple test.
314+
The main consideration is that you must specify the "baseline" or reference
315+
image, and compare it with a "generated" or test image. This is handled using
316+
the *decorator* functions `@check_figures_equal` and
317+
`@pytest.mark.mpl_image_compare` whose usage are further described below.
318+
319+
#### Using check_figures_equal
320+
321+
This approach draws the same figure using two different methods (the reference
322+
method and the tested method), and checks that both of them are the same.
323+
It takes two `pygmt.Figure` objects ('fig_ref' and 'fig_test'), generates a png
324+
image, and checks for the Root Mean Square (RMS) error between the two.
325+
Here's an example:
326+
327+
```python
328+
@check_figures_equal()
329+
def test_my_plotting_case(fig_ref, fig_test):
330+
"Test that my plotting function works"
331+
fig_ref.grdimage("@earth_relief_01d_g", projection="W120/15c", cmap="geo")
332+
fig_test.grdimage(grid, projection="W120/15c", cmap="geo")
333+
```
334+
335+
Note: This is the recommended way to test plots whenever possible, such as when
336+
we want to compare a reference GMT plot created from NetCDF files with one
337+
generated by PyGMT that passes through several layers of virtualfile machinery.
338+
Using this method will help save space in the git repository by not having to
339+
store baseline images as with the other method below.
340+
341+
#### Using mpl_image_compare
342+
343+
This method uses the [pytest-mpl](https://github.com/matplotlib/pytest-mpl)
344+
plug-in to test plot generating code.
315345
Every time the tests are run, `pytest-mpl` compares the generated plots with known
316346
correct ones stored in `pygmt/tests/baseline`.
317347
If your test created a `pygmt.Figure` object, you can test it by adding a *decorator* and

Makefile

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,7 @@ test:
2929
@echo ""
3030
@cd $(TESTDIR); python -c "import $(PROJECT); $(PROJECT).show_versions()"
3131
@echo ""
32-
# There are two steps to the test here because `test_grdimage_over_dateline`
33-
# passes only when it runs before the other tests.
34-
# See also https://github.com/GenericMappingTools/pygmt/pull/476
35-
cd $(TESTDIR); pytest -m runfirst $(PYTEST_ARGS) $(PROJECT)
36-
cd $(TESTDIR); pytest -m 'not runfirst' $(PYTEST_ARGS) $(PROJECT)
32+
cd $(TESTDIR); pytest $(PYTEST_ARGS) $(PROJECT)
3733
cp $(TESTDIR)/coverage.xml .
3834
cp -r $(TESTDIR)/htmlcov .
3935
rm -r $(TESTDIR)

doc/install.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Which GMT?
3131
PyGMT requires Generic Mapping Tools (GMT) version 6 as a minimum, which is the latest
3232
released version that can be found at
3333
the `GMT official site <https://www.generic-mapping-tools.org>`__.
34-
We need the latest GMT (>=6.1.0) since there are many changes being made to GMT itself in
34+
We need the latest GMT (>=6.1.1) since there are many changes being made to GMT itself in
3535
response to the development of PyGMT, mainly the new
3636
`modern execution mode <https://docs.generic-mapping-tools.org/latest/cookbook/introduction.html#modern-and-classic-mode>`__.
3737

environment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ channels:
55
dependencies:
66
- python=3.7
77
- pip
8-
- gmt=6.1.0
8+
- gmt=6.1.1
99
- numpy
1010
- pandas
1111
- xarray

examples/gallery/grid/track_sampling.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
fig = pygmt.Figure()
2626
# Plot the earth relief grid on Cylindrical Stereographic projection, masking land areas
27-
fig.basemap(region="d", frame=True, projection="Cyl_stere/8i")
27+
fig.basemap(region="g", frame=True, projection="Cyl_stere/150/-20/8i")
2828
fig.grdimage(grid=grid, cmap="gray")
2929
fig.coast(land="#666666")
3030
# Plot using circles (c) of 0.15cm, the sampled bathymetry points

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"scripts": {
33
"build:miniconda": "curl -o ~/miniconda.sh https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh && bash ~/miniconda.sh -b -p $HOME/miniconda",
4-
"build:pygmt": "conda env create -f environment.yml && source activate pygmt && conda install -c conda-forge -y gmt==6.1.0 && make install",
4+
"build:pygmt": "conda env create -f environment.yml && source activate pygmt && conda install -c conda-forge -y gmt==6.1.1 && make install",
55
"build:docs": "source activate pygmt && cd doc && make all && mv _build/html ../public",
66
"build": "export PATH=$HOME/miniconda/bin:$PATH && npm run build:miniconda && npm run build:pygmt && npm run build:docs"
77
}

pygmt/base_plotting.py

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
Does not define any special non-GMT methods (savefig, show, etc).
44
"""
55
import contextlib
6-
import csv
7-
86
import numpy as np
97
import pandas as pd
108

@@ -993,28 +991,16 @@ def text(
993991
if position is not None and isinstance(position, str):
994992
kwargs["F"] += f'+c{position}+t"{text}"'
995993

996-
with GMTTempFile(suffix=".txt") as tmpfile:
997-
with Session() as lib:
998-
fname = textfiles if kind == "file" else ""
999-
if kind == "vectors":
1000-
if position is not None:
1001-
fname = ""
1002-
else:
1003-
pd.DataFrame.from_dict(
1004-
{
1005-
"x": np.atleast_1d(x),
1006-
"y": np.atleast_1d(y),
1007-
"text": np.atleast_1d(text),
1008-
}
1009-
).to_csv(
1010-
tmpfile.name,
1011-
sep="\t",
1012-
header=False,
1013-
index=False,
1014-
quoting=csv.QUOTE_NONE,
1015-
)
1016-
fname = tmpfile.name
1017-
994+
with Session() as lib:
995+
file_context = dummy_context(textfiles) if kind == "file" else ""
996+
if kind == "vectors":
997+
if position is not None:
998+
file_context = dummy_context("")
999+
else:
1000+
file_context = lib.virtualfile_from_vectors(
1001+
np.atleast_1d(x), np.atleast_1d(y), np.atleast_1d(text)
1002+
)
1003+
with file_context as fname:
10181004
arg_str = " ".join([fname, build_arg_string(kwargs)])
10191005
lib.call_module("text", arg_str)
10201006

0 commit comments

Comments
 (0)