Skip to content

Commit

Permalink
Merge branch 'master' into remove-obsolete-caches
Browse files Browse the repository at this point in the history
  • Loading branch information
Zeitsperre authored Sep 5, 2023
2 parents c86e863 + 78e8927 commit 6a5028c
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions ravenpy/utilities/testdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ def file_md5_checksum(fname):

def get_local_testdata(
patterns: Union[str, Sequence[str]],
temp_folder: Union[str, os.PathLike],
temp_folder: Union[str, Path],
branch: str = "master",
_local_cache: Union[str, os.PathLike] = _default_cache_dir,
_local_cache: Union[str, Path] = _default_cache_dir,
) -> Union[Path, List[Path]]:
"""Copy specific testdata from a default cache to a temporary folder.
Expand All @@ -49,11 +49,11 @@ def get_local_testdata(
----------
patterns : str or Sequence of str
Glob patterns, which must include the folder.
temp_folder : str or os.PathLike
temp_folder : str or Path
Target folder to copy files and filetree to.
branch : str, optional
For GitHub-hosted files, the branch to download from.
_local_cache : str or os.PathLike
branch : str
For GitHub-hosted files, the branch to download from. Default: "master".
_local_cache : str or Path
Local cache of testing data.
Returns
Expand Down Expand Up @@ -171,24 +171,24 @@ def _get(

# idea copied from xclim that borrowed it from xarray that was borrowed from Seaborn
def get_file(
name: Union[str, os.PathLike, Sequence[Union[str, os.PathLike]]],
name: Union[str, Path, Sequence[Union[str, Path]]],
github_url: str = "https://github.com/Ouranosinc/raven-testdata",
branch: str = "master",
cache_dir: Path = _default_cache_dir,
cache_dir: Union[str, Path] = _default_cache_dir,
) -> Union[Path, List[Path]]:
"""
Return a file from an online GitHub-like repository.
If a local copy is found then always use that to avoid network traffic.
Parameters
----------
name : str or os.PathLike or Sequence of str or os.PathLike
name : str or Path or Sequence of str or Path
Name of the file or list/tuple of names of files containing the dataset(s) including suffixes.
github_url : str
URL to GitHub repository where the data is stored.
branch : str, optional
For GitHub-hosted files, the branch to download from.
cache_dir : Path
branch : str
For GitHub-hosted files, the branch to download from. Default: "master".
cache_dir : str or Path
The directory in which to search for and write cached data.
Returns
Expand All @@ -198,6 +198,8 @@ def get_file(
if isinstance(name, (str, Path)):
name = [name]

cache_dir = Path(cache_dir)

files = list()
for n in name:
fullname = Path(n)
Expand Down Expand Up @@ -235,8 +237,8 @@ def query_folder(
Regex pattern to identify a file.
github_url : str
URL to GitHub repository where the data is stored.
branch : str, optional
For GitHub-hosted files, the branch to download from.
branch : str
For GitHub-hosted files, the branch to download from. Default: "master".
Returns
-------
Expand Down Expand Up @@ -275,10 +277,10 @@ def open_dataset(
github_url: str = "https://github.com/Ouranosinc/raven-testdata",
branch: str = "master",
cache: bool = True,
cache_dir: Path = _default_cache_dir,
cache_dir: Union[str, Path] = _default_cache_dir,
**kwds,
) -> Dataset:
"""Open a dataset from the online GitHub-like repository.
r"""Open a dataset from the online GitHub-like repository.
If a local copy is found then always use that to avoid network traffic.
Expand All @@ -294,11 +296,11 @@ def open_dataset(
URL to GitHub repository where the data is stored.
branch : str, optional
For GitHub-hosted files, the branch to download from.
cache_dir : Path
The directory in which to search for and write cached data.
cache : bool
If True, then cache data locally for use on subsequent calls.
**kwds
cache_dir : str or Path
The directory in which to search for and write cached data.
\*\*kwds
For NetCDF files, keywords passed to xarray.open_dataset.
Returns
Expand All @@ -310,6 +312,7 @@ def open_dataset(
xarray.open_dataset
"""
name = Path(name)
cache_dir = Path(cache_dir)
if suffix is None:
suffix = ".nc"
fullname = name.with_suffix(suffix)
Expand Down

0 comments on commit 6a5028c

Please sign in to comment.