-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstrucfun.py
executable file
·51 lines (44 loc) · 1.62 KB
/
strucfun.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
# -*- coding: utf-8 -*-
#
# # Dobroslav P. Egorov
# # Kotel'nikov Institute of Radio-engineering and Electronics of RAS
# # 2019
#
import sys
import math
import time
from termcolor import colored
from session import Session, Series, Point
from settings import parameter
# from borland_datetime import TDateTime
def structural_function(tb: Series,
t_step: float = None,
part: float = 1,
rightLimit: float = sys.maxsize) -> Series:
tb.thin_fast(t_step)
dt_avg = 0
for i in range(tb.length - 1):
dt_avg += (tb.data[i+1].time - tb.data[i].time)
dt_avg /= (tb.length - 1)
out = Series(key=tb.key)
for m in range(int(part * tb.length)):
if m * dt_avg > rightLimit:
break
I = 0.
for k in range(tb.length - m):
I += (tb.data[k+m].val - tb.data[k].val) ** 2
I = math.sqrt(I / (tb.length - m))
out.add(Point(m * dt_avg, I))
return out
def structural_functions(MDATA: Session,
t_step: float = parameter.struct_func.t_step,
part: float = parameter.struct_func.part,
rightShowLimit: float = parameter.struct_func.rightShowLimit) -> Session:
print("Structural functions calculation...\t", end='', flush=True)
start_time = time.time()
data = Session()
for freq in MDATA.keys:
data.add(structural_function(MDATA.get_series(freq), t_step, part, rightShowLimit))
print('{:.3f} sec\t'.format(time.time() - start_time), end='')
print('[' + colored('OK', 'green') + ']')
return data