B
    d-                 @   sF   d Z ddlZdd Zdd Zdd Zd	d
 Zdd Zdddd
dgZdS )z Coordinate transformations.
    Nc             C   s   t | d |d  |d  S )ae   Calculates the magnitude in spherical coordinates from Cartesian
    coordinates.

    Parameters
    ----------
    x : {numpy.array, float}
        X-coordinate.
    y : {numpy.array, float}
        Y-coordinate.
    z : {numpy.array, float}
        Z-coordinate.

    Returns
    -------
    rho : {numpy.array, float}
        The radial amplitude.
       )numpysqrt)xyz r   ^/work/yifan.wang/ringdown/master-ringdown-env/lib/python3.7/site-packages/pycbc/coordinates.pycartesian_to_spherical_rho   s    r
   c             C   s0   t |trt|n|}t|| }|dtj  S )a[   Calculates the azimuthal angle in spherical coordinates from Cartesian
    coordinates. The azimuthal angle is in [0,2*pi].

    Parameters
    ----------
    x : {numpy.array, float}
        X-coordinate.
    y : {numpy.array, float}
        Y-coordinate.

    Returns
    -------
    phi : {numpy.array, float}
        The azimuthal angle.
    r   )
isinstanceintfloatr   Zarctan2pi)r   r   phir   r   r	    cartesian_to_spherical_azimuthal+   s    r   c             C   sR   t | ||}t|r,|r(t|| S dS ttj||t||dkdS dS )a   Calculates the polar angle in spherical coordinates from Cartesian
    coordinates. The polar angle is in [0,pi].

    Parameters
    ----------
    x : {numpy.array, float}
        X-coordinate.
    y : {numpy.array, float}
        Y-coordinate.
    z : {numpy.array, float}
        Z-coordinate.

    Returns
    -------
    theta : {numpy.array, float}
        The polar angle.
    g        r   )outwhereN)r
   r   ZisscalarZarccosdivideZ	ones_like)r   r   r   rhor   r   r	   cartesian_to_spherical_polar?   s
    
r   c             C   s,   t | ||}t| |}t| ||}|||fS )a
   Maps cartesian coordinates (x,y,z) to spherical coordinates
    (rho,phi,theta) where phi is in [0,2*pi] and theta is in [0,pi].

    Parameters
    ----------
    x : {numpy.array, float}
        X-coordinate.
    y : {numpy.array, float}
        Y-coordinate.
    z : {numpy.array, float}
        Z-coordinate.

    Returns
    -------
    rho : {numpy.array, float}
        The radial amplitude.
    phi : {numpy.array, float}
        The azimuthal angle.
    theta : {numpy.array, float}
        The polar angle.
    )r
   r   r   )r   r   r   r   r   thetar   r   r	   cartesian_to_sphericalY   s    
r   c             C   sH   | t | t | }| t | t | }| t | }|||fS )a
   Maps spherical coordinates (rho,phi,theta) to cartesian coordinates
    (x,y,z) where phi is in [0,2*pi] and theta is in [0,pi].

    Parameters
    ----------
    rho : {numpy.array, float}
        The radial amplitude.
    phi : {numpy.array, float}
        The azimuthal angle.
    theta : {numpy.array, float}
        The polar angle.

    Returns
    -------
    x : {numpy.array, float}
        X-coordinate.
    y : {numpy.array, float}
        Y-coordinate.
    z : {numpy.array, float}
        Z-coordinate.
    )r   cossin)r   r   r   r   r   r   r   r   r	   spherical_to_cartesianu   s    r   )__doc__r   r
   r   r   r   r   __all__r   r   r   r	   <module>   s   