def cartesian(x, y=None, z=None): max_dim = 1 for val in (x, y, z): if is_array(type(val)): if val.size > max_dim: max_dim = val.size if max_dim != 1: if is_scalar(type(x)) or (is_array(type(x)) and x.shape == (1, )): x = ones(max_dim) * x if is_scalar(type(y)) or (is_array(type(y)) and y.shape == (1, )): y = ones(max_dim) * y if is_scalar(type(z)) or (is_array(type(z)) and z.shape == (1, )): z = ones(max_dim) * z if type(x) == type(None): x = zeros(max_dim) if type(y) == type(None): y = zeros(max_dim) if type(z) == type(None): z = zeros(max_dim) if x.ndim == y.ndim == z.ndim == 1: if x.shape == y.shape == z.shape: return vstack((x, y, z)).T print 'EE: CoordinateSystem.cartesian() - This should not happen!'
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 cartesian(x, y=None, z=None): max_dim = 1 for val in (x, y, z): if is_array(type(val)): if val.size > max_dim: max_dim = val.size if max_dim != 1: if is_scalar(type(x)) or (is_array(type(x)) and x.shape == (1,)): x = ones(max_dim)*x if is_scalar(type(y)) or (is_array(type(y)) and y.shape == (1,)): y = ones(max_dim)*y if is_scalar(type(z)) or (is_array(type(z)) and z.shape == (1,)): z = ones(max_dim)*z if type(x) == type(None): x = zeros(max_dim) if type(y) == type(None): y = zeros(max_dim) if type(z) == type(None): z = zeros(max_dim) if x.ndim == y.ndim == z.ndim == 1: if x.shape == y.shape == z.shape: return vstack((x,y,z)).T print 'EE: CoordinateSystem.cartesian() - This should not happen!'
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 spherical(r, theta=None, phi=None): # def repetiveStuff(): # self.type = 'spherical' # self.shape = self.p.shape max_dim = 1 for val in (r, theta, phi): if is_array(type(val)): if val.size > max_dim: max_dim = val.size if max_dim != 1: if is_scalar(type(r)) or (is_array(type(r)) and r.shape == (1,)): r = ones(max_dim)*r if is_scalar(type(theta)) or (is_array(type(theta)) and theta.shape == (1,)): theta = ones(max_dim)*theta if is_scalar(type(phi)) or (is_array(type(phi)) and phi.shape == (1,)): phi = ones(max_dim)*phi if type(r) == type(None): r = zeros(max_dim) if type(theta) == type(None): theta = zeros(max_dim) if type(phi) == type(None): phi = zeros(max_dim) if r.ndim == theta.ndim == phi.ndim == 1: if r.shape == theta.shape == phi.shape: p = vstack((r,theta,phi)).T # repetiveStuff() return p print 'EE: CoordinateSystem.spherical() - This should not happen!'
def spherical(r, theta=None, phi=None): # def repetiveStuff(): # self.type = 'spherical' # self.shape = self.p.shape max_dim = 1 for val in (r, theta, phi): if is_array(type(val)): if val.size > max_dim: max_dim = val.size if max_dim != 1: if is_scalar(type(r)) or (is_array(type(r)) and r.shape == (1, )): r = ones(max_dim) * r if is_scalar(type(theta)) or (is_array(type(theta)) and theta.shape == (1, )): theta = ones(max_dim) * theta if is_scalar(type(phi)) or (is_array(type(phi)) and phi.shape == (1, )): phi = ones(max_dim) * phi if type(r) == type(None): r = zeros(max_dim) if type(theta) == type(None): theta = zeros(max_dim) if type(phi) == type(None): phi = zeros(max_dim) if r.ndim == theta.ndim == phi.ndim == 1: if r.shape == theta.shape == phi.shape: p = vstack((r, theta, phi)).T # repetiveStuff() return p print 'EE: CoordinateSystem.spherical() - This should not happen!'