How to use the cfgrib.dataset.open_file function in cfgrib

To help you get started, we’ve selected a few cfgrib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ecmwf / cfgrib / tests / test_30_dataset.py View on Github external
def test_Dataset_encode_cf_time():
    res = dataset.open_file(TEST_DATA, encode_cf=('time',))
    assert 'history' in res.attributes
    assert res.attributes['GRIB_edition'] == 1
    assert tuple(res.dimensions.keys()) == ('number', 'time', 'level', 'values')
    assert len(res.variables) == 9

    # equivalent to not np.isnan without importing numpy
    assert res.variables['t'].data[:, :, :, :].mean() > 0.0
github ecmwf / cfgrib / tests / test_30_dataset.py View on Github external
def test_Dataset():
    res = dataset.open_file(TEST_DATA)
    assert 'Conventions' in res.attributes
    assert 'institution' in res.attributes
    assert 'history' in res.attributes
    assert res.attributes['GRIB_edition'] == 1
    assert tuple(res.dimensions.keys()) == (
        'number',
        'time',
        'isobaricInhPa',
        'latitude',
        'longitude',
    )
    assert len(res.variables) == 9

    with pytest.warns(FutureWarning):
        dataset.open_file(TEST_DATA, mode='rw')
github ecmwf / cfgrib / tests / test_30_dataset.py View on Github external
def test_Dataset_reguler_gg_surface():
    path = os.path.join(SAMPLE_DATA_FOLDER, 'regular_gg_sfc.grib')
    res = dataset.open_file(path)

    assert res.dimensions == {'latitude': 96, 'longitude': 192}
    assert np.allclose(res.variables['latitude'].data[:2], [88.57216851, 86.72253095])
github ecmwf / cfgrib / tests / test_30_dataset.py View on Github external
def test_Dataset_no_encode():
    res = dataset.open_file(TEST_DATA, encode_cf=())
    assert 'Conventions' in res.attributes
    assert 'institution' in res.attributes
    assert 'history' in res.attributes
    assert res.attributes['GRIB_edition'] == 1
    assert tuple(res.dimensions.keys()) == ('number', 'dataDate', 'dataTime', 'level', 'values')
    assert len(res.variables) == 9
github ecmwf / cfgrib / tests / test_30_dataset.py View on Github external
def test_OnDiskArray():
    res = dataset.open_file(TEST_DATA).variables['t']

    assert isinstance(res.data, dataset.OnDiskArray)
    assert np.allclose(
        res.data[2:4:2, [0, 3], 0, 0, 0], res.data.build_array()[2:4:2, [0, 3], 0, 0, 0]
    )
github ecmwf / cfgrib / tests / test_30_dataset.py View on Github external
def test_Dataset_encode_cf_vertical():
    res = dataset.open_file(TEST_DATA, encode_cf=('vertical',))
    assert 'history' in res.attributes
    assert res.attributes['GRIB_edition'] == 1
    expected_dimensions = ('number', 'dataDate', 'dataTime', 'isobaricInhPa', 'values')
    assert tuple(res.dimensions.keys()) == expected_dimensions
    assert len(res.variables) == 9

    # equivalent to not np.isnan without importing numpy
    assert res.variables['t'].data[:, :, :, :, :].mean() > 0.0
github ecmwf / cfgrib / tests / test_30_dataset.py View on Github external
res = dataset.open_file(TEST_DATA)
    assert 'Conventions' in res.attributes
    assert 'institution' in res.attributes
    assert 'history' in res.attributes
    assert res.attributes['GRIB_edition'] == 1
    assert tuple(res.dimensions.keys()) == (
        'number',
        'time',
        'isobaricInhPa',
        'latitude',
        'longitude',
    )
    assert len(res.variables) == 9

    with pytest.warns(FutureWarning):
        dataset.open_file(TEST_DATA, mode='rw')
github ecmwf / cfgrib / tests / test_30_dataset.py View on Github external
def test_Dataset_encode_cf_geography():
    res = dataset.open_file(TEST_DATA, encode_cf=('geography',))
    assert 'history' in res.attributes
    assert res.attributes['GRIB_edition'] == 1
    assert tuple(res.dimensions.keys()) == (
        'number',
        'dataDate',
        'dataTime',
        'level',
        'latitude',
        'longitude',
    )
    assert len(res.variables) == 9

    # equivalent to not np.isnan without importing numpy
    assert res.variables['t'].data[:, :, :, :, :, :].mean() > 0.0