diff --git a/.github/workflows/cache_data.yaml b/.github/workflows/cache_data.yaml index 998158789b5..3a4a43852c3 100644 --- a/.github/workflows/cache_data.yaml +++ b/.github/workflows/cache_data.yaml @@ -1,18 +1,21 @@ -# Cache GMT remote data files and uploads as artifacts +# Cache GMT remote data files and upload as artifacts # # This workflow downloads data files needed by PyGMT tests/documentation from # the GMT data server and uploads as workflow artifacts which can be accessed # by other GitHub Actions workflows. # # It is scheduled to run every Sunday at 12:00 (UTC). If new remote files are -# needed urgently, maintainers can manually uncomment the 'pull_request:' line -# below to refresh the cache. +# needed urgently, maintainers can update the workflow file or +# 'pygmt/helpers/caching.py' file to refresh the cache. # name: Cache data on: - # Uncomment the 'pull_request' line below to manually re-cache data artifacts - # pull_request: + pull_request: + # Make any changes to the following files to refresh the cache + paths: + - 'pygmt/helpers/caching.py' + - '.github/workflows/cache_data.yaml' # Schedule runs on 12 noon every Sunday schedule: - cron: '0 12 * * 0' @@ -61,7 +64,7 @@ jobs: # Download remote files - name: Download remote data run: | - python -c "from pygmt.helpers.testing import download_test_data; download_test_data()" + python -c "from pygmt.helpers.caching import cache_data; cache_data()" # Upload the downloaded files as artifacts to GitHub - name: Upload artifacts to GitHub diff --git a/pygmt/helpers/caching.py b/pygmt/helpers/caching.py new file mode 100644 index 00000000000..e0786053e9f --- /dev/null +++ b/pygmt/helpers/caching.py @@ -0,0 +1,87 @@ +""" +Functions for download remote data files as cache. +""" +from pygmt.src import which + + +def cache_data(): + """ + Download GMT remote data files used in PyGMT tests and docs as cache files. + """ + # List of datasets to download + datasets = [ + # Earth relief grids + "@earth_gebco_01d_g", + "@earth_gebcosi_01d_g", + "@earth_gebcosi_15m_p", + "@earth_relief_01d_p", + "@earth_relief_01d_g", + "@earth_relief_30m_p", + "@earth_relief_30m_g", + "@earth_relief_10m_p", + "@earth_relief_10m_g", + "@earth_relief_05m_p", + "@earth_relief_05m_g", + "@earth_synbath_01d_g", + # List of tiles of 03s srtm data. + # Names like @N35E135.earth_relief_03s_g.nc are for internal use only. + # The naming scheme may change. DO NOT USE IT IN YOUR SCRIPTS. + "@N30W120.earth_relief_15s_p.nc", + "@N35E135.earth_relief_03s_g.nc", + "@N37W120.earth_relief_03s_g.nc", + "@N00W090.earth_relief_03m_p.nc", + "@N00E135.earth_relief_30s_g.nc", + "@N00W010.earth_relief_15s_p.nc", # Specific grid for 15s test + "@N04W010.earth_relief_03s_g.nc", # Specific grid for 03s test + # Earth synbath relief grid + "@S15W105.earth_synbath_30s_p.nc", + # Earth seafloor age grids + "@earth_age_01d_g", + "@N00W030.earth_age_01m_g.nc", # Specific grid for 01m test + # Earth geoid grids + "@earth_geoid_01d_g", + "@N00W030.earth_geoid_01m_g.nc", # Specific grid for 01m test + # Earth magnetic anomaly grids + "@earth_mag_01d_g", + "@S30W060.earth_mag_02m_p.nc", # Specific grid for 02m test + "@earth_mag4km_01d_g", + "@S30W120.earth_mag4km_02m_p.nc", # Specific grid for 02m test + # Earth mask grid + "@earth_mask_01d_g", + # Earth free-air anomaly grids + "@earth_faa_01d_g", + "@N00W030.earth_faa_01m_p.nc", # Specific grid for 01m test + # Earth vertical gravity gradient grids + "@earth_vgg_01d_g", + "@N00W030.earth_vgg_01m_p.nc", # Specific grid for 01m test + # Earth WDMAM grids + "@earth_wdmam_01d_g", + "@S90E000.earth_wdmam_03m_g.nc", # Specific grid for 03m test + # Earth day/night grids + "@earth_day_01d_p", + # Other cache files + "@capitals.gmt", + "@circuit.png", + "@earth_relief_20m_holes.grd", + "@EGM96_to_36.txt", + "@MaunaLoa_CO2.txt", + "@RidgeTest.shp", + "@RidgeTest.shx", + "@RidgeTest.dbf", + "@RidgeTest.prj", + "@Table_5_11.txt", + "@Table_5_11_mean.xyz", + "@fractures_06.txt", + "@hotspots.txt", + "@ridge.txt", + "@mars370d.txt", + "@srtm_tiles.nc", # needed for 03s and 01s relief data + "@static_earth_relief.nc", + "@ternary.txt", + "@test.dat.nc", + "@tut_bathy.nc", + "@tut_quakes.ngdc", + "@tut_ship.xyz", + "@usgs_quakes_22.txt", + ] + which(fname=datasets, download="a") diff --git a/pygmt/helpers/testing.py b/pygmt/helpers/testing.py index 6a9fbec5e17..81ffc2ff5cf 100644 --- a/pygmt/helpers/testing.py +++ b/pygmt/helpers/testing.py @@ -142,89 +142,6 @@ def wrapper(*args, ext="png", request=None, **kwargs): return decorator -def download_test_data(): - """ - Convenience function to download remote data files used in PyGMT tests and docs. - """ - # List of datasets to download - datasets = [ - # Earth relief grids - "@earth_gebco_01d_g", - "@earth_gebcosi_01d_g", - "@earth_gebcosi_15m_p", - "@earth_relief_01d_p", - "@earth_relief_01d_g", - "@earth_relief_30m_p", - "@earth_relief_30m_g", - "@earth_relief_10m_p", - "@earth_relief_10m_g", - "@earth_relief_05m_p", - "@earth_relief_05m_g", - "@earth_synbath_01d_g", - # List of tiles of 03s srtm data. - # Names like @N35E135.earth_relief_03s_g.nc is for internal use only. - # The naming scheme may change. DO NOT USE IT IN YOUR SCRIPTS. - "@N30W120.earth_relief_15s_p.nc", - "@N35E135.earth_relief_03s_g.nc", - "@N37W120.earth_relief_03s_g.nc", - "@N00W090.earth_relief_03m_p.nc", - "@N00E135.earth_relief_30s_g.nc", - "@N00W010.earth_relief_15s_p.nc", # Specific grid for 15s test - "@N04W010.earth_relief_03s_g.nc", # Specific grid for 03s test - # Earth synbath relief grids - "@S15W105.earth_synbath_30s_p.nc", - # Earth seafloor age grids - "@earth_age_01d_g", - "@N00W030.earth_age_01m_g.nc", # Specific grid for 01m test - # Earth geoid grids - "@earth_geoid_01d_g", - "@N00W030.earth_geoid_01m_g.nc", # Specific grid for 01m test - # Earth magnetic anomaly grids - "@earth_mag_01d_g", - "@S30W060.earth_mag_02m_p.nc", # Specific grid for 02m test - "@earth_mag4km_01d_g", - "@S30W120.earth_mag4km_02m_p.nc", # Specific grid for 02m test - # Earth mask grid - "@earth_mask_01d_g", - # Earth free-air anomaly grids - "@earth_faa_01d_g", - "@N00W030.earth_faa_01m_p.nc", # Specific grid for 01m test - # Earth vertical gravity gradient grids - "@earth_vgg_01d_g", - "@N00W030.earth_vgg_01m_p.nc", # Specific grid for 01m test - # Earth WDMAM grids - "@earth_wdmam_01d_g", - "@S90E000.earth_wdmam_03m_g.nc", # Specific grid for 03m test - # Earth day/night grids - "@earth_day_01d_p", - # Other cache files - "@capitals.gmt", - "@circuit.png", - "@earth_relief_20m_holes.grd", - "@EGM96_to_36.txt", - "@MaunaLoa_CO2.txt", - "@RidgeTest.shp", - "@RidgeTest.shx", - "@RidgeTest.dbf", - "@RidgeTest.prj", - "@Table_5_11.txt", - "@Table_5_11_mean.xyz", - "@fractures_06.txt", - "@hotspots.txt", - "@ridge.txt", - "@mars370d.txt", - "@srtm_tiles.nc", # needed for 03s and 01s relief data - "@static_earth_relief.nc", - "@ternary.txt", - "@test.dat.nc", - "@tut_bathy.nc", - "@tut_quakes.ngdc", - "@tut_ship.xyz", - "@usgs_quakes_22.txt", - ] - which(fname=datasets, download="a") - - def load_static_earth_relief(): """ Load the static_earth_relief file for internal testing.