Skip to content

Commit 1267a9c

Browse files
authored
Merge branch 'main' into coast/resolution
2 parents e24bbd8 + 8eb2b4f commit 1267a9c

16 files changed

+59
-70
lines changed

.github/workflows/benchmarks.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
steps:
3535
# Checkout current git repository
3636
- name: Checkout
37-
uses: actions/[email protected].1
37+
uses: actions/[email protected].2
3838
with:
3939
# fetch all history so that setuptools-scm works
4040
fetch-depth: 0

.github/workflows/cache_data.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
steps:
3737
# Checkout current git repository
3838
- name: Checkout
39-
uses: actions/[email protected].1
39+
uses: actions/[email protected].2
4040
with:
4141
# fetch all history so that setuptools-scm works
4242
fetch-depth: 0

.github/workflows/check-links.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ jobs:
2323

2424
steps:
2525
- name: Checkout the repository
26-
uses: actions/[email protected].1
26+
uses: actions/[email protected].2
2727
with:
2828
path: repository
2929

3030
- name: Checkout the documentation
31-
uses: actions/[email protected].1
31+
uses: actions/[email protected].2
3232
with:
3333
ref: gh-pages
3434
path: documentation

.github/workflows/ci_docs.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ jobs:
6969
steps:
7070
# Checkout current git repository
7171
- name: Checkout
72-
uses: actions/[email protected].1
72+
uses: actions/[email protected].2
7373
with:
7474
# fetch all history so that setuptools-scm works
7575
fetch-depth: 0
@@ -138,7 +138,7 @@ jobs:
138138
run: make -C doc clean all
139139

140140
- name: Checkout the gh-pages branch
141-
uses: actions/[email protected].1
141+
uses: actions/[email protected].2
142142
with:
143143
ref: gh-pages
144144
# Checkout to this folder instead of the current one

.github/workflows/ci_doctests.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
steps:
3636
# Checkout current git repository
3737
- name: Checkout
38-
uses: actions/[email protected].1
38+
uses: actions/[email protected].2
3939
with:
4040
# fetch all history so that setuptools-scm works
4141
fetch-depth: 0

.github/workflows/ci_tests.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ jobs:
103103
steps:
104104
# Checkout current git repository
105105
- name: Checkout
106-
uses: actions/[email protected].1
106+
uses: actions/[email protected].2
107107
with:
108108
# fetch all history so that setuptools-scm works
109109
fetch-depth: 0

.github/workflows/ci_tests_dev.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646
steps:
4747
# Checkout current git repository
4848
- name: Checkout
49-
uses: actions/[email protected].1
49+
uses: actions/[email protected].2
5050
with:
5151
# fetch all history so that setuptools-scm works
5252
fetch-depth: 0
@@ -96,7 +96,7 @@ jobs:
9696

9797
# Checkout current GMT repository
9898
- name: Checkout the GMT source from ${{ matrix.gmt_git_ref }} branch
99-
uses: actions/[email protected].1
99+
uses: actions/[email protected].2
100100
with:
101101
repository: 'GenericMappingTools/gmt'
102102
ref: ${{ matrix.gmt_git_ref }}

.github/workflows/ci_tests_legacy.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jobs:
4444
steps:
4545
# Checkout current git repository
4646
- name: Checkout
47-
uses: actions/[email protected].1
47+
uses: actions/[email protected].2
4848
with:
4949
# fetch all history so that setuptools-scm works
5050
fetch-depth: 0

.github/workflows/dvc-diff.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121

2222
steps:
2323
- name: Checkout
24-
uses: actions/[email protected].1
24+
uses: actions/[email protected].2
2525
with:
2626
# fetch all history so that dvc diff works
2727
fetch-depth: 0

.github/workflows/format-command.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ jobs:
1818
private-key: ${{ secrets.APP_PRIVATE_KEY }}
1919

2020
# Checkout the pull request branch
21-
- uses: actions/[email protected].1
21+
- uses: actions/[email protected].2
2222
with:
2323
token: ${{ steps.generate-token.outputs.token }}
2424
repository: ${{ github.event.client_payload.pull_request.head.repo.full_name }}
2525
ref: ${{ github.event.client_payload.pull_request.head.ref }}
2626

2727
# Setup Python environment
28-
- uses: actions/setup-python@v5.2.0
28+
- uses: actions/setup-python@v5.3.0
2929
with:
3030
python-version: '3.12'
3131

