How to use the cfgrib.cfmessage 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_build_data_var_components_encode_cf_geography():
    stream = messages.FileStream(path=TEST_DATA, message_class=cfmessage.CfMessage)
    index = stream.index(dataset.ALL_KEYS).subindex(paramId=130)
    dims, data_var, coord_vars = dataset.build_variable_components(
        index=index, encode_cf='geography'
    )
    assert dims == {
        'number': 10,
        'dataDate': 2,
        'dataTime': 2,
        'level': 2,
        'latitude': 61,
        'longitude': 120,
    }
    assert data_var.data.shape == (10, 2, 2, 2, 61, 120)

    # equivalent to not np.isnan without importing numpy
    assert data_var.data[:, :, :, :, :, :].mean() > 0.0
github ecmwf / cfgrib / tests / test_25_cfmessage.py View on Github external
def test_from_grib_date_time():
    message = {'dataDate': 20160706, 'dataTime': 1944}
    result = cfmessage.from_grib_date_time(message)

    assert result == 1467834240
github ecmwf / cfgrib / tests / test_25_cfmessage.py View on Github external
def test_to_grib_step():
    message = {}
    step_ns = 60 * 60 * 1e9

    cfmessage.to_grib_step(message, step_ns, step_unit=1)

    assert message['endStep'] == 1
    assert message['stepUnits'] == 1

    with pytest.raises(ValueError):
        cfmessage.to_grib_step(message, 0, step_unit=3)
github ecmwf / cfgrib / cfgrib / dataset.py View on Github external
def open_fileindex(
    path, grib_errors='warn', indexpath='{path}.{short_hash}.idx', index_keys=ALL_KEYS
):
    stream = messages.FileStream(path, message_class=cfmessage.CfMessage, errors=grib_errors)
    return stream.index(index_keys, indexpath=indexpath)