-
Notifications
You must be signed in to change notification settings - Fork 149
Description
Describe the bug
When running the method Hazard.local_exceedance_intensity for a hazard I obtain the error ValueError: Value array must be sorted in ascending order.. This is very cryptic and does not allow one to find the solution. This error is raised within the method utils.interpolation.preprocess_and_interpolate_ev.
The error arises because round_to_sig_digits can return floating point errors (e.g., 998.375 -> 1000.0, 1037.065->1000.00001)
Looking at the method utils.interpolation.preprocess_and_interpolate_ev I must say that both docstring and the error messages are all quite cryptic. An error message should not just say what went wrong, but why and what can be done. For example, the message raise ValueError("Both test frequencies and test values are given.") is not very useful. Why is this the case? The docstring does not specify that only either one can be used...
Climada Version: latest (develop branch)
System Information (please complete the following information):
- Operating system and version: on Euler
- Python version: 3.11.6
(to obtain this information execute > import sys >print(sys.version))
Code to reproduce error
test_frequency = np.array([0.2 , 0.05])
frequency = np.array([0.04545455, 0.04545455, 0.04545455, 0.04545455, 0.04545455,
0.04545455, 0.04545455, 0.04545455, 0.04545455, 0.04545455,
0.04545455, 0.04545455, 0.04545455, 0.04545455, 0.04545455,
0.04545455, 0.04545455, 0.04545455, 0.04545455, 0.04545455,
0.04545455, 0.04545455])
values = np.array([ 22.6 , 29.88 , 196.375, 419.1 , 199.52 , 1270.5 ,
0. , 432. , 132.7 , 252.58 , 0. , 998.375,
1037.065, 0. , 1634.2 , 1654.02 , 91.605, 1729.55 ,
56.68 , 929.86 , 0. , 1080.085])
u_interp.preprocess_and_interpolate_ev(
test_frequency,
None,
frequency,
values,
log_frequency=True,
log_values=True,
value_threshold=1,
method='interpolate',
y_asymptotic=0.0,
)
Extra question: is it really wanted to reduce all frequencies to 2 significant leading digits? I.e., 214 -> 210, 10340->1000 ?
Moreover: the rather important parameter n_sig_dig cannot be set in the interpolation method. This is quite strange, as nowhere is the rounding explained, and it is unclear how the choice of 2 affects the results.
More: the problem seems to be resolved by setting n_sig_dig=4. While this is a quick fix, it is completely unclear to me why this works and whether the results will be the same.