Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion tests/test_10_client.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
from pathlib import Path

import pytest

from xarray_esgf import Client


def test_download(tmp_path: Path, index_node: str) -> None:
@pytest.mark.parametrize("check_files", [True, False])
def test_download(tmp_path: Path, index_node: str, check_files: bool) -> None:
selection: dict[str, str | list[str]] = {
"query": '"tas_Amon_EC-Earth3-CC_ssp245_r1i1p1f1_gr_201901-201912.nc"'
}
client = Client(
selection,
esgpull_path=str(tmp_path / "esgpull"),
index_node=index_node,
check_files=check_files,
)

downloaded = client.download()
Expand Down
12 changes: 9 additions & 3 deletions xarray_esgf/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class Client:
esgpull_path: str | Path | None = None
index_node: str | None = None
retries: int = 0
check_files: bool = True
verify_ssl: bool = False

@cached_property
Expand Down Expand Up @@ -91,9 +92,14 @@ def files(self) -> list[File]:

@property
def missing_files(self) -> list[File]:
return [
file for file in self.files if self._client.fs.check(file) != FileCheck.Ok
]
missing_files = []
for file in tqdm.tqdm(self.files, desc="Looking for missing files:"):
file_path = Path(str(self._client.fs[file]))
if (self.check_files and self._client.fs.check(file) != FileCheck.Ok) or (
not self.check_files and not file_path.exists()
):
missing_files.append(file)
return missing_files

def download(self) -> list[File]:
files = []
Expand Down
6 changes: 4 additions & 2 deletions xarray_esgf/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,19 @@ def open_dataset( # type: ignore[override]
drop_variables: str | Iterable[str] | None = None,
esgpull_path: str | Path | None = None,
index_node: str | None = None,
retries: int = 0,
check_files: bool = True,
verify_ssl: bool = False,
concat_dims: DATASET_ID_KEYS | Iterable[DATASET_ID_KEYS] | None = None,
download: bool = False,
show_progress: bool = True,
retries: int = 0,
verify_ssl: bool = False,
) -> Dataset:
client = Client(
selection=filename_or_obj,
esgpull_path=esgpull_path,
index_node=index_node,
retries=retries,
check_files=check_files,
verify_ssl=verify_ssl,
)
return client.open_dataset(
Expand Down