B
    z‹d(
  ã               @   sD   d dl mZ dZdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ ZdS )é    )Úbasenamez(Duncan Macleod <duncan.macleod@ligo.org>c             C   s@   t | ƒ}| d¡\}}}}t|ƒ}t| d¡d ƒ}||| fS )aþ  Return the GPS segment covered by a URL following T050017

    Parameters
    ---------
    filename : `str`
        the path name of a file

    Returns
    -------
    segment : `tuple` of `int`
        the ``[start, stop)`` GPS interval covered by the given URL

    Notes
    -----
    `LIGO-T050017 <https://dcc.ligo.org/LIGO-T050017/public>`_ declares
    a filenaming convention that includes documenting the GPS start integer
    and integer duration of a file, see that document for more details.
    ú-Ú.r   )r   ÚsplitÚint)ÚurlÚbaseÚ_ÚsÚe© r   úX/work/yifan.wang/ringdown/master-ringdown-env/lib/python3.7/site-packages/gwosc/utils.pyÚurl_segment
   s
    r   c             C   s   t | ƒ}t||ƒS )aq  Returns True if a URL overlaps a [start, stop) GPS interval

    Parameters
    ----------
    url : `str`
        the URL of a file

    segment : `tuple` of `int`
        the ``[start, stop)`` GPS interval to check against

    Returns
    -------
    overlap? : `bool`
        `True` if the GPS interval for the URL matches that given,
        otherwise `False`
    )r   Úsegments_overlap)r   ÚsegmentZusegr   r   r   Úurl_overlaps_segment$   s    r   c             C   s&   t t| ƒ}t|Ž \}}t|ƒt|ƒfS )zúReturns the GPS `[start, end)` interval covered by a list or URLs

    Parameters
    ----------
    urls : `iterable` of `str`
        the list of URLs

    Returns
    -------
    a, b : 2-`tuple` of int`
        the GPS extent of the URL list
    )Úmapr   ÚzipÚminÚmax)ÚurlsZsegsÚstartsÚendsr   r   r   Úurllist_extent9   s    
r   c             C   s&   t dd„ | D ƒŽ \}}t|ƒt|ƒfS )zJReturns the GPS `[start, end)` interval covered by a strain meta dict
    c             S   s$   g | ]}|d  |d  |d  f‘qS )ZGPSstartÚdurationr   )Ú.0Úmetar   r   r   ú
<listcomp>O   s   z!strain_extent.<locals>.<listcomp>)r   r   r   )Zstrainr   r   r   r   r   Ústrain_extentK   s    r   c             C   s,   | sdS t | ƒ\}}||d ko*||d kS )zöReturns True if the list of URLS completely covers a GPS interval

    The URL list is presumed to be contiguous, so this just checks that
    the first URL (by GPS timestamp) and the last URL can form a segment
    that overlaps that given.
    Fr   é   )r   )r   r   ÚaÚbr   r   r   Úfull_coverageU   s    r"   c             C   s    | d |d ko| d |d k S )zAReturns True if GPS segment ``a`` overlaps GPS segment ``b``
    r   r   r   )r    r!   r   r   r   r   c   s    r   N)	Úos.pathr   Ú
__author__r   r   r   r   r"   r   r   r   r   r   Ú<module>   s   
