B
    {dܭ                 @   s   d Z ddlmZ ddlZddlmZ ddlmZ ejZejd Z	G dd	 d	e
ZG d
d deZG dd deZG dd deZG dd deZG dd deZdS )aM  This module provides classes for some spherical projection.
To be used when calling SphereProjAxes class.

SphericalProj : a virtual class (do nothing). Just a template for derived 
                (useful) classes

GnomonicProj : Gnomonic projection

AzimuthalProj : Azimuthal equidistant or Lambert azimuthal equal-area projection
   )rotator    N)	pixelfunc)UNSEENg     f@c               @   s   e Zd ZdZdZd'ddZdd Zdd	 Zeed
dZ	dd Z
d(ddZd)ddZd*ddZd+ddZd,ddZd-ddZd.ddZdd Zdd  Zd!d" Zd/d#d$Zd%d& ZdS )0SphericalProja  
    This class defines functions for spherical projection.

    This class contains class method for spherical projection computation. It
    should not be instantiated. It should be inherited from and methods should
    be overloaded for desired projection.
    NoneNc             K   sL   t j|d dd| _t j|dj| _t j|dj| _| | | jf | d S )NZZYX)rotcoordZ	eulertype)r	   )	RRotatorr   ZcoordoutcoordsysZcoordoutstrZcoordsysstrset_flipset_proj_plane_info)selfr   r	   flipconvkwds r   ]/work/yifan.wang/ringdown/master-ringdown-env/lib/python3.7/site-packages/healpy/projector.py__init__3   s
    
zSphericalProj.__init__c             K   s<   d}x|  D ]}|d k	rd}qW |s2t|| _nd | _d S )NTF)valuesdict
_arrayinfo)r   r   ZallNonevr   r   r   r   :   s    z!SphericalProj.set_proj_plane_infoc             C   s   | j S )N)r   )r   r   r   r   get_proj_plane_infoD   s    z!SphericalProj.get_proj_plane_infoz3Dictionary with information on the projection array)docc             C   s,   t |t | k	rdS | j|jko*| j|jkS )NF)typer   r   )r   ar   r   r   __eq__K   s    zSphericalProj.__eq__Fc             C   s   dS )a  From angular direction to position in the projection plane (%s).

        Input:
          - theta: if phi is None, theta[0] contains theta, theta[1] contains phi
          - phi  : if phi is not None, theta,phi are direction
          - lonlat: if True, angle are assumed in degree, and longitude, latitude
          - flipconv is either 'astro' or 'geo'. None will be default.
        Return:
          - x, y: position in %s plane.
        Nr   )r   thetaphilonlatdirectr   r   r   ang2xyP   s    zSphericalProj.ang2xyc             C   s   dS )a  From unit vector direction to position in the projection plane (%s).

        Input:
          - vx: if vy and vz are None, vx[0],vx[1],vx[2] defines the unit vector.
          - vy,vz: if defined, vx,vy,vz define the unit vector
          - lonlat: if True, angle are assumed in degree, and longitude, latitude
          - flipconv is either 'astro' or 'geo'. None will be default.

        Return:
          - x, y: position in %s plane.
        Nr   )r   vxvyvzr!   r   r   r   vec2xy]   s    zSphericalProj.vec2xyc             C   s   dS )a  From position in the projection plane to angular direction (%s).

        Input:
          - x : if y is None, x[0], x[1] define the position in %s plane.
          - y : if defined, x,y define the position in projection plane.
          - lonlat: if True, angle are assumed in degree, and longitude, latitude
          - flipconv is either 'astro' or 'geo'. None will be default.

        Return:
          - theta, phi : angular direction.
        Nr   )r   xyr    r!   r   r   r   xy2angk   s    zSphericalProj.xy2angc             C   s   dS )a  From position in the projection plane to unit vector direction (%s).

        Input:
          - x : if y is None, x[0], x[1] define the position in %s plane.
          - y : if defined, x,y define the position in projection plane.
          - lonlat: if True, angle are assumed in degree, and longitude, latitude
          - flipconv is either 'astro' or 'geo'. None will be default.

        Return:
          - theta, phi : angular direction.
        Nr   )r   r'   r(   r!   r   r   r   xy2vecy   s    zSphericalProj.xy2vecc             C   s   dS )a^  From position in the projection plane to image array index (%s).

        Input:
          - x : if y is None, x[0], x[1] define the position in %s plane.
          - y : if defined, x,y define the position in projection plane.
          - projinfo : additional projection information.

        Return:
          - i,j : image array indices.
        Nr   )r   r'   r(   r   r   r   xy2ij   s    zSphericalProj.xy2ijc             C   s   dS )a  From image array indices to position in projection plane (%s).

        Input:
          - if i and j are None, generate arrays of i and j as input
          - i : if j is None, i[0], j[1] define array indices in %s image.
          - j : if defined, i,j define array indices in image.
          - projinfo : additional projection information.

        Return:
          - x,y : position in projection plane.
        Nr   )r   ijr   r   r   ij2xy   s    zSphericalProj.ij2xyc                sx  |   \}}tjdkr"tjjj}ntjj}t||krP|jtjj	k	rP|jdk}nt
