
    IR-eX=                     P   d dl m Z  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mZ d d	lmZ d d
lmZ d dlmZ  eg d          Z e
g dg dg dgg d          Z ed          Zd Zd Zd Zd Zd Z d Z!d Z"d Z#d Z$d Z%d Z&d Z'd Z(d  Z)d! Z*d" Z+d# Z,d$ Z-d% Z.d& Z/ej0        1                    d'(          d)             Z2ej0        1                    d'(          d*             Z3d+ Z4ej0        5                    d,eeg          d-             Z6dS ).    )datetimeN)assert_allcloseassert_equal)units)ColumnTable)assert_quantity_allclose)Time	TimeDelta)BoxLeastSquaresLombScargle)
TimeSeries)Quantity)get_pkg_data_filename)z2016-03-22T12:30:31z2015-01-21T12:30:32z2016-03-22T12:30:40)         )      r   )r   r   r   )abc)nameszdata/sampled.csvc                  N    t                      } t          g dd          | d<   d S )N)iQ  iR  iS  mjdformattime)r   r
   tss    Elib/python3.11/site-packages/astropy/timeseries/tests/test_sampled.pytest_empty_initializationr"      s,    	B+++E:::BvJJJ    c                      t                      } t          j        t          d          5  g d| d<   d d d            d S # 1 swxY w Y   d S )NzSTimeSeries object is invalid - expected 'time' as the first column but found 'flux'matchr   r   r   flux)r   pytestraises
ValueErrorr   s    r!   !test_empty_initialization_invalidr,      s    	B	
 
 
   YY6
                 s   ?AAc                      t          t                    } | d         | j        u sJ t          | j        j        t          j                   d S )Nr   r   )r   
INPUT_TIMEr   r   isotr   s    r!   test_initialize_only_timer1   )   sE    		$	$	$Bf:    z/////r#   c                      t          t          g dg dgddg          } t          | j        j        t          j                   t          | d         g d           t          | d         g d           d S )N
   r   r   r         r   r   r   datar   )r   r/   r   r   r0   r   s    r!   test_initialization_with_datar:   0   ss    	:::yyy*A#s	T	T	TBz///C***%%%C)))$$$$$r#   c                      t          j        t          d          5  t          g dg dgddg           d d d            d S # 1 swxY w Y   d S )Nz1Either 'time' or 'time_start' should be specifiedr%   r3   r5   r   r   r9   r   )r)   r*   	TypeErrorr    r#   r!   test_initialize_only_datar?   7   s    	M
 
 
 C C 	YYY/SzBBBBC C C C C C C C C C C C C C C C C Cs   AA
Ac                  Z    t          t          t                    } | j        g dk    sJ d S )N)r   r9   )r   r   r   r   )r   r/   PLAIN_TABLEcolnamesr   s    r!   test_initialization_with_tablerC   >   s4    	+	6	6	6B;111111111r#   c            
          t          t          dddddd          t          dd          g dg d	gd
dg          } t          | j        j        g d           d S )N     r   r4   r   secr   r3   r5   r   r   
time_start
time_deltar9   r   )z2018-07-01T10:10:10.000z2018-07-01T10:10:13.000z2018-07-01T10:10:16.000)r   r   r   r   r   r0   r   s    r!   #test_initialization_with_time_deltarK   C   s    	D!QB33Qu---jj)))$Cj	
 
 
B 
	
 	
 	
    r#   c                      t          j        t          d          5  t          t	          dddddd          g dg dgd	d
