Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Renamed 'grib_errors' parameter to 'errors' to match open_file() signature #349

Merged
merged 9 commits into from
Aug 18, 2023
2 changes: 1 addition & 1 deletion .github/workflows/on-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
max-parallel: 5
matrix:
os: [ubuntu]
python: [3.7, 3.8]
python: [3.8]
extras: ['']
include:
- os: macos
Expand Down
44 changes: 23 additions & 21 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ In a Python interpreter try:
>>> ds = xr.open_dataset('era5-levels-members.grib', engine='cfgrib')
>>> ds
<xarray.Dataset>
Dimensions: (number: 10, time: 4, isobaricInhPa: 2, latitude: 61, longitude: 120)
Dimensions: (number: 10, time: 4, isobaricInhPa: 2, latitude: 61,
longitude: 120)
Coordinates:
* number (number) int64 0 1 2 3 4 5 6 7 8 9
* time (time) datetime64[ns] 2017-01-01 ... 2017-01-02T12:00:00
Expand Down Expand Up @@ -188,7 +189,8 @@ To translate to the Common Data Model of the Climate Data Store use:
>>> import cf2cdm
>>> cf2cdm.translate_coords(ds, cf2cdm.CDS)
<xarray.Dataset>
Dimensions: (realization: 10, forecast_reference_time: 4, plev: 2, lat: 61, lon: 120)
Dimensions: (realization: 10, forecast_reference_time: 4,
plev: 2, lat: 61, lon: 120)
Coordinates:
* realization (realization) int64 0 1 2 3 4 5 6 7 8 9
* forecast_reference_time (forecast_reference_time) datetime64[ns] 2017-01...
Expand Down Expand Up @@ -261,7 +263,7 @@ Data variables:
crain (y, x) float32 ...
cape (y, x) float32 ...
cin (y, x) float32 ...
hpbl (y, x) float32 ...
unknown (y, x) float32 ...
Attributes:
GRIB_edition: 2
GRIB_centre: kwbc
Expand Down Expand Up @@ -323,7 +325,7 @@ Attributes:
GRIB_centreDescription: US National Weather Service - NCEP...
GRIB_subCentre: 0
Conventions: CF-1.7
institution: US National Weather Service - NCEP , <xarray.Dataset>
institution: US National Weather Service - NCEP, <xarray.Dataset>
Dimensions: (y: 65, x: 93)
Coordinates:
time datetime64[ns] 2018-09-17
Expand All @@ -342,7 +344,7 @@ Attributes:
GRIB_centreDescription: US National Weather Service - NCEP...
GRIB_subCentre: 0
Conventions: CF-1.7
institution: US National Weather Service - NCEP , <xarray.Dataset>
institution: US National Weather Service - NCEP, <xarray.Dataset>
Dimensions: (y: 65, x: 93)
Coordinates:
time datetime64[ns] 2018-09-17
Expand All @@ -362,7 +364,7 @@ Attributes:
GRIB_centreDescription: US National Weather Service - NCEP...
GRIB_subCentre: 0
Conventions: CF-1.7
institution: US National Weather Service - NCEP , <xarray.Dataset>
institution: US National Weather Service - NCEP, <xarray.Dataset>
Dimensions: (y: 65, x: 93)
Coordinates:
time datetime64[ns] 2018-09-17
Expand All @@ -381,7 +383,7 @@ Attributes:
GRIB_centreDescription: US National Weather Service - NCEP...
GRIB_subCentre: 0
Conventions: CF-1.7
institution: US National Weather Service - NCEP , <xarray.Dataset>
institution: US National Weather Service - NCEP, <xarray.Dataset>
Dimensions: (y: 65, x: 93)
Coordinates:
time datetime64[ns] 2018-09-17
Expand All @@ -400,7 +402,7 @@ Attributes:
GRIB_centreDescription: US National Weather Service - NCEP...
GRIB_subCentre: 0
Conventions: CF-1.7
institution: US National Weather Service - NCEP , <xarray.Dataset>
institution: US National Weather Service - NCEP, <xarray.Dataset>
Dimensions: (heightAboveGroundLayer: 2, y: 65, x: 93)
Coordinates:
time datetime64[ns] 2018-09-17
Expand All @@ -418,7 +420,7 @@ Attributes:
GRIB_centreDescription: US National Weather Service - NCEP...
GRIB_subCentre: 0
Conventions: CF-1.7
institution: US National Weather Service - NCEP , <xarray.Dataset>
institution: US National Weather Service - NCEP, <xarray.Dataset>
Dimensions: (isobaricInhPa: 19, y: 65, x: 93)
Coordinates:
time datetime64[ns] 2018-09-17
Expand All @@ -441,7 +443,7 @@ Attributes:
GRIB_centreDescription: US National Weather Service - NCEP...
GRIB_subCentre: 0
Conventions: CF-1.7
institution: US National Weather Service - NCEP , <xarray.Dataset>
institution: US National Weather Service - NCEP, <xarray.Dataset>
Dimensions: (isobaricInhPa: 5, y: 65, x: 93)
Coordinates:
time datetime64[ns] 2018-09-17
Expand All @@ -459,7 +461,7 @@ Attributes:
GRIB_centreDescription: US National Weather Service - NCEP...
GRIB_subCentre: 0
Conventions: CF-1.7
institution: US National Weather Service - NCEP , <xarray.Dataset>
institution: US National Weather Service - NCEP, <xarray.Dataset>
Dimensions: (y: 65, x: 93)
Coordinates:
time datetime64[ns] 2018-09-17
Expand All @@ -478,7 +480,7 @@ Attributes:
GRIB_centreDescription: US National Weather Service - NCEP...
GRIB_subCentre: 0
Conventions: CF-1.7
institution: US National Weather Service - NCEP , <xarray.Dataset>
institution: US National Weather Service - NCEP, <xarray.Dataset>
Dimensions: (y: 65, x: 93)
Coordinates:
time datetime64[ns] 2018-09-17
Expand All @@ -499,7 +501,7 @@ Attributes:
GRIB_centreDescription: US National Weather Service - NCEP...
GRIB_subCentre: 0
Conventions: CF-1.7
institution: US National Weather Service - NCEP , <xarray.Dataset>
institution: US National Weather Service - NCEP, <xarray.Dataset>
Dimensions: (y: 65, x: 93)
Coordinates:
time datetime64[ns] 2018-09-17
Expand All @@ -518,7 +520,7 @@ Attributes:
GRIB_centreDescription: US National Weather Service - NCEP...
GRIB_subCentre: 0
Conventions: CF-1.7
institution: US National Weather Service - NCEP , <xarray.Dataset>
institution: US National Weather Service - NCEP, <xarray.Dataset>
Dimensions: (pressureFromGroundLayer: 2, y: 65, x: 93)
Coordinates:
time datetime64[ns] 2018-09-17
Expand All @@ -537,7 +539,7 @@ Attributes:
GRIB_centreDescription: US National Weather Service - NCEP...
GRIB_subCentre: 0
Conventions: CF-1.7
institution: US National Weather Service - NCEP , <xarray.Dataset>
institution: US National Weather Service - NCEP, <xarray.Dataset>
Dimensions: (pressureFromGroundLayer: 5, y: 65, x: 93)
Coordinates:
time datetime64[ns] 2018-09-17
Expand All @@ -558,7 +560,7 @@ Attributes:
GRIB_centreDescription: US National Weather Service - NCEP...
GRIB_subCentre: 0
Conventions: CF-1.7
institution: US National Weather Service - NCEP , <xarray.Dataset>
institution: US National Weather Service - NCEP, <xarray.Dataset>
Dimensions: (y: 65, x: 93)
Coordinates:
time datetime64[ns] 2018-09-17
Expand All @@ -576,7 +578,7 @@ Attributes:
GRIB_centreDescription: US National Weather Service - NCEP...
GRIB_subCentre: 0
Conventions: CF-1.7
institution: US National Weather Service - NCEP , <xarray.Dataset>
institution: US National Weather Service - NCEP, <xarray.Dataset>
Dimensions: (y: 65, x: 93)
Coordinates:
time datetime64[ns] 2018-09-17
Expand All @@ -594,7 +596,7 @@ Attributes:
GRIB_centreDescription: US National Weather Service - NCEP...
GRIB_subCentre: 0
Conventions: CF-1.7
institution: US National Weather Service - NCEP , <xarray.Dataset>
institution: US National Weather Service - NCEP, <xarray.Dataset>
Dimensions: (y: 65, x: 93)
Coordinates:
time datetime64[ns] 2018-09-17
Expand All @@ -605,6 +607,7 @@ Coordinates:
valid_time datetime64[ns] 2018-09-17
Dimensions without coordinates: y, x
Data variables:
unknown (y, x) float32 ...
cape (y, x) float32 ...
sp (y, x) float32 ...
acpcp (y, x) float32 ...
Expand All @@ -616,14 +619,13 @@ Data variables:
cicep (y, x) float32 ...
csnow (y, x) float32 ...
gust (y, x) float32 ...
hpbl (y, x) float32 ...
Attributes:
GRIB_edition: 2
GRIB_centre: kwbc
GRIB_centreDescription: US National Weather Service - NCEP...
GRIB_subCentre: 0
Conventions: CF-1.7
institution: US National Weather Service - NCEP , <xarray.Dataset>
institution: US National Weather Service - NCEP, <xarray.Dataset>
Dimensions: (y: 65, x: 93)
Coordinates:
time datetime64[ns] 2018-09-17
Expand All @@ -644,7 +646,7 @@ Attributes:
GRIB_centreDescription: US National Weather Service - NCEP...
GRIB_subCentre: 0
Conventions: CF-1.7
institution: US National Weather Service - NCEP ]
institution: US National Weather Service - NCEP]


