Skip to content
Snippets Groups Projects
Commit de60e366 authored by Frederik Steven's avatar Frederik Steven
Browse files

Removed plots and updated python scripts

parent f03ba937
Branches main
No related tags found
No related merge requests found
Showing
with 577 additions and 204 deletions
import numpy as np import numpy as np
from scipy.optimize import curve_fit from scipy.optimize import curve_fit
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import matplotlib.font_manager as font_manager
from matplotlib.offsetbox import AnchoredText from matplotlib.offsetbox import AnchoredText
import sys import sys
## Performs linear fit for calibration from sigfig import round
def FitAndPlot(xp, xm, z1p, z1m, z2p, z2m, z3p, z3m, zAllp, zAllm, Voltage, plots, raw):
#Linewidth
lw = 0.8
#
if(plots):
if(raw):
plt.title("Calibration Measurement " + str(Voltage))
plt.plot(xp, z1p, marker=".", color="tab:blue", label="z1-", linewidth=lw)
plt.plot(xp, z1m, marker=".", color="b", label="z1+", linewidth=lw)
plt.plot(xp, z2p, marker=".", color="tab:red", label="z2-", linewidth=lw)
plt.plot(xp, z2m, marker=".", color="chocolate", label="z2+", linewidth=lw)
plt.plot(xp, z3p, marker=".", color="tab:green", label="z3-", linewidth=lw)
plt.plot(xp, z3m, marker=".", color="darkolivegreen", label="z3+", linewidth=lw)
plt.plot(xp, zAllp, marker=".", color="tab:purple", label="zAll-", linewidth=lw)
plt.plot(xp, zAllm, marker=".", color="m", label="zAll+", linewidth=lw)
plt.ylabel(r"Measured Movement [$\mu m$]")
plt.xlabel("# of step")
plt.legend()
plt.grid()
plt.savefig("Plots\Calibration\\" + str(Voltage) + "_All_Data.pdf")
plt.show()
# Fit #plt.rcParams['font.family'] = 'monospace'
# Errors are 1/sqrt(12) * one pixel length in mikrometers
error_z1 = 8.87 / np.sqrt(12)
error_z2 = 9.62 / np.sqrt(12)
error_z3 = 9.80 / np.sqrt(12)
error_zAll = 9.00 / np.sqrt(12)
popt_z1p, pcov_z1p = curve_fit(linear, xp, z1p, error_z1)
popt_z1m, pcov_z1m = curve_fit(linear, xp, z1m, error_z1)
popt_z2p, pcov_z2p = curve_fit(linear, xp, z2p, error_z2)
popt_z2m, pcov_z2m = curve_fit(linear, xp, z2m, error_z2)
popt_z3p, pcov_z3p = curve_fit(linear, xp, z3p, error_z3)
popt_z3m, pcov_z3m = curve_fit(linear, xp, z3m, error_z3)
popt_zAllp, pcov_zAllp = curve_fit(linear, xp, zAllp, error_zAll)
popt_zAllm, pcov_zAllm = curve_fit(linear, xp, zAllm, error_zAll)
# Chi squared Computation per degree of freedom
chi_z1p = np.sum(((z1p - linear(xp, popt_z1p[0]))**2 / error_z1**2)) / (len(z1p) - 1)
chi_z1m = np.sum(((z1m - linear(xp, popt_z1m[0]))**2 / error_z1**2)) / (len(z1m) - 1)
chi_z2p = np.sum(((z2p - linear(xp, popt_z2p[0]))**2 / error_z2**2)) / (len(z2p) - 1)
chi_z2m = np.sum(((z2m - linear(xp, popt_z2m[0]))**2 / error_z2**2)) / (len(z2m) - 1)
chi_z3p = np.sum(((z3p - linear(xp, popt_z3p[0]))**2 / error_z3**2)) / (len(z3p) - 1)
chi_z3m = np.sum(((z3m - linear(xp, popt_z3m[0]))**2 / error_z3**2)) / (len(z3m) - 1)
chi_zAllp = np.sum(((zAllp - linear(xp, popt_zAllp[0]))**2 / error_zAll**2)) / (len(zAllp) - 1)
chi_zAllm = np.sum(((zAllm - linear(xp, popt_zAllm[0]))**2 / error_zAll**2)) / (len(zAllm) - 1)
# Plots
fig, ax = plt.subplots(2, 2)
fig.set_figheight(9)
fig.set_figwidth(16)
# Z1
capsize = 2
if(plots):
ax[0,0].set_title("Z1 calibration fit " + str(Voltage))
ax[0,0].set_xlabel("# of steps")
ax[0,0].set_ylabel(r"Measured Movement [$\mu m$]")
ax[0,0].errorbar(xp, z1p, error_z1, linestyle="none", marker=".", linewidth=lw, color="tab:blue", label="z1- data", capsize=capsize)
ax[0,0].errorbar(xp, z1m, error_z1, linestyle="none", marker=".", linewidth=lw, color="b", label="z1+ data", capsize=capsize)
ax[0,0].plot(xp, linear(xp, popt_z1p[0]), linewidth=lw, color="tab:blue", label="z1- fit")
ax[0,0].plot(xp, linear(xp, popt_z1m[0]), linewidth=lw, color="b", label="z1+ fit")
#ax = plt.gca()
anchored_text = AnchoredText(r"$b_-$= {:.2f} $\pm$ {:.2f} $n m$/step, $\chi^2/ndof =${:.2f}".format(popt_z1p[0] * 1000, np.sqrt(pcov_z1p[0][0]) * 1000, chi_z1p) + "\n" + "$b_+$= {:.2f} $\pm$ {:.2f} $n m$/step, $\chi^2/ndof =${:.2f}".format(popt_z1m[0] * 1000, np.sqrt(pcov_z1m[0][0]) * 1000, chi_z1m), loc=4)
ax[0,0].add_artist(anchored_text)
ax[0,0].legend()
plt.grid()
#plt.savefig("Plots\Calibration\Z1_" + str(Voltage) + ".pdf")
#plt.show()
print("slope in nm/step z1-:", popt_z1p[0] * 1000, " +- ", np.sqrt(pcov_z1p[0][0]) * 1000, " chi^2 ", chi_z1p)
print("slope in nm/step z1+:", popt_z1m[0] * 1000, " +- ", np.sqrt(pcov_z1m[0][0]) * 1000, " chi^2 ", chi_z1m)
#Z2
if(plots):
ax[0,1].set_title("Z2 calibration fit " + str(Voltage))
ax[0,1].set_xlabel("# of steps")
ax[0,1].set_ylabel(r"Measured Movement [$\mu m$]")
ax[0,1].errorbar(xp, z2p, error_z2, linestyle="none", marker=".", linewidth=lw, color="tab:red", label="z2- data", capsize=capsize)
ax[0,1].errorbar(xp, z2m, error_z2, linestyle="none", marker=".", linewidth=lw, color="chocolate", label="z2+ data", capsize=capsize)
ax[0,1].plot(xp, linear(xp, popt_z2p[0]), linewidth=lw, color="tab:red", label="z2- fit")
ax[0,1].plot(xp, linear(xp, popt_z2m[0]), linewidth=lw, color="chocolate", label="z2+ fit")
#ax = plt.gca()
anchored_text = AnchoredText(r"$b_-$= {:.2f} $\pm$ {:.2f} $n m$/step, $\chi^2/ndof =${:.2f}".format(popt_z2p[0] * 1000, np.sqrt(pcov_z2p[0][0]) * 1000, chi_z2p) + "\n" + "$b_+$= {:.2f} $\pm$ {:.2f} $n m$/step, $\chi^2/ndof =${:.2f}".format(popt_z2m[0] * 1000, np.sqrt(pcov_z2m[0][0]) * 1000, chi_z2m), loc=4)
ax[0,1].add_artist(anchored_text)
ax[0,1].legend()
plt.grid()
#plt.savefig("Plots\Calibration\Z2_" + str(Voltage) + ".pdf")
#plt.show()
print("slope in nm/step z2-:", popt_z2p[0] * 1000, " +- ", np.sqrt(pcov_z2p[0][0]) * 1000, " chi^2 ", chi_z2p)
print("slope in nm/step z2+:", popt_z2m[0] * 1000, " +- ", np.sqrt(pcov_z2m[0][0]) * 1000, " chi^2 ", chi_z2m)
#Z3
if(plots):
ax[1,0].set_title("Z3 calibration fit " + str(Voltage))
ax[1,0].set_xlabel("# of steps")
ax[1,0].set_ylabel(r"Measured Movement [$\mu m$]")
ax[1,0].errorbar(xp, z3p, error_z3, linestyle="none", marker=".", linewidth=lw, color="tab:green", label="z3- data", capsize=capsize)
ax[1,0].errorbar(xp, z3m, error_z3, linestyle="none", marker=".", linewidth=lw, color="darkolivegreen", label="z3+ data", capsize=capsize)
ax[1,0].plot(xp, linear(xp, popt_z3p[0]), linewidth=lw, color="tab:green", label="z3- fit")
ax[1,0].plot(xp, linear(xp, popt_z3m[0]), linewidth=lw, color="darkolivegreen", label="z3+ fit")
#ax = plt.gca()
anchored_text = AnchoredText(r"$b_-$= {:.2f} $\pm$ {:.2f} $n m$/step, $\chi^2/ndof =${:.2f}".format(popt_z3p[0] * 1000, np.sqrt(pcov_z3p[0][0]) * 1000, chi_z3p) + "\n" + "$b_+$= {:.2f} $\pm$ {:.2f} $n m$/step, $\chi^2/ndof =${:.2f}".format(popt_z3m[0] * 1000, np.sqrt(pcov_z3m[0][0]) * 1000, chi_z3m), loc=4)
ax[1,0].add_artist(anchored_text)
ax[1,0].legend()
plt.grid()
#plt.savefig("Plots\Calibration\Z3_" + str(Voltage) + ".pdf")
#plt.show()
print("slope in nm/step z3-:", popt_z3p[0] * 1000, " +- ", np.sqrt(pcov_z3p[0][0]) * 1000, " chi^2 ", chi_z3p)
print("slope in nm/step z3+:", popt_z3m[0] * 1000, " +- ", np.sqrt(pcov_z3m[0][0]) * 1000, " chi^2 ", chi_z3p)
#ZALL
if(plots):
ax[1,1].set_title("ZAll calibration fit " + str(Voltage))
ax[1,1].set_xlabel("# of steps")
ax[1,1].set_ylabel(r"Measured Movement [$\mu m$]")
ax[1,1].errorbar(xp, zAllp, error_zAll, linestyle="none", marker=".", linewidth=lw, color="tab:purple", label="zAll- data", capsize=capsize)
ax[1,1].errorbar(xp, zAllm, error_zAll, linestyle="none", marker=".", linewidth=lw, color="m", label="zAll+ data", capsize=capsize)
ax[1,1].plot(xp, linear(xp, popt_zAllp[0]), linewidth=lw, color="tab:purple", label="zAll- fit")
ax[1,1].plot(xp, linear(xp, popt_zAllm[0]), linewidth=lw, color="m", label="zAll+ fit")
#ax = plt.gca()
anchored_text = AnchoredText(r"$b_-$= {:.2f} $\pm$ {:.2f} $n m$/step, $\chi^2/ndof =${:.2f}".format(popt_zAllp[0] * 1000, np.sqrt(pcov_zAllp[0][0]) * 1000, chi_zAllp) + "\n" + "$b_+$= {:.2f} $\pm$ {:.2f} $n m$/step, $\chi^2/ndof =${:.2f}".format(popt_zAllm[0] * 1000, np.sqrt(pcov_zAllm[0][0]) * 1000, chi_zAllm), loc=4)
ax[1,1].add_artist(anchored_text)
ax[1,1].legend()
plt.grid()
plt.savefig("Plots\Calibration\Z_" + str(Voltage) + ".pdf")
plt.savefig("Plots\Calibration\Z_" + str(Voltage) + ".png", dpi=300)
plt.show()
print("slope in nm/step zAll-:", popt_zAllp[0] * 1000, " +- ", np.sqrt(pcov_zAllp[0][0]) * 1000, " chi^2 ", chi_zAllp) class var_with_err:
print("slope in nm/step zAll+:", popt_zAllm[0] * 1000, " +- ", np.sqrt(pcov_zAllm[0][0]) * 1000, " chi^2 ", chi_zAllp) def __init__(self, var, err):
self.var = var
self.err = err
def __str__(self):
return round(self.var, uncertainty=self.err)
def linear(x, b): def linear(x, b):
return b*x return b*x
def dataHandling(data, plots, raw): def FitAndPlot(x, z1p, z1m, z2p, z2m, z3p, z3m, z1p_err, z1m_err, z2p_err, z2m_err, z3p_err, z3m_err, voltage, sigma, plots = True, raw = False, residuals=True):
x = data[0]
z1p = data[1] font = font_manager.FontProperties(family='DejaVu Sans Mono', style='normal')
z1m = data[2]
z2p = data[3] fac = 1e6
z2m = data[4]
z3p = data[5] popt_z1p, pcov_z1p = curve_fit(linear, x, z1p, sigma=z1p_err)
z3m = data[6] popt_z1m, pcov_z1m = curve_fit(linear, x, z1m, sigma=z1m_err)
# Check if calibration performed for all otherwise use dummy data. popt_z2p, pcov_z2p = curve_fit(linear, x, z2p, sigma=z2p_err)
if(len(data) > 7): popt_z2m, pcov_z2m = curve_fit(linear, x, z2m, sigma=z2m_err)
zAllp = data[7] popt_z3p, pcov_z3p = curve_fit(linear, x, z3p, sigma=z3p_err)
zAllm = data[8] popt_z3m, pcov_z3m = curve_fit(linear, x, z3m, sigma=z3m_err)
step_z1p = var_with_err(popt_z1p[0] * fac, np.sqrt(pcov_z1p[0][0]) * fac)
step_z1m = var_with_err(popt_z1m[0] * fac, np.sqrt(pcov_z1m[0][0]) * fac)
step_z2p = var_with_err(popt_z2p[0] * fac, np.sqrt(pcov_z2p[0][0]) * fac)
step_z2m = var_with_err(popt_z2m[0] * fac, np.sqrt(pcov_z2m[0][0]) * fac)
step_z3p = var_with_err(popt_z3p[0] * fac, np.sqrt(pcov_z3p[0][0]) * fac)
step_z3m = var_with_err(popt_z3m[0] * fac, np.sqrt(pcov_z3m[0][0]) * fac)
chi_z1p = np.sum(((z1p - linear(x, popt_z1p[0]))/z1p_err)**2) / len(x - 2)
chi_z1m = np.sum(((z1m - linear(x, popt_z1m[0]))/z1m_err)**2) / len(x - 2)
chi_z2p = np.sum(((z2p - linear(x, popt_z2p[0]))/z2p_err)**2) / len(x - 2)
chi_z2m = np.sum(((z2m - linear(x, popt_z2m[0]))/z2m_err)**2) / len(x - 2)
chi_z3p = np.sum(((z3p - linear(x, popt_z3p[0]))/z3p_err)**2) / len(x - 2)
chi_z3m = np.sum(((z3m - linear(x, popt_z3m[0]))/z3m_err)**2) / len(x - 2)
err_z3z2p = popt_z3p[0] * fac / (popt_z2p[0] * fac)
err_z3z2m = popt_z3m[0] * fac / (popt_z2m[0] * fac)
err_z3z1p = popt_z3p[0] * fac / (popt_z1p[0] * fac)
err_z3z1m = popt_z3m[0] * fac / (popt_z1m[0] * fac)
err_z2z1p = popt_z2p[0] * fac / (popt_z1p[0] * fac)
err_z2z1m = popt_z2m[0] * fac / (popt_z1m[0] * fac)
print("### Voltage: ", voltage, " ###")
print("z1p: ", step_z1p, " nm/step ", "chi^2/ndof = ", chi_z1p)
print("z1m: ", step_z1m, " nm/step ", "chi^2/ndof = ", chi_z1m)
print("z2p: ", step_z2p, " nm/step ", "chi^2/ndof = ", chi_z2p)
print("z2m: ", step_z2m, " nm/step ", "chi^2/ndof = ", chi_z2m)
print("z3p: ", step_z3p, " nm/step ", "chi^2/ndof = ", chi_z3p)
print("z3m: ", step_z3m, " nm/step ", "chi^2/ndof = ", chi_z3m)
print("error (ratio) + z3/z2: ", popt_z3p[0] * fac / (popt_z2p[0] * fac))
print("error (ratio) - z3/z2: ", popt_z3m[0] * fac / (popt_z2m[0] * fac))
print("error (ratio) + z3/z1: ", popt_z3p[0] * fac / (popt_z1p[0] * fac))
print("error (ratio) - z3/z1: ", popt_z3m[0] * fac / (popt_z1m[0] * fac))
print("error (ratio) + z2/z1: ", popt_z2p[0] * fac / (popt_z1p[0] * fac))
print("error (ratio) - z2/z1: ", popt_z2m[0] * fac / (popt_z1m[0] * fac))
if plots:
x_inter = np.arange(min(x), max(x), 1)
l_jus = 5
if not residuals:
fig = plt.figure()
else: else:
zAllp = np.zeros(len(z1p)) fig, ax = plt.subplots(2,1, sharex=True, gridspec_kw={'height_ratios': [3,1]})
zAllm = np.zeros(len(z1m))
fig.set_figheight(4.5)
fig.set_figwidth(8)
if residuals:
ax[0].set_title("Mask Aligner Motors at " + str(voltage) + " V")
ax[0].errorbar(x + 80, z1p, z1p_err, marker=".", linestyle="none", capsize=3, label="z1+:".ljust(l_jus ) + str(step_z1p) + " nm/step ", color="tab:blue")
ax[0].errorbar(x + 40, z2p, z2p_err, marker=".", linestyle="none", capsize=3, label="z2+:".ljust(l_jus ) + str(step_z2p) + " nm/step ", color="tab:orange")
ax[0].errorbar(x - 40, z3p, z3p_err, marker=".", linestyle="none", capsize=3, label="z3+:".ljust(l_jus ) + str(step_z3p) + " nm/step ", color="tab:purple")
ax[0].plot(x_inter, linear(x_inter, popt_z1p[0]), color="tab:blue")
ax[0].plot(x_inter, linear(x_inter, popt_z1m[0]), color="tab:cyan")
ax[0].plot(x_inter, linear(x_inter, popt_z2p[0]), color="tab:orange")
ax[0].plot(x_inter, linear(x_inter, popt_z2m[0]), color="tab:red")
ax[0].errorbar(x - 80, z1m, z1m_err, marker=".", linestyle="none", capsize=3, label="z1-:".ljust(l_jus ) + str(step_z1m) + " nm/step ", color="tab:cyan")
ax[0].errorbar(x + 120, z2m, z2m_err, marker=".", linestyle="none", capsize=3, label="z2-:".ljust(l_jus ) + str(step_z2m) + " nm/step ", color="tab:red")
ax[0].errorbar(x, z3m, z3m_err, marker=".", linestyle="none", capsize=3, label="z3-:".ljust(l_jus ) + str(step_z3m) + " nm/step ", color="tab:pink")
ax[0].plot(x_inter, linear(x_inter, popt_z3p[0]), color="tab:purple")
ax[0].plot(x_inter, linear(x_inter, popt_z3m[0]), color="tab:pink")
ax[0].set_xlabel("Number of steps driven")
ax[0].set_ylabel("Distance travelled [mm]")
ax[0].legend(handletextpad=0.1, prop = font)
ax[0].grid()
plt.tight_layout()
#ax[1].set_title("residuals")
ax[1].errorbar(x + 80, z1p - linear(x, popt_z1p[0]), z1p_err, marker=".", linestyle="none", capsize=3, label="z1+:".ljust(l_jus ) + str(step_z1p) + " nm/step ", color="tab:blue")
ax[1].errorbar(x + 40, z2p - linear(x, popt_z2p[0]), z2p_err, marker=".", linestyle="none", capsize=3, label="z2+:".ljust(l_jus ) + str(step_z2p) + " nm/step ", color="tab:orange")
ax[1].errorbar(x- 40, z3p - linear(x, popt_z3p[0]), z3p_err, marker=".", linestyle="none", capsize=3, label="z3+:".ljust(l_jus ) + str(step_z3p) + " nm/step ", color="tab:purple")
ax[1].plot(x_inter, np.zeros(len(x_inter)), color="tab:blue")
ax[1].set_ylim(0 - max(np.absolute(z3m - linear(x, popt_z1m[0]))) - max(z3m_err) - 0.05, 0 + max(np.absolute(z3m - linear(x, popt_z1m[0]))) + max(z3m_err)+ 0.05)
#ax[1].plot(x_inter, linear(x_inter, popt_z1m[0]), color="tab:cyan")
FitAndPlot(x, x, z1p, z1m, z2p, z2m, z3p, z3m, zAllp, zAllm, 85, plots, raw) #ax[1].plot(x_inter, linear(x_inter, popt_z2p[0]), color="tab:orange")
#ax[1].plot(x_inter, linear(x_inter, popt_z2m[0]), color="tab:red")
ax[1].errorbar(x - 80, z1m - linear(x, popt_z1m[0]), z1m_err, marker=".", linestyle="none", capsize=3, label="z1-:".ljust(l_jus ) + str(step_z1m) + " nm/step ", color="tab:cyan")
ax[1].errorbar(x + 120, z2m - linear(x, popt_z1m[0]), z2m_err, marker=".", linestyle="none", capsize=3, label="z2-:".ljust(l_jus ) + str(step_z2m) + " nm/step ", color="tab:red")
ax[1].errorbar(x, z3m - linear(x, popt_z1m[0]), z3m_err, marker=".", linestyle="none", capsize=3, label="z3-:".ljust(l_jus ) + str(step_z3m) + " nm/step ", color="tab:pink")
#ax[1].plot(x_inter, linear(x_inter, popt_z3p[0]), color="tab:purple")
#ax[1].plot(x_inter, linear(x_inter, popt_z3m[0]), color="tab:pink")
ax[1].set_xlabel("Number of steps driven")
ax[1].set_ylabel("Distance travelled [mm]")
ax[1].grid()
else:
plt.title("Mask Aligner Motors at " + str(voltage) + " V")
plt.errorbar(x + 80, z1p, z1p_err, marker=".", linestyle="none", capsize=3, label="z1+:".ljust(l_jus ) + str(step_z1p) + " nm/step ", color="tab:blue")
plt.errorbar(x + 40, z2p, z2p_err, marker=".", linestyle="none", capsize=3, label="z2+:".ljust(l_jus ) + str(step_z2p) + " nm/step ", color="tab:orange")
plt.errorbar(x - 40, z3p, z3p_err, marker=".", linestyle="none", capsize=3, label="z3+:".ljust(l_jus ) + str(step_z3p) + " nm/step ", color="tab:purple")
plt.plot(x_inter, linear(x_inter, popt_z1p[0]), color="tab:blue")
plt.plot(x_inter, linear(x_inter, popt_z1m[0]), color="tab:cyan")
plt.plot(x_inter, linear(x_inter, popt_z2p[0]), color="tab:orange")
plt.plot(x_inter, linear(x_inter, popt_z2m[0]), color="tab:red")
plt.errorbar(x - 80, z1m, z1m_err, marker=".", linestyle="none", capsize=3, label="z1-:".ljust(l_jus ) + str(step_z1m) + " nm/step ", color="tab:cyan")
plt.errorbar(x + 120, z2m, z2m_err, marker=".", linestyle="none", capsize=3, label="z2-:".ljust(l_jus ) + str(step_z2m) + " nm/step ", color="tab:red")
plt.errorbar(x, z3m, z3m_err, marker=".", linestyle="none", capsize=3, label="z3-:".ljust(l_jus ) + str(step_z3m) + " nm/step ", color="tab:pink")
plt.plot(x_inter, linear(x_inter, popt_z3p[0]), color="tab:purple")
plt.plot(x_inter, linear(x_inter, popt_z3m[0]), color="tab:pink")
plt.xlabel("Number of steps driven")
plt.ylabel("Distance travelled [mm]")
plt.legend(handletextpad=0.1, prop = font)
plt.grid()
plt.tight_layout()
plt.savefig("Plots/CalibrationAfterRepair/" + str(voltage) + "V.pdf")
plt.savefig("Plots/CalibrationAfterRepair/" + str(voltage) + "V.png", dpi=300)
plt.show()
return step_z1p, step_z1m, step_z2p, step_z2m, step_z3p, step_z3m, err_z3z2p, err_z3z2m, err_z3z1p, err_z3z1m, err_z2z1p, err_z2z1m
def dataHandling(data, offset, voltage, plots, raw):
x = data[0 + offset]
z3m = data[1 + offset]
z3p = data[2 + offset]
z2m = data[3 + offset]
z2p = data[4 + offset]
z1m = data[5 + offset]
z1p = data[6 + offset]
z3m_err = data[7 + offset]
z3p_err = data[8 + offset]
z2m_err = data[9 + offset]
z2p_err = data[10 + offset]
z1m_err = data[11 + offset]
z1p_err = data[12 + offset]
sigma = np.ones(len(x)) * data[0][0]
#Check for empty data and fill with dummy
if np.isnan(z1p).any():
z1p = np.zeros(5)
if np.isnan(z1m).any():
z1m = np.zeros(5)
if np.isnan(z2p).any():
z2p = np.zeros(5)
if np.isnan(z2m).any():
z2m = np.zeros(5)
if np.isnan(z3p).any():
z3p = np.zeros(5)
if np.isnan(z3m).any():
z3m = np.zeros(5)
if np.isnan(z1p_err).any():
z1p_err = np.ones(5) * sigma
if np.isnan(z1m_err).any():
z1m_err = np.ones(5) * sigma
if np.isnan(z2p_err).any():
z2p_err = np.ones(5) * sigma
if np.isnan(z2m_err).any():
z2m_err = np.ones(5) * sigma
if np.isnan(z3p_err).any():
z3p_err = np.ones(5) * sigma
if np.isnan(z3m_err).any():
z3m_err = np.ones(5) * sigma
step_z1p, step_z1m, step_z2p, step_z2m, step_z3p, step_z3m, err_z3z2p, err_z3z2m, err_z3z1p, err_z3z1m, err_z2z1p, err_z2z1m = FitAndPlot(x, z1p, z1m, z2p, z2m, z3p, z3m, z1p_err, z1m_err, z2p_err, z2m_err, z3p_err, z3m_err, voltage, sigma, plots, raw)
return step_z1p, step_z1m, step_z2p, step_z2m, step_z3p, step_z3m, err_z3z2p, err_z3z2m, err_z3z1p, err_z3z1m, err_z2z1p, err_z2z1m
def main(): def main():
plots = True plots = True
raw = False raw = False
file = "C:\MaskAligner\Data\Calibration.csv" file = "C:\MaskAligner\Data\Calibration\CalibrationAfterRepair_13_11_23.csv"
# very Simple commandline parser # very Simple commandline parser
if("--no_plots" in sys.argv): if("--no_plots" in sys.argv):
...@@ -191,10 +231,77 @@ def main(): ...@@ -191,10 +231,77 @@ def main():
if("--raw_plot" in sys.argv): if("--raw_plot" in sys.argv):
raw = True raw = True
data = np.genfromtxt(file, skip_header=0, delimiter=",") data = np.genfromtxt(file, skip_header=1, delimiter=",")
data = data.T data = data.T
dataHandling(data, plots, raw) volt = data[0][0]
arr = []
arr.append(dataHandling(data, 1, volt, plots, raw))
arr = np.array(arr).T
## Plot motors errors against one another against voltage
"""
fig = plt.figure()
fig.set_figheight(4.5)
fig.set_figwidth(8)
plt.plot([70, 80, 100, 120], arr[6], label="error z3/z2+", marker=".", linestyle="dashed")
plt.plot([70, 80, 100, 120], arr[8], label="error z3/z1+", marker=".", linestyle="dashed")
plt.plot([70, 80, 100, 120], arr[10], label="error z2/z1+", marker=".", linestyle="dashed")
plt.plot([70, 80, 100, 120], arr[7], label="error z3/z2-", marker=".", linestyle="dashed")
plt.plot([70, 80, 100, 120], arr[9], label="error z3/z1-", marker=".", linestyle="dashed")
plt.plot([70, 80, 100, 120], arr[11], label="error z2/z1-", marker=".", linestyle="dashed")
plt.xlabel("Voltage [V]")
plt.ylabel("ratio of motor's stepsizes")
plt.legend()
plt.tight_layout()
plt.savefig("Plots/CalibrationAfterRepair/Errors.pdf")
plt.savefig("Plots/CalibrationAfterRepair/Errors.png", dpi=300)
plt.show()
## Plot stepsizes against voltage
fig = plt.figure()
fig.set_figheight(4.5)
fig.set_figwidth(8)
plt.errorbar([70, 80, 100, 120], [x.var for x in arr[0]], [x.err for x in arr[0]], label="z1+", marker=".", linestyle="dashed", capsize=3, color="tab:blue")
plt.errorbar([70, 80, 100, 120], [x.var for x in arr[1]], [x.err for x in arr[1]], label="z1-", marker=".", linestyle="dashed", capsize=3, color="tab:cyan")
plt.errorbar([70, 80, 100, 120], [x.var for x in arr[2]], [x.err for x in arr[2]], label="z2+", marker=".", linestyle="dashed", capsize=3, color="tab:orange")
plt.errorbar([70, 80, 100, 120], [x.var for x in arr[3]], [x.err for x in arr[3]], label="z2-", marker=".", linestyle="dashed", capsize=3, color="tab:red")
plt.errorbar([70, 80, 100, 120], [x.var for x in arr[4]], [x.err for x in arr[4]], label="z3+", marker=".", linestyle="dashed", capsize=3, color="tab:purple")
plt.errorbar([70, 80, 100, 120], [x.var for x in arr[5]], [x.err for x in arr[5]], label="z3-", marker=".", linestyle="dashed", capsize=3, color="tab:pink")
plt.xlabel("Voltage [V]")
plt.ylabel("stepsize [nm/step]")
plt.legend()
plt.tight_layout()
plt.savefig("Plots/CalibrationAfterRepair/Stepsizes.pdf")
plt.savefig("Plots/CalibrationAfterRepair/Stepsizes.png", dpi=300)
plt.show()
## Plot up/down ratio against Voltage
z1_ud = var_with_err(np.array([x.var for x in arr[0]])/np.array([x.var for x in arr[1]]), np.sqrt((1/np.array([x.var for x in arr[1]]) * np.array([x.err for x in arr[0]]))**2 + (np.array([x.var for x in arr[0]])/np.array([x.var for x in arr[1]])**2 * np.array([x.err for x in arr[1]]))**2))
z2_ud = var_with_err(np.array([x.var for x in arr[2]])/np.array([x.var for x in arr[3]]), np.sqrt((1/np.array([x.var for x in arr[3]]) * np.array([x.err for x in arr[2]]))**2 + (np.array([x.var for x in arr[2]])/np.array([x.var for x in arr[3]])**2 * np.array([x.err for x in arr[3]]))**2))
z3_ud = var_with_err(np.array([x.var for x in arr[4]])/np.array([x.var for x in arr[5]]), np.sqrt((1/np.array([x.var for x in arr[5]]) * np.array([x.err for x in arr[4]]))**2 + (np.array([x.var for x in arr[4]])/np.array([x.var for x in arr[5]])**2 * np.array([x.err for x in arr[5]]))**2))
fig = plt.figure()
fig.set_figheight(4.5)
fig.set_figwidth(8)
plt.errorbar([70, 80, 100, 120], z1_ud.var, z1_ud.err, label="z1", marker=".", linestyle="dashed", capsize=3, color="tab:blue")
plt.errorbar([70, 80, 100, 120], z2_ud.var, z2_ud.err, label="z2", marker=".", linestyle="dashed", capsize=3, color="tab:cyan")
plt.errorbar([70, 80, 100, 120], z3_ud.var, z3_ud.err, label="z3", marker=".", linestyle="dashed", capsize=3, color="tab:orange")
plt.xlabel("Voltage [V]")
plt.ylabel("ratio approach/retract")
plt.legend()
plt.tight_layout()
plt.savefig("Plots/CalibrationAfterRepair/ratioUD.pdf")
plt.savefig("Plots/CalibrationAfterRepair/ratioUD.png", dpi=300)
plt.show()
"""
if __name__ == "__main__": if __name__ == "__main__":
main() main()
\ No newline at end of file
@echo off @echo off
cd /D "%~dp0" cd /D "%~dp0"
for %%a in (%*) do py .\Calibration.py --file %%a for %%a in (%*) do py .\Calibration.py --file %%a
pause
\ No newline at end of file
import numpy as np
from scipy.optimize import curve_fit
import matplotlib.pyplot as plt
from matplotlib.offsetbox import AnchoredText
import sys
## Performs linear fit for calibration
def FitAndPlot(xp, xm, z1p, z1m, z2p, z2m, z3p, z3m, zAllp, zAllm, Voltage, plots, raw):
#Linewidth
lw = 0.8
#
if(plots):
if(raw):
plt.title("Calibration Measurement " + str(Voltage))
plt.plot(xp, z1p, marker=".", color="tab:blue", label="z1-", linewidth=lw)
plt.plot(xp, z1m, marker=".", color="b", label="z1+", linewidth=lw)
plt.plot(xp, z2p, marker=".", color="tab:red", label="z2-", linewidth=lw)
plt.plot(xp, z2m, marker=".", color="chocolate", label="z2+", linewidth=lw)
plt.plot(xp, z3p, marker=".", color="tab:green", label="z3-", linewidth=lw)
plt.plot(xp, z3m, marker=".", color="darkolivegreen", label="z3+", linewidth=lw)
plt.plot(xp, zAllp, marker=".", color="tab:purple", label="zAll-", linewidth=lw)
plt.plot(xp, zAllm, marker=".", color="m", label="zAll+", linewidth=lw)
plt.ylabel(r"Measured Movement [$\mu m$]")
plt.xlabel("# of step")
plt.legend()
plt.grid()
plt.savefig("Plots\Calibration\\" + str(Voltage) + "_All_Data.pdf")
plt.show()
# Fit
# Errors are 1/sqrt(12) * one pixel length in mikrometers
error_z1 = 8.87 / np.sqrt(12)
error_z2 = 9.62 / np.sqrt(12)
error_z3 = 9.80 / np.sqrt(12)
error_zAll = 9.00 / np.sqrt(12)
popt_z1p, pcov_z1p = curve_fit(linear, xp, z1p, error_z1)
popt_z1m, pcov_z1m = curve_fit(linear, xp, z1m, error_z1)
popt_z2p, pcov_z2p = curve_fit(linear, xp, z2p, error_z2)
popt_z2m, pcov_z2m = curve_fit(linear, xp, z2m, error_z2)
popt_z3p, pcov_z3p = curve_fit(linear, xp, z3p, error_z3)
popt_z3m, pcov_z3m = curve_fit(linear, xp, z3m, error_z3)
popt_zAllp, pcov_zAllp = curve_fit(linear, xp, zAllp, error_zAll)
popt_zAllm, pcov_zAllm = curve_fit(linear, xp, zAllm, error_zAll)
# Chi squared Computation per degree of freedom
chi_z1p = np.sum(((z1p - linear(xp, popt_z1p[0]))**2 / error_z1**2)) / (len(z1p) - 1)
chi_z1m = np.sum(((z1m - linear(xp, popt_z1m[0]))**2 / error_z1**2)) / (len(z1m) - 1)
chi_z2p = np.sum(((z2p - linear(xp, popt_z2p[0]))**2 / error_z2**2)) / (len(z2p) - 1)
chi_z2m = np.sum(((z2m - linear(xp, popt_z2m[0]))**2 / error_z2**2)) / (len(z2m) - 1)
chi_z3p = np.sum(((z3p - linear(xp, popt_z3p[0]))**2 / error_z3**2)) / (len(z3p) - 1)
chi_z3m = np.sum(((z3m - linear(xp, popt_z3m[0]))**2 / error_z3**2)) / (len(z3m) - 1)
chi_zAllp = np.sum(((zAllp - linear(xp, popt_zAllp[0]))**2 / error_zAll**2)) / (len(zAllp) - 1)
chi_zAllm = np.sum(((zAllm - linear(xp, popt_zAllm[0]))**2 / error_zAll**2)) / (len(zAllm) - 1)
# Plots
fig, ax = plt.subplots(2, 2)
fig.set_figheight(9)
fig.set_figwidth(16)
# Z1
capsize = 2
if(plots):
ax[0,0].set_title("Z1 calibration fit " + str(Voltage))
ax[0,0].set_xlabel("# of steps")
ax[0,0].set_ylabel(r"Measured Movement [$\mu m$]")
ax[0,0].errorbar(xp, z1p, error_z1, linestyle="none", marker=".", linewidth=lw, color="tab:blue", label="z1- data", capsize=capsize)
ax[0,0].errorbar(xp, z1m, error_z1, linestyle="none", marker=".", linewidth=lw, color="b", label="z1+ data", capsize=capsize)
ax[0,0].plot(xp, linear(xp, popt_z1p[0]), linewidth=lw, color="tab:blue", label="z1- fit")
ax[0,0].plot(xp, linear(xp, popt_z1m[0]), linewidth=lw, color="b", label="z1+ fit")
#ax = plt.gca()
anchored_text = AnchoredText(r"$b_-$= {:.2f} $\pm$ {:.2f} $n m$/step, $\chi^2/ndof =${:.2f}".format(popt_z1p[0] * 1000, np.sqrt(pcov_z1p[0][0]) * 1000, chi_z1p) + "\n" + "$b_+$= {:.2f} $\pm$ {:.2f} $n m$/step, $\chi^2/ndof =${:.2f}".format(popt_z1m[0] * 1000, np.sqrt(pcov_z1m[0][0]) * 1000, chi_z1m), loc=4)
ax[0,0].add_artist(anchored_text)
ax[0,0].legend()
plt.grid()
#plt.savefig("Plots\Calibration\Z1_" + str(Voltage) + ".pdf")
#plt.show()
print("slope in nm/step z1-:", popt_z1p[0] * 1000, " +- ", np.sqrt(pcov_z1p[0][0]) * 1000, " chi^2 ", chi_z1p)
print("slope in nm/step z1+:", popt_z1m[0] * 1000, " +- ", np.sqrt(pcov_z1m[0][0]) * 1000, " chi^2 ", chi_z1m)
#Z2
if(plots):
ax[0,1].set_title("Z2 calibration fit " + str(Voltage))
ax[0,1].set_xlabel("# of steps")
ax[0,1].set_ylabel(r"Measured Movement [$\mu m$]")
ax[0,1].errorbar(xp, z2p, error_z2, linestyle="none", marker=".", linewidth=lw, color="tab:red", label="z2- data", capsize=capsize)
ax[0,1].errorbar(xp, z2m, error_z2, linestyle="none", marker=".", linewidth=lw, color="chocolate", label="z2+ data", capsize=capsize)
ax[0,1].plot(xp, linear(xp, popt_z2p[0]), linewidth=lw, color="tab:red", label="z2- fit")
ax[0,1].plot(xp, linear(xp, popt_z2m[0]), linewidth=lw, color="chocolate", label="z2+ fit")
#ax = plt.gca()
anchored_text = AnchoredText(r"$b_-$= {:.2f} $\pm$ {:.2f} $n m$/step, $\chi^2/ndof =${:.2f}".format(popt_z2p[0] * 1000, np.sqrt(pcov_z2p[0][0]) * 1000, chi_z2p) + "\n" + "$b_+$= {:.2f} $\pm$ {:.2f} $n m$/step, $\chi^2/ndof =${:.2f}".format(popt_z2m[0] * 1000, np.sqrt(pcov_z2m[0][0]) * 1000, chi_z2m), loc=4)
ax[0,1].add_artist(anchored_text)
ax[0,1].legend()
plt.grid()
#plt.savefig("Plots\Calibration\Z2_" + str(Voltage) + ".pdf")
#plt.show()
print("slope in nm/step z2-:", popt_z2p[0] * 1000, " +- ", np.sqrt(pcov_z2p[0][0]) * 1000, " chi^2 ", chi_z2p)
print("slope in nm/step z2+:", popt_z2m[0] * 1000, " +- ", np.sqrt(pcov_z2m[0][0]) * 1000, " chi^2 ", chi_z2m)
#Z3
if(plots):
ax[1,0].set_title("Z3 calibration fit " + str(Voltage))
ax[1,0].set_xlabel("# of steps")
ax[1,0].set_ylabel(r"Measured Movement [$\mu m$]")
ax[1,0].errorbar(xp, z3p, error_z3, linestyle="none", marker=".", linewidth=lw, color="tab:green", label="z3- data", capsize=capsize)
ax[1,0].errorbar(xp, z3m, error_z3, linestyle="none", marker=".", linewidth=lw, color="darkolivegreen", label="z3+ data", capsize=capsize)
ax[1,0].plot(xp, linear(xp, popt_z3p[0]), linewidth=lw, color="tab:green", label="z3- fit")
ax[1,0].plot(xp, linear(xp, popt_z3m[0]), linewidth=lw, color="darkolivegreen", label="z3+ fit")
#ax = plt.gca()
anchored_text = AnchoredText(r"$b_-$= {:.2f} $\pm$ {:.2f} $n m$/step, $\chi^2/ndof =${:.2f}".format(popt_z3p[0] * 1000, np.sqrt(pcov_z3p[0][0]) * 1000, chi_z3p) + "\n" + "$b_+$= {:.2f} $\pm$ {:.2f} $n m$/step, $\chi^2/ndof =${:.2f}".format(popt_z3m[0] * 1000, np.sqrt(pcov_z3m[0][0]) * 1000, chi_z3m), loc=4)
ax[1,0].add_artist(anchored_text)
ax[1,0].legend()
plt.grid()
#plt.savefig("Plots\Calibration\Z3_" + str(Voltage) + ".pdf")
#plt.show()
print("slope in nm/step z3-:", popt_z3p[0] * 1000, " +- ", np.sqrt(pcov_z3p[0][0]) * 1000, " chi^2 ", chi_z3p)
print("slope in nm/step z3+:", popt_z3m[0] * 1000, " +- ", np.sqrt(pcov_z3m[0][0]) * 1000, " chi^2 ", chi_z3p)
#ZALL
if(plots):
ax[1,1].set_title("ZAll calibration fit " + str(Voltage))
ax[1,1].set_xlabel("# of steps")
ax[1,1].set_ylabel(r"Measured Movement [$\mu m$]")
ax[1,1].errorbar(xp, zAllp, error_zAll, linestyle="none", marker=".", linewidth=lw, color="tab:purple", label="zAll- data", capsize=capsize)
ax[1,1].errorbar(xp, zAllm, error_zAll, linestyle="none", marker=".", linewidth=lw, color="m", label="zAll+ data", capsize=capsize)
ax[1,1].plot(xp, linear(xp, popt_zAllp[0]), linewidth=lw, color="tab:purple", label="zAll- fit")
ax[1,1].plot(xp, linear(xp, popt_zAllm[0]), linewidth=lw, color="m", label="zAll+ fit")
#ax = plt.gca()
anchored_text = AnchoredText(r"$b_-$= {:.2f} $\pm$ {:.2f} $n m$/step, $\chi^2/ndof =${:.2f}".format(popt_zAllp[0] * 1000, np.sqrt(pcov_zAllp[0][0]) * 1000, chi_zAllp) + "\n" + "$b_+$= {:.2f} $\pm$ {:.2f} $n m$/step, $\chi^2/ndof =${:.2f}".format(popt_zAllm[0] * 1000, np.sqrt(pcov_zAllm[0][0]) * 1000, chi_zAllm), loc=4)
ax[1,1].add_artist(anchored_text)
ax[1,1].legend()
plt.grid()
plt.savefig("Plots\Calibration\Z_" + str(Voltage) + ".pdf")
plt.savefig("Plots\Calibration\Z_" + str(Voltage) + ".png", dpi=300)
plt.show()
print("slope in nm/step zAll-:", popt_zAllp[0] * 1000, " +- ", np.sqrt(pcov_zAllp[0][0]) * 1000, " chi^2 ", chi_zAllp)
print("slope in nm/step zAll+:", popt_zAllm[0] * 1000, " +- ", np.sqrt(pcov_zAllm[0][0]) * 1000, " chi^2 ", chi_zAllp)
def linear(x, b):
return b*x
def dataHandling(data, plots, raw):
x = data[0]
z1p = data[1]
z1m = data[2]
z2p = data[3]
z2m = data[4]
z3p = data[5]
z3m = data[6]
# Check if calibration performed for all otherwise use dummy data.
if(len(data) > 7):
zAllp = data[7]
zAllm = data[8]
else:
zAllp = np.zeros(len(z1p))
zAllm = np.zeros(len(z1m))
FitAndPlot(x, x, z1p, z1m, z2p, z2m, z3p, z3m, zAllp, zAllm, 85, plots, raw)
def main():
plots = True
raw = False
file = "C:\MaskAligner\Data\Calibration.csv"
# very Simple commandline parser
if("--no_plots" in sys.argv):
plots = False
if("--file" in sys.argv or "-f" in sys.argv):
for i in range(len(sys.argv)):
if("--file" in sys.argv[i] or "-f" == sys.argv[i]):
try:
file = sys.argv[i+1]
except:
print("No file or incorrect file specification.")
if("--raw_plot" in sys.argv):
raw = True
data = np.genfromtxt(file, skip_header=0, delimiter=",")
data = data.T
dataHandling(data, plots, raw)
if __name__ == "__main__":
main()
\ No newline at end of file
# -*- coding: utf-8 -*-
"""
Created on Wed Feb 7 14:40:15 2024
@author: admin
"""
import matplotlib.pyplot as plt
import numpy as np
def main():
file = "C:\MaskAligner\Data\Calibration07_02_24\CalibrationQuick.csv"
data = np.genfromtxt(file, delimiter=",", skip_header=1).T
Z1m = data[1]
Z1p = data[2]
Z2m = data[4]
Z2p = data[5]
Z3m = data[7]
Z3p = data[8]
plt.plot(np.zeros(len(Z1m)) + 0.1, Z1m, color="tab:blue", label="Z1", marker=".", linestyle="none")
plt.plot(np.zeros(len(Z2m)), Z2m, color="tab:orange", label="Z2", marker=".", linestyle="none")
plt.plot(np.zeros(len(Z3m)) - 0.1, Z3m, color="tab:green", label="Z3", marker=".", linestyle="none")
plt.plot(np.ones(len(Z1p)) + 0.1, Z1p, color="tab:blue", marker=".", linestyle="none")
plt.plot(np.ones(len(Z2p)), Z2p, color="tab:orange", marker=".", linestyle="none")
plt.plot(np.ones(len(Z3p)) - 0.1, Z3p, color="tab:green", marker=".", linestyle="none")
plt.errorbar(0 + 0.1, np.nanmean(Z1m), np.nanstd(Z1m, ddof=1), color="tab:blue", capsize=3, marker="_")
plt.errorbar(1 + 0.1, np.nanmean(Z1p), np.nanstd(Z1p, ddof=1), color="tab:blue", capsize=3, marker="_")
plt.errorbar(0, np.nanmean(Z2m), np.nanstd(Z2m, ddof=1), color="tab:orange", capsize=3, marker="_")
plt.errorbar(1, np.nanmean(Z2p), np.nanstd(Z2p, ddof=1), color="tab:orange", capsize=3, marker="_")
plt.errorbar(0 - 0.1, np.nanmean(Z3m), np.nanstd(Z3m, ddof=1), color="tab:green", capsize=3, marker="_")
plt.errorbar(1 - 0.1, np.nanmean(Z3p), np.nanstd(Z3p, ddof=1), color="tab:green", capsize=3, marker="_")
plt.xticks([0,1], ["-", "+"])
plt.xlabel("direction")
plt.ylabel(r"time [s] for distance of $\approx 2$ mm")
plt.legend()
plt.show()
if __name__ == "__main__":
main()
\ No newline at end of file
# -*- coding: utf-8 -*-
"""
Created on Fri Jan 26 13:18:01 2024
@author: admin
"""
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.pyplot as plt
import numpy as np
import sys
from datetime import datetime
from dateutil import parser
def main():
file = "C:\\MaskAligner\\Matlab\\test20.12.23\\Data_25-Jan-2024_10-16-48.csv"
if("--file" in sys.argv or "-f" in sys.argv):
for i in range(len(sys.argv)):
if("--file" in sys.argv[i] or "-f" == sys.argv[i]):
try:
file = sys.argv[i+1]
except:
print("No file or incorrect file specification.")
times = []
times_sec = []
pressures = []
with open(file, "r") as read_file:
lines = read_file.readlines()
#pressures = np.zeros(len(lines) - 1)
for i in range(1, len(lines)):
temp = lines[i].split(",")
if(i == 1):
for j in range(len(temp) - 3):
pressures.append(np.zeros(len(lines) - 1))
t = parser.parse(temp[0].replace(" ", " "))
times.append(t)
times_sec.append(temp[1])
for j in range(len(temp) - 3):
pressures[j][i-1] = float(temp[j+3])
for pressure in pressures:
plt.plot(times, pressure)
plt.ylabel("pressure [mbar]")
plt.yscale("log")
plt.show()
if __name__ == "__main__":
main()
\ No newline at end of file
@echo off
cd /D "%~dp0"
for %%a in (%*) do py .\PlotPressurePlortMatlabScript.py --file %%a
pause
\ No newline at end of file
# -*- coding: utf-8 -*-
"""
Created on Thu Nov 30 15:07:58 2023
@author: admin
"""
import time
import serial
import numpy as np
import matplotlib.pyplot as plt
def reading():
ser = serial.Serial('COM7', 19200, timeout=0, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, bytesize=8)
read_command = b"RFM%d\r" % 1
ser.write(read_command)
time.sleep(.03)
pressure = ''
while ser.inWaiting() > 0:
pressure += ser.read(1).decode('ascii')
print(pressure)
if pressure[0] == '0':
return float(pressure)
else:
return float('nan')
ser.close()
def main():
for i in range(0, 100):
pressure = []
temp_press = reading()
pressure.append(temp_press)
plt.plot(pressure)
plt.pause(0.05)
plt.show()
if __name__ == "__main__":
main()
\ No newline at end of file
No preview for this file type
File added
PythonScripts/Plots/ApproachCurves/ApproachCurve21_11_23_ToFullContact_editForPres.png

457 KiB

No preview for this file type
PythonScripts/Plots/ApproachCurves/ApproachCurveCurrent1.png

440 KiB | W: | H:

PythonScripts/Plots/ApproachCurves/ApproachCurveCurrent1.png

467 KiB | W: | H:

PythonScripts/Plots/ApproachCurves/ApproachCurveCurrent1.png
PythonScripts/Plots/ApproachCurves/ApproachCurveCurrent1.png
PythonScripts/Plots/ApproachCurves/ApproachCurveCurrent1.png
PythonScripts/Plots/ApproachCurves/ApproachCurveCurrent1.png
  • 2-up
  • Swipe
  • Onion skin
No preview for this file type
File added
PythonScripts/Plots/ApproachCurves/ApproachCurveCurrent3-cop.png

776 KiB

File added
PythonScripts/Plots/ApproachCurves/ApproachCurveCurrent4.png

505 KiB

No preview for this file type
No preview for this file type
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment