示例#1
0
def test_get_stations_with_elements():
    test_elements = [
        {
            'elements': 'PRCP',
            'includes': [
                'ASN00008230',
                'WA006567710',
                'VQC00672823',
            ],
            'excludes': ['SWE00136141', 'USR0000OHOR', 'USC00450935', 'USR0000THEN', 'USR0000MDRY'],
        }, {
            'elements': ['SNOW', 'TMAX'],
            'includes': [
                'ACW00011604',
                'USW00094895',
                'VQW00011640',
                'ZI000067991',
            ],
            'excludes': ['BR037642870', 'BR00C8-0100', 'BR048519530', 'BR002548070', 'IN009081600']
        },
    ]
    url_files = {
        'ghcnd-stations': 'ncdc/ghcnd/ghcnd-stations.txt',
        'ghcnd-inventory': 'ncdc/ghcnd/ghcnd-inventory.txt'
    }

    with test_util.mocked_urls(url_files):
        for test_element in test_elements:
            elements = test_element.get('elements')
            stations = ghcn_daily.get_stations(elements=elements,
                as_dataframe=True)
            _check_stations_dataframe(stations,
                test_element.get('includes'),
                test_element.get('excludes'))
示例#2
0
def test_get_stations_with_elements():
    test_elements = [
        {
            'elements': 'PRCP',
            'includes': [
                'ASN00008230',
                'WA006567710',
                'VQC00672823',
            ],
            'excludes': [
                'AR000870470',
                'AR000875850',
                'BC000068234',
                'GME00111464',
                'UY000864400',
            ],
        }, {
            'elements': 'PRCP',
            'includes': [
                'ASN00008230',
                'WA006567710',
                'VQC00672823',
            ],
            'excludes': [
                'AR000870470',
                'AR000875850',
                'BC000068234',
                'GME00111464',
                'UY000864400',
            ],
        }, {
            'elements': ['SNOW', 'TMAX'],
            'includes': [
                'ACW00011604',
                'USW00094895',
                'VQW00011640',
                'ZI000067991',
            ],
            'excludes': [
                'BR00B4-0010',
                'IN003070101',
                'KZ000038223',
                'ZA000067753',
            ],
        },
    ]
    url_files = {
        'ghcnd-stations': 'ncdc/ghcnd/ghcnd-stations.txt',
        'ghcnd-inventory': 'ncdc/ghcnd/ghcnd-inventory.txt'
    }

    with test_util.mocked_urls(url_files):
        for test_element in test_elements:
            elements = test_element.get('elements')
            stations = ghcn_daily.get_stations(elements=elements,
                as_dataframe=True)
            _check_stations_dataframe(stations,
                test_element.get('includes'),
                test_element.get('excludes'))
示例#3
0
def test_get_stations_as_dicts():
    with test_util.mocked_urls('ncdc/ghcnd/ghcnd-stations.txt'):
        stations = ghcn_daily.get_stations()
    assert len(stations) > 80000

    for test_station in test_stations:
        station_id = test_station.get('id')
        assert stations.get(station_id) == test_station
示例#4
0
def test_get_stations_as_dicts():
    with test_util.mocked_urls('ncdc/ghcnd/ghcnd-stations.txt'):
        stations = ghcn_daily.get_stations()
    assert len(stations) > 80000

    for test_station in test_stations:
        station_id = test_station.get('id')
        assert stations.get(station_id) == test_station
示例#5
0
def test_get_stations_as_dataframe():
    with test_util.mocked_urls('ncdc/ghcnd/ghcnd-stations.txt'):
        stations = ghcn_daily.get_stations(as_dataframe=True)
    assert len(stations) > 80000

    for test_station in test_stations:
        station_id = test_station.get('id')
        station = stations.xs(station_id)
        station_dict = util.misc._nans_to_nones(station.to_dict())
        assert station_dict == test_station