.github/workflows/publish-to-pypi.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ jobs:
4545

4646
steps:
4747
- name: Checkout
48-
uses: actions/[email protected].1
48+
uses: actions/[email protected].2
4949
with:
5050
# fetch all history so that setuptools-scm works
5151
fetch-depth: 0
5252

5353
- name: Set up Python
54-
uses: actions/setup-python@v5.2.0
54+
uses: actions/setup-python@v5.3.0
5555
with:
5656
python-version: '3.12'
5757

.github/workflows/release-baseline-images.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323

2424
steps:
2525
- name: Checkout
26-
uses: actions/[email protected].1
26+
uses: actions/[email protected].2
2727

2828
- name: Setup data version control (DVC)
2929
uses: iterative/[email protected]

.github/workflows/style_checks.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ jobs:
2424
steps:
2525
# Checkout current git repository
2626
- name: Checkout
27-
uses: actions/[email protected].1
27+
uses: actions/[email protected].2
2828

2929
# Setup Python
3030
- name: Set up Python
31-
uses: actions/setup-python@v5.2.0
31+
uses: actions/setup-python@v5.3.0
3232
with:
3333
python-version: '3.12'
3434

.github/workflows/type_checks.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ jobs:
3333
steps:
3434
# Checkout current git repository
3535
- name: Checkout
36-
uses: actions/[email protected].1
36+
uses: actions/[email protected].2
3737

3838
# Setup Python
3939
- name: Set up Python
40-
uses: actions/setup-python@v5.2.0
40+
uses: actions/setup-python@v5.3.0
4141
with:
4242
python-version: '3.12'
4343

pygmt/datasets/load_remote_dataset.py

+35-43
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,33 @@
22
Internal function to load GMT remote datasets.
33
"""
44

5-
from __future__ import annotations
6-
7-
from typing import TYPE_CHECKING, ClassVar, Literal, NamedTuple
5+
from collections.abc import Sequence
6+
from typing import Any, Literal, NamedTuple
87

8+
import xarray as xr
99
from pygmt.clib import Session
1010
from pygmt.exceptions import GMTInvalidInput
1111
from pygmt.helpers import build_arg_list, kwargs_to_strings
1212
from pygmt.src import which
1313

14-
if TYPE_CHECKING:
15-
from collections.abc import Sequence
16-
17-
import xarray as xr
18-
1914

2015
class Resolution(NamedTuple):
2116
"""
2217
Resolution code, the available grid registrations and whether it is tiled.
2318
2419
Attributes
2520
----------
26-
code : str
21+
code
2722
The resolution code. E.g., "01d", "30m", "01s".
28-
registrations : list
23+
registrations
2924
A list of the accepted registrations for a given resolution. Can be either
3025
"pixel" or "gridline".
31-
tiled : bool
26+
tiled
3227
States if the grid is tiled, which requires an argument for ``region``.
3328
"""
3429

3530
code: str
36-
registrations: ClassVar[list] = ["gridline", "pixel"]
31+
registrations: Sequence[str] = ["gridline", "pixel"]
3732
tiled: bool = False
3833

3934

@@ -43,20 +38,20 @@ class GMTRemoteDataset(NamedTuple):
4338
4439
Attributes
4540
----------
46-
description : str
41+
description
4742
The name assigned as an attribute to the DataArray.
48-
units : str, None
43+
units
4944
The units of the values in the DataArray.
50-
resolutions : dict
45+
resolutions
5146
Dictionary of available resolution as keys and Resolution objects as values.
52-
extra_attributes : dict
47+
extra_attributes
5348
A dictionary of extra or unique attributes of the dataset.
5449
"""
5550

5651
description: str
5752
units: str | None
5853
resolutions: dict[str, Resolution]
59-
extra_attributes: dict
54+
extra_attributes: dict[str, Any]
6055

6156

