Skip to content

Commit

Permalink
test_trop_cyclone: get test centroids from data api
Browse files Browse the repository at this point in the history
  • Loading branch information
emanuel-schmid committed Nov 23, 2023
1 parent 756c587 commit e015000
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
5 changes: 4 additions & 1 deletion climada/hazard/test/test_trop_cyclone.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import xarray as xr

from climada.util import ureg
from climada.util.api_client import Client
from climada.hazard.tc_tracks import TCTracks
from climada.hazard.trop_cyclone import (
TropCyclone, get_close_centroids, _vtrans, _B_holland_1980, _bs_holland_2008,
Expand All @@ -43,7 +44,9 @@
TEST_TRACK = DATA_DIR.joinpath("trac_brb_test.csv")
TEST_TRACK_SHORT = DATA_DIR.joinpath("trac_short_test.csv")

CENTR_TEST_BRB = Centroids.from_hdf5(DATA_DIR.joinpath('centr_brb_test.hdf5'))
CENTR_TEST_BRB = Centroids.from_hdf5(
Client().get_dataset_file(name='centr_test_brb', status='test_dataset'))


class TestReader(unittest.TestCase):
"""Test loading funcions from the TropCyclone class"""
Expand Down
22 changes: 22 additions & 0 deletions climada/util/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1072,3 +1072,25 @@ def rm_empty_dirs(directory: Path):
except OSError: # raised when the directory is not empty
pass
rm_empty_dirs(target_dir)

def get_dataset_file(self, **kwargs):
"""Convenience method. Combines ``get_dataset`` and ``download_dataset``.
Returns the path to a single file if the dataset has only one,
otherwise throws an error.

Check warning on line 1080 in climada/util/api_client.py

View check run for this annotation

Jenkins - WCR / Pylint

trailing-whitespace

LOW: Trailing whitespace
Raw output
Used when there is whitespace between the end of a line and the newline.
Parameters
----------
**kwargs
arguments for get_dataset and download_dataset
Returns
-------
Path
"""
download_arguments = {
'target_dir': kwargs.pop('target_dir', SYSTEM_DIR),
'organize_path': kwargs.pop('organize_path', True),
}
dsi = self.get_dataset_info(**kwargs)
_, [test_file] = self.download_dataset(dsi, **download_arguments)
return test_file

0 comments on commit e015000

Please sign in to comment.