Trigger loading data into memory and return this dataset. Data will be computed and/or loaded from disk or a remote source. Unlike ``.compute``, the original dataset is modified and returned. Normally, it should not be necessary to call this method in user code, be
(self, **kwargs)
| 529 | ) |
| 530 | |
| 531 | def load(self, **kwargs) -> Self: |
| 532 | """Trigger loading data into memory and return this dataset. |
| 533 | |
| 534 | Data will be computed and/or loaded from disk or a remote source. |
| 535 | |
| 536 | Unlike ``.compute``, the original dataset is modified and returned. |
| 537 | |
| 538 | Normally, it should not be necessary to call this method in user code, |
| 539 | because all xarray functions should either work on deferred data or |
| 540 | load data automatically. However, this method can be necessary when |
| 541 | working with many file objects on disk. |
| 542 | |
| 543 | Parameters |
| 544 | ---------- |
| 545 | **kwargs : dict |
| 546 | Additional keyword arguments passed on to ``dask.compute``. |
| 547 | |
| 548 | Returns |
| 549 | ------- |
| 550 | object : Dataset |
| 551 | Same object but with lazy data variables and coordinates as in-memory arrays. |
| 552 | |
| 553 | See Also |
| 554 | -------- |
| 555 | dask.compute |
| 556 | Dataset.compute |
| 557 | Dataset.load_async |
| 558 | DataArray.load |
| 559 | Variable.load |
| 560 | """ |
| 561 | # access .data to coerce everything to numpy or dask arrays |
| 562 | chunked_data = { |
| 563 | k: v._data for k, v in self.variables.items() if is_chunked_array(v._data) |
| 564 | } |
| 565 | if chunked_data: |
| 566 | chunkmanager = get_chunked_array_type(*chunked_data.values()) |
| 567 | |
| 568 | # evaluate all the chunked arrays simultaneously |
| 569 | evaluated_data: tuple[np.ndarray[Any, Any], ...] = chunkmanager.compute( |
| 570 | *chunked_data.values(), **kwargs |
| 571 | ) |
| 572 | |
| 573 | for k, data in zip(chunked_data, evaluated_data, strict=False): |
| 574 | self.variables[k].data = data |
| 575 | |
| 576 | # load everything else sequentially |
| 577 | [v.load() for k, v in self.variables.items() if k not in chunked_data] |
| 578 | |
| 579 | return self |
| 580 | |
| 581 | async def load_async(self, **kwargs) -> Self: |
| 582 | """Trigger and await asynchronous loading of data into memory and return this dataset. |