Example #1
0
def usgs_data(siteNumber, t1, t2,sel_int = 'HR',parameterCd = '00060'):
    if (sel_int == 'HR'):
        service='iv'
    else:
        service='dv'
    data = nwis.get_record(sites=siteNumber, service=service, start=t1, end=t2,parameterCd=parameterCd)
    site_info, md = nwis.get_info(sites=siteNumber)
    df = data.iloc[:,0:1]
    cname = site_info['station_nm'].iloc[0].split(',')[0]
    df.columns = [cname.title() + ' (USGS)']
    df = df.tz_localize(None)
    df = df.resample('60min').mean()
    return (df)
def test_get_info(requests_mock):
    """
    Tests get_info method correctly generates the request url and returns the result in a DataFrame.
    Note that only sites and format are passed as query params
    """
    format = "rdb"
    site = '01491000%2C01645000'
    parameter_cd = "00618"
    request_url = 'https://waterservices.usgs.gov/nwis/site?sites={}&parameterCd={}&siteOutput=Expanded&format={}'.format(site, parameter_cd, format)
    response_file_path = 'data/waterservices_site.txt'
    mock_request(requests_mock, request_url, response_file_path)
    df, md = get_info(sites=["01491000", "01645000"], parameterCd="00618")
    assert type(df) is DataFrame
    assert df.size == 24
    assert md.url == request_url
    assert_metadata(requests_mock, request_url, md, site, parameter_cd, format)