
    IR-ejw                     $   d Z ddlZddlmZ ddlZddlmZ ddl	m
Z
 ddlmZ ddlmZmZmZmZmZ dd	lmZmZ dd
lmZ g dZ G d de          Zd Zd Zd Zd Zd"dZd Zd Z d Z!d Z"d Z#d Z$d"dZ%d Z&d"dZ'd Z(d Z)d Z*d Z+d  Z,d! Z-dS )#z-A set of standard astronomical equivalencies.    N)UserList)siAstropyDeprecationWarning)
isiterable   )	astrophyscgsdimensionless_unscaledmiscr   )Unit
UnitsError)units)parallaxspectralspectral_densitydoppler_radiodoppler_opticaldoppler_relativisticdoppler_redshiftmass_energybrightness_temperaturethermodynamic_temperaturebeam_angular_areadimensionless_angleslogarithmictemperaturetemperature_energymolar_mass_amupixel_scaleplate_scaleEquivalencyc                   0     e Zd ZdZddZ fdZd Z xZS )r"   z
    A container for a units equivalency.

    Attributes
    ----------
    name: `str`
        The name of the equivalency.
    kwargs: `dict`
        Any positional or keyword arguments used to make the equivalency.
     Nc                 V    || _         |g| _        ||gnt                      g| _        d S N)datanamedictkwargs)self
equiv_listr(   r*   s       ;lib/python3.11/site-packages/astropy/units/equivalencies.py__init__zEquivalency.__init__6   s.    	F	"("4vhh466(    c                    t          |t                    r[t                                          |          }| j        d d          |j        z   |_        | j        d d          |j        z   |_        |S | j                            |          S r&   )
isinstancer"   super__add__r(   r*   r'   )r+   othernew	__class__s      r-   r3   zEquivalency.__add__;   su    e[)) 	,''//%((Cy|ej0CHQQQ%,6CJJ9$$U+++r/   c                 l    t          || j                  o| j        |j        k    o| j        |j        k    S r&   )r1   r6   r(   r*   )r+   r4   s     r-   __eq__zEquivalency.__eq__D   s8    udn-- ,	UZ',u|+	
r/   )r$   N)__name__
__module____qualname____doc__r.   r3   r8   __classcell__)r6   s   @r-   r"   r"   *   si        	 	C C C C
, , , , ,
 
 
 
 
 
 
r/   r"   c                  <    t          t          j        dfgd          S )a  Allow angles to be equivalent to dimensionless (with 1 rad = 1 m/m = 1).

    It is special compared to other equivalency pairs in that it
    allows this independent of the power to which the angle is raised,
    and independent of whether it is part of a more complicated unit.
    Nr   )r"   r   radian r/   r-   r   r   L   s     D)*,BCCCr/   c                  `    t          t          t          j        t          j        d fgd          S )zCAllow logarithmic units to be converted to dimensionless fractions.c                     d| z  S )Ng      $@r@   xs    r-   <lambda>zlogarithmic.<locals>.<lambda>Y   s    $PQ' r/   r   )r"   r   function_unitsdexnplog10r@   r/   r-   r   r   V   s/    
 ."4bh@Q@Q	RS  r/   c                  X    d } t          t          j        t          j        | fgd          S )zq
    Returns a list of equivalence pairs that handle the conversion
    between parallax angle and distance.
    c                     t          j        |           } d| z  }t          |          rt           j        ||dk     <   |S |dk     rt          j        t           j                  S |S )Nr   r   )rH   