g           d d d            d S # 1 swxY w Y   d S )Nz-'time' is scalar, so 'time_delta' is requiredr%   rE   rF   r   r4   r3   r5   r   r   )rI   r9   r   r)   r*   r=   r   r   r>   r#   r!   &test_initialization_missing_time_deltarN   T   s    	I
 
 
 
 
 	aBB77**iii(*	
 	
 	
 	

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
s   -AAAc                      t          j        t          d          5  t          t          t          dddddd          g dg dgd	d
g           d d d            d S # 1 swxY w Y   d S )Nz+Cannot specify both 'time' and 'time_start'r%   rE   rF   r   r4   r3   r5   r   r   )r   rI   r9   r   )r)   r*   r=   r   r/   r   r>   r#   r!   /test_initialization_invalid_time_and_time_startrP   _   s    	y(V	W	W	W 
 
aBB77**iii(*		
 	
 	
 	

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
s   3AA #A c                      t          j        t          d          5  t          t	          dddddd          g dg dg d	gd
dg           d d d            d S # 1 swxY w Y   d S )Nz0'time_delta' should be a Quantity or a TimeDeltar%   rE   rF   r   r4   )r   r   r   r3   r5   r   r   rH   rM   r>   r#   r!   &test_initialization_invalid_time_deltarR   i   s    	L
 
 
 
 
 	aBB77 yy**iii(*		
 	
 	
 	

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
s   0AA Ac                     t                                           } t          | d<   t          |           }t	          |j                  h dk    sJ t          |j        t          k              sJ t          g dt          gddg          }t	          |j                  ddhk    sJ t          |j        t          k              sJ d}t          j	        t          |          5  t          | t          	           d d d            n# 1 swxY w Y   t          j	        t          |          5  t          t          g dt          gddg
           d d d            d S # 1 swxY w Y   d S )Nr   )r9   >   r   r   r   r   r3   r   r<   zA'time' has been given both in the table and as a keyword argumentr%   )r9   r   r8   )rA   copyr/   r   setrB   allr   r)   r*   r=   )r9   ts1ts2MESSAGEs       r!   %test_initialization_with_time_in_datarZ   u   s   DDL
$


Cs| 7 7 77777sx:%&&&&&
:::z23-
H
H
HCs|----sx:%&&&&&RG	y	0	0	0 / /:..../ / / / / / / / / / / / / / / 
y	0	0	0 X X
***j)A#vWWWWX X X X X X X X X X X X X X X X X Xs$   #DD
D
,#EE #E c                      t          j        t          d          5  t          t          t
          d           d d d            d S # 1 swxY w Y   d S )NzP'n_samples' has been given both and it is not the same length as the input data.r%   i  )r   r9   	n_samples)r)   r*   r=   r   r/   rA   r>   r#   r!   test_initialization_n_samplesr]      s     

 
 
 F F 	
EEEEF F F F F F F F F F F F F F F F F F   AA
A
c                      t          j        t          d          5  t          t          ddgddggddg	           d d d            d S # 1 swxY w Y   d S )
Nz5Length of 'time' \(3\) should match data length \(2\)r%   r4   r   r   r6   r   r   r8   )r)   r*   r+   r   r/   r>   r#   r!   #test_initialization_length_mismatchr`      s    	R
 
 
 N N 	
2q'Aq6):3*MMMMN N N N N N N N N N N N N N N N N Ns    A		AAc                      t          j        t          d          5  t          t          t          dd                     d d d            d S # 1 swxY w Y   d S )Nz='time_delta' should not be specified since 'time' is an arrayr%   r   rG   r   )r   rJ   )r)   r*   r=   r   r/   r   r>   r#   r!   4test_initialization_invalid_both_time_and_time_deltarb      s    	N
 
 
 K K 	
y5/I/I/IJJJJ	K K K K K K K K K K K K K K K K K Ks   &AAAc                  T	   t          g dd          } t          |           }g d|d<   |                    dt          j        z            }t          |j        t                    sJ t          |j        j	        g d	d
           |                    dt          j        z  t          dd                    }t          |j        t                    sJ t          |j        j	        g dd
d
           |                    dt          j        z  dt          j        z            }t          |j        t                    sJ t          |j        j	        g dd
           |                    dt          j        z  dt          j        z            }t          |j        t                    sJ t          |j        j	        g dd
           |                    dt          j        z  dt          j        z  dt          j        z            }t          |j        t                    sJ t          |j        j	        g dd
           |                    dt          j        z  d          }t          |j        t                    sJ t          |j                            t          j                  g dd
           |                    dt          j        z  t          dd          d          }t          |j        t                    sJ t          |j                            t          j                  g dd
d
           |                    dt          j        z  dd          }t          |j        t                    sJ t          |j                            t          j                  g dd
           |                    dt          j        z  dd           }t          |j        t                    sJ t          |j                            t          j                  g d!d
           |                    dt          j        z  ddd"          }t          |j        t                    sJ t          |j                            t          j                  g d#d
           d S )$Nr   r   r      	      unixr   r.   r   r   r   r   r   r   r(   皙	@period)r   r   g333333333333?gffffff?gư>)rtol皙?)rl   
