
    HR-e\=                     |   d Z ddlZddlmc 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 Zd Zd	 Zej                            e d
          d             Zej                            e d
          d             Zej                            e d
          d             Zej                            e d
          ej                            dej        j        d         dddg          d                         Zd Zej                            e d
           G d d                      Zd ZdS )z'Testing :mod:`astropy.cosmology.units`.    N)Planck13default_cosmology)assert_quantity_allclose)	HAS_SCIPY)AstropyDeprecationWarningc                      t          j        t          d          5  t          j        j        t          j        u sJ 	 ddd           dS # 1 swxY w Y   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   u	astrophyslittlehcu     Blib/python3.11/site-packages/astropy/cosmology/tests/test_units.pytest_has_expected_unitsr      s     
/{	C	C	C 1 1{"bj000001 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1    A

AAc                      t          j        t          d          5  t          j        j        t          j        u sJ 	 ddd           dS # 1 swxY w Y   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   test_has_expected_equivalenciesr      s     
/{	C	C	C 5 5&"*444445 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5r   c                  V   dt           j        z  t           j        z  t           j        z  } dt           j        z  t          j        z  }t          |                    t           j        t	          j        |                     dt           j        z             t          j
                    j        j        t           j        z  t          j        z  }t          |                    t           j        t	          j                              dt           j        z             dt           j        z  t          j        dz  z  }t          |                    t           j        t	          j        |                     dt           j        z             dt           j        z  t           j        z  t           j        z  }dt           j        t          j        t          j        dz            z
  z  }t          |                    t           j        t	          j        |                    d	t           j        z             d
S )z-Test :func:`astropy.cosmology.units.with_H0`.F   d   g\(\?   
            N)r   kmsMpcr   r   r   tor   r   getH0valueLsunmagMagUnit)H0_70h70dist	cosmodisth1lumH0_10withlittlehmags         r   test_littlehr3   +   si   IOae#E15j2:%GWZZrz%/@/@AA3;OOO "%''*01582:EIY\\!%>>aeLLL 16MBJN*EUXXafbj.?.?@@!af*MMM IOae#E 1519RZ]#;#;;<N^..qubj6G6GHH"qu*UUUUUr   zCosmology needs scipy)reasonc                  l   dt           j        z  } dt          j        z  }| j        t           j        k    sJ | j        t          j        k    sJ t          j        |           dk    sJ | |k    sJ dt           j        dz  z  |k    sJ dt          j        z  t           j        dz  z  dt          j        z  k    sJ t          j        g           5  |                     t          j        t          j	                              |k    sJ t          j        t                    5  |                     t          j                   ddd           n# 1 swxY w Y   ddd           n# 1 swxY w Y   t          j        t          j	                              5  | |k    sJ 	 ddd           dS # 1 swxY w Y   dS )z<Test :func:`astropy.cosmology.units.dimensionless_redshift`.   redshift)r   N)r   r7   r   oneunitget_physical_typer#   set_enabled_equivalenciesr&   dimensionless_redshiftr   raises
ValueErroradd_enabled_equivalencies)zvals     r   test_dimensionless_redshiftrB   B   sN    	
BKA
ae)C 6R[    6QU????q!!Z//// 8888 Q3&&&& Hr{A~%!ad(2222 
	$R	(	(  ttAE)B)D)DtEELLLL]:&& 	 	DDKKK	 	 	 	 	 	 	 	 	 	 	 	 	 	 	               
	$R%>%@%@	A	A  Cxxxxx                 sI   AE" E?E"E	E"E	E""E&)E&	F))F-0F-c                  4   t          j        dt          j        z            } t	          j                    }dt          j        z  }|                     |          }t	          j	        |           5  t          j
                    }t          |                    t          j        |          |           t          |                    t          j        |          |           ddd           n# 1 swxY w Y   t          j
                    }t          |                    t          j        |          |                    |                     |                    |          |k    sJ t          j
        |           }t          |                    t          j        |          |           t          |                    t          j        |          |           t          j
        | d          }t          |                    t          j        |          |           dS )z:Test :func:`astropy.cosmology.units.redshift_temperature`.r6   Tcmb0   N绽|=ztol)r   cloner   Kr   r'   r   r7   Tcmbsetredshift_temperaturer   r&   )cosmodefault_cosmor@   rL   equivalencys        r   test_redshift_temperaturerR   b   s    NQS)))E%)++M
