Skip to content

Instantly share code, notes, and snippets.

@akira093 akira093/data.csv
Created Mar 2, 2013

Embed
What would you like to do?
#theta open nicol cross nicol
0 0.001640 0.000836
10 0.001300 0.001170
20 0.001210 0.001250
30 0.001410 0.001040
40 0.001820 0.000644
50 0.002220 0.000251
60 0.002450 0.000040
70 0.002390 0.000105
80 0.002080 0.000404
90 0.001670 0.000791
100 0.001340 0.001100
110 0.001250 0.001180
120 0.001430 0.000999
130 0.001800 0.000632
140 0.002180 0.000260
150 0.002410 0.000041
160 0.002370 0.000100
170 0.002050 0.000414
180 0.001600 0.000845
import pylab
from scipy.optimize import leastsq
# settings of pylab
params = {
"font.size": 20,
"font.family": "IPAGothic",
"lines.markersize":14,
}
pylab.rcParams.update(params)
pylab.xlabel("angle(degree)")
pylab.ylabel("intensity(W)")
# importing data
x, y1, y2 = pylab.loadtxt("data.csv", delimiter = ", ", unpack = True)
x_ = pylab.arange(0, 182, 2)
# open nicol
# Target function of open nicol
fitfunc = lambda p, x: p[0] * pylab.cos(2 * pylab.pi / 180. * x + p[1]) ** 2 + p[2]
# Distance to the target function
errfunc = lambda p, x, y: fitfunc(p, x) - y
p= [.0, pylab.pi / 4., 0.0]
res = leastsq(errfunc, p[:], args=(x, y1), full_output = True)
p1 = res[0]
pylab.plot(x, y1, "ro")
pylab.plot(x_, fitfunc(p1, x_), "r-")
# cross nicol
# Target function
fitfunc = lambda p, x: p[0] * pylab.sin(2 * pylab.pi/180. * x + p[1]) ** 2
# Distance to the target function
errfunc = lambda p, x, y: fitfunc(p, x) - y
# Initial guess for the parameters
params0 = [0., pylab.pi / 4.]
# Plot of the data and the fit
res = leastsq(errfunc, p[:], args=(x, y2), full_output = True)
p2= res[0]
pylab.plot(x, y2, "b^")
pylab.plot(x_, fitfunc(p2, x_), "b-")
pylab.savefig("optimize.png", bbox_inches = "tight")
pylab.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.