def annotate(image_in): image = filter_colors(image_in) gray = grayscale(image) blur_gray = gaussian(gray , c1.kernel_size) edges = canny(blur_gray, c1.low_threshold, c1.high_threshold) imshape = image.shape vertices = np.array([[\ ((imshape[1] * (1 - c1.trap_bottom_width)) // 2, imshape[0]),\ ((imshape[1] * (1 - c1.trap_top_width)) // 2, imshape[0] - imshape[0] * c1.trap_height),\ (imshape[1] - (imshape[1] * (1 - c1.trap_top_width)) // 2, imshape[0] - imshape[0] * c1.trap_height),\ (imshape[1] - (imshape[1] * (1 - c1.trap_bottom_width)) // 2, imshape[0])]]\ , dtype=np.int32) masked_edges = roi(edges, vertices) line_image = hough(masked_edges, c1.rho, c1.theta, c1.threshold, c1.min_line_length, c1.max_line_gap) initial_image = image_in.astype('uint8') annotated_image = weighted_img(line_image, initial_image) return annotated_image
def fit_gaussian(xs,ys,guess=[],x0_range=50.): '''Fits a Guassian profile on top of a background''' #import matplotlib.pyplot as plt fit_func = lambda p: ys - functions.gaussian(xs,p[0:3])- p[3] solution = leastsq(fit_func,guess) if solution[1] not in [1,2,3,4]: raise Error else: params = solution[0] print(params) return params
def gaussian_kernel(**kwargs): s = kwargs.get('size', 2) mu = kwargs.get('mu', 0.0) sigma = kwargs.get('sigma', 1.0) integer = kwargs.get('integer', False) x = array(range(-s,s+1)) g = gaussian(x, mu=mu, sigma=sigma) m = outer(g,g) if integer: gi = (m/m[0,0]).astype(int) return gi, npsum(gi) else: return m, npsum(m)
# ax_res_y2.set_yticks((ax_res.get_yticks() / 100) * yNorm) for xticklabel in ax.get_xticklabels(): xticklabel.set_visible(False) for xticklabel in axy2.get_xticklabels(): xticklabel.set_visible(False) ax.get_yticklabels()[0].set_visible(False) axy2.get_yticklabels()[0].set_visible(False) ax_res.get_yticklabels()[-1].set_visible(False) ax_res_y2.get_yticklabels()[-1].set_visible(False) if legend: ax.legend(loc='best') ax_res.set_xlabel(xlabel) ax.set_ylabel(ylabel) return fig, [ax, axy2, ax_res, ax_res_y2] if __name__ == '__main__': from functions import gaussian from lmfit.models import GaussianModel x = np.linspace(-3, 3, 200) y = gaussian(x, sigma=0.5) * (1 + np.random.normal(0, 0.1, len(x))) gmod = GaussianModel() para = gmod.guess(y, x=x) gfit = gmod.fit(y, para, x=x) models = [gfit.init_fit, gfit.best_fit] plt.close('all') fig, axes = plotResidual(x, y, models, yNorm=1.0, yThresh=0.1) axes[0].set_ylabel('relative [%]') axes[1].set_ylabel('absolute') axes[2].set_xlabel('xxx') plt.show()
wf = 0.010445 k = 9.04728 # in sqrt(amu)*ang sigma = 0.225 # broadening t = 100 # K zpl = 2.70845 # eV es = 1.0 ed = 3.0 ne = 400 # energy grid kb = 8.6173303e-5 # eV/K # initialize t = t * kb f = fcf_decimal(ni, nf, wi, wf, k) f = f**2 z = sum(exp(-i * wi / t) for i in range(100)) # partition e = np.linspace(es, ed, ne) pl = np.zeros(ne) # for ie in range(ne): for i in range(ni): ei = i * wi bz = exp(-ei / t) / z for j in range(nf): ef = j * wf pl[ie] += bz * e[ie]**3 * f[i, j] * gaussian( e[ie], zpl + ei - ef, sigma) tmp = np.vstack((e, pl)) np.savetxt('pl.dat', tmp.T) plt.plot(e, pl) plt.show()
'Student/Staff Ratio', 'Average Salary', 'Academic Services Expenditure per Student', 'Facilities Expenditure per Student'] bc_inds = list(df.index) bc_inds.insert(0, 'None') bc_col1, bc_col2 = st.beta_columns(2) metric = bc_col1.selectbox('Select Metric', bc_cols, index=0) institution = bc_col2.selectbox('Select Institution (Optional)', bc_inds, index=0) if metric != 'None': fig, ax = plt.subplots(figsize=(10,8)) if institution != 'None': x, gauss, std, mean, xpoint, ypoint, length= gaussian(df, metric, institution) ax.arrow(xpoint, ypoint, dx=0, dy=-length, width=std/30, head_length=length/6, length_includes_head=True) else: x, gauss, std, mean = gaussian(df, metric) ax.plot(x, gauss) ax.axes.yaxis.set_ticklabels([]) ax.set_axisbelow(True) ax.grid(True) ax.set_xlabel(f'{metric}') ax.set_title(f'{metric}\nMean = {round(mean,2)}, Standard Deviation = {round(std,2)}') st.pyplot(fig)
wij = 6e-4 # <0|dPsi/dQ> unit 1/Q # constants kb = 8.6173303e-5 # eV/K hbar = 6.582119514e-16 # eV.s/rad h = 4.135667662e-15 # eV.s ev = 1.6021766208e-19 # J amu = 1.660539040e-27 # kg ang = 1.0e-10 # m fr = ev / amu / ang**2 # initialize t = t * kb f = fcf_decimal(ni, nf, wi, wf, q) z = sum(exp(-i * wi / t) for i in range(200)) # partition beta = sqrt(wi * fr / (wi / hbar)**2 / 2) # hbar/omega unit Q^2 # rate = 0.0 for i in range(ni - 1): ei = i * wi bz = exp(-ei / t) / z for j in range(nf): ef = j * wf if i < 1: rate += 2*pi*beta**2*bz*(sqrt(i+1)*f[i+1,j])**2*zpl**2*wij**2* \ gaussian(zpl+ei,ef,sigma) else: rate += 2*pi*beta**2*bz*(sqrt(i+1)*f[i+1,j]+sqrt(i)*f[i-1,j])**2* \ zpl**2*wij**2*gaussian(zpl+ei,ef,sigma) print rate / h # Hz
#Initialisierung der DATEN p_d = 0.99 #Detektionsrate lambda_c = 0.3 #Clutter Intensität V = 5 #Cluttering Volume T = 0.001 #Abtastzeit F = np.array([[1, T], [0, 1]]) #Systemmatrix H = np.array([1, 0]) #Ausgangsmatrix n = 2 #Anzahl Objekte variance_motion = 0.25 variance_measurement = 0.2 variance_prior = 0.36 init_x1 = 0 init_x2 = 10 init_values = np.array([[init_x1, init_x2], [0, 0]]) x = np.arange(-20, 20, 0.1) init_prior_x1 = gaussian(x, init_x1, variance_prior) init_prior_x2 = gaussian(x, init_x2, variance_prior) number_states = len(F) # Zuständezahl estimate = np.zeros((number_states, n)) # Zustände geschätz estimate[0:number_states, 0:n] = init_values #Anfangswerte hinzufügen P = np.zeros((number_states, n * number_states)) 'nullmatrix wirklich sinnvolll??? -> die Varianz des Schätzfehlers wird mit 0 also nicht vorhanden initialisiert großer wert wäre sinnvoller' #Initialisierung KALMANFILTER Pini = np.diag([.01, .009]) Q = np.array([[.1, 0], [0, .1]]) R = np.array([[10]]) #KF = KalmanFilter(dim_x=2, dim_z=1) #KF.x = np.array([0,1]) # pos, velo init
rate = 0.0 for i in range(ni-4): ei = i*wi - 30*lam**2*beta**6/wi*(i**2+i+11./30) bz = exp(-ei/t)/z for j in range(nf): ef = j*wf if i < 1: ff[i,j] = beta*sqrt(i+1)*f[i+1,j] + lam*beta**4/3/wi* \ (-9*(2*i+1)*f[i,j]-2*(5*i+6)*sqrt((i+1)*(i+2))*f[i+2,j] - \ sqrt((i+1)*(i+2)*(i+3)*(i+4))*f[i+4,j]) elif i >= 1 and i < 2: ff[i,j] = beta*(sqrt(i+1)*f[i+1,j] + sqrt(i)*f[i-1,j]) + lam*beta**4/3/wi* \ (-9*(2*i+1)*f[i,j]-2*(5*i+6)*sqrt((i+1)*(i+2))*f[i+2,j] - \ sqrt((i+1)*(i+2)*(i+3)*(i+4))*f[i+4,j]) elif i >= 2 and i < 4: ff[i,j] = beta*(sqrt(i+1)*f[i+1,j] + sqrt(i)*f[i-1,j]) + lam*beta**4/3/wi* \ (2*(5*i-1)*sqrt(i*(i-1))*f[i-2,j]-9*(2*i+1)*f[i,j] - \ 2*(5*i+6)*sqrt((i+1)*(i+2))*f[i+2,j] - \ sqrt((i+1)*(i+2)*(i+3)*(i+4))*f[i+4,j]) else: ff[i,j] = beta*(sqrt(i+1)*f[i+1,j] + sqrt(i)*f[i-1,j]) + lam*beta**4/3/wi* \ (sqrt(i*(i-1)*(i-2)*(i-3))*f[i-4,j] + \ 2*(5*i-1)*sqrt(i*(i-1))*f[i-2,j]-9*(2*i+1)*f[i,j] - \ 2*(5*i+6)*sqrt((i+1)*(i+2))*f[i+2,j] - \ sqrt((i+1)*(i+2)*(i+3)*(i+4))*f[i+4,j]) rate += 2*pi*bz*ff[i,j]**2*zpl**2*wij**2*gaussian(zpl+ei,ef,sigma) print rate/h # Hz
k = 8.71 # in sqrt(amu)*ang sigma = 0.2665 # broadening t = 175 # K zpl = 2.74142 # eV es = 1.0 ed = 4.0 ne = 1000 # energy grid eps = 3.28 kb = 8.6173303e-5 # eV/K eh = 27.211385 # eV tau = 2.418884e-17 # hbar/Eh # initialize t = t * kb f = fcf_decimal(ni, nf, wi, wf, k) f = f**2 z = sum(exp(-i * wi / t) for i in range(200)) # partition e = np.linspace(es, ed, ne) a = sqrt(eps) / 3 / pi / 137**3 / tau pl = np.zeros(ne) # for ie in range(ne): for i in range(ni): ei = i * wi bz = exp(-ei / t) / z for j in range(nf): ef = j * wf pl[ie] += a * bz * (e[ie] / eh)**3 * f[i, j] * gaussian( e[ie], zpl + ei - ef, sigma) print sum(pl) * (e[1] - e[0])