Feature/hail tutorial #1275
Feature/hail tutorial #1275
26 fail, 1 skipped, 783 pass in 5m 7s
Annotations
Check warning on line 0 in climada.engine.test.test_cost_benefit.TestSteps
github-actions / Core / Unit Test Results (3.12)
test_calc_cb_change_pass (climada.engine.test.test_cost_benefit.TestSteps) failed
tests_xml/tests.xml [took 0s]
Raw output
TypeError: only 0-dimensional arrays can be converted to Python scalars
self = <climada.engine.test.test_cost_benefit.TestSteps testMethod=test_calc_cb_change_pass>
def test_calc_cb_change_pass(self):
"""Test _calc_cost_benefit with present value against reference value"""
hazard = Hazard.from_hdf5(HAZ_TEST_TC)
> entity = Entity.from_mat(ENT_TEST_MAT)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
climada/engine/test/test_cost_benefit.py:427:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
climada/entity/entity_def.py:99: in from_mat
exposures=Exposures.from_mat(file_name),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
climada/entity/exposures/base.py:1277: in from_mat
_read_mat_metadata(exp, data, file_name, var_names)
climada/entity/exposures/base.py:1597: in _read_mat_metadata
exposures.value_unit = u_hdf5.get_str_from_ref(
climada/util/hdf5_handler.py:110: in get_str_from_ref
return get_string(file[var])
^^^^^^^^^^^^^^^^^^^^^
climada/util/hdf5_handler.py:92: in get_string
return "".join(chr(int(c)) for c in array)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
.0 = <generator object Dataset.__iter__ at 0x7fdb5b816dc0>
> return "".join(chr(int(c)) for c in array)
^^^^^^
E TypeError: only 0-dimensional arrays can be converted to Python scalars
climada/util/hdf5_handler.py:92: TypeError
Check warning on line 0 in climada.engine.test.test_cost_benefit.TestSteps
github-actions / Core / Unit Test Results (3.12)
test_calc_cb_no_change_pass (climada.engine.test.test_cost_benefit.TestSteps) failed
tests_xml/tests.xml [took 0s]
Raw output
TypeError: only 0-dimensional arrays can be converted to Python scalars
self = <climada.engine.test.test_cost_benefit.TestSteps testMethod=test_calc_cb_no_change_pass>
def test_calc_cb_no_change_pass(self):
"""Test _calc_cost_benefit without present value against reference value"""
hazard = Hazard.from_hdf5(HAZ_TEST_TC)
> entity = Entity.from_mat(ENT_TEST_MAT)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
climada/engine/test/test_cost_benefit.py:369:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
climada/entity/entity_def.py:99: in from_mat
exposures=Exposures.from_mat(file_name),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
climada/entity/exposures/base.py:1277: in from_mat
_read_mat_metadata(exp, data, file_name, var_names)
climada/entity/exposures/base.py:1597: in _read_mat_metadata
exposures.value_unit = u_hdf5.get_str_from_ref(
climada/util/hdf5_handler.py:110: in get_str_from_ref
return get_string(file[var])
^^^^^^^^^^^^^^^^^^^^^
climada/util/hdf5_handler.py:92: in get_string
return "".join(chr(int(c)) for c in array)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
.0 = <generator object Dataset.__iter__ at 0x7fdb5b27d1c0>
> return "".join(chr(int(c)) for c in array)
^^^^^^
E TypeError: only 0-dimensional arrays can be converted to Python scalars
climada/util/hdf5_handler.py:92: TypeError
Check warning on line 0 in climada.engine.test.test_cost_benefit.TestSteps
github-actions / Core / Unit Test Results (3.12)
test_calc_impact_measures_pass (climada.engine.test.test_cost_benefit.TestSteps) failed
tests_xml/tests.xml [took 0s]
Raw output
TypeError: only 0-dimensional arrays can be converted to Python scalars
self = <climada.engine.test.test_cost_benefit.TestSteps testMethod=test_calc_impact_measures_pass>
def test_calc_impact_measures_pass(self):
"""Test _calc_impact_measures against reference value"""
self.assertTrue(HAZ_TEST_TC.is_file(), "{} is not a file".format(HAZ_TEST_TC))
hazard = Hazard.from_hdf5(HAZ_TEST_TC)
self.assertTrue(ENT_TEST_MAT.is_file(), "{} is not a file".format(ENT_TEST_MAT))
> entity = Entity.from_mat(ENT_TEST_MAT)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
climada/engine/test/test_cost_benefit.py:58:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
climada/entity/entity_def.py:99: in from_mat
exposures=Exposures.from_mat(file_name),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
climada/entity/exposures/base.py:1277: in from_mat
_read_mat_metadata(exp, data, file_name, var_names)
climada/entity/exposures/base.py:1597: in _read_mat_metadata
exposures.value_unit = u_hdf5.get_str_from_ref(
climada/util/hdf5_handler.py:110: in get_str_from_ref
return get_string(file[var])
^^^^^^^^^^^^^^^^^^^^^
climada/util/hdf5_handler.py:92: in get_string
return "".join(chr(int(c)) for c in array)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
.0 = <generator object Dataset.__iter__ at 0x7fdb5b27dd20>
> return "".join(chr(int(c)) for c in array)
^^^^^^
E TypeError: only 0-dimensional arrays can be converted to Python scalars
climada/util/hdf5_handler.py:92: TypeError
Check warning on line 0 in climada.engine.unsequa.test.test_unsequa.TestCalcImpact
github-actions / Core / Unit Test Results (3.12)
test_calc_sensitivity_all_pass (climada.engine.unsequa.test.test_unsequa.TestCalcImpact) failed
tests_xml/tests.xml [took 44s]
Raw output
ValueError: setting an array element with a sequence.
TypeError: only 0-dimensional arrays can be converted to Python scalars
The above exception was the direct cause of the following exception:
self = <climada.engine.unsequa.test.test_unsequa.TestCalcImpact testMethod=test_calc_sensitivity_all_pass>
def test_calc_sensitivity_all_pass(self):
"""Test compute sensitivity using all different sensitivity methods"""
# define input_vars
exp_unc, impf_unc, haz_unc = make_input_vars()
# dict to store the parameters and expected results for the tests
test_dict = {
"pawn": {
"sampling_method": "saltelli",
"sampling_kwargs": {},
"N": 4,
"sensitivity_kwargs": {"S": 10, "seed": 12345},
"test_param_name": ["x_exp", 0],
"test_si_name": ["CV", 16],
"test_si_value": [0.25000, 2],
},
"hdmr": {
"sampling_method": "saltelli",
"sampling_kwargs": {},
"N": 100,
"sensitivity_kwargs": {},
"test_param_name": ["x_exp", 2],
"test_si_name": ["Sa", 4],
"test_si_value": [0.004658, 3],
},
"ff": {
"sampling_method": "ff",
"sampling_kwargs": {"seed": 12345},
"N": 4,
"sensitivity_kwargs": {"second_order": True},
"test_param_name": ["x_exp", 0],
"test_si_name": ["IE", 4],
"test_si_value": [865181825.901295, 10],
},
"sobol": {
"sampling_method": "saltelli",
"sampling_kwargs": {},
"N": 4,
"sensitivity_kwargs": {},
"test_param_name": ["x_paa", 5],
"test_si_name": ["ST", 8],
"test_si_value": [0.313025, 10],
},
"dgsm": {
"sampling_method": "finite_diff",
"N": 4,
"sampling_kwargs": {"seed": 12345},
"sensitivity_kwargs": {
"num_resamples": 100,
"conf_level": 0.95,
"seed": 12345,
},
"test_param_name": ["x_exp", 0],
"test_si_name": ["dgsm", 8],
"test_si_value": [1.697516e-01, 9],
},
"fast": {
"sampling_method": "fast_sampler",
"sampling_kwargs": {"M": 4, "seed": 12345},
"N": 256,
"sensitivity_kwargs": {"M": 4, "seed": 12345},
"test_param_name": ["x_exp", 0],
"test_si_name": ["S1_conf", 8],
"test_si_value": [0.671396, 1],
},
"rbd_fast": {
"sampling_method": "saltelli",
"sampling_kwargs": {},
"N": 24,
"sensitivity_kwargs": {"M": 4, "seed": 12345},
"test_param_name": ["x_exp", 0],
"test_si_name": ["S1_conf", 4],
"test_si_value": [0.152609, 4],
},
"morris": {
"sampling_method": "morris",
"sampling_kwargs": {"seed": 12345},
"N": 4,
"sensitivity_kwargs": {},
"test_param_name": ["x_exp", 0],
"test_si_name": ["mu", 1],
"test_si_value": [5066460029.63911, 8],
},
}
def test_sensitivity_method(
exp_unc, impf_unc, haz_unc, sensitivity_method, param_dict, places
):
"""Function to test each seaprate sensitivity method"""
unc_calc = CalcImpact(exp_unc, impf_unc, haz_unc)
unc_data = unc_calc.make_sample(
N=param_dict["N"],
sampling_method=param_dict["sampling_method"],
sampling_kwargs=param_dict["sampling_kwargs"],
)
unc_data = unc_calc.uncertainty(
unc_data, calc_eai_exp=False, calc_at_event=False
)
# Call the sensitivity method with each method's specific arguments
unc_data = unc_calc.sensitivity(
unc_data,
sensitivity_method=sensitivity_method,
sensitivity_kwargs=param_dict["sensitivity_kwargs"],
)
self.assertEqual(
param_dict["test_param_name"][0],
unc_data.aai_agg_sens_df["param"][param_dict["test_param_name"][1]],
)
self.assertEqual(
param_dict["test_si_name"][0],
unc_data.aai_agg_sens_df["si"][param_dict["test_si_name"][1]],
)
self.assertAlmostEqual(
param_dict["test_si_value"][0],
unc_data.aai_agg_sens_df["aai_agg"][param_dict["test_si_value"][1]],
places=places,
)
self.assertEqual(unc_data.aai_agg_unc_df.size, unc_data.n_samples)
self.assertEqual(
unc_data.freq_curve_unc_df.size, unc_data.n_samples * len(unc_calc.rp)
)
self.assertTrue(unc_data.eai_exp_unc_df.empty)
self.assertTrue(unc_data.at_event_unc_df.empty)
# loop over each method and do test
for sensitivity_method, method_params in test_dict.items():
> test_sensitivity_method(
exp_unc,
impf_unc,
haz_unc,
sensitivity_method,
method_params,
places=2 if sensitivity_method == "rbd_fast" else 5,
)
climada/engine/unsequa/test/test_unsequa.py:697:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
climada/engine/unsequa/test/test_unsequa.py:667: in test_sensitivity_method
unc_data = unc_calc.sensitivity(
climada/engine/unsequa/calc_base.py:411: in sensitivity
sens_df = _calc_sens_df(
climada/engine/unsequa/calc_base.py:539: in _calc_sens_df
sens_indices = method.analyze(problem_sa, X, Y, **sensitivity_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
../../../micromamba/envs/climada_env_3.12/lib/python3.12/site-packages/SALib/analyze/hdmr.py:188: in analyze
SA, Em, RT, Y_em, idx = _compute(X, Y, settings, init_vars)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
../../../micromamba/envs/climada_env_3.12/lib/python3.12/site-packages/SALib/analyze/hdmr.py:365: in _compute
SA["S"][:, k], SA["Sa"][:, k], SA["Sb"][:, k] = ancova(
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
Y = array([1.89548304e+09, 6.42604823e+09, 4.86801391e+09, 6.35586800e+09,
2.88326355e+09, 1.99072724e+09, 2.166920...1.57009771e+10, 8.07953352e+09, 4.81638533e+09,
6.22430344e+08, 3.35572391e+09, 1.75075077e+10, 5.70262278e+09])
Y_em = array([[-1.39403327e+09, -3.88839155e+09, -1.92418530e+09, ...,
1.69758737e+08, 7.23023073e+07, -5.33323811e...00132165e+09, -1.38777238e+09, ...,
-1.94470185e+08, 1.48608949e+08, 4.36974645e+07]],
shape=(500, 10))
V_Y = array([6.09973149e+19]), R = 500, n = 10
def ancova(Y, Y_em, V_Y, R, n):
"""Analysis of Covariance."""
# Compute the sum of all Y_em terms
Y0 = np.sum(Y_em, axis=1)
# Initialize each variable
S, S_a, S_b = np.zeros((3, n))
# Analysis of covariance
for j in range(n):
# Covariance matrix of jth term of Y_em and actual Y
C = np.cov(np.stack((Y_em[:, j], Y), axis=0))
# Total sensitivity of jth term ( = Eq. 19 of Li et al )
> S[j] = C[0, 1] / V_Y
^^^^
E ValueError: setting an array element with a sequence.
../../../micromamba/envs/climada_env_3.12/lib/python3.12/site-packages/SALib/analyze/hdmr.py:688: ValueError
Check warning on line 0 in climada.entity.exposures.test.test_mat.TestReader
github-actions / Core / Unit Test Results (3.12)
test_read_demo_pass (climada.entity.exposures.test.test_mat.TestReader) failed
tests_xml/tests.xml [took 0s]
Raw output
TypeError: only 0-dimensional arrays can be converted to Python scalars
self = <climada.entity.exposures.test.test_mat.TestReader testMethod=test_read_demo_pass>
def test_read_demo_pass(self):
"""Read one single excel file"""
# Read demo excel file
> expo = Exposures.from_mat(ENT_TEST_MAT)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
climada/entity/exposures/test/test_mat.py:37:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
climada/entity/exposures/base.py:1277: in from_mat
_read_mat_metadata(exp, data, file_name, var_names)
climada/entity/exposures/base.py:1597: in _read_mat_metadata
exposures.value_unit = u_hdf5.get_str_from_ref(
climada/util/hdf5_handler.py:110: in get_str_from_ref
return get_string(file[var])
^^^^^^^^^^^^^^^^^^^^^
climada/util/hdf5_handler.py:92: in get_string
return "".join(chr(int(c)) for c in array)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
.0 = <generator object Dataset.__iter__ at 0x7fdb595b0e40>
> return "".join(chr(int(c)) for c in array)
^^^^^^
E TypeError: only 0-dimensional arrays can be converted to Python scalars
climada/util/hdf5_handler.py:92: TypeError
Check warning on line 0 in climada.entity.exposures.test.test_mat.TestOptionals
github-actions / Core / Unit Test Results (3.12)
test_no_assigned_pass (climada.entity.exposures.test.test_mat.TestOptionals) failed
tests_xml/tests.xml [took 0s]
Raw output
TypeError: only 0-dimensional arrays can be converted to Python scalars
self = <climada.entity.exposures.test.test_mat.TestOptionals testMethod=test_no_assigned_pass>
def test_no_assigned_pass(self):
"""Not error if no value unit."""
new_var_names = copy.deepcopy(DEF_VAR_MAT)
new_var_names["var_name"]["ass"] = "no valid assign"
> exp = Exposures.from_mat(ENT_TEST_MAT, var_names=new_var_names)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
climada/entity/exposures/test/test_mat.py:149:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
climada/entity/exposures/base.py:1277: in from_mat
_read_mat_metadata(exp, data, file_name, var_names)
climada/entity/exposures/base.py:1597: in _read_mat_metadata
exposures.value_unit = u_hdf5.get_str_from_ref(
climada/util/hdf5_handler.py:110: in get_str_from_ref
return get_string(file[var])
^^^^^^^^^^^^^^^^^^^^^
climada/util/hdf5_handler.py:92: in get_string
return "".join(chr(int(c)) for c in array)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
.0 = <generator object Dataset.__iter__ at 0x7fdb595b2b20>
> return "".join(chr(int(c)) for c in array)
^^^^^^
E TypeError: only 0-dimensional arrays can be converted to Python scalars
climada/util/hdf5_handler.py:92: TypeError
Check warning on line 0 in climada.entity.exposures.test.test_mat.TestOptionals
github-actions / Core / Unit Test Results (3.12)
test_no_category_pass (climada.entity.exposures.test.test_mat.TestOptionals) failed
tests_xml/tests.xml [took 0s]
Raw output
TypeError: only 0-dimensional arrays can be converted to Python scalars
self = <climada.entity.exposures.test.test_mat.TestOptionals testMethod=test_no_category_pass>
def test_no_category_pass(self):
"""Not error if no category id."""
new_var_names = copy.deepcopy(DEF_VAR_MAT)
new_var_names["var_name"]["cat"] = "no valid category"
> exp = Exposures.from_mat(ENT_TEST_MAT, var_names=new_var_names)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
climada/entity/exposures/test/test_mat.py:122:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
climada/entity/exposures/base.py:1277: in from_mat
_read_mat_metadata(exp, data, file_name, var_names)
climada/entity/exposures/base.py:1597: in _read_mat_metadata
exposures.value_unit = u_hdf5.get_str_from_ref(
climada/util/hdf5_handler.py:110: in get_str_from_ref
return get_string(file[var])
^^^^^^^^^^^^^^^^^^^^^
climada/util/hdf5_handler.py:92: in get_string
return "".join(chr(int(c)) for c in array)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
.0 = <generator object Dataset.__iter__ at 0x7fdb5b1faf80>
> return "".join(chr(int(c)) for c in array)
^^^^^^
E TypeError: only 0-dimensional arrays can be converted to Python scalars
climada/util/hdf5_handler.py:92: TypeError
Check warning on line 0 in climada.entity.exposures.test.test_mat.TestOptionals
github-actions / Core / Unit Test Results (3.12)
test_no_refyear_pass (climada.entity.exposures.test.test_mat.TestOptionals) failed
tests_xml/tests.xml [took 0s]
Raw output
TypeError: only 0-dimensional arrays can be converted to Python scalars
self = <climada.entity.exposures.test.test_mat.TestOptionals testMethod=test_no_refyear_pass>
def test_no_refyear_pass(self):
"""Not error if no value unit."""
new_var_names = copy.deepcopy(DEF_VAR_MAT)
new_var_names["var_name"]["ref"] = "no valid ref"
> exp = Exposures.from_mat(ENT_TEST_MAT, var_names=new_var_names)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
climada/entity/exposures/test/test_mat.py:158:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
climada/entity/exposures/base.py:1277: in from_mat
_read_mat_metadata(exp, data, file_name, var_names)
climada/entity/exposures/base.py:1597: in _read_mat_metadata
exposures.value_unit = u_hdf5.get_str_from_ref(
climada/util/hdf5_handler.py:110: in get_str_from_ref
return get_string(file[var])
^^^^^^^^^^^^^^^^^^^^^
climada/util/hdf5_handler.py:92: in get_string
return "".join(chr(int(c)) for c in array)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
.0 = <generator object Dataset.__iter__ at 0x7fdb5b1fb680>
> return "".join(chr(int(c)) for c in array)
^^^^^^
E TypeError: only 0-dimensional arrays can be converted to Python scalars
climada/util/hdf5_handler.py:92: TypeError
Check warning on line 0 in climada.entity.exposures.test.test_mat.TestOptionals
github-actions / Core / Unit Test Results (3.12)
test_no_region_pass (climada.entity.exposures.test.test_mat.TestOptionals) failed
tests_xml/tests.xml [took 0s]
Raw output
TypeError: only 0-dimensional arrays can be converted to Python scalars
self = <climada.entity.exposures.test.test_mat.TestOptionals testMethod=test_no_region_pass>
def test_no_region_pass(self):
"""Not error if no region id."""
new_var_names = copy.deepcopy(DEF_VAR_MAT)
new_var_names["var_name"]["reg"] = "no valid region"
> exp = Exposures.from_mat(ENT_TEST_MAT, var_names=new_var_names)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
climada/entity/exposures/test/test_mat.py:131:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
climada/entity/exposures/base.py:1277: in from_mat
_read_mat_metadata(exp, data, file_name, var_names)
climada/entity/exposures/base.py:1597: in _read_mat_metadata
exposures.value_unit = u_hdf5.get_str_from_ref(
climada/util/hdf5_handler.py:110: in get_str_from_ref
return get_string(file[var])
^^^^^^^^^^^^^^^^^^^^^
climada/util/hdf5_handler.py:92: in get_string
return "".join(chr(int(c)) for c in array)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
.0 = <generator object Dataset.__iter__ at 0x7fdb595b1c40>
> return "".join(chr(int(c)) for c in array)
^^^^^^
E TypeError: only 0-dimensional arrays can be converted to Python scalars
climada/util/hdf5_handler.py:92: TypeError
Check warning on line 0 in climada.entity.impact_funcs.test.test_imp_fun_set.TestReaderMat
github-actions / Core / Unit Test Results (3.12)
test_demo_file_pass (climada.entity.impact_funcs.test.test_imp_fun_set.TestReaderMat) failed
tests_xml/tests.xml [took 0s]
Raw output
TypeError: only 0-dimensional arrays can be converted to Python scalars
self = <climada.entity.impact_funcs.test.test_imp_fun_set.TestReaderMat testMethod=test_demo_file_pass>
def test_demo_file_pass(self):
"""Read demo excel file"""
# Read demo mat file
> imp_funcs = ImpactFuncSet.from_mat(ENT_TEST_MAT)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
climada/entity/impact_funcs/test/test_imp_fun_set.py:428:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
climada/entity/impact_funcs/impact_func_set.py:499: in from_mat
funcs_idx = _get_hdf5_funcs(imp, file_name, var_names)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
climada/entity/impact_funcs/impact_func_set.py:471: in _get_hdf5_funcs
type_str = u_hdf5.get_str_from_ref(file_name, fun_type)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
climada/util/hdf5_handler.py:110: in get_str_from_ref
return get_string(file[var])
^^^^^^^^^^^^^^^^^^^^^
climada/util/hdf5_handler.py:92: in get_string
return "".join(chr(int(c)) for c in array)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
.0 = <generator object Dataset.__iter__ at 0x7fdb595b0e40>
> return "".join(chr(int(c)) for c in array)
^^^^^^
E TypeError: only 0-dimensional arrays can be converted to Python scalars
climada/util/hdf5_handler.py:92: TypeError
Check warning on line 0 in climada.entity.measures.test.test_base.TestApply
github-actions / Core / Unit Test Results (3.12)
test_apply_ref_pass (climada.entity.measures.test.test_base.TestApply) failed
tests_xml/tests.xml [took 0s]
Raw output
TypeError: only 0-dimensional arrays can be converted to Python scalars
self = <climada.entity.measures.test.test_base.TestApply testMethod=test_apply_ref_pass>
def test_apply_ref_pass(self):
"""Test apply method: apply all measures but insurance"""
hazard = Hazard.from_hdf5(HAZ_TEST_TC)
> entity = Entity.from_mat(ENT_TEST_MAT)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
climada/entity/measures/test/test_base.py:492:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
climada/entity/entity_def.py:99: in from_mat
exposures=Exposures.from_mat(file_name),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
climada/entity/exposures/base.py:1277: in from_mat
_read_mat_metadata(exp, data, file_name, var_names)
climada/entity/exposures/base.py:1597: in _read_mat_metadata
exposures.value_unit = u_hdf5.get_str_from_ref(
climada/util/hdf5_handler.py:110: in get_str_from_ref
return get_string(file[var])
^^^^^^^^^^^^^^^^^^^^^
climada/util/hdf5_handler.py:92: in get_string
return "".join(chr(int(c)) for c in array)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
.0 = <generator object Dataset.__iter__ at 0x7fdb595b0200>
> return "".join(chr(int(c)) for c in array)
^^^^^^
E TypeError: only 0-dimensional arrays can be converted to Python scalars
climada/util/hdf5_handler.py:92: TypeError
Check warning on line 0 in climada.entity.measures.test.test_base.TestApply
github-actions / Core / Unit Test Results (3.12)
test_calc_impact_pass (climada.entity.measures.test.test_base.TestApply) failed
tests_xml/tests.xml [took 0s]
Raw output
TypeError: only 0-dimensional arrays can be converted to Python scalars
self = <climada.entity.measures.test.test_base.TestApply testMethod=test_calc_impact_pass>
def test_calc_impact_pass(self):
"""Test calc_impact method: apply all measures but insurance"""
hazard = Hazard.from_hdf5(HAZ_TEST_TC)
> entity = Entity.from_mat(ENT_TEST_MAT)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
climada/entity/measures/test/test_base.py:599:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
climada/entity/entity_def.py:99: in from_mat
exposures=Exposures.from_mat(file_name),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
climada/entity/exposures/base.py:1277: in from_mat
_read_mat_metadata(exp, data, file_name, var_names)
climada/entity/exposures/base.py:1597: in _read_mat_metadata
exposures.value_unit = u_hdf5.get_str_from_ref(
climada/util/hdf5_handler.py:110: in get_str_from_ref
return get_string(file[var])
^^^^^^^^^^^^^^^^^^^^^
climada/util/hdf5_handler.py:92: in get_string
return "".join(chr(int(c)) for c in array)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
.0 = <generator object Dataset.__iter__ at 0x7fdb595b2b20>
> return "".join(chr(int(c)) for c in array)
^^^^^^
E TypeError: only 0-dimensional arrays can be converted to Python scalars
climada/util/hdf5_handler.py:92: TypeError
Check warning on line 0 in climada.entity.measures.test.test_base.TestApply
github-actions / Core / Unit Test Results (3.12)
test_calc_impact_transf_pass (climada.entity.measures.test.test_base.TestApply) failed
tests_xml/tests.xml [took 0s]
Raw output
TypeError: only 0-dimensional arrays can be converted to Python scalars
self = <climada.entity.measures.test.test_base.TestApply testMethod=test_calc_impact_transf_pass>
def test_calc_impact_transf_pass(self):
"""Test calc_impact method: apply all measures and insurance"""
hazard = Hazard.from_hdf5(HAZ_TEST_TC)
> entity = Entity.from_mat(ENT_TEST_MAT)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
climada/entity/measures/test/test_base.py:633:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
climada/entity/entity_def.py:99: in from_mat
exposures=Exposures.from_mat(file_name),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
climada/entity/exposures/base.py:1277: in from_mat
_read_mat_metadata(exp, data, file_name, var_names)
climada/entity/exposures/base.py:1597: in _read_mat_metadata
exposures.value_unit = u_hdf5.get_str_from_ref(
climada/util/hdf5_handler.py:110: in get_str_from_ref
return get_string(file[var])
^^^^^^^^^^^^^^^^^^^^^
climada/util/hdf5_handler.py:92: in get_string
return "".join(chr(int(c)) for c in array)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
.0 = <generator object Dataset.__iter__ at 0x7fdb5b1f9380>
> return "".join(chr(int(c)) for c in array)
^^^^^^
E TypeError: only 0-dimensional arrays can be converted to Python scalars
climada/util/hdf5_handler.py:92: TypeError
Check warning on line 0 in climada.entity.measures.test.test_base.TestApply
github-actions / Core / Unit Test Results (3.12)
test_change_imp_func_pass (climada.entity.measures.test.test_base.TestApply) failed
tests_xml/tests.xml [took 0s]
Raw output
TypeError: only 0-dimensional arrays can be converted to Python scalars
self = <climada.entity.measures.test.test_base.TestApply testMethod=test_change_imp_func_pass>
def test_change_imp_func_pass(self):
"""Test _change_imp_func"""
> meas = MeasureSet.from_mat(ENT_TEST_MAT)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
climada/entity/measures/test/test_base.py:56:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
climada/entity/measures/measure_set.py:444: in from_mat
read_att_mat(meas_set, data, file_name, var_names)
climada/entity/measures/measure_set.py:381: in read_att_mat
color_str = u_hdf5.get_str_from_ref(
climada/util/hdf5_handler.py:110: in get_str_from_ref
return get_string(file[var])
^^^^^^^^^^^^^^^^^^^^^
climada/util/hdf5_handler.py:92: in get_string
return "".join(chr(int(c)) for c in array)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
.0 = <generator object Dataset.__iter__ at 0x7fdb5b1f9000>
> return "".join(chr(int(c)) for c in array)
^^^^^^
E TypeError: only 0-dimensional arrays can be converted to Python scalars
climada/util/hdf5_handler.py:92: TypeError
Check warning on line 0 in climada.entity.measures.test.test_base.TestApply
github-actions / Core / Unit Test Results (3.12)
test_cutoff_hazard_pass (climada.entity.measures.test.test_base.TestApply) failed
tests_xml/tests.xml [took 0s]
Raw output
TypeError: only 0-dimensional arrays can be converted to Python scalars
self = <climada.entity.measures.test.test_base.TestApply testMethod=test_cutoff_hazard_pass>
def test_cutoff_hazard_pass(self):
"""Test _cutoff_hazard_damage"""
> meas = MeasureSet.from_mat(ENT_TEST_MAT)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
climada/entity/measures/test/test_base.py:140:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
climada/entity/measures/measure_set.py:444: in from_mat
read_att_mat(meas_set, data, file_name, var_names)
climada/entity/measures/measure_set.py:381: in read_att_mat
color_str = u_hdf5.get_str_from_ref(
climada/util/hdf5_handler.py:110: in get_str_from_ref
return get_string(file[var])
^^^^^^^^^^^^^^^^^^^^^
climada/util/hdf5_handler.py:92: in get_string
return "".join(chr(int(c)) for c in array)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
.0 = <generator object Dataset.__iter__ at 0x7fdb5b1fbae0>
> return "".join(chr(int(c)) for c in array)
^^^^^^
E TypeError: only 0-dimensional arrays can be converted to Python scalars
climada/util/hdf5_handler.py:92: TypeError
Check warning on line 0 in climada.entity.measures.test.test_base.TestApply
github-actions / Core / Unit Test Results (3.12)
test_cutoff_hazard_region_pass (climada.entity.measures.test.test_base.TestApply) failed
tests_xml/tests.xml [took 0s]
Raw output
TypeError: only 0-dimensional arrays can be converted to Python scalars
self = <climada.entity.measures.test.test_base.TestApply testMethod=test_cutoff_hazard_region_pass>
def test_cutoff_hazard_region_pass(self):
"""Test _cutoff_hazard_damage in specific region"""
> meas = MeasureSet.from_mat(ENT_TEST_MAT)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
climada/entity/measures/test/test_base.py:176:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
climada/entity/measures/measure_set.py:444: in from_mat
read_att_mat(meas_set, data, file_name, var_names)
climada/entity/measures/measure_set.py:381: in read_att_mat
color_str = u_hdf5.get_str_from_ref(
climada/util/hdf5_handler.py:110: in get_str_from_ref
return get_string(file[var])
^^^^^^^^^^^^^^^^^^^^^
climada/util/hdf5_handler.py:92: in get_string
return "".join(chr(int(c)) for c in array)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
.0 = <generator object Dataset.__iter__ at 0x7fdb595b0660>
> return "".join(chr(int(c)) for c in array)
^^^^^^
E TypeError: only 0-dimensional arrays can be converted to Python scalars
climada/util/hdf5_handler.py:92: TypeError
Check warning on line 0 in climada.entity.measures.test.test_base.TestApply
github-actions / Core / Unit Test Results (3.12)
test_filter_exposures_pass (climada.entity.measures.test.test_base.TestApply) failed
tests_xml/tests.xml [took 0s]
Raw output
TypeError: only 0-dimensional arrays can be converted to Python scalars
self = <climada.entity.measures.test.test_base.TestApply testMethod=test_filter_exposures_pass>
def test_filter_exposures_pass(self):
"""Test _filter_exposures method with two values"""
meas = Measure(
exp_region_id=[3, 4],
haz_type="TC",
)
> exp = Exposures.from_mat(ENT_TEST_MAT)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
climada/entity/measures/test/test_base.py:317:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
climada/entity/exposures/base.py:1277: in from_mat
_read_mat_metadata(exp, data, file_name, var_names)
climada/entity/exposures/base.py:1597: in _read_mat_metadata
exposures.value_unit = u_hdf5.get_str_from_ref(
climada/util/hdf5_handler.py:110: in get_str_from_ref
return get_string(file[var])
^^^^^^^^^^^^^^^^^^^^^
climada/util/hdf5_handler.py:92: in get_string
return "".join(chr(int(c)) for c in array)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
.0 = <generator object Dataset.__iter__ at 0x7fdb5b1f82e0>
> return "".join(chr(int(c)) for c in array)
^^^^^^
E TypeError: only 0-dimensional arrays can be converted to Python scalars
climada/util/hdf5_handler.py:92: TypeError
Check warning on line 0 in climada.entity.measures.test.test_meas_set.TestReaderMat
github-actions / Core / Unit Test Results (3.12)
test_demo_file (climada.entity.measures.test.test_meas_set.TestReaderMat) failed
tests_xml/tests.xml [took 0s]
Raw output
TypeError: only 0-dimensional arrays can be converted to Python scalars
self = <climada.entity.measures.test.test_meas_set.TestReaderMat testMethod=test_demo_file>
def test_demo_file(self):
# Read demo excel file
> meas = MeasureSet.from_mat(ENT_TEST_MAT)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
climada/entity/measures/test/test_meas_set.py:477:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
climada/entity/measures/measure_set.py:444: in from_mat
read_att_mat(meas_set, data, file_name, var_names)
climada/entity/measures/measure_set.py:381: in read_att_mat
color_str = u_hdf5.get_str_from_ref(
climada/util/hdf5_handler.py:110: in get_str_from_ref
return get_string(file[var])
^^^^^^^^^^^^^^^^^^^^^
climada/util/hdf5_handler.py:92: in get_string
return "".join(chr(int(c)) for c in array)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
.0 = <generator object Dataset.__iter__ at 0x7fdb5b1f9a80>
> return "".join(chr(int(c)) for c in array)
^^^^^^
E TypeError: only 0-dimensional arrays can be converted to Python scalars
climada/util/hdf5_handler.py:92: TypeError
Check warning on line 0 in climada.entity.test.test_entity.TestReader
github-actions / Core / Unit Test Results (3.12)
test_from_mat (climada.entity.test.test_entity.TestReader) failed
tests_xml/tests.xml [took 0s]
Raw output
TypeError: only 0-dimensional arrays can be converted to Python scalars
self = <climada.entity.test.test_entity.TestReader testMethod=test_from_mat>
def test_from_mat(self):
"""Read entity from mat file produced by climada."""
> entity_mat = Entity.from_mat(ENT_TEST_MAT)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
climada/entity/test/test_entity.py:62:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
climada/entity/entity_def.py:99: in from_mat
exposures=Exposures.from_mat(file_name),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
climada/entity/exposures/base.py:1277: in from_mat
_read_mat_metadata(exp, data, file_name, var_names)
climada/entity/exposures/base.py:1597: in _read_mat_metadata
exposures.value_unit = u_hdf5.get_str_from_ref(
climada/util/hdf5_handler.py:110: in get_str_from_ref
return get_string(file[var])
^^^^^^^^^^^^^^^^^^^^^
climada/util/hdf5_handler.py:92: in get_string
return "".join(chr(int(c)) for c in array)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
.0 = <generator object Dataset.__iter__ at 0x7fdb5b1f82e0>
> return "".join(chr(int(c)) for c in array)
^^^^^^
E TypeError: only 0-dimensional arrays can be converted to Python scalars
climada/util/hdf5_handler.py:92: TypeError
Check warning on line 0 in climada.hazard.test.test_tc_tracks_synth.TestDecay
github-actions / Core / Unit Test Results (3.12)
test_decay_end_ocean (climada.hazard.test.test_tc_tracks_synth.TestDecay) failed
tests_xml/tests.xml [took 0s]
Raw output
TypeError: only 0-dimensional arrays can be converted to Python scalars
self = <climada.hazard.test.test_tc_tracks_synth.TestDecay testMethod=test_decay_end_ocean>
def test_decay_end_ocean(self):
"""Test decay is applied after landfall if the track ends over the ocean"""
# this track was generated without applying landfall decay
# (i.e. with decay=False in tc_synth.calc_perturbed_trajectories)
tracks_synth_nodecay_example = tc.TCTracks.from_netcdf(
TEST_TRACK_DECAY_END_OCEAN
)
# apply landfall decay
extent = tracks_synth_nodecay_example.get_extent()
land_geom = climada.util.coordinates.get_land_geometry(
extent=extent, resolution=10
)
> tracks_synth_nodecay_example.data = tc_synth._apply_land_decay(
tracks_synth_nodecay_example.data,
tc_synth.LANDFALL_DECAY_V,
tc_synth.LANDFALL_DECAY_P,
land_geom,
)
climada/hazard/test/test_tc_tracks_synth.py:462:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
climada/hazard/tc_tracks_synth.py:749: in _apply_land_decay
_apply_decay_coeffs(track, v_rel, p_rel, land_geom, s_rel)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
track = <xarray.Dataset> Size: 10kB
Dimensions: (time: 111)
Coordinates:
* time (time) da... data_provider: ibtracs_usa
id_no: 1997018111059.03
category: 4
v_rel = {-1: 0.00012859077693295416, 0: 0.0017226346292718126, 1: 0.002309772914350468, 2: 0.0025968221565522698, ...}
p_rel = {-1: (1.0088807492745373, 0.002117478217863062), 0: (1.0192813768091684, 0.003068578025845065), 1: (1.0362982218631644, 0.003620816186262243), 2: (1.0468630800617038, 0.004067381088015585), ...}
land_geom = <MULTIPOLYGON (((32.954 -26.079, 32.955 -26.106, 32.931 -26.256, 32.931 -26....>
s_rel = True
def _apply_decay_coeffs(track, v_rel, p_rel, land_geom, s_rel):
"""Change track's max sustained wind and central pressure using the land
decay coefficients.
Parameters
----------
track : xr.Dataset
TC track
v_rel : dict
{category: A}, where wind decay = exp(-x*A)
p_rel : dict
(category: (S, B)},
where pressure decay = S-(S-1)*exp(-x*B)
land_geom : shapely.geometry.multipolygon.MultiPolygon
land geometry
s_rel : bool
use environmental presure for S value (true) or
central presure (false)
Returns
-------
xr.Dataset
"""
# pylint: disable=protected-access
# return if historical track
if track.orig_event_flag:
return track
climada.hazard.tc_tracks.track_land_params(track, land_geom)
sea_land_idx, land_sea_idx = climada.hazard.tc_tracks._get_landfall_idx(track)
if not sea_land_idx.size:
return track
for idx, (sea_land, land_sea) in enumerate(zip(sea_land_idx, land_sea_idx)):
v_landfall = track["max_sustained_wind"][sea_land - 1].values
p_landfall = float(track["central_pressure"][sea_land - 1].values)
ss_scale = climada.hazard.tc_tracks.set_category(
v_landfall, track.attrs["max_sustained_wind_unit"]
)
if land_sea - sea_land == 1:
continue
S = _calc_decay_ps_value(track, p_landfall, land_sea - 1, s_rel)
if S <= 1:
# central_pressure at start of landfall > env_pres after landfall:
# set central_pressure to environmental pressure during whole lf
track["central_pressure"][sea_land:land_sea] = track[
"environmental_pressure"
][sea_land:land_sea]
else:
p_decay = _decay_p_function(
S, p_rel[ss_scale][1], track["dist_since_lf"][sea_land:land_sea].values
)
# dont apply decay if it would decrease central pressure
if np.any(p_decay < 1):
LOGGER.info(
"Landfall decay would decrease pressure for "
"track id %s, leading to an intensification "
"of the Tropical Cyclone. This behaviour is "
"unphysical and therefore landfall decay is not "
"applied in this case.",
track.sid,
)
p_decay[p_decay < 1] = (
track["central_pressure"][sea_land:land_sea][p_decay < 1]
/ p_landfall
)
track["central_pressure"][sea_land:land_sea] = p_landfall * p_decay
v_decay = _decay_v_function(
v_rel[ss_scale], track["dist_since_lf"][sea_land:land_sea].values
)
# dont apply decay if it would increase wind speeds
if np.any(v_decay > 1):
# should not happen unless v_rel is negative
LOGGER.info(
"Landfall decay would increase wind speed for "
"track id %s. This behavious in unphysical and "
"therefore landfall decay is not applied in this "
"case.",
track["sid"],
)
v_decay[v_decay > 1] = (
track["max_sustained_wind"][sea_land:land_sea][v_decay > 1] / v_landfall
)
track["max_sustained_wind"][sea_land:land_sea] = v_landfall * v_decay
# correct values of sea after a landfall (until next landfall, if any)
if land_sea < track["time"].size:
if idx + 1 < sea_land_idx.size:
# if there is a next landfall, correct until last point before
# reaching land again
end_cor = sea_land_idx[idx + 1]
else:
# if there is no further landfall, correct until the end of
# the track
end_cor = track["time"].size
> rndn = 0.1 * float(np.abs(np.random.normal(size=1) * 5) + 6)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
E TypeError: only 0-dimensional arrays can be converted to Python scalars
climada/hazard/tc_tracks_synth.py:1052: TypeError
Check warning on line 0 in climada.hazard.test.test_tc_tracks_synth.TestDecay
github-actions / Core / Unit Test Results (3.12)
test_decay_penv_gt_pcen (climada.hazard.test.test_tc_tracks_synth.TestDecay) failed
tests_xml/tests.xml [took 0s]
Raw output
TypeError: only 0-dimensional arrays can be converted to Python scalars
self = <climada.hazard.test.test_tc_tracks_synth.TestDecay testMethod=test_decay_penv_gt_pcen>
def test_decay_penv_gt_pcen(self):
"""Test decay is applied if penv at end of landfall < pcen just before landfall"""
# this track was generated without applying landfall decay
# (i.e. with decay=False in tc_synth.calc_perturbed_trajectories)
tracks_synth_nodecay_example = tc.TCTracks.from_netcdf(
TEST_TRACK_DECAY_PENV_GT_PCEN
)
# apply landfall decay
extent = tracks_synth_nodecay_example.get_extent()
land_geom = climada.util.coordinates.get_land_geometry(
extent=extent, resolution=10
)
> tracks_synth_nodecay_example.data = tc_synth._apply_land_decay(
tracks_synth_nodecay_example.data,
tc_synth.LANDFALL_DECAY_V,
tc_synth.LANDFALL_DECAY_P,
land_geom,
)
climada/hazard/test/test_tc_tracks_synth.py:532:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
climada/hazard/tc_tracks_synth.py:749: in _apply_land_decay
_apply_decay_coeffs(track, v_rel, p_rel, land_geom, s_rel)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
track = <xarray.Dataset> Size: 8kB
Dimensions: (time: 93)
Coordinates:
* time (time) date... data_provider: ibtracs_usa
id_no: 1988021112080.02
category: 4
v_rel = {-1: 0.00012859077693295416, 0: 0.0017226346292718126, 1: 0.002309772914350468, 2: 0.0025968221565522698, ...}
p_rel = {-1: (1.0088807492745373, 0.002117478217863062), 0: (1.0192813768091684, 0.003068578025845065), 1: (1.0362982218631644, 0.003620816186262243), 2: (1.0468630800617038, 0.004067381088015585), ...}
land_geom = <MULTIPOLYGON (((44.356 -20.138, 44.415 -20.083, 44.439 -20.055, 44.458 -20....>
s_rel = True
def _apply_decay_coeffs(track, v_rel, p_rel, land_geom, s_rel):
"""Change track's max sustained wind and central pressure using the land
decay coefficients.
Parameters
----------
track : xr.Dataset
TC track
v_rel : dict
{category: A}, where wind decay = exp(-x*A)
p_rel : dict
(category: (S, B)},
where pressure decay = S-(S-1)*exp(-x*B)
land_geom : shapely.geometry.multipolygon.MultiPolygon
land geometry
s_rel : bool
use environmental presure for S value (true) or
central presure (false)
Returns
-------
xr.Dataset
"""
# pylint: disable=protected-access
# return if historical track
if track.orig_event_flag:
return track
climada.hazard.tc_tracks.track_land_params(track, land_geom)
sea_land_idx, land_sea_idx = climada.hazard.tc_tracks._get_landfall_idx(track)
if not sea_land_idx.size:
return track
for idx, (sea_land, land_sea) in enumerate(zip(sea_land_idx, land_sea_idx)):
v_landfall = track["max_sustained_wind"][sea_land - 1].values
p_landfall = float(track["central_pressure"][sea_land - 1].values)
ss_scale = climada.hazard.tc_tracks.set_category(
v_landfall, track.attrs["max_sustained_wind_unit"]
)
if land_sea - sea_land == 1:
continue
S = _calc_decay_ps_value(track, p_landfall, land_sea - 1, s_rel)
if S <= 1:
# central_pressure at start of landfall > env_pres after landfall:
# set central_pressure to environmental pressure during whole lf
track["central_pressure"][sea_land:land_sea] = track[
"environmental_pressure"
][sea_land:land_sea]
else:
p_decay = _decay_p_function(
S, p_rel[ss_scale][1], track["dist_since_lf"][sea_land:land_sea].values
)
# dont apply decay if it would decrease central pressure
if np.any(p_decay < 1):
LOGGER.info(
"Landfall decay would decrease pressure for "
"track id %s, leading to an intensification "
"of the Tropical Cyclone. This behaviour is "
"unphysical and therefore landfall decay is not "
"applied in this case.",
track.sid,
)
p_decay[p_decay < 1] = (
track["central_pressure"][sea_land:land_sea][p_decay < 1]
/ p_landfall
)
track["central_pressure"][sea_land:land_sea] = p_landfall * p_decay
v_decay = _decay_v_function(
v_rel[ss_scale], track["dist_since_lf"][sea_land:land_sea].values
)
# dont apply decay if it would increase wind speeds
if np.any(v_decay > 1):
# should not happen unless v_rel is negative
LOGGER.info(
"Landfall decay would increase wind speed for "
"track id %s. This behavious in unphysical and "
"therefore landfall decay is not applied in this "
"case.",
track["sid"],
)
v_decay[v_decay > 1] = (
track["max_sustained_wind"][sea_land:land_sea][v_decay > 1] / v_landfall
)
track["max_sustained_wind"][sea_land:land_sea] = v_landfall * v_decay
# correct values of sea after a landfall (until next landfall, if any)
if land_sea < track["time"].size:
if idx + 1 < sea_land_idx.size:
# if there is a next landfall, correct until last point before
# reaching land again
end_cor = sea_land_idx[idx + 1]
else:
# if there is no further landfall, correct until the end of
# the track
end_cor = track["time"].size
> rndn = 0.1 * float(np.abs(np.random.normal(size=1) * 5) + 6)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
E TypeError: only 0-dimensional arrays can be converted to Python scalars
climada/hazard/tc_tracks_synth.py:1052: TypeError
Check warning on line 0 in climada.hazard.test.test_tc_tracks_synth.TestDecay
github-actions / Core / Unit Test Results (3.12)
test_wrong_decay_pass (climada.hazard.test.test_tc_tracks_synth.TestDecay) failed
tests_xml/tests.xml [took 1s]
Raw output
TypeError: only 0-dimensional arrays can be converted to Python scalars
self = <climada.hazard.test.test_tc_tracks_synth.TestDecay testMethod=test_wrong_decay_pass>
def test_wrong_decay_pass(self):
"""Test decay not implemented when coefficient < 1"""
track = tc.TCTracks.from_ibtracs_netcdf(
provider="usa", storm_id="1975178N28281"
)
track_gen = track.data[0]
# fmt: off
track_gen["lat"] = np.array(
[
28.20340431, 28.7915261, 29.38642458, 29.97836984, 30.56844404,
31.16265292, 31.74820301, 32.34449825, 32.92261894, 33.47430891,
34.01492525, 34.56789399, 35.08810845, 35.55965893, 35.94835174,
36.29355848, 36.45379561, 36.32473812, 36.07552209, 35.92224784,
35.84144186, 35.78298537, 35.86090718, 36.02440372, 36.37555559,
37.06207765, 37.73197352, 37.97524273, 38.05560287, 38.21901208,
38.31486156, 38.30813367, 38.28481808, 38.28410366, 38.25894812,
38.20583372, 38.22741099, 38.39970022, 38.68367797, 39.08329904,
39.41434629, 39.424984, 39.31327716, 39.30336335, 39.31714429,
39.27031932, 39.30848775, 39.48759833, 39.73326595, 39.96187967,
40.26954226, 40.76882202, 41.40398607, 41.93809726, 42.60395785,
43.57074792, 44.63816143, 45.61450458, 46.68528511, 47.89209365,
49.15580502,
]
)
track_gen["lon"] = np.array(
[
-79.20514075, -79.25243311, -79.28393082, -79.32324646, -79.36668585,
-79.41495519, -79.45198688, -79.40580325, -79.34965443, -79.36938122,
-79.30294825, -79.06809546, -78.70281969, -78.29418936, -77.82170609,
-77.30034709, -76.79004969, -76.37038827, -75.98641014, -75.58383356,
-75.18310414, -74.7974524, -74.3797645, -73.86393572, -73.37910948,
-73.01059003, -72.77051313, -72.68011328, -72.66864779, -72.62579773,
-72.56307717, -72.46607618, -72.35871353, -72.31120649, -72.15537583,
-71.75577051, -71.25287498, -70.75527907, -70.34788946, -70.17518421,
-70.04446577, -69.76582749, -69.44372386, -69.15881376, -68.84351922,
-68.47890287, -68.04184565, -67.53541437, -66.94008642, -66.25596075,
-65.53496635, -64.83491802, -64.12962685, -63.54118808, -62.72934383,
-61.34915091, -59.72580755, -58.24404252, -56.71972992, -55.0809336,
-53.31524758,
]
)
# fmt: on
v_rel = {
1: 0.002249541544102336,
-1: 0.00046889526284203036,
2: 0.002649273787364977,
0: 0.0016426186150461349,
3: 0.00246400811445618,
5: 0.0030442198547309075,
4: 0.002346537842810565,
}
p_rel = {
1: (1.028420239620591, 0.003174733355067952),
-1: (1.0046803184177564, 0.0007997633912500546),
2: (1.0498749735343516, 0.0034665588904747515),
0: (1.0140127424090262, 0.002131858515233042),
3: (1.0619445995372885, 0.003467268426139696),
5: (1.0894914184297835, 0.004315034379018768),
4: (1.0714354641894077, 0.002783787561718677),
}
track_gen.attrs["orig_event_flag"] = False
cp_ref = np.array([1012.0, 1012.0])
single_track = tc.TCTracks([track_gen])
extent = single_track.get_extent()
land_geom = climada.util.coordinates.get_land_geometry(
extent=extent, resolution=10
)
> track_res = tc_synth._apply_decay_coeffs(
track_gen, v_rel, p_rel, land_geom, True
)
climada/hazard/test/test_tc_tracks_synth.py:444:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
track = <xarray.Dataset> Size: 4kB
Dimensions: (time: 61, lat: 61, lon: 61)
Coordinates:
* time ...name: AMY
sid: 1975178N28281
id_no: 1975178028281.0
v_rel = {-1: 0.00046889526284203036, 0: 0.0016426186150461349, 1: 0.002249541544102336, 2: 0.002649273787364977, ...}
p_rel = {-1: (1.0046803184177564, 0.0007997633912500546), 0: (1.0140127424090262, 0.002131858515233042), 1: (1.028420239620591, 0.003174733355067952), 2: (1.0498749735343516, 0.0034665588904747515), ...}
land_geom = <MULTIPOLYGON (((-79.338 33.066, -79.336 33.065, -79.335 33.063, -79.337 33....>
s_rel = True
def _apply_decay_coeffs(track, v_rel, p_rel, land_geom, s_rel):
"""Change track's max sustained wind and central pressure using the land
decay coefficients.
Parameters
----------
track : xr.Dataset
TC track
v_rel : dict
{category: A}, where wind decay = exp(-x*A)
p_rel : dict
(category: (S, B)},
where pressure decay = S-(S-1)*exp(-x*B)
land_geom : shapely.geometry.multipolygon.MultiPolygon
land geometry
s_rel : bool
use environmental presure for S value (true) or
central presure (false)
Returns
-------
xr.Dataset
"""
# pylint: disable=protected-access
# return if historical track
if track.orig_event_flag:
return track
climada.hazard.tc_tracks.track_land_params(track, land_geom)
sea_land_idx, land_sea_idx = climada.hazard.tc_tracks._get_landfall_idx(track)
if not sea_land_idx.size:
return track
for idx, (sea_land, land_sea) in enumerate(zip(sea_land_idx, land_sea_idx)):
v_landfall = track["max_sustained_wind"][sea_land - 1].values
p_landfall = float(track["central_pressure"][sea_land - 1].values)
ss_scale = climada.hazard.tc_tracks.set_category(
v_landfall, track.attrs["max_sustained_wind_unit"]
)
if land_sea - sea_land == 1:
continue
S = _calc_decay_ps_value(track, p_landfall, land_sea - 1, s_rel)
if S <= 1:
# central_pressure at start of landfall > env_pres after landfall:
# set central_pressure to environmental pressure during whole lf
track["central_pressure"][sea_land:land_sea] = track[
"environmental_pressure"
][sea_land:land_sea]
else:
p_decay = _decay_p_function(
S, p_rel[ss_scale][1], track["dist_since_lf"][sea_land:land_sea].values
)
# dont apply decay if it would decrease central pressure
if np.any(p_decay < 1):
LOGGER.info(
"Landfall decay would decrease pressure for "
"track id %s, leading to an intensification "
"of the Tropical Cyclone. This behaviour is "
"unphysical and therefore landfall decay is not "
"applied in this case.",
track.sid,
)
p_decay[p_decay < 1] = (
track["central_pressure"][sea_land:land_sea][p_decay < 1]
/ p_landfall
)
track["central_pressure"][sea_land:land_sea] = p_landfall * p_decay
v_decay = _decay_v_function(
v_rel[ss_scale], track["dist_since_lf"][sea_land:land_sea].values
)
# dont apply decay if it would increase wind speeds
if np.any(v_decay > 1):
# should not happen unless v_rel is negative
LOGGER.info(
"Landfall decay would increase wind speed for "
"track id %s. This behavious in unphysical and "
"therefore landfall decay is not applied in this "
"case.",
track["sid"],
)
v_decay[v_decay > 1] = (
track["max_sustained_wind"][sea_land:land_sea][v_decay > 1] / v_landfall
)
track["max_sustained_wind"][sea_land:land_sea] = v_landfall * v_decay
# correct values of sea after a landfall (until next landfall, if any)
if land_sea < track["time"].size:
if idx + 1 < sea_land_idx.size:
# if there is a next landfall, correct until last point before
# reaching land again
end_cor = sea_land_idx[idx + 1]
else:
# if there is no further landfall, correct until the end of
# the track
end_cor = track["time"].size
> rndn = 0.1 * float(np.abs(np.random.normal(size=1) * 5) + 6)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
E TypeError: only 0-dimensional arrays can be converted to Python scalars
climada/hazard/tc_tracks_synth.py:1052: TypeError
Check warning on line 0 in climada.hazard.test.test_tc_tracks_synth.TestSynth
github-actions / Core / Unit Test Results (3.12)
test_random_walk_single_point (climada.hazard.test.test_tc_tracks_synth.TestSynth) failed
tests_xml/tests.xml [took 2s]
Raw output
TypeError: only 0-dimensional arrays can be converted to Python scalars
self = <climada.hazard.test.test_tc_tracks_synth.TestSynth testMethod=test_random_walk_single_point>
def test_random_walk_single_point(self):
found = False
for year in range(1951, 1981):
tc_track = tc.TCTracks.from_ibtracs_netcdf(
provider="usa", year_range=(year, year), discard_single_points=False
)
singlept = np.where([x["time"].size == 1 for x in tc_track.data])[0]
found = len(singlept) > 0
if found:
# found a case with a single-point track, keep max three tracks for efficiency
tc_track.data = tc_track.data[max(0, singlept[0] - 1) : singlept[0] + 2]
n_tr = tc_track.size
tc_track.equal_timestep()
> tc_track.calc_perturbed_trajectories(nb_synth_tracks=2)
climada/hazard/test/test_tc_tracks_synth.py:770:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
climada/hazard/tc_tracks.py:1690: in calc_perturbed_trajectories
climada.hazard.tc_tracks_synth.calc_perturbed_trajectories(self, **kwargs)
climada/hazard/tc_tracks_synth.py:273: in calc_perturbed_trajectories
tracks.data = _apply_land_decay(
climada/hazard/tc_tracks_synth.py:749: in _apply_land_decay
_apply_decay_coeffs(track, v_rel, p_rel, land_geom, s_rel)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
track = <xarray.Dataset> Size: 11kB
Dimensions: (time: 127)
Coordinates:
* time (time) da... HOW_gen1
sid: 1951272N20274_gen1
id_no: 1951272020274.01
v_rel = {-1: 0.00012859077693295416, 0: 0.0017226346292718126, 1: 0.002309772914350468, 2: 0.0025968221565522698, ...}
p_rel = {-1: (1.0088807492745373, 0.002117478217863062), 0: (1.0192813768091684, 0.003068578025845065), 1: (1.0362982218631644, 0.003620816186262243), 2: (1.0468630800617038, 0.004067381088015585), ...}
land_geom = <MULTIPOLYGON (((-90.347 20.972, -90.36 20.918, -90.378 20.881, -90.381 20.8...>
s_rel = True
def _apply_decay_coeffs(track, v_rel, p_rel, land_geom, s_rel):
"""Change track's max sustained wind and central pressure using the land
decay coefficients.
Parameters
----------
track : xr.Dataset
TC track
v_rel : dict
{category: A}, where wind decay = exp(-x*A)
p_rel : dict
(category: (S, B)},
where pressure decay = S-(S-1)*exp(-x*B)
land_geom : shapely.geometry.multipolygon.MultiPolygon
land geometry
s_rel : bool
use environmental presure for S value (true) or
central presure (false)
Returns
-------
xr.Dataset
"""
# pylint: disable=protected-access
# return if historical track
if track.orig_event_flag:
return track
climada.hazard.tc_tracks.track_land_params(track, land_geom)
sea_land_idx, land_sea_idx = climada.hazard.tc_tracks._get_landfall_idx(track)
if not sea_land_idx.size:
return track
for idx, (sea_land, land_sea) in enumerate(zip(sea_land_idx, land_sea_idx)):
v_landfall = track["max_sustained_wind"][sea_land - 1].values
p_landfall = float(track["central_pressure"][sea_land - 1].values)
ss_scale = climada.hazard.tc_tracks.set_category(
v_landfall, track.attrs["max_sustained_wind_unit"]
)
if land_sea - sea_land == 1:
continue
S = _calc_decay_ps_value(track, p_landfall, land_sea - 1, s_rel)
if S <= 1:
# central_pressure at start of landfall > env_pres after landfall:
# set central_pressure to environmental pressure during whole lf
track["central_pressure"][sea_land:land_sea] = track[
"environmental_pressure"
][sea_land:land_sea]
else:
p_decay = _decay_p_function(
S, p_rel[ss_scale][1], track["dist_since_lf"][sea_land:land_sea].values
)
# dont apply decay if it would decrease central pressure
if np.any(p_decay < 1):
LOGGER.info(
"Landfall decay would decrease pressure for "
"track id %s, leading to an intensification "
"of the Tropical Cyclone. This behaviour is "
"unphysical and therefore landfall decay is not "
"applied in this case.",
track.sid,
)
p_decay[p_decay < 1] = (
track["central_pressure"][sea_land:land_sea][p_decay < 1]
/ p_landfall
)
track["central_pressure"][sea_land:land_sea] = p_landfall * p_decay
v_decay = _decay_v_function(
v_rel[ss_scale], track["dist_since_lf"][sea_land:land_sea].values
)
# dont apply decay if it would increase wind speeds
if np.any(v_decay > 1):
# should not happen unless v_rel is negative
LOGGER.info(
"Landfall decay would increase wind speed for "
"track id %s. This behavious in unphysical and "
"therefore landfall decay is not applied in this "
"case.",
track["sid"],
)
v_decay[v_decay > 1] = (
track["max_sustained_wind"][sea_land:land_sea][v_decay > 1] / v_landfall
)
track["max_sustained_wind"][sea_land:land_sea] = v_landfall * v_decay
# correct values of sea after a landfall (until next landfall, if any)
if land_sea < track["time"].size:
if idx + 1 < sea_land_idx.size:
# if there is a next landfall, correct until last point before
# reaching land again
end_cor = sea_land_idx[idx + 1]
else:
# if there is no further landfall, correct until the end of
# the track
end_cor = track["time"].size
> rndn = 0.1 * float(np.abs(np.random.normal(size=1) * 5) + 6)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
E TypeError: only 0-dimensional arrays can be converted to Python scalars
climada/hazard/tc_tracks_synth.py:1052: TypeError
Check warning on line 0 in climada.util.test.test_hdf5.TestFunc
github-actions / Core / Unit Test Results (3.12)
test_get_list_str_from_ref (climada.util.test.test_hdf5.TestFunc) failed
tests_xml/tests.xml [took 0s]
Raw output
TypeError: only 0-dimensional arrays can be converted to Python scalars
self = <climada.util.test.test_hdf5.TestFunc testMethod=test_get_list_str_from_ref>
def test_get_list_str_from_ref(self):
"""Check import string from a HDF5 object reference"""
with h5py.File(HAZ_DEMO_MAT, "r") as file:
var = file["hazard"]["name"]
> var_list = u_hdf5.get_list_str_from_ref(HAZ_DEMO_MAT, var)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
climada/util/test/test_hdf5.py:96:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
climada/util/hdf5_handler.py:130: in get_list_str_from_ref
name_list.append(get_string(file[name[0]][:]).strip())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
climada/util/hdf5_handler.py:92: in get_string
return "".join(chr(int(c)) for c in array)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
.0 = <iterator object at 0x7fdb63c7cdf0>
> return "".join(chr(int(c)) for c in array)
^^^^^^
E TypeError: only 0-dimensional arrays can be converted to Python scalars
climada/util/hdf5_handler.py:92: TypeError
Check warning on line 0 in climada.util.test.test_hdf5.TestFunc
github-actions / Core / Unit Test Results (3.12)
test_get_str_from_ref (climada.util.test.test_hdf5.TestFunc) failed
tests_xml/tests.xml [took 0s]
Raw output
TypeError: only 0-dimensional arrays can be converted to Python scalars
self = <climada.util.test.test_hdf5.TestFunc testMethod=test_get_str_from_ref>
def test_get_str_from_ref(self):
"""Check import string from a HDF5 object reference"""
with h5py.File(HAZ_DEMO_MAT, "r") as file:
var = file["hazard"]["name"][0][0]
> res = u_hdf5.get_str_from_ref(HAZ_DEMO_MAT, var)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
climada/util/test/test_hdf5.py:89:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
climada/util/hdf5_handler.py:110: in get_str_from_ref
return get_string(file[var])
^^^^^^^^^^^^^^^^^^^^^
climada/util/hdf5_handler.py:92: in get_string
return "".join(chr(int(c)) for c in array)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
.0 = <generator object Dataset.__iter__ at 0x7fdbd345b060>
> return "".join(chr(int(c)) for c in array)
^^^^^^
E TypeError: only 0-dimensional arrays can be converted to Python scalars
climada/util/hdf5_handler.py:92: TypeError