epoch_time)g333333g?rn           g      ?皙?)ro   atolrl   
wrap_phase)r   r   r   rm   rp   rn   rs   rl   epoch_phase)rs   gffffffgٿrn   gg      )rl   rx   rv   )rs   g?gffffff@rn   g333333@皙@T)rl   normalize_phase)r         ?g׿?g      ?)rl   rq   rz   )gǿg      ?r}   rr   r{         ?r   rl   rv   rz   )r   r{   g      ?r|   g      ?r}   r~   rl   rx   rz   )r~   gۿg      r}   g      пg      Կ)rl   rx   rv   rz   )r~   g      ?g?r}   g?g      ?)r
   r   foldus
isinstancer   r   r   rG   r   to_valueone)timesr    tsfs      r!   	test_foldr      sd   $$$V444E				B###BvJ ''qs'
#
#Cch	*****CHL">">">TJJJJ ''qstC/G/G/G'
H
HCch	*****CHL"A"A"ASWXXXX ''qssQSy'
9
9Cch	*****CHL":":":FFFF ''qsac	'
:
:Cch	*****CHL"D"D"D4PPPP ''qsac	cACi'
P
PCch	*****CHL"@"@"@tLLLL ''qsD'
9
9Cch)))))!%  BBB    ''QSyT#f%=%=%=t   C ch)))))!%  KKK	    ''qsq$'
G
GCch)))))!%  >>>    ''qsd'
K
KCch)))))!%  NNN    ''QSydq$   C ch)))))!%  JJJ     r#   c                     t          g dd          } t          |           }g d|d<   t          j        t          j        d          5  |                    d	
           d d d            n# 1 swxY w Y   t          j        t          j        d          5  |                    d	t          j        z  
           d d d            n# 1 swxY w Y   t          j        t          j        d          5  |                    d	t          j        z  d           d d d            n# 1 swxY w Y   t          j        t          j        d          5  |                    d	t          j        z  dt          j        z  d           d d d            n# 1 swxY w Y   t          j        t          j        d          5  |                    d	t          j        z  d           d d d            n# 1 swxY w Y   t          j        t          j        d          5  |                    d	t          j        z  dt          j        z  d           d d d            n# 1 swxY w Y   t          j        t          d          5  |                    d	t          j        z  dt          j        z             d d d            n# 1 swxY w Y   t          j        t          d          5  |                    d	t          j        z  dt          j        z             d d d            n# 1 swxY w Y   t          j        t          d          5  |                    d	t          j        z  dd           d d d            n# 1 swxY w Y   t          j        t          d          5  |                    d	t          j        z  dd           d d d            d S # 1 swxY w Y   d S )Nrd   rh   r   r.   ri   r(   z,period should be a Quantity in units of timer%   rj   rk   zLepoch_phase should be a Quantity in units of time when normalize_phase=Falseg?rw   zSepoch_phase should be a dimensionless Quantity or a float when normalize_phase=TrueTr   zKwrap_phase should be a Quantity in units of time when normalize_phase=Falseru   z<wrap_phase should be dimensionless when normalize_phase=Truer   z-wrap_phase should be between 0 and the periodggz$wrap_phase should be between 0 and 1ry   )
r
   r   r)   r*   r   
UnitsErrorr   mr   r+   )r   r    s     r!   test_fold_invalid_optionsr      sX   $$$V444E				B###BvJ		J
 
 
   	s              
 
	J
 
 
 " " 	sQSy!!!" " " " " " " " " " " " " " "
 
	.
 
 
 3 3 	sQSyc2223 3 3 3 3 3 3 3 3 3 3 3 3 3 3 
	3
 
 
 O O 	sQSycACiNNNO O O O O O O O O O O O O O O 
	.
 
 
 2 2 	sQSyS1112 2 2 2 2 2 2 2 2 2 2 2 2 2 2 
	L
 
 
 N N 	sQSyS13YMMM	N N N N N N N N N N N N N N N 
I
 
 
 9 9 	sQSyTACZ8889 9 9 9 9 9 9 9 9 9 9 9 9 9 9
 
I
 
 
 9 9 	sQSyTACZ8889 9 9 9 9 9 9 9 9 9 9 9 9 9 9
 
