a
    ߙfb<                     @   s  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	 d dl
mZ d dlmZ d dlmZ d dlmZmZ d dlmZmZmZ d dlZd	ZeeeeZg d
ZddgZddgZddgZ ee!e"efee	dfe	dfg Z#G dd dZ$G dd dZ%G dd dZ&e j'(dedd Z)e j'(dddd Z*dd Z+e j',dd d! Z-e j',d"d#d$ Z.d%d& Z/e j'(ded'd( Z0e j'(d)eeed*d+ Z1d,d- Z2d.d/ Z3dS )0    N)nullcontext)convolveconvolve_fft)Gaussian2DKernel)AstropyUserWarning)units)	HAS_SCIPY
HAS_PANDAS)assert_array_almost_equal_nulpassert_array_almost_equalassert_allclose)z>f4z<f4>f8z<f8Nfillwrapextendinterpolater   TFr   c                
   @   sv  e Zd Zdd Zdd Zejde	e
eeeedd Zejde	e
eeeedd	 Zejde	e
eeeed
d Zejdedd Zejdedd Zejde
dd Zejde
dd Zejde	e
eeedd Zejde	e
eeedd Zejde	e
edd Zejde	e
edd  Zejd!ed"d# Zd$S )%TestConvolve1Dc                 C   s8   g d}g d}t ||dd}t|tg dd dS )J
        Test that convolve works correctly when inputs are lists
                    r         皙?g333333?r   Nboundary        g@      @ffffff@r#   g333333@r!   
   r   r
   nparrayselfxyz r-   Flib/python3.9/site-packages/astropy/convolution/tests/test_convolve.py	test_list%   s    zTestConvolve1D.test_listc                 C   s0   d}d}t ||dd}t|tg dd dS )zK
        Test that convolve works correctly when inputs are tuples
        r   r   Nr   r    r$   r%   r(   r-   r-   r.   
test_tuple0   s    zTestConvolve1D.test_tuple)r   nan_treatmentnormalize_kernelpreserve_nandtypec           	      C   sR   t jg d|dtj }t jg d|d}t||||||d}|j|jksNJ dS )zS
        Test that convolve works correctly when input array is a Quantity
        r   r4   r   r   r1   r2   r3   N)r&   r'   uZphr   Zunit)	r)   r   r1   r2   r3   r4   r*   r+   r,   r-   r-   r.   test_quantity;   s    
zTestConvolve1D.test_quantityc                 C   s   g d}g d}t j||d}t j||d}	d|j_d|	j_t||	||||d}
t t j||d|kslJ t t j||d|	ksJ dS )r   )      ?      @r"         @r"         @       @r   r5   Fr6   N)r&   r'   flags	writeabler   all)r)   r   r1   r2   r3   r4   r'   kernelr*   r+   r,   r-   r-   r.   test_input_unmodifiedO   s    
z$TestConvolve1D.test_input_unmodifiedc                 C   s   dddt jdddg}g d}t j||d}t j||d}	d|j_d|	j_| }
|	 }t||	||||d	}t |}t |}| }| }t |
| || ksJ t || |	| ksJ t t || sJ t t |	| sJ d
S )zB
        Test that convolve doesn't modify the input data
        r9   r:   r"   r<   r=   r   r5   Fr6   N)	r&   nanr'   r>   r?   copyr   isnanr@   )r)   r   r1   r2   r3   r4   r'   rA   r*   r+   Zx_copyZy_copyr,   Zarray_is_nanZkernel_is_nanZarray_not_nanZkernel_not_nanr-   r-   r.   test_input_unmodified_with_nank   s&    


z-TestConvolve1D.test_input_unmodified_with_nandtype_arraydtype_kernelc                 C   sB   t jg d|d}t jg d|d}t||}|j|jks>J dS )G
        Test that 32- and 64-bit floats are correctly handled
        r9          @      @r5   r!   r9   r!   Nr&   r'   r   r4   r)   rH   rI   r*   r+   r,   r-   r-   r.   
