1

I used this code to read grib data

import os
import numpy as np
import pandas as pd
import xarray as xr

path = "gfsanl_4_2019101000.g2"
os.chdir(path)
ds = xr.open_dataset('gfs_4_20191010_0000_006.grb2', engine='cfgrib')

And the output as is follows,

DatasetBuildError: multiple values for unique key, try re-open the file with one of:
    filter_by_keys={'typeOfLevel': 'hybrid'}
    filter_by_keys={'typeOfLevel': 'atmosphere'}
    filter_by_keys={'typeOfLevel': 'surface'}
    filter_by_keys={'typeOfLevel': 'unknown'}
    filter_by_keys={'typeOfLevel': 'isobaricInPa'}
    filter_by_keys={'typeOfLevel': 'isobaricInhPa'}
    filter_by_keys={'typeOfLevel': 'meanSea'}
    filter_by_keys={'typeOfLevel': 'depthBelowLandLayer'}
    filter_by_keys={'typeOfLevel': 'heightAboveGround'}
    filter_by_keys={'typeOfLevel': 'nominalTop'}
    filter_by_keys={'typeOfLevel': 'heightAboveGroundLayer'}
    filter_by_keys={'typeOfLevel': 'tropopause'}
    filter_by_keys={'typeOfLevel': 'maxWind'}
    filter_by_keys={'typeOfLevel': 'heightAboveSea'}
    filter_by_keys={'typeOfLevel': 'isothermZero'}
    filter_by_keys={'typeOfLevel': 'pressureFromGroundLayer'}
    filter_by_keys={'typeOfLevel': 'sigmaLayer'}
    filter_by_keys={'typeOfLevel': 'sigma'}
    filter_by_keys={'typeOfLevel': 'potentialVorticity'}

I tried to use filter_by_keys and backend_kwargs arguments to define the keys but I failed. Can you advice any solution for this?

1 Answer 1

1

If you add the backend_kwargs line, it will work properly, for example:-

ds = xr.open_dataset('gfs_4_20191010_0000_006.grb2',
                     engine='cfgrib',
                     backend_kwargs={'filter_by_keys': {'typeOfLevel': 'surface'}})

You can specify type of level you want to do the analysis specifically, the developers says cfgrib and its dependency has issues with handling multiple types of level at the moment. May be in future they will rectify this issue, as xarray always did and become an amazing tool.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.