diff --git a/climada/hazard/test/test_trop_cyclone.py b/climada/hazard/test/test_trop_cyclone.py index adacc97a9c..72507793d7 100644 --- a/climada/hazard/test/test_trop_cyclone.py +++ b/climada/hazard/test/test_trop_cyclone.py @@ -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, @@ -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""" diff --git a/climada/util/api_client.py b/climada/util/api_client.py index 9bdf0537c8..eb1ac17d25 100644 --- a/climada/util/api_client.py +++ b/climada/util/api_client.py @@ -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. + + 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