Skip to content

Commit

Permalink
Add download_test_data to download data files used in tests (#1310)
Browse files Browse the repository at this point in the history
Co-authored-by: Wei Ji <[email protected]>
Co-authored-by: Meghan Jones <[email protected]>
Co-authored-by: Yao Jiayuan <[email protected]>
  • Loading branch information
4 people authored Jun 2, 2021
1 parent aa4b8d1 commit 1ab551d
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 17 deletions.
36 changes: 19 additions & 17 deletions .github/workflows/cache_data.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,34 +17,36 @@ jobs:
shell: bash -l {0}

steps:
# Checkout current git repository
- name: Checkout
uses: actions/[email protected]
with:
# fecth all history so that setuptools-scm works
fetch-depth: 0

# Setup Miniconda
- name: Setup Miniconda
uses: conda-incubator/[email protected]
with:
channels: conda-forge
miniconda-version: "latest"

# Install GMT
- name: Install GMT
run: conda install -c conda-forge/label/dev gmt=6.2.0rc2
# Install GMT and other required dependencies from conda-forge
- name: Install dependencies
run: |
conda install conda-forge/label/dev::gmt=6.2.0rc2 \
numpy pandas xarray netCDF4 packaging matplotlib
# Install the package that we want to test
- name: Install the package
run: |
python setup.py sdist --formats=zip
pip install dist/*
# Download remote files
- name: Download remote data
run: |
gmt which -Ga @earth_relief_10m_p @earth_relief_10m_g \
@earth_relief_30m_p @earth_relief_30m_g \
@earth_relief_01d_p @earth_relief_01d_g \
@earth_relief_05m_p @earth_relief_05m_g
# Download one tile of the 03s srtm data.
# @N35E135.earth_relief_03s_g.nc is for internal use only.
# The naming scheme may change.
# DO NOT USE IT IN SCRIPTS.
gmt which -Ga @N35E135.earth_relief_03s_g.nc
# @srtm_tiles.nc is needed for 03s and 01s relief data
gmt which -Ga @srtm_tiles.nc
gmt which -Ga @ridge.txt @Table_5_11.txt @test.dat.nc \
@tut_bathy.nc @tut_quakes.ngdc @tut_ship.xyz \
@usgs_quakes_22.txt @fractures_06.txt
python -c "from pygmt.helpers.testing import download_test_data; download_test_data()"
# Upload the downloaded files as artifacts to GitHub
- name: Upload artifacts to GitHub
Expand Down
34 changes: 34 additions & 0 deletions pygmt/helpers/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from matplotlib.testing.compare import compare_images
from pygmt.exceptions import GMTImageComparisonFailure
from pygmt.src import which


def check_figures_equal(*, extensions=("png",), tol=0.0, result_dir="result_images"):
Expand Down Expand Up @@ -139,3 +140,36 @@ def wrapper(*args, ext="png", request=None, **kwargs):
return wrapper

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_relief_01d_p",
"@earth_relief_01d_g",
"@earth_relief_30m_p",
"@earth_relief_30m_g",
"@earth_relief_10m_p",
"@earth_relief_05m_p",
"@earth_relief_05m_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.
"@N35E135.earth_relief_03s_g.nc",
# Other cache files
"@fractures_06.txt",
"@ridge.txt",
"@srtm_tiles.nc", # needed for 03s and 01s relief data
"@Table_5_11.txt",
"@test.dat.nc",
"@tut_bathy.nc",
"@tut_quakes.ngdc",
"@tut_ship.xyz",
"@usgs_quakes_22.txt",
]
which(fname=datasets, download="a")

0 comments on commit 1ab551d

Please sign in to comment.