def set_limits(self, event=None): if len(self.set_xmin_range_entry.get()) != 0: left = float(self.set_xmin_range_entry.get()) self.ax1.set_xlim(left=left) if len(self.set_xmax_range_entry.get()) != 0: right = float(self.set_xmax_range_entry.get()) self.ax1.set_xlim(right=right) if len(self.set_y1min_range_entry.get()) != 0: y1_bottom = float(self.set_y1min_range_entry.get()) self.ax1.set_ylim(bottom=y1_bottom) if len(self.set_y1max_range_entry.get()) != 0: y1_top = float(self.set_y1max_range_entry.get()) self.ax1.set_ylim(top=y1_top) if len(self.set_y2min_range_entry.get()) != 0: y2_bottom = float(self.set_y2min_range_entry.get()) self.ax2.set_ylim(bottom=y2_bottom) if len(self.set_y2max_range_entry.get()) != 0: y2_top = float(self.set_y2max_range_entry.get()) self.ax2.set_ylim(top=y2_top) self.canvas1.draw() if self.use_normalize: if len(self.normalize_entry.get()) != 0: norm_local = float(self.normalize_entry.get()) norm_index = fnc.find_nearest(self.x_data_orig, norm_local) norm_min = max(norm_index - 50, 0) norm_value = max(self.y1_data_orig[norm_min:norm_index + 50]) self.y1_data = [x / norm_value for x in self.y1_data]
def d2x_prec(self, t, x): index_time = functions.find_nearest(self.array[:,0],t) #найдем ближашее время if self.array[:index_time].size < 16: index = self.array.size//2 dx = np.gradient(self.array[ :, 2],self.array[:, 0])[-1] else: index = 8 dx = np.gradient(self.array[ :, 2],self.array[:, 0])[-1] print(f'd2xprec is {dx}') return dx
def dx_prec(self, t, x): index_time = functions.find_nearest(self.array[:,0],t) #найдем ближашее время if self.array[:index_time].size < 16: index = self.array.size//2 dx = np.gradient(self.array[ :, 1],self.array[:, 0])[-1] else: index = 8 dx = np.gradient(self.array[ :, 1],self.array[:, 0])[-1] self.array = np.insert(self.array, index_time, [t,x], axis=0) return dx
def dx_prec(self, t, x): ''' Нахождение производной в случае уточнения времени(более точно)''' index_time = functions.find_nearest(self.array[:, 0], t) #найдем ближашее время if self.array[:index_time].size < 16: index = self.array.size // 2 dx = np.gradient(self.array[:, 1], self.array[:, 0])[-1] else: index = 8 dx = np.gradient(self.array[:, 1], self.array[:, 0])[-1] self.array = np.insert(self.array, index_time, [t, x], axis=0) return dx
def b_ic(E, Uph): #read spectrum data from spec_data e_ir = spec_data(Uph)[0] ne = spec_data(Uph)[1] #log of IR energies l_e_ir = [] for elt in e_ir: l_e_ir.append(np.log10(elt)) ind = 0 #index to find changeover from Thompson to KN b_arr = [] #empty array for storing b_ic values co = len(E) - 1 #start at highest index for j in range(len(E)): #Thompson limit: if E[j] < 1e-1: gam = E[j] / 5.1099891e-4 + 1. b_arr.append(8.36e-10 * Uph * gam * gam) #KN limit else: if ind < co: co = ind #find changeover index #find electron energy that labels the qint array k = fun.find_nearest(qint_E, E[j]) q_arr = qint[k] #fill array with integrand values int_arr = [] for i in range(len(e_ir)): int_arr.append(ne[i] / e_ir[i] * q_arr[i]) #integrate int_arr over IR spectrum energies, ignore #energies above the 279th index since the spectrum is #not well behaved above these values b_arr.append(123.2 * integrate.simps(int_arr[0:280], e_ir[0:280])) ind += 1 #apply conversion to match up Thompson and KN results conv = 8.36e-10 * Uph * (E[co] / 5.1099891e-4 + 1.)**2. / b_arr[co] for i in range(co, len(b_arr)): b_arr[i] *= conv return b_arr
indexes = np.linspace(par.segment_mesh, par.segment_mesh * par.N, par.N) indexes = np.ndarray.tolist(indexes) Sz_array = np.array([]) Mx_array = np.array([]) for i in indexes: i = int(i) Sz_array = np.append(Sz_array, S_y[i - 1]) Mx_array = np.append(Mx_array, Mx_y[i - 1]) ## change this later once we get the data D_y = L_y / par.L_D Sx_y = D_y e1_index = f.find_nearest(y_mesh, par.e1_loc) e2_index = f.find_nearest(y_mesh, par.e2_loc) Sx_y[e1_index:] = Sx_y[e1_index:] - par.T1 Sx_y[e2_index:] = Sx_y[e2_index:] - par.T2 Mz_y = sp_integrate.cumtrapz(Sx_y, y_mesh, initial=0) Sx_array = np.array([]) Mz_array = np.array([]) Ty_array = np.array([]) ### torsion due to pitching moment/sweep/aileron if aileron: Ty = external_loads.Ty_pitchingmoment else: Ty = external_loads.Ty_pitchingmoment / 10 for i in indexes: i = int(i)
def get_response(self, t, x, dx): ''' получить выход''' if self.array.size < 10 or t > self.array[ -1, 0]: #проверка, это продолжение во времени или запрос на уточнение if self.state == 1: if self.last_x < x: # случай когда функция возрастает y = x - self.epsylon / 2 else: #случай когда возрастающая функция перестала возрастать self.trashold = self.last_x - self.epsylon / 2 self.state = 0 y = self.trashold elif self.state == -1: if self.last_x > x: # случай когда функция убывает y = x + self.epsylon / 2 else: #случай когда убывающая функция перестала убывать self.trashold = self.last_x + self.epsylon / 2 self.state = 0 y = self.trashold elif self.state == 0: if abs(self.trashold - x) < self.epsylon / 2: pass elif x < self.last_x: self.state = -1 elif x > self.last_x: self.state = 1 y = self.trashold self.last_x = x # записуем в массив состояние обьекта if self.array.size == 0: self.array = np.array([t, x, y, self.state, self.trashold]) else: self.array = np.vstack( (self.array, [t, x, y, self.state, self.trashold])) # считаем производную if self.array.size < 25: if self.array.size < 6: dy = 0 else: index = self.array.size // 5 print(self.array.size) dy = np.gradient(self.array[-index:, 2], self.array[-index:, 0])[-1] else: index = 5 dy = np.gradient(self.array[-index:, 2], self.array[-index:, 0])[-1] return y, dy else: #время уже было index = functions.find_nearest(self.array[:, 0], t) #найдем ближашее время last_x, last_y, state, trashold = self.array[index, 1], self.array[ index, 2], self.array[index, 3], self.array[index, 4] if state == 1: #если функция возрастала if x > last_x: y = x - self.epsylon / 2 else: trashold = last_x - self.epsylon / 2 state = 0 y = trashold elif state == -1: #если функция убывала if x < last_x: y = x + self.epsylon / 2 else: trashold = last_x + self.epsylon / 2 state = 0 y = trashold elif state == 0: if abs(trashold - x) < self.epsylon / 2: pass elif x < last_x: state = -1 elif x > self.last_x: state = 1 y = trashold self.array = np.insert(self.array, index, [t, x, y, state, trashold], axis=0) dy = np.gradient(self.array[index - 2:index, 2], self.array[index - 2:index, 0])[-1] return y, dy
wave1 = openfile[4].data[1] wave2 = openfile[4].data[2] flux0 = openfile[1].data[0] flux1 = openfile[1].data[1] flux2 = openfile[1].data[2] c = 299792.458 lamshift = 1 + (vbc/c) wave0 = np.asarray(wave0) * lamshift wave1 = np.asarray(wave1) * lamshift wave2 = np.asarray(wave2) * lamshift leftwindow = functions.find_nearest(wave0,16770) rightwindow = functions.find_nearest(wave0,16850) #print(leftwindow,rightwindow) fluxmax = max(flux0[rightwindow:leftwindow]) fluxmin = min(flux0[rightwindow:leftwindow]) #print(fluxmin,fluxmax) if fluxmin > 0: fluxmin = -0.5*fluxmin else: fluxmin = 1.25*fluxmin print(counter) plt.figure(figsize=(20,10)) plt.plot(wave0,flux0) plt.plot(wave1,flux1) plt.plot(wave2,flux2)