File wellmet/qt_gui/qt_graph_widgets.py changed (mode: 100644) (index 443f6d2..6d8e689) |
... |
... |
import pandas as pd # required for estimation graph |
11 |
11 |
|
|
12 |
12 |
|
|
13 |
13 |
from .. import stm_df |
from .. import stm_df |
|
14 |
|
|
|
15 |
|
|
|
16 |
|
|
|
17 |
|
|
|
18 |
|
|
|
19 |
|
class GRaph(pg.PlotWidget): |
|
20 |
|
def __init__(self, stream, parent=None, *args, **kwargs): |
|
21 |
|
super().__init__(parent, *args, **kwargs) |
|
22 |
|
#č tím potokem je myšleno hlavní okínko |
|
23 |
|
self.stream = stream |
|
24 |
|
self.stream.box_runned.connect(self.replot) |
|
25 |
|
self.stream.slice_changed.connect(self.replot) |
|
26 |
|
|
|
27 |
|
self.stream.redraw_called.connect(self.redraw) |
|
28 |
|
|
|
29 |
|
|
|
30 |
|
self.redraw() |
|
31 |
|
|
|
32 |
|
|
|
33 |
|
|
|
34 |
|
def redraw(self): |
|
35 |
|
self.clear() |
|
36 |
|
self.setBackground('w') |
|
37 |
|
#č y limita v podstatě znemožní Log y graf |
|
38 |
|
self.setLimits(xMin=-0.45)#, yMin=-0.45) |
|
39 |
|
#size=self.w.px_size*1.5 |
|
40 |
|
pos = () #np.empty((nsim, 4)) |
|
41 |
|
size = self.stream.px_size * 2 |
|
42 |
|
self.failures = self.plot(pos, pen=None, symbol='x', symbolPen='r',\ |
|
43 |
|
symbolSize=size*1.5, name='Failures') # symbolBrush=0.2, |
|
44 |
|
self.failures.setZValue(100) |
|
45 |
|
|
|
46 |
|
self.proxy_failures = self.plot(pos, pen=None, symbol='p', symbolPen=0.5,\ |
|
47 |
|
symbolSize=size, symbolBrush=(217,83,25), name='Proxy failures') |
|
48 |
|
self.proxy_failures.setZValue(95) |
|
49 |
|
|
|
50 |
|
self.successes = self.plot(pos, pen=None, symbol='+', \ |
|
51 |
|
symbolSize=size*1.5, symbolPen='g', name='Successes') |
|
52 |
|
self.successes.setZValue(90) |
|
53 |
|
|
|
54 |
|
self.proxy_successes = self.plot(pos, pen=None, symbol='p', symbolPen=0.5, \ |
|
55 |
|
symbolSize=size, symbolBrush=(119,172,48), name='Proxy successes') |
|
56 |
|
self.proxy_successes.setZValue(85) |
|
57 |
|
|
|
58 |
|
|
|
59 |
|
self.nodes = self.plot(pos, pen=None, symbol='o', symbolPen=0.5, \ |
|
60 |
|
symbolSize=size, name='Nodes') |
|
61 |
|
self.nodes.setZValue(80) |
|
62 |
|
|
|
63 |
|
self.replot() |
|
64 |
|
|
|
65 |
|
|
|
66 |
|
def replot(self): |
|
67 |
|
nsim = self.stream.slider.value() |
|
68 |
|
|
|
69 |
|
sample_box = self.stream.sample_box[:nsim] |
|
70 |
|
|
|
71 |
|
lengths = np.sum(np.square(sample_box.G), axis=1) |
|
72 |
|
lengths = np.sqrt(lengths, out=lengths) #lengths of each radius-vector |
|
73 |
|
|
|
74 |
|
|
|
75 |
|
pos = np.empty((nsim, 2)) |
|
76 |
|
pos[:,0] = np.arange(nsim) |
|
77 |
|
pos[:,1] = lengths |
|
78 |
|
|
|
79 |
|
if hasattr(sample_box, 'failsi'): #č to je normálně sample_box |
|
80 |
|
failsi = sample_box.failsi |
|
81 |
|
|
|
82 |
|
try: # proxy denotes implicitly-known values |
|
83 |
|
proxy = sample_box.proxy.astype(bool) |
|
84 |
|
except AttributeError: |
|
85 |
|
proxy = np.full(nsim, False, dtype=np.bool) |
|
86 |
|
|
|
87 |
|
mask = np.all((failsi, ~proxy), axis=0) |
|
88 |
|
self.draw(self.failures, pos[mask]) |
|
89 |
|
|
|
90 |
|
mask = np.all((~failsi, ~proxy), axis=0) |
|
91 |
|
self.draw(self.successes, pos[mask]) |
|
92 |
|
|
|
93 |
|
mask = np.all((failsi, proxy), axis=0) |
|
94 |
|
self.draw(self.proxy_failures, pos[mask]) |
|
95 |
|
|
|
96 |
|
mask = np.all((~failsi, proxy), axis=0) |
|
97 |
|
self.draw(self.proxy_successes, pos[mask]) |
|
98 |
|
|
|
99 |
|
else: #č není to teda sample_box... |
|
100 |
|
#č snad se nám povede nakreslit aspoň tečky? |
|
101 |
|
self.draw(self.nodes, pos) |
|
102 |
|
|
|
103 |
|
|
|
104 |
|
@staticmethod |
|
105 |
|
def draw(plot_item, data): |
|
106 |
|
#č musím to udělat takhle |
|
107 |
|
#č jinač to zlobí při posunutích slajderu |
|
108 |
|
if len(data): |
|
109 |
|
plot_item.setData(data) |
|
110 |
|
plot_item.show() |
|
111 |
|
else: |
|
112 |
|
plot_item.hide() |
|
113 |
|
|
|
114 |
|
|
|
115 |
|
|
|
116 |
|
|
|
117 |
|
|
|
118 |
|
|
|
119 |
|
|
|
120 |
|
|
|
121 |
|
|
|
122 |
|
|
14 |
123 |
""" |
""" |
15 |
124 |
============= |
============= |
16 |
125 |
График виӝет |
График виӝет |
|
... |
... |
Estimation graph widgets |
20 |
129 |
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
21 |
130 |
""" |
""" |
22 |
131 |
|
|
|
132 |
|
|
|
133 |
|
#č na tuto třídu kladu požadavek aby kdyby něco uměla přepinat mezi zdroje |
|
134 |
|
#č teď to nepotřebuji a nevím jestli to vůbec budu chtit v budoucnu. |
|
135 |
|
#č Proto ji nechám teď vazanou jen na skřiňku. |
|
136 |
|
class BoxEstimationData(QtCore.QObject): |
|
137 |
|
estimations_updated = QtCore.pyqtSignal(pd.DataFrame) |
|
138 |
|
|
|
139 |
|
def __init__(self, box_estimations, signal, parent=None): |
|
140 |
|
#č QObject má jediný parametr a tím je parent |
|
141 |
|
super().__init__(parent=parent) |
|
142 |
|
self.box_estimations = box_estimations |
|
143 |
|
signal.connect(self.recalculate) |
|
144 |
|
|
|
145 |
|
self.setup_context_menu() |
|
146 |
|
self.recalculate() |
|
147 |
|
|
|
148 |
|
|
|
149 |
|
def setup_context_menu(self): |
|
150 |
|
self.TRI_menu = QtWidgets.QMenu("WellMet") |
|
151 |
|
|
|
152 |
|
# self.TRI_overall_chk = QtGui.QAction("TRI_overall_estimations", self.TRI_menu) |
|
153 |
|
# self.TRI_overall_chk.setCheckable(True) |
|
154 |
|
# self.TRI_overall_chk.setChecked(True) |
|
155 |
|
# self.TRI_overall_chk.triggered.connect(self.recalculate) |
|
156 |
|
# self.TRI_menu.addAction(self.TRI_overall_chk) |
|
157 |
|
# |
|
158 |
|
# self.simplex_chk = QtGui.QAction("Simplex estimations", self.TRI_menu) |
|
159 |
|
# self.simplex_chk.setCheckable(True) |
|
160 |
|
# self.simplex_chk.setChecked(True) |
|
161 |
|
# self.simplex_chk.triggered.connect(self.recalculate) |
|
162 |
|
# self.TRI_menu.addAction(self.simplex_chk) |
|
163 |
|
|
|
164 |
|
# # year, it was |
|
165 |
|
# ## hope, it is temporary |
|
166 |
|
# #self.sources_action_group = QtGui.QActionGroup(self.TRI_menu) |
|
167 |
|
# #self.sources_action_group.addAction(self.TRI_overall_chk) |
|
168 |
|
# #self.sources_action_group.addAction(self.simplex_chk) |
|
169 |
|
|
|
170 |
|
#self.TRI_menu.addSeparator() |
|
171 |
|
|
|
172 |
|
# self.proxy_chk = QtGui.QAction("Proxy", self.TRI_menu) |
|
173 |
|
# self.proxy_chk.setCheckable(True) |
|
174 |
|
# self.proxy_chk.setChecked(hasattr(self.dice_box, 'proxy')) |
|
175 |
|
# self.proxy_chk.triggered.connect(self.recalculate) |
|
176 |
|
# self.TRI_menu.addAction(self.proxy_chk) |
|
177 |
|
# |
|
178 |
|
# self.TRI_menu.addSeparator() |
|
179 |
|
|
|
180 |
|
self.reaction = QtGui.QAction("Update", self.TRI_menu) |
|
181 |
|
self.reaction.triggered.connect(self.recalculate) |
|
182 |
|
self.TRI_menu.addAction(self.reaction) |
|
183 |
|
|
|
184 |
|
self.excelaction = QtGui.QAction("Export to Excel", self.TRI_menu) |
|
185 |
|
self.excelaction.triggered.connect(self.export_to_excel) |
|
186 |
|
self.TRI_menu.addAction(self.excelaction) |
|
187 |
|
|
|
188 |
|
|
|
189 |
|
def export_to_excel(self): |
|
190 |
|
#č já bych nechtěl, aby mně export najednou spadl |
|
191 |
|
#č z jakéhokoliv důvodu |
|
192 |
|
try: |
|
193 |
|
proposal_filename = '.xlsx' |
|
194 |
|
filename, *__ = pg.FileDialog.getSaveFileName(self.stream, 'Export to Excel',\ |
|
195 |
|
proposal_filename, initialFilter='*.xlsx') |
|
196 |
|
if filename: |
|
197 |
|
self.df.to_excel(filename) |
|
198 |
|
except BaseException as e: |
|
199 |
|
print(self.__class__.__name__ + ":", repr(e)) |
|
200 |
|
|
|
201 |
|
|
|
202 |
|
def recalculate(self): |
|
203 |
|
self.df = df = pd.DataFrame(self.box_estimations) |
|
204 |
|
try: |
|
205 |
|
df.index = df.nsim |
|
206 |
|
#č odhady skříňky netřeba sortirovat. |
|
207 |
|
#č až se tu objeví něco dalšího, dodáme sort. |
|
208 |
|
self.estimations_updated.emit(df) |
|
209 |
|
|
|
210 |
|
except BaseException as e: |
|
211 |
|
print(self.__class__.__name__ + ":", repr(e)) |
|
212 |
|
|
|
213 |
|
|
|
214 |
|
|
|
215 |
|
|
|
216 |
|
class ErrorGraph(pg.PlotWidget): |
|
217 |
|
def __init__(self, pf_exact, signal, menu, parent=None, *args, **kwargs): |
|
218 |
|
super().__init__(parent, *args, **kwargs) |
|
219 |
|
|
|
220 |
|
self.pf_exact = pf_exact |
|
221 |
|
|
|
222 |
|
signal.connect(self.redraw) |
|
223 |
|
|
|
224 |
|
self.setup_context_menu(menu) |
|
225 |
|
self.setup() |
|
226 |
|
|
|
227 |
|
def setup_context_menu(self, menu): |
|
228 |
|
# creates instance of LegendItem |
|
229 |
|
# and saves it into plotItem.legend |
|
230 |
|
self.legend = self.addLegend() |
|
231 |
|
|
|
232 |
|
self.plotItem.ctrl.xGridCheck.setChecked(True) |
|
233 |
|
self.plotItem.ctrl.yGridCheck.setChecked(True) |
|
234 |
|
|
|
235 |
|
# menu of SimplexEstimationData |
|
236 |
|
self.plotItem.vb.menu.addMenu(menu) |
|
237 |
|
|
|
238 |
|
#č já se bojím. radší to uložím |
|
239 |
|
self.custom_menu = self.plotItem.vb.menu.addMenu("Error graph") |
|
240 |
|
|
|
241 |
|
self.legend_chk = QtGui.QAction("Legend", self.custom_menu) |
|
242 |
|
self.legend_chk.setCheckable(True) |
|
243 |
|
self.legend_chk.triggered.connect(lambda: self.legend.setVisible(self.legend_chk.isChecked())) |
|
244 |
|
self.custom_menu.addAction(self.legend_chk) |
|
245 |
|
# apply custom menu option |
|
246 |
|
self.legend.setVisible(self.legend_chk.isChecked()) |
|
247 |
|
|
|
248 |
|
self.laction = QtGui.QAction("Show labels", self.custom_menu) |
|
249 |
|
self.laction.triggered.connect(self.show_labels) |
|
250 |
|
self.custom_menu.addAction(self.laction) |
|
251 |
|
|
|
252 |
|
|
|
253 |
|
def show_labels(self): |
|
254 |
|
self.setLabel('left', "Failure probability estimation error") |
|
255 |
|
self.setLabel('bottom', "Number of simulations") |
|
256 |
|
|
|
257 |
|
|
|
258 |
|
def setup(self, *args, **kwargs): |
|
259 |
|
self.clear() |
|
260 |
|
self.setBackground('w') |
|
261 |
|
self.setLimits(xMin=-0.45) |
|
262 |
|
x = y = () # zde jen vytvoříme kostru, nakrmime daty v .redraw() |
|
263 |
|
|
|
264 |
|
# We will use logMode by default |
|
265 |
|
self.setLogMode(y=True) |
|
266 |
|
|
|
267 |
|
pen = pg.mkPen(color='m', width=2) |
|
268 |
|
self.pen_vertex = self.plot(x, y, pen=pen, name="simple pf estimation") |
|
269 |
|
pen = pg.mkPen(color='r', width=2) |
|
270 |
|
self.pen_weighted_vertex = self.plot(x, y, pen=pen, name="weighted pf estimation") |
|
271 |
|
|
|
272 |
|
|
|
273 |
|
def redraw(self, df): |
|
274 |
|
#č nevadí, ale není to slušné |
|
275 |
|
# #č zapíšeme do data rámu, snad nikomu nebude vadit |
|
276 |
|
# df['vertex_estimation_error'] = df['vertex_estimation'] - pf_exact |
|
277 |
|
# df['weighted_vertex_estimation_error'] = df['weighted_vertex_estimation'] - pf_exact |
|
278 |
|
|
|
279 |
|
v = (df['vertex_estimation'] - self.pf_exact).abs() |
|
280 |
|
wv = (df['weighted_vertex_estimation'] - self.pf_exact).abs() |
|
281 |
|
if len(v) > 1: #č nevím proč hazí chyby. Asi kvůli zadané širce. |
|
282 |
|
self.pen_vertex.setData(v.index.to_numpy(), v.to_numpy()) |
|
283 |
|
self.pen_weighted_vertex.setData(wv.index.to_numpy(), wv.to_numpy()) |
|
284 |
|
|
|
285 |
|
|
|
286 |
|
|
|
287 |
|
|
|
288 |
|
|
|
289 |
|
|
|
290 |
|
|
|
291 |
|
|
|
292 |
|
|
|
293 |
|
|
|
294 |
|
|
|
295 |
|
|
|
296 |
|
|
|
297 |
|
|
|
298 |
|
|
|
299 |
|
# |
|
300 |
|
# DEPRECATED |
|
301 |
|
# |
|
302 |
|
|
23 |
303 |
|
|
24 |
304 |
def get_estimation_data(estimations, metric): |
def get_estimation_data(estimations, metric): |
25 |
305 |
metric_dict = dict() |
metric_dict = dict() |
|
... |
... |
def get_estimation_data(estimations, metric): |
44 |
324 |
|
|
45 |
325 |
class SimplexEstimationData(QtCore.QObject): |
class SimplexEstimationData(QtCore.QObject): |
46 |
326 |
#š budeme mӓť svůj vlastní signaľčík |
#š budeme mӓť svůj vlastní signaľčík |
47 |
|
simplex_estimation_updated = QtCore.pyqtSignal() |
|
|
327 |
|
estimations_updated = QtCore.pyqtSignal(pd.DataFrame) |
48 |
328 |
|
|
49 |
329 |
def __init__(self, dice_box, stream=None, *args, **kwargs): |
def __init__(self, dice_box, stream=None, *args, **kwargs): |
50 |
330 |
super().__init__(stream, *args, **kwargs) |
super().__init__(stream, *args, **kwargs) |
|
... |
... |
class SimplexEstimationData(QtCore.QObject): |
128 |
408 |
|
|
129 |
409 |
self.df = stm_df.get_tri_data_frame(self.dice_box, sources=sources,\ |
self.df = stm_df.get_tri_data_frame(self.dice_box, sources=sources,\ |
130 |
410 |
apply_proxy=self.proxy_chk.isChecked()) |
apply_proxy=self.proxy_chk.isChecked()) |
131 |
|
self.simplex_estimation_updated.emit() |
|
|
411 |
|
self.estimations_updated.emit(self.df) |
132 |
412 |
|
|
133 |
413 |
except BaseException as e: |
except BaseException as e: |
134 |
414 |
print(self.__class__.__name__ + ":", repr(e)) |
print(self.__class__.__name__ + ":", repr(e)) |
|
... |
... |
class SimplexEstimationGraph(pg.PlotWidget): |
383 |
663 |
print(self.__class__.__name__ + ":", repr(e)) |
print(self.__class__.__name__ + ":", repr(e)) |
384 |
664 |
|
|
385 |
665 |
|
|
386 |
|
|
|
387 |
|
class SimplexErrorGraph(pg.PlotWidget): |
|
388 |
|
def __init__(self, simplex_data, parent=None, *args, **kwargs): |
|
389 |
|
super().__init__(parent, *args, **kwargs) |
|
390 |
|
self.simplex_data = simplex_data |
|
391 |
|
self.simplex_data.simplex_estimation_updated.connect(self.redraw) |
|
392 |
|
|
|
393 |
|
self.setup_context_menu() |
|
394 |
|
self.setup() |
|
395 |
|
|
|
396 |
|
def setup_context_menu(self): |
|
397 |
|
# creates instance of LegendItem |
|
398 |
|
# and saves it into plotItem.legend |
|
399 |
|
self.legend = self.addLegend() |
|
400 |
|
|
|
401 |
|
self.plotItem.ctrl.xGridCheck.setChecked(True) |
|
402 |
|
self.plotItem.ctrl.yGridCheck.setChecked(True) |
|
403 |
|
|
|
404 |
|
# menu of SimplexEstimationData |
|
405 |
|
self.plotItem.vb.menu.addMenu(self.simplex_data.TRI_menu) |
|
406 |
|
|
|
407 |
|
#č já se bojím. radší to uložím |
|
408 |
|
self.custom_menu = self.plotItem.vb.menu.addMenu("Error graph") |
|
409 |
|
|
|
410 |
|
self.legend_chk = QtGui.QAction("Legend", self.custom_menu) |
|
411 |
|
self.legend_chk.setCheckable(True) |
|
412 |
|
self.legend_chk.triggered.connect(lambda: self.legend.setVisible(self.legend_chk.isChecked())) |
|
413 |
|
self.custom_menu.addAction(self.legend_chk) |
|
414 |
|
# apply custom menu option |
|
415 |
|
self.legend.setVisible(self.legend_chk.isChecked()) |
|
416 |
|
|
|
417 |
|
self.laction = QtGui.QAction("Show labels", self.custom_menu) |
|
418 |
|
self.laction.triggered.connect(self.show_labels) |
|
419 |
|
self.custom_menu.addAction(self.laction) |
|
420 |
|
|
|
421 |
|
|
|
422 |
|
def show_labels(self): |
|
423 |
|
self.setLabel('left', "Failure probability estimation error") |
|
424 |
|
self.setLabel('bottom', "Number of simulations") |
|
425 |
|
|
|
426 |
|
|
|
427 |
|
def setup(self, *args, **kwargs): |
|
428 |
|
self.clear() |
|
429 |
|
self.setBackground('w') |
|
430 |
|
self.setLimits(xMin=-0.45) |
|
431 |
|
x = y = () # zde jen vytvoříme kostru, nakrmime daty v .redraw() |
|
432 |
|
|
|
433 |
|
# We will use logMode by default |
|
434 |
|
self.setLogMode(y=True) |
|
435 |
|
|
|
436 |
|
#xkcd_red = (253, 193, 197) # xkcd: pale rose (#fdc1c5) |
|
437 |
|
#red = (253, 0, 17, 96) |
|
438 |
|
|
|
439 |
|
#self.pen_f = self.plot(x, y, brush=red)#, name="failure domain estimation") |
|
440 |
|
#self.pen_f.setZValue(-100) |
|
441 |
|
|
|
442 |
|
|
|
443 |
|
pen = pg.mkPen(color='m', width=2) |
|
444 |
|
self.pen_vertex = self.plot(x, y, pen=pen, name="simple pf estimation") |
|
445 |
|
pen = pg.mkPen(color='r', width=2) #(118, 187, 255) |
|
446 |
|
self.pen_weighted_vertex = self.plot(x, y, pen=pen, name="weighted pf estimation") |
|
447 |
|
|
|
448 |
|
|
|
449 |
|
|
|
450 |
|
#č když se někde objeví nula se zapnutým LogModem - |
|
451 |
|
#č qtpygraph hned spadne a není možne ten pad zachytit |
|
452 |
|
def zerosafe(self, x, y, fallback_y=None): |
|
453 |
|
x = np.array(x) |
|
454 |
|
y = np.array(y) |
|
455 |
|
if fallback_y is None: |
|
456 |
|
fallback_y = y |
|
457 |
|
y = np.where(y > 0, y, fallback_y) |
|
458 |
|
mask = y > 0 |
|
459 |
|
return x[mask], y[mask] |
|
460 |
|
|
|
461 |
|
|
|
462 |
|
def redraw(self): |
|
463 |
|
#č neotravujme uživatele chybovejma hlaškama |
|
464 |
|
if hasattr(self.simplex_data.dice_box, 'pf_exact'): |
|
465 |
|
try: #ё тут всё что угодно может пойти не так |
|
466 |
|
pf_exact = self.simplex_data.dice_box.pf_exact |
|
467 |
|
|
|
468 |
|
df = self.simplex_data.df |
|
469 |
|
#č zapíšeme do data rámu, snad nikomu nebude vadit |
|
470 |
|
df['vertex_estimation_error'] = df['vertex_estimation'] - pf_exact |
|
471 |
|
df['weighted_vertex_estimation_error'] = df['weighted_vertex_estimation'] - pf_exact |
|
472 |
|
|
|
473 |
|
v = df['vertex_estimation_error'].abs() |
|
474 |
|
wv = df['weighted_vertex_estimation_error'].abs() |
|
475 |
|
|
|
476 |
|
x, y = self.zerosafe(v.index, v.to_numpy()) |
|
477 |
|
self.pen_vertex.setData(x, y) |
|
478 |
|
|
|
479 |
|
x, y = self.zerosafe(wv.index, wv.to_numpy()) |
|
480 |
|
self.pen_weighted_vertex.setData(x, y) |
|
481 |
|
|
|
482 |
|
|
|
483 |
|
except BaseException as e: |
|
484 |
|
print(self.__class__.__name__ + ":", repr(e)) |
|
|
666 |
|
# |
|
667 |
|
#class SimplexErrorGraph(pg.PlotWidget): |
|
668 |
|
# def __init__(self, simplex_data, parent=None, *args, **kwargs): |
|
669 |
|
# super().__init__(parent, *args, **kwargs) |
|
670 |
|
# self.simplex_data = simplex_data |
|
671 |
|
# self.simplex_data.simplex_estimation_updated.connect(self.redraw) |
|
672 |
|
# |
|
673 |
|
# self.setup_context_menu() |
|
674 |
|
# self.setup() |
|
675 |
|
# |
|
676 |
|
# def setup_context_menu(self): |
|
677 |
|
# # creates instance of LegendItem |
|
678 |
|
# # and saves it into plotItem.legend |
|
679 |
|
# self.legend = self.addLegend() |
|
680 |
|
# |
|
681 |
|
# self.plotItem.ctrl.xGridCheck.setChecked(True) |
|
682 |
|
# self.plotItem.ctrl.yGridCheck.setChecked(True) |
|
683 |
|
# |
|
684 |
|
# # menu of SimplexEstimationData |
|
685 |
|
# self.plotItem.vb.menu.addMenu(self.simplex_data.TRI_menu) |
|
686 |
|
# |
|
687 |
|
# #č já se bojím. radší to uložím |
|
688 |
|
# self.custom_menu = self.plotItem.vb.menu.addMenu("Error graph") |
|
689 |
|
# |
|
690 |
|
# self.legend_chk = QtGui.QAction("Legend", self.custom_menu) |
|
691 |
|
# self.legend_chk.setCheckable(True) |
|
692 |
|
# self.legend_chk.triggered.connect(lambda: self.legend.setVisible(self.legend_chk.isChecked())) |
|
693 |
|
# self.custom_menu.addAction(self.legend_chk) |
|
694 |
|
# # apply custom menu option |
|
695 |
|
# self.legend.setVisible(self.legend_chk.isChecked()) |
|
696 |
|
# |
|
697 |
|
# self.laction = QtGui.QAction("Show labels", self.custom_menu) |
|
698 |
|
# self.laction.triggered.connect(self.show_labels) |
|
699 |
|
# self.custom_menu.addAction(self.laction) |
|
700 |
|
# |
|
701 |
|
# |
|
702 |
|
# def show_labels(self): |
|
703 |
|
# self.setLabel('left', "Failure probability estimation error") |
|
704 |
|
# self.setLabel('bottom', "Number of simulations") |
|
705 |
|
# |
|
706 |
|
# |
|
707 |
|
# def setup(self, *args, **kwargs): |
|
708 |
|
# self.clear() |
|
709 |
|
# self.setBackground('w') |
|
710 |
|
# self.setLimits(xMin=-0.45) |
|
711 |
|
# x = y = () # zde jen vytvoříme kostru, nakrmime daty v .redraw() |
|
712 |
|
# |
|
713 |
|
# # We will use logMode by default |
|
714 |
|
# self.setLogMode(y=True) |
|
715 |
|
# |
|
716 |
|
# #xkcd_red = (253, 193, 197) # xkcd: pale rose (#fdc1c5) |
|
717 |
|
# #red = (253, 0, 17, 96) |
|
718 |
|
# |
|
719 |
|
# #self.pen_f = self.plot(x, y, brush=red)#, name="failure domain estimation") |
|
720 |
|
# #self.pen_f.setZValue(-100) |
|
721 |
|
# |
|
722 |
|
# |
|
723 |
|
# pen = pg.mkPen(color='m', width=2) |
|
724 |
|
# self.pen_vertex = self.plot(x, y, pen=pen, name="simple pf estimation") |
|
725 |
|
# pen = pg.mkPen(color='r', width=2) #(118, 187, 255) |
|
726 |
|
# self.pen_weighted_vertex = self.plot(x, y, pen=pen, name="weighted pf estimation") |
|
727 |
|
# |
|
728 |
|
# |
|
729 |
|
# |
|
730 |
|
# #č když se někde objeví nula se zapnutým LogModem - |
|
731 |
|
# #č qtpygraph hned spadne a není možne ten pad zachytit |
|
732 |
|
# def zerosafe(self, x, y, fallback_y=None): |
|
733 |
|
# x = np.array(x) |
|
734 |
|
# y = np.array(y) |
|
735 |
|
# if fallback_y is None: |
|
736 |
|
# fallback_y = y |
|
737 |
|
# y = np.where(y > 0, y, fallback_y) |
|
738 |
|
# mask = y > 0 |
|
739 |
|
# return x[mask], y[mask] |
|
740 |
|
# |
|
741 |
|
# |
|
742 |
|
# def redraw(self): |
|
743 |
|
# #č neotravujme uživatele chybovejma hlaškama |
|
744 |
|
# if hasattr(self.simplex_data.dice_box, 'pf_exact'): |
|
745 |
|
# try: #ё тут всё что угодно может пойти не так |
|
746 |
|
# pf_exact = self.simplex_data.dice_box.pf_exact |
|
747 |
|
# |
|
748 |
|
# df = self.simplex_data.df |
|
749 |
|
# #č zapíšeme do data rámu, snad nikomu nebude vadit |
|
750 |
|
# df['vertex_estimation_error'] = df['vertex_estimation'] - pf_exact |
|
751 |
|
# df['weighted_vertex_estimation_error'] = df['weighted_vertex_estimation'] - pf_exact |
|
752 |
|
# |
|
753 |
|
# v = df['vertex_estimation_error'].abs() |
|
754 |
|
# wv = df['weighted_vertex_estimation_error'].abs() |
|
755 |
|
# |
|
756 |
|
# x, y = self.zerosafe(v.index, v.to_numpy()) |
|
757 |
|
# self.pen_vertex.setData(x, y) |
|
758 |
|
# |
|
759 |
|
# x, y = self.zerosafe(wv.index, wv.to_numpy()) |
|
760 |
|
# self.pen_weighted_vertex.setData(x, y) |
|
761 |
|
# |
|
762 |
|
# |
|
763 |
|
# except BaseException as e: |
|
764 |
|
# print(self.__class__.__name__ + ":", repr(e)) |
485 |
765 |
|
|
486 |
766 |
|
|
487 |
767 |
|
|
|
... |
... |
class VoronoiEstimationGraph(pg.PlotWidget): |
915 |
1195 |
|
|
916 |
1196 |
|
|
917 |
1197 |
|
|
918 |
|
|
|
919 |
|
class GRaph(pg.PlotWidget): |
|
920 |
|
def __init__(self, stream, parent=None, *args, **kwargs): |
|
921 |
|
super().__init__(parent, *args, **kwargs) |
|
922 |
|
#č tím potokem je myšleno hlavní okínko |
|
923 |
|
self.stream = stream |
|
924 |
|
self.stream.box_runned.connect(self.replot) |
|
925 |
|
self.stream.slice_changed.connect(self.replot) |
|
926 |
|
|
|
927 |
|
self.stream.redraw_called.connect(self.redraw) |
|
928 |
|
|
|
929 |
|
|
|
930 |
|
self.redraw() |
|
931 |
|
|
|
932 |
|
|
|
933 |
|
|
|
934 |
|
def redraw(self): |
|
935 |
|
self.clear() |
|
936 |
|
self.setBackground('w') |
|
937 |
|
#č y limita v podstatě znemožní Log y graf |
|
938 |
|
self.setLimits(xMin=-0.45)#, yMin=-0.45) |
|
939 |
|
#size=self.w.px_size*1.5 |
|
940 |
|
pos = () #np.empty((nsim, 4)) |
|
941 |
|
size = self.stream.px_size * 2 |
|
942 |
|
self.failures = self.plot(pos, pen=None, symbol='x', symbolPen='r',\ |
|
943 |
|
symbolSize=size*1.5, name='Failures') # symbolBrush=0.2, |
|
944 |
|
self.failures.setZValue(100) |
|
945 |
|
|
|
946 |
|
self.proxy_failures = self.plot(pos, pen=None, symbol='p', symbolPen=0.5,\ |
|
947 |
|
symbolSize=size, symbolBrush=(217,83,25), name='Proxy failures') |
|
948 |
|
self.proxy_failures.setZValue(95) |
|
949 |
|
|
|
950 |
|
self.successes = self.plot(pos, pen=None, symbol='+', \ |
|
951 |
|
symbolSize=size*1.5, symbolPen='g', name='Successes') |
|
952 |
|
self.successes.setZValue(90) |
|
953 |
|
|
|
954 |
|
self.proxy_successes = self.plot(pos, pen=None, symbol='p', symbolPen=0.5, \ |
|
955 |
|
symbolSize=size, symbolBrush=(119,172,48), name='Proxy successes') |
|
956 |
|
self.proxy_successes.setZValue(85) |
|
957 |
|
|
|
958 |
|
|
|
959 |
|
self.nodes = self.plot(pos, pen=None, symbol='o', symbolPen=0.5, \ |
|
960 |
|
symbolSize=size, name='Nodes') |
|
961 |
|
self.nodes.setZValue(80) |
|
962 |
|
|
|
963 |
|
self.replot() |
|
964 |
|
|
|
965 |
|
|
|
966 |
|
def replot(self): |
|
967 |
|
nsim = self.stream.slider.value() |
|
968 |
|
|
|
969 |
|
sample_box = self.stream.sample_box[:nsim] |
|
970 |
|
|
|
971 |
|
lengths = np.sum(np.square(sample_box.G), axis=1) |
|
972 |
|
lengths = np.sqrt(lengths, out=lengths) #lengths of each radius-vector |
|
973 |
|
|
|
974 |
|
|
|
975 |
|
pos = np.empty((nsim, 2)) |
|
976 |
|
pos[:,0] = np.arange(nsim) |
|
977 |
|
pos[:,1] = lengths |
|
978 |
|
|
|
979 |
|
if hasattr(sample_box, 'failsi'): #č to je normálně sample_box |
|
980 |
|
failsi = sample_box.failsi |
|
981 |
|
|
|
982 |
|
try: # proxy denotes implicitly-known values |
|
983 |
|
proxy = sample_box.proxy.astype(bool) |
|
984 |
|
except AttributeError: |
|
985 |
|
proxy = np.full(nsim, False, dtype=np.bool) |
|
986 |
|
|
|
987 |
|
mask = np.all((failsi, ~proxy), axis=0) |
|
988 |
|
self.draw(self.failures, pos[mask]) |
|
989 |
|
|
|
990 |
|
mask = np.all((~failsi, ~proxy), axis=0) |
|
991 |
|
self.draw(self.successes, pos[mask]) |
|
992 |
|
|
|
993 |
|
mask = np.all((failsi, proxy), axis=0) |
|
994 |
|
self.draw(self.proxy_failures, pos[mask]) |
|
995 |
|
|
|
996 |
|
mask = np.all((~failsi, proxy), axis=0) |
|
997 |
|
self.draw(self.proxy_successes, pos[mask]) |
|
998 |
|
|
|
999 |
|
else: #č není to teda sample_box... |
|
1000 |
|
#č snad se nám povede nakreslit aspoň tečky? |
|
1001 |
|
self.draw(self.nodes, pos) |
|
1002 |
|
|
|
1003 |
|
|
|
1004 |
|
@staticmethod |
|
1005 |
|
def draw(plot_item, data): |
|
1006 |
|
#č musím to udělat takhle |
|
1007 |
|
#č jinač to zlobí při posunutích slajderu |
|
1008 |
|
if len(data): |
|
1009 |
|
plot_item.setData(data) |
|
1010 |
|
plot_item.show() |
|
1011 |
|
else: |
|
1012 |
|
plot_item.hide() |
|
1013 |
|
|
|