-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaux.py
79 lines (60 loc) · 1.72 KB
/
aux.py
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import logging
import os
import json
import glob
import numpy as np
import matplotlib as mpl
log = logging.getLogger(__name__)
def array2string(x, n_dec):
"""
string = convert_array2string(x, n_dec):
"""
arraystr = np.array2string(x, precision=n_dec,
separator=',', suppress_small=True)
return arraystr
class npin4linspace:
def __init__(self, ls):
self.__ls = ls
def get(self, x):
idx = []
for value in flatten([x]):
bmask = self.__ls <= value
idx.append(np.count_nonzero(bmask[:-1])-1)
return np.array(idx)
def parse_path(filepath):
path, filename = os.path.split(filepath)
if path == "":
path = "./"
prefix = os.path.splitext(os.path.basename(filename))[0]
return path, filename, prefix
class loop_minmax:
def __init__(self):
self.__min = None
self.__max = None
self.__flag = True
def reset(self):
self.__init__()
def set(self, min, max):
if self.__flag:
self.__min = min
self.__max = max
self.__flag = False
else:
if min < self.__min:
self.__min = min
if max > self.__max:
self.__max = max
def get(self):
return self.__min, self.__max
def flatten(list_in):
return [item for sublist in list_in for item in sublist]
def flatten_unique(list_in):
return list(set([item for sublist in list_in for item in sublist]))
def unique_ordered(seq):
seen = set()
seen_add = seen.add
return [x for x in seq if not (x in seen or seen_add(x))]
def listify(val):
if len(np.shape(val)) == 0:
val = [val]
return val