-
Notifications
You must be signed in to change notification settings - Fork 7
/
SerialFIB.py
3075 lines (2414 loc) · 120 KB
/
SerialFIB.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
# -*- coding: utf-8 -*-
'''
################################################################
# SerialFIB #
# #
# Sven Klumpe, Sara Goetz, Herman Fung #
# #
# Julia Mahamid, Jürgen Plitzko #
# #
# Max-Planck-Institute for Biochemistry #
# Martinsried, Germany #
# #
# European Molecular Biology Laboratory #
# Heidelberg, Germany #
# #
# #
# #
# if you use SerialFIB in your work, please cite: #
# DOI: #
# #
# #
# SerialFIB: A Developer’s Tool for Automated #
# cryo-FIB Customized Workflows #
# #
# with bug reports, suggestions, etc. please contact: #
# klumpe@biochem.mpg.de #
################################################################
'''
# Form implementation generated from reading ui file 'gui17.ui'
#
# Created by: PyQt5 UI code generator 5.6
#
# WARNING! All changes made in this file will be lost!
from PyQt5 import QtCore, QtGui, QtWidgets
#############################################
# Function Import #
#############################################
#### IMPORT AUTOSCRIPT STRUCTURES
try:
from autoscript_sdb_microscope_client.structures import *
except:
print("No Autoscript installed")
### IMPROT DRIVERS AND TOOLS
from src.AquilosDriver import fibsem
from src.scripteditor import Ui_ScriptEditor
from src.PatternDesigner import Ui_PatternFileEditor
from src.LamellaDesigner import Ui_LamellaDesigner
from src.VolumeDesigner import Ui_VolumeDesigner
from src.Param3D import Param3D
### INITIALIZE MICROSCOPE FROM DRIVER
scope=fibsem()
###
### IMPORT EXTERNAL PACKAGES
from PyQt5.QtCore import pyqtSignal
from PyQt5.QtGui import QPainter
from PyQt5.QtWidgets import QGraphicsScene
import numpy as np
import os
import src
import logging
import datetime
import cv2
import sys
import pickle
import src.project_3dct as project_3dct
import re
###
class Stream(QtCore.QObject):
'''
This class gets the output text such as error messages etc. and puts them in the GUI message
box as well as the logfile.
It does that by getting an update from the MainWindow function onUpdateText() as oyqtSignal
'''
newText = QtCore.pyqtSignal(str)
sys.stdout = open(r'./SFIB.log', mode='a')
def write(self, text):
if str(text)==" ":
print('test')
else:
self.newText.emit(str(text).split("\n")[0])
# TestImage load for developing
try:
testimage=AdornedImage.load('./DummyImages/testimage1.tif')
testimage2=AdornedImage.load('./DummyImages/testimage2.tif')
except:
print('No testcase or "wrong" developer computer')
#############################################
class Ui_MainWindow(object):
'''
Definition of the GUI class
'''
def __init__(self):
# Scene for the GraphicsView, SceneBuffer is a list of all the scenes that have been created
self.scene=QtWidgets.QGraphicsScene()
self.sceneBuffer=[]
# Dictionary of all stage positions
self.StagePos={}
# Dictionary of all patterns defined for the images in the Image Buffer.
self.pattern_dict={}
# Image Buffer handle is a number that keeps track of which image is opened in the graphicsView
# Image buffer images is a list of all images in the ImageBuffer
self.ImageBufferHandle=0
self.ImageBufferImages=[]
# Output directory for outfiles
import os
path = r'%s' % os.getcwd().replace('\\', '/')
self.output_dir=path
try:
scope.define_output_dir(self.output_dir)
except:
print("No Microscope connected")
self.SAVparamsfile=r'./SAVparams.spf'
self.roughmillprotocol=r'./roughmill.pro'
self.finemillprotocol=r'./finemill.pro'
self.custommillprotocol=r'./testprotocol.pro'
self.custompatternfile=r'./patternfile.pf'
self.settings=r'./standard.settings'
self.number=0
self.threads=[]
# Logfile initialization
self.sysout=open(self.output_dir + r'/'+r'/SFIB.log', mode='a')
self.log_out=''
# Initialization for correlation Images and associated tools, e.g. colors for displaying overlays
self.load_image_pixel_size=1
self.corrspots={}
self.copy=[]
self.pointer_projpixmap=None
self.colordict={"green":[0,255,0], "magenta":[255,0,255], "cyan":[0,255,255], "yellow":[255,255,0], "red":[255,0,0], "white":[255,255,255]}
self.CFproj=None
def get_scene(self):
'''
A function that gets the current scene displayed in the GraphicsView
Input: MainWindow class
Output: QGraphicsScene
'''
scene=self.scene
return(scene)
def get_scenebuffer(self):
'''
A function that gets the sceneBuffer
Input: MainWindow class
Output: List of QGraphicsScenes
'''
scenebuffer=self.sceneBuffer
return(scenebuffer)
def push_scene_to_buffer(self,scene,ImageBufferHandle):
'''
Function to overwrite the current scene given by the
ImageBufferHandle with the given scene
Input: scene [QGraphicsScene], ImageBufferHandle [int]
Output: None
'''
scenebuffer=self.sceneBuffer
scenebuffer[ImageBufferHandle]=scene
self.sceneBuffer=scenebuffer
return()
def get_pattern_dict(self):
'''
Function to get the pattern dictionnary for e.g. session file writing
Input: MainWindow class
Output: dictionary of patterns corresponding to the images in the ImageBuffer
'''
return(self.pattern_dict)
def push_pattern_dict(self,pattern_dict_new):
'''
Function to overwrite the pattern_dictionary if session file is read
Input: pattern_dictionary
Output: None
'''
self.pattern_dict=pattern_dict_new
return()
def get_number_imageBuffer(self):
'''
Get imageBufferHandle
Input: Ma
'''
return(self.ImageBufferHandle)
####
def setupUi(self, MainWindow):
'''
GUI Setup as created by pyuic
'''
MainWindow.setObjectName("MainWindow")
MainWindow.resize(1070, 917)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.verticalLayoutWidget = QtWidgets.QWidget(self.centralwidget)
self.verticalLayoutWidget.setGeometry(QtCore.QRect(10, 480, 201, 263))
self.verticalLayoutWidget.setObjectName("verticalLayoutWidget")
self.verticalLayout = QtWidgets.QVBoxLayout(self.verticalLayoutWidget)
self.verticalLayout.setContentsMargins(0, 0, 0, 0)
self.verticalLayout.setObjectName("verticalLayout")
self.label = QtWidgets.QLabel(self.verticalLayoutWidget)
self.label.setAlignment(QtCore.Qt.AlignCenter)
self.label.setObjectName("label")
self.verticalLayout.addWidget(self.label)
self.Button_AddPosition = QtWidgets.QPushButton(self.verticalLayoutWidget)
self.Button_AddPosition.setObjectName("Button_AddPosition")
self.verticalLayout.addWidget(self.Button_AddPosition)
self.Button_SaveImageForAlignment = QtWidgets.QPushButton(self.verticalLayoutWidget)
self.Button_SaveImageForAlignment.setObjectName("Button_SaveImageForAlignment")
self.verticalLayout.addWidget(self.Button_SaveImageForAlignment)
self.Button_SavePatterns = QtWidgets.QPushButton(self.verticalLayoutWidget)
self.Button_SavePatterns.setObjectName("Button_SavePatterns")
self.verticalLayout.addWidget(self.Button_SavePatterns)
self.Button_UpdateZ = QtWidgets.QPushButton(self.verticalLayoutWidget)
self.Button_UpdateZ.setObjectName("Button_UpdateZ")
self.verticalLayout.addWidget(self.Button_UpdateZ)
self.Button_GoToXYZ = QtWidgets.QPushButton(self.verticalLayoutWidget)
self.Button_GoToXYZ.setObjectName("Button_GoToXYZ")
self.verticalLayout.addWidget(self.Button_GoToXYZ)
self.Button_GoToXY = QtWidgets.QPushButton(self.verticalLayoutWidget)
self.Button_GoToXY.setObjectName("Button_GoToXY")
self.verticalLayout.addWidget(self.Button_GoToXY)
self.Button_DeleteItem = QtWidgets.QPushButton(self.verticalLayoutWidget)
self.Button_DeleteItem.setObjectName("Button_DeleteItem")
self.verticalLayout.addWidget(self.Button_DeleteItem)
####
#self.graphicsView = QtWidgets.QGraphicsView(self.centralwidget)
# Replacing the Standard QGraphicsView with the LamellaView Class
self.graphicsView = LamellaView(self.centralwidget)
#####
self.graphicsView.setGeometry(QtCore.QRect(480, 30, 581, 461))
self.graphicsView.setObjectName("graphicsView")
self.verticalLayoutWidget_4 = QtWidgets.QWidget(self.centralwidget)
self.verticalLayoutWidget_4.setGeometry(QtCore.QRect(0, 0, 207, 396))
self.verticalLayoutWidget_4.setObjectName("verticalLayoutWidget_4")
self.verticalLayout_4 = QtWidgets.QVBoxLayout(self.verticalLayoutWidget_4)
self.verticalLayout_4.setContentsMargins(0, 0, 0, 0)
self.verticalLayout_4.setObjectName("verticalLayout_4")
self.label_2 = QtWidgets.QLabel(self.verticalLayoutWidget_4)
self.label_2.setAlignment(QtCore.Qt.AlignCenter)
self.label_2.setObjectName("label_2")
self.verticalLayout_4.addWidget(self.label_2)
self.Button_SetOutputDirectory = QtWidgets.QPushButton(self.verticalLayoutWidget_4)
self.Button_SetOutputDirectory.setObjectName("Button_SetOutputDirectory")
self.verticalLayout_4.addWidget(self.Button_SetOutputDirectory)
self.Button_TakeImageIB = QtWidgets.QPushButton(self.verticalLayoutWidget_4)
self.Button_TakeImageIB.setObjectName("Button_TakeImageIB")
self.verticalLayout_4.addWidget(self.Button_TakeImageIB)
self.Button_TakeImageEB = QtWidgets.QPushButton(self.verticalLayoutWidget_4)
self.Button_TakeImageEB.setObjectName("Button_TakeImageEB")
self.verticalLayout_4.addWidget(self.Button_TakeImageEB)
self.Button_RunRoughProtocol = QtWidgets.QPushButton(self.verticalLayoutWidget_4)
self.Button_RunRoughProtocol.setObjectName("Button_RunRoughProtocol")
self.verticalLayout_4.addWidget(self.Button_RunRoughProtocol)
self.Button_RunFineProtocol = QtWidgets.QPushButton(self.verticalLayoutWidget_4)
self.Button_RunFineProtocol.setObjectName("Button_RunFineProtocol")
self.verticalLayout_4.addWidget(self.Button_RunFineProtocol)
self.Button_RunTrenchMilling = QtWidgets.QPushButton(self.verticalLayoutWidget_4)
self.Button_RunTrenchMilling.setObjectName("Button_RunTrenchMilling")
self.verticalLayout_4.addWidget(self.Button_RunTrenchMilling)
#self.Button_RunRoughMilling = QtWidgets.QPushButton(self.verticalLayoutWidget_4)
#self.Button_RunRoughMilling.setObjectName("Button_RunRoughMilling")
#self.verticalLayout_4.addWidget(self.Button_RunRoughMilling)
#self.Button_RunFineMilling = QtWidgets.QPushButton(self.verticalLayoutWidget_4)
#self.Button_RunFineMilling.setObjectName("Button_RunFineMilling")
#self.verticalLayout_4.addWidget(self.Button_RunFineMilling)
self.Button_LoadCorrelationImages = QtWidgets.QPushButton(self.verticalLayoutWidget_4)
self.Button_LoadCorrelationImages.setObjectName("Button_LoadCorrelationImages")
self.verticalLayout_4.addWidget(self.Button_LoadCorrelationImages)
self.label_3 = QtWidgets.QLabel(self.centralwidget)
self.label_3.setGeometry(QtCore.QRect(710, 10, 141, 16))
self.label_3.setObjectName("label_3")
self.tableWidget = QtWidgets.QTableWidget(self.centralwidget)
self.tableWidget.setGeometry(QtCore.QRect(230, 500, 831, 241))
self.tableWidget.setMouseTracking(False)
self.tableWidget.setAlternatingRowColors(True)
self.tableWidget.setColumnCount(8)
self.tableWidget.setObjectName("tableWidget")
self.tableWidget.setRowCount(0)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(0, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(1, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(2, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(3, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(4, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(5, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(6, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(7, item)
self.plainTextEdit = QtWidgets.QPlainTextEdit(self.centralwidget)
self.plainTextEdit.setGeometry(QtCore.QRect(10, 760, 1051, 111))
self.plainTextEdit.setReadOnly(True)
self.plainTextEdit.setObjectName("plainTextEdit")
self.label_4 = QtWidgets.QLabel(self.centralwidget)
self.label_4.setGeometry(QtCore.QRect(490, 740, 60, 16))
self.label_4.setObjectName("label_4")
self.ImageBuffer = QtWidgets.QListWidget(self.centralwidget)
self.ImageBuffer.setGeometry(QtCore.QRect(220, 30, 251, 201))
self.ImageBuffer.setObjectName("ImageBuffer")
self.label_5 = QtWidgets.QLabel(self.centralwidget)
self.label_5.setGeometry(QtCore.QRect(300, 10, 91, 16))
self.label_5.setObjectName("label_5")
self.comboBox = QtWidgets.QComboBox(self.centralwidget)
self.comboBox.setGeometry(QtCore.QRect(260, 430, 141, 26))
self.comboBox.setObjectName("comboBox")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.checkBox_fluo = QtWidgets.QCheckBox(self.centralwidget)
self.checkBox_fluo.setGeometry(QtCore.QRect(260, 400, 171, 20))
self.checkBox_fluo.setObjectName("checkBox_fluo")
self.label_6 = QtWidgets.QLabel(self.centralwidget)
self.label_6.setGeometry(QtCore.QRect(250, 470, 60, 16))
self.label_6.setObjectName("label_6")
self.label_7 = QtWidgets.QLabel(self.centralwidget)
self.label_7.setGeometry(QtCore.QRect(290, 240, 121, 16))
self.label_7.setObjectName("label_7")
self.verticalLayoutWidget_2 = QtWidgets.QWidget(self.centralwidget)
self.verticalLayoutWidget_2.setGeometry(QtCore.QRect(240, 260, 211, 134))
self.verticalLayoutWidget_2.setObjectName("verticalLayoutWidget_2")
self.verticalLayout_2 = QtWidgets.QVBoxLayout(self.verticalLayoutWidget_2)
self.verticalLayout_2.setContentsMargins(0, 0, 0, 0)
self.verticalLayout_2.setObjectName("verticalLayout_2")
self.Button_SetSAVparameters = QtWidgets.QPushButton(self.verticalLayoutWidget_2)
self.Button_SetSAVparameters.setObjectName("Button_SetSAVparameters")
self.verticalLayout_2.addWidget(self.Button_SetSAVparameters)
self.Button_RunVolumeImaging = QtWidgets.QPushButton(self.verticalLayoutWidget_2)
self.Button_RunVolumeImaging.setObjectName("Button_RunVolumeImaging")
self.verticalLayout_2.addWidget(self.Button_RunVolumeImaging)
self.Button_RunCustomProtocol = QtWidgets.QPushButton(self.verticalLayoutWidget_2)
self.Button_RunCustomProtocol.setObjectName("Button_RunCustomProtocol")
self.verticalLayout_2.addWidget(self.Button_RunCustomProtocol)
self.Button_RunCustomPatternfile = QtWidgets.QPushButton(self.verticalLayoutWidget_2)
self.Button_RunCustomPatternfile.setObjectName("Button_RunCustomPatternfile")
self.verticalLayout_2.addWidget(self.Button_RunCustomPatternfile)
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 1070, 22))
self.menubar.setObjectName("menubar")
self.menuFile = QtWidgets.QMenu(self.menubar)
self.menuFile.setObjectName("menuFile")
self.menuTools = QtWidgets.QMenu(self.menubar)
self.menuTools.setObjectName("menuTools")
self.menuCorrelation = QtWidgets.QMenu(self.menubar)
self.menuCorrelation.setObjectName("menuCorrelation")
self.menuTesting = QtWidgets.QMenu(self.menubar)
self.menuTesting.setObjectName("menuTesting")
self.menuSettings = QtWidgets.QMenu(self.menubar)
self.menuSettings.setObjectName("menuSettings")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.actionOpen = QtWidgets.QAction(MainWindow)
self.actionOpen.setObjectName("actionOpen")
self.actionClose = QtWidgets.QAction(MainWindow)
self.actionClose.setObjectName("actionClose")
self.actionSave_Session = QtWidgets.QAction(MainWindow)
self.actionSave_Session.setObjectName("actionSave_Session")
self.actionLoad_Session = QtWidgets.QAction(MainWindow)
self.actionLoad_Session.setObjectName("actionLoad_Session")
self.actionClose_2 = QtWidgets.QAction(MainWindow)
self.actionClose_2.setObjectName("actionClose_2")
self.actionOpen_Scripting = QtWidgets.QAction(MainWindow)
self.actionOpen_Scripting.setObjectName("actionOpen_Scripting")
self.actionScripting = QtWidgets.QAction(MainWindow)
self.actionScripting.setObjectName("actionScripting")
self.actionOpen_PatternDesigner = QtWidgets.QAction(MainWindow)
self.actionOpen_PatternDesigner.setObjectName("actionOpen_PatternDesigner")
self.actionCompute_FluoProjection = QtWidgets.QAction(MainWindow)
self.actionCompute_FluoProjection.setObjectName("actionCompute_FluoProjection")
self.actionLoad_Fluo_Projection = QtWidgets.QAction(MainWindow)
self.actionLoad_Fluo_Projection.setObjectName("actionLoad_Fluo_Projection")
self.actionLoad_Correlation_Images = QtWidgets.QAction(MainWindow)
self.actionLoad_Correlation_Images.setObjectName("actionLoad_Correlation_Images")
self.actionTestbutton1 = QtWidgets.QAction(MainWindow)
self.actionTestbutton1.setObjectName("actionTestbutton1")
self.actionTestbutton2 = QtWidgets.QAction(MainWindow)
self.actionTestbutton2.setObjectName("actionTestbutton2")
self.actionTestbutton3 = QtWidgets.QAction(MainWindow)
self.actionTestbutton3.setObjectName("actionTestbutton3")
self.actionTestbutton4 = QtWidgets.QAction(MainWindow)
self.actionTestbutton4.setObjectName("actionTestbutton4")
self.actionTestbutton5 = QtWidgets.QAction(MainWindow)
self.actionTestbutton5.setObjectName("actionTestbutton5")
self.actionSaveSettings = QtWidgets.QAction(MainWindow)
self.actionSaveSettings.setObjectName("actionSaveSettings")
self.actionLoadSettings = QtWidgets.QAction(MainWindow)
self.actionLoadSettings.setObjectName("actionLoadSettings")
self.actionVolumeDesigner = QtWidgets.QAction(MainWindow)
self.actionVolumeDesigner.setObjectName("actionVolumeDesigner")
self.actionLamellaDesigner = QtWidgets.QAction(MainWindow)
self.actionLamellaDesigner.setObjectName("actionLamellaDesigner")
self.actionSet_Output_Directory = QtWidgets.QAction(MainWindow)
self.actionSet_Output_Directory.setObjectName("actionSet_Output_Directory")
self.actionSet_SAV_parameters = QtWidgets.QAction(MainWindow)
self.actionSet_SAV_parameters.setObjectName("actionSet_SAV_parameters")
self.actionSet_Output_Directory_2 = QtWidgets.QAction(MainWindow)
self.actionSet_Output_Directory_2.setObjectName("actionSet_Output_Directory_2")
self.actionSet_Rough_Mill_protocol = QtWidgets.QAction(MainWindow)
self.actionSet_Rough_Mill_protocol.setObjectName("actionSet_Rough_Mill_protocol")
self.actionSet_Fine_Mill_protocol = QtWidgets.QAction(MainWindow)
self.actionSet_Fine_Mill_protocol.setObjectName("actionSet_Fine_Mill_protocol")
self.actionSet_Custom_Protocol = QtWidgets.QAction(MainWindow)
self.actionSet_Custom_Protocol.setObjectName("actionSet_Custom_Protocol")
self.actionSet_Custom_Milling = QtWidgets.QAction(MainWindow)
self.actionSet_Custom_Milling.setObjectName("actionSet_Custom_Milling")
self.menuFile.addAction(self.actionOpen)
self.menuFile.addAction(self.actionSave_Session)
self.menuFile.addAction(self.actionLoad_Session)
self.menuTools.addAction(self.actionLamellaDesigner)
self.menuTools.addAction(self.actionVolumeDesigner)
self.menuTools.addAction(self.actionOpen_PatternDesigner)
self.menuTools.addAction(self.actionScripting)
self.menuCorrelation.addAction(self.actionLoad_Correlation_Images)
self.menuCorrelation.addAction(self.actionCompute_FluoProjection)
self.menuCorrelation.addAction(self.actionLoad_Fluo_Projection)
self.menuTesting.addAction(self.actionTestbutton1)
self.menuTesting.addAction(self.actionTestbutton2)
self.menuTesting.addAction(self.actionTestbutton3)
self.menuTesting.addAction(self.actionTestbutton4)
self.menuTesting.addAction(self.actionTestbutton5)
self.menuSettings.addAction(self.actionSaveSettings)
self.menuSettings.addAction(self.actionLoadSettings)
self.menuSettings.addAction(self.actionSet_Output_Directory_2)
self.menuSettings.addAction(self.actionSet_SAV_parameters)
self.menuSettings.addAction(self.actionSet_Rough_Mill_protocol)
self.menuSettings.addAction(self.actionSet_Fine_Mill_protocol)
self.menuSettings.addAction(self.actionSet_Custom_Protocol)
self.menuSettings.addAction(self.actionSet_Custom_Milling)
self.menubar.addAction(self.menuFile.menuAction())
self.menubar.addAction(self.menuTools.menuAction())
self.menubar.addAction(self.menuCorrelation.menuAction())
self.menubar.addAction(self.menuSettings.menuAction())
self.menubar.addAction(self.menuTesting.menuAction())
#self.actionTestbutton3.triggered.connect(self.roughprotocol)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
'''
GUI Translate as created by pyuic5
'''
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "Serial FIB"))
self.label.setText(_translate("MainWindow", "Lamellae"))
self.Button_AddPosition.setText(_translate("MainWindow", "Add Position"))
self.Button_SaveImageForAlignment.setText(_translate("MainWindow", "Save Image for Alignment"))
self.Button_SavePatterns.setText(_translate("MainWindow", "Save Patterns"))
self.Button_UpdateZ.setText(_translate("MainWindow", "Update Z"))
self.Button_GoToXYZ.setText(_translate("MainWindow", "Go To XYZ"))
self.Button_GoToXY.setText(_translate("MainWindow", "Go To XY"))
self.Button_DeleteItem.setText(_translate("MainWindow", "Delete Item"))
self.label_2.setText(_translate("MainWindow", "Main Functions"))
self.Button_SetOutputDirectory.setText(_translate("MainWindow", "Set Output Directory"))
self.Button_TakeImageIB.setText(_translate("MainWindow", "Take Image IB"))
self.Button_TakeImageEB.setText(_translate("MainWindow", "Take Image EB"))
self.Button_RunRoughProtocol.setText(_translate("MainWindow", "Run Rough Protocol"))
self.Button_RunFineProtocol.setText(_translate("MainWindow", "Run Fine Protocol"))
self.Button_RunTrenchMilling.setText(_translate("MainWindow", "Run Trench Milling"))
#self.Button_RunRoughMilling.setText(_translate("MainWindow", "Run Rough Milling"))
#self.Button_RunFineMilling.setText(_translate("MainWindow", "Run Fine Milling"))
self.Button_LoadCorrelationImages.setText(_translate("MainWindow", "Load Correlation Images"))
self.label_3.setText(_translate("MainWindow", "Alignment Image"))
item = self.tableWidget.horizontalHeaderItem(0)
item.setText(_translate("MainWindow", "Label"))
item = self.tableWidget.horizontalHeaderItem(1)
item.setText(_translate("MainWindow", "X"))
item = self.tableWidget.horizontalHeaderItem(2)
item.setText(_translate("MainWindow", "Y"))
item = self.tableWidget.horizontalHeaderItem(3)
item.setText(_translate("MainWindow", "Z"))
item = self.tableWidget.horizontalHeaderItem(4)
item.setText(_translate("MainWindow", "R"))
item = self.tableWidget.horizontalHeaderItem(5)
item.setText(_translate("MainWindow", "T"))
item = self.tableWidget.horizontalHeaderItem(6)
item.setText(_translate("MainWindow", "Alignment Image?"))
item = self.tableWidget.horizontalHeaderItem(7)
item.setText(_translate("MainWindow", "Patterns?"))
self.label_4.setText(_translate("MainWindow", "Error Log"))
self.label_5.setText(_translate("MainWindow", "Image Buffer"))
self.comboBox.setItemText(0, _translate("MainWindow", "green"))
self.comboBox.setItemText(1, _translate("MainWindow", "magenta"))
self.comboBox.setItemText(2, _translate("MainWindow", "cyan"))
self.comboBox.setItemText(3, _translate("MainWindow", "yellow"))
self.comboBox.setItemText(4, _translate("MainWindow", "red"))
self.comboBox.setItemText(5, _translate("MainWindow", "white"))
self.checkBox_fluo.setText(_translate("MainWindow", "Fluorescence Overlay"))
self.label_6.setText(_translate("MainWindow", "Positions"))
self.label_7.setText(_translate("MainWindow", "Custom Functions"))
self.Button_SetSAVparameters.setText(_translate("MainWindow", "Set SAV parameters"))
self.Button_RunVolumeImaging.setText(_translate("MainWindow", "Run Volume Imaging"))
self.Button_RunCustomProtocol.setText(_translate("MainWindow", "Run Custom Protocol"))
self.Button_RunCustomPatternfile.setText(_translate("MainWindow", "Run Custom Patternfile"))
self.menuFile.setTitle(_translate("MainWindow", "File"))
self.menuTools.setTitle(_translate("MainWindow", "Tools"))
self.menuCorrelation.setTitle(_translate("MainWindow", "Correlation"))
self.menuTesting.setTitle(_translate("MainWindow", "Testing"))
self.menuSettings.setTitle(_translate("MainWindow", "Settings"))
self.actionOpen.setText(_translate("MainWindow", "Open New"))
self.actionClose.setText(_translate("MainWindow", "Close"))
self.actionSave_Session.setText(_translate("MainWindow", "Save Session"))
self.actionLoad_Session.setText(_translate("MainWindow", "Load Session"))
self.actionClose_2.setText(_translate("MainWindow", "Close"))
self.actionOpen_Scripting.setText(_translate("MainWindow", "Open Scripting"))
self.actionScripting.setText(_translate("MainWindow", "ScriptEditor"))
self.actionOpen_PatternDesigner.setText(_translate("MainWindow", "PatternDesigner"))
self.actionCompute_FluoProjection.setText(_translate("MainWindow", "Compute FluoProjection"))
self.actionLoad_Fluo_Projection.setText(_translate("MainWindow", "Load Fluo Projection"))
self.actionLoad_Correlation_Images.setText(_translate("MainWindow", "Load Correlation Images"))
self.actionTestbutton1.setText(_translate("MainWindow", "Draw Corr Pattern"))
self.actionTestbutton2.setText(_translate("MainWindow", "Align to Image Buffer"))
self.actionTestbutton3.setText(_translate("MainWindow", "Change Alignment Current"))
self.actionTestbutton4.setText(_translate("MainWindow", "Testbutton4"))
self.actionTestbutton5.setText(_translate("MainWindow", "Testbutton5"))
self.actionSaveSettings.setText(_translate("MainWindow", "SaveSettings"))
self.actionLoadSettings.setText(_translate("MainWindow", "LoadSettings"))
self.actionVolumeDesigner.setText(_translate("MainWindow", "VolumeDesigner"))
self.actionLamellaDesigner.setText(_translate("MainWindow", "LamellaDesigner"))
self.actionSet_Output_Directory.setText(_translate("MainWindow", "Set Output Directory"))
self.actionSet_SAV_parameters.setText(_translate("MainWindow", "Set SAV parameters"))
self.actionSet_Output_Directory_2.setText(_translate("MainWindow", "Set Output Directory"))
self.actionSet_Rough_Mill_protocol.setText(_translate("MainWindow", "Set Rough Mill protocol"))
self.actionSet_Fine_Mill_protocol.setText(_translate("MainWindow", "Set Fine Mill protocol"))
self.actionSet_Custom_Protocol.setText(_translate("MainWindow", "Set Custom Protocol"))
self.actionSet_Custom_Milling.setText(_translate("MainWindow", "Set Custom Milling"))
##################################
#### BUTTON DEFINITIONS #########
##################################
# Testcase defintion
self.testCase=True
self.ktest=0
# IMAGE BUFFER DEFINE
self.ImageBufferImages=[]
#self.ImageBufferHandle=0
'''
Whenever an image from the image buffer is loaded by double clicking
saving of the patterns is triggered into the pattern_dict as well as
showInGraphview, which takes the current ImageBufferHandle as changed by
double clicking and load that image into the GraphView
'''
self.ImageBuffer.itemDoubleClicked.connect(self.savePatterns)
self.ImageBuffer.itemDoubleClicked.connect(self.showInGraphview)
self.pattern_root=""
'''
ShortCut definitions for deleting patterns and fullscreenmode
'''
#### Delete Option ####
self.shortcut_backspace = QtWidgets.QShortcut(QtGui.QKeySequence("Backspace"), MainWindow)
self.shortcut_backspace.activated.connect(self.pattern_delete)
self.shortcut_delete = QtWidgets.QShortcut(QtGui.QKeySequence("Del"), MainWindow)
self.shortcut_delete.activated.connect(self.pattern_delete)
self.shortcut_fullscreen_graphview=QtWidgets.QShortcut(QtCore.Qt.Key_F5,MainWindow)
self.shortcut_fullscreen_graphview.activated.connect(self.toggleFullScreen)
self.shortcut_F6=QtWidgets.QShortcut(QtCore.Qt.Key_F6,MainWindow)
self.shortcut_F6.activated.connect(self.key_F6)
self.shortcut_copy=QtWidgets.QShortcut(QtGui.QKeySequence("Ctrl+c"),MainWindow)
self.shortcut_copy.activated.connect(self.button_savePatterns)
self.shortcut_copy.activated.connect(self.copy_patterns)
self.shortcut_paste=QtWidgets.QShortcut(QtGui.QKeySequence("Ctrl+v"),MainWindow)
self.shortcut_paste.activated.connect(self.paste_patterns)
#TextLogger
sys.stdout = Stream(newText=self.onUpdateText)
'''
Button Definitions
'''
# Button_Add_Position
self.Button_AddPosition.pressed.connect(self.AddPosition)
self.Button_AddPosition.pressed.connect(self.addRow)
# Button_DeleteItem
self.Button_DeleteItem.pressed.connect(self.removeRow)
# Button_GoToXYZ
self.Button_GoToXYZ.pressed.connect(self.GoToXYZ)
# Button_GoToXY
self.Button_GoToXY.pressed.connect(self.GoToXY)
# Button Take Image IB
self.Button_TakeImageIB.pressed.connect(self.button_savePatterns)
self.Button_TakeImageIB.pressed.connect(self.button_take_image_IB)
# Button Take Image EB
self.Button_TakeImageEB.pressed.connect(self.button_take_image_EB)
# Button Save Image for Alignment
self.Button_SaveImageForAlignment.pressed.connect(self.SaveImageForAlignment)
# Button Save Patterns
self.Button_SavePatterns.pressed.connect(self.button_savePatterns)
# Button Load Correlated Image
self.Button_LoadCorrelationImages.pressed.connect(self.load_correlated_image)
# Button Set Output Directory
self.Button_SetOutputDirectory.pressed.connect(self.define_directory)
self.Button_UpdateZ.pressed.connect(self.UpdateZ)
self.Button_SetSAVparameters.pressed.connect(self.define_SAVparams)
# Thread based implementations Button definition
self.Button_RunRoughProtocol.pressed.connect(self.roughprotocol)
self.Button_RunFineProtocol.pressed.connect(self.fineprotocol)
self.Button_RunVolumeImaging.pressed.connect(self.volumeimaging)
self.Button_RunCustomProtocol.pressed.connect(self.customprotocol)
self.Button_RunTrenchMilling.pressed.connect(self.trenchmill)
self.Button_RunCustomPatternfile.pressed.connect(self.custompatternfilerun)
'''
File Tab
'''
# Button Save Session
self.actionSave_Session.triggered.connect(self.save_session)
# Button Load Session
self.actionLoad_Session.triggered.connect(self.load_session)
# Button New Session
self.actionOpen.triggered.connect(self.new_session)
'''
Tools Tab
'''
# Button Open Scripting
self.actionScripting.triggered.connect(self.open_scripting)
# Button Open PatternEditor
self.actionOpen_PatternDesigner.triggered.connect(self.open_patterneditor)
self.actionVolumeDesigner.triggered.connect(self.open_volumedesigner)
self.actionLamellaDesigner.triggered.connect(self.open_lamelladesigner)
'''
Fluorescence Tab
'''
self.actionLoad_Correlation_Images.triggered.connect(self.load_correlated_image)
self.actionCompute_FluoProjection.triggered.connect(self.compute_fluo_proj)
self.actionLoad_Fluo_Projection.triggered.connect(self.load_fluo_proj)
self.checkBox_fluo.stateChanged.connect(self.overlay_fluo)
self.comboBox.currentIndexChanged.connect(self.overlay_fluo)
'''
Settings Tab
'''
self.actionSet_Output_Directory.triggered.connect(self.define_directory)
self.actionSet_Output_Directory_2.triggered.connect(self.define_directory)
self.actionSet_SAV_parameters.triggered.connect(self.define_SAVparams)
self.actionSet_Rough_Mill_protocol.triggered.connect(self.define_roughmillprotocol)
self.actionSet_Fine_Mill_protocol.triggered.connect(self.define_finemillprotocol)
self.actionSet_Custom_Protocol.triggered.connect(self.define_custommillprotocol)
self.actionSet_Custom_Milling.triggered.connect(self.define_custompatternfile)
self.actionSaveSettings.triggered.connect(self.save_settings)
self.actionLoadSettings.triggered.connect(self.load_settings)
'''
TestButtons
'''
# Button for Testing
self.actionTestbutton1.triggered.connect(self.draw_corr_pattern)
self.actionTestbutton2.triggered.connect(self.align_to_item)
self.actionTestbutton3.triggered.connect(self.set_alignment_current)
#### Graphics Viewer
self.graphicsView.aspectRatioMode = QtCore.Qt.KeepAspectRatio
##################################
# CODE:Button_take_image_IB #
##################################
def button_take_image_IB(self):
'''
Button to take an image at current mag etc. using the ion beam
Uses the driver function take_image_IB()
Input: None
Output: None
Action: Addition of image to ImageBuffer, showing Image in GraphicsView
'''
# ImageBufferHandle is set to the last image as given by the amount of images in the ImageBuffer
self.ImageBufferHandle=self.ImageBuffer.count()
# Image is taken using the Driver function and added as last element in the ImageBuffer
img=scope.take_image_IB()
numRows = self.ImageBuffer.count()
self.ImageBuffer.addItem(str(numRows) + " (IB Image)")
# Image Scene is grabed in order to set a new scene in the GraphicsView
scene=self.get_scene()
scene.clear()
self.graphicsView.setScene(scene)
# Check if image was taken, else add testimage
if self.testCase==True:
self.ktest=self.ktest+1
if img==():
if self.ktest%2==0:
array=testimage.data
self.ImageBufferImages.append(testimage)
else:
array=testimage2.data
self.ImageBufferImages.append(testimage2)
#print("Bla")
else:
array=img.data
self.ImageBufferImages.append(img)
else:
if img==():
print("No Microscope connected!")
return()
else:
array=img.data
self.ImageBufferImages.append(img)
### Convert 16 bit image to 8 bit to show it in the GraphicsView
array8u=cv2.convertScaleAbs(array, alpha=(255.0/65535.0))
img_8bit=np.uint8(array)
height,width=np.shape(img_8bit)
qImg=QtGui.QImage(img_8bit, width, height, QtGui.QImage.Format_Grayscale8)
pixmapImg=QtGui.QPixmap.fromImage(qImg)
# Set scene size to image size.
self.graphicsView.setSceneRect(QtCore.QRectF(pixmapImg.rect()))
self.graphicsView.fitInView(self.graphicsView.sceneRect(),self.graphicsView.aspectRatioMode)
w2=self.graphicsView.sceneRect().width()
h2=self.graphicsView.sceneRect().height()
#Add Image as pixmap to scene
scene.addPixmap(pixmapImg)
# Update SceneBuffer
self.scene=scene
self.sceneBuffer.append(self.scene)
# New Image cannot have fluorescence information, thus set checkBox to false
self.checkBox_fluo.setChecked(False)
# Adjust ImageBufferHandle to new Image
self.ImageBufferHandle=self.ImageBuffer.count()+1
return()
##################################
# /CODE:Button_take_image_IB #
##################################
def load_images(self,image):
'''
Same Setup as take_image_IB only that an image is loaded from a file
Input: Image as .tif
Output: None
Action: Addition of image to ImageBuffer, showing Image in GraphicsView
'''
numRows = self.ImageBuffer.count()
self.ImageBuffer.addItem(str(numRows) + " (IB Image)")
scene=self.get_scene()
scene.clear()
self.graphicsView.setScene(scene)
# Check if image was taken, else add testimage
if image==():
print("No Microscope connected!")
return()
else:
array=image.data
self.ImageBufferImages.append(image)
### Convert 16 bit image to 8 bit to show it in the GrahpicsView
array8u=cv2.convertScaleAbs(array, alpha=(255.0/65535.0))
img_8bit=np.uint8(array)
height,width=np.shape(img_8bit)
qImg=QtGui.QImage(img_8bit, width, height, QtGui.QImage.Format_Grayscale8)
pixmapImg=QtGui.QPixmap.fromImage(qImg)
# Set scene size to image size.
self.graphicsView.setSceneRect(QtCore.QRectF(pixmapImg.rect()))
self.graphicsView.fitInView(self.graphicsView.sceneRect(),self.graphicsView.aspectRatioMode)
w2=self.graphicsView.sceneRect().width()
h2=self.graphicsView.sceneRect().height()
#Add Image as pixmap to scene
scene.addPixmap(pixmapImg)
# Update SceneBuffer
self.scene=scene
self.sceneBuffer.append(self.scene)
# New Image cannot have fluorescence information, thus set checkBox to false
self.checkBox_fluo.setChecked(False)
return()
##################################
# CODE:Button_take_image_EB #
##################################
def button_take_image_EB(self):
'''
Button to take an image at current mag etc. using the electron beam
Uses the driver function take_image_EB()
Input: None
Output: None
Action: Addition of image to ImageBuffer, showing Image in GraphicsView
'''
img=scope.take_image_EB()
numRows = self.ImageBuffer.count()
self.ImageBuffer.addItem(str(numRows) + " (EB Image)")
scene=self.get_scene()
scene.clear()
self.graphicsView.setScene(scene)
self.ImageBufferHandle=numRows
# Check if image was taken, else add testimage
if self.testCase==True:
self.ktest=self.ktest+1
if img==():
if self.ktest%2==0:
array=testimage.data
self.ImageBufferImages.append(testimage)
else:
array=testimage2.data
self.ImageBufferImages.append(testimage2)
else:
array=img.data
self.ImageBufferImages.append(img)
else:
if img==():
print("No Microscope connected!")
return()
else:
array=img.data
self.ImageBufferImages.append(img)
### Convert 16 bit image to 8 bit to show it in the GrahpicsView
array8u=cv2.convertScaleAbs(array, alpha=(255.0/65535.0))
img_8bit=np.uint8(array)
height,width=np.shape(img_8bit)
qImg=QtGui.QImage(img_8bit, width, height, QtGui.QImage.Format_Grayscale8)
pixmapImg=QtGui.QPixmap.fromImage(qImg)
# Set scene size to image size.
self.graphicsView.setSceneRect(QtCore.QRectF(pixmapImg.rect()))
self.graphicsView.fitInView(self.graphicsView.sceneRect(),self.graphicsView.aspectRatioMode)
#Add Image as pixmap to scene
scene.addPixmap(pixmapImg)
# Update SceneBuffer
self.scene=scene
self.sceneBuffer.append(self.scene)
self.checkBox_fluo.setChecked(False)
return()
##################################
# /CODE:Button_take_image_EB #
##################################
##################################
# CODE:Button_run_rough_mill #
##################################
def Signal_Done(self,result):
print("Result: "+result)
self.progressDialog.close()
return()
def showInGraphview(self):
#self.savePatterns()
try:
number=self.ImageBuffer.currentItem().text().split(" ")[0]
except:
number=0