Skip to content

Commit fc710f9

Browse files
authored
Merge branch 'main' into static-earth-relief/grdvolume
2 parents 77a78d8 + 17105a3 commit fc710f9

File tree

7 files changed

+97
-55
lines changed

7 files changed

+97
-55
lines changed

examples/gallery/histograms/blockm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import pygmt
1111

1212
# Load sample data
13-
data = pygmt.datasets.load_japan_quakes()
13+
data = pygmt.datasets.load_sample_data(name="japan_quakes")
1414
# Select only needed columns
1515
data = data[["longitude", "latitude", "depth_km"]]
1616

examples/gallery/histograms/rose.py

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

1111
# Load sample compilation of fracture lengths and azimuth as
1212
# hypothetically digitized from geological maps
13-
data = pygmt.datasets.load_fractures_compilation()
13+
data = pygmt.datasets.load_sample_data(name="fractures")
1414

1515
fig = pygmt.Figure()
1616

examples/gallery/images/track_sampling.py

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

1919
# Load sample grid and point datasets
2020
grid = pygmt.datasets.load_earth_relief()
21-
points = pygmt.datasets.load_ocean_ridge_points()
21+
points = pygmt.datasets.load_sample_data(name="ocean_ridge_points")
2222
# Sample the bathymetry along the world's ocean ridges at specified track
2323
# points
2424
track = pygmt.grdtrack(points=points, grid=grid, newcolname="bathymetry")

examples/tutorials/basics/plot.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414

1515
###############################################################################
1616
# For example, let's load the sample dataset of tsunami generating earthquakes
17-
# around Japan (:func:`pygmt.datasets.load_japan_quakes`). The data is loaded
18-
# as a :class:`pandas.DataFrame`.
17+
# around Japan (:func:`pygmt.datasets.load_sample_data(name="japan_quakes")`).
18+
# The data is loaded as a :class:`pandas.DataFrame`.
1919

20-
data = pygmt.datasets.load_japan_quakes()
20+
data = pygmt.datasets.load_sample_data(name="japan_quakes")
2121