示例#6
0
def test_get_stations_as_dataframe():
    with test_util.mocked_urls('ncdc/ghcnd/ghcnd-stations.txt'):
        stations = ghcn_daily.get_stations(as_dataframe=True)
    assert len(stations) > 80000

    for test_station in test_stations:
        station_id = test_station.get('id')
        station = stations.xs(station_id)
        station_dict = util.misc._nans_to_nones(station.to_dict())
        assert station_dict == test_station
示例#7
0
def test_get_stations_with_elements():
    test_elements = [
        {
            'elements':
            'PRCP',
            'includes': [
                'ASN00008230',
                'WA006567710',
                'VQC00672823',
            ],
            'excludes': [
                'SWE00136141', 'USR0000OHOR', 'USC00450935', 'USR0000THEN',
                'USR0000MDRY'
            ],
        },
        {
            'elements': ['SNOW', 'TMAX'],
            'includes': [
                'ACW00011604',
                'USW00094895',
                'VQW00011640',
                'ZI000067991',
            ],
            'excludes': [
                'BR037642870', 'BR00C8-0100', 'BR048519530', 'BR002548070',
                'IN009081600'
            ]
        },
    ]
    url_files = {
        'ghcnd-stations': 'ncdc/ghcnd/ghcnd-stations.txt',
        'ghcnd-inventory': 'ncdc/ghcnd/ghcnd-inventory.txt'
    }

    with test_util.mocked_urls(url_files):
        for test_element in test_elements:
            elements = test_element.get('elements')
            stations = ghcn_daily.get_stations(elements=elements,
                                               as_dataframe=True)
            _check_stations_dataframe(stations, test_element.get('includes'),
                                      test_element.get('excludes'))
示例#8
0
 def _search_catalog(self, **kwargs):
     return ghcn_daily.get_stations(as_dataframe=True)
示例#9
0
def test_get_stations_with_date_range():
    test_ranges = [
        {
            'start': 2011,
            'end': None,
            'includes': [
                'KE000063661',
                'USS0021E07S',
                'ZI000067983',
            ],
            'excludes': [
                'JQW00021601',
                'USC00448257',
                'ZI000067991',
            ],
        }, {
            'start': None,
            'end': 1920,
            'includes': [
                'USW00094957',
                'WZ004451000',
                'WZ004455110',
                'WZ004834260',
            ],
            'excludes': [
                'ASN00005063',
                'CA00405DJDN',
                'CA005040896',
            ],
        }, {
            'start': 1937,
            'end': 1945,
            'includes': [
                'ASN00015621',
                'ASN00023053',
                'WZ004451000',
                'WZ004834260',
            ],
            'excludes': [
                'ASN00041460',
                'ASN00023301',
                'US1COLR0770',
                'US1COLR0850',
            ],
        }, {
            'start': 1960,
            'end': 1960,
            'includes': [
                'ASN00078019',
                'ASN00041435',
            ],
            'excludes': [
                'US1COLR0770',
                'US1COLR0850',
            ],
        },
    ]

    url_files = {
        'ghcnd-stations': 'ncdc/ghcnd/ghcnd-stations.txt',
        'ghcnd-inventory': 'ncdc/ghcnd/ghcnd-inventory.txt'
    }

    with test_util.mocked_urls(url_files):
        for test_range in test_ranges:
            start = test_range.get('start')
            end = test_range.get('end')
            stations = ghcn_daily.get_stations(start_year=start,
                end_year=end, as_dataframe=True)
            _check_stations_dataframe(stations,
                test_range.get('includes'),
                test_range.get('excludes'))
示例#10
0
def test_get_stations_by_state():
    with test_util.mocked_urls('ncdc/ghcnd/ghcnd-stations.txt'):
        stations = ghcn_daily.get_stations(state='TX', as_dataframe=True)
    assert len(stations) > 3200
示例#11
0
def test_get_stations_by_country():
    with test_util.mocked_urls('ncdc/ghcnd/ghcnd-stations.txt'):
        stations = ghcn_daily.get_stations(country='US', as_dataframe=True)
    assert len(stations) > 45000
