-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPy16GUI.py
More file actions
5051 lines (4147 loc) · 196 KB
/
Py16GUI.py
File metadata and controls
5051 lines (4147 loc) · 196 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
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 -*-
"""
Selection of graphical user interfaces (GUIs) that allow fast viewing and analysis of data
on the beamline I16 at Diamond Light Source Ltd.
By Dan Porter, PhD
Diamond
2016
Usage:
On an I16 workstation (as I16user)
- Double click the shortcut on the desktop "I16_Data_Viewer"
- Select "Run in Console"
On another Diamond workstation, the Diamond NX server or when remotely connecting:
- Open a terminal
- Type:
>> cd /dls_sw/i16/software/python/Py16/
>> module load python/ana
>> ipython -i --matplotlib tk Py16GUI.py
On another system
- Open a terminal/ console/ command prompt
Type:
>> cd /direcotry of Py16GUI.py
>> ipython -i --matplotlib tk Py16GUI.py
Operation:
1. On running the program, the main GUI (I16_Data_Viewer) will appear
2. Browse for the experimental and analysis directories
- the experimental directory is where the scan data is stored
- the analysis directory is where you wish to store any data you save or scripts you create
3. Click "Last" to load the latest data with automaticaly choosen axes
More Operations:
- Click "Update Pilatus Plot" to load the images from any area detector
- Click "Last Scans" to see a list of the last 100 scans that are selectable to plot
- Select a function from the "Fit" dropdown menu to apply a fit the current plot
- Click "Multiplot/ Peak Analysis" to open the I16_Peak_Analysis GUI
- Click "Export Plot" to generate an figure of the current scan
- Click "Print Current Scan" to send an image of the current scan to the default printer
- Click "Print All Figures" to send all open figures to a single 2x3 page
- Click "Meta" to see a full list of metadata for this scan
- Tick the box "Live Mode" to automatically update the GUI every 10s
- Click "Params" to change default parameters, such as error bars and temperature sensor
Console Commands:
If run in an interactive terminal, there is access to more functions via the command line, using the module "Py16progs.py"
It is already instantiated/ imported in the current session and is named "pp". For example:
pp.plotscan(123456) # plots the scan number 123456
d = pp.readscan(123456) # creates a data holder object 'd' with scan data
x,y,dy,varx,vary,ttl,d = pp.getdata(123456) # returns x/y data with automatic choice of variables
help(pp.getdata) # see the documentation on this function
Scripting:
Simple scipts can be automatically written to the analysis directory from the "MultiPlot/ Pleak Analysis" window
Pressing "Create File" will write a script including all necessary imports and parameters.
The script can the be altered for more complex analysis. Calls to the many functions in Py16Progs.py can be
made using the imported name "dp", for example:
dp.plotscan(123456) # plots the scan number 123456
d = dp.readscan(123456) # creates a data holder object 'd' with scan data
x,y,dy,varx,vary,ttl,d = dp.getdata(123456) # returns x/y data with automatic choice of variables
Custom Regions of Interest:
It is possible to define new regions of interest on an area detector and plot these.
Note that manual regions of interest have hot and broken pixels set to zero.
- Select the scan
- Click "Update Pilatus Plot"
- Edit the "Centre" and "ROI" boxes to define the box centre and size, press enter to update the plot
- The button "Find Peak" will find the largest pixel, the buttons "roi2" and "roi1" will generate standard ROIs
- In the "Y" dropdown menu, choose "Custom ROI" to plot the sum of this ROI
- Or: Choose "ROI - bkg" to plot the background subtracted sum (the background is defined by a region twice the ROIs size)
**********************
Main GUIs:
I16_Data_Viewer - Starts automatically, set the experiment directory to see scan details, plot scan and area detector data, access other GUIs
I16_Peak_Analysis - Plot and analyse multiple scans, including peak fitting and integration
I16_Advanced_Fitting - More fitting options, including masks
colour_cutoffs - A separate GUI that will interactively change the colormap max/min of the current figure.
Version 4.8.2
Last updated: 07/02/22
Version History:
07/02/16 0.9 Program created
29/02/16 1.0 I16_Data_Viewer and I16_Peak_Analysis Finished
03/03/16 1.1 Tested on Beamline, removed errors, cleaned up
28/04/16 1.2 Added Find Peak button
05/05/16 1.3 Added helper bar, made pilatus button clearer
09/05/16 1.4 Added buttons for find files and meta
10/05/16 1.5 Added print buffer + close all buttons
20/05/16 1.6 Added fit function to fit option menu and fixed reploting issue
12/07/16 1.7 Added Advanced Peak Fitting GUI
10/08/16 1.8 Added logplot and diffplot options
08/09/16 1.9 Added auto pilatus update checkbox
24/09/16 2.0 Removed requirement for SciSoftPi data loader
07/10/16 2.1 Some minor corrections, addition of parameters window
17/10/16 2.2 Addition of rem. Bkg for pilatus and pilatus peakregion/ background lines
14/12/16 2.3 New option menus for exp directories and X,Y variables, other minor improvements
20/12/16 2.4 Main app now resizes for screensize, Mac option added. Fixes for option menus. New Check buttons
08/02/17 2.5 Log of pilatus images added, other bugs fixed
25/02/17 2.6 Minor corrections and fixes, including multi-variable advanced fitting and persistence of custom ROIs
11/07/17 2.7 Added scan selector
24/07/17 2.8 Added colour_cutoffs and other bug fixes
01/08/17 2.9 Added check for large pilatus arrays, parameter "max array" in parameters window
02/10/17 2.9 Added ability to turn off normalisation in multi-plots
06/10/17 3.0 Added log plot to multiplots, plus other fixes
10/10/17 3.1 Added I16_Meta_Display, multiplotting from scan selector
23/10/17 3.2 Several minor improvements, including choice of plots for fitting
01/12/17 3.3 Update for matplotlib V2.1, reduce figure dpi, fix scaling of detector images
06/12/17 3.4 Added buttons for pixel2hkl and pixel2tth, plus other fixes
26/02/18 3.5 Added Custom Details plus improvements to image plotting, more fit functions
09/03/18 3.6 Updated to correct for python3.6 test errors
18/03/18 3.7 Default savedir directory, save Py16 parameter files to savedir directory
01/05/18 3.8 Updated for new PA + pilatus3
16/07/18 3.9 Upgraded Print_Buffer, added new plot options to multi-plot, added multi_plot input
20/11/18 4.0 Added plot toolbar, fast buttons for pilatus, external text viewer for log and checkscan
14/12/18 4.1 Some bug fixes, added windows printing
21/02/19 4.2 Some bug fixes, save scan corrected for custom rois, improved More Check Options
16/04/19 4.3 Added error checking on metadata
15/05/19 4.4 Added metadata plotting
23/10/19 4.5 Now python3 compatible, added metadata search and nexus button
29/11/19 4.6 Corrected multiple depvar error in multiplot
10/02/20 4.6 Changed multiplot range to list(range) for python3
29/02/20 4.6 Added reload to python gui
27/05/20 4.7 Added licence
11/02/21 4.8 Added colormap options, added image_gui
29/09/21 4.8.1 Corrected Meta_Display for None values
07/02/22 4.8.2 Some small changes
31/10/24 4.8.3 Attempted to make work in python 3.10 but askdirectory() doesn't work during run
###FEEDBACK### Please submit your bug reports, feature requests or queries to: dan.porter@diamond.ac.uk
@author: Dan Porter
I16, Diamond Light Source
2016
-----------------------------------------------------------------------------
Copyright 2020 Diamond Light Source Ltd.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Dr Daniel G Porter, dan.porter@diamond.ac.uk
www.diamond.ac.uk
Diamond Light Source, Chilton, Didcot, Oxon, OX11 0DE, U.K.
"""
"""
Future Ideas:
- Convert to Qt
- Add hover boxes over buttons
- During live mode, show last line of log file in info bar
- Advanced plot allow different estimates
- Advanced plot multi peak fitting
"""
import sys,os,datetime,time,subprocess,tempfile,glob,re
import __main__ as main
import numpy as np
if sys.version_info[0] < 3:
import Tkinter as tk
import tkFileDialog as filedialog
import tkMessageBox as messagebox
else:
import tkinter as tk
from tkinter import filedialog
from tkinter import messagebox
import matplotlib
matplotlib.use("TkAgg")
import matplotlib.pyplot as plt
import matplotlib.ticker as mtick
from matplotlib.colors import Normalize, LogNorm
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
try:
from matplotlib.backends.backend_tkagg import NavigationToolbar2TkAgg
except ImportError:
from matplotlib.backends.backend_tkagg import NavigationToolbar2Tk as NavigationToolbar2TkAgg
"""
# Import scisoftpy - dnp.io.load is used to read #.dat files
try:
import scisoftpy as dnp # Make sure this is in your python path
except ImportError:
# Find scisoftpy
print 'Hang on... just looking for scisoftpy...'
for dirName, subdirList, fileList in os.walk(os.path.abspath(os.sep)):
if 'uk.ac.diamond.scisoft.python' in dirName:
print 'Found scisoftpy at: ',dirName
sys.path.insert(0,dirName)
break
import scisoftpy as dnp
"""
# Import Py16progs - interprets data loaded and other handy functions
cf = os.path.abspath(os.path.dirname(__file__))
if cf not in sys.path:
print('Adding to path: ''{}'''.format(cf) )
sys.path.insert(0,cf)
import Py16progs as pp
try:
from image_gui import ImageGui
except ImportError:
print('ImageGui not available, please download image_gui.py to view detector images.')
# Version
Py16GUI_Version = '4.8.3'
# Print layout
default_print_layout = [3,2]
print_platform = 'windows' # different print commands for different os's
# App Fonts
BF= ["Times", 12]
SF= ["Times New Roman", 14]
LF= ["Times", 14]
HF= ['Courier',12]
# App Figure Sizes
WINDOWS = {'scan':[6,4], 'pilatus': [6,2.50]}
LINUX = {'scan':[6,4], 'pilatus': [6,2.90]}
MAC = {'scan':[5,3], 'pilatus': [5,2]}
# Window size needs to be different on Linux
if 'linux' in sys.platform:
print('Linux Distribution detected - adjusting figure size accordingly')
NORMAL = LINUX
print_platform = 'unix'
elif 'darwin' in sys.platform:
print('Mac OS detected - adjusting figure size accordingly')
NORMAL = MAC
print_platform = 'unix'
else:
NORMAL = WINDOWS
import win32api # requried for windows printing
"------------------------------------------------------------------------"
"---------------------------I16_Data_Viewer------------------------------"
"------------------------------------------------------------------------"
class I16_Data_Viewer():
"""
Main GUI to view and analyse I16 data quickly during or after an experiment.
OPERATION:
- Once started, enter your experiment data directory, or press "Browse"
- Enter the Scan number you wish to look at and press ENTER, or use "Last" to get the latest scan.
- To plot the data, select the fitting and normalisation options you would like, then press "Plot"
- To see a pilatus image, select the intensity-cutoffs and region of interest (ROI) and press "Pilatus"
- If you would like to send the data to the console, press "Send to Console", this will send the variables
x,y,dy,xvar,yvar,ttl,d to the console, where d is the dataholder with all the raw data.
- Py16progs is imported to the console by default as pp, so you can use these functions easily. e.g. pp.plotscan(0)
For more info on Py16progs and to see what functions are available, type: help(pp)
- The buttons "Export Plot/Pilatus" will create figures of the current scan that can be saved or printed.
- The button "Multiplot/ Peak Analysis" will take you to the Peak Analysis GUI.
"""
"------------------------------------------------------------------------"
"--------------------------GUI Initilisation-----------------------------"
"------------------------------------------------------------------------"
def __init__(self, figsize=NORMAL, resize=True):
# Create Tk inter instance
self.root = tk.Tk()
self.root.wm_title('I16 Data Viewer [V{}] by D G Porter [dan.porter@diamond.ac.uk]'.format(Py16GUI_Version))
self.root.minsize(width=640, height=480)
self.root.maxsize(width=1920, height=1200)
#self.root.maxsize(width = self.root.winfo_screenwidth(), height = self.root.winfo_screenheight())
#print self.root.winfo_screenwidth(), self.root.winfo_screenmmwidth()
#print self.root.winfo_screenheight(), self.root.winfo_screenmmheight()
# Get initial parameters
initial_dir = pp.filedir
initial_num = '000000'
initial_pilcen = pp.pil_centre
initial_ROI = [75,67]
initial_INT = [0,10]
# Update default save location for exported plots
plt.rcParams["savefig.directory"] = pp.savedir
self.pilatus_scan = 0
self.extra_scannos = [] # scan numbers for multiplots
frame = tk.Frame(self.root)
frame.pack(side=tk.LEFT,anchor=tk.N)
"------------------------------Help Window------------------------------"
frm_help = tk.Frame(frame,background='white',borderwidth=1)
frm_help.pack(fill=tk.X)
self.helper = tk.StringVar(frm_help,'Welcome to I16 Data Viewer, start by Browsing for your data directory.')
lbl_help = tk.Label(frm_help,textvariable=self.helper,font=HF,background='white')
lbl_help.pack(side=tk.LEFT,fill=tk.X,pady=5)
"----------------------------Data Directory-----------------------------"
# Data Folder
frm_fldr = tk.Frame(frame)
frm_fldr.pack(fill=tk.X)
self.filedir = tk.StringVar(frm_fldr,initial_dir)
lbl_fldr = tk.Label(frm_fldr, text='Data Folder: ',width=15,font=SF)
lbl_fldr.pack(side=tk.LEFT,padx=5,pady=5)
ety_fldr = tk.Entry(frm_fldr, textvariable=self.filedir, width=50)
ety_fldr.pack(side=tk.LEFT,padx=0,pady=5)
exp_list = [pp.filedir]+pp.exp_list_get()
opt_fldr = tk.OptionMenu(frm_fldr, self.filedir, *exp_list)
opt_fldr.config(width=1,height=1,fg=opt_fldr['menu']['bg'],activeforeground=opt_fldr['menu']['bg'])
opt_fldr.pack(side=tk.LEFT,padx=0,pady=5)
btn_fldr = tk.Button(frm_fldr, text='Browse',font=BF, command=self.f_fldr_browse)
btn_fldr.pack(side=tk.LEFT,padx=5,pady=5)
btn2_fldr = tk.Button(frm_fldr, text='Search',font=BF, command=self.f_fldr_find)
btn2_fldr.pack(side=tk.LEFT,padx=5,pady=5)
# Peak Analysis
btn_anal = tk.Button(frm_fldr, text='Peak Analysis',font=BF, command=self.f_anal)
btn_anal.pack(side=tk.RIGHT,padx=2)
# Scripting
btn_para = tk.Button(frm_fldr, text='Script',font=BF, command=self.f_script)
btn_para.pack(side=tk.RIGHT,padx=2)
# Parameters
btn_para = tk.Button(frm_fldr, text='Params',font=BF, command=self.f_params)
btn_para.pack(side=tk.RIGHT,padx=2)
# Help
btn_para = tk.Button(frm_fldr, text='Help',font=BF, command=self.f_help)
btn_para.pack(side=tk.RIGHT,padx=2)
# Analysis Folder
frm_fldr = tk.Frame(frame)
frm_fldr.pack(fill=tk.X)
self.savedir = tk.StringVar(frm_fldr,pp.savedir)
lbl_fldr = tk.Label(frm_fldr, text='Analysis Folder: ',width=15,font=SF)
lbl_fldr.pack(side=tk.LEFT,padx=5,pady=5)
ety_fldr = tk.Entry(frm_fldr, textvariable=self.savedir, width=50)
ety_fldr.pack(side=tk.LEFT,padx=0,pady=5)
sav_list = [pp.savedir]+pp.sav_list_get()
opt_fldr = tk.OptionMenu(frm_fldr, self.savedir, *sav_list)
opt_fldr.config(width=1,height=1,fg=opt_fldr['menu']['bg'],activeforeground=opt_fldr['menu']['bg'])
opt_fldr.pack(side=tk.LEFT,padx=0,pady=5)
btn_fldr = tk.Button(frm_fldr, text='Browse',font=BF, command=self.f_fldr2_browse)
btn_fldr.pack(side=tk.LEFT,padx=5,pady=5)
# Live Mode
self.livemode = tk.IntVar(frm_fldr,0)
chk_live = tk.Checkbutton(frm_fldr, text='Live Mode',font=BF, command=self.f_livemode, \
variable=self.livemode,onvalue = 1, offvalue = 0)
chk_live.pack(side=tk.RIGHT,padx=0)
# Differentiate Plot
self.diffplot = tk.IntVar(frm_fldr,0)
chk_diff = tk.Checkbutton(frm_fldr, text='Differentiate',font=BF,variable=self.diffplot, command=self.update_plot)
chk_diff.pack(side=tk.RIGHT,padx=0)
# Log Plot
self.logplot = tk.IntVar(frm_fldr,0)
chk_log = tk.Checkbutton(frm_fldr, text='Log',font=BF,variable=self.logplot, command=self.f_fldr2_log)
chk_log.pack(side=tk.RIGHT,padx=0)
# Auto Pilatus Plot
self.autopilplot = tk.IntVar(frm_fldr,0)
chk_log = tk.Checkbutton(frm_fldr, text='Pilatus',font=BF,variable=self.autopilplot, command=self.update_pilatus)
chk_log.pack(side=tk.RIGHT,padx=0)
"----------------------------Scan Number-----------------------------"
# Scan number
frm_scan = tk.Frame(frame)
frm_scan.pack(fill=tk.X)
self.scanno = tk.IntVar(frm_scan,initial_num)
lbl_scan = tk.Label(frm_scan, text='Scan No: ',font=SF)
lbl_scan.pack(side=tk.LEFT,padx=5,pady=5)
ety_scan = tk.Entry(frm_scan, textvariable=self.scanno, width=10)
ety_scan.bind('<Return>',self.update)
ety_scan.bind('<KP_Enter>',self.update)
ety_scan.pack(side=tk.LEFT,padx=1,pady=5)
btn_scan_dn = tk.Button(frm_scan, text='<', font=BF, command=self.f_scan_dn)
btn_scan_dn.pack(side=tk.LEFT)
btn_scan_up = tk.Button(frm_scan, text='>', font=BF, command=self.f_scan_up)
btn_scan_up.pack(side=tk.LEFT,padx=1)
btn_scan_st = tk.Button(frm_scan, text='Last',font=BF, command=self.f_scan_st)
btn_scan_st.pack(side=tk.LEFT,padx=1)
btn_scan_ld = tk.Button(frm_scan, text='Load',font=BF, command=self.f_scan_ld)
btn_scan_ld.pack(side=tk.LEFT)
btn_scan_mt = tk.Button(frm_scan, text='Meta',font=BF, command=self.f_scan_mt)
btn_scan_mt.pack(side=tk.LEFT)
btn_scan_mt = tk.Button(frm_scan, text='Nexus',font=BF, command=self.f_scan_nx)
btn_scan_mt.pack(side=tk.LEFT)
"----------------------------Plot Options-----------------------------"
# Plot button packed next to scan number buttons
frm_popt = tk.Frame(frm_scan)
frm_popt.pack(side=tk.RIGHT)
# Plot button
btn_plot = tk.Button(frm_popt, text='Plot',font=BF, command=self.f_popt_plot)
btn_plot.pack(side=tk.LEFT,padx=5,pady=5)
# varx box
self.varx = tk.StringVar(frm_popt,'Auto')
lbl_varx = tk.Label(frm_popt, text='X',font=SF)
lbl_varx.pack(side=tk.LEFT,padx=(5,2),pady=5)
#ety_varx = tk.Entry(frm_popt, textvariable=self.varx, width=8)
#ety_varx.bind('<Return>',self.update_plot)
#ety_varx.bind('<KP_Enter>',self.update_plot)
#ety_varx.pack(side=tk.LEFT,padx=(2,5),pady=5)
xlist = ['Auto']
self.opt_varx = tk.OptionMenu(frm_popt, self.varx, *xlist, command=self.f_popt_varx)
self.opt_varx.config(width=8)
self.opt_varx.pack(side=tk.LEFT,padx=(2,5),pady=5)
# vary box
self.vary = tk.StringVar(frm_popt,'Auto')
lbl_vary = tk.Label(frm_popt, text='Y',font=SF)
lbl_vary.pack(side=tk.LEFT,padx=(5,2),pady=5)
#ety_vary = tk.Entry(frm_popt, textvariable=self.vary, width=20)
#ety_vary.bind('<Return>',self.update_plot)
#ety_vary.bind('<KP_Enter>',self.update_plot)
#ety_vary.pack(side=tk.LEFT,padx=(2,3),pady=5)
ylist = ['Auto']
self.opt_vary = tk.OptionMenu(frm_popt, self.vary, *ylist,command=self.f_popt_vary)
self.opt_vary.config(width=10)
self.opt_vary.pack(side=tk.LEFT,padx=(2,3),pady=5)
# normalise menu
normopts = ['rc','ic1','none']
self.normtype = tk.StringVar(frm_popt, normopts[0])
lbl_nrm = tk.Label(frm_popt, text='Norm: ', font=SF)
lbl_nrm.pack(side=tk.LEFT,padx=0,pady=5)
opt_nrm = tk.OptionMenu(frm_popt, self.normtype, *normopts,command=self.f_popt_norm)
opt_nrm.config(width=4)
opt_nrm.pack(side=tk.LEFT,padx=0,pady=5)
# fit menu
fitopts = ['None','Gauss','Lorentz','pVoight','Max','Sum']
self.fittype = tk.StringVar(frm_popt, fitopts[0])
lbl_fit = tk.Label(frm_popt, text='Fit: ', font=SF)
lbl_fit.pack(side=tk.LEFT,padx=0,pady=5)
opt_fit = tk.OptionMenu(frm_popt, self.fittype, *fitopts,command=self.f_popt_fit)
opt_fit.config(width=5)
opt_fit.pack(side=tk.LEFT,padx=0,pady=5)
"----------------------------Scan details-----------------------------"
# Create frame just for long commands
frm_cmd = tk.Frame(frame)
frm_cmd.pack(fill=tk.X)
# Create frame
frm_detl = tk.Frame(frame)
frm_detl.pack(side=tk.LEFT,fill=tk.Y,anchor=tk.NW)
# Initilise frame variables
self.cmd = tk.StringVar(frm_detl,'')
self.N = tk.StringVar(frm_detl,'')
self.HKL = tk.StringVar(frm_detl,'')
self.ENG = tk.StringVar(frm_detl,'')
self.T = tk.StringVar(frm_detl,'')
self.atten = tk.StringVar(frm_detl,'')
self.trans = tk.StringVar(frm_detl,'')
self.mm = tk.StringVar(frm_detl,'')
self.do = tk.StringVar(frm_detl,'')
self.pol = tk.StringVar(frm_detl,'tth = thp = pol = ')
self.eta = tk.StringVar(frm_detl,'')
self.chi = tk.StringVar(frm_detl,'')
self.dlt = tk.StringVar(frm_detl,'')
self.mu = tk.StringVar(frm_detl,'')
self.gam = tk.StringVar(frm_detl,'')
self.azir= tk.StringVar(frm_detl,'')
self.psi = tk.StringVar(frm_detl,'')
self.phi = tk.StringVar(frm_detl,'')
self.sx = tk.StringVar(frm_detl,'')
self.sy = tk.StringVar(frm_detl,'')
self.sz = tk.StringVar(frm_detl,'')
self.spara = tk.StringVar(frm_detl,'')
self.sperp = tk.StringVar(frm_detl,'')
self.ss = tk.StringVar(frm_detl,'')
self.ds = tk.StringVar(frm_detl,'')
self.runtime = tk.StringVar(frm_detl,'')
self.timetaken = tk.StringVar(frm_detl,'')
# Write values to frame
self.writeval(frm_cmd,'Command',self.cmd,wid=80)
self.writeval(frm_detl,'Npoints',self.N)
self.writeval(frm_detl,'HKL',self.HKL)
self.writeval(frm_detl,'Energy',self.ENG)
self.writeval(frm_detl,'Temp',self.T)
self.writeval(frm_detl,'Atten',self.atten)
self.writeval(frm_detl,'Minimirrors',self.mm)
self.writeval(frm_detl,'Detector offset',self.do)
# Analyser
frm_pol = tk.Frame(frm_detl)
frm_pol.pack(fill=tk.X, pady=(10,0))
lbl_pol = tk.Label(frm_pol, textvariable=self.pol,
font=SF, width= 40)
lbl_pol.pack(side=tk.LEFT)
# Eta
frm_eta = tk.Frame(frm_detl)
frm_eta.pack(fill=tk.X, pady=(10,0))
lbl_eta1 = tk.Label(frm_eta, text='eta:',
font=SF, width= 12, anchor=tk.E)
lbl_eta1.pack(side=tk.LEFT)
lbl_eta2 = tk.Label(frm_eta, textvariable=self.eta,
font=SF, width= 8, anchor=tk.W)
lbl_eta2.pack(side=tk.LEFT)
lbl_mu1 = tk.Label(frm_eta, text='mu:',
font=SF, width= 12, anchor=tk.E)
lbl_mu1.pack(side=tk.LEFT)
lbl_mu2 = tk.Label(frm_eta, textvariable=self.mu,
font=SF, width= 8, anchor=tk.W)
lbl_mu2.pack(side=tk.LEFT,fill=tk.X)
# Delta
frm_del = tk.Frame(frm_detl)
frm_del.pack(fill=tk.X)
lbl_del1 = tk.Label(frm_del, text='delta:',
font=SF, width= 12, anchor=tk.E)
lbl_del1.pack(side=tk.LEFT)
lbl_del2 = tk.Label(frm_del, textvariable=self.dlt,
font=SF, width= 8, anchor=tk.W)
lbl_del2.pack(side=tk.LEFT)
lbl_gam1 = tk.Label(frm_del, text='gamma:',
font=SF, width= 12, anchor=tk.E)
lbl_gam1.pack(side=tk.LEFT)
lbl_gam2 = tk.Label(frm_del, textvariable=self.gam,
font=SF, width= 8, anchor=tk.W)
lbl_gam2.pack(side=tk.LEFT,fill=tk.X)
# Chi, Phi
frm_chi = tk.Frame(frm_detl)
frm_chi.pack(fill=tk.X)
lbl_chi1 = tk.Label(frm_chi, text='chi:',
font=SF, width= 12, anchor=tk.E)
lbl_chi1.pack(side=tk.LEFT)
lbl_chi2 = tk.Label(frm_chi, textvariable=self.chi,
font=SF, width= 8, anchor=tk.W)
lbl_chi2.pack(side=tk.LEFT)
lbl_phi1 = tk.Label(frm_chi, text='phi:',
font=SF, width= 12, anchor=tk.E)
lbl_phi1.pack(side=tk.LEFT)
lbl_phi2 = tk.Label(frm_chi, textvariable=self.phi,
font=SF, width= 8, anchor=tk.W)
lbl_phi2.pack(side=tk.LEFT)
# Psi
frm_psi = tk.Frame(frm_detl)
frm_psi.pack(fill=tk.X, pady=(5,0))
lbl_psi1 = tk.Label(frm_psi, text='psi:',
font=SF, width= 12, anchor=tk.E)
lbl_psi1.pack(side=tk.LEFT)
lbl_psi2 = tk.Label(frm_psi, textvariable=self.psi,
font=SF, width= 9, anchor=tk.W)
lbl_psi2.pack(side=tk.LEFT)
lbl_psi2 = tk.Label(frm_psi, textvariable=self.azir,
font=SF, width= 8, anchor=tk.W)
lbl_psi2.pack(side=tk.LEFT,fill=tk.X)
# sx,sy,sz
frm_sx = tk.Frame(frm_detl)
frm_sx.pack(fill=tk.X, pady=(10,0))
lbl_sx1 = tk.Label(frm_sx, text='sx:',
font=SF, width= 6, anchor=tk.E)
lbl_sx1.pack(side=tk.LEFT)
lbl_sx2 = tk.Label(frm_sx, textvariable=self.sx,
font=SF, width= 7, anchor=tk.W)
lbl_sx2.pack(side=tk.LEFT)
lbl_sy1 = tk.Label(frm_sx, text='sy:',
font=SF, width= 6, anchor=tk.E)
lbl_sy1.pack(side=tk.LEFT)
lbl_sy2 = tk.Label(frm_sx, textvariable=self.sy,
font=SF, width= 7, anchor=tk.W)
lbl_sy2.pack(side=tk.LEFT)
lbl_sz1 = tk.Label(frm_sx, text='sz:',
font=SF, width= 6, anchor=tk.E)
lbl_sz1.pack(side=tk.LEFT)
lbl_sz2 = tk.Label(frm_sx, textvariable=self.sz,
font=SF, width= 7, anchor=tk.W)
lbl_sz2.pack(side=tk.LEFT)
# sperp, spara
frm_sp = tk.Frame(frm_detl)
frm_sp.pack(fill=tk.X)
lbl_sp1 = tk.Label(frm_sp, text='sperp:',
font=SF, width= 6, anchor=tk.E)
lbl_sp1.pack(side=tk.LEFT)
lbl_sp2 = tk.Label(frm_sp, textvariable=self.sperp,
font=SF, width= 7, anchor=tk.W)
lbl_sp2.pack(side=tk.LEFT)
lbl_sr1 = tk.Label(frm_sp, text='spara:',
font=SF, width= 6, anchor=tk.E)
lbl_sr1.pack(side=tk.LEFT)
lbl_sr2 = tk.Label(frm_sp, textvariable=self.spara,
font=SF, width= 7, anchor=tk.W)
lbl_sr2.pack(side=tk.LEFT)
# Sample Slits, Detector Slits
frm_ss = tk.Frame(frm_detl)
frm_ss.pack(fill=tk.X, pady=(10,0))
lbl_ss1 = tk.Label(frm_ss, text='Sample Slits: ',
font=SF, width= 16, anchor=tk.E)
lbl_ss1.pack(side=tk.LEFT)
lbl_ss2 = tk.Label(frm_ss, textvariable=self.ss,
font=SF, width= 12, anchor=tk.W)
lbl_ss2.pack(side=tk.LEFT)
frm_ds = tk.Frame(frm_detl)
frm_ds.pack(fill=tk.X, pady=(0,10))
lbl_ds1 = tk.Label(frm_ds, text='Detector Slits: ',
font=SF, width= 16, anchor=tk.E)
lbl_ds1.pack(side=tk.LEFT)
lbl_ds2 = tk.Label(frm_ds, textvariable=self.ds,
font=SF, width= 12, anchor=tk.W)
lbl_ds2.pack(side=tk.LEFT)
# Custom 1,2
frm_cst1 = tk.Frame(frm_detl)
frm_cst1.pack(fill=tk.X, pady=(0,0))
self.custom1 = tk.StringVar(frm_cst1,'Custom')
self.custom1_val = tk.StringVar(frm_cst1,'--')
ylist = ['Custom']
self.opt_cust1 = tk.Button(frm_cst1, textvariable=self.custom1, font=BF, command=self.f_detl_custom1)
#self.opt_cust1 = tk.OptionMenu(frm_cst1, self.custom1, *ylist,command=self.f_detl_custom1)
self.opt_cust1.config(width=15)
self.opt_cust1.pack(side=tk.LEFT,padx=(10,3))
lbl_cust = tk.Label(frm_cst1, textvariable=self.custom1_val,font=SF)
lbl_cust.pack(side=tk.LEFT,padx=(5,2))
frm_cst2 = tk.Frame(frm_detl)
frm_cst2.pack(fill=tk.X, pady=(0,10))
self.custom2 = tk.StringVar(frm_cst2,'Custom')
self.custom2_val = tk.StringVar(frm_cst2,'--')
ylist = ['Custom']
self.opt_cust2 = tk.Button(frm_cst2, textvariable=self.custom2, font=BF, command=self.f_detl_custom2)
#self.opt_cust2 = tk.OptionMenu(frm_cst2, self.custom2, *ylist,command=self.f_detl_custom2)
self.opt_cust2.config(width=15)
self.opt_cust2.pack(side=tk.LEFT,padx=(10,3))
lbl_cust = tk.Label(frm_cst2, textvariable=self.custom2_val,font=SF)
lbl_cust.pack(side=tk.LEFT,padx=(5,2))
# Time Info
self.writeval(frm_detl,'Ran on',self.runtime)
self.writeval(frm_detl,'Time Taken',self.timetaken)
"-----------------------------Check EXP buttons-----------------------"
# Continue in frm_detl, from bottom
# Check Log
frm_log = tk.Frame(frm_detl)
frm_log.pack(side=tk.BOTTOM,fill=tk.X, anchor=tk.SW)
self.logmins = tk.IntVar(frm_detl,10)
btn_log = tk.Button(frm_log, text='Check Log', width=10,
font=BF, command=self.f_checklog)
btn_log.pack(side=tk.LEFT,padx=5)
lbl_log = tk.Label(frm_log, text='Check last N mins',font=SF,width=18)
lbl_log.pack(side=tk.LEFT,padx=5)
ety_log = tk.Entry(frm_log, textvariable=self.logmins, width=4)
ety_log.pack(side=tk.LEFT,padx=5)
btn_log_dn = tk.Button(frm_log, text='<',font=BF, command=self.f_log_dn)
btn_log_dn.pack(side=tk.LEFT)
btn_log_up = tk.Button(frm_log, text='>',font=BF, command=self.f_log_up)
btn_log_up.pack(side=tk.LEFT,padx=5)
# Check Num
frm_chk = tk.Frame(frm_detl)
frm_chk.pack(side=tk.BOTTOM,fill=tk.X)
self.chknum = tk.IntVar(frm_detl,10)
btn_chk = tk.Button(frm_chk, text='Check Scans', width=10,
font=BF, command=self.f_checknum)
btn_chk.pack(side=tk.LEFT,padx=5)
lbl_chk = tk.Label(frm_chk, text='Check last N scans',font=SF,width=18)
lbl_chk.pack(side=tk.LEFT,padx=5)
ety_chk = tk.Entry(frm_chk, textvariable=self.chknum, width=4)
ety_chk.pack(side=tk.LEFT,padx=5)
btn_chk_dn = tk.Button(frm_chk, text='<',font=BF, command=self.f_chk_dn)
btn_chk_dn.pack(side=tk.LEFT)
btn_chk_up = tk.Button(frm_chk, text='>',font=BF, command=self.f_chk_up)
btn_chk_up.pack(side=tk.LEFT,padx=5)
# More Check options
frm_mor = tk.Frame(frm_detl)
frm_mor.pack(side=tk.BOTTOM,fill=tk.X)
btn_mor = tk.Button(frm_mor, text='More Check Options',font=BF, command=self.f_chk_mor)
btn_mor.pack(side=tk.LEFT,padx=5)
btn_exp = tk.Button(frm_mor, text='Check Exp',font=BF, command=self.f_chk_exp)
btn_exp.pack(side=tk.LEFT,padx=5)
btn_lat = tk.Button(frm_mor, text='Check Latt',font=BF, command=self.f_chk_lat)
btn_lat.pack(side=tk.LEFT,padx=5)
# Scan Selector
self.scan_selector_showval=''
frm_ssl = tk.Frame(frm_detl,relief=tk.RAISED)
frm_ssl.pack(side=tk.BOTTOM,fill=tk.X)
btn_ssl = tk.Button(frm_ssl, text='Last scans window',font=BF, command=self.f_scn_sel)
btn_ssl.pack(side=tk.LEFT,fill=tk.X,padx=5)
self.select_all_scans = tk.IntVar(frm_ssl,0)
chk_ssl = tk.Checkbutton(frm_ssl, text='All scans (slow)?',variable=self.select_all_scans)
chk_ssl.pack(side=tk.LEFT)
"----------------------------Plotting Window-----------------------------"
# Create frame on right hand side
frm_rgt = tk.Frame(frame)
frm_rgt.pack(side=tk.RIGHT, fill=tk.X, anchor=tk.NE, expand = tk.YES)
# Create frame for plot
frm_plt = tk.Frame(frm_rgt)
frm_plt.pack(fill=tk.X,expand=tk.YES)
self.fig1 = plt.Figure(figsize=figsize['scan'],dpi=80)
self.fig1.patch.set_facecolor('w')
self.ax1 = self.fig1.add_subplot(111)
self.ax1.set_autoscaley_on(True)
self.ax1.set_autoscalex_on(True)
self.plt1, = self.ax1.plot([1,2,3,4,5,6,7,8],[5,6,1,3,8,9,3,5],'o-',c=pp.plot_colors[0],linewidth=2)
self.plt2, = self.ax1.plot([],[],'g:') # marker point for pilatus
self.pfit, = self.ax1.plot([],[],'-',c=pp.plot_colors[-1],linewidth=2) # fit line
self.extra_plots = []
self.ax1.set_xlabel('varx')
self.ax1.set_ylabel('vary')
self.ax1.set_title('Scan number',fontsize=16)
self.fig1.subplots_adjust(left=0.25,bottom=0.2,right=0.95)
# Change formats in x & y axes so they are nicer
self.ax1.get_yaxis().set_major_formatter(mtick.FormatStrFormatter('%8.3g'))
self.ax1.get_xaxis().get_major_formatter().set_useOffset(False)
canvas = FigureCanvasTkAgg(self.fig1, frm_plt)
canvas.get_tk_widget().configure(bg='black')
#canvas.bind("<Button-1>",figureclick) # this doesn't work - FigureCanvasTkAgg doesn't have bind
#canvas.bind("<B1-Motion>",figurehold)
canvas.draw()
canvas.get_tk_widget().pack(side=tk.RIGHT, fill=tk.BOTH, anchor=tk.NE, expand=tk.YES)
#canvas.get_tk_widget().pack()
#self.update_plot()
# Add matplotlib toolbar under plot
self.toolbar = NavigationToolbar2TkAgg( canvas, frm_rgt )
self.toolbar.update()
self.toolbar.pack(side=tk.TOP)
"----------------------------Pilatus Options-----------------------------"
# Pilatus option buttons below plot figure
frm_pilopt = tk.Frame(frm_rgt)
frm_pilopt.pack()
# Pilatus variables
self.pilatus_active = False
self.pilatus_scan = 0
self.pilpos = 0
self.pilstr = tk.StringVar(frm_pilopt,'(0) eta = 0')
self.pilcen_i = tk.IntVar(frm_pilopt,initial_pilcen[0])
self.pilcen_j = tk.IntVar(frm_pilopt,initial_pilcen[1])
self.roisiz_i = tk.IntVar(frm_pilopt,initial_ROI[0])
self.roisiz_j = tk.IntVar(frm_pilopt,initial_ROI[1])
self.pilint_i = tk.DoubleVar(frm_pilopt,initial_INT[0])
self.pilint_j = tk.DoubleVar(frm_pilopt,initial_INT[1])
# Plot button
frm_pilopt1 = tk.Frame(frm_pilopt)
frm_pilopt1.pack(side=tk.LEFT,fill=tk.BOTH)
btn_pilopt = tk.Button(frm_pilopt1, text='Update Pilatus Plot',wraplength=60,font=BF, command=self.f_pilopt_plot)
btn_pilopt.pack(side=tk.LEFT,fill=tk.Y,padx=2)
# Pilatus centre + ROI size
frm_pilopt2 = tk.Frame(frm_pilopt)
frm_pilopt2.pack(fill=tk.X)
lbl_pilcen = tk.Label(frm_pilopt2, text='Centre:',font=SF,width=6)
lbl_pilcen.pack(side=tk.LEFT,padx=1)
ety_pilcen_i = tk.Entry(frm_pilopt2, textvariable=self.pilcen_i, width=4)
ety_pilcen_i.bind('<Return>',self.update_pilatus)
ety_pilcen_i.bind('<KP_Enter>',self.update_pilatus)
ety_pilcen_i.pack(side=tk.LEFT,padx=1)
ety_pilcen_j = tk.Entry(frm_pilopt2, textvariable=self.pilcen_j, width=4)
ety_pilcen_j.bind('<Return>',self.update_pilatus)
ety_pilcen_j.bind('<KP_Enter>',self.update_pilatus)
ety_pilcen_j.pack(side=tk.LEFT,padx=1)
lbl_roisiz = tk.Label(frm_pilopt2, text='ROI:',font=SF,width=5)
lbl_roisiz.pack(side=tk.LEFT,padx=1)
ety_roisiz_i = tk.Entry(frm_pilopt2, textvariable=self.roisiz_i, width=4)
ety_roisiz_i.bind('<Return>',self.update_pilatus)
ety_roisiz_i.bind('<KP_Enter>',self.update_pilatus)
ety_roisiz_i.pack(side=tk.LEFT,padx=1)
ety_roisiz_j = tk.Entry(frm_pilopt2, textvariable=self.roisiz_j, width=4)
ety_roisiz_j.bind('<Return>',self.update_pilatus)
ety_roisiz_j.bind('<KP_Enter>',self.update_pilatus)
ety_roisiz_j.pack(side=tk.LEFT,padx=1)
btn_peak = tk.Button(frm_pilopt2, text='Find Peak',font=BF,command=self.f_pilopt_peak)
btn_peak.pack(side=tk.LEFT,padx=2)
#btn_droi = tk.Button(frm_pilopt2, text='nroi',font=BF,command=self.f_pilopt_nroi)
#btn_droi.pack(side=tk.LEFT,padx=2)
btn_def2 = tk.Button(frm_pilopt2, text='roi2',font=BF,command=self.f_pilopt_def2)
btn_def2.pack(side=tk.LEFT,padx=2)
btn_def1 = tk.Button(frm_pilopt2, text='roi1',font=BF,command=self.f_pilopt_def1)
btn_def1.pack(side=tk.LEFT,padx=2)
# Pilatus Image intensity cutoffs + pos buttons
frm_pilopt3 = tk.Frame(frm_pilopt)
frm_pilopt3.pack(fill=tk.X)
lbl_pilint = tk.Label(frm_pilopt3, text='CLim:',font=SF,width=4)
lbl_pilint.pack(side=tk.LEFT,padx=2)
ety_pilint_i = tk.Entry(frm_pilopt3, textvariable=self.pilint_i, width=4)
ety_pilint_i.bind('<Return>',self.update_pilatus)
ety_pilint_i.bind('<KP_Enter>',self.update_pilatus)
ety_pilint_i.pack(side=tk.LEFT,padx=1)
ety_pilint_j = tk.Entry(frm_pilopt3, textvariable=self.pilint_j, width=6)
ety_pilint_j.bind('<Return>',self.update_pilatus)
ety_pilint_j.bind('<KP_Enter>',self.update_pilatus)
ety_pilint_j.pack(side=tk.LEFT,padx=1)
lbl_pilpos = tk.Label(frm_pilopt3, textvariable=self.pilstr,font=SF,width=14)
lbl_pilpos.pack(side=tk.LEFT,padx=2)
btn_pilpos0 = tk.Button(frm_pilopt3, text='<<',font=BF, command=self.f_pilopt_posleftfast)
btn_pilpos0.pack(side=tk.LEFT,padx=0)
btn_pilpos1 = tk.Button(frm_pilopt3, text='<',font=BF, command=self.f_pilopt_posleft)
btn_pilpos1.pack(side=tk.LEFT,padx=0)
btn_pilpos2 = tk.Button(frm_pilopt3, text='>',font=BF, command=self.f_pilopt_posright)
btn_pilpos2.pack(side=tk.LEFT,padx=0)
btn_pilpos3 = tk.Button(frm_pilopt3, text='>>',font=BF, command=self.f_pilopt_posrightfast)
btn_pilpos3.pack(side=tk.LEFT,padx=0)
frm_pilopt3a = tk.Frame(frm_pilopt3)
frm_pilopt3a.pack(side=tk.LEFT,fill=tk.X)
# Remove background
self.rembkg = tk.IntVar(frm_pilopt3,0)
chk_rbkg = tk.Checkbutton(frm_pilopt3a, text='Rem. Bkg',font=('Times',8),borderwidth=0,variable=self.rembkg, command=self.f_pilopt_rembkg)
chk_rbkg.pack(side=tk.TOP,padx=0,pady=0)
self.remfrm = tk.IntVar(frm_pilopt3,0)
chk_rfrm = tk.Checkbutton(frm_pilopt3a, text='Rem. Frm',font=('Times',8),borderwidth=0,variable=self.remfrm, command=self.f_pilopt_remfrm)
chk_rfrm.pack(side=tk.TOP,padx=0,pady=0)
"----------------------------Pilatus Window------------------------------"
# Figure window 2, below pilatus options buttons
frm_pil = tk.Frame(frm_rgt)
frm_pil.pack(fill=tk.X,expand=tk.YES)
self.fig2 = plt.Figure(figsize=figsize['pilatus'],dpi=80)
self.fig2.patch.set_facecolor('w')
self.ax2 = self.fig2.add_subplot(111)
self.ax2.set_xticklabels([])
self.ax2.set_yticklabels([])
self.ax2.set_xticks([])
self.ax2.set_yticks([])
self.ax2.set_autoscaley_on(True)
self.ax2.set_autoscalex_on(True)
self.ax2.set_frame_on(False)
self.pilim = self.ax2.imshow(np.zeros([195,487]), cmap=pp.default_colormap)
#default_image = pp.misc.imread( os.path.dirname(__file__)+'\default_image.png')
#self.pilim = self.ax2.imshow(default_image)
self.ax2.set_position([0,0,1,1])
#self.fig2.subplots_adjust(left=0.2,bottom=0.2)
ROIcen = initial_pilcen
ROIsize = [75,67]
pil_centre = initial_pilcen
pil_size = [195,487]
idxi = np.array([ROIcen[0]-ROIsize[0]//2,ROIcen[0]+ROIsize[0]//2+1])
idxj = np.array([ROIcen[1]-ROIsize[1]//2,ROIcen[1]+ROIsize[1]//2+1])
self.pilp1, = self.ax2.plot(idxj[[0,1,1,0,0]],idxi[[0,0,1,1,0]],'k-',linewidth=2) # ROI
self.pilp2, = self.ax2.plot([pil_centre[1],pil_centre[1]],[0,pil_size[0]],'k:',linewidth=2) # vertical line
self.pilp3, = self.ax2.plot([0,pil_size[1]],[pil_centre[0],pil_centre[0]],'k:',linewidth=2) # Horizontal line
self.pilp4, = self.ax2.plot([],[],'r-',linewidth=2) # ROI background
self.pilp5, = self.ax2.plot([],[],'y-',linewidth=2) # Peak region
self.ax2.set_aspect('equal')
self.ax2.autoscale(tight=True)
canvas2 = FigureCanvasTkAgg(self.fig2, frm_pil)
canvas2.get_tk_widget().configure(bg='black')
canvas2.draw()
canvas2.get_tk_widget().pack(side=tk.RIGHT, fill=tk.BOTH, anchor=tk.NE, expand=tk.YES)
"-----------------------------Final Options------------------------------"
# Buttons at bottom right
frm_fnl = tk.Frame(frm_rgt)
frm_fnl.pack()
# Button to send data to Console
btn_send = tk.Button(frm_fnl, text='Send to Console',font=BF, command=self.f_fnl_send)
btn_send.pack(side=tk.LEFT,padx=2,pady=5)
# Button to send data to Console
btn_splot = tk.Button(frm_fnl, text='Export Plot',font=BF, command=self.f_fnl_splot)
btn_splot.pack(side=tk.LEFT,padx=2,pady=5)
# Button to send data to Console
btn_spil = tk.Button(frm_fnl, text='Export Pilatus',font=BF, command=self.f_fnl_spil)
btn_spil.pack(side=tk.LEFT,padx=2)
# Button to send data to Console
btn_spil = tk.Button(frm_fnl, text='pil2hkl',font=BF, command=self.f_fnl_phkl)
btn_spil.pack(side=tk.LEFT,padx=2)
# Button to send data to Console
btn_spil = tk.Button(frm_fnl, text='pil2tth',font=BF, command=self.f_fnl_ptth)
btn_spil.pack(side=tk.LEFT,padx=2)
# Row 2
frm_fnl2 = tk.Frame(frm_rgt)
frm_fnl2.pack()
# Button to save plot
btn_send = tk.Button(frm_fnl2, text='Save Current Scan',font=BF, command=self.f_fnl_splotsave)
btn_send.pack(side=tk.LEFT,padx=2,pady=1)
# Button to print plot
btn_send = tk.Button(frm_fnl2, text='Print Current Scan',font=BF, command=self.f_fnl_splotprint)
btn_send.pack(side=tk.LEFT,padx=2,pady=1)
# Button to print all figures
btn_send = tk.Button(frm_fnl2, text='Print All Figures',font=BF, command=self.f_fnl_splotbuffer)
btn_send.pack(side=tk.LEFT,padx=2,pady=1)
# Button to close all figures
btn_send = tk.Button(frm_fnl2, text='Close All',font=BF, command=self.f_fnl_splotclose)
btn_send.pack(side=tk.LEFT,padx=2,pady=1)
# Check widget size vs screen size
if resize and self.root.winfo_height() > self.root.winfo_screenheight()-80:
print('Screen Height = ',self.root.winfo_screenheight())
print('App Height = ',self.root.winfo_height())
print('Oh... this is a small screen. I\'ll just make the viewer smaller...')
# App Fonts
BF[1] -= 2
SF[1] -= 2
LF[1] -= 2
HF[1] -= 2
# App Figure Sizes
NORMAL['scan'] = [NORMAL['scan'][0]*0.9,NORMAL['scan'][1]*0.9]
NORMAL['pilatus'] = [NORMAL['pilatus'][0]*0.9,NORMAL['pilatus'][1]*0.9]
self.root.destroy()
I16_Data_Viewer()
# Load initial data
if pp.latest() is not None:
self.f_scan_st()
if not hasattr(sys, 'ps1'):
# If not in interactive mode, start mainloop
self.root.protocol("WM_DELETE_WINDOW", self.on_closing)
self.root.mainloop()
"------------------------------------------------------------------------"
"---------------------------Button Functions-----------------------------"
"------------------------------------------------------------------------"
def f_fldr_opt(self):
"Load previous experiment"
pass
def f_fldr_browse(self):
"Browse for data directory"
inidir = self.filedir.get()
new_dir = filedialog.askdirectory(
parent=self.root,
initialdir=inidir,
title='Choose data directory',
mustexist=True
)
if new_dir:
self.filedir.set(new_dir)
self.savedir.set(new_dir +os.path.sep+'processing')
#self.helper.set('Now set the analysis folder - saved images and scripts will be stored here')
def f_fldr_find(self):
"Search for data directory"
inidir = self.filedir.get()
num = self.scanno.get()
if num > 1000:
self.helper.set('Searching file directories for scan #{}'.format(num))
newdir = pp.findfile(num,topdir=inidir)
self.filedir.set(newdir)