R[A::a==D 
	u	%	% G G-// ac;!7!7>>> k!B!BAFFFG G G G G G G G G G G G G G G )++KQTT!#{33]5G5G5J5JKKKa  D(((( )%00KQTT!#{33T:::TWWR[+>>BBB )%e<<<KTWWR[+>>BBBBBs   .A0C**C.1C.c                     t           j        t           j        z  t           j        z  } t	          j        d| z            }t          j                    }dt          j	        z  }|
                    |          }|                    t           j        t           j        z  t           j        z            dz  t          j        z  }t          j        |          5  t          j                    }t          |                    | |          |           t          |                    t          j	        |          |           t          |                    t          j        |          |           t          |                    t          j	        |          |           ddd           n# 1 swxY w Y   t          j                    }t          |                    | |          |
                    |                     |
                    |          |k    sJ t          j        |          }t          |                    | |          |           t          |                    t          j	        |          |           t          |                    t          j        |          |           t          |                    t          j	        |          |           t          j        |d          }t          |                    t          j	        |          |           t          |                    t          j	        |          |           dS )z5Test :func:`astropy.cosmology.units.redshift_hubble`.r   )r(   rF   NrG   rH   )r   r#   r$   r%   r   rJ   r   r'   r   r7   Hto_valuer   rM   redshift_hubbler   r&   )r9   rO   rP   r@   rT   hrQ   s          r   test_redshift_hubblerX      s    4!#:DNcDj)))E%)++M
R[A

A	

14!#:%&&,rz9A 
	u	%	% D D(** dK!8!8!<<< bk;!?!?CCC bj+!>!>BBB bk;!?!?CCCD D D D D D D D D D D D D D D $&&KQTT$44mooa6H6HIII??1"""" $U++KQTT$44a888QTT"+{;;Q???QTT"*k::A>>>QTT"+{;;Q??? $U777KQTT"+{;;Q???QTT"+{;;Q?????s   CF!!F%(F%kindcomovinglookback
luminosityc                    dt           j        z  } t          t          | dz             |          }t          j        t          |           }|j        d         dk    sJ |j        d         d         t          k    sJ |j        d         d         | k    sJ t          |                    t          j
        |          |           t          |                    t           j        |          |           dS )	z7Test :func:`astropy.cosmology.units.redshift_distance`.rF   	_distance)	cosmologyrY   r   redshift_distancer`   distanceN)r   r7   getattrr   ra   namekwargsr   r&   r   r%   )rY   r@   drQ   s       r   test_redshift_distancerg      s     	R[A-$,--a00A&EEEK A"55555a -9999a ,4444 QTT!%55q999QTT"+{;;Q?????r   c                      t          j        t          d          5  t          j        d           ddd           dS # 1 swxY w Y   dS )zBTest :func:`astropy.cosmology.units.redshift_distance` wrong kind.`kind`r	   N)rY   )r   r=   r>   r   ra   r   r   r   !test_redshift_distance_wrong_kindrj      s    	z	2	2	2 ( (
$''''( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( (s   ?AAc                       e Zd ZdZ ej        d          d             Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zej                            dg d          d             ZdS )Test_with_redshiftz-Test `astropy.cosmology.units.with_redshift`.class)scopec                 F    t          j        dt          j        z            S )zTest cosmology.r6   rD   )r   rJ   r   rK   selfs    r   rO   zTest_with_redshift.cosmo   s     ~AG,,,,r   c                 <    t          j                    }||k    sJ dS )z1The default is different than the test cosmology.N)r   r'   )rq   rO   rP   s      r   test_cosmo_differentz'Test_with_redshift.test_cosmo_different   s'    )-//%%%%%%r   c                 ^    t          j        ddd          }t          |          dk    sJ dS )z<Test the equivalency  ``with_redshift`` without any enabled.NF)rb   hubblerL   r   )r   with_redshiftlen)rq   rO   rQ   s      r   test_no_equivalencyz&Test_with_redshift.test_no_equivalency   s8    &UOOO;1$$$$$$r   c                 8   dt           j        z  }d}t          j        |          5  t          j        d          }t          j        t          j        |          5  |	                    t          j
        |           ddd           n# 1 swxY w Y   ddd           n# 1 swxY w Y   t          j        |d          }t          j        t          j        |          5  |	                    t          j
        |           ddd           dS # 1 swxY w Y   dS )z0Test ``with_redshift`` with the temperature off.rF   zE^'redshift' \(redshift\) and 'K' \(temperature\) are not convertible$FrL   r	   N)r   r7   r   rM   rv   r   r=   r   UnitConversionErrorr&   rK   rq   rO   r@   err_msgrQ   s        r   test_temperature_offz'Test_with_redshift.test_temperature_off   s   T 	
 "5)) 	' 	'*666Kq4GDDD ' 'QS+&&&' ' ' ' ' ' ' ' ' ' ' ' ' ' '	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' &u5999]10@@@ 	# 	#DDk"""	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	#G   6B !B	=B 	B	B B	B  B$'B$!!DDDc                    t          j                    }dt          j        z  }|                    |          }t          j        |          5  t          j        d          }t          |                    t          j
        |          |           t          |                    t          j        |          |           ddd           n# 1 swxY w Y   t          j        d          }t          |                    t          j
        |          |                    |                     |                    |          |k    sJ t          j        |d          }t          |                    t          j
        |          |           t          |                    t          j        |          |           t          j        |dddi          }t          |                    t          j        |          |           dS )z'Test temperature equivalency component.rF   Trz   NrI   rG   )rL   atzkw)r   r'   r   r7   rL   rM   rv   r   r&   r   rK   )rq   rO   rP   r@   rL   rQ   s         r   test_temperaturez#Test_with_redshift.test_temperature   s   )-//zz!}} "5)) 	K 	K*555K$QTT!#{%;%;TBBB$TWWR[+%F%FJJJ	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K &D111 ac;!7!79K9KA9N9NOOO!!!$$,,,, &u4888 ac;!7!7>>> k!B!BAFFF &u4OOO k!B!BAFFFFFs   A2C