2222
# Set the region for the plot to be slightly larger than the data bounds.
2323
region = [

pygmt/src/blockm.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,18 @@ def blockmean(data=None, x=None, y=None, z=None, outfile=None, **kwargs):
147147
is not set.
148148
- None if ``outfile`` is set (filtered output will be stored in file
149149
set by ``outfile``).
150+
151+
Example
152+
-------
153+
>>> import pygmt # doctest: +SKIP
154+
>>> # Load a table of ship observations of bathymetry off Baja California
155+
>>> data = pygmt.datasets.load_sample_data(
156+
... name="bathymetry"
157+
... ) # doctest: +SKIP
158+
>>> # Calculate block mean values within 5 by 5 minute bins
159+
>>> data_bmean = pygmt.blockmean(
160+
... data=data, region=[245, 255, 20, 30], spacing="5m"
161+
... ) # doctest: +SKIP
150162
"""
151163
return _blockm(
152164
block_method="blockmean", data=data, x=x, y=y, z=z, outfile=outfile, **kwargs
@@ -225,6 +237,18 @@ def blockmedian(data=None, x=None, y=None, z=None, outfile=None, **kwargs):
225237
is not set.
226238
- None if ``outfile`` is set (filtered output will be stored in file
227239
set by ``outfile``).
240+
241+
Example
242+
-------
243+
>>> import pygmt # doctest: +SKIP
244+
>>> # Load a table of ship observations of bathymetry off Baja California
245+
>>> data = pygmt.datasets.load_sample_data(
246+
... name="bathymetry"
247+
... ) # doctest: +SKIP
248+
>>> # Calculate block median values within 5 by 5 minute bins
249+
>>> data_bmedian = pygmt.blockmedian(
250+
... data=data, region=[245, 255, 20, 30], spacing="5m"
251+
... ) # doctest: +SKIP
228252
"""
229253
return _blockm(
230254
block_method="blockmedian", data=data, x=x, y=y, z=z, outfile=outfile, **kwargs
@@ -303,6 +327,18 @@ def blockmode(data=None, x=None, y=None, z=None, outfile=None, **kwargs):
303327
is not set.
304328
- None if ``outfile`` is set (filtered output will be stored in file
305329
set by ``outfile``).
330+
331+
Example
332+
-------
333+
>>> import pygmt # doctest: +SKIP
334+
>>> # Load a table of ship observations of bathymetry off Baja California
335+
>>> data = pygmt.datasets.load_sample_data(
336+
... name="bathymetry"
337+
... ) # doctest: +SKIP
338+
>>> # Calculate block mode values within 5 by 5 minute bins
339+
>>> data_bmode = pygmt.blockmode(
340+
... data=data, region=[245, 255, 20, 30], spacing="5m"
341+
... ) # doctest: +SKIP
306342
"""
307343
return _blockm(
308344
block_method="blockmode", data=data, x=x, y=y, z=z, outfile=outfile, **kwargs

pygmt/tests/test_grdcut.py

Lines changed: 18 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,29 @@
11
"""
22
Tests for grdcut.
33
"""
4-
import os
5-
64
import numpy as np
75
import pytest
86
import xarray as xr
97
from pygmt import grdcut, load_dataarray
10-
from pygmt.datasets import load_earth_relief
118
from pygmt.exceptions import GMTInvalidInput
129
from pygmt.helpers import GMTTempFile
10+
from pygmt.helpers.testing import load_static_earth_relief
1311

1412

1513
@pytest.fixture(scope="module", name="grid")
1614
def fixture_grid():
1715
"""
1816
Load the grid data from the sample earth_relief file.
1917
"""
20-
return load_earth_relief(registration="pixel")
18+
return load_static_earth_relief()
19+
20+
21+
@pytest.fixture(scope="module", name="region")
22+
def fixture_region():
23+
"""
24+
Set the data region.
25+
"""
26+
return [-53, -49, -20, -17]
2127

2228

2329
@pytest.fixture(scope="module", name="expected_grid")
@@ -27,55 +33,31 @@ def fixture_grid_result():
2733
"""
2834
return xr.DataArray(
2935
data=[
30-
[-5069.5, -5105.0, -4937.0, -4708.0],
31-
[-4115.5, -4996.0, -4762.0, -4599.0],
32-
[-656.0, -160.0, -3484.5, -3897.5],
36+
[446.5, 481.5, 439.5, 553.0],
37+
[757.0, 570.5, 538.5, 524.0],
38+
[796.0, 886.0, 571.5, 638.5],
3339
],
34-
coords=dict(lon=[-2.5, -1.5, -0.5, 0.5], lat=[2.5, 3.5, 4.5]),
40+
coords=dict(lon=[-52.5, -51.5, -50.5, -49.5], lat=[-19.5, -18.5, -17.5]),
3541
dims=["lat", "lon"],
3642
)
3743

3844

39-
def test_grdcut_file_in_file_out(expected_grid):
40-
"""
41-
grdcut an input grid file, and output to a grid file.
42-
"""
43-
with GMTTempFile(suffix=".nc") as tmpfile:
44-
result = grdcut("@earth_relief_01d", outgrid=tmpfile.name, region=[-3, 1, 2, 5])
45-
assert result is None # return value is None
46-
assert os.path.exists(path=tmpfile.name) # check that outgrid exists
47-
temp_grid = load_dataarray(tmpfile.name)
48-
xr.testing.assert_allclose(a=temp_grid, b=expected_grid)
49-
50-
51-
def test_grdcut_file_in_dataarray_out(expected_grid):
52-
"""
53-
grdcut an input grid file, and output as DataArray.
54-
"""
55-
outgrid = grdcut("@earth_relief_01d", region=[-3, 1, 2, 5])
56-
assert isinstance(outgrid, xr.DataArray)
57-
assert outgrid.gmt.registration == 1 # Pixel registration
58-
assert outgrid.gmt.gtype == 1 # Geographic type
59-
# check information of the output grid
60-
xr.testing.assert_allclose(a=outgrid, b=expected_grid)
61-
62-
63-
def test_grdcut_dataarray_in_file_out(grid, expected_grid):
45+
def test_grdcut_dataarray_in_file_out(grid, expected_grid, region):
6446
"""
6547
grdcut an input DataArray, and output to a grid file.
6648
"""
6749
with GMTTempFile(suffix=".nc") as tmpfile:
68-
result = grdcut(grid, outgrid=tmpfile.name, region=[-3, 1, 2, 5])
50+
result = grdcut(grid, outgrid=tmpfile.name, region=region)
6951
assert result is None # grdcut returns None if output to a file
7052
temp_grid = load_dataarray(tmpfile.name)
7153
xr.testing.assert_allclose(a=temp_grid, b=expected_grid)
7254

7355

74-
def test_grdcut_dataarray_in_dataarray_out(grid, expected_grid):
56+
def test_grdcut_dataarray_in_dataarray_out(grid, expected_grid, region):
7557
"""
7658
grdcut an input DataArray, and output as DataArray.
7759
"""
78-
outgrid = grdcut(grid, region=[-3, 1, 2, 5])
60+
outgrid = grdcut(grid, region=region)
7961
assert isinstance(outgrid, xr.DataArray)
8062
xr.testing.assert_allclose(a=outgrid, b=expected_grid)
8163

pygmt/tests/test_grdfill.py

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,20 @@
77
import pytest
88
import xarray as xr
99
from pygmt import grdfill, load_dataarray
10-
from pygmt.datasets import load_earth_relief
1110
from pygmt.exceptions import GMTInvalidInput
1211
from pygmt.helpers import GMTTempFile
12+
from pygmt.helpers.testing import load_static_earth_relief
1313

1414

1515
@pytest.fixture(scope="module", name="grid")
1616
def fixture_grid():
1717
"""
18-
Load the grid data from the sample earth_relief file and set value(s) to
19-
NaN.
18+
Load the grid data from the static_earth_relief file and set value(s) to
19+
NaN and inf.
2020
"""
21-
grid = load_earth_relief(registration="pixel", region=[125, 130, -25, -20])
22-
grid[2:4, 1:3] = np.nan
23-
grid[0:2, 2:4] = np.inf
21+
grid = load_static_earth_relief()
22+
grid[3:6, 3:5] = np.nan
23+
grid[6:8, 2:4] = np.inf
2424
return grid
2525

2626

@@ -31,15 +31,39 @@ def fixture_grid_result():
3131
"""
3232
return xr.DataArray(
3333
data=[
34-
[442.5, 439.0, np.inf, np.inf, 508.0],
35-
[393.0, 364.5, np.inf, np.inf, 506.5],
36-
[362.0, 20.0, 20.0, 373.5, 402.5],
37-
[321.5, 20.0, 20.0, 356.0, 422.5],
38-
[282.5, 318.0, 326.5, 379.5, 383.5],
34+
[347.5, 344.5, 386.0, 640.5, 617.0, 579.0, 646.5, 671.0],
35+
[383.0, 284.5, 344.5, 394.0, 491.0, 556.5, 578.5, 618.5],
36+
[373.0, 367.5, 349.0, 352.5, 419.5, 428.0, 570.0, 667.5],
37+
[557.0, 435.0, 385.5, 20.0, 20.0, 496.0, 519.5, 833.5],
38+
[561.5, 539.0, 446.5, 20.0, 20.0, 553.0, 726.5, 981.0],
39+
[310.0, 521.5, 757.0, 20.0, 20.0, 524.0, 686.5, 794.0],
40+
[521.5, 682.5, np.inf, np.inf, 571.5, 638.5, 739.5, 881.5],
41+
[308.0, 595.5, np.inf, np.inf, 580.0, 770.0, 927.0, 920.0],
42+
[601.0, 526.5, 535.0, 299.0, 398.5, 645.0, 797.5, 964.0],
43+
[494.5, 488.5, 357.0, 254.5, 286.0, 484.5, 653.5, 930.0],
44+
[450.5, 395.5, 366.0, 248.0, 250.0, 354.5, 550.0, 797.5],
45+
[345.5, 320.0, 335.0, 292.0, 207.5, 247.0, 325.0, 346.5],
46+
[349.0, 313.0, 325.5, 247.0, 191.0, 225.0, 260.0, 452.5],
47+
[347.5, 331.5, 309.0, 282.0, 190.0, 208.0, 299.5, 348.0],
3948
],
4049
coords=dict(
41-
lon=[125.5, 126.5, 127.5, 128.5, 129.5],
42-
lat=[-24.5, -23.5, -22.5, -21.5, -20.5],
50+
lon=[-54.5, -53.5, -52.5, -51.5, -50.5, -49.5, -48.5, -47.5],
51+
lat=[
52+
-23.5,
53+
-22.5,
54+
-21.5,
55+
-20.5,
56+
-19.5,
57+
-18.5,
58+
-17.5,
59+
-16.5,
60+
-15.5,
61+
-14.5,
62+
-13.5,
63+
-12.5,
64+
-11.5,
65+
-10.5,
66+
],
4367
),
4468
dims=["lat", "lon"],
4569
)

0 commit comments

Comments
 (0)