def __run__(self, length, fname=None): if not fname: fname = self.fname self.__save_hv_state__() readout(self.connection.sis_address(), 3333, fname, range(0,16), length, self.stderr, self.__info__ ) self.run_num += 1 myargv = ctypes.c_char_p*2 argv = myargv('python', fname) libpath = os.path.abspath( os.path.join( os.path.dirname(__file__), '../lib/libscout.so')) proc = Process(target=ctypes.CDLL(libpath).main, args=(2,argv)) proc.start() return proc
def graphit(FILENAME, sheet_no, P_col, y_col, label, P_unit = None): """ Plots graph for the given diaphragm from readings in given file FILENAME: File to be read sheet_no: Sheet number to be read from P_col: Pressure column to be read y_col: Deflection column to be read label: Legend for the plot """ P = np.array(readout.readout(FILENAME, sheet_no, P_col)) y = np.array(readout.readout(FILENAME, sheet_no, y_col)) if P_unit == "bar": #convert pressure from bar to Pa P = P * 1e5 else: #convert pressure from Kg/cm^2 to Pa P = np.array(writeout.kgcm2toPa(P)) graph(P * 1e-5, y, "Pressure[bar]", "Deflection[mm]", label, 'o')
def graphit(FILENAME, sheet_no, P_col, y_col, label, P_unit=None): """ Plots graph for the given diaphragm from readings in given file FILENAME: File to be read sheet_no: Sheet number to be read from P_col: Pressure column to be read y_col: Deflection column to be read label: Legend for the plot """ P = np.array(readout.readout(FILENAME, sheet_no, P_col)) y = np.array(readout.readout(FILENAME, sheet_no, y_col)) if P_unit == "bar": #convert pressure from bar to Pa P = P * 1e5 else: #convert pressure from Kg/cm^2 to Pa P = np.array(writeout.kgcm2toPa(P)) graph(P * 1e-5, y, "Pressure[bar]", "Deflection[mm]", label, 'o')
def func_s(adj, theta): W = theta.lea_matrix A = theta.para_a b = theta.para_b N, D = adj.shape[0], A.size x = np.zeros((N,D)) for i in range(N): x[i][1] = 1 return np.dot(A, readout(adj, W, x, T)) + b
def relativeErr(theory, expt): """ Determines the relative error between the theoretical and experimental values theory: Theoretical values numpy array expt: Experimental values numpy array """ return np.divide(np.subtract(theory, expt), theory) * 1e2 if __name__ == "__main__": plt.close('all') P = np.array( readout.readout("../expt/Pvsy/curvefitdata_single_upto3kgcm2.xls", 0, 0)) * 9.81e4 y = np.array( readout.readout("../expt/Pvsy/curvefitdata_single_upto3kgcm2.xls", 0, 1)) plt.plot(P, y, 'o') plt.title("Pressure vs deflection") c1, c2 = curveFit(func, y * 1e-3, P, diaphNB40_50) #calculating and plotting percent relative error Pmax = 4e5 P = np.arange(0, Pmax, Pmax / 1000) y_analytical = np.array(membrane.detDeflectTensile(P, diaphNB40_50)) y_curvefit = funcinv(P, diaphNB40_50, c1, c2) error = relativeErr(y_analytical, y_curvefit) plt.figure() membrane.graph(
F_curveFit = np.linspace(0, max(F_f), num = 100, endpoint = True) y_curveFit = funcSLinear(F_curveFit, popt_Fvsy[0]) stiffness_Fvsy = 1.0 / popt_Fvsy[0] plt.figure("SRV bellows Fvsy characteristics") graph(F_f, y_f, "Force[N]", "Deflection[mm]", "Force vs Deflection at Suaan", '-o') graph(F_curveFit, y_curveFit, "Force[N]", "Deflection[mm]","Fitted curve k=" + str(stiffness_Fvsy) + " N/mm") plt.figure() graphit("../../brv/bellow_Pvsdeflection_PT100.xls", 0,0, 3, "Trial1 Increasing", P_unit="bar") graphit("../../brv/bellow_Pvsdeflection_PT100.xls", 1,0, 3, "Trial1 Decreasing", P_unit="bar") graphit("../../brv/bellow_Pvsdeflection_PT100.xls", 2,0, 3, "Trial2 Increasing", P_unit="bar") graphit("../../brv/bellow_Pvsdeflection_PT100.xls", 3,0, 3, "Trial1 Decreasing", P_unit="bar") graphit("../../brv/bellow_Pvsdeflection_PT100.xls", 4,0, 3, "Trial3 Increasing", P_unit="bar") P = [] y = [] for i in range(5): P.extend(readout.readout("../../brv/bellow_Pvsdeflection_PT100.xls", i, 0)) y.extend(readout.readout("../../brv/bellow_Pvsdeflection_PT100.xls", i, 3)) P = np.array(P) mat = np.zeros((len(P), 2)) mat[:,0] = P mat[:,1] = y deleteRows = [] for i in range(len(P)): if mat[i,1] >= 9: deleteRows.append(i) mat = np.delete(mat, deleteRows, axis = 0) mat = mat[np.argsort(mat[:,0])] popt_Pvsy, pcov_Pvsy = curve_fit(funcSLinear, mat[:,0], mat[:,1]) P_curveFit = np.linspace(0, mat[-1,0], num = 100, endpoint = True) y_curveFit = funcSLinear(P_curveFit, popt_Pvsy[0]) stiffness_Pvsy = 1.0 / popt_Pvsy[0]
3, 0, 3, "Trial1 Decreasing", P_unit="bar") graphit("../../brv/bellow_Pvsdeflection_PT100.xls", 4, 0, 3, "Trial3 Increasing", P_unit="bar") P = [] y = [] for i in range(5): P.extend( readout.readout("../../brv/bellow_Pvsdeflection_PT100.xls", i, 0)) y.extend( readout.readout("../../brv/bellow_Pvsdeflection_PT100.xls", i, 3)) P = np.array(P) mat = np.zeros((len(P), 2)) mat[:, 0] = P mat[:, 1] = y deleteRows = [] for i in range(len(P)): if mat[i, 1] >= 9: deleteRows.append(i) mat = np.delete(mat, deleteRows, axis=0) mat = mat[np.argsort(mat[:, 0])] popt_Pvsy, pcov_Pvsy = curve_fit(funcSLinear, mat[:, 0], mat[:, 1]) P_curveFit = np.linspace(0, mat[-1, 0], num=100, endpoint=True) y_curveFit = funcSLinear(P_curveFit, popt_Pvsy[0])
gsc02.move(angles[i] * DEG2STEP, 0) waitUntilRotationIsFinished(angles[i] * DEG2STEP) status = gsc02.getStatus() current_pos = int(status.split(b',')[0].replace(b' ', b'')) ## gsc02.initializeOrigin(1,0) #imitate power off print("Stage power off") PSupply.PS_init(0., 6, 1.5, 0) time.sleep(1) print("\nSetting up the FG:") time.sleep(1) FGenerator.initialize(wavelength) time.sleep(1) print("Reading PMT") readout.readout(angles[i], 50, "sipm_nocoating/monitor_fwd") time.sleep(1) print("\nSetting up the FG:") time.sleep(1) FGenerator_target.initialize(wavelength) time.sleep(1) print("Reading SiPM") takedata.takedata("sipm_nocoating/3500_500_4_%ddeg_fwd.fits" % (angles[i]), 40000, target_runid, 900) target_runid = 1 print("Finished reading") print("Stage power on") time.sleep(1) PSupply.PS_init(24., 6, 1.5, 0) time.sleep(1) gsc02.setSpeed(1, 50, 1000, 1, 50, 1000, 1)
angles[i]) gsc02.setSpeed(1, 50, 1000, 1, 50, 1000, 1) time.sleep(1) gsc02.move(angles[i] * DEG2STEP, 0) waitUntilRotationIsFinished(angles[i] * DEG2STEP) status = gsc02.getStatus() current_pos = int(status.split(b',')[0].replace(b' ', b'')) ## gsc02.initializeOrigin(1,0) #imitate power off print("Stage power off") PSupply.PS_init(0., 6, 1.5, 0) time.sleep(1) print("Reading PMT") readout.readout(angles[i], 50, "pmt/fwd") print("Stage power on") time.sleep(1) PSupply.PS_init(24., 6, 1.5, 0) time.sleep(1) gsc02.setSpeed(1, 50, 1000, 1, 50, 1000, 1) time.sleep(1) gsc02.move(-current_pos, 0) waitUntilRotationIsFinished(-current_pos) gsc02.initializeOrigin(1, 0) print("waiting 3 seconds in 0deg, can interrupt now if needed") print(".........") time.sleep(1) print("......") time.sleep(1)
print "\nUsing curve fitting to experimental data\nc1 = " + str(popt[0]) + "\nc2 = " + str(popt[1]) return popt def relativeErr(theory, expt): """ Determines the relative error between the theoretical and experimental values theory: Theoretical values numpy array expt: Experimental values numpy array """ return np.divide(np.subtract(theory, expt), theory) * 1e2 if __name__ == "__main__": plt.close('all') P = np.array(readout.readout("../expt/Pvsy/curvefitdata_single_upto3kgcm2.xls", 0, 0)) * 9.81e4 y = np.array(readout.readout("../expt/Pvsy/curvefitdata_single_upto3kgcm2.xls", 0, 1)) plt.plot(P, y, 'o') plt.title("Pressure vs deflection") c1, c2= curveFit(func, y * 1e-3, P, diaphNB40_50) #calculating and plotting percent relative error Pmax = 4e5 P = np.arange(0, Pmax, Pmax/1000) y_analytical = np.array(membrane.detDeflectTensile(P, diaphNB40_50)) y_curvefit = funcinv(P, diaphNB40_50, c1, c2) error = relativeErr(y_analytical, y_curvefit) plt.figure() membrane.graph(P, error, "Pressure[Pa]", "Percent relative error", "Percent relative error between theoretical and analytical") plt.grid() plt.show()
print("\n\n\t=====Starting the cycle for angle: %d degrees fwd=====" % angles[i]) gsc02.setSpeed(1, 50, 1000, 1, 50, 1000, 1) time.sleep(1) gsc02.move(angles[i] * DEG2STEP, 0) waitUntilRotationIsFinished(angles[i] * DEG2STEP) status = gsc02.getStatus() current_pos = int(status.split(b',')[0].replace(b' ', b'')) ## gsc02.initializeOrigin(1,0) #imitate power off print("Stage power off") PSupply.PS_init(0., 6, 1.5, 0) time.sleep(1) print("Reading PMT") readout.readout(angles[i], nsamples, "sipm_nocoating/monitor_fwd") time.sleep(1) print("Reading SiPM") takedata.takedata("sipm_nocoating/2500_0_4_%ddeg_fwd.fits" % (angles[i]), 40000, target_runid, 900) target_runid = 1 print("Finished reading") print("Stage power on") time.sleep(1) PSupply.PS_init(24., 6, 1.5, 0) time.sleep(1) gsc02.setSpeed(1, 50, 1000, 1, 50, 1000, 1) time.sleep(1) gsc02.move(-current_pos, 0) waitUntilRotationIsFinished(-current_pos) gsc02.initializeOrigin(1, 0)