forked from ZJouba/virtual_creatures
-
Notifications
You must be signed in to change notification settings - Fork 0
/
monteplotter_4.py
684 lines (563 loc) · 24.7 KB
/
monteplotter_4.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
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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
import ast
import gc
import os
import pickle
import sys
import time
import tqdm
import tkinter as tk
from itertools import groupby
from math import cos, pi, radians, sin
from tkinter import filedialog
import multiprocessing
import matplotlib
matplotlib.use('TKAgg')
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from bokeh.application import Application
from bokeh.application.handlers import FunctionHandler
from bokeh.embed import file_html
from bokeh.events import Tap
from bokeh.io import export_png, export_svgs, output_file, save, show
from bokeh.layouts import Spacer, column, row
from bokeh.models import ColumnDataSource, Label, Range1d, Select
from bokeh.models.glyphs import Patch
from bokeh.models.markers import Cross
from bokeh.models.widgets import Div, Paragraph, PreText
from bokeh.palettes import RdYlGn11 as palette
from bokeh.palettes import brewer
from bokeh.plotting import curdoc, figure, reset_output
from bokeh.resources import CDN
from bokeh.server.server import Server
from bokeh.transform import log_cmap
from descartes.patch import PolygonPatch
from nltk.util import ngrams
from shapely.geometry import LineString, MultiLineString
from shapely import ops
from sklearn.preprocessing import MinMaxScaler, StandardScaler
from tabulate import tabulate
from tornado.ioloop import IOLoop
from scipy import stats
from Tools.Gen_Tools import plot_creature
def preProcessing(allData):
print('\n' + ('-' * 100))
print('Preprocessing...')
print('-' * 100 + '\n')
# if not isinstance(allData, pd.DataFrame):
# allData = pd.DataFrame(allData[1:], columns=allData[0])
# allData.fillna(0, inplace=True)
# allData.replace(np.inf, 0, inplace=True)
# allData.drop_duplicates(subset=['L_string', 'Fitness'], inplace=True)
# allData.reset_index(inplace=True)
if allData.shape[0] > 1000:
allData = allData.sample(20000, weights='Area')
# try:
# allData['Angle'] = allData['Angle'].apply(lambda x: x*(180/pi))
# except:
# pass
# allData['% Overlap'] = allData.apply(
# lambda x: ((1 - x['Area']) / (x['Linestring'].length + 0.785)),
# axis=1)
# allData['Centroid_X'] = allData['Linestring'].apply(
# lambda x: x.centroid.x)
# allData['Centroid_Y'] = allData['Linestring'].apply(
# lambda x: x.centroid.y)
# allData['Compactness'] = allData['Bounds'].apply(
# lambda x: np.linalg.norm(x))
# allData['Length'] = allData['Linestring'].apply(
# lambda x: x.length)
# scaler = MinMaxScaler(feature_range=(0, 10))
# allData['S_Area'] = scaler.fit_transform(
# allData['Area'].values.reshape(-1, 1))
# sscaler = MinMaxScaler(feature_range=(0, 0.05))
# allData['S_Fitness'] = sscaler.fit_transform(
# allData['Fitness'].values.reshape(-1, 1))
# ngram_list = allData['L_string'].apply(lambda x: ((''.join(tup))
# for i in range(2, 6) for tup in list(ngrams(list(x), i))))
# gram = []
# for ngram in ngram_list:
# tmp = [[*v] for _, v in groupby(sorted(ngram, key=len), key=len)]
# gram.append(tmp)
# allData['Rolling n-grams'] = gram
# gc.collect()
# for i in range(2, 6):
# allData['{}-gram'.format(i)] = allData['L_string'].apply(lambda x: [x[j:j+i]
# for j in range(0, len(x), i)])
# allData.to_csv("frameCSV.csv")
return allData
def modify_doc(doc):
"""Add plots to the document
Parameters
----------
doc : bokeh.document.document.Document
A Bokeh document to which plots can be added
Returns
----------
Document
"""
# plotData = allData.select_dtypes(include=np.number)
# scatter = ColumnDataSource(data=plotData)
# line = ColumnDataSource(data=dict(x=[], y=[]))
# r_1 = ColumnDataSource(data=dict(x=[], y=[]))
# r_2 = ColumnDataSource(data=dict(x=[], y=[]))
# polygon = ColumnDataSource(data=dict(x=[], y=[]))
# r_1_poly = ColumnDataSource(data=dict(x=[], y=[]))
# r_2_poly = ColumnDataSource(data=dict(x=[], y=[]))
# dist = ColumnDataSource(data=dict(x=[0], F=[0], P=[0], M=[0]))
nums = [1000, 10000, 100000]
for num in nums:
allData = allData.sample(num, weights='Area')
hist, edges = np.histogram(
allData['Area'].values, bins='auto')
bincenters = 0.5*(edges[1:]+edges[:-1])
pdf = stats.norm.pdf(bincenters)
dist_dict = ColumnDataSource(dict(
hist=hist, edges_left=edges[:-1], edges_right=edges[1:]))
# palette.reverse()
# mapper = log_cmap(
# field_name='Area', palette=palette, low=0, high=500)
# tooltips1 = [
# ('index', '$index'),
# ('F', '@{PercentF}{0.0%}'),
# ('+', '@{Percent+}{0.0%}'),
# ('-', '@{Percent-}{0.0%}'),
# ('[', '@{Percent[}{0.0%}'),
# (']', '@{Percent]}{0.0%}'),
# ('X', '@{PercentX}{0.0%}'),
# ('_', '@{Percent_}{0.0%}'),
# ]
# tooltips2 = [
# ('index', '$index'),
# ('F', '@{MaxF}'),
# ('+', '@{Max+}'),
# ('-', '@{Max-}'),
# ]
# tips_angle = [
# ('Angle', '@Angle')
# ]
""" Plots
-----------------------------------------------------------------------------------------------------
"""
# scargs = {
# 'size': 7,
# 'source': scatter,
# 'color': mapper,
# 'alpha': 0.6,
# 'nonselection_fill_color': mapper,
# 'nonselection_fill_alpha': 0.1,
# 'selection_fill_alpha': 1,
# 'selection_fill_color': 'red',
# }
plot_width = 450
plot_height = 500
# fargs = {
# 'plot_width': plot_width,
# 'plot_height': plot_height,
# 'tools': 'pan,wheel_zoom,box_zoom,reset,tap,save,box_select',
# 'output_backend': 'webgl',
# }
# per_scatter = figure(**fargs, title="Fitness", tooltips=tooltips1)
# per_scatter.xaxis.axis_label = '% of character'
# per_scatter.yaxis.axis_label = 'Fitness'
# per_scatter.scatter('PercentF', 'Fitness', **scargs)
# seq_scatter = figure(**fargs, title="Area", tooltips=tooltips2)
# seq_scatter.xaxis.axis_label = 'Length of sequence'
# seq_scatter.yaxis.axis_label = 'Area'
# seq_scatter.scatter('MaxF', 'Area', **scargs)
# ang_scatter = figure(**fargs, title="Angle", tooltips=tips_angle)
# ang_scatter.scatter('Angle', 'Area', **scargs)
# ang_scatter.xaxis.axis_label = 'Angle (degrees)'
# ang_scatter.yaxis.axis_label = 'Area'
# rule_1_plot = figure(plot_width=300, plot_height=plot_height//2,
# title="Rule 1", output_backend="webgl", match_aspect=True)
# rule_1_plot.patch(x='x', y='y', source=r_1_poly)
# rule_1_plot.line(x='x', y='y', line_color='red', source=r_1)
# rule_2_plot = figure(plot_width=300, plot_height=plot_height//2,
# title="Rule 2", output_backend="webgl", match_aspect=True)
# rule_2_plot.patch(x='x', y='y', source=r_2_poly)
# rule_2_plot.line(x='x', y='y', line_color='red', source=r_2)
# char_F_dist = figure(plot_width=plot_width, plot_height=plot_height//2,
# title="F character distribution", output_backend="webgl"
# )
# char_F_dist.varea_stack('F', x='x', source=dist)
# char_F_dist.xaxis.axis_label = 'L_string length'
# char_M_dist = figure(plot_width=plot_width, plot_height=plot_height//2,
# title="- character distribution", output_backend="webgl"
# )
# char_M_dist.varea_stack('M', x='x', source=dist)
# char_M_dist.xaxis.axis_label = 'L_string length'
# char_P_dist = figure(plot_width=plot_width, plot_height=plot_height//2,
# title="+ character distribution", output_backend="webgl"
# )
# char_P_dist.varea_stack('P', x='x', source=dist)
# char_P_dist.xaxis.axis_label = 'L_string length'
# overlap_scatter = figure(**fargs, title="Overlap")
# overlap_scatter.xaxis.axis_label = 'Angle'
# overlap_scatter.yaxis.axis_label = '% Overlap'
# overlap_scatter.scatter('Angle', '% Overlap', **scargs)
# comp_scatter = figure(**fargs, title="Compactness")
# comp_scatter.xaxis.axis_label = 'Creature length'
# comp_scatter.yaxis.axis_label = 'Bounding box diagonal distance'
# comp_scatter.scatter('Length', 'Compactness', **scargs)
# centr_scatter = figure(
# **fargs, title="Centroid location", match_aspect=True)
# centr_scatter.xaxis.axis_label = 'X'
# centr_scatter.yaxis.axis_label = 'Y'
# centr_scatter.scatter('Centroid_X', 'Centroid_Y',
# radius='S_Area', **scargs)
# comp_angle = figure(**fargs, title="Compactness")
# comp_angle.xaxis.axis_label = 'Angle'
# comp_angle.yaxis.axis_label = 'Bounding box diagonal distance'
# comp_angle.scatter('Angle', 'Compactness', **scargs)
# comp_char = figure(**fargs, title="Compactness")
# comp_char.xaxis.axis_label = '% of char'
# comp_char.yaxis.axis_label = 'Bounding box diagonal distance'
# # comp_char.scatter('Percent+', 'Compactness', **scargs)
# # comp_char.scatter('Percent-', 'Compactness', **scargs)
# comp_area = figure(**fargs, title="Compactness")
# comp_area.xaxis.axis_label = 'Area'
# comp_area.yaxis.axis_label = 'Bounding box diagonal distance'
# comp_area.scatter('Area', 'Compactness', **scargs)
dist_plot = figure(plot_width=plot_width*3,
plot_height=plot_height,
title="Distributions",
output_backend="webgl",
x_axis_label='Area',
y_axis_label='Number of creatures'
)
# dist_select = Select(value=' ', title='Metric',
# options=list(allData.select_dtypes(include=[np.number]).columns[1:].values))
# dist_plot.quad(top='hist', bottom=0, left='edges_left', right='edges_right',
# fill_color="navy", line_color="white", alpha=0.5, source=dist_dict)
dist_plot.line(bincenters, pdf)
# branch_scatter = figure(
# **fargs, title="Branching chars")
# branch_scatter.xaxis.axis_label = '% of ['
# branch_scatter.yaxis.axis_label = '% of ]'
# branch_scatter.scatter('Percent[', 'Percent]',
# radius='S_Fitness', **scargs)
# F_plot = figure(**fargs, title="Area")
# F_plot.xaxis.axis_label = 'No. of F'
# F_plot.yaxis.axis_label = 'Area'
# F_plot.scatter('CountF', 'Area', **scargs)
# scatter_select_x = Select(value='Area', title='Any plot x-value',
# options=list(allData.select_dtypes(include=[np.number]).columns[1:].values))
# scatter_select_y = Select(value='Area', title='Any plot y-value',
# options=list(allData.select_dtypes(include=[np.number]).columns[1:].values))
# scatter_select = figure(**fargs,
# title="Any scatter",
# x_axis_label='Select metric',
# y_axis_label='Select metric',
# tooltips=tooltips1
# )
# """ Text
# -----------------------------------------------------------------------------------------------------
# """
# L_string = Paragraph(text='Select creature', width=1200)
# characteristics = Div(text='Select creature', width=450)
# grams_static = PreText(text='Select creature', width=450)
# grams_rolling = PreText(text='Select creature', width=450)
# coordinates = PreText(text='Select creature', width=450)
# def clear():
# line.data = dict(x=[0, 0], y=[0, 0])
# polygon.data = dict(x=[0, 0], y=[0, 0])
# r_1.data = dict(x=[0, 0], y=[0, 0])
# r_2.data = dict(x=[0, 0], y=[0, 0])
# r_1_poly.data = dict(x=[0, 0], y=[0, 0])
# r_2_poly.data = dict(x=[0, 0], y=[0, 0])
# dist.data = dict(x=[0], F=[0], M=[0], P=[0])
# L_string.text = 'Select creature'
# characteristics.text = 'Select creature'
# grams_static.text = 'Select creature'
# grams_rolling.text = 'Select creature'
# coordinates.text ='Select creature'
# def to_coords(string, angle):
# """Converts rule to coordinates
# Parameters
# ----------
# string : String
# L_string of creature
# angle : Float
# Delta-angle (in radians) for creature
# Returns
# -------
# List
# Coordinate list representing L_string
# """
# num_chars = len(string)
# coords = np.zeros((num_chars + 1, 4), np.double)
# nodes = np.zeros((1, 4), np.double)
# rotVec = np.array((
# (cos(angle), -sin(angle), 0),
# (sin(angle), cos(angle), 0),
# (0, 0, 1)
# ))
# start_vec = np.array((0, 1, 0), np.float64)
# curr_vec = start_vec
# i = 1
# for c in string:
# """
# 1: Node
# 2: Branch
# 3: Saved
# """
# if c == 'F':
# coords[i, :3] = (coords[i-1, :3] + (1 * curr_vec))
# i += 1
# if c == '-':
# curr_vec = np.dot(curr_vec, (-1*rotVec))
# if c == '+':
# curr_vec = np.dot(curr_vec, rotVec)
# if c == '[':
# nodes = np.vstack((nodes, coords[i-1]))
# coords[i-1, 3] = 3
# nodes[-1, 3] = 1
# if c == ']':
# if coords[i-1, 3] == 1:
# # coords[i, 3] = 2
# coords[i-1] = nodes[-1]
# # i += 1
# else:
# coords[i-1, 3] = 2
# if len(nodes) == 1:
# coords[i] = nodes[-1]
# else:
# value, nodes = nodes[-1], nodes[:-1]
# coords[i] = value
# i += 1
# coords = np.delete(coords, np.s_[i:], 0)
# return coords
# def plot_creature(event):
# """Plots creature and corresponding characteristics on datapoint select
# Parameters
# ----------
# event : bokeh.event
# On Tap event registered by Bokeh
# """
# def draw():
# fig = plt.figure()
# ax = fig.add_subplot(111)
# # creature = ops.unary_union([
# # ops.unary_union(creature_moves)] + [creature_linestring])
# creature_patch = PolygonPatch(creature_linestring.buffer(0.5), fc='Blue') #, alpha=0.1)
# ax.add_patch(creature_patch)
# if isinstance(creature_linestring, MultiLineString):
# for line in creature_linestring:
# x, y = line.xy
# ax.plot(x, y, 'r-', zorder=1)
# else:
# x, y = creature_linestring.xy
# ax.plot(x, y, 'r-', zorder=1)
# # for move in creature_moves:
# # for line in move:
# # x, y = line.xy
# # ax.plot(x, y, 'g--', alpha=0.25)
# # for p in env.patches:
# # p = PolygonPatch(p)
# # color = np.random.rand(3,)
# # p.set_color(color)
# # p.set_alpha(0.4)
# # ax.add_patch(p)
# ax.autoscale(axis='y')
# ax.axis('equal')
# ax.plot(0, 0, 'Pr')
# # plt.draw()
# # fig.canvas.draw_idle()
# # plt.pause(1)
# clear()
# if len(scatter.selected.indices) > 0:
# creature_index = scatter.selected.indices[0]
# creature = allData.iloc[creature_index, :]
# coords = creature['Coords']
# try:
# rules = creature['Rules']
# try:
# rules = rules['X']
# probas = rules['probabilities']
# rules = rules['options']
# except:
# probas = [0, 0]
# characteristics.text = 'Area:\t{:.2f}'.format(creature['Area']) + \
# '</br>' + \
# 'Achievable creature area:\t{}'.format(creature['L_string'].count('F')+0.785) + \
# '</br>' + \
# 'Overlap:\t{:.1%}'.format(1 - creature['Area'] / (creature['L_string'].count('F')+0.785)) + \
# '</br>' + \
# 'Length of L_string:\t{}'.format(len(creature['L_string'])) + \
# '</br>' + \
# 'Achievable maxmimum area:\t{}'.format(
# len(creature['L_string']) + 0.785) + \
# '</br>' + \
# 'Rule 1: <i><tab>{}</i>'.format(rules[0]) + \
# '<tab><tab> Pr: <tab>{:.2%}'.format(probas[0]) + \
# '</br>' + \
# 'Rule 2: <i><tab>{}</i>'.format(rules[1]) + \
# '<tab><tab> Pr: <tab>{:.2%}'.format(probas[1])
# except:
# characteristics.text = 'Area:\t{:.2f}'.format(creature['Area']) + \
# '</br>' + \
# 'Achievable creature area:\t{}'.format(creature['L_string'].count('F')+0.785) + \
# '</br>' + \
# 'Overlap:\t{:.1%}'.format(1 - creature['Area'] / (creature['L_string'].count('F')+0.785)) + \
# '</br>' + \
# 'Length of L_string:\t{}'.format(len(creature['L_string'])) + \
# '</br>' + \
# 'Achievable maxmimum area:\t{}'.format(
# len(creature['L_string']) + 0.785)
# L_string.text = '{}'.format(creature['L_string'])
# n_grams = {}
# for i in range(2, len(creature['Rolling n-grams'])):
# n_grams[str(i) + '-gram'] = creature[str(i) + '-gram']
# gram_frame_1 = pd.DataFrame.from_dict(n_grams, orient='index').T
# # gram_frame_1 = pd.DataFrame.from_dict(
# # {'2-gram': creature['2-gram'],
# # '3-gram': creature['3-gram'],
# # '4-gram': creature['4-gram'],
# # '5-gram': creature['5-gram'],
# # },
# # orient='index').T
# counts = [pd.value_counts(gram_frame_1[i]).reset_index().astype(
# str).apply(' '.join, 1) for i in gram_frame_1]
# out = pd.concat(counts, 1).fillna('')
# out.columns = gram_frame_1.columns
# grams_static.text = ('-' * 14) + ' Static n-grams ' + ('-' * 14) + '\n' + str(
# tabulate(out, headers='keys'))
# n_grams = {}
# for i in range(len(creature['Rolling n-grams'])):
# n_grams[str(i) + '-gram'] = creature['Rolling n-grams'][i]
# gram_frame_2 = pd.DataFrame.from_dict(n_grams, orient='index').T
# counts = [pd.value_counts(gram_frame_2[i]).reset_index().astype(
# str).apply(' '.join, 1) for i in gram_frame_1]
# out = pd.concat(counts, 1).fillna('')
# out.columns = gram_frame_1.columns
# grams_rolling.text = ('-' * 14) + ' Rolling n-grams ' + ('-' * 14) + '\n' + str(
# tabulate(out, headers='keys'))
# coordinates.text = str(
# tabulate(creature['Coords'], headers='keys'))
# creature_linestring = creature['Linestring']
# # creature_moves = creature['moves']
# if 'F' in rules[0]:
# r_1_coords = to_coords(rules[0], creature['Angle'])
# r_1_morphology = LineString(r_1_coords[:, 0:2])
# r_1_poly.data = dict(
# x=r_1_morphology.buffer(0.5).exterior.coords.xy[0],
# y=r_1_morphology.buffer(0.5).exterior.coords.xy[1],
# )
# r_1.data = dict(x=r_1_coords[:, 0], y=r_1_coords[:, 1])
# if 'F' in rules[1]:
# r_2_coords = to_coords(rules[1], creature['Angle'])
# r_2_morphology = LineString(r_2_coords[:, 0:2])
# r_2_poly.data = dict(
# x=r_2_morphology.buffer(0.5).exterior.coords.xy[0],
# y=r_2_morphology.buffer(0.5).exterior.coords.xy[1],
# )
# r_2.data = dict(x=r_2_coords[:, 0], y=r_2_coords[:, 1])
# c_string = creature['L_string']
# bins_width = 10
# bins = int(len(c_string)//bins_width)
# dists = {}
# dists['F'] = []
# dists['P'] = []
# dists['M'] = []
# dists['x'] = []
# for i in range(bins):
# start = ((i-1)*bins_width)
# end = (i*bins_width)-1
# dists['F'].append(c_string.count('F', start, end))
# dists['P'].append(c_string.count('+', start, end))
# dists['M'].append(c_string.count('-', start, end))
# [dists['x'].append(i) for i in range(1, bins+1)]
# dist.data = dists
# draw()
# plt.pause(20)
# # plt.show()
# else:
# clear()
# plt.close('all')
# def update_dist(attrname, old, new):
# scaler = StandardScaler()
# name = dist_select.value
# hist, edges = np.histogram(
# scaler.fit_transform(
# allData[name].values.reshape(-1, 1)), bins=int(allData.shape[0]/10))
# dist_dict.data = dict(
# hist=hist, edges_left=edges[:-1], edges_right=edges[1:])
# dist_plot.xaxis.axis_label = name
# def update_scatter(attrname, old, new):
# scatter_select.renderers = []
# scatter_select.scatter(
# x=scatter_select_x.value, y=scatter_select_y.value, **scargs)
# scatter_select.xaxis.axis_label = scatter_select_x.value
# scatter_select.yaxis.axis_label = scatter_select_y.value
# per_scatter.on_event(Tap, plot_creature)
# seq_scatter.on_event(Tap, plot_creature)
# ang_scatter.on_event(Tap, plot_creature)
# overlap_scatter.on_event(Tap, plot_creature)
# comp_scatter.on_event(Tap, plot_creature)
# centr_scatter.on_event(Tap, plot_creature)
# comp_angle.on_event(Tap, plot_creature)
# comp_char.on_event(Tap, plot_creature)
# comp_area.on_event(Tap, plot_creature)
# F_plot.on_event(Tap, plot_creature)
# dist_select.on_change('value', update_dist)
# scatter_select_x.on_change('value', update_scatter)
# scatter_select_y.on_change('value', update_scatter)
# branch_scatter.on_event(Tap, plot_creature)
# scatter_select.on_event(Tap, plot_creature)
# row_A = row(L_string)
# row_B = row(per_scatter, seq_scatter, ang_scatter, overlap_scatter)
# row_C_right = column(rule_1_plot, rule_2_plot)
# row_C_middle = row(grams_rolling, grams_static)
# row_C = row(
# characteristics,
# Spacer(width=50),
# row_C_middle,
# Spacer(width=50),
# row_C_right)
# row_D = row(char_F_dist, char_M_dist, char_P_dist)
# row_E = row(comp_scatter, comp_angle, comp_char, centr_scatter)
# row_F = row(comp_area, F_plot, branch_scatter, coordinates)
# row_G = column(dist_select, dist_plot)
# row_H = column(scatter_select_x, scatter_select_y, scatter_select)
# layout = column(
# row_A,
# row_B,
# # row_C,
# # row_D,
# # row_E,
# # row_F,
# row_G,
# row_H,
# )
# clear()
doc.add_root(dist_plot)
def main():
"""Launch bokeh server and connect to it
"""
print('\n' + ('-' * 100))
print('Select file...')
print('-' * 100 + '\n')
global allData #, env
root = tk.Tk()
root.attributes("-topmost", True)
root.withdraw()
filepath = filedialog.askopenfilename()
if filepath:
allData = pickle.load(open(filepath, 'rb'))
# env_path = os.path.dirname(filepath) + '/Environment ' + filepath[-22:]
# env = pickle.load(open(env_path, 'rb'))
# allData = tqdm.tqdm(preProcessing(allData), total=allData.shape[0], file=sys.stdout)
# allData = preProcessing(allData)
print('\n' + ('-' * 100))
print('ALL DONE!')
print('-' * 100 + '\n')
print("Preparing a bokeh application.")
io_loop = IOLoop.current()
bokeh_app = Application(FunctionHandler(modify_doc))
server = Server({'/app': bokeh_app}, io_loop=io_loop, port=5001)
server.start()
print("Opening Bokeh application on http://localhost:5006/")
server.show('/app')
io_loop.start()
main()