
[c           @` sT  d  Z  d d l m Z m Z m Z m Z d d l Z d d l Z d d l	 m
 Z
 m Z m Z 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 y  d d l m Z m Z e Z Wn e k
 r e  Z n Xd g Z! d e" f d     YZ# e j$ j% d  d    Z& d   Z' d   Z( d   Z) d   Z* d S(   u(   Tests for blackbody model and functions.i    (   t   absolute_importt   unicode_literalst   divisiont   print_functionNi   (   t   BlackBody1Dt   blackbody_nut   blackbody_lambdat   FNU(   t   LevMarLSQFitteri   (   t   assert_quantity_allcloset   catch_warnings(   t	   constants(   t   units(   t   AstropyUserWarning(   t   optimizet	   integrateu   *t   TestBlackbody1Dc           B` sU   e  Z e j j d  d e j d e j f  d    Z e j j	 d  d    Z
 RS(   u   temperaturei  g3333M@c         C` s   d t  j d t j d t  j d } t d | d |  } t | d t  j  d t  j  t | d	 t  j	  d t  j  d  S(
   Ni  i   g      ?i   t   temperaturet   bolometric_fluxgffffff?gRAgE|'fj@(
   t   ut   L_sunt   npt   pit   pcR   R	   t   micront   Jyt   THz(   t   selfR   R   t   b(    (    sD   lib/python2.7/site-packages/astropy/modeling/tests/test_blackbody.pyt   test_evaluate   s
    '	!u   not HAS_SCIPYc         C` s   t    } t d t j  } t j d d d g  t j } t j d d d g  t j } | | | |  } t | j	 d t j  t | j
 d t j t j d t j  d  S(	   Ni  g      ?i   i
   i   g5?S}1@gOOr>i   (   R   R   R   t   KR   t   arrayR   R   R	   R   R   t   ergt   cmt   s(   R   t   fitterR   t   wavt   fnut   b_fit(    (    sD   lib/python2.7/site-packages/astropy/modeling/tests/test_blackbody.pyt   test_fit*   s    	(   t   __name__t
   __module__t   pytestt   markt   parametrizeR   R   t   deg_CR   t   skipifR'   (    (    (    sD   lib/python2.7/site-packages/astropy/modeling/tests/test_blackbody.pyR      s   2u   not HAS_SCIPYc          C` s   t  j t  j d t  j }  t j d d d  t  j } d t  j } t j d d   t	 | |  t  j
 } Wd QX| j |  t  j |   t  j
 } | j t  j  } t j | j d	 | j } t j | d
 t j } t j j | | j d d d S(   uC   Test Planck function.

    .. note:: Needs ``scipy`` to work.

    i   i    i   i g      Y@t   allu   ignoreNt   xi   t   rtolg{Gz?(   R   t   Wattt   mt   umR   t   logspacet   AAR   t   errstateR   t   srt   tot   spectral_densityR   t   trapzt   valuet   constt   sigma_sbR   t   testingt   assert_allclose(   t	   flux_unitt   wavet   tempt   bb_nut   fluxt   lumt   intfluxt   ans(    (    sD   lib/python2.7/site-packages/astropy/modeling/tests/test_blackbody.pyt   test_blackbody_scipy:   s    "c          C` s7  t  j t  j d t  j t  j }  d d d d g } d } t j d d   t | |  t  j } Wd	 QX| j	 |  t  j
 | t  j   t  j } t j | d  s t  t j | d
 j  d k  s t  t j j | j d d
 !d d g d d t j d d   t d d  } Wd	 QX| j d k s3t  d	 S(   u#   Test Planck function with overflow.i   i    g     @@g     j@gAjZKg     @R/   u   ignoreNiizi   g %T9^Cg Yʲ+CR1   gMbP?(   R   t   photonR!   R"   R6   R   R7   R   R8   R9   R:   t   isnant   AssertionErrort   log10R<   R?   R@   (   t   photlamRB   RC   t   bb_lamRE   (    (    sD   lib/python2.7/site-packages/astropy/modeling/tests/test_blackbody.pyt   test_blackbody_overflowN   s    ")"	c       
   C` s   t  j t j t j d t j }  t  j d d  . t d d d d d g t j	 d	  |  } Wd
 QX| j
 t k sy t  t  j | d j  d k  s t  t  j j | j d d d d d g d d d
 S(   u4   Test that it is consistent with IRAF SYNPHOT BBFUNC.i   R/   u   ignoreid   i   i  g     @g     j@i  Ni    iqgӶ8g=n:gdb:R1   g{Gz?(   R   R   R=   t   R_sunt   kpcR   R8   R7   R   R6   t   unitR   RL   RM   R<   R?   R@   (   t   facRE   (    (    sD   lib/python2.7/site-packages/astropy/modeling/tests/test_blackbody.pyt   test_blackbody_synphotc   s    "/"	c       	   C` s  t  j t   }  t d t j d  Wd QX|  j j d d k sH t  t	 t
   } t d t j d  Wd QXt |  d k s t  d | d j j d k s t  t	 t
   } t d	 t j d  Wd QXt |  d k s t  d | d j j d k s
t  d S(
   u   Test exceptions.i  iNi    u(   Temperature should be positive: -100.0 Ki  i   u   invalidg      (   R*   t   raisest
   ValueErrorR   R   R6   R<   t   argsRL   R
   R   t   lent   message(   t   exct   w(    (    sD   lib/python2.7/site-packages/astropy/modeling/tests/test_blackbody.pyt&   test_blackbody_exceptions_and_warningst   s     c          C` s   t  d t j d d d g t j  }  t j j |  j d d d g d d	 t  d
 d d g t j d d d g t j  }  t j j |  j d d d g d d	 t  t j d  t j t j d  t j  }  |  j	 d k s t
  d S(   uB   Regression test to make sure that the temperature can be an array.g333333?id   i   i,  g=?=gz]=gf̘=R1   gh㈵>i   i   i   glg=g;V$X=g_ P=i   N(   i   i   (   i   i   (   R   R   t   mmR   R   R?   R@   R<   t   onest   shapeRL   (   RE   (    (    sD   lib/python2.7/site-packages/astropy/modeling/tests/test_blackbody.pyt    test_blackbody_array_temperature   s    &	/	/(+   t   __doc__t
   __future__R    R   R   R   R*   t   numpyR   t	   blackbodyR   R   R   R   t   fittingR   t   tests.helperR	   R
   t    R   R=   R   R   t   utils.exceptionsR   t   scipyR   R   t   Truet	   HAS_SCIPYt   ImportErrort   Falset   __doctest_skip__t   objectR   R+   R.   RI   RP   RU   R]   Ra   (    (    (    sD   lib/python2.7/site-packages/astropy/modeling/tests/test_blackbody.pyt   <module>   s*   ""

	 			