d}t|jtjtj }	| t|| t|| }
tj|| |d|
}
||
d |
d |
d }t |r jtjj	k	r | }t| j| < n|t trdt|  |j}| }t|	| }t||< || } fdd	|D }tj||j|jd
||< n | }||	|< |	S )a  Create an array containing the projection of the map.

        Input:
          - vec2pix_func: a function taking theta,phi and returning pixel number
          - map: an array containing the spherical map to project,
                 the pixelisation is described by vec2pix_func
        Return:
          - a 2D array with the projection of the map.

        Note: the Projector must contain information on the array.
        z1.1FN)r   r	   r   r      c             3   s   | ]} | V  qd S )Nr   ).0p)mapr   r   	<genexpr>   s    z(SphericalProj.projmap.<locals>.<genexpr>)count)r.   np__version__macoreZMaskedArrayarrayr   masknomaskslicezerosshapefloat64infr*   asarrayr
   r   mkcoordI
isinstancer   r   Zin1dkeysreshapeZ
zeros_likeZfromiterZdtypesize)r   r2   Zvec2pix_funcr   r	   r'   r(   ZmatypewZimgvecZpixZmpixZis_pix_seenZis_pix_unseenZpix_seeniterabler   )r2   r   projmap   s2    
 zSphericalProj.projmapc             C   s8   |dkrd}|dkrd| _ n|dkr,d| _ ntddS )zflipconv is either 'astro' or 'geo'. None will be default.

        With 'astro', east is toward left and west toward right.
        It is the opposite for 'geo'
        NZastroZgeor   z4flipconv must be 'astro', 'geo' or None for default.)_flip
ValueError)r   r   r   r   r   r      s    zSphericalProj.set_flipc             C   s   dS )zoGet the extension of the projection plane.

        Return:
          extent = (left,right,bottom,top)
        Nr   )r   r   r   r   
get_extent   s    zSphericalProj.get_extentc             C   s   dt  S )zGet the field of view in degree of the plane of projection

        Return:
          fov: the diameter in radian of the field of view
        g       @)pi)r   r   r   r   get_fov   s    zSphericalProj.get_fovc             C   sN   t | jjd dd d t \}}|r2||fS td |t  |t fS dS )a
  Get the center of the projection.

        Input:
          - lonlat : if True, will return longitude and latitude in degree,
                     otherwise, theta and phi in radian
        Return:
          - theta,phi or lonlat depending on lonlat keyword
        r   r/      g       @N)r5   rA   r   ZrotsrP   dtor)r   r    Zlonlatr   r   r   
get_center   s    	&zSphericalProj.get_centerc             C   sR   | j d kr||fS |d kr&| j | j fS t|tkr<|| j fS t|d | j fS d S )Nr   )r   r   strtuple)r   r	   r   r   r   rB      s    

zSphericalProj.mkcoord)NNN)NFF)NNF)NFF)NF)N)NN)NN)F)__name__
__module____qualname____doc__namer   r   r   property	arrayinfor   r"   r&   r)   r*   r+   r.   rK   r   rO   rQ   rU   rB   r   r   r   r   r   (   s(   









*
r   c                   s   e Zd ZdZdZd fdd	Zd fdd		ZdddZej	jeef e_dddZ
ej
jeef e
_dddZ	ej	jeef e	_d ddZejjeef e_d!ddZejjeef e_d"ddZejjeef e_dd Zdd Z  ZS )#GnomonicProjz:This class provides class methods for Gnomonic projection.ZGnomonicNc                s&   t t| jf |||||d| d S )N)r   r	   xsizeysizereso)superr_   r   )r   r   r	   r`   ra   rb   r   )	__class__r   r   r   
  s    zGnomonicProj.__init__         ?c                s>   |d krd}|d kr|}|d kr$d}t t| j|||d d S )Nre   g      ?)r`   ra   rb   )rc   r_   r   )r   r`   ra   rb   )rd   r   r   r     s    
