-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdisplacement.py
49 lines (39 loc) · 1.22 KB
/
displacement.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
#this creates the displacement on the grating
import numpy as np
import matplotlib.pyplot as plt
from scipy import interpolate
from microsaccades_functions import *
#displacement is zero and standard derivation is receptor size (0.5 arcmin)
mu, sigma = 0.,.5
dis = np.random.normal(mu, sigma)
x = np.arange(0, 101,1.)
y = np.random.normal(mu, sigma, 101)
tck = interpolate.splrep(x, y, s=0)
xnew = np.arange(0, 100, .1)
ynew = interpolate.splev(xnew, tck, der=0)
ms_disp = -4*np.ones(300)
ms_disp = np.append(ms_disp,10*np.ones(300))
ms_disp = np.append(ms_disp,-10*np.ones(300))
ms_disp = np.append(ms_disp,2*np.ones(100))
ynew = np.add(ynew,ms_disp)
xnewer = np.arange(0, 1000, 1.)
plt.figure()
plt.plot(xnewer, ynew)
plt.legend(['Linear', 'Cubic Spline'])
plt.title('Cubic-spline interpolation')
plt.savefig('img/grating_phase/displacements.pdf')
plt.show()
d_data = open('data/phase_displacement.data','w+')
np.save(d_data, ynew)
d_data.close()
'''
x = np.linspace(0, 100, num=101, endpoint=True)
smooth = interp1d(x, dis, kind='cubic')
xnew = np.linspace(0, 100, num=1001, endpoint=True)
plt.plot(x, dis, 'o', xnew, smooth(xnew), '-')
#x=np.arange(0,len(dis),1.)
#res=interp1d(x, dis, kind='cubic')
#print res
#plt.plot(dis)
plt.show()
'''