plot_test.py
7.39 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
import numpy as np
import matplotlib.pyplot as plt
import datetime
import os.path
import loca_data
import math
'''
# реализация метода ньютона-рафсона
def newton_raphson(study_func, target_val, start_x, max_iter_count=10, max_err=1e-3, delta_x=1e-6):
# начальное значение аргумента
finded_x = start_x
# Цикл нахождения решения
iter_count = 0
err_y = 1e20
# цикл поиска решения
while (iter_count <= max_iter_count) and (abs(err_y) > max_err):
# Вычисляем производную dy/dx в точке x
# dfdx в принципе нам может быть известен аналитически, и в таком случае
# предпочтительно использовать аналитическое выражение.
dfdx = (study_func(finded_x + 0.5 * delta_x) - study_func(finded_x - 0.5 * delta_x)) / delta_x
# Находим приращение по y
err_y = study_func(finded_x) - target_val
# и по x
err_x = err_y / dfdx
# Получаем новое решение
finded_x = finded_x - err_x
# меняем к - во итераций
iter_count += 1
return finded_x
'''
'''
x = np.random.randint(low=1, high=11, size=50)
y = x + np.random.randint(1, 5, size=x.size)
data = np.column_stack((x, y))
fig, (ax1, ax2) = plt.subplots(
nrows=1, ncols=2,
figsize=(8, 4)
)
ax1.scatter(x=x, y=y, marker='o', c='r', edgecolor='b')
ax1.set_title('Scatter: $x$ versus $y$')
ax1.set_xlabel('$x$')
ax1.set_ylabel('$y$')
ax2.hist(
data, bins=np.arange(data.min(), data.max()),
label=('x', 'y')
)
ax2.legend(loc=(0.65, 0.8))
ax2.set_title('Frequencies of $x$ and $y$')
ax2.yaxis.tick_right()
x = [0,1,2,3,4,5]
y1 = [1,1,2,2,4,0]
y2 = [5,1,3,6,4,10]
y3 = [0,1,3,2,6,8]
fig, ax = plt.subplots()
ax.plot(x, y1, label = 'TEST1')
ax.plot(x, y2, label = 'ЕУЫЕ2')
ax.plot(x, y3, label = 'tmp3')
ax.legend()
#fig.set_figheight(5)
#fig.set_figwidth(8)
plt.show()
class Test():
def __init__(self, _id, _data1, _data2):
self.id = _id
self.data1 = _data1
self.data2 = _data2
res = {
1:Test(1, "12345", "54321"),
2:Test(2, "11111", "aaaaa"),
3:Test(3, "ddddd", "qwqwqw")
}
for val in res.keys():
print(res[val].data1)
datetime_min = datetime.datetime(2020, 1, 29, 22, 50, 0)
timestamp = int(datetime_min.timestamp())
png_path = r"d:\PYTHON\tests\test1\png"
file_path = "{}\\dj_286m_{}.png".format(png_path, timestamp)
print(file_path)
print(os.path.exists(file_path))
zero = -1.06
class RiverCrossSection():
def __init__(self, _left_slope = 5.0, _bottom = 18.0, _right_slope = 5.0, _max_h = 3.6, _zero_bsv = -1.06, _n_roughness = 0.035, _i_bias = 0.00244):
# параметры трапеции
self._zero_wlevel = _zero_bsv
self._trap_a = _left_slope # ширина левого склона трапеции русла
self._trap_b = _bottom # ширина дна трапеции русла
self._trap_c = _right_slope # ширина правого склона трапеции русла
self._trap_d = _max_h # высота трапеции русла
if self._trap_d >= 0:
self._trap_leftCtg = self._trap_a / self._trap_d # котангенс левого угла трапеции русла
self._trap_rightCtg = self._trap_c / self._trap_d # котангенс правого угла трапеции русла
else:
self._trap_leftCtg = 0 # котангенс левого угла трапеции русла
self._trap_rightCtg = 0 # котангенс правого угла трапеции русла
self._i_rb_part = _i_bias # уклон русла
self._n_rb_part = _n_roughness # шероховатость русла
# площадь сечения (м^2)
def f_trap_area(self, h):
return self._trap_b * h + (self._trap_leftCtg + self._trap_rightCtg) * h * h / 2
# смоченный периметр (м)
def f_trap_perimetr(self, h):
return self._trap_b + \
math.sqrt(self._trap_leftCtg ** 2 + 1) * h + \
math.sqrt(self._trap_rightCtg ** 2 + 1) * h
# гидрологический радиус
def f_hydro_r(self, h):
return self.f_trap_area(h) / self.f_trap_perimetr(h)
# скорость потока (м/с)
def f_flow_speed(self, h):
return self.f_hydro_r(h)**(2./3) * math.sqrt(self._i_rb_part) / self._n_rb_part
# расход воды (м^3/с)
def f_flow_rate(self, h):
if h <= 0.:
return 0.
return self.f_trap_area(h) * self.f_flow_speed(h)
# расход воды (м^3/с)
def f_flow_rate_by_bs_h(self, bs_h):
return self.f_flow_rate(bs_h - self._zero_wlevel)
# уровень воды (м), определяемый по расходу воды (м^3/с)
def high_by_flow_rate(self, flow_rate):
if flow_rate <= 0.:
return 0.
return newton_raphson(self.f_flow_rate, flow_rate, 1.)
# уровень воды (м), определяемый по расходу воды (м^3/с) по балтийской системе высот
def bs_water_level(self, flow_rate):
return self.high_by_flow_rate(flow_rate) + self._zero_wlevel
real34 = loca_data.GetLevel34()
get_flow = RiverCrossSection()
min_flow = 100
max_flow = 0
for key in real34.keys():
real_level = real34[key]
#real_level = real_level - zero
flow = get_flow.f_flow_rate_by_bs_h(real_level)
if flow < min_flow:
min_flow = flow
if flow > max_flow:
max_flow = flow
print("{}-{}".format(real_level, flow))
print("{}-{}".format(min_flow, max_flow))
datetime_min = datetime.datetime(2020, 1, 29, 22, 50, 0)
datetime_max = datetime.datetime(2020, 2, 1, 0, 0, 0)
date_diff = datetime_max - datetime_min
print(date_diff.seconds / 600)
'''
first_dic = dict(a = "123", b = 1.9, c = 567)
first_dic1 = dict(a = "124", b = 2.9, c = 1567)
first_dic2 = dict(a = "125", b = 3.9, c = 2567)
first_dic3 = dict(a = "126", b = 4.9, c = 3567)
first_dic35 = None
first_dic4 = dict(a = "127", b = 5.9, c = 4567)
secon_dic = dict(aa = "qwe", bb = 0.0, cc = 3214)
def GetAllValues(_dict_with_pref):
key_store = []
value_store = []
for dwp_k in _dict_with_pref.keys():
dwp = _dict_with_pref[dwp_k]
if dwp is not None:
for k in dwp.keys():
key_store.append(str(dwp_k) + "_" + str(k))
value_store.append(str(dwp[k]))
return key_store, value_store
ks, vs = GetAllValues(dict(fd = first_dic, sd = secon_dic))
#print("\t".join(ks))
#print("\t".join(vs))
#timestamp = int(_datetime.timestamp())
#file_path = r"\png\dj_286m_{}.png".format(timestamp)
#print(os.listdir('.\\png\\'))
files = os.listdir('.\\png\\')
for f in files:
ts = int(f.replace("dj_286m_","").replace(".png",""))
dt = datetime.datetime.fromtimestamp(ts)
print(dt)
# 2. Ищем файл и формируем матрицу
#if not os.path.exists(os.path.abspath(os.curdir) + file_path):
# return result