CCc                 \   t           j        t           j        z  t           j        z  }dt          j        z  }d}t          j        |          5  t	          j        d          }t          j
        t           j        |          5  |                    ||           ddd           n# 1 swxY w Y   ddd           n# 1 swxY w Y   t	          j        |d          }t          j
        t           j        |          5  |                    ||           ddd           dS # 1 swxY w Y   dS )z'Test ``with_redshift`` with Hubble off.rF   zP^'redshift' \(redshift\) and 'km / \(Mpc s\)' \(frequency\) are not convertible$Fru   r	   N)r   r#   r$   r%   r   r7   r   rM   rv   r   r=   r{   r&   )rq   rO   r9   r@   r}   rQ   s         r   test_hubble_offz"Test_with_redshift.test_hubble_off  s   taczAE! 	 "5)) 	( 	(*%888Kq4GDDD ( (T;'''( ( ( ( ( ( ( ( ( ( ( ( ( ( (	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( &uU;;;]10@@@ 	$ 	$DD{###	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$sH   6B<B%B<%B)	)B<,B)	-B<<C C =D!!D%(D%c                 p   t           j        t           j        z  t           j        z  }t	          j                    }dt          j        z  }|                    |          }|	                    t           j        t           j        z  t           j        z            dz  t          j
        z  }t	          j        |          5  t          j        d          }t          |                    ||          |           t          |                    t          j        |          |           t          |                    t          j
        |          |           t          |                    t          j        |          |           ddd           n# 1 swxY w Y   t          j        d          }t          |                    ||          |                    |                     |                    |          |k    sJ t          j        |d          }t          |                    ||          |           t          |                    t          j        |          |           t          |                    t          j
        |          |           t          |                    t          j        |          |           t          j        |dddi          }t          |                    t          j        |          |           t          |                    t          j        |          |           dS )	z"Test Hubble equivalency component.rF   r   Tr   NrI   rG   )ru   r   )r   r#   r$   r%   r   r'   r   r7   rT   rU   r   rM   rv   r   r&   )rq   rO   r9   rP   r@   rT   rW   rQ   s           r   test_hubblezTest_with_redshift.test_hubble   s   taczAE!)-//GGAJJJJqtaczAE)**S02:= "5)) 	H 	H*$777K$QTT$%<%<a@@@$QTT"+{%C%CQGGG$QTT"*k%B%BAFFF$QTT"+{%C%CQGGG	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H &d333 dK!8!8-//!:L:LMMMq!!Q&&&& &uT::: dK!8!8!<<< bk;!?!?CCC bj+!>!>BBB bk;!?!?CCC &uT&%QQQ bk;!?!?CCC bk;!?!?CCCCCs   ;CFFFc                 8   dt           j        z  }d}t          j        |          5  t          j        d          }t          j        t          j        |          5  |	                    t          j
        |           ddd           n# 1 swxY w Y   ddd           n# 1 swxY w Y   t          j        |d          }t          j        t          j        |          5  |	                    t          j
        |           ddd           dS # 1 swxY w Y   dS )z-Test ``with_redshift`` with the distance off.rF   zB^'redshift' \(redshift\) and 'Mpc' \(length\) are not convertible$Nrb   r	   )r   r7   r   rM   rv   r   r=   r   r{   r&   r%   r|   s        r   test_distance_offz$Test_with_redshift.test_distance_offI  s   W "5)) 	) 	)*D999Kq4GDDD ) )QUK((() ) ) ) ) ) ) ) ) ) ) ) ) ) )	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) &ut<<<]10@@@ 	% 	%DD$$$	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	%r   c                 N   dt           j        z  }t          j                                        |          }t          j                    }t          |                    t          j	        |          |           t          |                    t           j        |          |           dS )z"Test distance equivalency default.rF   N)