z)O	P	P	P I I
sQSyT4HHHI I I I I I I I I I I I I I I 
z)O	P	P	P H H
sQSyS$GGGH H H H H H H H H H H H H H H H H Hs   A..A25A2$C		CC4%D%%D),D)3FFF:%G++G/2G/3III;2J99J= J=2LL!$L!&M55M9<M9&OOOc                     t          j        d          } |                                 }g d|d<   |                    |                     t
          j                  d           t          j        |          }t          |j
        j        t
          j                   |j        ddgk    sJ t          |j                  dk    sJ |j        d         j        d         t
          k                                    sJ t          j        |d	
          }|j
        j        d	k    sJ |                                }|j        j        |                     t
          j                  j        k                                    sJ |j        |                     dg          k    sJ |d         |d         k                                    sJ t          j        t.          d          5  t          j        d            d d d            n# 1 swxY w Y   |                                 }g d|d<   t          j        t.          d          5  t          j        |           d d d            d S # 1 swxY w Y   d S )Npandasr'   r   T)inplacer   r   r   tcb)
time_scalez"Input should be a pandas DataFramer%   z'DataFrame does not have a DatetimeIndex)r)   importorskip	DataFrame	set_indexDatetimeIndexr/   
datetime64r   from_pandasr   r   r0   rB   lenindicescolumnsrV   scale	to_pandasindexvaluesIndexr*   r=   )r   df1r    ts_tcbdf2df4s         r!   test_pandasr   A  s    **F




CyyCHMM&&&z'<==tMLLL			$	$Bz///;63-''''rz??aJv&q)Z7<<>>>>>#CE:::F;%%%%
,,..CIZ-B C C JJOOQQQQQ;&,,u------HC %%'''''	y(M	N	N	N % %t$$$% % % % % % % % % % % % % % % 



CyyCH	y(R	S	S	S $ $s###$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $s$   G??HH I""I&)I&c                      t          j        t          d          5  t          j        t
          d           d d d            d S # 1 swxY w Y   d S )NzS``time_column`` should be provided since the default Table readers are being used\.r%   csvr   r)   r*   r+   r   readCSV_FILEr>   r#   r!   test_read_time_missingr   `  s    	
 
 
 0 0 	////0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0s   AA	A	c                      t          j        t          d          5  t          j        t
          dd           d d d            d S # 1 swxY w Y   d S )Nz/Time column 'abc' not found in the input data\.r%   abcr   time_columnr   r   r>   r#   r!   test_read_time_wrongr   k  s    	L
 
 
 C C 	eEBBBBC C C C C C C C C C C C C C C C C Cr^   c                      t          j        t          dd          } | j        g dk    sJ t	          |           dk    sJ | d         j        dk    sJ | d                                         d	k    sJ d S )
NDater   r   )r   ABCDEFGr   r   isor   g     p@)r   r   r   rB   r   r   sum)
timeseriess    r!   	test_readr   r  s    veLLLJ"M"M"MMMMMz??b    f$----c?  E))))))r#   astropy)sourcec                     ddl m}  t          d          }t          j        |           5  t          j        |d          }d d d            n# 1 swxY w Y   |d         j        dk    sJ |d         j        dk    sJ |d	         j	        
                                d
