-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathresonance_lines.py
78 lines (70 loc) · 2.36 KB
/
resonance_lines.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
import numpy as np
import pylab as plt
plt.style.use('classic')
import matplotlib
matplotlib.rcParams['mathtext.fontset'] = 'dejavusans'
matplotlib.rcParams['mathtext.rm'] = 'sans'
class resonance_lines(object):
def __init__(self, Qx_range, Qy_range, orders, periodicity):
if np.std(Qx_range):
self.Qx_min = np.min(Qx_range)
self.Qx_max = np.max(Qx_range)
else:
self.Qx_min = np.floor(Qx_range)-0.05
self.Qx_max = np.floor(Qx_range)+1.05
if np.std(Qy_range):
self.Qy_min = np.min(Qy_range)
self.Qy_max = np.max(Qy_range)
else:
self.Qy_min = np.floor(Qy_range)-0.05
self.Qy_max = np.floor(Qy_range)+1.05
self.periodicity = periodicity
nx, ny = [], []
for order in np.nditer(np.array(orders)):
t = np.array(range(-order, order+1))
nx.extend(order - np.abs(t))
ny.extend(t)
nx = np.array(nx)
ny = np.array(ny)
cextr = np.array([nx*np.floor(self.Qx_min)+ny*np.floor(self.Qy_min),
nx*np.ceil(self.Qx_max)+ny*np.floor(self.Qy_min),
nx*np.floor(self.Qx_min)+ny*np.ceil(self.Qy_max),
nx*np.ceil(self.Qx_max)+ny*np.ceil(self.Qy_max)], dtype='int')
cmin = np.min(cextr, axis=0)
cmax = np.max(cextr, axis=0)
res_sum = [range(cmin[i], cmax[i]+1) for i in range(cextr.shape[1])]
self.resonance_list = zip(nx, ny, res_sum)
def plot_resonance(self, figure_object = None, interactive=True):
if(interactive):
plt.ion()
if figure_object:
fig = figure_object
plt.figure(fig.number)
else:
fig = plt.figure()
Qx_min = self.Qx_min
Qx_max = self.Qx_max
Qy_min = self.Qy_min
Qy_max = self.Qy_max
plt.xlim(Qx_min, Qx_max)
plt.ylim(Qy_min, Qy_max)
plt.xlabel('$\mathrm{Q_x}$' , fontsize='large')
plt.ylabel('$\mathrm{Q_y}$', fontsize='large')
for resonance in self.resonance_list:
nx = resonance[0]
ny = resonance[1]
for res_sum in resonance[2]:
if ny:
line, = plt.plot([Qx_min, Qx_max], \
[(res_sum-nx*Qx_min)/ny, (res_sum-nx*Qx_max)/ny])
else:
line, = plt.plot([float(res_sum)/nx, float(res_sum)/nx],[Qy_min, Qy_max])
if ny%2:
plt.setp(line, linestyle='--', zorder=1) # for skew resonances
if res_sum%self.periodicity:
plt.setp(line, color='b', zorder=1) # non-systematic resonances
else:
plt.setp(line, color='r', zorder=1, linewidth=2.0) # systematic resonances
if(interactive):
plt.draw()
return fig