Skip to content

Change test_makecpt.py to use colorbar instead of grdimage #1748

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Feb 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pygmt/tests/baseline/test_makecpt_categorical.png.dvc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
outs:
- md5: 9a8c5ecec5f8962987635057f577a01c
size: 6029
- md5: 49bc3322fbb073626fe5f61b92a473fb
size: 4692
path: test_makecpt_categorical.png
4 changes: 2 additions & 2 deletions pygmt/tests/baseline/test_makecpt_continuous.png.dvc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
outs:
- md5: 9a18c81caa92725aa9de5c2dd7d74e46
size: 75856
- md5: 28eec5c7c5b76ba0659c20dd60ed8108
size: 2861
path: test_makecpt_continuous.png
4 changes: 2 additions & 2 deletions pygmt/tests/baseline/test_makecpt_cyclic.png.dvc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
outs:
- md5: 4ad410eb2843b3b47818121563c79254
size: 4628
- md5: 150c12b8d8959561bdf36d380dc23d10
size: 3747
path: test_makecpt_cyclic.png
4 changes: 4 additions & 0 deletions pygmt/tests/baseline/test_makecpt_plot_colorbar.png.dvc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
outs:
- md5: 989d9bf57f716f4721f14992bf39a359
size: 2529
path: test_makecpt_plot_colorbar.png
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
outs:
- md5: dbf2dcd2c30bdb921599a09b0ba258f8
size: 3386
path: test_makecpt_plot_colorbar_scaled_with_series.png
4 changes: 0 additions & 4 deletions pygmt/tests/baseline/test_makecpt_plot_grid.png.dvc

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion pygmt/tests/baseline/test_makecpt_plot_points.png.dvc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
outs:
- md5: b28ff0dad316d0b6a860b8af7e402a56
- md5: 7944289487b6efd9755a931e371d8022
size: 26601
path: test_makecpt_plot_points.png
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
outs:
- md5: 6a5ca01aebcc23b00dc884fcd9c927d8
size: 141567
- md5: 412c8de63e53ebac483e0fd42b79cad6
size: 3620
path: test_makecpt_reverse_color_and_zsign.png
4 changes: 2 additions & 2 deletions pygmt/tests/baseline/test_makecpt_reverse_color_only.png.dvc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
outs:
- md5: 5ad9b6aab72e45be8a1adc20f9e1c0e9
size: 71377
- md5: 3d919f2db5ae1302f38a0178224074c6
size: 3964
path: test_makecpt_reverse_color_only.png
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
outs:
- md5: 26f3d0d95a68799ddd4eb8a130bc1445
size: 97790
- md5: 8235d66d1606fce2380f7fd034e874c1
size: 2907
path: test_makecpt_truncated_zlow_zhigh.png
71 changes: 31 additions & 40 deletions pygmt/tests/test_makecpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import numpy as np
import pytest
from pygmt import Figure, makecpt
from pygmt.datasets import load_earth_relief
from pygmt.exceptions import GMTInvalidInput
from pygmt.helpers import GMTTempFile

Expand All @@ -22,24 +21,16 @@ def fixture_points():
return np.loadtxt(POINTS_DATA)


@pytest.fixture(scope="module", name="region")
def fixture_region():
@pytest.fixture(scope="module", name="position")
def fixture_position():
"""
The data region.
Return a standard position argument for the colorbar.
"""
return [10, 70, -5, 10]


@pytest.fixture(scope="module", name="grid")
def fixture_grid():
"""
Load the grid data from the sample earth_relief file.
"""
return load_earth_relief(registration="gridline")
return "x0c/0c+w10c+h"


@pytest.mark.mpl_image_compare
def test_makecpt_plot_points(points, region):
def test_makecpt_plot_points(points):
"""
Use static color palette table to change color of points.
"""
Expand All @@ -49,33 +40,33 @@ def test_makecpt_plot_points(points, region):
x=points[:, 0],
y=points[:, 1],
color=points[:, 2],
region=region,
region=[10, 70, -5, 10],
style="c1c",
cmap=True,
)
return fig


