U
    e»{j\=  ã                   @   s0  d Z ddlZddlm  mZ ddlmZ ddlm	Z	m
Z
 ddlmZ ddlmZ ddlmZ dd„ Zd	d
„ Zdd„ Zejje dd�dd„ ƒZejje dd�dd„ ƒZejje dd�dd„ ƒZejje dd�ej dejjd dddg¡dd„ ƒƒZdd„ Zejje dd�G dd„ dƒƒZd d!„ ZdS )"z'Testing :mod:`astropy.cosmology.units`.é    N)ÚPlanck13Údefault_cosmology)Úassert_quantity_allclose)Ú	HAS_SCIPY)ÚAstropyDeprecationWarningc                	   C   s0   t jtdd�� tjjtjks"t‚W 5 Q R X dS )a7  
    Test that this module has the expected set of units. Some of the units are
    imported from :mod:`astropy.units`, or vice versa. Here we test presence,
    not usage. Units from :mod:`astropy.units` are tested in that module. Units
    defined in :mod:`astropy.cosmology` will be tested subsequently.
    z	`littleh`©ÚmatchN)ÚpytestÚwarnsr   ÚuZ	astrophysÚlittlehÚcuÚAssertionError© r   r   úa/var/www/html/bwave/python/venv/lib/python3.8/site-packages/astropy/cosmology/tests/test_units.pyÚtest_has_expected_units   s    r   c                	   C   s0   t jtdd�� tjjtjks"t‚W 5 Q R X dS )aO  
    Test that this module has the expected set of equivalencies. Many of the
    equivalencies are imported from :mod:`astropy.units`, so here we test
    presence, not usage. Equivalencies from :mod:`astropy.units` are tested in
    that module. Equivalencies defined in :mod:`astropy.cosmology` will be
    tested subsequently.
    z	`with_H0`r   N)r	   r
   r   r   ÚequivalenciesÚwith_H0r   r   r   r   r   r   Útest_has_expected_equivalencies   s    r   c                  C   s  dt j t j t j } dt j tj }t| t jt | ¡¡dt j ƒ t	 
¡ jjt j tj }t| t jt ¡ ¡dt j ƒ dt j tjd  }t| t jt | ¡¡dt j ƒ dt j t j t j }dt jt  tjd ¡  }t| t jt |¡¡d	t j ƒ d
S )z-Test :func:`astropy.cosmology.units.with_H0`.éF   éd   g\�Âõ(\ß?éþÿÿÿé   é
   é   é   é   N)r   ÚkmÚsÚMpcr   r   r   Útor   r   ÚgetÚH0ÚvalueZLsunÚmagZMagUnit)ZH0_70Zh70distZ	cosmodistZh1lumZH0_10Zwithlittlehmagr   r   r   Útest_littleh+   s      r%   zCosmology needs scipy)Úreasonc               
   C   s  dt j } dtj }| jt jks$t‚| jtjks4t‚t | ¡dksFt‚| |ksRt‚dt jd  |ksht‚dtj t jd  dtj ksŠt‚t g ¡�D | j	tjt  
¡ d�|ks²t‚t t¡� |  	tj¡ W 5 Q R X W 5 Q R X t t  
¡ ¡� | |ksút‚W 5 Q R X dS )z<Test :func:`astropy.cosmology.units.dimensionless_redshift`.é   Úredshift)r   N)r   r(   r   ÚoneÚunitr   Zget_physical_typer   Zset_enabled_equivalenciesr    Zdimensionless_redshiftr	   ÚraisesÚ
ValueErrorZadd_enabled_equivalencies)ÚzÚvalr   r   r   Útest_dimensionless_redshiftB   s    

" r/   c               	   C   s   t jdtj d�} t ¡ }dtj }|  |¡}t 	| ¡�6 t 
¡ }t| tj|¡|ƒ t| tj|¡|ƒ W 5 Q R X t 
¡ }t| tj|¡| |¡ƒ | |¡|ks¨t‚t 
| ¡}t| tj|¡|ƒ t| tj|¡|ƒ tj
| dd�}t| tj|¡|ƒ dS )z:Test :func:`astropy.cosmology.units.redshift_temperature`.r'   ©ZTcmb0é   ç»½×Ùß|Û=©ÚztolN)r   Úcloner   ÚKr   r!   r   r(   ÚTcmbÚsetZredshift_temperaturer   r    r   )ÚcosmoÚdefault_cosmor-   r7   Úequivalencyr   r   r   Útest_redshift_temperatureb   s     