z GnomonicProj.set_proj_plane_infoFc             C   s<  |s|  |||}n:|d kr*|d kr*|}n$|d k	rF|d k	rF|||f}ntd| j}t|d dk}| svtjj}t|d ds|tjjk	rtj	}tj	}	n$||d  |d  }|d |d  }	np|dk}
t
|d jtj	 }t
|d jtj	 }	||d |
  |d |
  ||
< |d |
 |d |
  |	|
< ||	fS )Nz2vy and vz must be both defined or both not definedr   g        __len__r   r/   F)r   rN   rM   r5   rA   anyr7   r;   hasattrnanr=   r>   )r   r#   r$   r%   r!   rI   flipr:   r'   r(   rH   r   r   r   r&     s.     zGnomonicProj.vec2xyc             C   sx   | j }|d kr|\}}t|t| }}dtd|d  |d   }||| | || f}|sp| j|S |S d S )Ng      ?r/   )rM   r5   rA   sqrtr   rC   )r   r'   r(   r!   rk   Zrm1rI   r   r   r   r*   8  s    zGnomonicProj.xy2vecc             C   s   t j|||d}| j||dS )N)r    )r!   )r
   dir2vecr&   )r   r   r   r    r!   rI   r   r   r   r"   F  s    zGnomonicProj.ang2xyc             C   s   t j| j|||d|dS )N)r!   )r    )r
   vec2dirr*   )r   r'   r(   r    r!   r   r   r   r)   L  s    zGnomonicProj.xy2angc             C   s   | j d krtdt| j d }t| j d }| j d }|d krH|\}}|d t }d|d  d|d   }}t|||  t}	t|||  t}
|
|	fS )Nz@No projection plane array information defined for this projectorr`   ra   rb   g      N@g      ?r   )r^   	TypeErrorintrS   r5   aroundastype)r   r'   r(   r`   ra   rb   dxxcycr-   r,   r   r   r   r+   Q  s    

zGnomonicProj.xy2ijc             C   s@  | j d krtdt| j d }t| j d }| j d }|d t }d|d  d|d   }}|d kr|d krtt|t|}	|	| | }
tt|t|}	|	| | }n|d k	r|d k	rt|| | }
t|| | }nJ|d k	r0|d kr0|\}}t|| | }
t|| | }ntd|
|fS )	Nz@No projection plane array information defined for this projectorr`   ra   rb   g      N@g      ?r   zWrong parameters)	r^   ro   rp   rS   r5   outeronesarangerA   )r   r,   r-   r`   ra   rb   rs   rt   ru   idxr'   r(   r   r   r   r.   c  s,    

zGnomonicProj.ij2xyc             C   sJ   | j d | j d  }}| dd\}}| |d |d \}}||||fS )Nr`   ra   r   r   )r^   r.   )r   r`   ra   leftbottomrighttopr   r   r   rO     s    zGnomonicProj.get_extentc             C   s.   | j | dddd\}}}t|}d| S )Nr   T)r!   g       @)r*   r.   r5   arccos)r   r#   r$   r%   r   r   r   r   rQ     s    
zGnomonicProj.get_fov)NNNNN)re   Nrf   )NNF)NF)NFF)NFF)N)NN)rX   rY   rZ   r[   r\   r   r   r&   r   r"   r*   r)   r+   r.   rO   rQ   __classcell__r   r   )rd   r   r_     s$   





r_   c                   s$  e Zd ZdZdZg Zd# fdd	Z fddZd$d
dZe	jjeef e_d%ddZ
e	j
jeef e
_d&ddZe	jjeef e_d'ddZe	jjeef e_d(ddZe	jjeef e_d)ddZe	jjeef e_dd Zedd Zed*ddZedd Zedd  Zed!d" Z  ZS )+MollweideProjz;This class provides class methods for Mollweide projection.Z	MollweideN   c                s*   |    tt| jf |||d| d S )N)r   r	   r`   )_MollweideProj__initialise_datarc   r   r   )r   r   r	   r`   r   )rd   r   r   r     s    zMollweideProj.__init__c                s   t t| j|d d S )N)r`   )rc   r   r   )r   r`   )rd   r   r   r     s    z!MollweideProj.set_proj_plane_infoFc             C   s   |st | |||\}}nt |||\}}| j}tj\}}	|t dt  t }td | }
t||	|
}|d t | t	| }t
|}||fS )Nr/   g       @)r
   rn   r   rM   r   _MollweideProj__molldatarP   _MollweideProj__lininterpr5   cossin)r   r#   r$   r%   r!   r   r   rk   XYrT   Ar'   r(   r   r   r   r&     s    

zMollweideProj.vec2xyc             C   s$  | j }|d kr|\}}t|d d t|d  dk}| sJtjj}t|ds|tjjk	rrtjtjtjfS td| d|  }t	|}dt
 |||   }|t
 d | t|d }	td| d|  }
|
t|	 |
t|	 |f}|s| j|S |S n|dk}t|jtj t|jtj t|jtj f}td||  d||   }t	|| }dt
 ||| |   |d |< |t
 d ||  t|d }	td|d |  d|d |   }
|
t|	 |d	 |< |
t|	 |d |< |s| j|S |S d S )
Nr/   g      @g      ?rg   r   g       @gư>Fr   )rM   r5   rA   rh   r7   r;   ri   rj   rl   arcsinrP   maximumr   r   r   rC   r=   r>   )r   r'   r(   r!   rk   r:   sr   zr   szrI   rH   r   r   r   r*     s@    $
  &zMollweideProj.xy2vecc             C   s   | j tj|||d|dS )N)r    )r!   )r&   r
   rm   )r   r   r   r    r!   r   r   r   r"     s    zMollweideProj.ang2xyc             C   s   | j |||d}tj||dS )N)r!   )r    )r*   r
   rn   )r   r'   r(   r    r!   rI   r   r   r   r)     s    zMollweideProj.xy2angc       
      C   s@  | j d krtdt| j d }|d }|d kr8|\}}|d d |d d  }}t|drt|| d | t}t|||  t}|d d |d  dk}	|	 stjj	}	tjj
||	d}tjj
||	d}n^|d d |d  dkrtjtj }}n4t|| d | t}t|||  t}||fS )	Nz@No projection plane array information defined for this projectorr`   r/   g      ?g       @rg   g      @)r:   )r^   ro   rp   ri   r5   rq   rr   rh   r7   r;   r9   rj   )
r   r'   r(   r`   ra   rt   ru   r-   r,   r:   r   r   r   r+     s*    

zMollweideProj.xy2ijc             C   s  | j d krtdt| j d }|d }|d d |d d  }}|d kr|d krtt|t|}|| | }tt|t|}d||  | }	|	d d |d  dk}
|
 stjj	}
tjj
|	|
d}	tjj
||
d}n|d k	rN|d k	rNt|| | }dt||  | }	|	d d |d  dkrtjtj }	}nv|d k	r|d kr|\}}t|| | }dt||  | }	|	d d |d  dkrtjtj }	}ntd|	|fS )	Nz@No projection plane array information defined for this projectorr`   r/   g      ?g       @g      @)r:   z,i and j must be both given or both not given)r^   ro   rp   r5   rv   rx   rw   rh   r7   r;   r9   rA   rj   )r   r,   r-   r`   ra   rt   ru   ry   r(   r'   r:   r   r   r   r.     s:    
zMollweideProj.ij2xyc             C   s   dS )N)g       g       @g      g      ?r   )r   r   r   r   rO     s    zMollweideProj.get_extentc              C   s   t tjdkrtdddd t } tjtjtj| 	 | dd}t
t d g| td gg} t
t d g|td gg}tj|  tj| d S )Nr   g      ?g     f@g     V@
   )niterr/   )lenr   r   r5   rx   rS   _MollweideProj__findRoot_MollweideProj__fmoll_MollweideProj__dfmollcopyZconcatenaterP   append)r   r   r   r   r   Z__initialise_data   s    zMollweideProj.__initialise_datad   c       	      C   sN   |}t t|d}d}x2||k rH| || ||| }||7 }|d7 }qW |S )Ni  r   r   )minabs)	fdfZx0ZargsfZargsdfr   r'   r,   rs   r   r   r   Z
__findRoot-  s    
zMollweideProj.__findRootc             C   s$   d|  t d|   tt |  S )Ng       @)r5   r   rP   )r'   argsr   r   r   Z__fmoll8  s    zMollweideProj.__fmollc             C   s   ddt d|    S )Ng       @g      ?)r5   r   )r'   r   r   r   r   Z__dfmoll<  s    zMollweideProj.__dfmollc             C   sR   |  |}||d  || ||d   | | | |d    || |d     }|S )Nr   )Zsearchsorted)r   r   r'   ry   r(   r   r   r   Z__lininterp@  s    
0zMollweideProj.__lininterp)NNr   )NNF)NF)NFF)NFF)N)NN)NNr   )rX   rY   rZ   r[   r\   r   r   r   r&   r   r*   r"   r)   r+   r.   rO   staticmethodr   r   r   r   r   r   r   r   )rd   r   r     s0   

(



!
r   c                   s  e Zd ZdZdZd fdd	Z fddZdd
dZejjeef e_dddZ	ej	jeef e	_dddZ
ej
jeef e
_d ddZejjeef e_d!ddZejjeef e_d"ddZejjeef e_dd Zejje_dd Zd#ddZejje_  ZS )$CartesianProjz;This class provides class methods for Cartesian projection.Z	CartesianN   c          	      s(   t t| jf ||||||d| d S )N)r   r	   r`   ra   lonralatra)rc   r   r   )r   r   r	   r`   ra   r   r   r   )rd   r   r   r   N  s    
zCartesianProj.__init__c                s>  |d krddg}n4t |d |d  d}|dkr6d}|d | |d< |d krVddg}t|dkst|dks|d d	k s|d d
ks|d |d krtd| jt |d d | j  }t |}t|}|d kr|d |d  |d |d   }tt|| }nt|}t|t| }t	t
| j|||||d d S )Ng     fg     f@r   r   ih  g     Vg     V@r/   iZ   zRWrong argument lonra or latra. Must be lonra=[a,b],latra=[c,d] c<d, c>=-90, d<=+90)r`   r   r   ra   ratio)r5   modr   ro   rM   r?   rp   roundfloatrc   r   r   )r   r`   ra   r   r   Z
lonra_spanr   )rd   r   r   r   b  s2    


 
z!CartesianProj.set_proj_plane_infoFc       
      C   sr   |st | |||\}}nt |||\}}| j}||t dt  t  }|t }td | }	|	t }	||	fS )Nr/   g       @)r
   rn   r   rM   rP   rS   )
r   r#   r$   r%   r!   r   r   rk   r'   r(   r   r   r   r&     s    zCartesianProj.vec2xyc                s   |d krt |\}}nt |t | }}| j}td |t   || t }|sr| jt 	 |	 }nt 	 |	 } fdd|D }|S )Ng       @c                s   g | ]}|  jqS r   )rF   r>   )r0   r   )r   r   r   
<listcomp>  s    z(CartesianProj.xy2vec.<locals>.<listcomp>)
r5   rA   rM   rP   rS   r   rC   r
   rm   flatten)r   r'   r(   r!   rk   r   rI   r   )r   r   r*     s    zCartesianProj.xy2vecc             C   s   | j tj|||d|dS )N)r    )r!   )r&   r
   rm   )r   r   r   r    r!   r   r   r   r"     s    zCartesianProj.ang2xyc             C   s   | j |||d}tj||dS )N)r!   )r    )r*   r
   rn   )r   r'   r(   r    r!   rI   r   r   r   r)     s    zCartesianProj.xy2angc       
      C   sp  | j d krtdt| j d }t| j d }| j d }| j d }|d krZt|\}}nt|t| }}t||d  |d |d   |d  tj}t||d  |d |d   |d  tj}t|j	dkr8|dk ||kB |dk B ||kB }	|	
 stjj}	tjj||	d}tjj||	d}n0|dk s`||ks`|dk s`||krhd  }}||fS )	Nz@No projection plane array information defined for this projectorr`   ra   r   r   r   r   )r:   )r^   ro   rp   r5   rA   rq   rr   Zint64r   r>   rh   r7   r;   r9   )
r   r'   r(   r`   ra   r   r   r-   r,   r:   r   r   r   r+     s.    


** 
(zCartesianProj.xy2ijc             C   sT  | j d krtdt| j d }t| j d }| j d }| j d }|d k	rb|d krbt|\}}n&|d k	r|d k	rt|t| }}|d kr@|d kr@tt|t|}t|d |d  |d  | }||d 7 }tt|t|}t|d |d  |d  | }	|	|d 7 }	tj	
|	}	tj	
|}n|d k	rD|d k	rDt|d |d  |d  | }||d 7 }t|d |d  |d  | }	|	|d 7 }	t|jdkr|	d	k |	d
kB |dk B |dkB }
|
 stj	j}
