a
    ߙfbv5                     @   s>  d dl Z d dlmZmZ d dlmZ d dlmZm	Z	 d dl
mZ d dlmZmZ d dlmZ d dlmZ e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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%d.d/ Z&d0d1 Z'd2d3 Z(d4d5 Z)e j*+d6eegd7d8 Z,dS )9    N)assert_equalassert_allclose)units)Time	TimeDelta)get_pkg_data_filename)BoxLeastSquaresLombScargle)BinnedTimeSeries)assert_quantity_allclosezdata/binned.csvc                  C   s   t  } tg ddd| d< d S )N         mjdformattime_bin_start)r
   r   ts r   Clib/python3.9/site-packages/astropy/timeseries/tests/test_binned.pytest_empty_initialization   s    r   c                  C   sT   t  } tt}g d| d< W d    n1 s20    Y  |jjd dksPJ d S )Nr   Zfluxr   zcBinnedTimeSeries object is invalid - expected 'time_bin_start' as the first column but found 'flux')r
   pytestraises
ValueErrorvalueargs)r   excr   r   r   !test_empty_initialization_invalid   s    *r   c                  C   s   t t } tg dgd W d    n1 s00    Y  | jjd dksNJ t t"} tdg dgd W d    n1 s0    Y  | jjd dksJ d S )Nr      r   )datar   z''time_bin_start' has not been specified2016-03-22T12:30:31)r   r"   <Either 'time_bin_size' or 'time_bin_end' should be specified)r   r   	TypeErrorr
   r   r   r   r   r   r   $test_initialization_time_bin_invalid"   s    .0r'   c                  C   s   t t"} tddgidd W d    n1 s20    Y  | jjd dksPJ t t*} tddgidgtj d W d    n1 s0    Y  | jjd d	ksJ d S )
Nr   r#   )r"   r   r   zK'time_bin_start' has been given both in the table and as a keyword argumenttime_bin_sizer   )r"   r(   zJ'time_bin_size' has been given both in the table and as a keyword argument)r   r   r%   r
   r   r   usr&   r   r   r   !test_initialization_time_bin_both/   s    
$

$r+   c                  C   s   t t$} tddgiddd W d    n1 s40    Y  | jjd dksRJ tddgidtdd}t|jt	j
js~J d S )Ntimer#   r   )r"   r   r(   r   z3'time_bin_size' should be a Quantity or a TimeDelta)r   r   r%   r
   r   r   r   
isinstancer(   r)   ZquantityZQuantity)r   r   r   r   r   !test_initialization_time_bin_size@   s    
$
r.   c                  C   sf   t t4} tddgitdddtdddd W d    n1 sD0    Y  | jjd dksbJ d S )	Nr,   r#   r   r   r   )r"   r   time_bin_endr   z:'time_bin_start' is scalar, so 'time_bin_size' is required)r   r   r%   r
   r   r   r   r&   r   r   r   )test_initialization_time_bin_start_scalarQ   s    


$r0   c                  C   sb   t t0} ttg ddddtj dd W d    n1 s@0    Y  | jjd dks^J d S )	Nr   Zcxcsecr   r   
   )r   r(   n_binsr   zS'n_bins' cannot be specified if 'time_bin_start' or 'time_bin_size' are not scalar'	r   r   r%   r
   r   r)   r*   r   r   r&   r   r   r   ,test_initialization_n_bins_invalid_arguments\   s    $r4   c               	   C   sp   t t>} tddgitddddtj tddddd W d    n1 sN0    Y  | jjd d	kslJ d S )
Nr,   r#   r   r   r   r1   )r"   r   r(   r/   r2   r   zH'n_bins' has been given and it is not the same length as the input data.r3   r&   r   r   r   test_initialization_n_binsi   s    


$r5   c               	   C   s   t t8} tddgiddgdtj tdddd W d    n1 sH0    Y  | jjd d	ksfJ t t	(} tddgidgd d d W d    n1 s0    Y  | jjd d
ksJ d S )Nr,   r#   2016-03-22T12:30:32r   r   r   )r"   r   r(   r/   r   z<Length of 'time_bin_start' (2) should match table length (1)r$   )
r   r   r   r
   r)   r*   r   r   r   r%   r&   r   r   r   #test_initialization_non_scalar_timew   s    

