Add functions to compute, plot, store the local hazard exceedence intensity and RP maps #857
GitHub Actions / Core / Unit Test Results (3.9)
failed
Jun 20, 2024 in 0s
3 fail, 662 pass in 8m 2s
Annotations
Check warning on line 0 in climada.hazard.test.test_base.TestSelect
github-actions / Core / Unit Test Results (3.9)
test_select_new_fraction_zero (climada.hazard.test.test_base.TestSelect) failed
tests_xml/tests.xml [took 0s]
Raw output
AssertionError: RuntimeError not raised
self = <climada.hazard.test.test_base.TestSelect testMethod=test_select_new_fraction_zero>
def test_select_new_fraction_zero(self):
"""Check if a new fraction of only zeros is handled correctly"""
hazard = dummy_hazard()
hazard.centroids.gdf["region_id"] = [1, 1, 2]
# Select a part of the hazard where fraction is zero only
with self.assertRaisesRegex(
RuntimeError,
"Your selection created a Hazard object where the fraction matrix is zero "
"everywhere"
):
> hazard.select(event_id=[3, 4], reg_id=[2])
E AssertionError: RuntimeError not raised
climada/hazard/test/test_base.py:608: AssertionError
Check warning on line 0 in climada.hazard.test.test_io.TestReadDefaultNetCDF
github-actions / Core / Unit Test Results (3.9)
test_event_no_time (climada.hazard.test.test_io.TestReadDefaultNetCDF) failed
tests_xml/tests.xml [took 0s]
Raw output
AssertionError: no logs of level WARNING or higher triggered on climada.hazard.io
self = <climada.hazard.test.test_io.TestReadDefaultNetCDF testMethod=test_event_no_time>
def test_event_no_time(self):
"""Test if an event coordinate that is not a time works"""
with xr.open_dataset(self.netcdf_path) as dataset:
size = dataset.sizes["time"]
# Positive integers (interpreted as ordinals)
time = [2, 1]
dataset["time"] = time
hazard = Hazard.from_xarray_raster(dataset, "", "")
self._assert_default_types(hazard)
np.testing.assert_array_equal(
hazard.intensity.toarray(), [[0, 1, 2, 3, 4, 5], [6, 7, 8, 9, 10, 11]]
)
np.testing.assert_array_equal(hazard.date, time)
np.testing.assert_array_equal(hazard.event_name, np.full(size, ""))
# Strings
dataset["time"] = ["a", "b"]
with self.assertLogs("climada.hazard.io", "WARNING") as cm:
hazard = Hazard.from_xarray_raster(dataset, "", "")
np.testing.assert_array_equal(hazard.date, np.ones(size))
> np.testing.assert_array_equal(hazard.event_name, np.full(size, ""))
climada/hazard/test/test_io.py:185:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../../../micromamba/envs/climada_env_3.9/lib/python3.9/unittest/_log.py:67: in __exit__
self._raiseFailure(
E AssertionError: no logs of level WARNING or higher triggered on climada.hazard.io
Check warning on line 0 in climada.hazard.test.test_io.TestHDF5
github-actions / Core / Unit Test Results (3.9)
test_write_read_unsupported_type (climada.hazard.test.test_io.TestHDF5) failed
tests_xml/tests.xml [took 0s]
Raw output
AssertionError: no logs of level WARNING or higher triggered on climada.hazard.io
self = <climada.hazard.test.test_io.TestHDF5 testMethod=test_write_read_unsupported_type>
def test_write_read_unsupported_type(self):
"""Check if the write command correctly handles unsupported types"""
file_name = str(DATA_DIR.joinpath('test_unsupported.h5'))
# Define an unsupported type
class CustomID:
id = 1
# Create a hazard with unsupported type as attribute
hazard = dummy_hazard()
hazard.event_id = CustomID()
# Write the hazard and check the logs for the correct warning
with self.assertLogs(logger="climada.hazard.io", level="WARN") as cm:
> hazard.write_hdf5(file_name)
climada/hazard/test/test_io.py:677:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../../../micromamba/envs/climada_env_3.9/lib/python3.9/unittest/_log.py:67: in __exit__
self._raiseFailure(
E AssertionError: no logs of level WARNING or higher triggered on climada.hazard.io
Loading