
    IR-e,                     @   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mZ d dlmZ d dlmZ  e
g d          Zd	 Zd
 Zd Zd Zd Zd Zd Zd Z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             Zej                            ddej        z  dej        z  dej        z  dej        z  g          d             Z dS )    N)assert_equal)units)Time)aggregate_downsamplereduceat)
TimeSeries)AstropyUserWarning)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            
         t           j                            t          j        d          g d          } t          t          j        d          g dt           j                  }t          ||            t          t          j        d          t          j        d          d d d         t           j                  }t          |t          j        g d                     t          t          j        d          g dt           j                  }t          |t          j        g d                     t          t          t          j        d          t          j        d          d d d         t           j                  t          t          j        d          t          j        d          d d d         t           j                             d S )N   )r                        r   )g      ?      @      @g      @)g      ?r   r   r   g      @r   r   g      @)	npaddr   arangesumr   meanarraynanmean)
add_output
sum_outputmean_outputnanmean_outputs       Hlib/python3.11/site-packages/astropy/timeseries/tests/test_downsample.pytest_reduceatr%      s^   1/G/G/GHHJ")A,,(@(@(@"&IIJZ(((29Q<<1ccc):BGDDKbh';';';<<===bill,D,D,DbgNNN*L*L*L!M!MNNN1ry||CCaC0"'::1ry||CCaC0"*==        c                      t          j        t          d          5  t          d            d d d            d S # 1 swxY w Y   d S )Nz"time_series should be a TimeSeriesmatch)pytestraises	TypeErrorr    r&   r$   test_timeseries_invalidr.   *   s    	y(L	M	M	M # #T"""# # # # # # # # # # # # # # # # # #s   9= =c                      t          j        t          d          5  t          t	                      d           d d d            d S # 1 swxY w Y   d S )Nz3'time_bin_size' should be a Quantity or a TimeDeltar(   r   )time_bin_size)r*   r+   r,   r   r   r-   r&   r$   test_time_bin_invalidr1   /   s     
O
 
 
 < < 	Z\\;;;;< < < < < < < < < < < < < < < < < <s   AAAc                      t          t          g dgdg          } t          j        t          d          5  t          |            d d d            d S # 1 swxY w 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   )tss    r$   test_binning_arg_invalidr;   8   s    	???*;C5	I	I	IB	<
 
 
 ! !
 	R   ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !s   AAAc                     t          t          g dgdg          } t          | dgdgt          j        z            }t          |j        j        dg           t          | ddgd	
          }t          |j        j        ddg           d S )Nr3   r4   r5   r
   r   )time_bin_startr0   2016-03-22T12:30:31.000r   r   r=   time_bin_end2016-03-22T12:30:33.0002016-03-22T12:30:34.000)	r   r9   r   usr   r=   isotr@   )r:   
down_startdown_ends      r$   test_time_bin_conversionrH   B   s    	???*;C5	I	I	IB &
121#)  J */2K1LMMM#
-/DE*  H
 "	"$=>    r&   c                      t          t          g dgdg          } t          | ddg          }t          |j        j        ddg           d S )	Nr3   r4   r5   r
   r   )r=   rA   2016-03-22T12:30:35.000)r   r9   r   r   r@   rE   )r:   down_auto_ends     r$   test_time_bin_end_autorL   V   sq    	???*;C5	I	I	IB )
13HI  M "'	"$=>    r&   c                      t          t          g dgdg          } t          | ddg          }t          |j        j        ddg           d S )	Nr3   r4   r5   r   r   )r@   r>   rA   )r   r9   r   r   r=   rE   )r:   down_start_arrays     r$   test_time_bin_start_arrayrO   d   sr    	???*;C5	I	I	IB ,
/1FG   ',	"$=>    r&   c                  4   t          t          g dgdg          } t          | d          }t          |j        j        ddg           t          t                    }d|d	z
  ||d	z   fD ].}t          | t          |
          }t          |          |k    sJ /d S )Nr3   r4   r5   r   )n_binsr>   rA   r   r   )r=   rQ   )r   r9   r   r   r=   rE   len)r:   
down_nbinsn_timesrQ   s       r$   
test_nbinsrU   t   s    	???*;C5	I	I	IB &b333J!&	"$=>   *ooGgk7GaK8 * *)"ZPVWWW
:')))))* *r&   c            	      
   t          t          g dgdg          } t          t          g dt          j        z  gdg          }t          j        dk    rdt          j        z  }d }n,dt          j        z  }| j        d         dt          j        z  z
  }t          | ||          }t          j
        |j        g d	|z             t          |j        j        t          g d
                     t          |d         j        j        t#          j        g d                     t          | d|z  |          }t          j
        |j        g d|z             t          |j        j        t          g d                     t          |d         j        j        t#          j        g d                     t          | d|z  |          }t          j
        |j        ddg|z             t          |j        j        t          ddg                     t          |d         j        j        t#          j        ddg                     t          | d|z  |          }t          j
        |j        ddg|z             t          |j        j        t          ddg                     t          |d         j        j        t#          j        ddg                     t          |d|z  |          }t          j
        |j        ddg|z             t          |j        j        t          ddg                     |d         j        j        dk    sJ t          |d         j        t#          j        ddg                     t          | g d|z  |          }	t          j
        |	j        g d|z             t          |	j        j        t          g d                     t          |	d         j        j        t#          j        g d                     t          | t          ddg          t          ddg                    }
