-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot_tools.py
147 lines (119 loc) · 4.42 KB
/
plot_tools.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
# -*- coding: utf-8 -*-
"""
Created on Fri Jul 12 19:44:34 2013
@author: JG
"""
import matplotlib
from matplotlib import pyplot as plt
import numpy as np
import analysis
def plot_pyqt(imv, data, dataview):
yimage = analysis.yimage_calc(data, dataview)
yimage = np.rot90(yimage, 1)
imv.setImage(yimage)
def graph_pyqt(curve1, curve2, data, dataview):
xdata = analysis.xdata_calc(data, dataview)
ydata = analysis.ydata_calc(data, dataview)
curve1.setData(xdata,ydata, pen="w")
curve2.setData(xdata,ydata, pen="w")
def change_display(axes, data, dataview):
"""
changes the view between ev and wavelength for ev and wavelength data
"""
axes.cla()
xdata = analysis.xdata_calc(data, dataview)
ydata = analysis.ydata_calc(data, dataview)
img2, = axes.plot(xdata,ydata,'.')
if dataview.display_ev:
axes.set_xlabel('ev')
else:
axes.set_xlabel('$\lambda$ [nm]')
return img2
def change_display_pyqt(graph, dataview):
if dataview.display_ev:
text='ev'
else:
text='wavelength [nm]'
graph.setLabel(axis='bottom',text=text )
def initialize_graph(axes, data, dataview):
"""
initializes the graph on screen
xs and ys start from 0
"""
axes.cla()
xdata = analysis.xdata_calc(data, dataview)
ydata = analysis.ydata_calc(data, dataview)
maxval = analysis.maxval_calc(data, dataview)
axes.set_ylim((-maxval/10,maxval))
img2, = axes.plot(xdata, ydata,'.')
if dataview.display_ev:
plt.xlabel('ev')
else:
plt.xlabel('$\lambda$ [nm]')
return img2
def initialize_image(axes, data, dataview):
'Initializes the image from the datacube'
yimage = analysis.yimage_calc(data, dataview)
maxval = analysis.maxval_calc(data, dataview)
img = axes.imshow(yimage, interpolation='nearest', clim = (0,maxval),
cmap='spectral')
xdata = analysis.xdata_calc(data, dataview)
slice1 = dataview.slider_val
if dataview.display_ev:
axes.set_title('Current Slice ev:%0.2f'%float(xdata[slice1]))
else:
axes.set_title('Current Slice Wavelength:%0.2f'%float(xdata[slice1]))
plt.yticks([])
plt.xticks([])
return img
def plot_graph(img, axes, data, dataview):
"""updates the graph on screen with the given x and y coordinates"""
ydata = analysis.ydata_calc(data, dataview)
img.set_ydata(ydata)
img.figure.canvas.draw()
def plot_image(img, axes, data, dataview):
"""updates the image on screen with a new cube slice from slider"""
yimage = analysis.yimage_calc(data, dataview)
img.set_array(yimage)
max_color, min_color = analysis.colors_calc(data, dataview)
if dataview.auto_color:
img.autoscale()
vmin, vmax = img.get_clim()
dataview.mincolor = vmin
dataview.maxcolor = vmax
else:
img.set_clim(vmax=max_color, vmin=min_color)
xdata = analysis.xdata_calc(data, dataview)
slice1 = dataview.slider_val
if dataview.display_ev:
axes.set_title('Current Slice ev:%0.2f'%float(xdata[slice1]))
else:
axes.set_title('Current Slice Wavelength:%0.0f '%float(xdata[slice1]))
img.figure.canvas.draw()
def show_slices(self,N=100,axis=0):
"""
Remnant of Aaron's original code. I need to update this for the
new version.
show N slices out of a data cube. N square root must be an integer
"""
self.slices = QtGui.QWidget()
self.slices.fig = plt.figure(figsize=(8.0, 6.0))
self.slices.canvas = FigureCanvas(self.slices.fig)
self.slices.canvas.setParent(self.slices)
dE = 1600/N
inds = np.r_[0:dE]
m = self.maxval*(N/16)
NN = np.floor(np.sqrt(N))
for i in np.arange(0,N):
plt.subplot(NN,NN,i+1)
plt.imshow(np.sum(self.ycube[i*dE + inds,:],axis=0),
interpolation='nearest' )
#plt.title('%0.0f to %0.0f nm'%tuple(self.mf1.xdata[np.r_[i*dE + inds][[0,-1]],1,1].tolist()))
#plt.colorbar()
plt.yticks([])
plt.xticks([])
plt.clim(0,m)
vbox = QtGui.QVBoxLayout()
vbox.addWidget(self.slices.canvas)
self.slices.setLayout(vbox)
self.slices.show()