def MBdist( n, e_photon, thick ): # n: particle number, loct: start point(x-x0), scale: sigma, wl: wavelength,thick: thickness of the cathode assert e_photon > bandgap if e_photon - bandgap - 0.8 <= 0: scale = e_photon - bandgap loct = 0 else: scale = 0.8 loct = e_photon - bandgap - scale data = maxwell.rvs(loc=loct, scale=scale, size=n) data_ene = np.array(data) params = maxwell.fit(data, floc=0) data_v = np.sqrt(2 * data_ene * ec / me) * 10**9 p2D = [] wl = ((19.82 - 27.95 * e_photon + 11.15 * e_photon**2) * 10**-3)**-1 pens = expon.rvs(loc=0, scale=wl, size=n) penss = filter(lambda x: x <= thick, pens) params_exp = expon.fit(pens, floc=0) i = 0 for n in range(len(penss)): phi = random.uniform(0, 2 * math.pi) # initial angular poy = random.uniform(-1 * 10**6, 1 * 10**6) # initial y direction position p2D.append([ penss[i], poy, data_v[i] * math.cos(phi), data_v[i] * math.sin(phi), data_v[i], data[i] ]) #p2D: (z,y,vz,vy,v,ene) i += 1 p2D = np.array(p2D) return params, p2D, penss, params_exp
def plot_hist_and_fit_gauss(data_list, binno=60, normed=1, facecolor="green", linecolor='r--', alpha=0.5): """ return (mu, sigma) """ # fit the data by maxwell-boltzmann distribution # mawell.fit returns shape, loc, scale : tuple of floats # MLEs for any shape statistics, followed by those for location and # scale. params = maxwell.fit(data_list) print params # plot the histogram of the data #(n, bins, patches) = plt.hist(data_list, binno, range=(0, 50), normed=normed, facecolor=facecolor, alpha=alpha) (n, bins, patches) = plt.hist(data_list, binno, normed=normed, facecolor=facecolor, alpha=alpha) x = np.linspace(0, 25, 100) # add a 'best fit' line plt.plot(x, maxwell.pdf(x, *params), linecolor, lw=3) print get_max_likelihood(data_list, params[0], params[1]) return params
def quiver_desired_velocity(crStats\ ,further_conditioning = None ,grid_x=40,grid_y=40,small_incr=.00001\ ,qty='vel' ,spec_type='gt' ,img_format='png' ,**kw): x_class_v,y_class_v,u_means,v_means,u_delta,v_delta,u_all,v_all =\ sub_eval_desired_velocity_qtys(crStats ,further_conditioning\ ,grid_x,grid_y,small_incr\ ,qty\ ,spec_type) plt.figure() plt.hist2d(u_delta,v_delta,**hist2d_param) plt.title('Overall noise distribution') plt.savefig(PATH_PREFIX + 'total_noise_%s_%s.%s' % (qty,spec_type,img_format)) rv = maxwell() speed_delta = np.sqrt(np.asarray(u_delta)**2 + np.asarray(v_delta)**2) loc,scale = maxwell.fit(speed_delta) plt.figure() plt.hist(speed_delta,**hist_param_noLog) x = np.linspace(0,2,100) plt.plot(x,maxwell.pdf(x,scale=scale,loc=loc)) plt.title('Overall abs noise distribution') plt.savefig(PATH_PREFIX + 'maxwellian_noise_%s_%s.%s' % (qty,spec_type,img_format)) temperature = np.sqrt( np.asarray([np.var(us) for us in u_all]) + np.asarray([np.var(vs) for vs in v_all]) ) speed = [np.mean(np.sqrt(np.asarray(us)**2 + np.asarray(vs)**2)) for us,vs in zip(u_all,v_all) ] plt.figure() plt.quiver(x_class_v,y_class_v,u_means,v_means,temperature,**kw) plt.colorbar() plt.title('cross-realization "thermal" noise [m/s]') plt.xlabel('x [m]') plt.ylabel('y [m]') plt.savefig(PATH_PREFIX + 'quiver_thermal_noise_%s_%s.%s' % (qty,spec_type,img_format)) plt.figure() plt.quiver(x_class_v,y_class_v,u_means,v_means,speed,**kw) plt.colorbar() plt.title('average speed') plt.xlabel('x [m]') plt.ylabel('y [m]') plt.savefig(PATH_PREFIX + 'quiver_average_modulus_%s_%s.%s' % (qty,spec_type,img_format))
for i in colnames: df[i]= (df[i] - df[i].min()) / (df[i].max() - df[i].min()) print(df) df.plot(x='Temperature') plt.show() y = input('Enter temperature') d1 = df[df['Temperature'] >= int(y)] a = input('Second temperature') d2 = d1[d1['Temperature'] <= int(a)] colnames2 = list(d2.columns) for i in colnames2: df[i] = (df[i] - df[i].min()) / (df[i].max() - df[i].min()) main = d2.plot(x='Temperature') line = plt.axhline(y=0.5, color='black', linestyle='-') plt.show() maxwell = stats.maxwell for column in d2.columns: params= maxwell.fit(d2.columns, floc=0) print(params)