@pytest.mark.mpl_image_compare
def test_makecpt_plot_grid(grid):
def test_makecpt_plot_colorbar(position):
"""
Use static color palette table to change color of grid.
Use static color palette table to plot a colorbar.
"""
fig = Figure()
makecpt(cmap="relief")
fig.grdimage(grid, projection="W0/10c")
fig.colorbar(cmap=True, frame=True, position=position)
return fig


@pytest.mark.mpl_image_compare
def test_makecpt_plot_grid_scaled_with_series(grid):
def test_makecpt_plot_colorbar_scaled_with_series(position):
"""
Use static color palette table scaled to a min/max series to change color
of grid.
Use static color palette table scaled to a min/max series and plot it on a
colorbar.
"""
fig = Figure()
makecpt(cmap="oleron", series=[-4500, 4500])
fig.grdimage(grid, projection="W0/10c")
makecpt(cmap="oleron", series=[0, 1000])
fig.colorbar(cmap=True, frame=True, position=position)
return fig


Expand Down Expand Up @@ -105,70 +96,70 @@ def test_makecpt_invalid_output():


@pytest.mark.mpl_image_compare
def test_makecpt_truncated_zlow_zhigh(grid):
def test_makecpt_truncated_zlow_zhigh(position):
"""
Use static color palette table that is truncated to z-low and z-high.
"""
fig = Figure()
makecpt(cmap="rainbow", truncate=[0.15, 0.85], series=[-4500, 4500])
fig.grdimage(grid, projection="W0/10c")
makecpt(cmap="rainbow", truncate=[0.15, 0.85], series=[0, 1000])
fig.colorbar(cmap=True, frame=True, position=position)
return fig


@pytest.mark.mpl_image_compare
def test_makecpt_reverse_color_only(grid):
def test_makecpt_reverse_color_only(position):
"""
Use static color palette table with its colors reversed.
"""
fig = Figure()
makecpt(cmap="earth", reverse=True)
fig.grdimage(grid, projection="W0/10c")
makecpt(cmap="earth", reverse=True, series=[0, 1000])
fig.colorbar(cmap=True, frame=True, position=position)
return fig


@pytest.mark.mpl_image_compare
def test_makecpt_reverse_color_and_zsign(grid):
def test_makecpt_reverse_color_and_zsign(position):
"""
Use static color palette table with both its colors and z-value sign
reversed.
"""
fig = Figure()
makecpt(cmap="earth", reverse="cz")
fig.grdimage(grid, projection="W0/10c")
makecpt(cmap="earth", reverse="cz", series=[0, 1000])
fig.colorbar(cmap=True, frame=True, position=position)
return fig


@pytest.mark.mpl_image_compare
def test_makecpt_continuous(grid):
def test_makecpt_continuous(position):
"""
Use static color palette table that is continuous from blue to white and
scaled from -4500 to 4500m.
scaled from 0 to 1000 m.
"""
fig = Figure()
makecpt(cmap="blue,white", continuous=True, series=[-4500, 4500])
fig.grdimage(grid, projection="W0/10c")
makecpt(cmap="blue,white", continuous=True, series=[0, 1000])
fig.colorbar(cmap=True, frame=True, position=position)
return fig


@pytest.mark.mpl_image_compare
def test_makecpt_categorical(region):
def test_makecpt_categorical(position):
"""
Use static color palette table that is categorical.
"""
fig = Figure()
makecpt(cmap="categorical", categorical=True)
fig.colorbar(cmap=True, region=region, frame=True, position="JBC")
fig.colorbar(cmap=True, frame=True, position=position)
return fig


@pytest.mark.mpl_image_compare
def test_makecpt_cyclic(region):
def test_makecpt_cyclic(position):
"""
Use static color palette table that is cyclic.
"""
fig = Figure()
makecpt(cmap="cork", cyclic=True)
fig.colorbar(cmap=True, region=region, frame=True, position="JBC")
fig.colorbar(cmap=True, frame=True, position=position)
return fig


Expand Down