Skip to content

Commit b39c65e

Browse files
corrected error in rounding numebrs
1 parent 9597363 commit b39c65e

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

climada/util/interpolation.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def preprocess_and_interpolate_ev(
3737
value_threshold=None,
3838
method="interpolate",
3939
y_asymptotic=np.nan,
40-
n_sig_dig=2,
40+
n_sig_dig=3,
4141
):
4242
"""Wrapper function to first preprocess (frequency, values) data and and then inter- and
4343
extrapolate to test frequencies or test values.
@@ -334,7 +334,7 @@ def _interpolate_small_input(x_test, x_train, y_train, logy, y_asymptotic):
334334
return y_test
335335

336336

337-
def group_frequency(frequency, value, n_sig_dig=2):
337+
def group_frequency(frequency, value, n_sig_dig):
338338
"""
339339
Util function to aggregate (add) frequencies for equal values
340340
@@ -346,7 +346,6 @@ def group_frequency(frequency, value, n_sig_dig=2):
346346
Value array in ascending order
347347
n_sig_dig : int
348348
number of significant digits for value when grouping frequency.
349-
Defaults to 2.
350349
351350
Returns:
352351
------
@@ -388,7 +387,7 @@ def round_to_sig_digits(x, n_sig_dig):
388387
np.array
389388
rounded array
390389
"""
391-
x = np.asarray(x)
392-
x_positive = np.where(np.isfinite(x) & (x != 0), np.abs(x), 10 ** (n_sig_dig - 1))
393-
mags = 10 ** (n_sig_dig - 1 - np.floor(np.log10(x_positive)))
394-
return np.round(x * mags) / mags
390+
391+
return np.vectorize(np.format_float_positional)(
392+
x, precision=n_sig_dig, unique=False, fractional=False, trim="k"
393+
).astype(float)

0 commit comments

Comments
 (0)