Skip to content

Commit

Permalink
Fix fixture_xr_image to open earth_day_01d_p directly with rioxarray (#…
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
weiji14 committed Jan 11, 2024
1 parent 9e3f0b1 commit 5bfcbeb
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 35 deletions.
6 changes: 3 additions & 3 deletions pygmt/helpers/caching.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
"""
Functions for download remote data files as cache.
Functions for downloading remote data files to cache.
"""
from pygmt.src import which


def cache_data():
"""
Download GMT remote data files used in PyGMT tests and docs as cache files.
Download GMT remote data files used in PyGMT tests and docs to cache folder.
"""
# List of datasets to download
datasets = [
Expand Down Expand Up @@ -57,7 +57,7 @@ def cache_data():
# Earth WDMAM grids
"@earth_wdmam_01d_g",
"@S90E000.earth_wdmam_03m_g.nc", # Specific grid for 03m test
# Earth day/night grids
# Earth day/night images
"@earth_day_01d_p",
# Other cache files
"@capitals.gmt",
Expand Down
5 changes: 3 additions & 2 deletions pygmt/tests/baseline/test_tilemap_no_clip_False.png.dvc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
outs:
- md5: e2a9a57f61bdca0c21ddec3e1ae5d819
size: 16595
- md5: e55d9848135fc14c9cfc3d2c85bd82bb
size: 16472
path: test_tilemap_no_clip_False.png
hash: md5
5 changes: 3 additions & 2 deletions pygmt/tests/baseline/test_tilemap_no_clip_True.png.dvc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
outs:
- md5: 86ce085faad17433dfabba675d0379ee
size: 38836
- md5: 53949854f32b450e55f1be86102387e9
size: 38816
path: test_tilemap_no_clip_True.png
hash: md5
5 changes: 3 additions & 2 deletions pygmt/tests/baseline/test_tilemap_ogc_wgs84.png.dvc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
outs:
- md5: 6da0601f305a6c3391e4a1aa0aee6173
size: 37139
- md5: 5f225e4dd26f44e07bcbd8e713c67dbe
size: 37343
path: test_tilemap_ogc_wgs84.png
hash: md5
5 changes: 3 additions & 2 deletions pygmt/tests/baseline/test_tilemap_web_mercator.png.dvc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
outs:
- md5: 2965f6711c5878014491c7e6f791048e
size: 62077
- md5: 14f7afd5d48ed6aed88d495783f0ba42
size: 62398
path: test_tilemap_web_mercator.png
hash: md5
26 changes: 2 additions & 24 deletions pygmt/tests/test_grdimage_image.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
"""
Test Figure.grdimage on 3-band RGB images.
"""
import numpy as np
import pandas as pd
import pytest
import xarray as xr
from pygmt import Figure, which

rasterio = pytest.importorskip("rasterio")
rioxarray = pytest.importorskip("rioxarray")


Expand All @@ -19,26 +15,8 @@ def fixture_xr_image():
"""
geotiff = which(fname="@earth_day_01d_p", download="c")
with rioxarray.open_rasterio(filename=geotiff) as rda:
if len(rda.band) == 1:
with rasterio.open(fp=geotiff) as src:
df_colormap = pd.DataFrame.from_dict(
data=src.colormap(1), orient="index"
)
array = src.read()

red = np.vectorize(df_colormap[0].get)(array)
green = np.vectorize(df_colormap[1].get)(array)
blue = np.vectorize(df_colormap[2].get)(array)
# alpha = np.vectorize(df_colormap[3].get)(array)

rda.data = red
da_red = rda.astype(dtype=np.uint8).copy()
rda.data = green
da_green = rda.astype(dtype=np.uint8).copy()
rda.data = blue
da_blue = rda.astype(dtype=np.uint8).copy()

xr_image = xr.concat(objs=[da_red, da_green, da_blue], dim="band")
if len(rda.band) == 3:
xr_image = rda.load()
assert xr_image.sizes == {"band": 3, "y": 180, "x": 360}
return xr_image

Expand Down

0 comments on commit 5bfcbeb

Please sign in to comment.