k    sJ t          |          dk    sJ t          |j                  dk    sJ d S )Nr   )UnitsWarningz/timeseries/kplr010666592-2009131110544_slc.fitszkepler.fitsr   r   r0   tdbsap_fluxelectron / si7     )astropy.unitsr   r   r)   warnsr   r   r   r   unit	to_stringr   r   )r   filenamer   s      r!   test_kepler_astropyr   z  s>   ******$%VWWH	l	#	# E E_XmDDD
E E E E E E E E E E E E E E E f$....f#u,,,,j!&0022nDDDDz??e####z!""b((((((s   AAAc                     t          d          } t          j        t          d          5  t	          j        | d          }d d d            n# 1 swxY w Y   |d         j        dk    sJ |d         j        dk    sJ |d	         j        	                                d
k    sJ t          |          dk    sJ t          |j                  dk    sJ d S )NzJtimeseries/hlsp_tess-data-alerts_tess_phot_00025155310-s01_tess_v1_lc.fitsz Ignoring 815 rows with NaN timesr%   z	tess.fitsr   r   r0   r   r   r   i=K  r   )r   r)   r   UserWarningr   r   r   r   r   r   r   r   )r   r   s     r!   test_tess_astropyr     s6   $T H 
k)K	L	L	L C C_XkBBB
C C C C C C C C C C C C C C Cf$....f#u,,,,j!&0022nDDDDz??e####z!""b((((((s   AAAc                     t          t          g dg dgddg          } |                                  d}t          j        t
          |                    d                    5  |                                                     t          g d	d
          d           d d d            n# 1 swxY w Y   t          j        t
          |                    d                    5  |                                 	                    t          g d	d
          t          g d	d
          gddg           d d d            n# 1 swxY w Y   t          j        t
          |                    d                    5  |                                 
                    ddg           d d d            n# 1 swxY w Y   t          j        t
          |                    d                    5  |                                                     d           d d d            n# 1 swxY w Y   t          j        t
          |                    d                    5  |                                                     ddg           d d d            n# 1 swxY w Y   t          j        t
          |                    d                    5  |                                                     dd           d d d            n# 1 swxY w Y   d}|                                 }ddg|_        t          j        t
          |          5  |                    d           d d d            d S # 1 swxY w Y   d S )Nr3   r5   r   r   r8   zQTimeSeries object is invalid - expected 'time' as the first column but found '{}'r   r%   )r   r   r6   )namer   )r   der   )indexesr   bananazfTimeSeries object is invalid - expected \['time', 'a'\] as the first columns but found \['time', 'b'\])r   r/   rT   r)   r*   r+   r   
add_columnr   add_columnskeep_columnsremove_columnremove_columnsrename_column_required_columns)r    rY   ts_2cols_requireds      r!   test_required_columnsr     s    
:::yyy*A#s	T	T	TB GGIII	 
 
z)<)<	=	=	= C C
		VIIIC888BBBC C C C C C C C C C C C C C C 
z)<)<	=	=	= 
 

		IIIC(((&*E*E*EFQRTUPV 	 	
 	
 	

 
 
 
 
 
 
 
 
 
 
 
 
 
 

 
z)<)<	=	=	= + +
		Sz***+ + + + + + + + + + + + + + + 
z)<)<	=	=	= ( (
		'''( ( ( ( ( ( ( ( ( ( ( ( ( ( ( 
z)<)<	=	=	= 0 0
		  &#///0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
z)A)A	B	B	B 2 2
		1112 2 2 2 2 2 2 2 2 2 2 2 2 2 2
	&  		+13-'	z	1	1	1 - -'',,,- - - - - - - - - - - - - - - - - -s   $;B++B/2B/$AE  EE9*F//F36F3((HH #H *JJJ)K99K= K=>M!!M%(M%clsc                    t          t          g dg dgddg          }|                     |d          }t          ||           sJ t	          |j        j        |j        j                   t          |j	        |d                    |j
        J |                     |dd          }t          |j
        |d                    |                     |dd          }t	          |j
        d           d S )Nr3   r5   r   r   r8   )uncertaintyg?)r   r/   from_timeseriesr   r   tjdr   r   ydyr	   )r   r    p1p2p3s        r!   test_periodogramr     s     
:::yyy*A#s	T	T	TB			R	%	%Bb#BDGRWZ(((r#w5===			R#		6	6BRUBsG,,,			R#		6	6BBE3r#   )7r   r)   numpy.testingr   r   r   r   r   astropy.tabler   r   astropy.tests.helperr	   astropy.timer
   r   astropy.timeseries.periodogramsr   r   astropy.timeseries.sampledr   r   r   astropy.utils.datar   r/   rA   r   r"   r,   r1   r:   r?   rC   rK   rN   rP   rR   rZ   r]   r`   rb   r   r   r   r   r   r   markremote_datar   r   r   parametrizer   r>   r#   r!   <module>r      s           7 7 7 7 7 7 7 7       ' ' ' ' ' ' ' ' 9 9 9 9 9 9 ( ( ( ( ( ( ( ( H H H H H H H H 1 1 1 1 1 1 " " " " " " 4 4 4 4 4 4TWWWXX
eZZZIII6oooNNN  !344; ; ;

 
 
0 0 0% % %C C C2 2 2
  "
 
 

 
 
	
 	
 	
X X X0
F 
F 
FN N NK K KS S Sl?H ?H ?HD$ $ $>0 0 0C C C* * * 	**) ) +*) 	**
) 
) +*
)-- -- --` + >??    @?     r#   