a
    ߙfbg                     @   s  d dl Zd dlZd dlmZ d dlmZ d dlmZ e	ddgddgd	d
ggZ
e	ddgddgdd	ggZejde
d dfeddfgdd Zed4 ejjddddZ
ejjddddZW d   n1 s0    Y  ejde
egdd Zed4 ejjd dddZ
ejjdd ddZW d   n1 s<0    Y  ejde
d dfedd fgdd Zed4 ejjddddZ
ejjddddZW d   n1 s0    Y  ejde
ddfeddfgdd Zed4 ejjd dd dZ
ejjdd d dZW d   n1 s$0    Y  ejde
d dfedd fgd!d" Zed4 ejjddd dZ
ejjddd dZW d   n1 s0    Y  ejde
ddfeddfgd#d$ ZdS )%    N)assert_allclose)RipleysKEstimator)NumpyRNGContext                  zpoints, x_min, x_max
   c                 C   st   d}t ddd}t|||||d}t g d}t||| |ddd	d
 t g d}t||| |ddd	d
 dS )a  
    Test against Ripley's K function implemented in R package `spatstat`
        +-+---------+---------+----------+---------+-+
      6 +                                          * +
        |                                            |
        |                                            |
    5.5 +                                            +
        |                                            |
        |                                            |
      5 +                     *                      +
        |                                            |
    4.5 +                                            +
        |                                            |
        |                                            |
      4 + *                                          +
        +-+---------+---------+----------+---------+-+
          1        1.5        2         2.5        3

        +-+---------+---------+----------+---------+-+
      3 + *                                          +
        |                                            |
        |                                            |
    2.5 +                                            +
        |                                            |
        |                                            |
      2 +                     *                      +
        |                                            |
    1.5 +                                            +
        |                                            |
        |                                            |
      1 +                                          * +
        +-+---------+---------+----------+---------+-+
         -3       -2.5       -2        -1.5       -1
    d   r   g      @r   )areax_miny_minx_maxy_max)r   r   r   禛 P@r   nonedataZradiimodegMbP?atol)r   r   r   ~jtT@r   translationN)nplinspacer   arrayr   )pointsr   r   r   rKestZANS_NONEZ	ANS_TRANS r%   ?lib/python3.9/site-packages/astropy/stats/tests/test_spatial.pytest_ripley_K_implementation   s    %
r'   {   )r   r   )lowhighsizeir"   c                 C   s8   d}t |d}tddd}t||| |ddd  d S )	N2   )r   r      r   r   r   r   )r   r   r    r   )r"   r   r$   r#   r%   r%   r&   test_ripley_uniform_propertyG   s    
r.   )i  r   zpoints, low, highc           	      C   s\   t d||||d}tddd}||}g d}|D ] }|| ||d}t||dd	 q6d S )
Nr   r   r   r   r   r   r         ?   ohserr   Zripleyr   皙?r   r   r   r    poissonr   )	r"   r)   r*   r$   r#   KposmodesmKest_rr%   r%   r&   test_ripley_large_densityW   s    

r;   c           	      C   sj   t d||||d}tddd}t||}g d}|D ](}t|| ||d}t||ddd q<d S )	Nr1   r   r   r   r   r   r   333333?r2   r   r4   r   Zrtol)r   r   r    meanr6   r   )	r"   r)   r*   r$   r#   Z	Kpos_meanr8   r9   Z	Kest_meanr%   r%   r&   test_ripley_modesh   s    
r@   )r,   r   c                 C   sJ   t d||||d}tddd}||}|| |dd}t||dd	 d S )
Nr   r/   r   r0   r1   	var-widthr   r4   r   r5   )r"   r)   r*   r$   r#   r7   r:   r%   r%   r&   #test_ripley_large_density_var_widthy   s    

rB   c                 C   s\   t d||||d}tddd}t|| |dd}t|| |dd}t||ddd	 d S )
Nr1   r<   r   r=   r3   r   rA   r4   r>   )r   r   r    r?   r   )r"   r)   r*   r$   r#   Z
Kest_ohserZKest_var_widthr%   r%   r&   test_ripley_var_width   s    
rC   )Znumpyr   ZpytestZnumpy.testingr   Zastropy.stats.spatialr   Zastropy.utils.miscr   r!   abZmarkZparametrizer'   ZrandomZuniformr.   r;   r@   rB   rC   r%   r%   r%   r&   <module>   sB   
2
0


2

2

2
	
2