a
    ߙfb'                     @   s8  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
 d dlmZ d dlmZ d dlmZmZ e
g dZd	d
 Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zejdedd edd dfedd edd edd fed g edd dfed g eddd dfgdd  ZdS )!    N)assert_equal)units)Time)AstropyUserWarning)
TimeSeries)aggregate_downsamplereduceat)2016-03-22T12:30:31z2016-03-22T12:30:322016-03-22T12:30:332016-03-22T12:30:342016-03-22T12:30:35c                  C   s   t jt dg d} tt dg dt j}t||  tt dt dd d d t j}t|t g d tt dg dt j}t|t g d ttt dt dd d d t jtt dt dd d d t j d S )N   )r                        r   )g      ?      @      @g      @)g      ?r   r   r   g      @r   r   g      @)	npaddr   Zarangesumr   ZmeanarrayZnanmean)Z
add_outputZ
sum_outputZmean_outputZnanmean_output r   Glib/python3.9/site-packages/astropy/timeseries/tests/test_downsample.pytest_reduceat   s    
$$"r   c                  C   sJ   t t} td  W d    n1 s(0    Y  | jjd dksFJ d S )Nr   z"time_series should be a TimeSeries)pytestraises	TypeErrorr   valueargs)excr   r   r   test_timeseries_invalid$   s    &r$   c                   C   s@   t jtdd tt dd W d    n1 s20    Y  d S )Nz3'time_bin_size' should be a Quantity or a TimeDeltamatchr   )time_bin_size)r   r   r    r   r   r   r   r   r   test_time_bin_invalid*   s    r(   c                  C   sP   t tg dgdgd} tjtdd t|  W d    n1 sB0    Y  d S )Nr   r   r   r   r   atimedatanamesz_With single 'time_bin_start' either 'n_bins', 'time_bin_size' or time_bin_end' must be providedr%   )r   
INPUT_TIMEr   r   r    r   )tsr   r   r   test_binning_arg_invalid2   s    r1   c                  C   sf   t tg dgdgd} t| dgdgtj d}t|jjdg t| ddgd	d
}t|jjddg d S )Nr)   r*   r+   r	   r   )time_bin_startr'   2016-03-22T12:30:31.000r
   r   r2   time_bin_end2016-03-22T12:30:33.0002016-03-22T12:30:34.000)	r   r/   r   usr   r2   isotr5   )r0   Z
down_startZdown_endr   r   r   test_time_bin_conversion9   s    

r;   c                  C   s<   t tg dgdgd} t| ddgd}t|jjddg d S )	Nr)   r*   r+   r	   r
   )r2   r6   2016-03-22T12:30:35.000)r   r/   r   r   r5   r:   )r0   Zdown_auto_endr   r   r   test_time_bin_end_autoG   s    r=   c                  C   s<   t tg dgdgd} t| ddgd}t|jjddg d S )	Nr)   r*   r+   r
   r   )r5   r3   r6   )r   r/   r   r   r2   r:   )r0   Zdown_start_arrayr   r   r   test_time_bin_start_arrayQ   s    r>   c                  C   sx   t tg dgdgd} t| dd}t|jjddg tt}d|d	 ||d	 fD ]"}t| t|d
}t||ksPJ qPd S )Nr)   r*   r+   r   )n_binsr3   r6   r   r   )r2   r?   )r   r/   r   r   r2   r:   len)r0   Z
down_nbinsZn_timesr?   r   r   r   
test_nbins]   s    rA   c                  C   sn  t tg dgdgd} t tg dtj gdgd}tjdkrLdtj }d }ndtj }| jd dtj  }t	| ||d}t
|jg d	|  t|jjtg d
 t|d jjtg d t	| d| |d}t
|jg d|  t|jjtg d t|d jjtg d t	| d| |d}t
|jddg|  t|jjtddg t|d jjtddg t	| d| |d}t
|jddg|  t|jjtddg t|d jjtddg t	|d| |d}t
|jddg|  t|jjtddg |d jjdks"J t|d jtddg t	| g d| |d}	t
|	jg d|  t|	jjtg d t|	d jjtg d t	| tddgtddgd}
t
|
jddgtj  t|
jjtddg t|
d jjtddg tjtddH t	| tddgtd d!gd}t|d jtddg W d    n1 s`0    Y  d S )"Nr)   r*   r+   l        r   g!?r   )r'   r2   )r   r   r   r   r   )r3   2016-03-22T12:30:32.000r6   r7   r<   r   )r   r   r   )r3   r6   r<   )r   r   r   r   r3   r7   r   r<   r   Zctr   g      @)r   r   r   )r3   r6   r7   )r   r   r   rB   r4   zaOverlapping bins should be avoided since they can lead to double-counting of data during binning.r%   r6   r   z2016-03-22T12:30:36.000)r   r/   r8   countsysmaxsizer9   r,   nsr   Ziscloser'   r   r2   r:   r   r-   r   r   Zunitnamesecondr   Zwarnsr   )r0   Zts_unitsZtime_bin_incrr2   Zdown_1Zdown_2Zdown_3Zdown_4Z
down_unitsZdown_uneven_binsZdown_time_arrayZdown_overlap_binsr   r   r   test_downsamplel   sn    


rI   z"time, time_bin_start, time_bin_endr   r   r   c                 C   s   t | tt| gdgd}t|||d}t|t|ks>J t|d dksRJ |j |d k sl|dur|d j sJ n.|j |d k r|d d |d d ksJ dS )ztRegression test for #12527: allow downsampling even if all bins fall
    before or beyond the time span of the data.r*   r+   r4   r'   r   Nr   )	r   r   Zonesr@   r   allr,   minmask)r,   r2   r5   r0   Zdownr   r   r   test_downsample_edge_cases   s    	rM   )rD   r   Znumpyr   Znumpy.testingr   Zastropyr   r8   Zastropy.timer   Zastropy.utils.exceptionsr   Zastropy.timeseries.sampledr   Zastropy.timeseries.downsampler   r   r/   r   r$   r(   r1   r;   r=   r>   rA   rI   ZmarkZparametrizerM   r   r   r   r   <module>   s4   
H 