tj	j
|	|
d}	tj	j
||
d}n2|	d	k s8|	d
ks8|dk s8|dkrLtj }	}ntd|	|fS )Nz@No projection plane array information defined for this projectorr`   ra   r   r   r   r   g      ?iLrR   ir   )r:   z,i and j must be both given or both not given)r^   ro   rp   r5   rA   rv   rx   rw   r   r7   r9   r   r>   rh   r;   rj   )r   r,   r-   r`   ra   r   r   ry   r(   r'   r:   r   r   r   r.     sF    


     
(zCartesianProj.ij2xyc             C   s0   | j d }| j d }|d |d |d |d fS )Nr   r   r   r   )r^   )r   r   r   r   r   r   rO     s    

zCartesianProj.get_extentc             C   sv   t | jd }t | jd }t| j| dddd}t| j| |d |d dd}t||  }d| S )Nr`   ra   r   T)r!   r   r/   )rp   r^   r5   rA   r*   r.   r~   sum)r   r`   ra   Zv1Zv2r   r   r   r   rQ     s    $zCartesianProj.get_fovc             C   sL   | j d }| j d }d|d |d   }d|d |d   }| j|||dS )Nr   r   g      ?r   r   )r    )r^   r)   )r   r    r   r   rt   ru   r   r   r   rU     s
    

zCartesianProj.get_center)NNr   NNN)NNF)NF)NFF)NFF)N)NN)F)rX   rY   rZ   r[   r\   r   r   r&   r   r*   r"   r)   r+   r.   rO   rQ   rU   r   r   r   )rd   r   r   I  s4        #





(

r   c                   s   e Zd ZdZdZd fdd	Z fdd	Zdd
dZejjeef e_dddZ	ej	jeef e	_dddZ
ej
jeef e
_dddZejjeef e_dddZejjeef e_dddZejjeef e_dd Zejje_  ZS )OrthographicProjz7This class provides methods for orthographic projectionZOrthographicN   Fc                s$   t t| jf ||||d| d S )N)r   r	   r`   half_sky)rc   r   r   )r   r   r	   r`   r   r   )rd   r   r   r     s    zOrthographicProj.__init__c                s   t t| j||d d S )N)r`   r   )rc   r   r   )r   r`   r   )rd   r   r   r   $  s    
z$OrthographicProj.set_proj_plane_infoc             C   s  |st | |||\}}nt |||\}}| jd krBtd| jd }| j}||t  dt  t }td | }	t|	t	| }
|s|
d8 }
t	|	}t|	t| }t
|dk r|dk }t|
dr|rtj|
|< n|
|  d9  < n|r|rtj}
n|
d9 }
|r<t|
d t|d  dk}n0tt|
d dd d t|d  dk}|
 rt|
dstj}
tj}ntj|
|< tj||< |
|fS )	Nz@No projection plane array information defined for this projectorr   r/   g       @g      ?r   rg   rL   )r
   rn   r   r^   ro   rM   rP   r5   r   r   rh   ri   rj   rA   r   )r   r#   r$   r%   r!   r   r   r   rk   rT   r'   r(   ZcoscZhmaskr:   r   r   r   r&   )  sJ    



" 


zOrthographicProj.vec2xyc             C   s  |d kr|\}}t |dr0t|t| }}| jd krBtd| jd }| j}d }|st |drt|dkr|dk}||  d9  < n|dkrd}| }|d7 }t|d |d  }t |drtj||d	k< n|d	krtj}t	|}t |drtj|t
|d	k< nt
|d	kr&tj}t	|}	t|t|}
|
|9 }
|d k	rzt |
drrt|
|  |
|< nt|
 }
td
 |	 }t||
}|s| j|S |S d S )Nrg   z@No projection plane array information defined for this projectorr   g        rL   r   g      ?r/   r   g       @)ri   r5   rA   r^   ro   rM   rh   rl   rj   r   r   arctan2r   rP   r
   rm   r   rC   )r   r'   r(   r!   r   rk   r:   rcrT   r   r   rI   r   r   r   r*   Z  sR    







