Source code for coordsys
# -*- coding: utf-8 -*-
import abc
import numpy as np
[docs]class Coordinates(object):
'''
Base class for coordinate containers. All coordinates are expected to be
stored as Cartesian regardless of the coordinate system. This class is
then responsible for converting to any supported coordinate system.
'''
__metaclass__ = abc.ABCMeta
@abc.abstractmethod
def __init__(self):
pass
[docs]class CartesianCoordinates(Coordinates):
'''
Basic container class for Cartesian coordinates.
:param x: The *x*-coordinate; may be a float type or NumPy array
:param y: The *y*-coordinate; may be a float type or NumPy array
:param z: The *z*-coordinate; may be a float type or NumPy array
'''
def __init__(self, x, y, z):
self.x = x
self.y = y
self.z = z
[docs]class SphericalCoordinates(Coordinates):
'''
Basic container class for spherical polar coordinates.
:param r: The radial coordinate; may be a float type or NumPy array
:param theta: The latitudinal coordinate; may be a float type or NumPy array
:param phi: The azimuthal coordinate; may be a float type or NumPy array
'''
def __init__(self, r, theta, phi):
self.x = r * np.sin(theta) * np.cos(phi)
self.y = r * np.sin(theta) * np.sin(phi)
self.z = r * np.cos(theta)
[docs]class CylindricalCoordinates(Coordinates):
'''
Basic container class for cylindrical coordinates.
:param s: The radial coordinate; may be a float type or NumPy array
:param phi: The azimuthal coordinate; may be a float type or NumPy array
:param z: The vertical coorindate; may be a float type or NumPy array
'''
def __init__(self, s, phi, z):
self.x = s * np.cos(phi)
self.y = s * np.sin(phi)
self.z = z