def s2c(p): # if self.type != 'spherical': # print 'EE: Huh? The coordinates are not spherical...' # return if p.shape[1] == 1: print 'EE: Can\'t do much with a single coordinate...' return elif p.shape[1] == 2: r = p[:,0] theta = p[:,1] # phi = zeros(self.p[:,3] # rho = z = r*cos(theta) y = zeros(z.size) x = r*sin(theta) p[:] = vstack((x,y,z)).T elif p.shape[1] == 3: r = p[:,0] theta = p[:,1] phi = p[:,2] rho = r*sin(theta) z = r*cos(theta) y = rho*sin(phi) x = rho*cos(phi) p = Coordinate(x=x,y=y,z=z) return p
def s2c(p): # if self.type != 'spherical': # print 'EE: Huh? The coordinates are not spherical...' # return if p.shape[1] == 1: print 'EE: Can\'t do much with a single coordinate...' return elif p.shape[1] == 2: r = p[:, 0] theta = p[:, 1] # phi = zeros(self.p[:,3] # rho = z = r * cos(theta) y = zeros(z.size) x = r * sin(theta) p[:] = vstack((x, y, z)).T elif p.shape[1] == 3: r = p[:, 0] theta = p[:, 1] phi = p[:, 2] rho = r * sin(theta) z = r * cos(theta) y = rho * sin(phi) x = rho * cos(phi) p = Coordinate(x=x, y=y, z=z) return p
def __new__(self, M=10, a=0.54, phi=0, normalised=True): # Create the window if phi == 0: wc = a + (1 - a) * np.cos(2 * pi * np.linspace(-0.5, 0.5, M)) win = wc / sum(wc) # Normalised window else: n = np.linspace(-0.5, 0.5, M) wc = a + (1 - a) * np.cos(2 * pi * n) # Window coefficients m = np.arange(0, M) # Create M indeces from 0 to 1 aa = exp(-1j * 2 * pi * m * phi) # Steering vector ws = dot(wc, aa) # Normalisation factor win = aa * wc / ws # Steered and normalised window w = np.Ndarray.__new__(self, win) # axes=('M',), # desc = 'Rectangular (phi=%d)'%phi) # desc='Rectangular (phi=%d)'%phi, # shape_desc=('M','1')) return w
def getWindow( image, tx_coords, # x,y tx_angle, # radians img_coords, # x_min, x_max, y_min, y_max width=0.8, scale=1): Nx, Ny = image.shape N = Nx img_width = img_coords[1] - img_coords[0] img_length = img_coords[3] - img_coords[2] x_mean = np.mean(img_coords[0:2]) y_mean = np.mean(img_coords[2:4]) dx = float(img_width) / Nx dy = float(img_length) / Ny image_window = np.ones(image.shape) x_old = np.zeros(N) x_new = np.zeros(N) # tx_img_range = img_coords[2] r = img_coords[2] + dy / 2 has_overflowed = False for row in range(Ny): row_data = image_window[:, row] x_cut = r * np.sin(tx_angle / 2) # x_cut_rel = x_cut / extent[0] # w_idx = np.linspace(0,1,N) x_old[:] = np.linspace(x_mean - (2 - width) * x_cut, x_mean + (2 - width) * x_cut, N) #*0.5/img_width + 0.5 x_new[:] = np.linspace(img_coords[0], img_coords[1], Nx) #*0.5/img_width + 0.5 up = x_new[x_new > x_old[0]] updown = up[up <= x_old[-1]] # print(x_cut, updown.shape[0]) Nlower = Nx - up.shape[0] Nhigher = Nx - updown.shape[0] - Nlower transition = (0.5 + 0.5 * np.cos( np.linspace(0, np.pi, int(Nx * width * x_cut / (2 * img_width))))) * scale + (1 - scale) # fn = None # if row == 0: # fn = pl.figure() # ax = fn.add_subplot(121) # ax.plot(transition) Nt = transition.shape[0] if N <= 2 * Nt: w = np.ones(N) has_overflowed = True else: w = np.hstack( (2 - scale - transition, np.ones(N - 2 * Nt), transition)) w_new_center = np.interpolate1D(x_old, w, updown, kind='linear', fill_value=1 - scale) w_new = np.hstack((np.ones(Nlower) * (1 - scale), w_new_center, np.ones(Nhigher) * (1 - scale))) image_window[:, row] = w_new # if row == 0: # ax = fn.add_subplot(122) # ax.plot(w_new) # fn.savefig('test2.eps') r = r + dy if has_overflowed: print("WARNING: Not making a window") return image_window