Advanced usage
Expand Down
4 changes: 2 additions & 2 deletions cfgrib/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,9 @@ def dump(inpaths, variable, cdm, engine):
ds = cf2cdm.translate_coords(ds, coord_model=coord_model)

if variable:
ds_or_da = ds[variable]
ds_or_da = ds[variable] # type: ignore
else:
ds_or_da = ds
ds_or_da = ds # type: ignore

print(ds_or_da)

Expand Down
7 changes: 3 additions & 4 deletions cfgrib/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,7 @@ def open_fileindex(

def open_file(
path: T.Union[str, "os.PathLike[str]"],
grib_errors: str = "warn",
errors: str = "warn",
indexpath: str = messages.DEFAULT_INDEXPATH,
filter_by_keys: T.Dict[str, T.Any] = {},
read_keys: T.Sequence[str] = (),
Expand All @@ -792,9 +792,8 @@ def open_file(
) -> Dataset:
"""Open a GRIB file as a ``cfgrib.Dataset``."""
path = os.fspath(path)
stream = messages.FileStream(path, errors=grib_errors)

stream = messages.FileStream(path, errors=errors)
index_keys = compute_index_keys(time_dims, extra_coords)
index = open_fileindex(stream, indexpath, index_keys, filter_by_keys=filter_by_keys)

return open_from_index(index, read_keys, time_dims, extra_coords, **kwargs)
return open_from_index(index, read_keys, time_dims, extra_coords, errors=errors, **kwargs)
2 changes: 1 addition & 1 deletion cfgrib/xarray_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def open_variable_datasets(path, backend_kwargs={}, **kwargs):
for key in ["filter_by_keys", "indexpath"]
if key in backend_kwargs
}
errors = backend_kwargs.get("grib_errors", "warn")
errors = backend_kwargs.get("errors", "warn")
stream = messages.FileStream(path, errors=errors)
index = open_fileindex(stream, computed_keys=cfmessage.COMPUTED_KEYS, **fileindex_kwargs)
datasets = [] # type: T.List[xr.Dataset]
Expand Down
Loading
Loading