How to use the cfgrib.bindings.codes_new_from_samples 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_10_bindings.py View on Github external
def test_codes_set():
    message_id = bindings.codes_new_from_samples('regular_ll_sfc_grib2')

    bindings.codes_set(message_id, 'endStep', 2)
    bindings.codes_set(message_id, 'longitudeOfFirstGridPointInDegrees', 1.0)
    bindings.codes_set(message_id, 'gridType', 'regular_ll')

    with pytest.raises(TypeError):
        bindings.codes_set(message_id, 'endStep', [])
github ecmwf / cfgrib / tests / test_10_bindings.py View on Github external
def test_codes_new_from_samples_errors():
    with pytest.raises(ValueError):
        bindings.codes_new_from_samples('non-existent')
github ecmwf / cfgrib / tests / test_10_bindings.py View on Github external
def test_codes_write(tmpdir):
    message_id = bindings.codes_new_from_samples('regular_ll_sfc_grib2')
    grib_file = tmpdir.join('test.grib')

    with open(str(grib_file), 'wb') as file:
        bindings.codes_write(message_id, file)

    assert grib_file.read_binary()[:4] == b'GRIB'

    with open(str(grib_file)) as file:
        bindings.codes_grib_new_from_file(file)
github ecmwf / cfgrib / tests / test_10_bindings.py View on Github external
def test_codes_set_array():
    message_id = bindings.codes_new_from_samples('regular_ll_sfc_grib2')

    bindings.codes_set_array(message_id, 'values', [0.0])
    bindings.codes_set_array(message_id, 'values', [0])

    with pytest.raises(ValueError):
        bindings.codes_set_array(message_id, 'values', [])

    with pytest.raises(TypeError):
        bindings.codes_set_array(message_id, 'values', ['a'])
github ecmwf / cfgrib / tests / test_10_bindings.py View on Github external
def test_codes_new_from_samples():
    res = bindings.codes_new_from_samples('regular_ll_sfc_grib2')

    assert isinstance(res, bindings.ffi.CData)
    assert "grib_handle *'" in repr(res)
github ecmwf / cfgrib / cfgrib / messages.py View on Github external
def from_sample_name(cls, sample_name, product_kind=eccodes.CODES_PRODUCT_GRIB, **kwargs):
        codes_id = eccodes.codes_new_from_samples(sample_name, product_kind)
        return cls(codes_id=codes_id, **kwargs)