python-audio-autotest-3.10 1.5.12rc1__py3-none-any.whl → 1.5.12rc3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
pyaatlibs/logger.py CHANGED
@@ -12,12 +12,15 @@ except ImportError:
12
12
  import Queue as queue
13
13
  import StringIO as sio
14
14
 
15
+
15
16
  class LoggerThread(threading.Thread):
16
17
  MAX_SIZE = 100000
17
18
  BUF_SIZE = 10
18
19
  LOG_DIR = ROOT_DIR + "{}{}{}".format(SEP, "{}log", SEP)
19
20
 
20
- def __init__(self, prefix="", logfolder_prefix="", max_size=MAX_SIZE, buf_size=BUF_SIZE, log_dir=LOG_DIR):
21
+ def __init__(
22
+ self, prefix="", logfolder_prefix="", max_size=MAX_SIZE, buf_size=BUF_SIZE, log_dir=LOG_DIR
23
+ ):
21
24
  super(LoggerThread, self).__init__()
22
25
  self.daemon = True
23
26
  self.msg_q = queue.Queue()
@@ -27,7 +30,9 @@ class LoggerThread(threading.Thread):
27
30
  self.max_size = max_size
28
31
  self.buf_size = buf_size
29
32
  self.current_size = 0
30
- self.log_dir = log_dir.format("{}-".format(logfolder_prefix) if len(logfolder_prefix) > 0 else logfolder_prefix)
33
+ self.log_dir = log_dir.format(
34
+ "{}-".format(logfolder_prefix) if len(logfolder_prefix) > 0 else logfolder_prefix
35
+ )
31
36
  self._to_stdout = False
32
37
  self._to_file = False
33
38
 
@@ -45,7 +50,9 @@ class LoggerThread(threading.Thread):
45
50
  def _update_timestamp(self):
46
51
  t = datetime.datetime.now()
47
52
  prefix = "{}-".format(self.prefix) if len(self.prefix) > 0 else ""
48
- self.filename = "{}{}{:02d}{:02d}_{:02d}{:02d}{:02d}.log.txt".format(prefix, t.year, t.month, t.day, t.hour, t.minute, t.second)
53
+ self.filename = "{}{}{:02d}{:02d}_{:02d}{:02d}{:02d}.log.txt".format(
54
+ prefix, t.year, t.month, t.day, t.hour, t.minute, t.second
55
+ )
49
56
  self.log_timestamp = t
50
57
 
51
58
  def _dump(self):
@@ -61,6 +68,7 @@ class LoggerThread(threading.Thread):
61
68
  def wait_for_queue_empty(self):
62
69
  while not self.msg_q.empty():
63
70
  import time
71
+
64
72
  time.sleep(0.5)
65
73
 
66
74
  def push(self, msg):
@@ -94,13 +102,13 @@ class LoggerThread(threading.Thread):
94
102
 
95
103
  if self._to_stdout:
96
104
  import sys
105
+
97
106
  sys.stdout.write(logtext)
98
107
  sys.stdout.flush()
99
108
 
100
109
  self.current_size += 1
101
110
 
102
- if self.current_size > 0 and \
103
- (self.current_size % self.buf_size == 0 or force_dump):
111
+ if self.current_size > 0 and (self.current_size % self.buf_size == 0 or force_dump):
104
112
  self._dump()
105
113
 
106
114
  if self.current_size >= self.max_size:
@@ -112,6 +120,7 @@ class LoggerThread(threading.Thread):
112
120
  self._dump()
113
121
  self.current_size = 0
114
122
 
123
+
115
124
  class Logger(object):
116
125
  WORK_THREAD = None
117
126
  HAS_BEEN_INIT = False
@@ -131,11 +140,15 @@ class Logger(object):
131
140
  BOTH_FILE_AND_STDOUT = STDOUT | FILE
132
141
 
133
142
  @staticmethod
134
- def init(mode=Mode.BOTH_FILE_AND_STDOUT, prefix="", logfolder_prefix="", log_dir=LoggerThread.LOG_DIR):
143
+ def init(
144
+ mode=Mode.BOTH_FILE_AND_STDOUT, prefix="", logfolder_prefix="", log_dir=LoggerThread.LOG_DIR
145
+ ):
135
146
  if Logger.HAS_BEEN_INIT:
136
147
  return
137
148
 
138
- Logger.WORK_THREAD = LoggerThread(prefix=prefix, logfolder_prefix=logfolder_prefix, log_dir=log_dir)
149
+ Logger.WORK_THREAD = LoggerThread(
150
+ prefix=prefix, logfolder_prefix=logfolder_prefix, log_dir=log_dir
151
+ )
139
152
 
140
153
  if mode & Logger.Mode.STDOUT > 0:
141
154
  Logger.WORK_THREAD.to_stdout()
@@ -162,7 +175,7 @@ class Logger(object):
162
175
  @staticmethod