r   r7   r   r'   comoving_distancerv   r   r&   r   r%   )rq   r@   rf   rQ   s       r   test_distance_defaultz(Test_with_redshift.test_distance_defaultY  s~    !##55a88&(( ae[!9!91=== bk;!?!?CCCCCr   c                     t          j        t          d          5  t          j        t                     ddd           dS # 1 swxY w Y   dS )z.Test distance equivalency, but the wrong kind.ri   r	   r   N)r   r=   r>   r   rv   rp   s    r   test_distance_wrong_kindz+Test_with_redshift.test_distance_wrong_kindb  s    ]:X666 	2 	2j1111	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2s   AAArY   )r[   r\   r]   c           	         t           }dt          j        z  } t          ||dz             |          }t	          j                    }||k    sJ t	          j        |          5  t          j        |          }t          |	                    t          j        |          |           ddd           n# 1 swxY w Y   t          j        |          }t          |	                    t          j        |           t          ||dz             |                     t          j         t          ||dz             |          |          rJ t          j        ||          }t          |	                    t          j        |          |           t          |	                    t          j        |          |           t          j        ||ddi          }t          |	                    t          j        |          |           dS )zTest distance equivalency.rF   r_   r   NrI   rG   )rb   r   )r   r   r7   rc   r   r'   rM   rv   r   r&   r   r%   allclose)rq   rY   rO   r@   distrP   rQ   s          r   test_distancez Test_with_redshift.test_distanceg  s#    1wud[011!44)-//%%%% "5)) 	E 	E*D999K$QTT!%%=%=tDDD	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E &555 DD$$&PgmTK=O&P&PQR&S&S	
 	
 	
 :HgmTK5GHHKKTRRRRR &ut<<< ae[!9!94@@@ k!B!BAFFF &utFE?SSS k!B!BAFFFFFs   "AB22B69B6N)__name__
__module____qualname____doc__r   fixturerO   rs   rx   r~   r   r   r   r   r   r   markparametrizer   r   r   r   rl   rl      s       77V^'"""- - #"-& & &
% % %# # #$G G G<$ $ $(%D %D %DR% % % D D D2 2 2
 [V%K%K%KLLG G MLG G Gr   rl   c                      t          j                    } t          | j                  dk    sJ t	          | j        d         d                   dk    sJ d S )Nr   r   r7   )r   get_current_unit_registryrw   r   str)base_registrys    r    test_equivalency_context_managerr     sZ    /11M }*++q0000}*1-a011Z??????r   ) r   r   astropy.cosmology.unitsr`   unitsr   astropy.unitsr   astropy.cosmologyr   r   astropy.tests.helperr   "astropy.utils.compat.optional_depsr   astropy.utils.exceptionsr   r   r   r3   r   skipifrB   rR   rX   r   ra   __defaults__rg   rj   rl   r   r   r   r   <module>r      sd   - -
  $ $ $ $ $ $ $ $ $       9 9 9 9 9 9 9 9 9 9 9 9 9 9 8 8 8 8 8 8 > > > > > >1 1 1	5 	5 	5V V V. 	M*ABB  CB> 	M*ABBC C CBC: 	M*ABB%@ %@ CB%@P 	M*ABB
&r*J
LQ @ @	  CB
@"( ( ( 	M*ABB@G @G @G @G @G @G @G CB@GF@ @ @ @ @r   