zOrthographicProj.xy2vecc             C   s   | j tj|||d|dS )N)r    )r!   )r&   r
   rm   )r   r   r   r    r!   r   r   r   r"     s    zOrthographicProj.ang2xyc             C   s   t j| j|||d|dS )N)r!   )r    )r
   rn   r*   )r   r'   r(   r    r!   r   r   r   r)     s    zOrthographicProj.xy2angc             C   s  | j d krtdt| j d }| j d }|r4d}nd}|| }|d krXt|\}}nt|t| }}|d d |d d  }}t|dr0|r|d |d  dk}	n$t|d dd d |d  dk}	|	 stjj	}	tjj
t|| | | t|	d	}
tjj
t|||  t|	d	}n|rL|d |d  dksx|st|d dd d |d  dkrtjtj }}
n4t|| | | t}
t|||  t}||
fS )
Nz@No projection plane array information defined for this projectorr`   r   r   r/   g      ?g       @rg   )r:   )r^   ro   rp   r5   rA   ri   r   rh   r7   r;   r9   rq   rr   rj   )r   r'   r(   r`   r   r   ra   rt   ru   r:   r-   r,   r   r   r   r+     s8    

$(&,zOrthographicProj.xy2ijc             C   s  | j d krtdt| j d }| j d }|r4d}nd}|| }|d d |d d  }}|d kr|d krtt|t|}	|	| | }
tt|t|}	||	|  | }n|d k	r|d k	rt|| | }
|t||  | }nN|d k	r8|d kr8|\}}t|| | }
|t||  | }ntd|r\|d |
d  dk}n$t|d dd d |
d  dk}|	 stj
j}tj
j||d	}tj
j|
|d	}
t|d
kr|d
 }t|
d
kr|
d
 }
||
fS )Nz@No projection plane array information defined for this projectorr`   r   r   r/   g      ?g       @z,i and j must be both given or both not given)r:   r   )r^   ro   rp   r5   rv   rx   rw   rA   r   rh   r7   r;   r9   r   )r   r,   r-   r`   r   r   ra   rt   ru   ry   r(   r'   r:   r   r   r   r.     sF    

$
zOrthographicProj.ij2xyc             C   s8   | j d krtd| j d }|r&d}nd}| |ddfS )Nz@No projection plane array information defined for this projectorr   g      ?g       @g      )r^   ro   )r   r   r   r   r   r   rO     s    

zOrthographicProj.get_extent)NNr   F)NNF)NF)NFF)NFF)N)NN)rX   rY   rZ   r[   r\   r   r   r&   r   r*   r"   r)   r+   r.   rO   r   r   r   )rd   r   r     s$   
/
/


'
+r   c                   s   e Zd ZdZdZd fdd	Zd fd
d	ZdddZejjeef e_dddZ	ej	jeef e	_d ddZ
ej
jeef e
_d!ddZejjeef e_d"ddZejjeef e_d#ddZejjeef e_dd Zejje_dd Z  ZS )$AzimuthalProjzuThis class provides methods for Lambert azimuthal equal-area projection and
    azimuthal equidistant projection
    Z	AzimuthalNc       	   
      s*   t t| jf |||||||d| d S )N)r   r	   r`   ra   rb   lambr   )rc   r   r   )	r   r   r	   r`   ra   rb   r   r   r   )rd   r   r   r     s    zAzimuthalProj.__init__         ?TFc                sZ   |d krd}|d kr|}|d kr$d}|d kr0d}|d kr<d}t t| j|||||d d S )Ni   g      ?TF)r`   ra   rb   r   r   )rc   r   r   )r   r`   ra   rb   r   r   )rd   r   r   r     s    
z!AzimuthalProj.set_proj_plane_infoc             C   s  |st | |||\}}nt |||\}}| jd krBtd| j}| jd }| jd }	||t dt  t  }td | }
|rtddt	|
t	|   }n(t
t	|
t	| }|t| }|t	|
 t| }|t|
 }|rd}ntd }|	r(|r |d }n|d }t|d t|d  |k}t|dsp|tjjk	rtjtjfS ntj||< tj||< ||fS )	Nz@No projection plane array information defined for this projectorr   r   r/   g       @g      ?g      @rg   )r
   rn   r   r^   ro   rM   rP   r5   rl   r   r~   r   rA   ri   r7   r;   rj   )r   r#   r$   r%   r!   r   r   rk   r   r   rT   Zkprimer   r'   r(   r2maxr:   r   r   r   r&   (  s>    


$
 

