From b2c8520739a862aee567a27261fcb690a064b9d1 Mon Sep 17 00:00:00 2001 From: Julia Signell Date: Tue, 27 Jun 2023 07:50:47 -0400 Subject: [PATCH] Clarify difference between compute and load in xarray example (#225) --- xarray.ipynb | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/xarray.ipynb b/xarray.ipynb index 8c0122d8..fb9bb316 100644 --- a/xarray.ipynb +++ b/xarray.ipynb @@ -132,7 +132,13 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Call `.compute()` or `.load()` when you want your result as a `xarray.DataArray` with data stored as NumPy arrays.\n", + "Call `.compute()` or `.load()` when you want your result as a `xarray.DataArray` with data stored as NumPy arrays. \n", + "\n", + "
\n", + " \n", + "NOTE: `load()` alters the DataArray inplace whereas `compute()` returns a new DataArray object.\n", + "\n", + "
\n", "\n", "If you started `Client()` above then you may want to watch the status page during computation." ] @@ -143,7 +149,7 @@ "metadata": {}, "outputs": [], "source": [ - "computed_da = da3.load()\n", + "computed_da = da3.compute()\n", "type(computed_da.data)" ] }, @@ -191,7 +197,8 @@ "metadata": {}, "outputs": [], "source": [ - "da.resample(time='1w').mean('time').std('time')" + "resampled_da = da.resample(time='1w').mean('time')\n", + "resampled_da.std('time')" ] }, { @@ -200,7 +207,7 @@ "metadata": {}, "outputs": [], "source": [ - "da.resample(time='1w').mean('time').std('time').load().plot(figsize=(12, 8))" + "resampled_da.std('time').plot(figsize=(12, 8))" ] }, { @@ -216,7 +223,7 @@ "metadata": {}, "outputs": [], "source": [ - "da_smooth = da.rolling(time=30).mean().persist()\n", + "da_smooth = da.rolling(time=30).mean()\n", "da_smooth" ] }, @@ -338,7 +345,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.12" + "version": "3.10.5" } }, "nbformat": 4,