From 1f3896057cace869d25374e4d2cd9fa5acf633de Mon Sep 17 00:00:00 2001 From: emanuel-schmid Date: Fri, 30 Jun 2023 16:46:33 +0200 Subject: [PATCH 1/3] tc_tracks: suppress RuntimeWarnings from xarray --- climada/hazard/tc_tracks.py | 107 +++++++++++++++++++++--------------- 1 file changed, 62 insertions(+), 45 deletions(-) diff --git a/climada/hazard/tc_tracks.py b/climada/hazard/tc_tracks.py index 5e7b3916b3..523f1eaada 100644 --- a/climada/hazard/tc_tracks.py +++ b/climada/hazard/tc_tracks.py @@ -155,6 +155,7 @@ Bloemendaal et al. (2020): Generation of a global synthetic tropical cyclone hazard dataset using STORM. Scientific Data 7(1): 40.""" + class TCTracks(): """Contains tropical cyclone tracks. @@ -1360,27 +1361,35 @@ def write_hdf5(self, file_name, complevel=5): Specifies a compression level (0-9) for the zlib compression of the data. A value of 0 or None disables compression. Default: 5 """ - data = [] - for track in self.data: - # convert "time" into a data variable and use a neutral name for the steps - track = track.rename(time="step") - track["time"] = ("step", track["step"].values) - track["step"] = np.arange(track.sizes["step"]) - # change dtype from bool to int to be NetCDF4-compliant - track.attrs['orig_event_flag'] = int(track.attrs['orig_event_flag']) - data.append(track) + with warnings.catch_warnings(): + warnings.filterwarnings( + "ignore", + message="invalid value encountered in cast", + module="xarray", + category=RuntimeWarning, + ) + + data = [] + for track in self.data: + # convert "time" into a data variable and use a neutral name for the steps + track = track.rename(time="step") + track["time"] = ("step", track["step"].values) + track["step"] = np.arange(track.sizes["step"]) + # change dtype from bool to int to be NetCDF4-compliant + track.attrs['orig_event_flag'] = int(track.attrs['orig_event_flag']) + data.append(track) - # concatenate all data sets along new dimension "storm" - ds_combined = xr.combine_nested(data, concat_dim=["storm"]) - ds_combined["storm"] = np.arange(ds_combined.sizes["storm"]) + # concatenate all data sets along new dimension "storm" + ds_combined = xr.combine_nested(data, concat_dim=["storm"]) + ds_combined["storm"] = np.arange(ds_combined.sizes["storm"]) - # convert attributes to data variables of combined dataset - df_attrs = pd.DataFrame([t.attrs for t in data], index=ds_combined["storm"].to_series()) - ds_combined = xr.merge([ds_combined, df_attrs.to_xarray()]) + # convert attributes to data variables of combined dataset + df_attrs = pd.DataFrame([t.attrs for t in data], index=ds_combined["storm"].to_series()) + ds_combined = xr.merge([ds_combined, df_attrs.to_xarray()]) - encoding = {v: dict(zlib=True, complevel=complevel) for v in ds_combined.data_vars} - LOGGER.info('Writing %d tracks to %s', self.size, file_name) - ds_combined.to_netcdf(file_name, encoding=encoding) + encoding = {v: dict(zlib=True, complevel=complevel) for v in ds_combined.data_vars} + LOGGER.info('Writing %d tracks to %s', self.size, file_name) + ds_combined.to_netcdf(file_name, encoding=encoding) @classmethod def from_hdf5(cls, file_name): @@ -1396,34 +1405,42 @@ def from_hdf5(cls, file_name): tracks : TCTracks TCTracks with data from the given HDF5 file. """ - _raise_if_legacy_or_unknown_hdf5_format(file_name) - ds_combined = xr.open_dataset(file_name) - - # when writing ' Date: Tue, 11 Jul 2023 17:46:04 +0200 Subject: [PATCH 2/3] regression test: fix misconfiguration --- script/jenkins/petals_regression_test/Jenkinsfile | 3 +++ script/jenkins/set_config.py | 12 ++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 script/jenkins/set_config.py diff --git a/script/jenkins/petals_regression_test/Jenkinsfile b/script/jenkins/petals_regression_test/Jenkinsfile index f373e04e89..d2257fe432 100644 --- a/script/jenkins/petals_regression_test/Jenkinsfile +++ b/script/jenkins/petals_regression_test/Jenkinsfile @@ -11,6 +11,9 @@ pipeline { source activate climada_env pip install -e ~/jobs/petals_install_env/workspace/ + cp ~/jobs/petals_install_env/workspace/climada.conf ./climada_conf + python script/jenkins/set_config.py test_directory ~/jobs/petals_install_env/workspace/climada_petals + pytest --junitxml=tests_xml/tests.xml ~/jobs/petals_install_env/workspace/climada_petals ''' } diff --git a/script/jenkins/set_config.py b/script/jenkins/set_config.py new file mode 100644 index 0000000000..406eabb5e9 --- /dev/null +++ b/script/jenkins/set_config.py @@ -0,0 +1,12 @@ +import sys +import json + +key = sys.argv[1] +val = sys.argv[2] +jsonfile = 'climada.conf' + +with open(jsonfile, encoding='UTF-8') as inf: + data = json.load(inf) +data[key] = val +with open(jsonfile, 'w', encoding='UTF-8') as outf: + json.dump(data, outf) From d2d4f1f49cc884c7e28ecbcd1beb56d2985f55d9 Mon Sep 17 00:00:00 2001 From: emanuel-schmid Date: Wed, 12 Jul 2023 10:28:47 +0200 Subject: [PATCH 3/3] fix typo --- script/jenkins/install_env.sh | 2 ++ script/jenkins/petals_regression_test/Jenkinsfile | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/script/jenkins/install_env.sh b/script/jenkins/install_env.sh index 3a6045144a..c3ab7f150a 100644 --- a/script/jenkins/install_env.sh +++ b/script/jenkins/install_env.sh @@ -5,5 +5,7 @@ mamba env create -f requirements/env_climada.yml --name climada_env source activate climada_env python -m pip install -e "./[test]" + make install_test + conda deactivate diff --git a/script/jenkins/petals_regression_test/Jenkinsfile b/script/jenkins/petals_regression_test/Jenkinsfile index d2257fe432..22b3bef5b2 100644 --- a/script/jenkins/petals_regression_test/Jenkinsfile +++ b/script/jenkins/petals_regression_test/Jenkinsfile @@ -11,10 +11,12 @@ pipeline { source activate climada_env pip install -e ~/jobs/petals_install_env/workspace/ - cp ~/jobs/petals_install_env/workspace/climada.conf ./climada_conf + cp ~/jobs/petals_install_env/workspace/climada.conf climada.conf python script/jenkins/set_config.py test_directory ~/jobs/petals_install_env/workspace/climada_petals pytest --junitxml=tests_xml/tests.xml ~/jobs/petals_install_env/workspace/climada_petals + + git checkout climada.conf ''' } }