B
    {‹d  ã               @   sN  d Z ddlZddlmZ ddlmZmZ ddl	m
Z
mZmZmZmZmZmZmZmZmZmZmZmZmZ dej Zejd Zd	d
ddddddddddddddgZd.dd„Zd/dd„Zd0dd	„Zd1dd
„Zd d„ Z d!d„ Z!d"d„ Z"d2d#d„Z#d3d$d„Z$d4d%d„Z%d5d&d„Z&d'd„ Z'd(d„ Z(d6d)d„Z)d7d*d„Z*d8d+d„Z+d9d,d„Z,d:d-d„Z-dS );z8
This submodule provides a healpy-compatible interface.
é    N)Úunits)ÚCartesianRepresentationÚUnitSphericalRepresentationé   )Únside_to_pixel_resolutionÚnside_to_pixel_areaÚnside_to_npixÚnpix_to_nsideÚnested_to_ringÚring_to_nestedÚlevel_to_nsideÚlonlat_to_healpixÚhealpix_to_lonlatÚxyz_to_healpixÚhealpix_to_xyzÚboundaries_lonlatÚbilinear_interpolation_weightsÚinterpolate_bilinear_lonlaté´   é   Únside2resolÚnside2pixareaÚ
nside2npixÚ
npix2nsideÚpix2angÚang2pixÚpix2vecÚvec2pixÚorder2nsideÚ	nest2ringÚ	ring2nestÚ
boundariesÚvec2angÚang2vecÚget_interp_weightsÚget_interp_valFc             C   sp   |r |   tj¡j|  tj¡jfS |  tj¡j|   tj¡j }} t | ¡rTt| | fS tjt||d}|| fS d S )N)Úout)	ÚtoÚuÚdegÚvalueÚradÚnpZisscalarÚPI_2Úsubtract)ÚlonÚlatÚlonlat© r2   úc/work/yifan.wang/ringdown/master-ringdown-env/lib/python3.7/site-packages/astropy_healpix/healpy.pyÚ_lonlat_to_healpy&   s    
r4   c             C   s^   |r"t  | ¡t }t  |¡t }ntt  | ¡ }t  |¡}tj|tjddtj|tjddfS )NF)Úcopy)r,   ÚasarrayÚRAD2DEGr-   r(   ZQuantityr+   )ÚthetaÚphir1   r/   r0   r2   r2   r3   Ú_healpy_to_lonlat5   s    
r:   c             C   s,   t | ƒ}|r| tj¡jS | tj¡jS dS )z?Drop-in replacement for healpy `~healpy.pixelfunc.nside2resol`.N)r   r'   r(   Úarcminr*   r+   )Únsider;   Ú
resolutionr2   r2   r3   r   B   s    c             C   s0   t | ƒ}|r| tjd ¡jS | tj¡jS dS )zADrop-in replacement for healpy `~healpy.pixelfunc.nside2pixarea`.r   N)r   r'   r(   r)   r*   Úsr)r<   ÚdegreesZarear2   r2   r3   r   K   s    c             C   s   t | ƒS )z>Drop-in replacement for healpy `~healpy.pixelfunc.nside2npix`.)r   )r<   r2   r2   r3   r   T   s    c             C   s   t | ƒS )z>Drop-in replacement for healpy `~healpy.pixelfunc.npix2nside`.)r	   )Znpixr2   r2   r3   r   Y   s    c             C   s   t | ƒS )z?Drop-in replacement for healpy `~healpy.pixelfunc.order2nside`.)r   )Úorderr2   r2   r3   r   ^   s    c             C   s(   t || |rdndd\}}t|||dS )z;Drop-in replacement for healpy `~healpy.pixelfunc.pix2ang`.ÚnestedÚring)r@   )r1   )r   r4   )r<   ÚipixÚnestr1   r/   r0   r2   r2   r3   r   c   s    c             C   s*   t |||d\}}t||| |r"dnddS )z;Drop-in replacement for healpy `~healpy.pixelfunc.ang2pix`.)r1   rA   rB   )r@   )r:   r   )r<   r8   r9   rD   r1   r/   r0   r2   r2   r3   r   i   s    c             C   s   t || |rdnddS )z;Drop-in replacement for healpy `~healpy.pixelfunc.pix2vec`.rA   rB   )r@   )r   )r<   rC   rD   r2   r2   r3   r   o   s    c             C   s   t |||| |rdnddS )z;Drop-in replacement for healpy `~healpy.pixelfunc.vec2pix`.rA   rB   )r@   )r   )r<   ÚxÚyÚzrD   r2   r2   r3   r   t   s    c             C   s    t  |¡jt jdd}t|| ƒS )z=Drop-in replacement for healpy `~healpy.pixelfunc.nest2ring`.F)r5   )r,   Ú
atleast_1dÚastypeÚint64r
   )r<   rC   r2   r2   r3   r   y   s    c             C   s    t  |¡jt jdd}t|| ƒS )z=Drop-in replacement for healpy `~healpy.pixelfunc.ring2nest`.F)r5   )r,   rH   rI   rJ   r   )r<   rC   r2   r2   r3   r       s    c             C   st   t  |¡}|jdkrtdƒ‚t||| |r,dndd\}}t||ƒ}| ¡ jj 	dd¡}|j
d dkrl|d S |S dS )z4Drop-in replacement for healpy `~healpy.boundaries`.r   zArray has to be one dimensionalrA   rB   )r@   r   N)r,   r6   ÚndimÚ
ValueErrorr   r   Zto_cartesianÚxyzr*   ZswapaxesÚshape)r<   ZpixÚsteprD   r/   r0   Úrep_sphÚrep_carr2   r2   r3   r!   …   s    


c             C   s>   |   ¡ \}}}t|||ƒ}| t¡}t|j ¡ |j ¡ |dS )z;Drop-in replacement for healpy `~healpy.pixelfunc.vec2ang`.)r1   )Z	transposer   Úrepresent_asr   r4   r/   Zravelr0   )Zvectorsr1   rE   rF   rG   rQ   rP   r2   r2   r3   r"   ”   s    
c             C   s.   t | ||d\}}t||ƒ}| t¡}|jjS )z;Drop-in replacement for healpy `~healpy.pixelfunc.ang2vec`.)r1   )r:   r   rR   r   rM   r*   )r8   r9   r1   r/   r0   rP   rQ   r2   r2   r3   r#   œ   s    

c             C   sD   |dkrt | ||d\}}t|||d\}}t||| |r<dnddS )z˜
    Drop-in replacement for healpy `~healpy.pixelfunc.get_interp_weights`.

    Although note that the order of the weights and pixels may differ.
    N)rC   rD   )r1   rA   rB   )r@   )r   r:   r   )r<   r8   r9   rD   r1   r/   r0   r2   r2   r3   r$   ¤   s    c             C   s*   t |||d\}}t||| |r"dnddS )zL
    Drop-in replacement for healpy `~healpy.pixelfunc.get_interp_val`.
    )r1   rA   rB   )r@   )r:   r   )Úmr8   r9   rD   r1   r/   r0   r2   r2   r3   r%   ²   s    )F)F)F)F)FF)FF)F)F)r   F)F)F)NFF)FF).Ú__doc__Únumpyr,   Zastropyr   r(   Z"astropy.coordinates.representationr   r   Úcorer   r   r   r	   r
   r   r   r   r   r   r   r   r   r   Úpir7   r-   Ú__all__r4   r:   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r2   r2   r2   r3   Ú<module>   sP   @




	
	