示例#12
0
def test_get_stations_with_elements():
    test_elements = [
        {
            'elements':
            'PRCP',
            'includes': [
                'ASN00008230',
                'WA006567710',
                'VQC00672823',
            ],
            'excludes': [
                'AR000870470',
                'AR000875850',
                'BC000068234',
                'GME00111464',
                'UY000864400',
            ],
        },
        {
            'elements':
            'PRCP',
            'includes': [
                'ASN00008230',
                'WA006567710',
                'VQC00672823',
            ],
            'excludes': [
                'AR000870470',
                'AR000875850',
                'BC000068234',
                'GME00111464',
                'UY000864400',
            ],
        },
        {
            'elements': ['SNOW', 'TMAX'],
            'includes': [
                'ACW00011604',
                'USW00094895',
                'VQW00011640',
                'ZI000067991',
            ],
            'excludes': [
                'BR00B4-0010',
                'IN003070101',
                'KZ000038223',
                'ZA000067753',
            ],
        },
    ]
    url_files = {
        'ghcnd-stations': 'ncdc/ghcnd/ghcnd-stations.txt',
        'ghcnd-inventory': 'ncdc/ghcnd/ghcnd-inventory.txt'
    }

    with test_util.mocked_urls(url_files):
        for test_element in test_elements:
            elements = test_element.get('elements')
            stations = ghcn_daily.get_stations(elements=elements,
                                               as_dataframe=True)
            _check_stations_dataframe(stations, test_element.get('includes'),
                                      test_element.get('excludes'))
示例#13
0
def test_get_stations_with_date_range():
    test_ranges = [
        {
            'start': 2011,
            'end': None,
            'includes': [
                'KE000063661',
                'USS0021E07S',
                'ZI000067983',
            ],
            'excludes': [
                'JQW00021601',
                'USC00448257',
                'ZI000067991',
            ],
        },
        {
            'start':
            None,
            'end':
            1920,
            'includes': [
                'USW00094957',
                'WZ004451000',
                'WZ004455110',
                'WZ004834260',
            ],
            'excludes': [
                'ASN00005063',
                'CA00405DJDN',
                'CA005040896',
            ],
        },
        {
            'start':
            1937,
            'end':
            1945,
            'includes': [
                'ASN00015621',
                'ASN00023053',
                'WZ004451000',
                'WZ004834260',
            ],
            'excludes': [
                'ASN00041460',
                'ASN00023301',
                'US1COLR0770',
                'US1COLR0850',
            ],
        },
        {
            'start': 1960,
            'end': 1960,
            'includes': [
                'ASN00078019',
                'ASN00041435',
            ],
            'excludes': [
                'US1COLR0770',
                'US1COLR0850',
            ],
        },
    ]

    url_files = {
        'ghcnd-stations': 'ncdc/ghcnd/ghcnd-stations.txt',
        'ghcnd-inventory': 'ncdc/ghcnd/ghcnd-inventory.txt'
    }

    with test_util.mocked_urls(url_files):
        for test_range in test_ranges:
            start = test_range.get('start')
            end = test_range.get('end')
            stations = ghcn_daily.get_stations(start_year=start,
                                               end_year=end,
                                               as_dataframe=True)
            _check_stations_dataframe(stations, test_range.get('includes'),
                                      test_range.get('excludes'))
示例#14
0
def test_get_stations_by_state():
    with test_util.mocked_urls('ncdc/ghcnd/ghcnd-stations.txt'):
        stations = ghcn_daily.get_stations(state='TX', as_dataframe=True)
    assert 3200 < len(stations) < 3500
示例#15
0
def test_get_stations_by_country():
    with test_util.mocked_urls('ncdc/ghcnd/ghcnd-stations.txt'):
        stations = ghcn_daily.get_stations(country='US', as_dataframe=True)
    assert 45000 < len(stations) < 47000