a
    ߙfbH                     @   sv   d dl Z d dlZd dlZd dlmZmZmZ d dlm	Z	m
Z
 d dlmZ d dlmZ d dlmZmZ G dd dZdS )	    N)convolveconvolve_fftconvolve_models)modelsfitting)NumpyRNGContext)	HAS_SCIPY)assert_allcloseassert_almost_equalc                   @   s   e Zd Zejdddgejddd Zejdddgejddd Zejdddgejdd	d
 Z	ejdddgdd Z
ejdddgdd Zejdddgejddd ZdS )TestConvolve1DModelsmoder   r   znot HAS_SCIPYc                 C   sZ   t ddd}t ddd}t|||d}tdd}t| d}t|||dd d S )	N   r   r      z(model(x), kernel(x))h㈵>Zatol)r   
Gaussian1Dr   nparangeevalr	   selfr   kernelmodel
model_convxans r   Mlib/python3.9/site-packages/astropy/convolution/tests/test_convolve_models.py,test_is_consistency_with_astropy_convolution   s    zATestConvolve1DModels.test_is_consistency_with_astropy_convolutionc                 C   sz   ddl m} tddd}tddd}t|||d}tdd}|||||dd}t|||||  dd	 d S )
Nr   fftconvolver   r   r   r   samer   r   )	scipy.signalr"   r   r   r   r   r   r	   sumr   r   r"   r   r   r   r   r   r   r   r   test_against_scipy   s    z'TestConvolve1DModels.test_against_scipyc                 C   sp   ddl m} tddd}tddd}t|||dd}tdd}|||||dd	}t|||d
d d S )Nr   r!   r   Fr   Znormalize_kernelr   r   r#   r   r   r   )r$   r"   r   r   r   r   r   r	   r&   r   r   r   +test_against_scipy_with_additional_keywords'   s    z@TestConvolve1DModels.test_against_scipy_with_additional_keywordsc                 C   s   t dtdtj  dd}t dtdtj  dd}t|||dd}t ddttj  dtd}tdd}t||||d	d
 dS )z
        Test that convolving N(a, b) with N(c, d) gives N(a + c, b + d),
        where N(., .) stands for Gaussian probability density function,
        in which a and c are their means and b and d are their variances.
        r         Fr(      r   r   MbP?r   N)	r   r   mathZsqrtr   Zpir   r   r	   )r   r   r   r   r   r   r   r   r   r   test_sum_of_gaussians5   s    $z*TestConvolve1DModels.test_sum_of_gaussiansc                 C   sd   t  }t  }t|||d}tddd}|d |dk  | d |dk  }t|||dd d S )Nr   r   c   r   r-   r   )r   Box1Dr   r   linspacer	   r   r   r   r   test_convolve_box_modelsF   s    "z-TestConvolve1DModels.test_convolve_box_modelsc                 C   s   t  }t  }tddd}t jdd}td* ||tjjt|d }W d   n1 sb0    Y  t	|||d	d
}t
 }||||}	t|	|| }
t|
ddd dS )z:
        test that a convolve model can be fitted
        r      r1   
   )Z	amplitude{   )sizeNFr(   g        r*   )decimal)r   r2   r   r   r3   r   ZrandomZnormallenr   r   ZLevMarLSQFitterZmeanr
   )r   r   Zb1Zg1r   Z
fake_modelZ	fake_dataZ
init_modelZfitterZfitted_modelmer   r   r   test_fitting_convolve_modelsP   s    
8z1TestConvolve1DModels.test_fitting_convolve_modelsN)__name__
__module____qualname__pytestZmarkZparametrizeZskipifr    r'   r)   r/   r4   r<   r   r   r   r   r      s    
	



	
r   )r.   Znumpyr   r@   Zastropy.convolution.convolver   r   r   Zastropy.modelingr   r   Zastropy.utils.miscr   Z"astropy.utils.compat.optional_depsr   Znumpy.testingr	   r
   r   r   r   r   r   <module>   s   