$
$r7   c                  C   sT   t ddtj g dgd} t| jjg d t| jjg d t| jjg d d S )Nr#   r   r    r   r(   r"   )2016-03-22T12:30:31.0002016-03-22T12:30:34.0002016-03-22T12:30:37.000)z2016-03-22T12:30:32.500z2016-03-22T12:30:35.500z2016-03-22T12:30:38.500)r:   r;   2016-03-22T12:30:40.000r
   r)   r*   r   r   isottime_bin_centerr/   r   r   r   r   test_even_contiguous   s    r@   c                  C   sR   t g ddg dgd} t| jjg d t| jjg d t| jjg d d S )N)r#   r6   2016-03-22T12:30:40z2016-03-22T12:30:55r    r   r/   r"   )r9   2016-03-22T12:30:32.000r<   )2016-03-22T12:30:31.5002016-03-22T12:30:36.000z2016-03-22T12:30:47.500)rC   r<   z2016-03-22T12:30:55.000r
   r   r   r>   r?   r/   r   r   r   r   test_uneven_contiguous   s    rG   c                  C   s\   t g dg dtj g dgd} t| jjg d t| jjg d t| jjg d d S )N)r#   z2016-03-22T12:30:38z2016-03-22T12:34:40)   d   r   r    r8   )r9   z2016-03-22T12:30:38.000z2016-03-22T12:34:40.000)z2016-03-22T12:30:33.500z2016-03-22T12:31:28.000z2016-03-22T12:34:41.000)rE   z2016-03-22T12:32:18.000z2016-03-22T12:34:42.000r=   r   r   r   r   test_uneven_non_contiguous   s    rJ   c                  C   sV   t g dg dg dgd} t| jjg d t| jjg d t| jjg d d S )N)r#   z2016-03-22T12:30:33rA   )r6   z2016-03-22T12:30:35z2016-03-22T12:30:41r    rB   )r9   z2016-03-22T12:30:33.000r<   )rD   r:   z2016-03-22T12:30:40.500)rC   z2016-03-22T12:30:35.000z2016-03-22T12:30:41.000rF   r   r   r   r   test_uneven_non_contiguous_full   s    rK   c                  C   sP   t t} tjtdd W d    n1 s.0    Y  | jjd dksLJ d S )Ncsvr   r   z\``time_bin_start_column`` should be provided since the default Table readers are being used.r   r   r   r
   readCSV_FILEr   r   r&   r   r   r   test_read_empty   s    ,rP   c                  C   sR   t t } tjtddd W d    n1 s00    Y  | jjd dksNJ d S )N
time_startrL   )time_bin_start_columnr   r   zJEither `time_bin_end_column` or `time_bin_size_column` should be provided.rM   r&   r   r   r   test_read_no_size_end   s    .rS   c                  C   sV   t t$} tjtddddd W d    n1 s40    Y  | jjd dksRJ d S )NrQ   ZENDbin_sizerL   )rR   time_bin_end_columntime_bin_size_columnr   r   zECannot specify both `time_bin_end_column` and `time_bin_size_column`.rM   r&   r   r   r   test_read_both_extra_bins   s    2rW   c                  C   sT   t t"} tjtdddd W d    n1 s20    Y  | jjd dksPJ d S NrQ   rT   rL   )rR   rV   r   r   zVThe bin size unit should be specified as an astropy Unit using ``time_bin_size_unit``.rM   r&   r   r   r   test_read_size_no_unit   s    0rY   c                  C   sX   t t&} tjtddtjdd W d    n1 s60    Y  | jj	d dksTJ d S )NabcrT   rL   rR   rV   Ztime_bin_size_unitr   r   z8Bin start time column 'abc' not found in the input data.
r   r   r   r
   rN   rO   r)   secondr   r   r&   r   r   r   test_read_start_time_missing  s    4r^   c                  C   sT   t t"} tjtdddd W d    n1 s20    Y  | jjd dksPJ d S )NrQ   missingrL   rR   rU   r   r   z:Bin end time column 'missing' not found in the input data.rM   r&   r   r   r   test_read_end_time_missing  s    0ra   c                  C   sX   t t&} tjtddtjdd W d    n1 s60    Y  | jj	d dksTJ d S )NrQ   r_   rL   r[   r   z6Bin size column 'missing' not found in the input data.r\   r&   r   r   r   test_read_size_missing  s    4rb   c                  C   sT   t t"} tjtdddd W d    n1 s20    Y  | jjd dksPJ d S rX   rM   r&   r   r   r   test_read_time_unit_missing  s    0rc   c                  C   s   t jtdddd} | jg dks$J t| dks4J | d  dksHJ t jtdd	tjdd
} | jg dkspJ t| dksJ | d  dksJ d S )NrQ   time_endrL   r`   )	r   r(   rT   ABCDEFr1   rf   g\(@rT   r[   )	r   r(   rd   re   rf   rg   rh   ri   rj   )r
   rN   rO   Zcolnameslensumr)   r]   )Z
timeseriesr   r   r   	test_read  s    rm   clsc                 C   s   t ddtj g dg dgddgd}| |d}t|| s@J t|jj|jj t	|j
|d  |jd u spJ | j|ddd}t|j|d  | j|dd	d}t|jd	 d S )
Nr#   r   r    )r   r!   r   ab)r   r(   r"   names)Zuncertaintyg?)r
   r)   r*   Zfrom_timeseriesr-   r   tZjdr?   r   yZdyr   )rn   r   Zp1Zp2Zp3r   r   r   test_periodogram)  s    rt   )-r   Znumpy.testingr   r   Zastropyr   r)   Zastropy.timer   r   Zastropy.utils.datar   Zastropy.timeseries.periodogramsr   r	   Zastropy.timeseries.binnedr
   Zastropy.tests.helperr   rO   r   r   r'   r+   r.   r0   r4   r5   r7   r@   rG   rJ   rK   rP   rS   rW   rY   r^   ra   rb   rc   rm   ZmarkZparametrizert   r   r   r   r   <module>   s@   