B
    zdF                 @   sr   d Z ddlmZmZmZmZ dddgZdZdddd	ej	fd
dZ
dddZdddddd	dej	fddZdd ZdS )a  
`gwosc.locate` provides functions to determine the file URLs containing
data for a specific dataset.

You can search for remote data URLS based on the event name:

>>> from gwosc.locate import get_event_urls
>>> get_event_urls('GW150914')
['https://gwosc.org/eventapi/json/GWTC-1-confident/GW150914/v3/H-H1_GWOSC_4KHZ_R1-1126259447-32.hdf5',
 'https://gwosc.org/eventapi/json/GWTC-1-confident/GW150914/v3/H-H1_GWOSC_4KHZ_R1-1126257415-4096.hdf5',
 'https://gwosc.org/eventapi/json/GWTC-1-confident/GW150914/v3/L-L1_GWOSC_4KHZ_R1-1126259447-32.hdf5',
 'https://gwosc.org/eventapi/json/GWTC-1-confident/GW150914/v3/L-L1_GWOSC_4KHZ_R1-1126257415-4096.hdf5']

You can down-select the URLs using keyword arguments:

>>> get_event_urls('GW150914', detector='L1', duration=32)
['https://gwosc.org/eventapi/json/GWTC-1-confident/GW150914/v3/L-L1_GWOSC_4KHZ_R1-1126259447-32.hdf5']

You can search for remote data URLs based on the GPS time interval as
follows:

>>> from gwosc.locate import get_urls
>>> get_urls('L1', 968650000, 968660000)
['https://gwosc.org/archive/data/S6/967835648/L-L1_LOSC_4_V1-968646656-4096.hdf5',
 'https://gwosc.org/archive/data/S6/967835648/L-L1_LOSC_4_V1-968650752-4096.hdf5',
 'https://gwosc.org/archive/data/S6/967835648/L-L1_LOSC_4_V1-968654848-4096.hdf5',
 'https://gwosc.org/archive/data/S6/967835648/L-L1_LOSC_4_V1-968658944-4096.hdf5']

By default, this method will return the paths to HDF5 files for the 4 kHz
sample-rate data, these can be specified as keyword arguments.
For full information, see :func:`get_urls`.
   )apidatasetsurlsutilsget_urlsget_run_urlsget_event_urlsz(Duncan Macleod <duncan.macleod@ligo.org>N   hdf5c             C   s   t |}t |}xdD ]x}tj||| ||f||d}	xX|	D ]P}
|dkr^t|
| |||||d}nt|
| ||||||d}t|||fr:|S q:W qW td| ||f dS )a  Fetch the URLs from GWOSC regarding a given GPS interval

    Parameters
    ----------
    detector : `str`
        the prefix of the relevant GW detector

    start : `int`
        the GPS start time of your query

    end : `int`
        the GPS end time of your query

    dataset : `str`, `None`, optional
        the name of the dataset to query, e.g. ``'GW150914'``

    version : `int`, `None`, optional
        the data-release version for the selected datasets

    sample_rate : `int`, optional, default : ``4096``
        the sampling rate (Hz) of files you want to find

    format : `str`, optional, default: ``'hdf5'``
        the file format (extension) you want to find

    host : `str`, optional
        the URL of the remote GWOSC server

    Returns
    -------
    urls : `list` of `str`
        the list of remote file URLs that contain data matching the
        relevant parameters
    )eventrun)matchtypedetectorsegmentversionhostr   )r   sample_rateformat)r   startendr   r   r   r   z4Cannot find a GWOSC dataset for %s covering [%d, %d)N)intr   Z_iter_datasetsr   r   r   Zfull_coverage
ValueError)r   r   r   Zdatasetr   r   r   r   ZdstypeZdsetsdstr    r   Y/work/yifan.wang/ringdown/master-ringdown-env/lib/python3.7/site-packages/gwosc/locate.pyr   1   sB    *


c          	   K   s>   t j| ||||dt jd}ttj|d f||d|S )a\  Fetch the URLs from GWOSC regarding a given event

    Parameters
    ----------
    event : `str`
        the ID of the event

    detector : `str`, optional
        the detector for files you want to find

    start : `int`
        the GPS start time of your query

    end : `int`
        the GPS end time of your query

    format : `str`, optional, default: ``'hdf5'``
        the file format (extension) you want to find

    sample_rate : `int`, optional, default : ``4096``
        the sampling rate (Hz) of files you want to find

    host : `str`, optional
        the URL of the remote GWOSC server

    version : `int`, `None`, optional
        the data-release version for the selected datasets

    Returns
    -------
    urls : `list` of `str`
        the list of remote file URLs that contain data matching the
        relevant parameters
    r   )ZgpsstartZgpsendr   strain)r   sampling_rate)r   Zfetch_run_jsonpopDEFAULT_URL_urlslurlssieve)r   r   r   r   r   r   r   metar   r   r   r      s    ,c	             K   s   t tj| ||d|dd  d }
|
d }|dkrB|dkrBd}n,|dkrTtd n||dkrhtd
 n|f}ttj|f||||d|	S )	a\  Fetch the URLs from GWOSC regarding a given event

    Parameters
    ----------
    event : `str`
        the ID of the event

    detector : `str`, optional
        the detector for files you want to find

    format : `str`, optional, default: ``'hdf5'``
        the file format (extension) you want to find

    sample_rate : `int`, optional, default : ``4096``
        the sampling rate (Hz) of files you want to find

    host : `str`, optional
        the URL of the remote GWOSC server

    start : `int`
        the GPS start time of your query

    end : `int`
        the GPS end time of your query

    version : `int`, `None`, optional
        the data-release version for the selected datasets

    Returns
    -------
    urls : `list` of `str`
        the list of remote file URLs that contain data matching the
        relevant parameters
    T)catalogr   fullr   events    r   Ninf)r   r   r   r   )listr   Z_fetch_allevents_event_jsonvaluesfloatr    r!   r"   )r   r$   r   r   r   r   r   r   r   r   r#   r   r   r   r   r   r      s&    /c             C   s   dd | D S )Nc             S   s   g | ]}|d  qS )urlr   ).0ur   r   r   
<listcomp>  s    z_urls.<locals>.<listcomp>r   )r   r   r   r   r      s    r    )r
   r	   )__doc__ r   r   r   r!   r   __all__
__author__r   r   r   r   r    r   r   r   r   <module>$   s&   
V 
9C