From 63aaaa0eaddcb6716837e21971488846018002d8 Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Sat, 4 Mar 2023 11:22:00 +1300 Subject: [PATCH 1/2] Fix bug with different band dtype from load_tile_map by casting to uint8 The band list `[0, 1, 2]` was being converted to int32 on Windows + NumPy 1.24, but is int64 on other platforms. Casting the band coordinate explicitly to `uint8` for consistency. --- pygmt/datasets/tile_map.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pygmt/datasets/tile_map.py b/pygmt/datasets/tile_map.py index 2afe28acbf9..c13e30bd03c 100644 --- a/pygmt/datasets/tile_map.py +++ b/pygmt/datasets/tile_map.py @@ -102,7 +102,7 @@ def load_tile_map(region, zoom="auto", source=None, lonlat=True, wait=0, max_ret Frozen({'band': 3, 'y': 1024, 'x': 1536}) >>> raster.coords Coordinates: - * band (band) int64 0 1 2 + * band (band) uint8 0 1 2 * y (y) float64 1.663e+05 1.663e+05 1.663e+05 ... 1.272e+05 ... * x (x) float64 1.153e+07 1.153e+07 1.153e+07 ... 1.158e+07 ... """ @@ -137,7 +137,7 @@ def load_tile_map(region, zoom="auto", source=None, lonlat=True, wait=0, max_ret dataarray = xr.DataArray( data=rgb_image, coords={ - "band": [0, 1, 2], # Red, Green, Blue + "band": np.uint8([0, 1, 2]), # Red, Green, Blue "y": np.linspace(start=top, stop=bottom, num=rgb_image.shape[1]), "x": np.linspace(start=left, stop=right, num=rgb_image.shape[2]), }, From ea9e7dceef00ef1b2c68630a8d59190a33c1037a Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Sat, 4 Mar 2023 20:56:50 +1300 Subject: [PATCH 2/2] Make tile_map doctest faster by using a smaller zoom level Just plotting the Southern Hemisphere at zoom level 1. --- pygmt/datasets/tile_map.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pygmt/datasets/tile_map.py b/pygmt/datasets/tile_map.py index c13e30bd03c..44344d5903b 100644 --- a/pygmt/datasets/tile_map.py +++ b/pygmt/datasets/tile_map.py @@ -94,17 +94,18 @@ def load_tile_map(region, zoom="auto", source=None, lonlat=True, wait=0, max_ret >>> import contextily >>> from pygmt.datasets import load_tile_map >>> raster = load_tile_map( - ... region=[103.60, 104.06, 1.22, 1.49], # West, East, South, North + ... region=[-180.0, 180.0, -90.0, 0.0], # West, East, South, North + ... zoom=1, # less detailed zoom level ... source=contextily.providers.Stamen.TerrainBackground, ... lonlat=True, # bounding box coordinates are longitude/latitude ... ) >>> raster.sizes - Frozen({'band': 3, 'y': 1024, 'x': 1536}) + Frozen({'band': 3, 'y': 256, 'x': 512}) >>> raster.coords Coordinates: * band (band) uint8 0 1 2 - * y (y) float64 1.663e+05 1.663e+05 1.663e+05 ... 1.272e+05 ... - * x (x) float64 1.153e+07 1.153e+07 1.153e+07 ... 1.158e+07 ... + * y (y) float64 -7.081e-10 -7.858e+04 ... -1.996e+07 -2.004e+07 + * x (x) float64 -2.004e+07 -1.996e+07 ... 1.996e+07 2.004e+07 """ # pylint: disable=too-many-locals if contextily is None: