def director_field_vectorized(self, k, x, jac=False): """ Returns the value of the vector field for a nonlinear class at a given point. args: k (int) : indexes which nonlinear class x (numpy.array) : (2,N) kwargs: jac: If True then returns the Jacobian of the vector-field too. returns: out1: ndarray (2,N) out2: ndarray (2,2,N) if jac==True """ from numpy.polynomial.legendre import legval2d, legder theta = legval2d(x[0] / self.width, x[1] / self.height, self.theta_coeffs[k]) out1 = np.array([np.cos(theta), np.sin(theta)]) if jac: dtheta_dx = legval2d(x[0] / self.width, x[1] / self.height, legder(self.theta_coeffs[k], axis=0)) / self.width dtheta_dy = legval2d(x[0] / self.width, x[1] / self.height, legder(self.theta_coeffs[k], axis=1)) / self.height N = x.shape[1] out2 = np.zeros((2, 2, N)) out2[0, 0, :] = -out1[1] * dtheta_dx out2[0, 1, :] = -out1[1] * dtheta_dy out2[1, 0, :] = out1[0] * dtheta_dx out2[1, 1, :] = out1[0] * dtheta_dy return out1, out2 return out1
def director_field(self, k, x, jac=False): """ Returns the value of the vector field for a nonlinear class. args: x: ndarray (2,) k: int kwargs: jac: If True then returns the Jacobian of the vector-field too. returns: out1: ndarray (2,) out2: ndarray (2,2) if jac==True """ from numpy.polynomial.legendre import legval2d, legder theta = legval2d(x[0] / self.width, x[1] / self.height, self.theta_coeffs[k]) #NOTE: Yes, I know this scaling seems off by a factor of 2. At the moment, this is correct. However, this should be refactored so that we use a scaling convention that is consistent with the rest of the code-base (e.g. posteriors.x_given_k out1 = np.array([np.cos(theta), np.sin(theta)]) if jac: dtheta_dx = legval2d(x[0] / self.width, x[1] / self.height, legder(self.theta_coeffs[k], axis=0)) / self.width dtheta_dy = legval2d(x[0] / self.width, x[1] / self.height, legder(self.theta_coeffs[k], axis=1)) / self.height out2 = np.zeros((2, 2)) out2[0, 0] = -out1[1] * dtheta_dx out2[0, 1] = -out1[1] * dtheta_dy out2[1, 0] = out1[0] * dtheta_dx out2[1, 1] = out1[0] * dtheta_dy return out1, out2 return out1
def __gradient(self, point_grid: ndarray) -> (NUMPY_TYPE, NUMPY_TYPE): coeffs_of_grad_x = legder(self.__c.mat / self.__scale.mat, axis=0) coeffs_of_grad_y = legder(self.__c.mat / self.__scale.mat, axis=1) sqrt_p = legval2d(*point_grid, self.__c.mat/self.__scale.mat) factor = 2.0 * self.__controller.N grad_x = factor * sqrt_p * legval2d(*point_grid, coeffs_of_grad_x) grad_y = factor * sqrt_p * legval2d(*point_grid, coeffs_of_grad_y) return self.__map.out(grad_x), self.__map.out(grad_y)
def leg2d_fit(x, y, z, m, n, sigma_clipping=False, **kw): from copy import deepcopy from numpy.polynomial import legendre m = m + 1 n = n + 1 if 'sigma' in kw: s = np.array(kw['sigma']) else: s = np.ones(shape=len(x), dtype=float) if sigma_clipping == True: x1 = deepcopy(x) y1 = deepcopy(y) z1 = deepcopy(z) s1 = deepcopy(s) while 1: X = np.zeros(shape=(len(z1), m * n), dtype=float) for i in range(len(z1)): for j in range(m): for k in range(n): c = np.zeros(shape=(m, n), dtype=float) c[j, k] = 1.0 X[i, j * n + k] = legendre.legval2d(x1[i], y1[i], c) X[i] = X[i] / s1[i]**2 sol1 = np.linalg.lstsq(X, z1 / s1**2, rcond=-1) sol2d1 = sol1[0].reshape(m, n) fit1 = legendre.legval2d(x1, y1, sol2d1) res1 = z1 - fit1 rms1 = rmsd(z1, fit1) mask1 = abs(res1) > 3.0 * rms1 if len(mask1[mask1 == True]) == 0: mask = np.array([i in z1 for i in z]) break else: x1 = x1[~mask1] y1 = y1[~mask1] z1 = z1[~mask1] s1 = s1[~mask1] else: X = np.zeros(shape=(len(z), m * n), dtype=float) for i in range(len(z)): for j in range(m): for k in range(n): c = np.zeros(shape=(m, n), dtype=float) c[j, k] = 1.0 X[i, j * n + k] = legendre.legval2d(x[i], y[i], c) X[i] = X[i] / s[i]**2 sol1 = np.linalg.lstsq(X, z / s**2, rcond=-1) sol2d1 = sol1[0].reshape(m, n) mask = np.ones(shape=(z), dtype=bool) return sol2d1, mask
def cost_function(theta_flat ): V_sum = 0 N = 0 theta = theta_flat.reshape( (k_max+1, k_max+1)) from numpy.polynomial.legendre import legval2d,leggauss V_mean = legval2d( x_arr/V_scale[0], y_arr/V_scale[1], theta).mean() k_span = np.arange( k_max+1) res = 2*(k_max+10) x_span = np.linspace(-V_scale[0], V_scale[0], res) y_span = np.linspace(-V_scale[1], V_scale[1], res) x_grid,y_grid = np.meshgrid(x_span, y_span) I = width*height*np.exp( - legval2d( x_grid/V_scale[0], y_grid/V_scale[1] , theta)).sum() / (res**2) regularization = np.sqrt( np.einsum( 'ij,i,j', theta**2 , k_span**2 , k_span**2 ) ) lambda_0 = 1e-4 return V_mean + np.log(I) + lambda_0 * regularization
def Stormer_Verlet(x0, y0, x1, y1, n_steps, theta, V_scale, Delta_t=1.0): from numpy.polynomial.legendre import legder, legval2d theta_x = legder(theta, axis=0, m=1) theta_y = legder(theta, axis=1, m=1) x_pred = np.zeros(n_steps) y_pred = np.zeros(n_steps) x_pred[0], x_pred[1] = (x0, x1) y_pred[0], y_pred[1] = (y0, y1) for k in range(n_steps - 2): x1, y1 = (x_pred[k + 1], y_pred[k + 1]) x0, y0 = (x_pred[k], y_pred[k]) V_x = legval2d(x1 / V_scale[0], y1 / V_scale[1], theta_x) / V_scale[0] V_y = legval2d(x1 / V_scale[0], y1 / V_scale[1], theta_y) / V_scale[1] x_pred[k + 2] = 2 * x1 - x0 - Delta_t**2 * V_x y_pred[k + 2] = 2 * y1 - y0 - Delta_t**2 * V_y return x_pred, y_pred
def test_legval2d(self): x1, x2, x3 = self.x y1, y2, y3 = self.y #test exceptions assert_raises(ValueError, leg.legval2d, x1, x2[:2], self.c2d) #test values tgt = y1*y2 res = leg.legval2d(x1, x2, self.c2d) assert_almost_equal(res, tgt) #test shape z = np.ones((2, 3)) res = leg.legval2d(z, z, self.c2d) assert_(res.shape == (2, 3))
def test_legval2d(self): x1, x2, x3 = self.x y1, y2, y3 = self.y #test exceptions assert_raises(ValueError, leg.legval2d, x1, x2[:2], self.c2d) #test values tgt = y1*y2 res = leg.legval2d(x1, x2, self.c2d) assert_almost_equal(res, tgt) #test shape z = np.ones((2,3)) res = leg.legval2d(z, z, self.c2d) assert_(res.shape == (2,3))
def Stormer_Verlet(x0, y0, x1, y1, n_steps, theta, V_scale, Delta_t=1.0): from numpy.polynomial.legendre import legder,legval2d theta_x = legder( theta, axis=0, m=1) theta_y = legder( theta, axis=1, m=1) x_pred = np.zeros(n_steps) y_pred = np.zeros(n_steps) x_pred[0],x_pred[1] = (x0,x1) y_pred[0],y_pred[1] = (y0,y1) for k in range(n_steps-2): x1,y1 = (x_pred[k+1],y_pred[k+1]) x0,y0 = (x_pred[k],y_pred[k]) V_x = legval2d( x1/V_scale[0], y1/V_scale[1], theta_x )/V_scale[0] V_y = legval2d( x1/V_scale[0], y1/V_scale[1], theta_y )/V_scale[1] x_pred[k+2] = 2*x1 - x0 - Delta_t**2 * V_x y_pred[k+2] = 2*y1 - y0 - Delta_t**2 * V_y return x_pred, y_pred
def legendre_basis_2d(Gx, Gy, alpha, grid_spacing=[1.0, 1.0]): # Compute x-coords and y-coords, each ranging from -1 to 1 x_grid = (sp.arange(Gx) - (Gx - 1) / 2.) / (Gx / 2.) y_grid = (sp.arange(Gy) - (Gy - 1) / 2.) / (Gy / 2.) # Create meshgrid of these xs, ys = np.meshgrid(x_grid, y_grid) basis_dim = alpha * (alpha + 1) / 2 G = Gx * Gy raw_basis = sp.zeros([G, basis_dim]) k = 0 for a in range(alpha): for b in range(alpha): if a + b < alpha: c = sp.zeros([alpha, alpha]) c[a, b] = 1 raw_basis[:,k] = \ legval2d(xs,ys,c).T.reshape([G]) k += 1 # Normalize this basis using my convension basis = normalize(raw_basis, grid_spacing) # Return normalized basis return basis
def cost_function(theta_flat ): V_sum = 0 N = 0 theta = theta_flat.reshape( (k_max+1, k_max+1)) from numpy.polynomial.legendre import legval2d,leggauss V_mean = legval2d( 2*x_arr/width, 2*y_arr/height, theta).mean() k_span = np.arange( k_max+1) res = 2*(k_max+10) x_span = np.linspace(-width/2, width/2, res) y_span = np.linspace(-height/2, height/2, res) x_grid,y_grid = np.meshgrid(x_span, y_span) Area = width*height #TODO: Consider using scipy.dblquad to compute I I = Area*np.exp( - legval2d( 2*x_grid/width, 2*y_grid/height , theta)).mean() regularization = np.sqrt( np.einsum( 'ij,i,j', theta**2 , k_span**2 , k_span**2 ) ) lambda_0 = 1e-4 return V_mean + np.log(I) + lambda_0 * regularization
def cost_function(theta_flat): V_sum = 0 N = 0 theta = theta_flat.reshape((k_max + 1, k_max + 1)) from numpy.polynomial.legendre import legval2d, leggauss V_mean = legval2d(x_arr / V_scale[0], y_arr / V_scale[1], theta).mean() k_span = np.arange(k_max + 1) res = 2 * (k_max + 10) x_span = np.linspace(-V_scale[0], V_scale[0], res) y_span = np.linspace(-V_scale[1], V_scale[1], res) x_grid, y_grid = np.meshgrid(x_span, y_span) I = width * height * np.exp(-legval2d(x_grid / V_scale[0], y_grid / V_scale[1], theta)).sum() / (res **2) regularization = np.sqrt( np.einsum('ij,i,j', theta**2, k_span**2, k_span**2)) lambda_0 = 1e-4 return V_mean + np.log(I) + lambda_0 * regularization
def cost_function(theta_flat): V_sum = 0 N = 0 theta = theta_flat.reshape((k_max + 1, k_max + 1)) from numpy.polynomial.legendre import legval2d, leggauss V_mean = legval2d(2 * x_arr / width, 2 * y_arr / height, theta).mean() k_span = np.arange(k_max + 1) res = 2 * (k_max + 10) x_span = np.linspace(-width / 2, width / 2, res) y_span = np.linspace(-height / 2, height / 2, res) x_grid, y_grid = np.meshgrid(x_span, y_span) Area = width * height #TODO: Consider using scipy.dblquad to compute I I = Area * np.exp(-legval2d(2 * x_grid / width, 2 * y_grid / height, theta)).mean() regularization = np.sqrt( np.einsum('ij,i,j', theta**2, k_span**2, k_span**2)) lambda_0 = 0.01 return V_mean + np.log(I) + lambda_0 * regularization
def legReconstruct(orders, locations, coeffs,unusedNumPts): if len(locations.shape)==1: return np.array(leg.legval(locations, coeffs)) else: if locations.shape[1] == 2: return leg.legval2d(locations[:,0], locations[:,1], coeffs) elif locations.shape[1] == 3: return leg.legval3d(locations[:,0],locations[:,1],locations[:,2], coeffs) else: return genericLegVal(locations, coeffs)
def evaluate(self, x,y): if not self.leg: x_poly = poly(np.array([x-self.x1off,y-self.y1off]), self.coeff_x) y_poly = poly(np.array([x-self.x1off,y-self.y1off]), self.coeff_y) if not self.fit_spline_b: return x_poly+ self.xroff, y_poly+ self.yroff x_poly = self.spline_x.ev(x_poly, y_poly) + x_poly y_poly = self.spline_y.ev(x_poly, y_poly) + y_poly else: x_in = self.norm(x-self.x1off,axis='x') y_in = self.norm(y-self.y1off,axis='y') x_poly = self.rnorm(legval2d(x_in, y_in, self.c_x), 'x') y_poly = self.rnorm(legval2d(x_in, y_in, self.c_y), 'y') return x_poly + self.xroff , y_poly + self.yroff
def test_legvander2d(self) : # also tests polyval2d for non-square coefficient array x1, x2, x3 = self.x c = np.random.random((2, 3)) van = leg.legvander2d(x1, x2, [1, 2]) tgt = leg.legval2d(x1, x2, c) res = np.dot(van, c.flat) assert_almost_equal(res, tgt) # check shape van = leg.legvander2d([x1], [x2], [1, 2]) assert_(van.shape == (1, 5, 6))
def director_field_vectorized(self, k, x, jac=False): """ Returns the value of the vector field for a nonlinear class at a given point. args: k (int) : indexes which nonlinear class x (numpy.array) : (2,N) kwargs: jac: If True then returns the Jacobian of the vector-field too. returns: out1: ndarray (2,N) out2: ndarray (2,2,N) if jac==True """ from numpy.polynomial.legendre import legval2d, legder theta = legval2d( x[0]/self.width, x[1]/self.height, self.theta_coeffs[k] ) out1 = np.array([np.cos(theta), np.sin(theta)]) if jac: dtheta_dx = legval2d( x[0]/self.width, x[1]/self.height, legder( self.theta_coeffs[k], axis=0) ) / self.width dtheta_dy = legval2d( x[0]/self.width, x[1]/self.height, legder( self.theta_coeffs[k], axis=1) ) / self.height N = x.shape[1] out2 = np.zeros((2,2,N)) out2[0,0,:] = -out1[1]*dtheta_dx out2[0,1,:] = -out1[1]*dtheta_dy out2[1,0,:] = out1[0]*dtheta_dx out2[1,1,:] = out1[0]*dtheta_dy return out1, out2 return out1
def get_angle(points, alpha, k_max, width, height): """ Return angle at points given Legendre coefficients args: points (numpy.ndarray): an array of shape (2 x N_points) alpha (numpy.ndarray): an array of shape (k_max+1, k_max+1) returns: angle (numpy.ndarray): an array of shape (N,) """ alpha = alpha.reshape((k_max + 1, k_max + 1)) from numpy.polynomial.legendre import legval2d return legval2d(points[0] / width, points[1] / height, alpha)
def get_angle( points, alpha, k_max, width, height): """ Return angle at points given Legendre coefficients args: points (numpy.ndarray): an array of shape (2 x N_points) alpha (numpy.ndarray): an array of shape (k_max+1, k_max+1) returns: angle (numpy.ndarray): an array of shape (N,) """ alpha = alpha.reshape( (k_max+1, k_max+1) ) from numpy.polynomial.legendre import legval2d return legval2d( points[0] / width , points[1] / height, alpha )
def legval_scale(x, y, coeffs): """ Returns the values of a legend repolynomial at N points, scaled so the whole plane is [0,1]**2 Takes x: np.array(N_Points): x values to evaluate Takes y: np.array(N_Points): y values to evaluate Takes coeffs: np.array(K_max_degree): legendre polynomial coefficients Returns np.array(N_Points) """ return legendre.legval2d(x/scene_scale[0], y/scene_scale[1], coeffs)
def legval_scale(x, y, coeffs): """ Returns the values of a legend repolynomial at N points, scaled so the whole plane is [0,1]**2 Takes x: np.array(N_Points): x values to evaluate Takes y: np.array(N_Points): y values to evaluate Takes coeffs: np.array(K_max_degree): legendre polynomial coefficients Returns np.array(N_Points) """ return legendre.legval2d(x / scene_scale[0], y / scene_scale[1], coeffs)
def director_field(self, k, x, jac=False ): """ Returns the value of the vector field for a nonlinear class. args: x: ndarray (2,) k: int kwargs: jac: If True then returns the Jacobian of the vector-field too. returns: out1: ndarray (2,) out2: ndarray (2,2) if jac==True """ from numpy.polynomial.legendre import legval2d, legder theta = legval2d( x[0]/self.width, x[1]/self.height, self.theta_coeffs[k] ) out1 = np.array([np.cos(theta), np.sin(theta)]) if jac: dtheta_dx = legval2d( x[0]/self.width, x[1]/self.height, legder( self.theta_coeffs[k], axis=0) ) / self.width dtheta_dy = legval2d( x[0]/self.width, x[1]/self.height, legder( self.theta_coeffs[k], axis=1) ) / self.height out2 = np.zeros( (2,2) ) out2[0,0] = - out1[1]*dtheta_dx out2[0,1] = - out1[1]*dtheta_dy out2[1,0] = out1[0]*dtheta_dx out2[1,1] = out1[0]*dtheta_dy return out1, out2 return out1
def jac_ode_function(xy, t, alpha, width, height, speed=1.0): """ returns velocity feild for input into odeint args: xy (np.ndarray) : shape = (2,) t (float): alpha: coefficients for angles returns: out (np.ndarray) : jacobian of velocity field, shape = (2,2) """ x = xy[0] y = xy[1] theta = legval2d(x / width, y / height, alpha) theta_x = legval2d(x / width, y / height, legder(alpha, axis=0)) / width theta_y = legval2d(x / width, y / height, legder(alpha, axis=1)) / height out = np.zeros((2, 2)) out[0, 0] = -np.sin(theta) * theta_x out[0, 1] = -np.sin(theta) * theta_y out[1, 0] = np.cos(theta) * theta_x out[1, 1] = np.cos(theta) * theta_y out *= speed return out
def jac_ode_function( xy, t, alpha, width, height, speed=1.0 ): """ returns velocity feild for input into odeint args: xy (np.ndarray) : shape = (2,) t (float): alpha: coefficients for angles returns: out (np.ndarray) : jacobian of velocity field, shape = (2,2) """ x = xy[0] y = xy[1] theta = legval2d( x / width, y / height, alpha ) theta_x = legval2d( x / width, y / height, legder( alpha, axis=0) ) / width theta_y = legval2d( x / width, y / height, legder( alpha, axis=1) ) / height out = np.zeros( (2,2) ) out[0,0] = - np.sin(theta)*theta_x out[0,1] = - np.sin(theta)*theta_y out[1,0] = np.cos(theta)*theta_x out[1,1] = np.cos(theta)*theta_y out *= speed return out
def ode_function( xy, t, alpha, width, height, speed=1.0): """ returns velocity feild for input into odeint args: xy (np.ndarray) : shape = (2,) t (float): alpha: coefficients for angles returns: out (np.ndarray) : velocity """ x = xy[0] y = xy[1] theta = legval2d( x / width, y / height, alpha ) out = speed*np.array( [np.cos(theta), np.sin(theta) ] ) return out
def ode_function(xy, t, alpha, width, height, speed=1.0): """ returns velocity feild for input into odeint args: xy (np.ndarray) : shape = (2,) t (float): alpha: coefficients for angles returns: out (np.ndarray) : velocity """ x = xy[0] y = xy[1] theta = legval2d(x / width, y / height, alpha) out = speed * np.array([np.cos(theta), np.sin(theta)]) return out
def at(self, point: PointAt) -> float64: point = self.__point_type_checked(point) mapped_point = self.__map.in_from(point) p = square(legval2d(*mapped_point, self.__c.mat/self.__scale.mat)) return self.__map.out(p * self.__N)
left_edge = 50 right_edge = 4049 xind = np.arange(left_edge, right_edge + 1) o = [82, 102, 121] x = [512, 2048, 3584] x1 = np.linspace(-7.5, 7.5, 1000) fig = plt.figure(figsize=(15, 10)) for i in range(3): for j in range(3): ax1 = plt.Axes( fig, [0.14 + j * 0.3, 0.07 + 0.05 + 0.32 * i, 0.23, 0.23 - 0.05]) fig.add_axes(ax1) sig = legendre.legval2d(o[i] / normalizing_constant0, x[j] / normalizing_constant1, sig_sol2d) beta = legendre.legval2d(o[i] / normalizing_constant0, x[j] / normalizing_constant1, beta_sol2d) tck_coeffs1 = np.zeros(shape=len(res_tck_coeffs_array), dtype=float) for k in range(len(res_tck_coeffs_array)): tck_coeffs1[k] = res_tck_coeffs_array[k](x[j], o[i]) tck1 = (res_knots, tck_coeffs1, res_deg) y1 = np.exp(-(abs(x1) / sig)**beta) + splev(x1, tck1) ax1.plot(x1, y1, 'k-', label=f'BR', zorder=10) sig_gh = legendre.legval2d(o[i] / normalizing_constant0, x[j] / normalizing_constant1, sig_gh_sol2d) An_gh = np.zeros(shape=(len(An_gh_sol2d)), dtype=float) for k in range(len(An_gh)): An_gh[k] = legendre.legval2d(o[i] / normalizing_constant0, x[j] / normalizing_constant1,
m1 = 5 + 1 m2 = 3 + 1 f_lines_1_rf = deepcopy(f_lines_1) normalizing_constant0 = 150.0 normalizing_constant1 = 4096.0 f_lines_1_rf[:, 0] = f_lines_1_rf[:, 0] / normalizing_constant0 f_lines_1_rf[:, 1] = f_lines_1_rf[:, 1] / normalizing_constant1 while 1: X = np.zeros(shape=(len(f_lines_1_rf), m1 * m2), dtype=float) for i in range(len(f_lines_1_rf)): for j in range(m1): for k in range(m2): c = np.zeros(shape=(m1, m2), dtype=float) c[j, k] = 1.0 X[i, j * m2 + k] = legendre.legval2d(f_lines_1_rf[i, 0], f_lines_1_rf[i, 1], c) wav_sol_1 = np.linalg.lstsq(X, f_lines_1_rf[:, 0] * f_lines_1_rf[:, 3], rcond=-1) wav_sol2d_1 = wav_sol_1[0].reshape(m1, m2) fitwv1 = np.array([ legendre.legval2d(f_lines_1_rf[i, 0], f_lines_1_rf[i, 1], wav_sol2d_1) / f_lines_1_rf[i, 0] for i in range(len(f_lines_1_rf)) ]) res1 = fitwv1 - f_lines_1_rf[:, 3] rms1 = rmsd(fitwv1, f_lines_1_rf[:, 3]) if rms1 < 3.0e-3: print(rms1, len(f_lines_1_rf))
def __density(self, point_grid: NUMPY_TYPE) -> NUMPY_TYPE: density = square(legval2d(*point_grid, self.__c.mat/self.__scale.mat)) return self.__map.out(density) * self.__controller.N
def full_model(self, points, *params): """""" return legval2d(points[:, 0], points[:, 1], self.params_to_coeff(params))
chunk_nodes_init = np.arange(0, data_oct.shape[1], 30) flag = 0 for order in range(len(data_oct)): if order+order_init in np.arange(82, 125) and order+order_init>=dodo[0] and order+order_init<=dodo[1]: x = np.arange(data_oct.shape[1]) y = data_oct[order, x] xind = np.arange(512-128, 4096-(512-128)+1) c1 = chunk_nodes_init[(xind[0] - chunk_nodes_init)<0][0] c2 = chunk_nodes_init[(xind[-1] - chunk_nodes_init)>0][-1] chunk = chunk_nodes_init[np.where(chunk_nodes_init==c1)[0][0]:np.where(chunk_nodes_init==c2)[0][0]+1] left_wav = legendre.legval2d((order+order_init)/normalizing_constant0, chunk[0]/normalizing_constant1, wav_sol2d_1)/((order+order_init)/normalizing_constant0) right_wav = legendre.legval2d((order+order_init)/normalizing_constant0, chunk[-1]/normalizing_constant1, wav_sol2d_1)/((order+order_init)/normalizing_constant0) low_n = int(np.floor((speed_of_light/left_wav*10.0 - f_0) / f_rep)) - 1 high_n = int(np.ceil((speed_of_light/right_wav*10.0 - f_0) / f_rep)) + 1 line_n_order = np.arange(low_n, high_n+1) line_wav_order = speed_of_light / (f_0 + f_rep*line_n_order) * 10.0 def wav2pos(x, o, w): return legendre.legval2d(o/normalizing_constant0, x/normalizing_constant1, wav_sol2d_1)/(o/normalizing_constant0) - w line_order = np.zeros(shape=(0,3), dtype=float) for i in range(len(line_wav_order)): xtemp1 = root_scalar(wav2pos, args=(order+order_init, line_wav_order[i]), bracket=[0, 4095], method='ridder').root line_order = np.append(line_order, [[line_n_order[i], line_wav_order[i], xtemp1]], axis=0) # 0n, 1wav, 2line_center_(ThAr_solution) # plt.figure() # plt.plot(x, y)
def on(self, grid: Grid) -> ndarray: grid = self.__grid_type_checked(grid) x_line = linspace(*self.__map.legendre_interval, grid.x) y_line = linspace(*self.__map.legendre_interval, grid.y) x_grid, y_grid = meshgrid(x_line, y_line) return square(legval2d(x_grid, y_grid, self.__c.mat/self.__scale.mat))
if order + order_init in np.arange( 82, 125 ) and order + order_init >= dodo[0] and order + order_init <= dodo[1]: x = np.arange(data_oct.shape[1]) y = data_oct[order, x] xind = np.arange(512 - 128, 4096 - (512 - 128) + 1) c1 = chunk_nodes_init[(xind[0] - chunk_nodes_init) < 0][0] c2 = chunk_nodes_init[(xind[-1] - chunk_nodes_init) > 0][-1] chunk = chunk_nodes_init[np.where( chunk_nodes_init == c1)[0][0]:np.where( chunk_nodes_init == c2)[0][0] + 1] left_wav = legendre.legval2d( (order + order_init) / normalizing_constant0, chunk[0] / normalizing_constant1, wav_sol2d_1) / ( (order + order_init) / normalizing_constant0) right_wav = legendre.legval2d( (order + order_init) / normalizing_constant0, chunk[-1] / normalizing_constant1, wav_sol2d_1) / ( (order + order_init) / normalizing_constant0) low_n = int(np.floor( (speed_of_light / left_wav * 10.0 - f_0) / f_rep)) - 1 high_n = int(np.ceil( (speed_of_light / right_wav * 10.0 - f_0) / f_rep)) + 1 line_n_order = np.arange(low_n, high_n + 1) line_wav_order = speed_of_light / (f_0 + f_rep * line_n_order) * 10.0 def wav2pos(x, o, w): return legendre.legval2d(
def wav2pos(x, o, w): return legendre.legval2d( o / normalizing_constant0, x / normalizing_constant1, wav_sol2d_1) / (o / normalizing_constant0) - w