6257
datasets = {
@@ -389,9 +384,8 @@ def _load_remote_dataset(
389384
The grid resolution. The suffix ``d``, ``m``, and ``s`` stand for arc-degrees,
390385
arc-minutes, and arc-seconds, respectively.
391386
region
392-
The subregion of the grid to load, in the form of a list
393-
[*xmin*, *xmax*, *ymin*, *ymax*] or a string *xmin/xmax/ymin/ymax*.
394-
Required for tiled grids.
387+
The subregion of the grid to load, in the form of a sequence [*xmin*, *xmax*,
388+
*ymin*, *ymax*] or an ISO country code. Required for tiled grids.
395389
registration
396390
Grid registration type. Either ``"pixel"`` for pixel registration or
397391
``"gridline"`` for gridline registration. Default is ``None``, where
@@ -417,41 +411,39 @@ def _load_remote_dataset(
417411

418412
# Check resolution
419413
if resolution not in dataset.resolutions:
420-
raise GMTInvalidInput(
414+
msg = (
421415
f"Invalid resolution '{resolution}' for {dataset.description} dataset. "
422416
f"Available resolutions are: {', '.join(dataset.resolutions)}."
423417
)
418+
raise GMTInvalidInput(msg)
424419
resinfo = dataset.resolutions[resolution]
425420

426421
# Check registration
427-
if registration is None:
428-
# Use gridline registration unless only pixel registration is available
429-
registration = "gridline" if "gridline" in resinfo.registrations else "pixel"
430-
elif registration in {"pixel", "gridline"}:
431-
if registration not in resinfo.registrations:
432-
raise GMTInvalidInput(
433-
f"{registration} registration is not available for the "
434-
f"{resolution} {dataset.description} dataset. Only "
435-
f"{resinfo.registrations[0]} registration is available."
422+
match registration:
423+
case None:
424+
# Use gridline registration unless only pixel registration is available
425+
reg = "g" if "gridline" in resinfo.registrations else "p"
426+
case x if x not in resinfo.registrations:
427+
msg = (
428+
f"Invalid grid registration '{registration}' for the {resolution} "
429+
f"{dataset.description} dataset. Should be either 'pixel', 'gridline' "
430+
"or None. Default is None, where a gridline-registered grid is "
431+
"returned unless only the pixel-registered grid is available."
436432
)
437-
else:
438-
raise GMTInvalidInput(
439-
f"Invalid grid registration: '{registration}', should be either 'pixel', "
440-
"'gridline' or None. Default is None, where a gridline-registered grid is "
441-
"returned unless only the pixel-registered grid is available."
442-
)
433+
raise GMTInvalidInput(msg)
434+
case _:
435+
reg = registration[0]
443436

444-
fname = f"@{prefix}_{resolution}_{registration[0]}" # type: ignore[index]
445437
if resinfo.tiled and region is None:
446-
raise GMTInvalidInput(
447-
f"'region' is required for {dataset.description} resolution '{resolution}'."
438+
msg = (
439+
f"The 'region' parameter is required for {dataset.description} "
440+
f"resolution '{resolution}'."
448441
)
442+
raise GMTInvalidInput(msg)
449443

444+
fname = f"@{prefix}_{resolution}_{reg}"
450445
kind = "image" if name in {"earth_day", "earth_night"} else "grid"
451-
kwdict = {
452-
"R": region, # region can be None
453-
"T": "i" if kind == "image" else "g",
454-
}
446+
kwdict = {"R": region, "T": {"grid": "g", "image": "i"}[kind]}
455447
with Session() as lib:
456448
with lib.virtualfile_out(kind=kind) as voutgrd:
457449
lib.call_module(

pygmt/src/grd2xyz.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
grd2xyz - Convert grid to data table
33
"""
44

5-
from typing import TYPE_CHECKING, Literal
5+
from typing import Literal
66

77
import numpy as np
88
import pandas as pd
@@ -17,9 +17,6 @@
1717
validate_output_table_type,
1818
)
1919

20-
if TYPE_CHECKING:
21-
from collections.abc import Hashable
22-
2320
__doctest_skip__ = ["grd2xyz"]
2421

2522

@@ -152,11 +149,11 @@ def grd2xyz(
152149
)
153150

154151
# Set the default column names for the pandas dataframe header.
155-
column_names: list[Hashable] = ["x", "y", "z"]
152+
column_names: list[str] = ["x", "y", "z"]
156153
# Let output pandas column names match input DataArray dimension names
157154
if output_type == "pandas" and isinstance(grid, xr.DataArray):
158155
# Reverse the dims because it is rows, columns ordered.
159-
column_names = [grid.dims[1], grid.dims[0], grid.name]
156+
column_names = [str(grid.dims[1]), str(grid.dims[0]), str(grid.name)]
160157

161158
with Session() as lib:
162159
with (

0 commit comments

Comments
 (0)