limits = np.arange(0.90, 0.99, 0.01) avers = [] parms = [[], []] for lim in limits: position = np.argwhere(data >= lim) pos_zero = np.argwhere(data >= 0) pos_tp = int(position[-1]) + 1 pos_zero = int(pos_zero[-1]) summ = [] parm1, parm2 = cv(exp_mod, time[0:pos_tp], data[0:pos_tp]) sig = parm1 parm3, parm4 = cv(parab_mod, time[pos_tp:pos_zero], data[pos_tp:pos_zero]) te = parm1 + parm3 parm2 = np.sqrt(np.diag(parm2)) aver = [parm2[0], parm2[1]] avers.append(parm2[0] * 2 + parm2[1]) parms[0].append(parm1) parms[1].append(parm3) #position = int(np.argwhere(avers == np.amin(avers)))
return modelo1 def modelo2(x, A, B, C, mu, sigma): modelo2 = recta(x, A, B) - lorentz(x, C, mu, sigma) return modelo2 # Main Setup x = sp.loadtxt('espectro.dat')[:, 0] # long de onda y = sp.loadtxt('espectro.dat')[:, 1] # Flujo sigma = sp.std(x) mu = sp.mean(x) A, B = sp.polyfit(x, y, 1) C = 1 * 10**(-16) # valor mas pequeno de y a1, b1 = cv(modelo1, x, y, [A, B, C, mu, sigma]) a2, b2 = cv(modelo2, x, y, [A, B, C, mu, sigma]) modelo1v = modelo1(x, *a1) modelo2v = modelo2(x, *a2) # Grafico modelo 1 fig1 = plt.figure(1) fig1.clf() plt.plot(x, y, 'b-') plt.plot(x, modelo1v, 'r-') plt.xlabel(r'Longitud de onda [$\AA$]') plt.ylabel(r'Flujo [$erg s^{-1} Hz^{-1}cm^{-2}$]') plt.title('Curva y modelamiento de Espectro ' + 'por Gaussiana') plt.grid(True)
import numpy as np import matplotlib.pyplot as plt from scipy.optimize import curve_fit as cv #Import the data from the Text File data = np.genfromtxt("Draft4.txt", skip_header=3, delimiter="\t") print(data) time = data[:, 0] V_out = data[:, 1] def func(x, b): #we know V0 is o.5 so only have program find b in the function return 0.5 * np.exp(-b * x) popt1, pcov1 = cv(func, time, V_out) print(popt1) bVal1 = str(round(popt1[0], 3)) eq1 = " 0.5 * EXP(-" + bVal1 + "x)" plt.xlabel("Time / s") plt.ylabel("Voltage / V") plt.plot(time, V_out, "r", label="V_out, " + eq1) plt.title("Time against Voltage at Different Parts of the Circuit") plt.legend()
limits = np.arange(0.2, 1, 0.01) avers = [] sizes = [[], []] alphas = [] limas = [[], []] for lim in limits: #get cond_cool and rad_cool position = np.argwhere(data >= lim) pos_zero = np.argwhere(data >= 0) pos_tp = int(position[-1]) + 1 parm1, parm2 = cv(cond_cool, time[0:pos_tp], data[0:pos_tp], bounds=(0, 20)) parm3, parm4 = cv(rad_cool, time[pos_tp:-1], data[pos_tp:-1], bounds=(0, 20)) size_c = parm1 size_r = parm3[1] alpha = parm3[0] sizes[0].append(size_c) sizes[1].append(size_r) alphas.append(alpha) time2 = np.arange(0, 15, 0.01) for lim_timea in time2[2:-1]:
data = data[maximum: -1] time = time[maximum: -1] limits = np.arange(0.1, 0.99, 0.01) avers = [] parms = [[],[]] for lim in limits: position = np.argwhere(data >= lim) pos_zero = np.argwhere(data >= 0) pos_tp = int(position[-1]) + 1 pos_zero = int(pos_zero[-1]) parm1, parm2 = cv(fl.A_exp, time[0 : pos_tp], data[0 : pos_tp]) sig = parm1[0] parm3, parm4 = cv(fl.A_parab, time[pos_tp : pos_zero], data[pos_tp : pos_zero]) alpha = parm3[0] parms[0].append(sig) parms[1].append(alpha) aver = 0.0 ind = 0 for i in time: aver += (fl.A_full(i, parm1[0], parm3[0], lim) - data[ind])**2 ind += 1 aver = np.float(np.sqrt(aver / len(time))) avers.append(aver)
def modelo2(x, A, B, C, mu, sigma): modelo2 = recta(x, A, B) - lorentz(x, C, mu, sigma) return modelo2 # Main Setup x = sp.loadtxt('espectro.dat')[:, 0] # long de onda y = sp.loadtxt('espectro.dat')[:, 1] # Flujo sigma = sp.std(x) mu = sp.mean(x) A, B = sp.polyfit(x, y, 1) C = 1 * 10**(-16) # valor mas pequeno de y a1, b1 = cv(modelo1, x, y, [A, B, C, mu, sigma]) a2, b2 = cv(modelo2, x, y, [A, B, C, mu, sigma]) modelo1v = modelo1(x, *a1) modelo2v = modelo2(x, *a2) # Grafico modelo 1 fig1 = plt.figure(1) fig1.clf() plt.plot(x, y, 'b-') plt.plot(x, modelo1v, 'r-') plt.xlabel(r'Longitud de onda [$\AA$]') plt.ylabel(r'Flujo [$erg s^{-1} Hz^{-1}cm^{-2}$]') plt.title('Curva y modelamiento de Espectro ' + 'por Gaussiana') plt.grid(True) fig1.savefig('gauss')