From eeb6c63794ae2d07371c17522e92372c3444cdd7 Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Mon, 8 Jan 2024 09:37:01 +1300 Subject: [PATCH 1/4] Fix fixture_xr_image to open earth_day_01d_p directly with rioxarray Rioxarray can now read the 3-bands from `@earth_day_01d_p` directly without needing to parse the colorinterp information from the GeoTIFF file. --- pygmt/tests/test_grdimage_image.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pygmt/tests/test_grdimage_image.py b/pygmt/tests/test_grdimage_image.py index acb43af0695..e7ac4ef74a7 100644 --- a/pygmt/tests/test_grdimage_image.py +++ b/pygmt/tests/test_grdimage_image.py @@ -19,7 +19,9 @@ 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: + if len(rda.band) == 3: # GMT 6.5.0 or above + xr_image = rda.load() + elif len(rda.band) == 1: # GMT 6.4.0 or below with rasterio.open(fp=geotiff) as src: df_colormap = pd.DataFrame.from_dict( data=src.colormap(1), orient="index" From 4f02cb3f7433f9f626b1844607e8d8328efe3761 Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Mon, 8 Jan 2024 13:15:20 +1300 Subject: [PATCH 2/4] Update baseline images for test_tilemap_* with GMT 6.5.0 and gs 10.02.1 --- pygmt/tests/baseline/test_tilemap_no_clip_False.png.dvc | 5 +++-- pygmt/tests/baseline/test_tilemap_no_clip_True.png.dvc | 5 +++-- pygmt/tests/baseline/test_tilemap_ogc_wgs84.png.dvc | 5 +++-- pygmt/tests/baseline/test_tilemap_web_mercator.png.dvc | 5 +++-- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/pygmt/tests/baseline/test_tilemap_no_clip_False.png.dvc b/pygmt/tests/baseline/test_tilemap_no_clip_False.png.dvc index ee75af24cf8..84a1c0803d5 100644 --- a/pygmt/tests/baseline/test_tilemap_no_clip_False.png.dvc +++ b/pygmt/tests/baseline/test_tilemap_no_clip_False.png.dvc @@ -1,4 +1,5 @@ outs: -- md5: e2a9a57f61bdca0c21ddec3e1ae5d819 - size: 16595 +- md5: e55d9848135fc14c9cfc3d2c85bd82bb + size: 16472 path: test_tilemap_no_clip_False.png + hash: md5 diff --git a/pygmt/tests/baseline/test_tilemap_no_clip_True.png.dvc b/pygmt/tests/baseline/test_tilemap_no_clip_True.png.dvc index 19222ba877c..dae700d7e58 100644 --- a/pygmt/tests/baseline/test_tilemap_no_clip_True.png.dvc +++ b/pygmt/tests/baseline/test_tilemap_no_clip_True.png.dvc @@ -1,4 +1,5 @@ outs: -- md5: 86ce085faad17433dfabba675d0379ee - size: 38836 +- md5: 53949854f32b450e55f1be86102387e9 + size: 38816 path: test_tilemap_no_clip_True.png + hash: md5 diff --git a/pygmt/tests/baseline/test_tilemap_ogc_wgs84.png.dvc b/pygmt/tests/baseline/test_tilemap_ogc_wgs84.png.dvc index 979599bfe5b..518f7492c29 100644 --- a/pygmt/tests/baseline/test_tilemap_ogc_wgs84.png.dvc +++ b/pygmt/tests/baseline/test_tilemap_ogc_wgs84.png.dvc @@ -1,4 +1,5 @@ outs: -- md5: 6da0601f305a6c3391e4a1aa0aee6173 - size: 37139 +- md5: 5f225e4dd26f44e07bcbd8e713c67dbe + size: 37343 path: test_tilemap_ogc_wgs84.png + hash: md5 diff --git a/pygmt/tests/baseline/test_tilemap_web_mercator.png.dvc b/pygmt/tests/baseline/test_tilemap_web_mercator.png.dvc index 11b6b2bc856..642514a7d4b 100644 --- a/pygmt/tests/baseline/test_tilemap_web_mercator.png.dvc +++ b/pygmt/tests/baseline/test_tilemap_web_mercator.png.dvc @@ -1,4 +1,5 @@ outs: -- md5: 2965f6711c5878014491c7e6f791048e - size: 62077 +- md5: 14f7afd5d48ed6aed88d495783f0ba42 + size: 62398 path: test_tilemap_web_mercator.png + hash: md5 From 98f30acfdceb13e0229fa71cadaedf1a3e2e2fd0 Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Mon, 8 Jan 2024 13:25:22 +1300 Subject: [PATCH 3/4] Trigger re-caching of earth_day_01d_p file Modify pygmt/helpers/caching.py file slightly to create new cache. --- pygmt/helpers/caching.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pygmt/helpers/caching.py b/pygmt/helpers/caching.py index e0786053e9f..833809185c0 100644 --- a/pygmt/helpers/caching.py +++ b/pygmt/helpers/caching.py @@ -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 = [ @@ -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", From b8c9c3c04310134177516acfcd4fddc03640f652 Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Tue, 9 Jan 2024 09:58:20 +1300 Subject: [PATCH 4/4] 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 https://github.com/GenericMappingTools/gmtserver-admin/issues/257 for more info. --- pygmt/tests/test_grdimage_image.py | 26 +------------------------- 1 file changed, 1 insertion(+), 25 deletions(-) diff --git a/pygmt/tests/test_grdimage_image.py b/pygmt/tests/test_grdimage_image.py index e7ac4ef74a7..c713957dc91 100644 --- a/pygmt/tests/test_grdimage_image.py +++ b/pygmt/tests/test_grdimage_image.py @@ -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") @@ -19,28 +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) == 3: # GMT 6.5.0 or above + if len(rda.band) == 3: xr_image = rda.load() - elif len(rda.band) == 1: # GMT 6.4.0 or below - 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") assert xr_image.sizes == {"band": 3, "y": 180, "x": 360} return xr_image