-
Notifications
You must be signed in to change notification settings - Fork 0
/
ifs_properties_topo.py
1276 lines (985 loc) · 44.1 KB
/
ifs_properties_topo.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
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Jul 14 19:00:22 2018
@author: evgeniy
"""
from ifs_properties_plot import PropertiesIFS
# from ifs_operators_plot import incGeneral
import ifs_operators_plot as oper
from collections import OrderedDict
import json
import os
class PropertiesIFSTopo(PropertiesIFS):
def __init__(self, label=None,
holder=None,
topo_const=None,
radius=3,
annotations=None,
alpha_marker=0.5,
labels_size=12,
show_ann=True,
hide_ifs=False,
showverts=True,
showedges=False,
showlabels=False):
super(PropertiesIFSTopo, self).__init__(
label=label,
holder=holder,
radius=radius,
annotations=annotations,
alpha_marker=alpha_marker,
labels_size=labels_size,
show_ann=show_ann,
hide_ifs=hide_ifs,
showverts=showverts,
showedges=showedges,
showlabels=showlabels)
self.topo_const = topo_const
self.axes = self.holder.axes
# self.idx_active = None
@classmethod
def from_property_topoconst(cls, prop, topo_const):
return PropertiesIFSTopo(prop.label,
prop.holder,
topo_const,
prop.radius,
prop.annotations,
prop.alpha_marker,
prop.labels_size,
prop.show_ann,
prop.hide_ifs,
prop.showverts,
prop.showedges,
prop.showlabels)
@classmethod
def from_json(cls, json_path_prop,
json_path_topoconst,
ax,
bins,
rotation,
color='b',
marker='o'):
topo_const = TopoConst.from_json(json_path_topoconst, ax)
prop = PropertiesIFS.from_json(json_path_prop, ax, bins, rotation,
color=color,
marker=marker,
# radius=radius
)
return PropertiesIFSTopo.from_property_topoconst(prop, topo_const)
def save_to_json(self, json_path_prop, json_path_topoconst):
super(PropertiesIFSTopo, self).save_to_json(json_path_prop)
self.topo_const.save_to_json(json_path_topoconst)
def save_to_json_default(self, event):
path = self.default_path
path_topo = self.topo_const.default_path
self.save_to_json(path, path_topo)
def update_topo_const(self, alpha, beta):
self.topo_const.set_topoconst(alpha, beta)
# def draw_holder_annotations(self, ax):
# super(PropertiesIFSTopo, self).draw_holder_annotations(ax)
# self.topo_const_triang.draw_topo_object(ax)
def incGeneral(self):
return oper.incGeneral(self.get_data_pair(),
self.topo_const.alpha,
self.topo_const.beta,
self.topo_const.gamma_a,
self.topo_const.gamma_b)
def clGeneral(self):
return oper.clGeneral(self.get_data_pair(),
self.topo_const.alpha,
self.topo_const.beta,
self.topo_const.gamma_a,
self.topo_const.gamma_b)
def applyInclusion(self):
data = self.incGeneral()
self.set_data(data[0], data[1])
self.set_data_annotations(list(zip(data[0], data[1])))
def applyClosure(self):
print('original closure')
print(self.get_data())
data = self.clGeneral()
self.set_data(data[0], data[1])
print(list(zip(data[0], data[1])))
print(self.get_data())
self.set_data_annotations(list(zip(data[0], data[1])))
#########################
# Introducing two alphas and betas
class PropertiesIFSTopoGeneral(PropertiesIFS):
def __init__(self, label=None,
holder=None,
topo_const=None,
radius=2,
annotations=None,
alpha_marker=0.5,
labels_size=12,
show_ann=True,
hide_ifs=False,
showverts=True,
showedges=False,
showlabels=False):
super(self.__class__, self).__init__(label,
holder,
radius,
annotations,
alpha_marker,
labels_size,
show_ann,
hide_ifs,
showverts,
showedges,
showlabels)
self.topo_const = topo_const
self.axes = self.holder.axes
# self.idx_active = None
@classmethod
def from_property_topoconst(cls, prop, topo_const):
return PropertiesIFSTopoGeneral(prop.label,
prop.holder,
topo_const,
prop.radius,
prop.annotations,
prop.alpha_marker,
prop.labels_size,
prop.show_ann,
prop.hide_ifs,
prop.showverts,
prop.showedges,
prop.showlabels)
@classmethod
def from_json(cls, json_path_prop,
json_path_topoconst,
ax,
bins,
rotation,
color='b',
marker='o'):
topo_const = TopoConstGeneral.from_json(json_path_topoconst, ax)
prop = PropertiesIFS.from_json(json_path_prop, ax, bins, rotation,
color=color,
marker=marker)
return PropertiesIFSTopoGeneral.from_property_topoconst(prop, topo_const)
def save_to_json_default(self, event):
path = self.default_path
path_topo = self.topo_const.default_path
self.save_to_json(path, path_topo)
def save_to_json(self, json_path_prop, json_path_topoconst):
super(PropertiesIFSTopo, self).save_to_json(json_path_prop)
self.topo_const.save_to_json(json_path_topoconst)
def update_topo_const(self, alpha, beta):
self.topo_const.set_topoconst(alpha, beta)
# def draw_holder_annotations(self, ax):
# super(PropertiesIFSTopo, self).draw_holder_annotations(ax)
# self.topo_const_triang.draw_topo_object(ax)
def incGeneral2(self):
return oper.incGeneral2(self.get_data_pair(),
self.topo_const.alpha0,
self.topo_const.beta0,
self.topo_const.alpha,
self.topo_const.beta,
self.topo_const.gamma_a,
self.topo_const.gamma_b)
def clGeneral2(self):
return oper.clGeneral2(self.get_data_pair(),
self.topo_const.alpha0,
self.topo_const.beta0,
self.topo_const.alpha,
self.topo_const.beta,
self.topo_const.gamma_a,
self.topo_const.gamma_b)
def fill_fixed(self):
#self.axes
pass
def applyInclusion(self,
fill_fixed=False): # Fill fixed points
data = self.incGeneral2()
self.set_data(data[0], data[1])
self.set_data_annotations(list(zip(data[0], data[1])))
def applyClosure(self,
fill_fixed=False):
data = self.clGeneral2()
self.set_data(data[0], data[1])
#print(list(zip(data[0], data[1])))
self.set_data_annotations(list(zip(data[0], data[1])))
##############################################################################
##########################
class PropertiesIFSTopoInteractive(PropertiesIFSTopo):
def __init__(self, label=None,
holder=None,
topo_const=None,
radius=5,
annotations=None,
alpha_marker=0.5,
labels_size=12,
show_ann=True,
hide_ifs=False,
showverts=True,
showedges=False,
showlabels=False):
super(PropertiesIFSTopoInteractive, self).__init__(label,
holder,
topo_const,
radius,
annotations,
alpha_marker,
labels_size,
hide_ifs,
show_ann,
showverts,
showedges,
showlabels)
self.idx_active = None
@classmethod
def from_properties_ifs_topo(cls, prop_ifs_topo):
return cls(prop_ifs_topo.label,
prop_ifs_topo.holder,
prop_ifs_topo.topo_const,
prop_ifs_topo.radius,
prop_ifs_topo.annotations,
prop_ifs_topo.alpha_marker,
prop_ifs_topo.labels_size,
prop_ifs_topo.hide_ifs,
prop_ifs_topo.show_ann,
prop_ifs_topo.showverts,
prop_ifs_topo.showedges,
prop_ifs_topo.showlabels)
def set_animated(self, value):
super(PropertiesIFSTopo, self).set_animated(value)
self.topo_const.set_animated(value)
def connect(self):
canvas = self.axes.figure.canvas
# self.ciddraw = canvas.mpl_connect('draw_event',
# self.draw_callback)
self.cidpress = canvas.mpl_connect('button_press_event',
self.button_press_callback)
# self.cidkeypress = self.canvas.mpl_connect('key_press_event',
# self.key_press_callback)
self.cidrelease = canvas.mpl_connect('button_release_event',
self.button_release_callback)
self.cidmotion = canvas.mpl_connect('motion_notify_event',
self.motion_notify_callback)
def disconnect(self):
'disconnect all the stored connection ids'
canvas = self.axes.figure.canvas
canvas.mpl_disconnect(self.cidmotion)
canvas.mpl_disconnect(self.cidpress)
canvas.mpl_disconnect(self.cidrelease)
canvas.mpl_disconnect(self.cidmotion)
def draw_callback(self, event):
self.draw_holder_annotations(self.axes)
canvas = self.axes.figure.canvas
canvas.blit(self.axes.bbox)
self.background = canvas.copy_from_bbox(self.axes.figure.bbox)
def button_press_callback(self, event):
'whenever a mouse button is pressed'
print('button_pres - event in axis')
print(event.inaxes)
print('contains:')
print(self.holder.contains(event))
if event.inaxes is None or event.inaxes != self.axes:
return
if event.button != 1:
return
if not self.holder.get_visible():
return
self.idx_active = self.get_ind_under_point(event.xdata,
event.ydata)
if self.idx_active is None:
return
canvas = self.axes.figure.canvas
axes = self.axes
if self.idx_active > -1:
if self.show_ann:
self.set_animated_annotations(True)
if self.showverts:
self.holder.set_animated(True)
else:
self.topo_const.set_animated(True)
canvas.draw()
self.background = canvas.copy_from_bbox(self.axes.figure.bbox)
# now redraw just the rectangle
if self.idx_active > -1:
self.draw_holder_annotations(self.axes)
else:
self.topo_const.draw_topo_object()
# and blit just the redrawn area
canvas.blit(axes.bbox)
print('button press callback: idx = %d'
% -1 if self.idx_active is None else self.idx_active)
def get_ind_under_point(self, xdata, ydata):
'get the index of the vertex under point if within epsilon tolerance'
# display coords
# print(event.inaxes)
xy = np.asarray(self.get_data_pair())
print('get the index..')
print(self.get_data_pair())
print(xy)
x0, y0 = xy[0], xy[1]
x = np.zeros(len(x0)+1, dtype=float)
x[0:-1] = x0
x[-1] = self.topo_const.alpha
y = np.zeros(len(y0)+1, dtype=float)
y[0:-1] = y0
y[-1] = self.topo_const.beta
# print(x)
# print(y)
# print(event.xdata, event.ydata)
# print(event.x, event.y)
# print(self.ax01.transData.inverted().transform((event.x, event.y)))
# print(event.xdata, event.ydata)
d = np.sqrt((x - xdata)**2 + (y - ydata)**2)
indseq = np.nonzero(np.equal(d, np.amin(d)))[0]
ind = indseq[0]
ind = None if (d[ind] >= self.epsilon) else ind
ind = -1 if ind == len(x0) else ind
print('ind found: %d' % ind if ind is not None else -5)
return ind
def motion_notify_callback(self, event):
# print('on mouse movement')
if event.inaxes is None or event.inaxes != self.axes:
return
if event.button != 1:
return
if not self.holder.get_visible():
return
if self.idx_active is None:
# print('idx_act %d' % -1 if idx_act is None else idx_act)
return
# The drop & drag point should stay
# within the triangular area
xdata = min(max(0.0, event.xdata), 1.0)
ydata = min(max(0.0, event.ydata), 1.0)
# print('on mouse movement')
if self.idx_active > -1:
self.update_holder_annotation(xdata, ydata)
print('update holder & annotation')
# self.update_holder_annotation(prop_ifs_inactive,
# idx_act,
# xdata, ydata)
self.axes.figure.canvas.restore_region(self.background)
self.draw_holder_annotations(self.axes)
elif self.idx_active == -1:
self.update_topo_const(xdata, ydata)
self.axes.figure.canvas.restore_region(self.background)
self.topo_const.draw_topo_object()
self.axes.figure.canvas.blit(self.axes.bbox)
def update_holder_annotation(self, xdata, ydata):
# print("..in update holder annotations...")
if xdata + ydata >= 1.0:
pos = ((xdata-ydata+1)/2, (ydata-xdata+1)/2)
else:
pos = (xdata,ydata)
line_xy = list(zip(*self.get_data_pair()))
line_xy[self.idx_active] = pos
data = list(zip(*line_xy))
self.set_data(data[0], data[1])
if self.show_ann:
print("updating the annotation...")
self.set_data_annotations_single(self.idx_active, pos)
def button_release_callback(self, event):
'whenever a mouse button is released'
if event.button != 1:
return
if not self.holder.get_visible():
return
# print("active prop %s" % self.ax_active)
# print("active prop %s" % self.active_lines_idx[self.ax_active][0].label)
self.idx_active = None
self.set_animated(False)
self.set_animated_annotations(False)
self.axes.figure.canvas.draw()
###############################################################################
## Topo Const
##################
import matplotlib.pyplot as plt
class TopoConst(object):
def __init__(self, ax, alpha, beta, gamma_a, gamma_b, companion=None, label=None):
self.label = label
self.companion = companion
self.alpha = alpha
self.beta = beta
self.gamma_a = gamma_a
self.gamma_b = gamma_b
self.axes = ax
self.alpha2dline, = ax.plot([alpha]*3,
[0.0, beta, 1-alpha],
color='r',
linewidth=2)
self.beta2dline, = ax.plot([0.0, alpha, 1 - beta],
[beta]*3,
color='g',
linewidth=2)
self.gamma_a2dline, = ax.plot([alpha*gamma_a]*2,
[0.0, 1 - alpha*gamma_a],
color='black')
self.gamma_b2dline, = ax.plot([0.0, 1 - beta*gamma_b],
[beta*gamma_b]*2,
color='black')
self.alpha_ann = self.axes.annotate(r'$\alpha$',
(self.alpha,0.0),
xytext=(self.alpha-0.01,-0.08), fontsize=20)
self.beta_ann = self.axes.annotate(r'$\beta$',
(0.0, self.beta),
xytext=(-0.05, self.beta-0.01), fontsize=20)
self.gamma_a_ann = self.axes.annotate(r'$\gamma_{\alpha}.\alpha$',
(self.alpha*self.gamma_a,0.0),
xytext=(self.alpha*self.gamma_a-0.01,-0.08), fontsize=20)
self.gamma_b_ann = self.axes.annotate(r'$\gamma_{\beta}.\beta$',
(0.0, self.beta*self.gamma_b),
xytext=(-0.12, self.beta*self.gamma_b-0.01), fontsize=20)
self.set_annotations()
def set_animated(self,value):
self.alpha2dline.set_animated(value)
self.beta2dline.set_animated(value)
def set_annotations(self):
self.alpha_ann.set_position((self.alpha-0.01,-0.08))
self.alpha_ann.set_text(r'$\alpha$')
self.beta_ann.set_position((-0.05, self.beta-0.01))
self.beta_ann.set_text(r'$\beta$')
self.gamma_a_ann.set_position((self.alpha*self.gamma_a-0.01,-0.08))
self.gamma_a_ann.set_text(r'$\gamma_{\alpha}.\alpha$')
self.gamma_b_ann.set_position((-0.12, self.beta*self.gamma_b-0.01))
self.gamma_b_ann.set_text(r'$\gamma_{\beta}.\beta$')
@classmethod
def from_json(cls, json_path, ax):
with open(json_path) as data_file:
data = json.load(data_file)
# assert set(data.keys())==set(['alpha','beta','gamma_a','gamma_b'])
return TopoConst(ax,
alpha=data['alpha'],
beta=data['beta'],
gamma_a=data['gamma_a'],
gamma_b=data['gamma_b'])
def save_to_json(self, json_path):
holder = OrderedDict([('alpha', self.alpha),
('beta', self.beta),
('gamma_a', self.gamma_a),
('gamma_b', self.gamma_b)])
with open(json_path, 'w') as fp:
json.dump(holder, fp, indent=4)
print('Saving: ' + json_path)
print(holder)
@property
def default_path(self):
path = os.path.abspath(os.path.join(os.path.dirname( __file__ ),
'..',
'working_dir',
self.label + "_.json"))
return path
def save_to_json_default(self, event):
path = self.default_path
self.save_to_json(self, path)
def set_topoconst(self, alpha, beta):
self.alpha = alpha
self.beta = beta
self.alpha2dline.set_data([alpha]*3,
[0.0, beta, 1-alpha])
self.beta2dline.set_data([0.0, alpha, 1 - beta],
[beta]*3)
self.gamma_a2dline.set_data([self.alpha*self.gamma_a]*2,
[0.0, 1 - alpha*self.gamma_a])
self.gamma_b2dline.set_data([0.0, 1 - self.beta*self.gamma_b],
[self.beta*self.gamma_b]*2)
self.set_annotations()
def _fill_basic(self):
pass
def fill_fixed(self, typ):
assert typ in ['closure', 'inclusion']
# fill fixed points
# self.axes.fill_between([0.0, self.alpha0],
# [1.0, 1-self.alpha0],
# hatch = '\\',
# #step = 'post',
# facecolor='none',
# edgecolor='red')
self.axes.fill_between([self.alpha,1-self.beta,1-self.gamma_b*self.beta],
[1-self.alpha,self.beta, 0.0],
hatch = '\\',
#step = 'post',
facecolor='none',
edgecolor='red')
if typ == 'inclusion':
self._fill_inclusion()
elif typ == 'closure':
self._fill_closure()
def fill_nu_full(self):
self.axes.fill_between([0.0, 1-self.beta],
[1.0, self.beta],
[self.beta, self.beta],
hatch = '/',
#step = 'post',
facecolor='none',
edgecolor='g')
def fill_nu_limited(self):
self.axes.fill_between([0.0, self.alpha, 1-self.beta],
[1.0-self.gamma_a*self.alpha, 1-self.alpha, self.beta],
[self.beta, self.beta, self.beta],
hatch = '/',
#step = 'post',
facecolor='none',
edgecolor='g')
self.axes.plot([0.0, self.gamma_a*self.alpha],
[1-self.gamma_a*self.alpha, 1-self.gamma_a*self.alpha],
linewidth=1.2,
color='black')
self.axes.plot([0.0, self.alpha],
[1-self.alpha, 1-self.alpha],
linewidth=1.2,
color='black')
self.axes.plot([0.0, self.alpha],
[1-self.gamma_a*self.alpha, 1-self.alpha],
linewidth=2,
color='g')
def fill_mu_limited(self):
self.axes.fill_between([self.alpha,1-self.beta,1-self.gamma_b*self.beta],
[1-self.alpha,self.beta, 0.0],
hatch = '\\',
#step = 'post',
facecolor='none',
edgecolor='red')
self.axes.plot([1-self.beta, 1-self.beta],
[0.0, self.beta],
linewidth=1.2,
color='black')
self.axes.plot([1-self.gamma_b*self.beta, 1-self.gamma_b*self.beta],
[0.0, self.gamma_b*self.beta],
linewidth=1.2,
color='black')
self.axes.plot([1-self.beta, 1-self.gamma_b*self.beta],
[self.beta, 0.0],
linewidth=2,
color='red')
def fill_mu_full(self):
self.axes.fill_between([self.alpha, 1.0],
[1-self.alpha, 0.0],
hatch = '\\',
#step = 'post',
facecolor='none',
edgecolor='red')
def fill_mu_line(self):
self.axes.fill_between([-0.01, 0.01],
[1.0, 1.0],
[0, 0],
hatch = '\\',
#step = 'post',
facecolor='none',
edgecolor='red')
def fill_nu_line(self):
self.axes.fill_between([0.0, 1.0],
[0.01, 0.01],
[-0.01, -0.01],
hatch = '/',
#step = 'post',
facecolor='none',
edgecolor='green')
def fill_inclusion_indicator_interior(self):
self.axes.text(self.alpha*0.5 - 0.05, self.beta*0.5 - 0.05,
r' $\varepsilon_{0,\nu}$',
fontsize=30)
self.axes.text(self.alpha*0.5 - 0.05, self.beta + (1.0 - self.beta)/2 - 0.05,
r' $\varepsilon_{\blacksquare,\nu}$',
fontsize=30)
self.axes.text(self.alpha + (1.0 - self.alpha)/2 - 0.05, self.beta*0.5 - 0.05,
r' $\varepsilon_{\diamondsuit,\mu}$',
fontsize=30)
self.axes.text(self.alpha + (1.0 - self.alpha -self.beta)/4 ,
self.beta + (1.0 - self.beta - self.alpha)/4 ,
r' $\varepsilon_{eq}$',
fontsize=30)
self.axes.text( - 0.05, self.beta + (1.0 - self.beta)/2 - 0.15,
r' $\varepsilon_{eq}$',
fontsize=30)
def draw_topo_object(self):
self.axes.draw_artist(self.alpha2dline)
self.axes.draw_artist(self.beta2dline)
def set_visible(self, flag):
self.alpha2dline.set_visible(flag)
self.beta2dline.set_visible(flag)
def get_visible(self):
return self.alpha2dline.get_visible() and \
self.beta2dline.get_visible()
###############################################################################
############################
class TopoConstGeneral(object):
def __init__(self,
ax,
alpha,
beta,
gamma_a,
gamma_b,
alpha0=0.0,
beta0=0.0,
companion=None):
assert alpha + beta <= 1.0
fontsize=10
self.companion = companion
self.alpha = alpha
self.beta = beta
self.alpha0 = alpha0
self.beta0 = beta0
self.gamma_a = gamma_a
self.gamma_b = gamma_b
self.axes = ax
self.alpha2dline0, = ax.plot([alpha0]*3,
[0.0, beta0, 1-alpha0],
color='r',
linewidth=2)
self.beta2dline0, = ax.plot([0.0, alpha0, 1 - beta0],
[beta0]*3,
color='g',
linewidth=2)
self.alpha2dline, = ax.plot([alpha]*3,
[0.0, beta, 1-alpha],
color='r',
linewidth=2)
self.beta2dline, = ax.plot([0.0, alpha, 1 - beta],
[beta]*3,
color='g',
linewidth=2)
dAlpha = alpha - alpha0
dBeta = beta - beta0
self.gamma_a2dline, = ax.plot([(alpha0+dAlpha*gamma_a)]*2,
[0.0, 1 - (alpha0+dAlpha*gamma_a)],
color='black')
self.gamma_b2dline, = ax.plot([0.0, 1 - (beta0 + dBeta*gamma_b)],
[beta0 + dBeta*gamma_b]*2,
color='black')
self.alpha_ann0 = self.axes.annotate(r'$\alpha_1$',
(self.alpha0,0.0),
xytext=(self.alpha0-0.01,-0.01), fontsize=fontsize)
self.beta_ann0 = self.axes.annotate(r'$\beta_1$',
(0.0, self.beta0),
xytext=(-0.05, self.beta0-0.01), fontsize=fontsize)
self.alpha_ann = self.axes.annotate(r'$\alpha_2$',
(self.alpha,0.0),
xytext=(self.alpha-0.01,
-0.01),
fontsize=fontsize)
self.beta_ann = self.axes.annotate(r'$\beta_2$',
(0.0, self.beta),
xytext=(-0.05, self.beta-0.01), fontsize=fontsize)
self.gamma_a_ann = self.axes.annotate(r'$\gamma_{\alpha}.\Delta_\alpha$',
(self.alpha0+ dAlpha*self.gamma_a, 0.01),
xytext=(self.alpha0+ dAlpha*self.gamma_a-0.05, .01), #rotation=45,
fontsize=10)
self.gamma_b_ann = self.axes.annotate(r'$\gamma_{\beta}.\Delta_\beta$',
(0.0, self.beta0+dBeta*self.gamma_b),
fontsize=fontsize)
self.set_annotations_general()
def fill_fixed(self):
# fill fixed points
self.axes.fill_between([0.0, self.alpha0],
[1.0, 1-self.alpha0],
hatch = '\\',
#step = 'post',
facecolor='none',
edgecolor='red')
self.axes.fill_between([self.alpha, 1.0],
[1-self.alpha, 0.0],
hatch = '\\',
#step = 'post',
facecolor='none',
edgecolor='red')
#
self.axes.fill_between([0.0, 1-self.beta0, 1.0],
[self.beta0, self.beta0, 0.0],
hatch = '/',
#step = 'post',
facecolor='none',
edgecolor='g')
self.axes.fill_between([0.0, 1-self.beta],
[1.0, self.beta],
[self.beta, self.beta],
hatch = '/',
#step = 'post',
facecolor='none',
edgecolor='g')
def set_animated(self,value):
self.alpha2dline.set_animated(value)
self.beta2dline.set_animated(value)
def set_annotations_general(self):
print('call set annot general')
dAlpha = self.alpha - self.alpha0
dBeta = self.beta - self.beta0
self.alpha_ann0.set_position((self.alpha0-0.01,-0.08))
self.alpha_ann0.set_text(r'$\alpha_1$')
self.beta_ann0.set_position((-0.05, self.beta0-0.01))
self.beta_ann0.set_text(r'$\beta_1$')
self.alpha_ann.set_position((self.alpha-0.01,-0.08))
self.alpha_ann.set_text(r'$\alpha_2$')
self.beta_ann.set_position((-0.05, self.beta-0.01))
self.beta_ann.set_text(r'$\beta_2$')
self.gamma_a_ann.set_position((self.alpha0+ dAlpha*self.gamma_a-0.01,-0.08))
self.gamma_a_ann.set_text(r'$\gamma_{\alpha}.\Delta_\alpha$')
self.gamma_b_ann.set_position((-0.12, self.beta0+dBeta*self.gamma_b-0.01))
self.gamma_b_ann.set_text(r'$\gamma_{\beta}.\Delta_\beta$')
@classmethod
def from_json(cls, json_path, ax):
with open(json_path) as data_file:
data = json.load(data_file)
#assert set(data.keys())==set(['alpha','beta','gamma_a','gamma_b'])
return TopoConstGeneral(ax,
alpha=data['alpha'],
beta=data['beta'],
gamma_a=data['gamma_a'],
gamma_b=data['gamma_b'],
alpha0=data['alpha0'],
beta0=data['beta0'],)
def save_to_json(self, json_path):
holder = OrderedDict([('alpha', self.alpha),
('beta', self.beta),
('gamma_a', self.gamma_a),
('gamma_b', self.gamma_b)])
with open(json_path, 'w') as fp:
json.dump(holder, fp, indent=4)
print('Saving: ' + json_path)
print(holder)
def save_to_json_default(self, event):
path = os.path.abspath(os.path.join(os.path.dirname( __file__ ),
'..',
'working_dir',
self.label + "_.json"))
self.save_to_json(self, path)
def set_topoconst(self, alpha, beta, alpha0, beta0):
self.alpha = alpha
self.beta = beta
self.alpha0=alpha0
self.beta0=beta0
dAlpha = alpha - self.alpha0
dBeta = beta - self.beta0
self.alpha2dline.set_data([alpha]*3,
[0.0, beta, 1-alpha])
self.beta2dline.set_data([0.0, alpha, 1 - beta],
[beta]*3)
self.gamma_a2dline.set_data([alpha0+dAlpha*self.gamma_a]*2,
[0.0, 1 - alpha0+dAlpha*self.gamma_a])
self.gamma_b2dline.set_data([0.0, 1 - beta0 + dBeta*self.gamma_b],
[beta0 + dBeta*self.gamma_b]*2)
self.set_annotations()
def draw_topo_object(self):
self.axes.draw_artist(self.alpha2dline)
self.axes.draw_artist(self.beta2dline)
def set_visible(self, flag):
self.alpha2dline.set_visible(flag)
self.beta2dline.set_visible(flag)
def get_visible(self):
return self.alpha2dline.get_visible() and \
self.beta2dline.get_visible()
###############################################################################
class TopoConstInteractive(TopoConst):
def __init__(self, ax,
alpha, beta,
gamma_a, gamma_b,
companion=None,
label=None):
super(self.__class__, self).__init__(ax, alpha, beta, gamma_a, gamma_b)
self.label = label
self.companion = companion
self.active_artist = None
def connect(self):
'connect to all the events we need'
canvas = self.axes.figure.canvas
self.cidpick = canvas.mpl_connect('pick_event',