r<   c               	   C   s�  t jt j t j } tjd|  d�}t ¡ }dtj	 }| 
|¡}| t jt j t j ¡d tj }t |¡�\ t ¡ }t| | |¡|ƒ t| tj	|¡|ƒ t| tj|¡|ƒ t| tj	|¡|ƒ W 5 Q R X t ¡ }t| | |¡| 
|¡ƒ | 
|¡|ksþt‚t |¡}t| | |¡|ƒ t| tj	|¡|ƒ t| tj|¡|ƒ t| tj	|¡|ƒ tj|dd�}t| tj	|¡|ƒ t| tj	|¡|ƒ dS )z5Test :func:`astropy.cosmology.units.redshift_hubble`.r   )r"   r1   r2   r3   N)r   r   r   r   r   r5   r   r!   r   r(   ÚHÚto_valuer   r8   Zredshift_hubbler   r    r   )r*   r9   r:   r-   r=   Úhr;   r   r   r   Útest_redshift_hubble€   s.    

"
r@   ÚkindéÿÿÿÿÚcomovingÚlookbackÚ
luminosityc                 C   s”   dt j }tt| d ƒ|ƒ}t jt| d�}|jd dks<t‚|jd d tksRt‚|jd d | ksht‚t| 	t
j|¡|ƒ t| 	t j|¡|ƒ dS )	z7Test :func:`astropy.cosmology.units.redshift_distance`.r1   Ú	_distance)Ú	cosmologyrA   r   Úredshift_distancerG   ÚdistanceN)r   r(   Úgetattrr   rH   Únamer   Úkwargsr   r    r   r   )rA   r-   Údr;   r   r   r   Útest_redshift_distance©   s    
rN   c                	   C   s*   t jtdd�� tjdd� W 5 Q R X dS )zBTest :func:`astropy.cosmology.units.redshift_distance` wrong kind.ú`kind`r   N)rA   )r	   r+   r,   r   rH   r   r   r   r   Ú!test_redshift_distance_wrong_kind¿   s    rP   c                   @   sˆ   e Zd ZdZejdd�dd„ ƒZdd„ Zdd	„ Zd
d„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zej ddddg¡dd„ ƒZdS )ÚTest_with_redshiftz-Test `astropy.cosmology.units.with_redshift`.Úclass)Úscopec                 C   s   t jdtj d�S )zTest cosmology.r'   r0   )r   r5   r   r6   ©Úselfr   r   r   r9   É   s    zTest_with_redshift.cosmoc                 C   s   t  ¡ }||kst‚dS )z1The default is different than the test cosmology.N)r   r!   r   )rU   r9   r:   r   r   r   Útest_cosmo_differentÐ   s    z'Test_with_redshift.test_cosmo_differentc                 C   s$   t jdddd�}t|ƒdks t‚dS )z<Test the equivalency  ``with_redshift`` without any enabled.NF)rI   Úhubbler7   r   )r   Úwith_redshiftÚlenr   )rU   r9   r;   r   r   r   Útest_no_equivalencyÕ   s    z&Test_with_redshift.test_no_equivalencyc              
   C   s–   dt j }d}t |¡�< t jdd�}tjtj|d�� | 	tj
|¡ W 5 Q R X W 5 Q R X t j|dd�}tjtj|d�� | 	tj
|¡ W 5 Q R X dS )z0Test ``with_redshift`` with the temperature off.r1   zE^'redshift' \(redshift\) and 'K' \(temperature\) are not convertible$F©r7   r   N)r   r(   r   r8   rX   r	   r+   r   ÚUnitConversionErrorr    r6   ©rU   r9   r-   Úerr_msgr;   r   r   r   Útest_temperature_offÜ   s    
ÿ"z'Test_with_redshift.test_temperature_offc              	   C   s   t  ¡ }dtj }| |¡}t  |¡�: tjdd�}t| t	j
|¡|ƒ t| tj|¡|ƒ W 5 Q R X tjdd�}t| t	j
|¡| |¡ƒ | |¡|ksžt‚tj|dd�}t| t	j
|¡|ƒ t| tj|¡|ƒ tj|dddid�}t| tj|¡|ƒ dS )z'Test temperature equivalency component.r1   Tr[   r4   r2   )r7   ÚatzkwN)r   r!   r   r(   r7   r8   rX   r   r    r   r6   r   )rU   r9   r:   r-   r7   r;   r   r   r   Útest_temperatureî   s    

z#Test_with_redshift.test_temperaturec              
   C   s¤   t jt j t j }dtj }d}t |¡�: tjdd�}t	j