test_dtype   s    
zTestConvolve1D.test_dtype)convfuncr   c                 C   sB   t jg ddd}t jdgdd}||||d}t j|| dS )zV
        Test that a unit kernel with a single element returns the same array
        rK   r   r5   r9   r   N)r&   r'   Ztestingr   )r)   r   rR   r*   r+   r,   r-   r-   r.   test_unity_1_none   s    z TestConvolve1D.test_unity_1_noner   c                 C   sr   t jg ddd}t jg ddd}t|||d}|du r\t |t jg dddksnJ nt ||ksnJ dS )z|
        Test that a unit kernel with three elements returns the same array
        (except when boundary is None).
        rK   r   r5   rN   r   Nr!   rL   r!   r&   r'   r   r@   r)   r   r*   r+   r,   r-   r-   r.   test_unity_3   s    "zTestConvolve1D.test_unity_3c                 C   s   t jg ddd}t jg ddd}t|||dd}|du r^t |t jg dddksJ nt|d	krt |t jg d
ddksJ nJ|dkrt |t jg dddksJ n t |t jg dddksJ dS )z
        Test that the different modes are producing the correct results using
        a uniform kernel with three elements
        )r9   r!   rM   r   r5   r9   r9   r9   Fr   r2   N)r!   r:   r!   r   r9   r:   rM   r   )r:   r:   r:   )rL   r:   r;   rU   rV   r-   r-   r.   test_uniform_3   s    """zTestConvolve1D.test_uniform_3r6   c           	   	   C   s   t jdt jdgdd}t jg ddd}|dkrD|sDtjtdd}nt }|$ t||||||d	}W d
   n1 sx0    Y  |rt |d sJ t 	|}t 	|}|d
u rt 
|t jg dddksJ nt 
||ksJ d
S )z
        Test that a unit kernel with three elements returns the same array
        (except when boundary is None). This version includes a NaN value in
        the original array.
        r9   rM   r   r5   rN   r   z9nan_treatment='interpolate', however, NaN values detectedmatchr6   Nr   r!   r!   r!   )r&   r'   rC   pytestwarnsr   r   r   rE   
nan_to_numr@   )	r)   r   r1   r2   r3   r*   r+   ctxr,   r-   r-   r.   test_unity_3_withnan   s&    
$

"z#TestConvolve1D.test_unity_3_withnanc           	      C   s   t jdt jdgdd}t jg ddd}t||||||d}|rRt |d sRJ t |}g dg d	g d
g dg dg dg dg dg dg dg dg dg dg dg dg dd|||f }|rd|d< t|t j|ddd dS )z
        Test that the different modes are producing the correct results using
        a uniform kernel with three elements. This version includes a NaN
        value in the original array.
        r9   rM   r   r5   rX   r6   r   )r      r   )r   r   r   )r   UUUUUU?r   )r   r   r   )      ?rd         ?)rg   r   g      @)gUUUUUU?re   r9   )r   r      )rd   rd   rd   )r   r   r   )re   re   re   )r   r   r   r   rd   rh   )rh   r   	   )gUUUUUU?re   rL   )rd   r   r   ))Nr   T)Nr   F)Nr   T)Nr   F)r   r   T)r   r   F)r   r   T)r   r   F)r   r   T)r   r   F)r   r   T)r   r   F)r   r   T)r   r   F)r   r   T)r   r   Fr   r$   N)r&   r'   rC   r   rE   ra   r
   )	r)   r   r1   r2   r3   r*   r+   r,   rsltr-   r-   r.   test_uniform_3_withnan  s>    

z%TestConvolve1D.test_uniform_3_withnanrY   c                 C   s   |rt d g d}g d}tjt|ddds6J t||||d}g dg d	g d
g dd| }t|tj|ddd dS )zK
        Test that convolve works correctly with zero sum kernels.
        (You can't normalize by a zero sum kernel	r   rd   rh   r   r   r   r   r   rj   	rp   rp   rp   r   rp   rp   rp   rp   r   g:0yE>)ZatolrY   )	r!   r!   r!   r!   r!   r!   r!   r!   r!   )	                  r!   r!         $@      5@     @@      G@)	g      Bg      ;g      2g      "r!         "@      2@      ;@      B@)	g      $rq   rr   rs   r!   r9   rM   r;   rt   r   r   r5   r$   N)r_   xfailr&   Zisclosesumr   r
   r'   r)   r   r2   r*   r+   r,   rk   r-   r-   r.   test_zero_sum_kernel7  s    
z#TestConvolve1D.test_zero_sum_kernelc                 C   sz   |rt d g d}tjg dg ddd}t||||d}g dg d	g d
g dd| }t|tj|ddd dS )zQ
        Test that convolve works correctly with integer masked kernels.
        rm   rn   ro   )	r   r   r   r   r   r   r   r   r   r!   mask
fill_valuerY   )	r!   r!   r!   r!   rx   r!   r!   r!   r!   )	rs   rM   r;   r=   rx   rt   ru   rv   rw   )	g      ?g      5g      &rs   rx   rt         4@g      >@      D@)	      r!   r:   r<   rx   rt         (@      .@      3@r   r   r5   r$   N)r_   r|   mar'   r   r
   r&   r~   r-   r-   r.   test_int_masked_kernelR  s    
z%TestConvolve1D.test_int_masked_kernelr3   c                 C   sf   t jg dg ddd}tjg ddd}t|||d}|rVt|d	 sNJ d
|d	< t|dd dS )zP
        Test that convolve works correctly with integer masked arrays.
        )rh   r   r         )r   r   r   r   r   r!   r   rX   r   r5   )r3   rd   r   )gUUUUUU@r   r      r   r$   N)r   r'   r&   r   rE   r
   )r)   r3   r*   r+   r,   r-   r-   r.   test_int_masked_arrayl  s    z$TestConvolve1D.test_int_masked_arrayN)__name__
__module____qualname__r/   r0   r_   markparametrize	itertoolsproductBOUNDARY_OPTIONSNANHANDLING_OPTIONSNORMALIZE_OPTIONSPRESERVE_NAN_OPTIONSVALID_DTYPESr8   rB   rF   VALID_DTYPE_MATRIXrQ   BOUNDARIES_AND_CONVOLUTIONSrS   rW   r[   rc   rl   r   r   r   r-   r-   r-   r.   r   #   s   


"




&
-

r   c                   @   s   e Zd Zdd Zejdedd Zejde	dd Z
ejde	d	d
 Zejde	dd Zejde	dd Zejde	dd Zejde	dd Zejde	dd ZdS )TestConvolve2Dc                 C   sb   g dg dg dg}t ||dddd}t||d t ||dddd}t|t|td d d	S )
r   r   r   r   r   r   Tr   r   r2   r$   Frj   N)r   r
   r&   r'   floatr)   r*   r,   r-   r-   r.   r/     s    zTestConvolve2D.test_listrG   c                 C   s^   t jg dg dg dg|d}t jg dg dg dg|d}t||}|j|jksZJ dS rJ   rK   r:   r"   r;   r<   r=   rx   r5   r^   rN   NrO   rP   r-   r-   r.   rQ     s    


zTestConvolve2D.test_dtyper   c                 C   sV   t jg dg dg dgdd}t jdggdd}t|||d}t ||ksRJ dS )	zD
        Test that a 1x1 unit kernel returns the same array
        rK   r   r   r   r5   r9   r   NrU   rV   r-   r-   r.   test_unity_1x1_none  s    
z"TestConvolve2D.test_unity_1x1_nonec                 C   s   t jg dg dg dgdd}t jg dg dg dgdd}t|||d}|d	u rt |t jg dg d
g dgddksJ nt ||ksJ d	S )zl
        Test that a 3x3 unit kernel returns the same array (except when
        boundary is None).
        rK   r   r   r   r5   r^   rN   r   N)r!   r"   r!   rU   rV   r-   r-   r.   test_unity_3x3  s*    

zTestConvolve2D.test_unity_3x3c                 C   s  t jg dg dg dgdd}t jg dg dg dgdd}t|||dd}|d	u rt|t jg d
g dg d
gddd n|dkrt|t jg dg dg dgddd nZ|dkrt|t jg dg dg dgddd n(t|t jg dg dg dgddd d	S )u
        Test that the different modes are producing the correct results using
        a 3x3 uniform kernel.
        )r!   r!   rM   )r9   r!   r!   rT   r   r5   rX   FrY   Nr^   )r!   r;   r!   r$   r   rZ   )rM   r;   r"   )rM   rM   rL   r   )r;   r;   r;   )rL   r<   r   )r:   r;   r=   )r;   r"   r:   r&   r'   r   r
   rV   r-   r-   r.   test_uniform_3x3  s`    

zTestConvolve2D.test_uniform_3x3c                 C   s   t jg ddt jdgg dgdd}t jg dg dg dgdd}t|||d	d
d}t |d shJ t |}t |}|du rt |t jg dg dg dgddksJ nt ||ksJ dS )z
        Test that a 3x3 unit kernel returns the same array (except when
        boundary is None). This version includes a NaN value in the original
        array.
        rK   r:   r;   r   r   r5   r^   rN   r   Tr   r1   r3   )r   r   N)r&   r'   rC   r   rE   ra   r@   rV   r-   r-   r.   test_unity_3x3_withnan  s4    





z%TestConvolve2D.test_unity_3x3_withnanc                 C   s,  t jg ddt jdgg dgdd}t jg dg dg dgdd}t|||dd	d
}|du rt|t jg dg dg dgddd n|dkrt|t jg dg dg dgddd nn|dkrt|t jg dg dg dgddd n<|dkr t|t jg dg dg dgddd ntddS )
        Test that the different modes are producing the correct results using
        a 3x3 uniform kernel. This version includes a NaN value in the
        original array.
        r!   r!   r:   r9   r!   r!   rM   r!   r   r5   rX   r   Fr   r1   r2   Nr^   )r!   r=   r!   r$   )r9   r"   r:   )r:   r=   r<   )r:   r:   rM   r   )r=   r=   r=   r   )rL   rx         0@)r"   r=   g      &@)r=   r<   r;   Invalid boundary specificationr&   r'   rC   r   r
   
ValueErrorrV   r-   r-   r.   test_uniform_3x3_withnanfilled  sh    




z-TestConvolve2D.test_uniform_3x3_withnanfilledc                 C   s,  t jg ddt jdgg dgdd}t jg dg dg dgdd}t|||dd	d
}|du rt|t jg dg dg dgddd n|dkrt|t jg dg dg dgddd nn|dkrt|t jg dg dg dgddd n<|dkr t|t jg dg dg dgddd ntddS )r   r   r9   r!   r   r   r5   rX   r   Tr   Nr^   rN   r$   r   )g      ?      ?rf   )rf   r9         ?)rf   rf   g      ?r   r   )g      ?g      ?rL   )r   r9   g      ?)r9   r   g      ?r   r   rV   r-   r-   r.    test_uniform_3x3_withnaninterped,  sh    




z/TestConvolve2D.test_uniform_3x3_withnaninterpedc                 C   s(  t jg dg dg dgdd}t jg dg dg dgdd}t|||dd	d
}|d u rt|t jg dg dg dgddd n|dkrt|t jg dg dg dgddd nn|dkrt|t jg dg dg dgddd n<|dkrt|t jg dg dg dgddd ntdd S )Nr   )r9   rL   r!   r   r   r5   )r9   rs   r9   )rs   r!   rs   r   Fr   r^   r$   )r9   r   rL   )r9   r!   rr   )       rs   rs   r   )r!   g       r;   )r"   r!         )rL   rM   r   r   )rL   rs   r   )r!   r!   r9   )rL   r   rL   r   )r&   r'   r   r
   r   rV   r-   r-   r.   test_non_normalized_kernel_2DR  sh    



z,TestConvolve2D.test_non_normalized_kernel_2DN)r   r   r   r/   r_   r   r   r   rQ   r   r   r   r   r   r   r   r   r-   r-   r-   r.   r   ~  s"   



!

%
%r   c                   @   s   e Zd Zdd Zejdedd Zejde	dd Z
ejde	d	d
 Zejde	dd Zejdee	edd Zejde	dd Zejde	dd ZdS )TestConvolve3Dc                 C   sf   g dg dg dgg dg dg dgg dg dg dgg}t ||dddd}t|d |d dS )	r   r   r   r   Fr      r$   N)r   r
   r   r-   r-   r.   r/   u  s    
zTestConvolve3D.test_listrG   c                 C   s^   t jg dg dg dg|d}t jg dg dg dg|d}t||}|j|jksZJ dS r   rO   rP   r-   r-   r.   rQ     s    


zTestConvolve3D.test_dtyper   c                 C   s   t jg dg dg dgg dg dg dgg dg dg d	ggd
d}t jdgggd
d}t|||d}t ||ks~J dS )zF
        Test that a 1x1x1 unit kernel returns the same array
        r9   rL   r9   rL   rM   r9   rM   rL   r"   r:   rM   r9   )r"   r!   rL   r;   r9   r9   r<   r!   rL   r=   rL   rM   rx   rL   rL   r   r5   r9   r   NrU   rV   r-   r-   r.   test_unity_1x1x1_none  s    z$TestConvolve3D.test_unity_1x1x1_nonec              
   C   s   t jg dg dg dgg dg dg dgg dg dg d	ggd
d}t jdd
d}d|d< t|||d}|du rt |t jg dg dg dgg dg dg dgg dg dg dggd
dksJ nt ||ksJ dS )zn
        Test that a 3x3x3 unit kernel returns the same array (except when
        boundary is None).
        r   r   r   r   r"   rM   rL   r   r   r   r   r   r5   rh   rh   rh   r9   r   r   Nr^   r   )r&   r'   zerosr   r@   rV   r-   r-   r.   test_unity_3x3x3  s"    zTestConvolve3D.test_unity_3x3x3c              	   C   s  t jg dg dg dgg dg dg dgg dg dg d	ggd
d}t jdd
d}t|||dd}|du rt|t jg dg dg dgg dg dg dgg dg dg dggd
dd n|dkr$t|t jg dg dg dgg dg dg dgg dg dg dggd
dd n|dkrt|t jg dg dg dgg dg dg dgg dg dg dggd
dd nRt|t jg dg d g d!gg d"g d#g d$gg d%g d&g d'ggd
dd dS )(r   r   r   r   r   r   r   r   r   r   r   r5   r   FrY   Nr^   )r!        @T@r!   r$   r   )      7@g      <@r   )g     A@rw         9@)r   g      A@ry   )r         I@r   )     O@r   r{   )rw         N@rz   )      @@r   r   )r   g     N@      6@)r{   g      F@r   r   )r   r   r   )g     @P@      K@     E@)     R@g     P@     L@)     @U@     S@     Q@)      X@r   rw   )g      [@r   r   )g      ^@g     V@      O@)g     _@      V@g     H@)g     a@r        I@)g     `c@g      Z@g     J@)r&   r'   onesr   r
   rV   r-   r-   r.   test_uniform_3x3x3  sV    

z!TestConvolve3D.test_uniform_3x3x3)r   r1   c              
   C   s  t jg dg dg dgg ddt jdgg dgg dg d	g d
ggdd}t jddd}d|d< t||||dd}t |d sJ t |}t |}|du rt |t jg dg dg dgg dg dg dgg dg dg dggddksJ nt ||ksJ dS )z
        Test that a 3x3x3 unit kernel returns the same array (except when
        boundary is None). This version includes a NaN value in the original
        array.
        r   r   r   r   r"   rL   r   r   r   r   r   r5   r   r9   r   Tr   Nr^   )r&   r'   rC   r   r   rE   ra   r@   )r)   r   r1   r*   r+   r,   r-   r-   r.   test_unity_3x3x3_withnan  s,    



z'TestConvolve3D.test_unity_3x3x3_withnanc              	   C   s  t jg dg dg dgg ddt jdgg dgg dg d	g d
ggdd}t jddd}t|||ddd}|du rt|t jg dg dg dgg dg dg dgg dg dg dggddd n"|dkr*t|t jg dg dg dgg dg dg dgg dg dg dggddd n|dkrt|t jg dg dg dgg dg dg dgg dg dg dggddd nf|d krt|t jg d!g d"g d#gg d$g d%g d&gg d'g d(g d)ggddd ntd*dS )+r   r   r   r   r   r"   rL   r   r   r   r   r   r5   r   r   Fr   Nr^   r!   r   r!   r$   r   r         *@r   r   r   r   g      ?@r        B@     G@r   r   r   rv   r   r   g      8@g      =@r   r   r   g      M@r   rv   g     D@r   r   )r   r   r   r   r   r   r   g      R@r   r   g     T@r         Q@     @W@r   r   g     @Z@r   r   g     @]@r   g     M@g      _@r   rw   g     @a@r   g      H@g      c@g     @Y@r   Invalid Boundary Option)r&   r'   rC   r   r   r
   r   rV   r-   r-   r.   !test_uniform_3x3x3_withnan_filled  s    

	

		z0TestConvolve3D.test_uniform_3x3x3_withnan_filledc              	   C   s  t jg dg dg dgg ddt jdgg dgg dg d	g d
ggdd}t jddd}t|||ddd}| d }|t |  | }|du rt|t jg dg dg dgg dg dg dgg dg dg dggdd| d n|dkrRt|t jg dg dg dgg dg dg dgg dg dg dggdd| d n|d kr|t|t |	dg dd nj|d!krt|t jg d"g d#g d$gg d%g d&g d'gg d(g d)g d*ggdd| d nt
d+dS ),r   r   r   r   r   r"   rL   r   r   r   r   r   r5   r   r   Tr   r   Nr^   r   r$   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )r&   r'   rC   r   r   r}   Zisfiniter
   ZtileZastyper   )r)   r   r*   r+   r,   ZkernsumZmidr-   r-   r.   #test_uniform_3x3x3_withnan_interped/  s    

			

 
			z2TestConvolve3D.test_uniform_3x3x3_withnan_interpedN)r   r   r   r/   r_   r   r   r   rQ   r   r   r   r   r   r   r   r   r   r   r-   r-   r-   r.   r   t  s&   





0r   r   c                 C   s   t jg ddd}t jg ddd}t||| dd}| dkrXt|t jg dd	dd
 nj| du r|t|t jg dd	dd
 nF| dkrt|t jg dd	dd
 n"| dkrt|t jg dd	dd
 dS )zo
    Regression test for #6264: make sure that asymmetric convolution
    functions go the right direction
    )rM   r!   r9   r   r5   ri   FrY   r   )r;   rt   rL   r   r$   N)r!   rt   r!   r   )r   rt   rM   r   )rx   rt   r"   r   )r   r*   r+   r,   r-   r-   r.   test_asymmetric_kerneld  s    r   ndimsri   c                 C   sh   t jd t jjdg|   }t jd t jjdg|   }t||dd}t||dd}t||d d S )Nr   rh   r   r      )r&   ZrandomZseedZrandnZrandr   r   r
   )r   r'   rA   Zconv_fZconv_dr-   r-   r.   test_convolution_consistency{  s    r   c                  C   s\   t g d} t g d}tt || dt|| dd tt || dt|| dd d S )Nri   r   r   rh   rd   r   sameFr2   )r&   r'   r   r   r   )r*   r+   r-   r-   r.   &test_astropy_convolution_against_numpy  s    r  znot HAS_SCIPYc                  C   sd   ddl m}  tg d}tg d}t| ||dt||dd t| ||dt||dd d S )Nr   )fftconvolveri   r   r   Fr  )Zscipy.signalr  r&   r'   r   r   r   )r  r*   r+   r-   r-   r.   &test_astropy_convolution_against_scipy  s    r  znot HAS_PANDASc                  C   sd   dd l } ttddd}d}t|t|f| }| |}t|t|f| }t|| d S )Nr   i  i  r$   rh   )pandasr&   r'   Zlinspacer   r   ZSeriesr   )r  ZwaveZboxcarZnonseries_resultZwave_seriesZseries_resultr-   r-   r.   test_regression_6099  s    
r  c                  C   sF   t dd } tt td|  W d    n1 s80    Y  d S )Nrh   rM   Zglork)r&   r   r_   raises	TypeErrorr   )rA   r-   r-   r.   test_invalid_array_convolve  s    r	  c                 C   s\   t g dg dg dg}t d}d|d< t||d| d}t|d	d
ddf | d S )N)r   rd   rh   rd   r   )r   r   rd   r   r   )r   r   r   r   r   )r   r   r   )r   r   F)r2   r   r   r   r   rj   )r&   r'   r   r   r   )r   rA   imageresultr-   r-   r.   !test_non_square_kernel_asymmetric  s
    
r  rY   c                 C   s   t ddd}t|jtj}tj||jd d ddd}tjtdd6 t	||| d	|d
}t
t|snJ W d    n1 s0    Y  t|jd d |jd d ftj}tj||jd d ddd}t	||| d	|d
}t
t| sJ d S )Nr   r   r   rd   Zconstant)Z	pad_widthmodeZconstant_valuesznan_treatment='interpolate', however, NaN values detected post convolution. A contiguous region of NaN values, larger than the kernel size, are present in the input array. Increase the kernel size to avoid this.r\   r   r   )r   r&   ZfullshaperC   Zpadr_   r`   r   r   anyrE   )r   r2   rA   Znan_centroidr
  r  r-   r-   r.   test_uninterpolated_nan_regions  s(    	
2&
r  c                  C   sj   t g dg dg dg} dtj }dtj }t|| d}t| |dt jdd}t| |dt jdd}d	S )
z
    Issue #9168 pointed out that kernels can be (unitless) quantities, which
    leads to crashes when inplace modifications are made to arrays in
    convolve/convolve_fft, so we now strip the quantity aspects off of kernels.
    rK   r   r   r   )Zx_stddevr   T)r   r   r3   N)r&   r'   r7   Zarcsecr   r   rC   r   )r*   Zkernel_fwhmZ
pixel_sizerA   r  r-   r-   r.   test_regressiontest_issue9168  s    


r  c                   C   sL   t jtdd* tdtjdgg ddd W d    n1 s>0    Y  d S )NzSetting nan_treatment='interpolate' requires the kernel to be normalized, but the input kernel has a sum close to zero. For a zero-sum kernel and data with NaNs, set nan_treatment='fill'.r\   r   rh   )rp   rd   rp   Fr  )r_   r  r   r   r&   rC   r-   r-   r-   r.   !test_convolve_nan_zero_sum_kernel  s    r  )4r_   Znumpyr&   Znumpy.mar   
contextlibr   Zastropy.convolution.convolver   r   Zastropy.convolution.kernelsr   Zastropy.utils.exceptionsr   Zastropyr   r7   Z"astropy.utils.compat.optional_depsr   r	   Znumpy.testingr
   r   r   r   r   listr   r   r   r   r   r   zipcycler   r   r   r   r   r   r   r   r  Zskipifr  r  r	  r  r  r  r  r-   r-   r-   r.   <module>   sl     ] w q









