-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c690c17
commit 276d0ba
Showing
2 changed files
with
42 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
"""Utilitiaries used in tests, such as download test resources.""" | ||
|
||
from tempfile import NamedTemporaryFile | ||
|
||
import requests | ||
import xarray as xr | ||
|
||
|
||
def load_dataset_url(url: str) -> NamedTemporaryFile: | ||
"""Download a NetCDF file from the internet and return a Xarray Dataset.""" | ||
with NamedTemporaryFile(suffix=".nc", delete=True) as tmpfile: | ||
response = requests.get(url) | ||
response.raise_for_status() | ||
tmpfile.write(response.content) | ||
|
||
inds = xr.open_dataset(tmpfile.name) | ||
|
||
return inds | ||
|
||
|
||
def load_dataarray_url(url: str) -> NamedTemporaryFile: | ||
"""Download a NetCDF file from the internet and return a Xarray Dataset.""" | ||
with NamedTemporaryFile(suffix=".nc", delete=True) as tmpfile: | ||
response = requests.get(url) | ||
response.raise_for_status() | ||
tmpfile.write(response.content) | ||
|
||
inds = xr.open_dataarray(tmpfile.name) | ||
|
||
return inds |