
[c           @` sG  d  d l  m Z m Z m Z m Z d  d l Z d  d l Z d  d l Z d  d l	 m
 Z
 d d l m Z d d l m Z m Z m Z m Z m Z m Z d d l m Z m Z d d	 l m Z y d  d l Z e Z Wn e k
 r e Z n Xd
 d d g Z e e e g Z e e e g Z  e j! j" d e# e j$ e e    d    Z% e j! j" d e  d    Z& e j! j" d e# e j$ e  e    d    Z' e j! j" d e  d    Z( e j! j) d  d    Z* e j! j) d  d    Z+ e j! j) d  d    Z, d   Z- d   Z. d   Z/ d   Z0 d   Z1 d   Z2 d   Z3 d S(    i    (   t   absolute_importt   divisiont   print_functiont   unicode_literalsN(   t   assert_allclosei   (   t   discretize_modeli   (   t
   Gaussian1Dt   Box1Dt   MexicanHat1Dt
   Gaussian2Dt   Box2Dt   MexicanHat2D(   t	   models_1Dt	   models_2D(   t   create_modelu   centeru   linear_interpu
   oversampleu   model_classu   modec         C` s   |  t  k r( | d k r( t j d  n  t |  } t |  |  } t | t |  d d | } t | j   t |  d d d d S(	   uK   
    Test if the sum of all pixels corresponds nearly to the integral.
    u   centeru)   Non integrating mode. Skip integral test.u   x_limt   modeu   integralt   atolg-C6?N(   R   t   pytestt   skipR   R   R   R   t   sum(   t   model_classR   t
   parameterst   modelt   values(    (    sH   lib/python2.7/site-packages/astropy/convolution/tests/test_discretize.pyt   test_pixel_sum_1D   s    
c         C` s\   t  d d d  } t j d d  } | |  } t | d
 d |  } t | | d d d	 S(   ut   
    Discretize Gaussian with different modes and check
    if result is at least similar to Gaussian1D.eval().
    i   i    i   iie   R   R   gMbP?N(   iie   (   R   t   npt   arangeR   R   (   R   R   t   xR   t   disc_values(    (    sH   lib/python2.7/site-packages/astropy/convolution/tests/test_discretize.pyt   test_gaussian_eval_1D+   s
    c         C` s   |  t  k r( | d k r( t j d  n  t |  } t |  |  } t | t |  d t |  d d | } t | j   t |  d d d d	 S(
   uK   
    Test if the sum of all pixels corresponds nearly to the integral.
    u   centeru)   Non integrating mode. Skip integral test.u   x_limu   y_limR   u   integralR   g-C6?N(   R
   R   R   R   R   R   R   R   (   R   R   R   R   R   (    (    sH   lib/python2.7/site-packages/astropy/convolution/tests/test_discretize.pyt   test_pixel_sum_2D8   s    
c         C` s   t  d d d d d  } t j d d  } t j d d  } t j | |  \ } } | | |  } t | d	 d
 d |  } t | | d d d S(   us   
    Discretize Gaussian with different modes and check
    if result is at least similar to Gaussian2D.eval()
    g{Gz?i    i   ii   R   R   N(   ii   (   ii   (   R	   R   R   t   meshgridR   R   (   R   R   R   t   yR   R   (    (    sH   lib/python2.7/site-packages/astropy/convolution/tests/test_discretize.pyt   test_gaussian_eval_2DH   s    u   not HAS_SCIPYc          C` s   t  d d d d d  t  d d d d d  t  d d d d d  g }  t j d d  } t j d d  } t j | |  \ } } xH |  D]@ } | | |  } t | d d d d } t | | d	 d q Wd
 S(   u1   
    Discretize Gaussian with integrate mode
    g{Gz?i    i   i   ii   R   u	   integrateR   N(   ii   (   ii   (   R	   R   R   R   R   R   (   t
   model_listR   R    R   R   R   (    (    sH   lib/python2.7/site-packages/astropy/convolution/tests/test_discretize.pyt$   test_gaussian_eval_2D_integrate_modeZ   s    c          C` s^   t  d d d  }  t |  d d d d d	 } t | j   t j d t j  d d
 d d S(   uN   
    Test subpixel accuracy of the integrate mode with gaussian 1D model.
    i   i    g?ii   R   u	   integratet   factorid   R   gh㈵>N(   ii   (   R   R   R   R   R   t   sqrtt   pi(   t   gauss_1DR   (    (    sH   lib/python2.7/site-packages/astropy/convolution/tests/test_discretize.pyt   test_subpixel_gauss_1Dn   s    c          C` s^   t  d d d d d  }  t |  d d d d d d	 } t | j   d t j d
 d d d S(   uN   
    Test subpixel accuracy of the integrate mode with gaussian 2D model.
    i   i    g?ii   R   u	   integrateR$   id   g{Gz?R   gh㈵>N(   ii   (   ii   (   R	   R   R   R   R   R&   (   t   gauss_2DR   (    (    sH   lib/python2.7/site-packages/astropy/convolution/tests/test_discretize.pyt   test_subpixel_gauss_2Dx   s    c          C` s9   d   }  t  |  d  } t | t j d d  d  d S(   u7   
    Test discretize when a 1d function is passed.
    c         S` s   |  d S(   Ni   (    (   R   (    (    sH   lib/python2.7/site-packages/astropy/convolution/tests/test_discretize.pyt   f   s    ii   i   N(   ii   (   R   R   R   R   (   R+   R    (    (    sH   lib/python2.7/site-packages/astropy/convolution/tests/test_discretize.pyt   test_discretize_callable_1d   s    	c          C` sW   d   }  t  |  d d	  } t j d
  d \ } } | d | d } t | |  d S(   u7   
    Test discretize when a 2d function is passed.
    c         S` s   |  d | d S(   Ni   (    (   R   R    (    (    sH   lib/python2.7/site-packages/astropy/convolution/tests/test_discretize.pyR+      s    ii   i   i   i   N(   ii   (   ii   (   i   i   (   R   R   t   indicesR   (   R+   t   actualR    R   t   desired(    (    sH   lib/python2.7/site-packages/astropy/convolution/tests/test_discretize.pyt   test_discretize_callable_2d   s
    	c          C` sK   t  j t   }  t t d  d  Wd QX|  j j d d k sG t  d S(   u   
    Test type exception.
    i    ii   Nu   Model must be callable.(   ii   (   R   t   raisest	   TypeErrorR   t   floatt   valuet   argst   AssertionError(   t   exc(    (    sH   lib/python2.7/site-packages/astropy/convolution/tests/test_discretize.pyt   test_type_exception   s    c       	   C` sQ   d   }  t  j t   } t |  d d  Wd QX| j j d d k sM t  d S(	   u&   
    Test dimension exception 1d.
    c         S` s   |  d S(   Ni   (    (   R   (    (    sH   lib/python2.7/site-packages/astropy/convolution/tests/test_discretize.pyR+      s    ii   Ni    u)   y range specified, but model is only 1-d.(   ii   (   ii   (   R   R1   t
   ValueErrorR   R4   R5   R6   (   R+   R7   (    (    sH   lib/python2.7/site-packages/astropy/convolution/tests/test_discretize.pyt   test_dim_exception_1d   s    	c          C` sN   d   }  t  j t   } t |  d  Wd QX| j j d d k sJ t  d S(   u&   
    Test dimension exception 2d.
    c         S` s   |  d | d S(   Ni   (    (   R   R    (    (    sH   lib/python2.7/site-packages/astropy/convolution/tests/test_discretize.pyR+      s    ii   Ni    u'   y range not specified, but model is 2-d(   ii   (   R   R1   R9   R   R4   R5   R6   (   R+   R7   (    (    sH   lib/python2.7/site-packages/astropy/convolution/tests/test_discretize.pyt   test_dim_exception_2d   s    	c          C` sN   d   }  t  j t   } t |  d  Wd  QX| j j d d k sJ t  d  S(   Nc         S` s   |  d | d S(   Ni   (    (   R   R    (    (    sH   lib/python2.7/site-packages/astropy/convolution/tests/test_discretize.pyR+      s    g/$$g(\u&@i    uT   The difference between the upper an lower limit of 'x_range' must be a whole number.(   g/$$g(\u&@(   R   R1   R9   R   R4   R5   R6   (   R+   R7   (    (    sH   lib/python2.7/site-packages/astropy/convolution/tests/test_discretize.pyt   test_float_x_range_exception   s    	c       	   C` sQ   d   }  t  j t   } t |  d d	  Wd  QX| j j d d k sM t  d  S(
   Nc         S` s   |  d | d S(   Ni   (    (   R   R    (    (    sH   lib/python2.7/site-packages/astropy/convolution/tests/test_discretize.pyR+      s    ii   g/$$g(\u&@i    uT   The difference between the upper an lower limit of 'y_range' must be a whole number.(   ii   (   g/$$g(\u&@(   R   R1   R9   R   R4   R5   R6   (   R+   R7   (    (    sH   lib/python2.7/site-packages/astropy/convolution/tests/test_discretize.pyt   test_float_y_range_exception   s    	(   u   model_classu   mode(   u   model_classu   mode(4   t
   __future__R    R   R   R   t	   itertoolsR   t   numpyR   t   numpy.testingR   t   utilsR   t   modeling.functional_modelsR   R   R   R	   R
   R   t   modeling.tests.example_modelsR   R   t   modeling.tests.test_modelsR   t   scipyt   Truet	   HAS_SCIPYt   ImportErrort   Falset   modest   test_models_1Dt   test_models_2Dt   markt   parametrizet   listt   productR   R   R   R!   t   skipifR#   R(   R*   R,   R0   R8   R:   R;   R<   R=   (    (    (    sH   lib/python2.7/site-packages/astropy/convolution/tests/test_discretize.pyt   <module>   s<   ".

00

	
							