Skip to content
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

Fix bug with different band dtype from load_tile_map by casting to uint8 #2393

Merged
merged 2 commits into from
Mar 4, 2023
Merged
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
13 changes: 7 additions & 6 deletions pygmt/datasets/tile_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -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) int64 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 ...
* band (band) uint8 0 1 2
* 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:
Expand Down Expand Up @@ -137,7 +138,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]),
},
Expand Down