Skip to content

Commit f379164

Browse files
weiji14seismanmichaelgrundyvonnefroehlich
authored
Add function to load raster tile maps using contextily (#2125)
New dataset function to load XYZ tiles! Uses contextily to retrieve the tiles based on a bounding box. Included an example doctest that shows how the map tiles can be loaded into an xarray.DataArray. Added a new section in the API docs and intersphinx mappings for contextily and xyzservices. * Use correct Spherical Mercator coordinates Can't assume that the input bounding box (which can be in longitude/latitude) is the same as the returned extent (which is always in EPSG:3857). * Change ll parameter to lonlat To fix pylint `C0103: Argument name "ll" doesn't conform to snake_case naming style (invalid-name)`. * Add contextily to CI build matrix and include it as optional dependency Let the Continuous Integration tests run with `contextily`, include it in pyproject.toml and environment.yml, and document it in `doc/install.rst` as an optional dependency. * Set default bounding box coordinates to be lonlat Bounding box coordinates are assumed to be longitude/latitude by default, rather than in Spherical Mercator. * Skip doctest when contextily is not installed Using the `__doctest_requires__` variable, see https://github.com/astropy/pytest-doctestplus/tree/v0.12.1#doctest-dependencies * Add intersphinx link for rasterio Also updated intersphinx link for xarray to new URL at https://docs.xarray.dev/en/stable * Document wait and max_retries parameters used in contextily.bounds2img * Use PyGMT's convention for default values in docstrings Modified from original contextily.bounds2img docstring to fit PyGMT's standards. Xref https://github.com/Generi cMappingTools/pygmt/pull/1182. * Rename load_map_tiles to load_tile_map Also create new dedicated section for load_tile_map in the API docs index. * Add zoom parameter and remove kwargs Wrap all of the parameters in contextily.bounds2img, and so can remove kwargs. Need to disable the pylint recommendation `R0914: Too many local variables`. * Add contextily to docs build CI requirements * Add contextily to pygmt.show_versions() dependency list * Document the three possible source options thoroughly Split out the three possible source options into bullet points. Link to https://contextily.readthedocs.io/en/latest/providers_deepdive.html, give an example OpenStreetMap URL, and link to https://contextily.readthedocs.io/en/stable/working_with_local_files.html. * Add more detail about the zoom level of detail --------- Co-authored-by: Dongdong Tian <[email protected]> Co-authored-by: Michael Grund <[email protected]> Co-authored-by: Yvonne Fröhlich <[email protected]>
1 parent 3305bf2 commit f379164

File tree

13 files changed

+180
-6
lines changed

13 files changed

+180
-6
lines changed

.github/workflows/ci_docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ jobs:
7171
- name: Install dependencies
7272
run: |
7373
mamba install gmt=6.4.0 numpy pandas xarray netCDF4 packaging \
74-
build ipython make myst-parser geopandas \
74+
build ipython make myst-parser contextily geopandas \
7575
sphinx sphinx-copybutton sphinx-design sphinx-gallery sphinx_rtd_theme
7676
7777
# Show installed pkg information for postmortem diagnostic

.github/workflows/ci_tests.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747
optional-packages: ''
4848
- python-version: '3.11'
4949
numpy-version: '1.24'
50-
optional-packages: 'geopandas ipython'
50+
optional-packages: 'contextily geopandas ipython'
5151
timeout-minutes: 30
5252
defaults:
5353
run:

.github/workflows/ci_tests_dev.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ jobs:
101101
geopandas ghostscript libnetcdf hdf5 zlib curl pcre make
102102
pip install --pre --prefer-binary \
103103
numpy pandas xarray netCDF4 packaging \
104-
build dvc ipython 'pytest>=6.0' pytest-cov \
104+
build contextily dvc ipython 'pytest>=6.0' pytest-cov \
105105
pytest-doctestplus pytest-mpl sphinx-gallery
106106
107107
# Pull baseline image data from dvc remote (DAGsHub)

.github/workflows/ci_tests_legacy.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ jobs:
6666
run: |
6767
mamba install gmt=${{ matrix.gmt_version }} numpy \
6868
pandas xarray netCDF4 packaging \
69-
geopandas ipython \
69+
contextily geopandas ipython \
7070
build dvc make 'pytest>=6.0' \
7171
pytest-cov pytest-doctestplus pytest-mpl sphinx-gallery
7272

ci/requirements/docs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ dependencies:
1212
- netCDF4
1313
- packaging
1414
# Optional dependencies
15+
- contextily
1516
- geopandas
1617
# Development dependencies (general)
1718
- build

doc/api/index.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,13 @@ and store them in GMT's user data directory.
227227
datasets.load_earth_vertical_gravity_gradient
228228
datasets.load_sample_data
229229

230+
In addition, there is also a special function to load XYZ tile maps via
231+
:doc:`contextily <contextily:index>` to be used as base maps.
232+
233+
.. autosummary::
234+
:toctree: generated
235+
236+
datasets.load_tile_map
230237

231238
.. currentmodule:: pygmt
232239

doc/conf.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,14 @@
5454

5555
# intersphinx configuration
5656
intersphinx_mapping = {
57-
"python": ("https://docs.python.org/3/", None),
57+
"contextily": ("https://contextily.readthedocs.io/en/stable/", None),
5858
"geopandas": ("https://geopandas.org/en/stable/", None),
5959
"numpy": ("https://numpy.org/doc/stable/", None),
60+
"python": ("https://docs.python.org/3/", None),
6061
"pandas": ("https://pandas.pydata.org/pandas-docs/stable/", None),
62+
"rasterio": ("https://rasterio.readthedocs.io/en/stable/", None),
6163
"xarray": ("https://docs.xarray.dev/en/stable/", None),
64+
"xyzservices": ("https://xyzservices.readthedocs.io/en/stable", None),
6265
}
6366

6467
# options for sphinx-copybutton

doc/install.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ PyGMT requires the following libraries to be installed:
106106
The following are optional dependencies:
107107

108108
* `IPython <https://ipython.org>`__: For embedding the figures in Jupyter notebooks (recommended).
109+
* `Contextily <https://contextily.readthedocs.io>`__: For retrieving tile maps from the internet.
109110
* `GeoPandas <https://geopandas.org>`__: For using and plotting GeoDataFrame objects.
110111

111112
Installing GMT and other dependencies

environment.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ dependencies:
1212
- netCDF4
1313
- packaging
1414
# Optional dependencies
15+
- contextily
1516
- geopandas
1617
- ipython
1718
# Development dependencies (general)

pygmt/__init__.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,15 @@ def _get_ghostscript_version():
158158
"machine": platform.platform(),
159159
}
160160

161-
deps = ["numpy", "pandas", "xarray", "netCDF4", "packaging", "geopandas"]
161+
deps = [
162+
"numpy",
163+
"pandas",
164+
"xarray",
165+
"netCDF4",
166+
"packaging",
167+
"contextily",
168+
"geopandas",
169+
]
162170

163171
print("PyGMT information:")
164172
print(f" version: {__version__}")

0 commit comments

Comments
 (0)