Skip to content

Commit 27a752c

Browse files
authored
Merge pull request #7 from malmans2/ecmwf-datastores-client
Migrate to ecmwf-datastores-client
2 parents 409b371 + 2b944ca commit 27a752c

File tree

6 files changed

+12
-13
lines changed

6 files changed

+12
-13
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ This Open Source project is build by B-Open - https://www.bopen.eu
77
xarray-ecmwf is a Python library and [Xarray](https://docs.xarray.dev) backend with the following functionalities:
88

99
- opens an ECMWF style request as a Xarray Dataset connected to the remote services
10-
- the [Climate Data Store](https://cds.climate.copernicus.eu) via [cdsapi](https://github.com/ecmwf/cdsapi): ERA5, Seasonal forecasts
11-
- the [Athospheric Data Store](https://ads.atmosphere.copernicus.eu) via cdsapi
10+
- the [Climate Data Store](https://cds.climate.copernicus.eu) via [ecmwf-datastores-client](https://github.com/ecmwf/ecmwf-datastores-client): ERA5, Seasonal forecasts
11+
- the [Atmospheric Data Store](https://ads.atmosphere.copernicus.eu) via ecmwf-datastores-client
1212
- the [ECMWF Open data](https://www.ecmwf.int/en/forecasts/datasets/open-data) via [ecmwf-opendata](https://github.com/ecmwf/ecmwf-opendata): High resolution forecasts, ensemble forecast
1313
- allows lazy loading the data and well integrated with [Dask](https://www.dask.org) and [Dask.distributed](https://distributed.dask.org)
1414
- allows chunking the input request according to a configurable splitting strategy. Allowed strategies:

ci/environment-integration.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ dependencies:
77
- pytest
88
- pytest-cov
99
# DO NOT EDIT ABOVE THIS LINE, ADD DEPENDENCIES BELOW
10-
- cdsapi
1110
- ecmwf-api-client
11+
- ecmwf-datastores-client
1212
- ecmwf-opendata
1313
- pandas-stubs
1414
- pip

environment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ channels:
99
# DO NOT EDIT ABOVE THIS LINE, ADD DEPENDENCIES BELOW AS SHOWN IN THE EXAMPLE
1010
dependencies:
1111
- attrs
12-
- cdsapi
1312
- cfgrib
13+
- ecmwf-datastores-client
1414
- ecmwf-opendata
1515
- pip
1616
- xarray

pyproject.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ classifiers = [
1212
"Programming Language :: Python :: 3.11",
1313
"Topic :: Scientific/Engineering"
1414
]
15-
dependencies = ["cdsapi", "cfgrib", "ecmwf-opendata", "polytope-client", "xarray"]
16-
description = "Xarray backend to access data via the cdsapi package"
15+
dependencies = ["cfgrib", "ecmwf-datastores-client", "ecmwf-opendata", "polytope-client", "xarray"]
16+
description = "Xarray backend to access ECMWF datastores"
1717
dynamic = ["version"]
1818
license = {file = "LICENSE"}
1919
name = "xarray-ecmwf"
@@ -32,7 +32,6 @@ strict = true
3232
[[tool.mypy.overrides]]
3333
ignore_missing_imports = true
3434
module = [
35-
"cdsapi",
3635
"cf2cdm",
3736
"ecmwf",
3837
"ecmwf.opendata",

xarray_ecmwf/client_cdsapi.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from typing import Any
44

55
import attrs
6-
import cdsapi
6+
import ecmwf.datastores
77
import numpy as np
88
import xarray as xr
99

@@ -16,13 +16,13 @@
1616

1717
@attrs.define
1818
class CdsapiRequestClient:
19-
client_kwargs: dict[str, Any] = {"quiet": True, "retry_max": 1}
19+
client_kwargs: dict[str, Any] = {"maximum_tries": 1}
2020

2121
def submit_and_wait_on_result(self, request: dict[str, Any]) -> Any:
2222
request = request.copy()
2323
dataset = request.pop("dataset")
24-
client = cdsapi.Client(**self.client_kwargs)
25-
return client.retrieve(dataset, request | {"format": "grib"})
24+
client = ecmwf.datastores.Client(**self.client_kwargs)
25+
return client.submit_and_wait_on_results(dataset, request | {"format": "grib"})
2626

2727
def get_filename(self, result: Any) -> str:
2828
return result.location.split("/")[-1] # type: ignore

xarray_ecmwf/engine_ecmwf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def retrieve_once(
108108
if not os.path.isdir(self.cache_folder):
109109
os.makedirs(self.cache_folder, exist_ok=True)
110110

111-
with xr.backends.locks.get_write_lock(f"{HOSTNAME}-grib"): # type: ignore
111+
with xr.backends.locks.get_write_lock(f"{HOSTNAME}-grib"):
112112
if not os.path.exists(path):
113113
robust_save_to_file(self.request_client.download, (result,), path)
114114
ds = self.open_dataset(path)
@@ -142,7 +142,7 @@ def cached_empty_dataset(self, request: dict[str, Any]) -> Iterator[xr.Dataset]:
142142
if not os.path.exists(path):
143143
with self.retrieve(request) as read_ds:
144144
# check again as the retrieve may be long
145-
with xr.backends.locks.get_write_lock(f"{HOSTNAME}-zarr"): # type: ignore
145+
with xr.backends.locks.get_write_lock(f"{HOSTNAME}-zarr"):
146146
if not os.path.exists(path):
147147
# NOTE: be sure that read_ds is chunked so compute=False only
148148
# writes the metadata. Some open_dataset

0 commit comments

Comments
 (0)