Skip to content

Commit 5bfcbeb

Browse files
authored
Fix fixture_xr_image to open earth_day_01d_p directly with rioxarray (#2963)
Rioxarray can now read the 3-bands from `@earth_day_01d_p` directly without needing to parse the colorinterp information from the GeoTIFF file. * Update baseline images for test_tilemap_* with GMT 6.5.0 and gs 10.02.1 * Trigger re-caching of earth_day_01d_p file Modify pygmt/helpers/caching.py file slightly to create new cache. * Remove elif block for manually creating RGB image Downloading @earth_day_01d_p using GMT 6.4.0 actually works. The new earth_day_01d_p.tif file processed on 2023-09-29 doesn't have the quantized colormap, so no need for the extra handling. See GenericMappingTools/gmtserver-admin#257 for more info.
1 parent 9e3f0b1 commit 5bfcbeb

6 files changed

+17
-35
lines changed

pygmt/helpers/caching.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
"""
2-
Functions for download remote data files as cache.
2+
Functions for downloading remote data files to cache.
33
"""
44
from pygmt.src import which
55

66

77
def cache_data():
88
"""
9-
Download GMT remote data files used in PyGMT tests and docs as cache files.
9+
Download GMT remote data files used in PyGMT tests and docs to cache folder.
1010
"""
1111
# List of datasets to download
1212
datasets = [
@@ -57,7 +57,7 @@ def cache_data():
5757
# Earth WDMAM grids
5858
"@earth_wdmam_01d_g",
5959
"@S90E000.earth_wdmam_03m_g.nc", # Specific grid for 03m test
60-
# Earth day/night grids
60+
# Earth day/night images
6161
"@earth_day_01d_p",
6262
# Other cache files
6363
"@capitals.gmt",
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
outs:
2-
- md5: e2a9a57f61bdca0c21ddec3e1ae5d819
3-
size: 16595
2+
- md5: e55d9848135fc14c9cfc3d2c85bd82bb
3+
size: 16472
44
path: test_tilemap_no_clip_False.png
5+
hash: md5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
outs:
2-
- md5: 86ce085faad17433dfabba675d0379ee
3-
size: 38836
2+
- md5: 53949854f32b450e55f1be86102387e9
3+
size: 38816
44
path: test_tilemap_no_clip_True.png
5+
hash: md5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
outs:
2-
- md5: 6da0601f305a6c3391e4a1aa0aee6173
3-
size: 37139
2+
- md5: 5f225e4dd26f44e07bcbd8e713c67dbe
3+
size: 37343
44
path: test_tilemap_ogc_wgs84.png
5+
hash: md5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
outs:
2-
- md5: 2965f6711c5878014491c7e6f791048e
3-
size: 62077
2+
- md5: 14f7afd5d48ed6aed88d495783f0ba42
3+
size: 62398
44
path: test_tilemap_web_mercator.png
5+
hash: md5

pygmt/tests/test_grdimage_image.py

+2-24
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
"""
22
Test Figure.grdimage on 3-band RGB images.
33
"""
4-
import numpy as np
5-
import pandas as pd
64
import pytest
7-
import xarray as xr
85
from pygmt import Figure, which
96

10-
rasterio = pytest.importorskip("rasterio")
117
rioxarray = pytest.importorskip("rioxarray")
128

139

@@ -19,26 +15,8 @@ def fixture_xr_image():
1915
"""
2016
geotiff = which(fname="@earth_day_01d_p", download="c")
2117
with rioxarray.open_rasterio(filename=geotiff) as rda:
22-
if len(rda.band) == 1:
23-
with rasterio.open(fp=geotiff) as src:
24-
df_colormap = pd.DataFrame.from_dict(
25-
data=src.colormap(1), orient="index"
26-
)
27-
array = src.read()
28-
29-
red = np.vectorize(df_colormap[0].get)(array)
30-
green = np.vectorize(df_colormap[1].get)(array)
31-
blue = np.vectorize(df_colormap[2].get)(array)
32-
# alpha = np.vectorize(df_colormap[3].get)(array)
33-
34-
rda.data = red
35-
da_red = rda.astype(dtype=np.uint8).copy()
36-
rda.data = green
37-
da_green = rda.astype(dtype=np.uint8).copy()
38-
rda.data = blue
39-
da_blue = rda.astype(dtype=np.uint8).copy()
40-
41-
xr_image = xr.concat(objs=[da_red, da_green, da_blue], dim="band")
18+
if len(rda.band) == 3:
19+
xr_image = rda.load()
4220
assert xr_image.sizes == {"band": 3, "y": 180, "x": 360}
4321
return xr_image
4422

0 commit comments

Comments
 (0)