t          j
        |
j        ddgt          j        z             t          |
j        j        t          ddg                     t          |
d         j        j        t#          j        ddg                     t-          j        t0          d          5  t          | t          ddg          t          d d!g                    }t          |d         j        t#          j        ddg                     d d d            d S # 1 swxY w Y   d S )"Nr3   r4   r5   l        r   g!?r   )r0   r=   )r   r   r   r   r   )r>   2016-03-22T12:30:32.000rA   rB   rJ   r   )r   r   r   )r>   rA   rJ   )r   r   r   r   r>   rB   r   rJ   r   ctr   g      @)r   r   r   )r>   rA   rB   )r   r   r   rW   r?   zaOverlapping bins should be avoided since they can lead to double-counting of data during binning.r(   rA   r   z2016-03-22T12:30:36.000)r   r9   rC   countsysmaxsizerD   r6   nsr   iscloser0   r   r=   rE   r   r7   r   r   unitnamesecondr*   warnsr	   )r:   ts_unitstime_bin_incrr=   down_1down_2down_3down_4
down_unitsdown_uneven_binsdown_time_arraydown_overlap_binss               r$   test_downsamplerl      s   	???*;C5	I	I	IB89#  H
 {UAC "QS(a!$h.!
-  F If"OOOm$CDDD"  	
 	
   !&(A(ABBB!
!m+N  F If"III$=>>>"  	
 	
	 	 	 !&(;(;<<<!
!m+N  F If"QF]$:;;;"')BCDD   !&!Q(8(8999!
!m+N  F If"QF]$:;;;"')BCDD   !&!Q(8(8999%M 1.  J Ij&A(>???!&')BCDD   c?$,,,,C%rxc
';';<<< ,
)))m3N   I,iii-.GHHH',  	
 	
	 	 	 !#&+0"(9992E2EFFF +
68QRSS46OPQQ  O
 Io+aVah->???&+')BCDD   %*/1a&1A1ABBB 
B
 
 
 D D 1!:<U VWW46OPQQ
 
 

 	&s+0"(Aq62B2BCCCD D D D D D D D D D D D D D D D D Ds   A UUUz"time, time_bin_start, time_bin_endr   r   r   c                 $   t          | t          j        t          |                     gdg          }t	          |||          }t          |          t          |          k    sJ t          |d         dk              sJ |j                                        |d         k     s|#|d         j                                        sJ dS |j                                        |d         k     r |d         d         |d         d         k    sJ dS dS )ztRegression test for #12527: allow downsampling even if all bins fall
    before or beyond the time span of the data.r4   r5   r?   r0   r   Nr   )	r   r   onesrR   r   allr6   minmask)r6   r=   r@   r:   downs        r$   test_downsample_edge_casesrs     s     
RWSYY%7%7$8	F	F	FB
>  D t99N++++++tO$)*****	w{{}}~a(((L,D

ssuu	 	 	 	 	 
*	*	*IaLBsGAJ&&&& 
+	*&&r&   diff_from_base
   2   d   c                     dt           j        z  }ddlm} t	          ddd          }|| z   }||z   } |||          } |||          }||k    sJ dS )	ae  
    A test on time precision limit supported by downsample().

    It is related to an implementation details: that time comparison (and sorting indirectly)
    is done with relative time for computational efficiency.
    The relative time converted has a slight loss of precision, which worsens
    as the gap between a time and the base time increases, e.g., when downsampling
    a timeseries that combines current observation with archival data years back.

    This test is to document the acceptable precision limit.

    see also: https://github.com/astropy/astropy/pull/13069#issuecomment-1093069184
    i  r   )_to_relative_longdoublez1980-01-01T12:30:31.000rE   tdb)formatscaleN)rC   r\   astropy.timeseries.downsamplery   r   )rt   precision_limitry   t_baset2t3r_t2r_t3s           r$   test_time_precision_limitr   !  s    " ADjOEEEEEE+F%HHHF	.	 B	o	B""2v..D""2v..D $;;;;;;r&   )!rZ   numpyr   r*   numpy.testingr   astropyr   rC   astropy.timer   r}   r   r   astropy.timeseries.sampledr   astropy.utils.exceptionsr	   r9   r%   r.   r1   r;   rH   rL   rO   rU   rl   markparametrizers   yearr   r-   r&   r$   <module>r      sK   


      & & & & & &             H H H H H H H H 1 1 1 1 1 1 7 7 7 7 7 7T   
   # # #
< < <! ! !  (     * * *"|D |D |D~ (	BQBABB.	ABBBQBAaC9	QC*RaR.$/	QC*SSqS/40	 
 
 
( q16z2;QVS16\J     r&   