Skip to content

Commit 6a08b92

Browse files
committed
refactor dask.config.set
1 parent 76264fe commit 6a08b92

8 files changed

Lines changed: 9 additions & 35 deletions

File tree

PyStemmusScope/forcing_io.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Module for forcing data input and output operations."""
22
from pathlib import Path
3+
import dask
34
import hdf5storage
45
import numpy as np
56
import xarray as xr
@@ -130,12 +131,14 @@ def read_forcing_data_global( # noqa:PLR0913 (too many arguments)
130131
Returns:
131132
Dictionary containing the forcing data.
132133
"""
133-
return global_data.collect_datasets(
134-
global_data_dir=global_data_dir,
135-
latlon=(lat, lon),
136-
time_range=(start_time, end_time),
137-
timestep=timestep,
138-
)
134+
# see https://docs.dask.org/en/latest/array-slicing.html#efficiency
135+
with dask.config.set(**{"array.slicing.split_large_chunks": True}): # type: ignore
136+
return global_data.collect_datasets(
137+
global_data_dir=global_data_dir,
138+
latlon=(lat, lon),
139+
time_range=(start_time, end_time),
140+
timestep=timestep,
141+
)
139142

140143

141144
def write_dat_files(data: dict, input_dir: Path):

PyStemmusScope/global_data/cams_co2.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
"""Module for loading and validating the CAMS CO2 dataset."""
22
from pathlib import Path
33
from typing import Union
4-
import dask
54
import numpy as np
65
import xarray as xr
76
from PyStemmusScope.global_data import utils
87

98

10-
# see https://docs.dask.org/en/latest/array-slicing.html#efficiency
11-
dask.config.set(**{"array.slicing.split_large_chunks": True}) # type: ignore
12-
139
RESOLUTION_CAMS = 0.75 # Resolution of the dataset in degrees
1410

1511

PyStemmusScope/global_data/cci_landcover.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
"""Module for loading and validating the ESA CCI land cover dataset."""
22
from pathlib import Path
33
from typing import Union
4-
import dask
54
import numpy as np
65
import pandas as pd
76
import xarray as xr
87
from PyStemmusScope.global_data import utils
98

109

11-
# see https://docs.dask.org/en/latest/array-slicing.html#efficiency
12-
dask.config.set(**{"array.slicing.split_large_chunks": True}) # type: ignore
13-
1410
RESOLUTION_CCI = 1 / 360 # Resolution of the dataset in degrees
1511
FILEPATH_LANDCOVER_TABLE = Path(__file__).parent / "assets" / "lccs_to_igbp_table.csv"
1612

PyStemmusScope/global_data/copernicus_lai.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
"""Module for loading and validating the Copernicus LAI dataset."""
22
from pathlib import Path
33
from typing import Union
4-
import dask
54
import numpy as np
65
import xarray as xr
76
from PyStemmusScope.global_data import utils
87

98

10-
# see https://docs.dask.org/en/latest/array-slicing.html#efficiency
11-
dask.config.set(**{"array.slicing.split_large_chunks": True}) # type: ignore
12-
139
RESOLUTION_LAI = 1 / 112 # Resolution of the LAI dataset in degrees
1410

1511

PyStemmusScope/global_data/era5.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,12 @@
22
from pathlib import Path
33
from typing import Literal
44
from typing import Union
5-
import dask
65
import numpy as np
76
import PyStemmusScope.variable_conversion as vc
87
import xarray as xr
98
from PyStemmusScope.global_data import utils
109

1110

12-
# see https://docs.dask.org/en/latest/array-slicing.html#efficiency
13-
dask.config.set(**{"array.slicing.split_large_chunks": True}) # type: ignore
14-
1511
ERA5_VARIABLES = ["u10", "v10", "mtpr", "sp", "ssrd", "strd"]
1612
ERA5LAND_VARIABLES = ["t2m", "d2m"]
1713
RESOLUTION_ERA5 = 0.25 # Resolution in degrees, to find nearest gridpoint.

PyStemmusScope/global_data/eth_canopy_height.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,10 @@
22
import gzip
33
from pathlib import Path
44
from typing import Union
5-
import dask
65
import xarray as xr
76
from PyStemmusScope.global_data import utils
87

98

10-
# see https://docs.dask.org/en/latest/array-slicing.html#efficiency
11-
dask.config.set(**{"array.slicing.split_large_chunks": True}) # type: ignore
12-
139
MAX_DISTANCE = 0.01 # Maximum lat/lon distance to be considered nearby.
1410

1511

PyStemmusScope/global_data/prism_dem.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,10 @@
22
import gzip
33
from pathlib import Path
44
from typing import Union
5-
import dask
65
import xarray as xr
76
from PyStemmusScope.global_data import utils
87

98

10-
# see https://docs.dask.org/en/latest/array-slicing.html#efficiency
11-
dask.config.set(**{"array.slicing.split_large_chunks": True}) # type: ignore
12-
139
MAX_DISTANCE = 0.01 # Maximum lat/lon distance to be considered nearby. Approx 1km.
1410

1511

PyStemmusScope/global_data/utils.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
"""Utility funtions for the global data IO."""
22
from typing import Union
3-
import dask
43
import numpy as np
54
import xarray as xr
65

76

8-
# see https://docs.dask.org/en/latest/array-slicing.html#efficiency
9-
dask.config.set(**{"array.slicing.split_large_chunks": True}) # type: ignore
10-
11-
127
class MissingDataError(Exception):
138
"""Error to be raised when requested data is missing."""
149

0 commit comments

Comments
 (0)