163
176
  def log(tag=None, msg=None, level=Verbosity.NONE):
164
177
  if not tag or not msg:
165
- raise(ValueError("no tag or msg argument for Logger.log"))
178
+ raise (ValueError("no tag or msg argument for Logger.log"))
166
179
 
167
180
  if Logger.VERBOSITY_LEVEL != Logger.Verbosity.NONE and level > Logger.VERBOSITY_LEVEL:
168
181
  return
@@ -1,12 +1,14 @@
1
1
  import numpy as np
2
2
 
3
+
3
4
  def sort_values(signal):
4
5
  signal = np.array(signal)
5
6
  idices = np.argsort(signal, axis=0)
6
7
  return zip(list(idices), list(signal[idices]))
7
8
 
9
+
8
10
  def find_peaks(signal):
9
11
  peaks = []
10
12
  max_idx = np.argmax(signal)
11
- peaks.append((max_idx, signal[max_idx]+1e-50))
13
+ peaks.append((max_idx, signal[max_idx] + 1e-50))
12
14
  return peaks
@@ -3,6 +3,7 @@ from librosa.core import load as audioload
3
3
  from scipy.fftpack import fft
4
4
  import matplotlib.pyplot as plt
5
5
 
6
+
6
7
  class SignalMatcher(object):
7
8
  FRAME_MILLIS_PER_FEATURE = 20
8
9
 
@@ -13,33 +14,37 @@ class SignalMatcher(object):
13
14
 
14
15
  def _gen_feat(self):
15
16
  sig_len = len(self.refsig)
16
- framesize = int(np.round(self.reffs*SignalMatcher.FRAME_MILLIS_PER_FEATURE/1000.))
17
- nfft = int(2**np.ceil(np.log2(framesize)))
18
- self.feats = np.zeros([nfft/2, int(np.ceil(sig_len*1./framesize))])
17
+ framesize = int(np.round(self.reffs * SignalMatcher.FRAME_MILLIS_PER_FEATURE / 1000.0))
18
+ nfft = int(2 ** np.ceil(np.log2(framesize)))
19
+ self.feats = np.zeros([nfft / 2, int(np.ceil(sig_len * 1.0 / framesize))])
19
20
 
20
21
  frame_sig = np.zeros([framesize])
21
22
  for frame_idx in range(self.feats.shape[1]):
22
23
  frame_sig[:] = 0
23
24
  idx_from = frame_idx * framesize
24
25
  idx_to = min([idx_from + framesize, sig_len])
25
- frame_sig[:idx_to-idx_from] = self.refsig[idx_from:idx_to]
26
- self.feats[:, frame_idx] = np.abs(fft(frame_sig, nfft))[:nfft/2]
26
+ frame_sig[: idx_to - idx_from] = self.refsig[idx_from:idx_to]
27
+ self.feats[:, frame_idx] = np.abs(fft(frame_sig, nfft))[: nfft / 2]
27
28
 
28
29
  def visualize_feat(self, outpath):
29
30
  feats = np.array(self.feats)
30
31
  feats += 1e-32
31
32
  feats = 20 * np.log10(feats)
32
- plt.imshow(feats, vmax=np.max(feats), vmin=np.max(feats)-40, cmap="gray", origin="lower")
33
+ plt.imshow(feats, vmax=np.max(feats), vmin=np.max(feats) - 40, cmap="gray", origin="lower")
33
34
  plt.colorbar()
34
35
 
35
- ticks = plt.gca().get_yticks()*1.0/feats.shape[0] * self.reffs/2.0
36
+ ticks = plt.gca().get_yticks() * 1.0 / feats.shape[0] * self.reffs / 2.0
36
37
  ticks = np.array(np.round(ticks), dtype=int)
37
38
  plt.gca().set_yticklabels(ticks)
38
39
  plt.gca().set_ylabel("frequency (Hz)")
39
- plt.gca().set_xlabel("frame index ({} ms/frame)".format(SignalMatcher.FRAME_MILLIS_PER_FEATURE))
40
+ plt.gca().set_xlabel(
41
+ "frame index ({} ms/frame)".format(SignalMatcher.FRAME_MILLIS_PER_FEATURE)
42
+ )
40
43
 
41
44
  xlim = plt.gca().get_xlim()
42
- plt.gcf().set_size_inches([(xlim[1]-xlim[0])*SignalMatcher.FRAME_MILLIS_PER_FEATURE/1000.0, 3])
45
+ plt.gcf().set_size_inches(
46
+ [(xlim[1] - xlim[0]) * SignalMatcher.FRAME_MILLIS_PER_FEATURE / 1000.0, 3]
47
+ )
43
48
 
44
49
  plt.savefig(outpath, bbox_inches="tight", pad_inches=0, dpi=300)
45
50
  plt.gcf().clear()