asanyarrayr   nanarray)rD   ds     r-   parallax_converterz$parallax.<locals>.parallax_converterd   s^    M!Ea== 	vAa!eHH 1uux'''r/   r   )r"   r   	arcsecondr	   parsec)rP   s    r-   r   r   ^   s:       
,	(*<	=>
  r/   c                     t           j        j        t           j        j        z  dt          j        z  t          j        dz  } t          j        t          j        z  }t          t          j        t          j
        fdft          j        t          j        fdft          j
        t          j        fdfdft          j        | d ft          j
        | fdfd	ft          j        | fd
fdf| |fdfdft          j        |fdft          j
        |fdfdft          j        |fdfdfg
d          S )a  
    Returns a list of equivalence pairs that handle spectral
    wavelength, wave number, frequency, and energy equivalencies.

    Allows conversions between wavelength units, wave number units,
    frequency units, and energy units as they relate to light.

    There are two types of wave number:

        * spectroscopic - :math:`1 / \lambda` (per meter)
        * angular - :math:`2 \pi / \lambda` (radian per meter)

    g       @c                     | z  S r&   r@   rD   cs    r-   rE   zspectral.<locals>.<lambda>       AE r/   c                     | z  S r&   r@   rD   hcs    r-   rE   zspectral.<locals>.<lambda>   s    26 r/   c                     | z  S r&   r@   rD   hs    r-   rE   zspectral.<locals>.<lambda>   rX   r/   c                     | z  S r&   r@   r]   s    r-   rE   zspectral.<locals>.<lambda>   s    QU r/   c                     d| z  S )Ng      ?r@   rC   s    r-   rE   zspectral.<locals>.<lambda>   s
    q r/   c                     | z  S r&   r@   rV   s    r-   rE   zspectral.<locals>.<lambda>   s    !a% r/   c                     | z  S r&   r@   rV   s    r-   rE   zspectral.<locals>.<lambda>   s    1q5 r/   c                     | z  S r&   r@   rZ   s    r-   rE   zspectral.<locals>.<lambda>   s    R r/   c                     | z  S r&   r@   rZ   s    r-   rE   zspectral.<locals>.<lambda>   s    26 r/   c                     | z  S r&   r@   rD   two_pis    r-   rE   zspectral.<locals>.<lambda>   s    a&j r/   c                     | z  S r&   r@   rf   s    r-   rE   zspectral.<locals>.<lambda>   s    AJ r/   c                     | z  S r&   r@   rf   s    r-   rE   zspectral.<locals>.<lambda>   s    
 r/   c                     | z  z  S r&   r@   rD   rW   rg   s    r-   rE   zspectral.<locals>.<lambda>   s    !a r/   c                     | z  z  S r&   r@   rk   s    r-   rE   zspectral.<locals>.<lambda>   s    1q56> r/   c                     | z  z  S r&   r@   rD   r[   rg   s    r-   rE   zspectral.<locals>.<lambda>   s    F
R r/   c                     | z  z  S r&   r@   rn   s    r-   rE   zspectral.<locals>.<lambda>   s    26F? r/   r   )_sirW   valuer^   rH   pir   mr?   r"   HzJ)
inv_m_spec	inv_m_angrW   r^   r[   rg   s     @@@@r-   r   r   w   s}    	AA	
QB25[FrJ	BD IT25////*T24))))*UBD////????;T:001UJAT:////1A1A1A1AB$8$8$8$8:N:N:N:NOT922223UI777779Q9Q9Q9Q9QRT9777779R9R9R9R9RS	
 	  r/   c                    :;< ddl m} t           |          r|t          d          | z   t          j                            t          j        t          j	        z            :t          j
        j        j        ;:;z  <t          j        t          j        z  t          j        dz  z  t          j	        z  }t          j        t          j        z  t          j        dz  z  t          j	        z  }t          j        t          j        dz  z  t          j	        z  }|}t"          j        t          j        dz  t          j	        z  t          j        z  z  }t"          j        t          j        dz  t          j	        z  t          j        z  z  }t"          j        t          j        dz  t          j	        z  z  }	t          j        t          j	        z  t          j        z  }
t          j        t          j	        z  t          j        z  }t          j        t          j	        z  }|}t"          j        t          j	        t          j        z  z  }t"          j        t          j	        t          j        z  z  }t          j        t          j        z  t          j        dz  z  t          j	        z  t          j        z  }t          j        t          j        z  t          j        dz  z  t          j	        z  t          j        z  }t          j        t          j        dz  z  t          j	        z  t          j        z  }|}t"          j        t          j        dz  t          j	        z  t          j        z  t          j        z  z  }t"          j        t          j        dz  t          j	        z  t          j        z  t          j        z  z  }t          j        t          j	        z  t          j        z  t          j        z  }t          j        t          j	        z  t          j        z  t          j        z  }t          j        t          j	        z  t          j        z  }|}t"          j        t          j	        t          j        z  t          j        z  z  }t"          j        t          j	        t          j        z  t          j        z  z  }: fd}: fd} fd} fd	} fd
}  fd}!< fd}"< fd}#; fd}$; fd}%: fd}&: fd}'|"}(|#}):< fd}*:< fd}+|},|}-| }.|!}/|"}0|#}1|$}2|%}3|&}4|'}5|(}6|)}7|*}8|+}9t)          g ||||f||||f||| |!f|||"|#f|||$|%f|||&|'f|||(|)f|||*|+f|	||"|#f||
||f|
||,|-f|||.|/f|||0|1f||
|2|3f|||4|5f||
|6|7f|||8|9f||||f||||f||| |!f|||"|#f|||$|%f|||&|'f|||(|)f|||*|+f||||f|||,|-f|||.|/f|||0|1f|||2|3f|||4|5f|||6|7f|||8|9fd |d          S )a	  
    Returns a list of equivalence pairs that handle spectral density
    with regard to wavelength and frequency.

    Parameters
    ----------
    wav : `~astropy.units.Quantity`
        `~astropy.units.Quantity` associated with values being converted
        (e.g., wavelength or frequency).

    Notes
    -----
    The ``factor`` argument is left for backward-compatibility with the syntax
    ``spectral_density(unit, factor)`` but users are encouraged to use
    ``spectral_density(factor * unit)`` instead.

    r   )UnitBaseNz7If `wav` is specified as a unit, `factor` should be set   c                 n    |                      t          j        t                                dz  z  z  S Nrz   to_valuer   AAr   rD   c_Apswavs    r-   f_la_to_f_nuz&spectral_density.<locals>.f_la_to_f_nu   ,    CLL

33q85@AAr/   c                 n    |                      t          j        t                                dz  z  z  S r|   r}   r   s    r-   f_la_from_f_nuz(spectral_density.<locals>.f_la_from_f_nu   r   r/   c                 b    |                      t          j        t                                z  S r&   r~   r   rt   r   rD   r   s    r-   f_nu_to_nu_f_nuz)spectral_density.<locals>.f_nu_to_nu_f_nu   "    3<<xzz2222r/   c                 b    |                      t          j        t                                z  S r&   r   r   s    r-   f_nu_from_nu_f_nuz+spectral_density.<locals>.f_nu_from_nu_f_nu   r   r/   c                 b    |                      t          j        t                                z  S r&   r}   r   s    r-   f_la_to_la_f_laz)spectral_density.<locals>.f_la_to_la_f_la   r   r/   c                 b    |                      t          j        t                                z  S r&   r}   r   s    r-   f_la_from_la_f_laz+spectral_density.<locals>.f_la_from_la_f_la   r   r/   c                 h    | z                       t          j        t                                z  S r&   r}   rD   r[   r   s    r-   phot_f_la_to_f_laz+spectral_density.<locals>.phot_f_la_to_f_la   s&    AvRUHJJ7777r/   c                 h    |                      t          j        t                                z  z  S r&   r}   r   s    r-   phot_f_la_from_f_laz-spectral_density.<locals>.phot_f_la_from_f_la   s'    3<<xzz222R77r/   c                 h    | z                       t          j        t                                z  S r&   r}   rD   h_cgsr   s    r-   phot_f_la_to_f_nuz+spectral_density.<locals>.phot_f_la_to_f_nu   s&    qy3<<xzz::::r/   c                 h    |                      t          j        t                                z  z  S r&   r}   r   s    r-   phot_f_la_from_f_nuz-spectral_density.<locals>.phot_f_la_from_f_nu   s'    CLL

33e;<<r/   c                 n    |                      t          j        t                                dz  z  z  S r|   r}   r   s    r-   phot_f_la_to_phot_f_nuz0spectral_density.<locals>.phot_f_la_to_phot_f_nu   s,    3<<xzz22a77%??r/   c                 n    | z                       t          j        t                                dz  z  S r|   r}   r   s    r-   phot_f_la_from_phot_f_nuz2spectral_density.<locals>.phot_f_la_from_phot_f_nu   s+    qy3<<xzz::a???r/   c                 t    | z  z                       t          j        t                                dz  z  S N   r}   rD   r   r[   r   s    r-   phot_f_nu_to_f_laz+spectral_density.<locals>.phot_f_nu_to_f_la  s/    2v~RUHJJ ? ?1 DDDr/   c                 t    |                      t          j        t                                dz  z  z  z  S r   r}   r   s    r-   phot_f_nu_from_f_laz-spectral_density.<locals>.phot_f_nu_from_f_la  s0    3<<xzz22a772:FFr/   r   )r   factor)corery   r1   
ValueErrorrp   rW   r~   r   r   sr^   r
   rq   ergangstromcmrt   r	   photonsrr"   )=r   r   ry   f_laf_nunu_f_nula_f_la	phot_f_la	phot_f_nula_phot_f_laL_nuL_lanu_L_nula_L_la	phot_L_la	phot_L_nuS_laS_nunu_S_nula_S_la	phot_S_la	phot_S_nuSL_nuSL_lanu_SL_nula_SL_la
phot_SL_la
phot_SL_nur   r   r   r   r   r   r   r   r   r   r   r   phot_f_nu_to_f_nuphot_f_nu_from_f_nur   r   L_nu_to_nu_L_nuL_nu_from_nu_L_nuL_la_to_la_L_laL_la_from_la_L_laphot_L_la_to_L_laphot_L_la_from_L_laphot_L_la_to_L_nuphot_L_la_from_L_nuphot_L_la_to_phot_L_nuphot_L_la_from_phot_L_nuphot_L_nu_to_L_nuphot_L_nu_from_L_nuphot_L_nu_to_L_laphot_L_nu_from_L_lar   r   r[   s=   `                                                         @@@r-   r   r      s   $ #x   >VWWWslENN2524<((EEIOE	B 7R[ 25!8+bd2D7RU?RUAX%,Dgq 24'GG BE1HrtObe$;<I BE1HrtObe$;<I#ruax"$7L 7RT>BE!D7RT>BK'DgnGG BD25L1I BD25L1I 7R[ 25!8+bd2RU:D7RU?RUAX%,ru4Dgq 24'"%/GG BE1HrtObe$;be$CDI BE1HrtObe$;be$CDI GbdNRU"RU*EGbdNR[(250Ew~%HH!RTBE\BE%9:J!RTBE\BE%9:JB B B B B BB B B B B B3 3 3 3 33 3 3 3 33 3 3 3 33 3 3 3 38 8 8 8 8 88 8 8 8 8 8; ; ; ; ; ;= = = = = =@ @ @ @ @ @@ @ @ @ @ @ *-E E E E E E EG G G G G G G &O)%O))-)-37)-)-'	
4~6'	
 7O->?'	
 7O->?	'	

 /1DE'	
 /1DE'	
 	#9;ST'	
 /1DE'	
 /1DE'	
 7$57JK'	
 4~6'	
 7O->?'	
 7O->?'	
  /1DE!'	
" /1DE#'	
$ 	#9;ST%'	
& /1DE''	
( /1DE)'	
, 4~6-'	
. 7O->?/'	
0 7O->?1'	
2 /1DE3'	
4 /1DE5'	
6 	#9;ST7'	
8 /1DE9'	
: /1DE;'	
> E<8?'	
@ Ho/@AA'	
B Ho/@AC'	
D  13FGE'	
F  13FGG'	
H %;=UVI'	
J  13FGK'	
L  13FGM'	
P 	v&&U+ + +r/   c                     t                      t          j                            d           fd} fd} fd} fd} fd} fd}t	          t
          j        t
          j        t
          j        z  ||ft
          j	        t
          j        t
          j        z  ||ft
          j
        t
          j        t
          j        z  ||fgdd	 i          S )
a  
    Return the equivalency pairs for the radio convention for velocity.

    The radio convention for the relation between velocity and frequency is:

    :math:`V = c \frac{f_0 - f}{f_0}  ;  f(V) = f_0 ( 1 - V/c )`

    Parameters
    ----------
    rest : `~astropy.units.Quantity`
        Any quantity supported by the standard spectral equivalencies
        (wavelength, energy, frequency, wave number).

    References
    ----------
    `NRAO site defining the conventions <https://www.gb.nrao.edu/~fghigo/gbtdoc/doppler.html>`_

    Examples
    --------
    >>> import astropy.units as u
    >>> CO_restfreq = 115.27120*u.GHz  # rest frequency of 12 CO 1-0 in GHz
    >>> radio_CO_equiv = u.doppler_radio(CO_restfreq)
    >>> measured_freq = 115.2832*u.GHz
    >>> radio_velocity = measured_freq.to(u.km/u.s, equivalencies=radio_CO_equiv)
    >>> radio_velocity  # doctest: +FLOAT_CMP
    <Quantity -31.209092088877583 km / s>
    km/sc                 t                         t          j        t                                }|| z
  |z  z  S Nequivalenciesr   rD   restfreqckmsrests     r-   to_vel_freqz"doppler_radio.<locals>.to_vel_freqf  s2    ==hjj=AA1*T11r/   c                 x                         t          j        t                                }| z  }|d|z
  z  S Nr   r   r   rD   r   vovercr   r   s      r-   from_vel_freqz$doppler_radio.<locals>.from_vel_freqj  6    ==hjj=AAT1v:&&r/   c                 r                         t          j        t                                }| |z
  | z  z  S r&   r}   rD   restwavr   r   s     r-   
to_vel_wavz!doppler_radio.<locals>.to_vel_wavo  s0    --xzz22G"T))r/   c                 r                         t          j        t                                }|z  | z
  z  S r&   r}   r   s     r-   from_vel_wavz#doppler_radio.<locals>.from_vel_wavs  s/    --xzz22~**r/   c                 t                         t          j        t                                }|| z
  |z  z  S r   r~   r   eVr   rD   restenr   r   s     r-   	to_vel_enz doppler_radio.<locals>.to_vel_enw  s2    ruHJJ??
v&--r/   c                 x                         t          j        t                                }| z  }|d|z
  z  S r   r   rD   r   r   r   r   s      r-   from_vel_enz"doppler_radio.<locals>.from_vel_en{  6    ruHJJ??TV$$r/   r   r   assert_is_spectral_unitrp   rW   r~   r"   r   rt   kmr   r   r   r   r   r   r   r   r   r   r   s   `      @r-   r   r   F  sB   8 D!!!5>>&!!D2 2 2 2 2 2' ' ' ' ' '
* * * * * *+ + + + + +. . . . . .% % % % % %
 UBEBDL+}=UBEBDL*l;UBEBDL)[9	

 		  r/   c                     t                      t          j                            d           fd} fd} fd} fd} fd} fd}t	          t
          j        t
          j        t
          j        z  ||ft
          j	        t
          j        t
          j        z  ||ft
          j
        t
          j        t
          j        z  ||fgdd	 i          S )
a  
    Return the equivalency pairs for the optical convention for velocity.

    The optical convention for the relation between velocity and frequency is:

    :math:`V = c \frac{f_0 - f}{f  }  ;  f(V) = f_0 ( 1 + V/c )^{-1}`

    Parameters
    ----------
    rest : `~astropy.units.Quantity`
        Any quantity supported by the standard spectral equivalencies
        (wavelength, energy, frequency, wave number).

    References
    ----------
    `NRAO site defining the conventions <https://www.gb.nrao.edu/~fghigo/gbtdoc/doppler.html>`_

    Examples
    --------
    >>> import astropy.units as u
    >>> CO_restfreq = 115.27120*u.GHz  # rest frequency of 12 CO 1-0 in GHz
    >>> optical_CO_equiv = u.doppler_optical(CO_restfreq)
    >>> measured_freq = 115.2832*u.GHz
    >>> optical_velocity = measured_freq.to(u.km/u.s, equivalencies=optical_CO_equiv)
    >>> optical_velocity  # doctest: +FLOAT_CMP
    <Quantity -31.20584348799674 km / s>
    r   c                 t                         t          j        t                                }|| z
  z  | z  S r   r   r   s     r-   r   z$doppler_optical.<locals>.to_vel_freq  s2    ==hjj=AAx!|$q((r/   c                 x                         t          j        t                                }| z  }|d|z   z  S r   r   r   s      r-   r   z&doppler_optical.<locals>.from_vel_freq  r   r/   c                 r                         t          j        t                                }| |z  dz
  z  S Nr   r}   r   s     r-   r   z#doppler_optical.<locals>.to_vel_wav  s/    --xzz22q7{Q''r/   c                 v                         t          j        t                                }| z  }|d|z   z  S r  r}   rD   r   r   r   r   s      r-   r   z%doppler_optical.<locals>.from_vel_wav  s4    --xzz22T!f*%%r/   c                 t                         t          j        t                                }|| z
  z  | z  S r   r   r   s     r-   r   z"doppler_optical.<locals>.to_vel_en  s2    ruHJJ??vz"Q&&r/   c                 x                         t          j        t                                }| z  }|d|z   z  S r   r   r   s      r-   r   z$doppler_optical.<locals>.from_vel_en  r   r/   r   r   r   r   s   `      @r-   r   r     sB   8 D!!!5>>&!!D) ) ) ) ) )' ' ' ' ' '
( ( ( ( ( (& & & & & &
' ' ' ' ' '% % % % % %
 UBEBDL+}=UBEBDL*l;UBEBDL)[9	

 		  r/   c                     t                      t          j                            d           fd} fd} fd} fd} fd} fd}t	          t
          j        t
          j        t
          j        z  ||ft
          j	        t
          j        t
          j        z  ||ft
          j
        t
          j        t
          j        z  ||fgdd	 i          S )
a  
    Return the equivalency pairs for the relativistic convention for velocity.

    The full relativistic convention for the relation between velocity and frequency is:

    :math:`V = c \frac{f_0^2 - f^2}{f_0^2 + f^2} ;  f(V) = f_0 \frac{\left(1 - (V/c)^2\right)^{1/2}}{(1+V/c)}`

    Parameters
    ----------
    rest : `~astropy.units.Quantity`
        Any quantity supported by the standard spectral equivalencies
        (wavelength, energy, frequency, wave number).

    References
    ----------
    `NRAO site defining the conventions <https://www.gb.nrao.edu/~fghigo/gbtdoc/doppler.html>`_

    Examples
    --------
    >>> import astropy.units as u
    >>> CO_restfreq = 115.27120*u.GHz  # rest frequency of 12 CO 1-0 in GHz
    >>> relativistic_CO_equiv = u.doppler_relativistic(CO_restfreq)
    >>> measured_freq = 115.2832*u.GHz
    >>> relativistic_velocity = measured_freq.to(u.km/u.s, equivalencies=relativistic_CO_equiv)
    >>> relativistic_velocity  # doctest: +FLOAT_CMP
    <Quantity -31.207467619351537 km / s>
    >>> measured_velocity = 1250 * u.km/u.s
    >>> relativistic_frequency = measured_velocity.to(u.GHz, equivalencies=relativistic_CO_equiv)
    >>> relativistic_frequency  # doctest: +FLOAT_CMP
    <Quantity 114.79156866993588 GHz>
    >>> relativistic_wavelength = measured_velocity.to(u.mm, equivalencies=relativistic_CO_equiv)
    >>> relativistic_wavelength  # doctest: +FLOAT_CMP
    <Quantity 2.6116243681798923 mm>
    r   c                                          t          j        t                                }|dz  | dz  z
  |dz  | dz  z   z  z  S )Nr   rz   r   r   s     r-   r   z)doppler_relativistic.<locals>.to_vel_freq  sH    ==hjj=AA!ad"x{QT'9:TAAr/   c                                          t          j        t                                }| z  }|d|z
  d|z   z  dz  z  S )Nr   r         ?r   r   s      r-   r   z+doppler_relativistic.<locals>.from_vel_freq  sD    ==hjj=AATAJ1<8S@@@r/   c                                          t          j        t                                }| dz  |dz  z
  |dz  | dz  z   z  z  S r|   r}   r   s     r-   r   z(doppler_relativistic.<locals>.to_vel_wav  sF    --xzz221wz!gqj1a4&784??r/   c                                          t          j        t                                }| z  }|d|z   d|z
  z  dz  z  S Nr   r  r}   r  s      r-   r   z*doppler_relativistic.<locals>.from_vel_wav  sB    --xzz22T1v:!f*5#===r/   c                                          t          j        t                                }|dz  | dz  z
  |dz  | dz  z   z  z  S r|   r   r   s     r-   r   z'doppler_relativistic.<locals>.to_vel_en
  sF    ruhjj11	AqD VQYA%56==r/   c                                          t          j        t                                }| z  }|d|z
  d|z   z  dz  z  S r  r   r   s      r-   r   z)doppler_relativistic.<locals>.from_vel_en  sB    ruhjj11T!f*f63>>>r/   r   r   r   r   s   `      @r-   r   r     sU   F D!!!5>>&!!DB B B B B BA A A A A A
@ @ @ @ @ @> > > > > >
> > > > > >? ? ? ? ? ?
 UBEBDL+}=UBEBDL*l;UBEBDL)[9	

 		  r/   c                      t           j        t           j        z  } t          j                            |           fd}fd}t          t          | ||fgd          S )z
    Returns the equivalence between Doppler redshift (unitless) and radial velocity.

    .. note::

        This equivalency is not compatible with cosmological
        redshift in `astropy.cosmology.units`.

    c                 0    d| z   dz  }|dz
  z  |dz   z  S )Nr   rz   r@   )zzponesqC_KMSs     r-   convert_z_to_rvz)doppler_redshift.<locals>.convert_z_to_rv+  s(    q5Q,!$!44r/   c                 N    | z  }t          j        d|z   d|z
  z            dz
  S r  )rH   sqrt)rvbetar  s     r-   convert_rv_to_zz)doppler_redshift.<locals>.convert_rv_to_z/  s.    EzwDQX.//!33r/   r   )r   r   r   rp   rW   r~   r"   r   )rv_unitr  r  r  s      @r-   r   r     s}     ebdlGENN7##E5 5 5 5 54 4 4 4 4 
 '?O	LM  r/   c                  j    t          t          j        t          j        z  t          j        fgd          S )z=
    Returns the equivalence between amu and molar mass.
    r   )r"   r   gmolr   ur@   r/   r-   r   r   9  s'     /02BCCCr/   c            
          t           j        j        dz   t          t          j        t          j         fd fdft          j        t          j        dz  z  t          j        t          j        dz  z   fd fdft          j        t          j        dz  z  t          j        t          j        dz  z   fd fdft          j        t          j        z  t          j        t          j        z   fd	 fd
fgd          S )ze
    Returns a list of equivalence pairs that handle the conversion
    between mass and energy.
    rz   c                     | z  S r&   r@   rD   c2s    r-   rE   zmass_energy.<locals>.<lambda>H  s    AF r/   c                     | z  S r&   r@   r#  s    r-   rE   zmass_energy.<locals>.<lambda>H  s    a"f r/   c                     | z  S r&   r@   r#  s    r-   rE   zmass_energy.<locals>.<lambda>I      B r/   c                     | z  S r&   r@   r#  s    r-   rE   zmass_energy.<locals>.<lambda>I      !b& r/   r   c                     | z  S r&   r@   r#  s    r-   rE   zmass_energy.<locals>.<lambda>J  r'  r/   c                     | z  S r&   r@   r#  s    r-   rE   zmass_energy.<locals>.<lambda>J  r)  r/   c                     | z  S r&   r@   r#  s    r-   rE   zmass_energy.<locals>.<lambda>K  s    !b& r/   c                     | z  S r&   r@   r#  s    r-   rE   zmass_energy.<locals>.<lambda>K  s    AF r/   r   )	rp   rW   rq   r"   r   kgru   rs   r   )r$  s   @r-   r   r   @  s    
 
aBUBD****,<,<,<,<=URT1W_bdRT1Wn.>.>.>.>@P@P@P@PQURT1W_bdRT1Wn.>.>.>.>@P@P@P@PQURT\24"$;(8(8(8(8:J:J:J:JK		
 	  r/   c                 "  	 | j                             t          j                  rQ|j                             t          j                  st          d          t          j        dt                     || }} | 	                    t          j
        t                                }dt          j        z  t          j        z  |dz  z  t          j        dz  z  	                    t           j                  j        t           j        dt          j        z  |dz  z  t          j        dz  z  z  	                    t          j                  j        	|~|                    t          j                  fd}	fd}t)          t           j        t          j        ||ft           j        t           j        z  t          j        ||fgd| |d          S fd	}	fd
}t)          t           j        t          j        z  t          j        ||fgd| |d          S )a  
    Defines the conversion between Jy/sr and "brightness temperature",
    :math:`T_B`, in Kelvins.  The brightness temperature is a unit very
    commonly used in radio astronomy.  See, e.g., "Tools of Radio Astronomy"
    (Wilson 2009) eqn 8.16 and eqn 8.19 (these pages are available on `google
    books
    <https://books.google.com/books?id=9KHw6R8rQEMC&pg=PA179&source=gbs_toc_r&cad=4#v=onepage&q&f=false>`__).

    :math:`T_B \equiv S_\nu / \left(2 k \nu^2 / c^2 \right)`

    If the input is in Jy/beam or Jy (assuming it came from a single beam), the
    beam area is essential for this computation: the brightness temperature is
    inversely proportional to the beam area.

    Parameters
    ----------
    frequency : `~astropy.units.Quantity`
        The observed ``spectral`` equivalent `~astropy.units.Unit` (e.g.,
        frequency or wavelength).  The variable is named 'frequency' because it
        is more commonly used in radio astronomy.
        BACKWARD COMPATIBILITY NOTE: previous versions of the brightness
        temperature equivalency used the keyword ``disp``, which is no longer
        supported.
    beam_area : `~astropy.units.Quantity` ['solid angle']
        Beam area in angular units, i.e. steradian equivalent

    Examples
    --------
    Arecibo C-band beam::

        >>> import numpy as np
        >>> from astropy import units as u
        >>> beam_sigma = 50*u.arcsec
        >>> beam_area = 2*np.pi*(beam_sigma)**2
        >>> freq = 5*u.GHz
        >>> equiv = u.brightness_temperature(freq)
        >>> (1*u.Jy/beam_area).to(u.K, equivalencies=equiv)  # doctest: +FLOAT_CMP
        <Quantity 3.526295144567176 K>

    VLA synthetic beam::

        >>> bmaj = 15*u.arcsec
        >>> bmin = 15*u.arcsec
        >>> fwhm_to_sigma = 1./(8*np.log(2))**0.5
        >>> beam_area = 2.*np.pi*(bmaj*bmin*fwhm_to_sigma**2)
        >>> freq = 5*u.GHz
        >>> equiv = u.brightness_temperature(freq)
        >>> (u.Jy/beam_area).to(u.K, equivalencies=equiv)  # doctest: +FLOAT_CMP
        <Quantity 217.2658703625732 K>

    Any generic surface brightness:

        >>> surf_brightness = 1e6*u.MJy/u.sr
        >>> surf_brightness.to(u.K, equivalencies=u.brightness_temperature(500*u.GHz)) # doctest: +FLOAT_CMP
        <Quantity 130.1931904778803 K>
    zFThe inputs to `brightness_temperature` are frequency and angular area.zThe inputs to `brightness_temperature` have changed. Frequency is now the first input, and angular area is the second, optional input.rz   Nc                     | z  z  S r&   r@   )x_jybmbeam	factor_Jys    r-   convert_Jy_to_Kz/brightness_temperature.<locals>.convert_Jy_to_K  s    D=9,,r/   c                     | z  z  S r&   r@   )x_Kr2  factor_Ks    r-   convert_K_to_Jyz/brightness_temperature.<locals>.convert_K_to_Jy  s    :((r/   r   )	frequency	beam_areac                     | z  S r&   r@   )x_jysrr3  s    r-   convert_JySr_to_Kz1brightness_temperature.<locals>.convert_JySr_to_K  s    I%%r/   c                     | z  S r&   r@   )r6  r7  s    r-   convert_K_to_JySrz1brightness_temperature.<locals>.convert_K_to_JySr  s    >!r/   )unitis_equivalentr   r   rt   r   warningswarnr   toGHzr   rp   k_BKrW   r	   Jyrq   r~   r"   r2  )
r9  r:  nur4  r8  r=  r?  r2  r3  r7  s
          @@@r-   r   r   Q  s   r ~##BE** 4~++BE22 	X   	- &		
 	
 	
  ))9		bfhjj	)	)BSWrt#b!e+ceQh6::9<HHNICGb!e 3ceQh >?CCBDIIOH!!"%((	- 	- 	- 	- 	- 	-	) 	) 	) 	) 	) 	) rt_oF	.oW %#)<<
 
 	
	& 	& 	& 	& 	&	" 	" 	" 	" 	" lRU"BD*;=NOP$#)<<
 
 	
r/   c           	         t          t          j        t          |           ft          j        dz  t          |           dz  ft          j        t          j        z  t          j        t          |           z  fgdd| i          S )a  
    Convert between the ``beam`` unit, which is commonly used to express the area
    of a radio telescope resolution element, and an area on the sky.
    This equivalency also supports direct conversion between ``Jy/beam`` and
    ``Jy/steradian`` units, since that is a common operation.

    Parameters
    ----------
    beam_area : unit-like
        The area of the beam in angular area units (e.g., steradians)
        Must have angular area equivalent units.
    rT   r   r:  )r"   r	   r2  r   rH  )r:  s    r-   r   r     sp     ^T)__-^RiB!67\IN*IL4	??,JK	

 		i   r/   c                 6   |                      t          j        t                                |ddlm} |                                j        }|fdfd}fd}t          t          j
        t          j        z  t          j        ||fgd| |d          S )	a~  Defines the conversion between Jy/sr and "thermodynamic temperature",
    :math:`T_{CMB}`, in Kelvins.  The thermodynamic temperature is a unit very
    commonly used in cosmology. See eqn 8 in [1].

    :math:`K_{CMB} \equiv I_\nu / \left(2 k \nu^2 / c^2  f(\nu) \right)`

    with :math:`f(\nu) = \frac{ x^2 e^x}{(e^x - 1 )^2}`
    where :math:`x = h \nu / k T`

    Parameters
    ----------
    frequency : `~astropy.units.Quantity`
        The observed `spectral` equivalent `~astropy.units.Unit` (e.g.,
        frequency or wavelength). Must have spectral units.
    T_cmb :  `~astropy.units.Quantity` ['temperature'] or None
        The CMB temperature at z=0.  If `None`, the default cosmology will be
        used to get this temperature. Must have units of temperature.

    Notes
    -----
    For broad band receivers, this conversion do not hold
    as it highly depends on the frequency

    References
    ----------
    .. [1] Planck 2013 results. IX. HFI spectral response
       https://arxiv.org/abs/1303.5070

    Examples
    --------
    Planck HFI 143 GHz::

        >>> from astropy import units as u
        >>> from astropy.cosmology import Planck15
        >>> freq = 143 * u.GHz
        >>> equiv = u.thermodynamic_temperature(freq, Planck15.Tcmb0)
        >>> (1. * u.mK).to(u.MJy / u.sr, equivalencies=equiv)  # doctest: +FLOAT_CMP
        <Quantity 0.37993172 MJy / sr>

    Nr   )default_cosmologyc                     t           j        | z  t           j        z  |z  }|dz  t          j        |          z  t          j        |          dz  z  S r|   )rp   r^   rF  rH   expexpm1)rI  T_cmbrD   s      r-   fz$thermodynamic_temperature.<locals>.f  sB    EBJ 5(!tbfQii"(1++"222r/   c                                dz  t           j        z  t          j        z  dz  z  t           j        dz  z                      t          j                  }| |z  S r|   )rp   rF  r   rG  rW   r~   r	   rH  )r1  r   rQ  rI  s     r-   r4  z2thermodynamic_temperature.<locals>.convert_Jy_to_K  sW    !B%%!)cg%,r1u4suax?IIL
 
 r/   c                     t           j                   dz  t          j        z  dz  z  t          j        dz  z  z                      t          j                  }| |z  S r|   )r	   rH  rp   rF  rW   r~   r   rG  )r6  r   rQ  rI  s     r-   r8  z2thermodynamic_temperature.<locals>.convert_K_to_Jy  sW    ,!!B%%!)cg"5A"=q"HISSD
 
 V|r/   r   )r9  rP  )rD  r   rE  r   astropy.cosmologyrL  getTcmb0r"   r	   rH  r   rG  )r9  rP  rL  r4  r8  rQ  rI  s        @@r-   r   r     s    R 
bfhjj	)	)B}777777!%%''- 3 3 3 3           
,
o	GH#%00  r/   c                      ddl m}  ddl m} t          j        }t          j        }t          ||d d f|| d d f|| d d	 f|| d
 d f||d d f||d d fgd          S )zConvert between Kelvin, Celsius, Rankine and Fahrenheit here because
    Unit and CompositeUnit cannot do addition or subtraction properly.
    r   )deg_F)deg_Rc                     | dz
  S Ngfffffq@r@   rC   s    r-   rE   ztemperature.<locals>.<lambda>&  
    QZ r/   c                     | dz   S r[  r@   rC   s    r-   rE   ztemperature.<locals>.<lambda>&  
    1v: r/   c                     | dz  dz   S )N?      @@r@   rC   s    r-   rE   ztemperature.<locals>.<lambda>'  s    QWt^ r/   c                     | dz
  dz  S )Nra  r`  r@   rC   s    r-   rE   ztemperature.<locals>.<lambda>'  s    DC7G r/   c                     | dz  dz
  S )Nr`  Q|@r@   rC   s    r-   rE   ztemperature.<locals>.<lambda>(  s    QWv- r/   c                     | dz   dz  S )Nrd  r`  r@   rC   s    r-   rE   ztemperature.<locals>.<lambda>(  s    !f*9K r/   c                     | dz
  S Nrd  r@   rC   s    r-   rE   ztemperature.<locals>.<lambda>)  r\  r/   c                     | dz   S rg  r@   rC   s    r-   rE   ztemperature.<locals>.<lambda>)  r^  r/   c                     | dz
  dz  S )NQ~@rq?r@   rC   s    r-   rE   ztemperature.<locals>.<lambda>*  s    a&jU3 r/   c                     | dz  dz   S )Nr`  rj  r@   rC   s    r-   rE   ztemperature.<locals>.<lambda>*  s    q3w?O r/   c                     | dz  S )Nrk  r@   rC   s    r-   rE   ztemperature.<locals>.<lambda>+  s
    Q%[ r/   c                     | dz  S )Nr`  r@   rC   s    r-   rE   ztemperature.<locals>.<lambda>+  s
    AG r/   r   )imperialrX  rY  r   rG  deg_Cr"   )FRrG  Cs       r-   r   r     s     %$$$$$$$$$$$
A
A'')=)=>++-G-GH--/K/KL'')=)=>335O5OP((*;*;<	
 	
 
 
r/   c                       t           j        j         t           j        j        t	          t
          j        t
          j         fd fdfgd          S )z;Convert between Kelvin and keV(eV) to an equivalent amount.c                     | z  z  S r&   r@   rD   erF  s    r-   rE   z$temperature_energy.<locals>.<lambda>6  s    a#g r/   c                     | z  z  S r&   r@   rv  s    r-   rE   z$temperature_energy.<locals>.<lambda>6  s    !q3w- r/   r   )rp   rw  rq   rF  r"   r   rG  r   )rw  rF  s   @@r-   r   r   1  sX    A
'-C
$.....0G0G0G0G0G	HI  r/   c                     	 |                      t          j        t                                 d S # t          t
          f$ r}t          d          d }~ww xY w)NzRThe 'rest' value must be a spectral equivalent (frequency, wavelength, or energy).)rD  r   rt   r   AttributeErrorr   )rq   exs     r-   r   r   ;  sb    


#####J' 
 
 
2
 
 	

s   ,0 AAAc                    | j                                         }t          t          |j        |j                            }|                    t          j        d          }|dk    rt          | t          j        z            }n2|dk    rt          t          j        | z            }nt          d          t          t          j        |fgdd| i          S )a  
    Convert between pixel distances (in units of ``pix``) and other units,
    given a particular ``pixscale``.

    Parameters
    ----------
    pixscale : `~astropy.units.Quantity`
        The pixel scale either in units of <unit>/pixel or pixel/<unit>.
    r   rT   r   z?The pixel scale unit must have pixel dimensionality of 1 or -1.r    pixscale)r@  	decomposer)   zipbasespowersrU  r   pixr   r   r"   )r}  
decomposed
dimensions	pix_powerphysical_units        r-   r    r    E  s     ((**Jc**J,=>>??Jtx++IBX011	aTX011M
 
 	
 
(M	"#]Z4J  r/   c                    | j                             t          j        t          j        z            r-|                     t          j        t          j        z            np| j                             t          j        t          j        z            r0d| z                      t          j        t          j        z            nt          d          t          t          j        t          j        fdfdfgdd| i          S )a!  
    Convert between lengths (to be interpreted as lengths in the focal plane)
    and angular units with a specified ``platescale``.

    Parameters
    ----------
    platescale : `~astropy.units.Quantity`
        The pixel scale either in units of distance/pixel or distance/angle.
    r   z;The pixel scale must be in angle/distance or distance/anglec                     | z  S r&   r@   )rO   platescale_vals    r-   rE   zplate_scale.<locals>.<lambda>s  s    Q%7 r/   c                     | z  S r&   r@   )ar  s    r-   rE   zplate_scale.<locals>.<lambda>s  s    1~CU r/   r!   
platescale)	r@  rA  r   arcsecrs   r~   r?   r   r"   )r  r  s    @r-   r!   r!   a  s     $$RY%566 X#,,RY-=>>		&	&rtbi'7	8	8 Xj.2229rt3CDDVWWW
$	77779U9U9U9U	VW	z"  r/   c                     | dk    r#dd l }ddlm} ddlm}  |j        d|           |S t          dt          d| d          )	Nwith_H0r   )r  r   z`with_H0` is deprecated from `astropy.units.equivalencies` since astropy 5.0 and may be removed in a future version. Use `astropy.cosmology.units.with_H0` instead.zmodule z has no attribute .)rB  astropy.cosmology.unitsr  astropy.utils.exceptionsr   rC  rz  r9   )attrrB  r  r   s       r-   __getattr__r  |  s    y333333FFFFFF= &		
 	
 	
 
J8JJJJJ
K
KKr/   r&   ).r<   rB  collectionsr   numpyrH   astropy.constantsr   rp   r  r   astropy.utils.miscr   r$   r	   r
   r   r   r   r   r   functionr   rF   __all__r"   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r  r@   r/   r-   <module>r     sh   3 3                  ( ' ' ' ' ' > > > > > > ) ) ) ) ) ) > > > > > > > > > > > > > > " " " " " " " " - - - - - -  .
 
 
 
 
( 
 
 
DD D D    2# # #Lf f f fRB B BJC C CLJ J JZ  6D D D  "g
 g
 g
 g
T  0D D D DN  .  
 
 
  8  6L L L L Lr/   