chi_squared_new = chi_squared(v1_45.independent_variables_array, v1_45.relative_intensities, v1_45.relative_std, fit_params_new, average_angle=0, precision=-1) plot_runs(v1_45, title="Sample 1 (LUX), 178nm, Vacuum, 45 degrees", label="data", log=True) plot_TSTR_fit(45., 1., fit_params_old, label="fitted with old fitter", color="b", average_angle=0, precision=-1, fit_text="Old Fit, chi^2=" + str(round(chi_squared_old, 4)) + ": ", fit_text_offset=0.05) plot_TSTR_fit(45., 1., fit_params_new, label="fitted with new fitter", color="g", average_angle=0, precision=-1, fit_text="New Fit, chi^2=" + str(round(chi_squared_new, 4)) + ": ") plt.show()
1.7])) # theta_r shift range is +5 to -10 deg #fit_params=fit_params_simple[ii] # fit_params=[.051,2.47,.076,1] print("Fit parameters (rho_L, n, gamma): " + str(fit_params)) # Plot BRIDF model from fits n_LXe_178 = 1.69 sigma_theta_i = -1 precision = -1 average_angle = -1 plot_TSTR_fit(angles[ii], n_LXe_178, fit_params, color=colors[ii], average_angle=average_angle, precision=precision, sigma_theta_i=sigma_theta_i, include_fit_text=False) chi_sq = chi_squared(run_data[0], run_data[1], run_data[2], fit_params, average_angle=average_angle, precision=precision, sigma_theta_i=sigma_theta_i) print("Chi squared from fit for angle={0} deg: {1:.3f}".format( angles[ii], chi_sq)) plt.text( 0.02,
n=n_LXe plt.xlim(0,85) plt.ylim(1e-3,1e2) plt.yscale("log") #colors=["r","g","b","m","c","y"] colors=[plt.cm.plasma(i) for i in np.linspace(0.2,0.90,len(runs))] # colors=[cmap(i) for i in np.linspace(0,1,len(runs))] label_x=[0.63,0.93,0.88,0.85,0.9,0.88] # Positions for s9 low_p label_y=[0.27,0.31,0.45,0.63,0.75,0.88] #label_x=[0.25,0.45,0.55,0.65,0.75,0.85] # Positions for s9 in vacuum #label_y=[0.6,0.62,0.65,0.7,0.76,0.85] angle_labels=[r"$\theta_i=30^{\circ}$",r"$45^{\circ}$",r"$52^{\circ}$",r"$60^{\circ}$",r"$67^{\circ}$",r"$75^{\circ}$"] for ii in range(len(angle_shifts)): plot_TSTR_fit(angle_shifts[ii], n, fit_params, color=colors[ii], label=None, average_angle=average_angle, precision=precision, sigma_theta_i=sigma_theta_i, include_fit_text=False) plt.text(label_x[ii], label_y[ii], angle_labels[ii],transform=plt.gca().transAxes,fontsize=13,color=colors[ii]) # Set x-axis tick marks to every 10 deg loc = matplotlib.ticker.MultipleLocator(base=10.0) # this locator puts ticks at regular intervals ax.xaxis.set_major_locator(loc) # Add grid lines plt.grid(b=True,which='major',color="lightgray",linestyle='--') # plt.grid(b=True,which='major',axis='x',color="lightgray",linestyle=':') # plt.grid(b=True,which='both',axis='y',color="lightgray",linestyle=':') #plt.tight_layout() t2=time.time()
# fit_params_lowp_215=[1.011,1.563,0.118] # 2.15 solid angle factor print("Fit parameters (rho_L, n, gamma): "+str(fit_params)) #print("Fit angle: "+str(fit_ang)) t1=time.time() print("Fitting time: {0}".format(t1-t0)) # phi_r_list = np.linspace(-np.pi,np.pi,10) # BRIDF_test_list = [BRIDF(52., phi_r, 0., 1.69, 0.5, fit_params) for phi_r in phi_r_list] # print("BRIDF at normal incidence and viewing: ",BRIDF_test_list) # Plot BRIDF model from fits n_LXe_178 = 1.69 sigma_theta_i=2. precision=0.25 average_angle=4 #plot_TSTR_fit(20., n_LXe_178, fit_params, color="r", average_angle=average_angle, precision=precision, sigma_theta_i=sigma_theta_i) plot_TSTR_fit(30., n_LXe_178, fit_params, color="r", average_angle=average_angle, precision=precision, sigma_theta_i=sigma_theta_i) plot_TSTR_fit(45., n_LXe_178, fit_params, color="g", average_angle=average_angle, precision=precision, sigma_theta_i=sigma_theta_i) plot_TSTR_fit(52., n_LXe_178, fit_params, color="b", average_angle=average_angle, precision=precision, sigma_theta_i=sigma_theta_i) plot_TSTR_fit(60., n_LXe_178, fit_params, color="m", average_angle=average_angle, precision=precision, sigma_theta_i=sigma_theta_i) #independent_variables_array = get_independent_variables_and_relative_intensities(runs)[0] #independent_variables_array = [list+[sigma_theta_i,precision,average_angle] for list in independent_variables_array] #print([list[2] for list in independent_variables_array]) #theta_r_list = [list[0] for list in independent_variables_array] #plt.plot(theta_r_list,fitter(independent_variables_array, np.log(fit_params[0]),np.log(fit_params[1]-1),np.log(fit_params[2])),color="y") plot_TSTR_fit(67., n_LXe_178, fit_params, color="c", average_angle=average_angle, precision=precision, sigma_theta_i=sigma_theta_i) plot_TSTR_fit(75., n_LXe_178, fit_params, color="y", average_angle=average_angle, precision=precision, sigma_theta_i=sigma_theta_i) # plot_TSTR_fit(75., n_LXe_178, fit_params, color="y", average_angle=average_angle, precision=precision, sigma_theta_i=sigma_theta_i,phi_r=5) # plot_TSTR_fit(75., n_LXe_178, fit_params, color="y", average_angle=average_angle, precision=precision, sigma_theta_i=sigma_theta_i,phi_r=10) #plt.text(0.1,0.1,r"Fit: $\rho_L$={0:.3f}, n={1:.2f}, $\gamma$={2:.3f}".format(*fit_params),transform=plt.gca().transAxes,fontsize=13) #plt.text(0.1,0.2,r"Fit: $\rho_L$={0:.3f}, n={1:.2f}, $\gamma$={2:.3f}, K={3:.3f}".format(*fit_params),transform=plt.gca().transAxes,fontsize=13) t2=time.time()
fit_params = fit_parameters( get_independent_variables_and_relative_intensities(v1_30), p0=[0.24, 1.2, .1, 5.0], average_angle=4., precision=0.25, use_errs=True, use_spike=True) plot_runs(v1_30, title="Sample 1 (LUX), 178nm, Vacuum, 30 degrees", label="data", log=True) plot_TSTR_fit(30., 1., fit_params, label="fitted", color="k", average_angle=4., precision=0.25) print("done with 30") fit_params = fit_parameters( get_independent_variables_and_relative_intensities(v1_45), p0=[0.24, 1.2, .1, 5.0], average_angle=4., precision=0.25, use_errs=True, use_spike=True) plot_runs(v1_45, title="Sample 1 (LUX), 178nm, Vacuum, 45 degrees", label="data",
m18path = "vuv_height_comparison_and_first_data/M18 turn/center of sample/" m1830 = Run(m18path + "2018_08_30__15_16_18.txt") m1845 = Run(m18path + "2018_08_30__15_22_02.txt") m1860 = Run(m18path + "2018_08_30__15_29_09.txt") m1875 = Run(m18path + "2018_08_30__15_35_27.txt") runs = [m1830, m1845, m1860, m1875] plot_runs(runs, title="M18 turn, 175nm", log=True, labels=["30 degrees", "45 degrees", "60 degrees", "75 degrees"]) fit_params = fit_parameters( get_independent_variables_and_relative_intensities(runs)) plot_TSTR_fit(30., 1., fit_params, label="fitted", color="k") plot_TSTR_fit(45., 1., fit_params, color="k") plot_TSTR_fit(60., 1., fit_params, color="k") plot_TSTR_fit(75., 1., fit_params, color="k") plt.figure() x = [30, 45, 60, 75] y_diffuse = [reflectance_diffuse(theta, 1., 0.5, fit_params) for theta in x] y_specular = [reflectance_specular(theta, 1., 0.5, fit_params) for theta in x] y_total = [y_diffuse[i] + y_specular[i] for i in range(len(y_specular))] plt.plot(x, y_diffuse, label="diffuse") plt.plot(x, y_specular, label="specular") plt.plot(x, y_total, label="total")
import matplotlib.pyplot as plt import numpy as np from file_reader import Run, get_independent_variables_and_relative_intensities from plotting import plot_runs, plot_TSTR_fit from TSTR_fit_new import fit_parameters, fit_parameters_and_angle, BRIDF_plotter, reflectance_diffuse, reflectance_specular, BRIDF import time # Plots BRIDF at a few angles w/ and w/o specular spike, as well as hemispherical reflectances # Used for testing effects of the specular spike model params fit_params = [.74, 1.45, 0.049] # From Coimbra fit fit_params_spec = [.74, 1.45, 0.049, 1.7] # From Coimbra fit plot_TSTR_fit(45., 1., fit_params, color="k", label="no spike", average_angle=4., precision=0.25) plot_TSTR_fit(65., 1., fit_params, color="k", average_angle=4., precision=0.25) plot_TSTR_fit(80., 1., fit_params, color="k", average_angle=4., precision=0.25) plot_TSTR_fit(45., 1., fit_params_spec, color="r", label="with spike", average_angle=4., precision=0.25) plot_TSTR_fit(65., 1., fit_params_spec,
""" fit_params_30 = [0.99,1.54,.15] fit_params_45 = [0.99,1.54,.15] fit_params_52 = [0.99,1.54,.15] fit_params_60 = [0.99,1.54,.15] fit_params_67 = [0.99,1.54,.15] fit_params_75 = [0.99,1.54,.15] """ t1 = time.time() print("Fitting time: {0}".format(t1 - t0)) plot_TSTR_fit(30, n_LXe_178, fit_params_all, color="r", average_angle=average_angle, precision=precision, sigma_theta_i=sigma_theta_i, include_fit_text=True) plot_TSTR_fit(45, n_LXe_178, fit_params_all, color="g", average_angle=average_angle, precision=precision, sigma_theta_i=sigma_theta_i, include_fit_text=False) plot_TSTR_fit(52, n_LXe_178, fit_params_all, color="b",
#labels=["30 degrees", "45 degrees", "52 degrees", "60 degrees", "67 degrees", "75 degrees"] labels = ["30 degrees", "45 degrees", "60 degrees", "75 degrees"] # Plot BRIDF data sample_name = "Sample 1 (LUX)" #plot_runs(runs, title=sample_name+", 178nm", log=True, labels=labels, errorbars=True) #plt.show() # In a loop: ask for input params, plot model overlaid on data get_input = True params = [0.24, 1.27, 0.1, 5.0, 0.1, 0.5] plot_TSTR_fit(30., 1.69, params, label="total", color="k", average_angle=4., precision=0.25, sigma_theta_i=2.) # these parts of the plot do not currently average over the aperture theta_r_in_degrees_array = np.linspace(0., 85., 100) #plt.plot(theta_r_in_degrees_array, BRIDF_plotter(theta_r_in_degrees_array, 0., 30., 1.69, 0.5, params[:5], average_angle=4, precision=0.25, sigma_theta_i=2.), label="total, averaged over aperture") plt.plot(theta_r_in_degrees_array, BRIDF_plotter(theta_r_in_degrees_array, 0., 30., 1.69, 0.5, params[:5]), label="total, not averaged over aperture") plt.plot(theta_r_in_degrees_array, BRIDF_specular_plotter(theta_r_in_degrees_array, 0., 30., 1.69, 0.5, params[:5]), label="specular")
plot_runs(runs, title=sample_name+", 175 nm", log=True, labels=labels, errorbars=True,legend_loc=6) t0=time.time() # Fit data fit_params = fit_parameters(get_independent_variables_and_relative_intensities(runs),p0=[0.75,1.57,0.2],average_angle=4., precision=-1,use_errs=True,use_spike=False) #fit_params_ang = fit_parameters_and_angle(get_independent_variables_and_relative_intensities(runs),average_angle=4.) #fit_ang = fit_params_ang[0] #fit_params = fit_params_ang[1:] print("Fit parameters (rho_L, n, gamma): "+str(fit_params)) #print("Fit angle: "+str(fit_ang)) t1=time.time() print("Fitting time: {0}".format(t1-t0)) # Plot BRIDF model from fits #plot_TSTR_fit(8., 1., fit_params, label="fitted", color="k", average_angle=4., precision=-1) plot_TSTR_fit(33., 1., fit_params, color="k", average_angle=4., precision=-1) plot_TSTR_fit(45., 1., fit_params, color="k", average_angle=4., precision=-1) plot_TSTR_fit(61., 1., fit_params, color="k", average_angle=4., precision=-1) plot_TSTR_fit(76, 1., fit_params, color="k", average_angle=4., precision=-1) #plt.text(0.1,0.1,r"Fit: $\rho_L$={0:.3f}, n={1:.2f}, $\gamma$={2:.3f}".format(*fit_params),transform=plt.gca().transAxes,fontsize=13) #plt.text(0.1,0.2,r"Fit: $\rho_L$={0:.3f}, n={1:.2f}, $\gamma$={2:.3f}, K={3:.3f}".format(*fit_params),transform=plt.gca().transAxes,fontsize=13) t2=time.time() print("Plotting time: {0}".format(t2-t1)) # Now calculate hemispherical reflectance # plt.figure() # # Different incident angles to calculate for # x = [8,30,45,60]#[30, 45, 60, 75]#[0,10,20,30, 45, 55, 60, 65, 70, 75, 80, 85]# # y_diffuse = [reflectance_diffuse(theta, 1., 0.5, fit_params) for theta in x]
#plt.figure(fig_num) plot_runs(runs, title=sample_name + ", 175 nm", log=True, labels=labels, errorbars=True) # Trying setting incident angles by hand, for better fits to specular spike n_LXe_178 = 1.69 n = 1.0 #n_LXe_178 #sigma_theta_i=2.0 precision = 0.25 average_angle = 4. plot_TSTR_fit(25., n, fit_params, label="fitted", color="r", average_angle=average_angle, precision=precision, sigma_theta_i=sigma_theta_i) plot_TSTR_fit(40., n, fit_params, color="g", average_angle=average_angle, precision=precision, sigma_theta_i=sigma_theta_i) plot_TSTR_fit(48., n, fit_params, color="b", average_angle=average_angle,