Open and decode a dataset from a file or file-like object. Parameters ---------- filename_or_obj : str, Path, file-like, bytes, memoryview or DataStore Strings and Path objects are interpreted as a path to a netCDF file or an OpenDAP URL and opened with python-netCDF4, u
(
filename_or_obj: T_PathFileOrDataStore,
*,
engine: T_Engine = None,
chunks: T_Chunks = None,
cache: bool | None = None,
decode_cf: bool | None = None,
mask_and_scale: bool | Mapping[str, bool] | None = None,
decode_times: (
bool | CFDatetimeCoder | Mapping[str, bool | CFDatetimeCoder] | None
) = None,
decode_timedelta: (
bool | CFTimedeltaCoder | Mapping[str, bool | CFTimedeltaCoder] | None
) = None,
use_cftime: bool | Mapping[str, bool] | None = None,
concat_characters: bool | Mapping[str, bool] | None = None,
decode_coords: Literal["coordinates", "all"] | bool | None = None,
drop_variables: str | Iterable[str] | None = None,
create_default_indexes: bool = True,
inline_array: bool = False,
chunked_array_type: str | None = None,
from_array_kwargs: dict[str, Any] | None = None,
backend_kwargs: dict[str, Any] | None = None,
**kwargs,
)
| 387 | |
| 388 | |
| 389 | def open_dataset( |
| 390 | filename_or_obj: T_PathFileOrDataStore, |
| 391 | *, |
| 392 | engine: T_Engine = None, |
| 393 | chunks: T_Chunks = None, |
| 394 | cache: bool | None = None, |
| 395 | decode_cf: bool | None = None, |
| 396 | mask_and_scale: bool | Mapping[str, bool] | None = None, |
| 397 | decode_times: ( |
| 398 | bool | CFDatetimeCoder | Mapping[str, bool | CFDatetimeCoder] | None |
| 399 | ) = None, |
| 400 | decode_timedelta: ( |
| 401 | bool | CFTimedeltaCoder | Mapping[str, bool | CFTimedeltaCoder] | None |
| 402 | ) = None, |
| 403 | use_cftime: bool | Mapping[str, bool] | None = None, |
| 404 | concat_characters: bool | Mapping[str, bool] | None = None, |
| 405 | decode_coords: Literal["coordinates", "all"] | bool | None = None, |
| 406 | drop_variables: str | Iterable[str] | None = None, |
| 407 | create_default_indexes: bool = True, |
| 408 | inline_array: bool = False, |
| 409 | chunked_array_type: str | None = None, |
| 410 | from_array_kwargs: dict[str, Any] | None = None, |
| 411 | backend_kwargs: dict[str, Any] | None = None, |
| 412 | **kwargs, |
| 413 | ) -> Dataset: |
| 414 | """Open and decode a dataset from a file or file-like object. |
| 415 | |
| 416 | Parameters |
| 417 | ---------- |
| 418 | filename_or_obj : str, Path, file-like, bytes, memoryview or DataStore |
| 419 | Strings and Path objects are interpreted as a path to a netCDF file |
| 420 | or an OpenDAP URL and opened with python-netCDF4, unless the filename |
| 421 | ends with .gz, in which case the file is gunzipped and opened with |
| 422 | scipy.io.netcdf (only netCDF3 supported). Bytes, memoryview and |
| 423 | file-like objects are opened by scipy.io.netcdf (netCDF3) or h5netcdf |
| 424 | (netCDF4). |
| 425 | engine : {"netcdf4", "scipy", "pydap", "h5netcdf", "zarr", None}\ |
| 426 | , installed backend \ |
| 427 | or subclass of xarray.backends.BackendEntrypoint, optional |
| 428 | Engine to use when reading files. If not provided, the default engine |
| 429 | is chosen based on available dependencies, by default preferring |
| 430 | "netcdf4" over "h5netcdf" over "scipy" (customizable via |
| 431 | ``netcdf_engine_order`` in ``xarray.set_options()``). A custom backend |
| 432 | class (a subclass of ``BackendEntrypoint``) can also be used. |
| 433 | chunks : int, dict, 'auto' or None, default: None |
| 434 | If provided, used to load the data into dask arrays. |
| 435 | |
| 436 | - ``chunks="auto"`` will use dask ``auto`` chunking taking into account the |
| 437 | engine preferred chunks. |
| 438 | - ``chunks=None`` skips using dask. This uses xarray's internally private |
| 439 | :ref:`lazy indexing classes <internal design.lazy indexing>`, |
| 440 | but data is eagerly loaded into memory as numpy arrays when accessed. |
| 441 | This can be more efficient for smaller arrays or when large arrays are sliced before computation. |
| 442 | - ``chunks=-1`` loads the data with dask using a single chunk for all arrays. |
| 443 | - ``chunks={}`` loads the data with dask using the engine's preferred chunk |
| 444 | size, generally identical to the format's chunk size. If not available, a |
| 445 | single chunk for all arrays. |
| 446 |
searching dependent graphs…