zAzimuthalProj.vec2xyc             C   s  |d kr|\}}t |dr0t|t| }}| jd krBtd| j}| jd }| jd }|rfd}ntd }|r|r|d }n|d }t|d t|d  |k}| stjj	}t |ds|tjj	k	rtj
tj
tj
fS t|d |d  }	|rdt|	d  }
n|	}
t|t|
 |	 }t|t|
 |	t|
 }||9 }ttd | |}|sz| j|S |S n |dk}t|jtj
 t|jtj
 t|jtj
 f}t|| d || d  }	|rdt|	d  }
n|	}
t|| t|
 |	 }t|| t|
 |	t|
 }||9 }t|t| |d	 |< t|t| |d
 |< t||d |< |s| j|S |S d S )Nrg   z@No projection plane array information defined for this projectorr   r   g      @r/   g       @Fr   r   )ri   r5   rA   r^   ro   rM   rP   rh   r7   r;   rj   rl   r   r   r   r   r
   rm   r   rC   r=   r>   )r   r'   r(   r!   rk   r   r   r   r:   rhor   rT   r   rI   rH   r   r   r   r*   R  sf    




  $zAzimuthalProj.xy2vecc             C   s   | j tj|||d|dS )N)r    )r!   )r&   r
   rm   )r   r   r   r    r!   r   r   r   r"     s    zAzimuthalProj.ang2xyc             C   s   t j| j|||d|dS )N)r!   )r    )r
   rn   r*   )r   r'   r(   r    r!   r   r   r   r)     s    zAzimuthalProj.xy2angc             C   s  | j d krtdt| j d }t| j d }| j d }| j d }| j d }|rVd}ntd }|rx|rp|d	 }n|d }|d kr|\}}|d
 t }	d|d  d|d   }
}t|dr(|d |d  |k}| stjj	}tjj
t|
||	  t|d}tjj
t|||	  t|d}nV|d |d  |krNtjtj }}n0t|
||	  t}t|||	  t}||fS )Nz@No projection plane array information defined for this projectorr`   ra   rb   r   r   g      @r/   g       @g      N@g      ?r   rg   )r:   )r^   ro   rp   rP   rS   ri   rh   r5   r7   r;   r9   rq   rr   rj   )r   r'   r(   r`   ra   rb   r   r   r   rs   rt   ru   r:   r-   r,   r   r   r   r+     s>    




$&zAzimuthalProj.xy2ijc             C   s  | j d krtdt| j d }t| j d }| j d }| j d }| j d }|d t }d|d	  d|d	   }	}
|r|d
}ntd }|r|r|d }n|d
 }|d kr|d krtt|t|}||
 | }tt|t|}||	 | }n|d k	r2|d k	r2t	||
 | }t	||	 | }nJ|d k	rt|d krt|\}}t	||
 | }t	||	 | }ntdt
|dr|d |d  |k}| stjj}tjj||d}tjj||d}n$|d |d  |krtjtj }}||fS )Nz@No projection plane array information defined for this projectorr`   ra   rb   r   r   g      N@g      ?r   g      @r/   g       @z,i and j must be both given or both not givenrg   )r:   )r^   ro   rp   rS   rP   r5   rv   rx   rw   rA   ri   rh   r7   r;   r9   rj   )r   r,   r-   r`   ra   rb   r   r   rs   rt   ru   r   ry   r(   r'   r:   r   r   r   r.     sN    





zAzimuthalProj.ij2xyc             C   s   t | jd }t | jd }| jd }|d t }d|d  d|d   }}| | }| | }|d | | }	|d | | }
||	||
fS )Nr`   ra   rb   g      N@g      ?r   )rp   r^   rS   )r   r`   ra   rb   rs   rt   ru   rz   r{   r|   r}   r   r   r   rO     s    


zAzimuthalProj.get_extentc             C   sV   | j d }| j| dddd\}}}t|}t|rBd| S |rJtS dt S d S )Nr   r   T)r!   g       @)r^   r*   r.   r5   r~   isfiniterP   )r   r   r#   r$   r%   r   r   r   r   rQ     s    


zAzimuthalProj.get_fov)NNNNNNN)r   Nr   TF)NNF)NF)NFF)NFF)N)NN)rX   rY   rZ   r[   r\   r   r   r&   r   r*   r"   r)   r+   r.   rO   rQ   r   r   r   )rd   r   r     s2         
(
@


(
.
r   )r[    r   r
   numpyr5   r   r   rP   rS   objectr   r_   r   r   r   r   r   r   r   r   <module>   s"   
 ^  ? R a