55from collections .abc import Callable , Hashable , Iterable
66from functools import cached_property
77from pathlib import Path
8- from typing import Literal , get_args
8+ from typing import Any , Literal , get_args
99
1010import tqdm
1111import xarray as xr
@@ -117,10 +117,15 @@ def download(self) -> list[File]:
117117 def _open_datasets (
118118 self ,
119119 concat_dims : DATASET_ID_KEYS | Iterable [DATASET_ID_KEYS ] | None ,
120- drop_variables : str | Iterable [str ] | None = None ,
121- download : bool = False ,
122- show_progress : bool = True ,
120+ drop_variables : str | Iterable [str ] | None ,
121+ download : bool ,
122+ show_progress : bool ,
123+ sel : dict [Hashable , Any ],
123124 ) -> dict [str , Dataset ]:
125+ sel = {
126+ k : slice (* v ["slice" ]) if isinstance (v , dict ) else v for k , v in sel .items ()
127+ }
128+
124129 if isinstance (concat_dims , str ):
125130 concat_dims = [concat_dims ]
126131 concat_dims = concat_dims or []
@@ -139,6 +144,7 @@ def _open_datasets(
139144 drop_variables = drop_variables ,
140145 storage_options = {"ssl" : self .verify_ssl },
141146 )
147+ ds = ds .sel ({k : v for k , v in sel .items () if k in ds .dims })
142148 grouped_objects [file .dataset_id ].append (ds .drop_encoding ())
143149
144150 combined_datasets = {}
@@ -173,9 +179,14 @@ def open_dataset(
173179 drop_variables : str | Iterable [str ] | None = None ,
174180 download : bool = False ,
175181 show_progress : bool = True ,
182+ sel : dict [Hashable , Any ] | None = None ,
176183 ) -> Dataset :
177184 combined_datasets = self ._open_datasets (
178- concat_dims , drop_variables , download , show_progress
185+ concat_dims = concat_dims ,
186+ drop_variables = drop_variables ,
187+ download = download ,
188+ show_progress = show_progress ,
189+ sel = sel or {},
179190 )
180191
181192 obj = xr .combine_by_coords (
0 commit comments