t j|d�� | ||¡ W 5 Q R X W 5 Q R X tj|dd�}t	j
t j|d�� | ||¡ W 5 Q R X dS )z'Test ``with_redshift`` with Hubble off.r1   zP^'redshift' \(redshift\) and 'km / \(Mpc s\)' \(frequency\) are not convertible$F©rW   r   N)r   r   r   r   r   r(   r   r8   rX   r	   r+   r\   r    )rU   r9   r*   r-   r^   r;   r   r   r   Útest_hubble_off  s    
ÿ z"Test_with_redshift.test_hubble_offc              	   C   s’  t jt j t j }t ¡ }dtj }| |¡}| 	t jt j t j ¡d tj
 }t |¡�` tjdd�}t| ||¡|ƒ t| tj|¡|ƒ t| tj
|¡|ƒ t| tj|¡|ƒ W 5 Q R X tjdd�}t| ||¡| |¡ƒ | |¡|ksöt‚tj|dd�}t| ||¡|ƒ t| tj|¡|ƒ t| tj
|¡|ƒ t| tj|¡|ƒ tj|dddid�}t| tj|¡|ƒ t| tj|¡|ƒ dS )	z"Test Hubble equivalency component.r1   r   Trb   r4   r2   )rW   r`   N)r   r   r   r   r   r!   r   r(   r=   r>   r   r8   rX   r   r    r   )rU   r9   r*   r:   r-   r=   r?   r;   r   r   r   Útest_hubble   s,    

"zTest_with_redshift.test_hubblec              
   C   s–   dt j }d}t |¡�< t jdd�}tjtj|d�� | 	tj
|¡ W 5 Q R X W 5 Q R X t j|dd�}tjtj|d�� | 	tj
|¡ W 5 Q R X dS )z-Test ``with_redshift`` with the distance off.r1   zB^'redshift' \(redshift\) and 'Mpc' \(length\) are not convertible$N©rI   r   )r   r(   r   r8   rX   r	   r+   r   r\   r    r   r]   r   r   r   Útest_distance_offI  s    
"z$Test_with_redshift.test_distance_offc                 C   sL   dt j }t ¡  |¡}t  ¡ }t| tj	|¡|ƒ t| t j|¡|ƒ dS )z"Test distance equivalency default.r1   N)
r   r(   r   r!   Zcomoving_distancerX   r   r    r   r   )rU   r-   rM   r;   r   r   r   Útest_distance_defaultY  s
    
z(Test_with_redshift.test_distance_defaultc              	   C   s*   t jtdd�� tjtd� W 5 Q R X dS )z.Test distance equivalency, but the wrong kind.rO   r   re   N)r	   r+   r,   r   rX   rT   r   r   r   Útest_distance_wrong_kindb  s    z+Test_with_redshift.test_distance_wrong_kindrA   rC   rD   rE   c              	   C   s  t }dtj }t||d ƒ|ƒ}t ¡ }||ks4t‚t |¡�& tj|d�}t	| 
tj|¡|ƒ W 5 Q R X tj|d�}t	| 
tj|¡t||d ƒ|ƒƒ t t||d ƒ|ƒ|¡r¶t‚tj||d�}t	| 
tj|¡|ƒ t	| 
tj|¡|ƒ tj||ddid�}t	| 
tj|¡|ƒ dS )zTest distance equivalency.r1   rF   re   r4   r2   )rI   r`   N)r   r   r(   rJ   r   r!   r   r8   rX   r   r    r   r   Zallclose)rU   rA   r9   r-   Údistr:   r;   r   r   r   Útest_distanceg  s&    
 ÿz Test_with_redshift.test_distanceN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r	   Zfixturer9   rV   rZ   r_   ra   rc   rd   rf   rg   rh   ÚmarkÚparametrizerj   r   r   r   r   rQ   Å   s   

)	rQ   c                  C   s8   t  ¡ } t| jƒdkst‚t| jd d ƒdks4t‚d S )Nr   r   r(   )r   Zget_current_unit_registryrY   r   r   Ústr)Zbase_registryr   r   r   Ú test_equivalency_context_manager‰  s    rr   ) rn   r	   Zastropy.cosmology.unitsrG   Zunitsr   Zastropy.unitsr   Zastropy.cosmologyr   r   Zastropy.tests.helperr   Z"astropy.utils.compat.optional_depsr   Zastropy.utils.exceptionsr   r   r   r%   ro   Zskipifr/   r<   r@   rp   rH   Ú__defaults__rN   rP   rQ   rr   r   r   r   r   Ú<module>   s6   


(þ D