Skip to content
Snippets Groups Projects

Fixes problem with crop-tgrid

Merged Fraser William Goldsworth requested to merge m301014/pyicon:fix-croptgrid into master
3 files
+ 60
31
Compare changes
  • Side-by-side
  • Inline
Files
3
+ 37
15
import pytest
from pathlib import Path
import pytest
import xarray as xr
import pyicon as pyic
@pytest.fixture()
def raw_grid():
cur_dir = Path(__file__).parent.resolve()
grid_path = cur_dir / "test_data/icon_grid_0014_R02B04_O.nc"
def lazy_raw_grid():
path_data = Path(pyic.params['path_example_data'])
path_data.mkdir(parents=True, exist_ok=True)
grid_path = path_data / "icon_grid_0014_R02B04_O.nc"
if not grid_path.exists():
import requests
@@ -19,37 +21,57 @@ def raw_grid():
raise FileNotFoundError("{grid_path} does not exist and unable to \
download it")
ds_grid = xr.open_dataset(grid_path)
ds_grid = xr.open_dataset(grid_path, chunks="auto")
return ds_grid
@pytest.fixture()
def processed_tgrid(raw_grid):
return pyic.convert_tgrid_data(raw_grid)
def eager_raw_grid(lazy_raw_grid):
ds_raw_grid = lazy_raw_grid.compute()
return ds_raw_grid
@pytest.fixture()
def lazy_processed_tgrid(lazy_raw_grid):
return pyic.convert_tgrid_data(lazy_raw_grid)
@pytest.fixture()
def eager_processed_tgrid(eager_raw_grid):
return pyic.convert_tgrid_data(eager_raw_grid)
@pytest.fixture()
def examp_icon_dataset():
#cur_dir = Path(__file__).parent.resolve()
#fpath_data = cur_dir / "test_data/icon_example_data_r2b6.nc"
def lazy_examp_icon_dataset():
path_data = Path(pyic.params['path_example_data'])
path_data.mkdir(parents=True, exist_ok=True)
fpath_data = path_data / "icon_example_data_r2b4.nc"
if not fpath_data.exists():
import requests
download_link = "https://swift.dkrz.de/v1/dkrz_07387162e5cd4c81b1376bd7c648bb60/pyicon_example_data/icon_example_data_r2b4.nc"
download_link = "https://swift.dkrz.de/v1/dkrz_83018ad4-3c8d-4c7d-b684-7ba0742caa1a/pyicon_test_data/icon_example_data_r2b4.nc?temp_url_sig=03fb5d20a44832c7cf736ab83c1be3936364dbf6&temp_url_expires=2026-11-24T11:53:16Z"
try:
r = requests.get(download_link, allow_redirects=True)
r = requests.get(download_link, allow_redirects=True, stream=True)
with open(fpath_data, "wb") as fobj:
fobj.write(r.content)
except:
raise FileNotFoundError("{fpath_data} does not exist and unable to \
download it")
ds = xr.open_dataset(fpath_data)
ds = xr.open_dataset(fpath_data, chunks="auto")
return ds
@pytest.fixture()
def examp_icon_dataarray(examp_icon_dataset):
return examp_icon_dataset["to"]
def eager_examp_icon_dataset(lazy_examp_icon_dataset):
return lazy_examp_icon_dataset.compute()
@pytest.fixture()
def lazy_examp_icon_dataarray(lazy_examp_icon_dataset):
return lazy_examp_icon_dataset["to"]
@pytest.fixture()
def eager_examp_icon_dataarray(eager_examp_icon_dataset):
return eager_examp_icon_dataset["to"]
Loading