ecmwf/cfgrib

Add option ignore_keys (similar to filter_keys)

floriankrb opened this issue · 2 comments

When a user wants to open a grib file containing multiple gribs with inconsistent values, cfgrib refuses (rightfully) to merge them, leading to an error such as:

DatasetBuildError: multiple values for unique key, try re-open the file with one of:
    filter_by_keys={'dataType': 'pf'}
    filter_by_keys={'dataType': 'cf'}

While this solves some issues, it is not enough when the user does not want to filter, but prefers to ignore this key. I would like to extend the filter_keys option and add a new ignore_keys option.

For a key in the list provided by the user in ignore_keys, cfgrib should force the value to None when reading these keys. And the error message above could become:

DatasetBuildError: multiple values for unique key, try re-open the file with one of:
    filter_by_keys={'dataType': 'pf'}
    filter_by_keys={'dataType': 'cf'}
    ignore_keys=['dataType']

This is related to ecmwf/climetlab#33 (and maybe others, such as #263 and #268 and https://gis.stackexchange.com/questions/372729/unable-to-read-grib-datas-with-xarray).