-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathutils.py
More file actions
58 lines (45 loc) · 1.35 KB
/
utils.py
File metadata and controls
58 lines (45 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# Copyright (C) 2017-2025 by
# Dominik Traxl <dominik.traxl@posteo.org>
# All rights reserved.
# BSD-3-Clause License.
from collections.abc import Iterable
import numpy as np
def _create_bin_edges(x, bins, log_bins, floor):
xmax = x.max()
xmin = x.min()
if log_bins is False:
if floor is False:
bin_edges = np.linspace(xmin, xmax, bins)
else:
bin_edges = np.unique(np.floor(np.linspace(xmin, xmax, bins)))
bin_edges[-1] = xmax
else:
log_xmin = np.log10(xmin)
log_xmax = np.log10(xmax)
bins = int(np.ceil((log_xmax - log_xmin) * bins))
if floor is False:
bin_edges = np.logspace(log_xmin, log_xmax, bins)
else:
bin_edges = np.unique(np.floor(np.logspace(log_xmin, log_xmax, bins)))
bin_edges[-1] = xmax
return bin_edges
def _dic_translator(x, dic):
x = x.copy()
for i in range(len(x)):
x[i] = dic[x[i]]
return x
def _is_array_like(x):
return isinstance(x, Iterable) and not isinstance(x, str)
def _flatten(x):
result = []
for el in x:
if _is_array_like(el):
result.extend(_flatten(el))
else:
result.append(el)
return result
def _merge_dicts(*dicts):
result = {}
for dictionary in dicts:
result.update(dictionary)
return result