From ad40947573985a6763166175015d4fd534787b9a Mon Sep 17 00:00:00 2001 From: dcherian Date: Fri, 23 Jun 2023 11:50:48 -0600 Subject: [PATCH] small edits --- .../apply_ufunc/complex-output-numpy.ipynb | 12 ++++---- advanced/apply_ufunc/example-interp.ipynb | 2 +- .../apply_ufunc/simple_dask_apply_ufunc.ipynb | 4 ++- .../simple_numpy_apply_ufunc.ipynb | 29 +++++++++++++++++-- 4 files changed, 37 insertions(+), 10 deletions(-) diff --git a/advanced/apply_ufunc/complex-output-numpy.ipynb b/advanced/apply_ufunc/complex-output-numpy.ipynb index 3d6d8426..b259e74b 100644 --- a/advanced/apply_ufunc/complex-output-numpy.ipynb +++ b/advanced/apply_ufunc/complex-output-numpy.ipynb @@ -52,9 +52,13 @@ }, "outputs": [], "source": [ + "%xmode minimal\n", + "\n", "import xarray as xr\n", "import numpy as np\n", "\n", + "xr.set_options(display_expand_data=False)\n", + "\n", "air = (\n", " xr.tutorial.load_dataset(\"air_temperature\")\n", " .air.sortby(\"lat\") # np.interp needs coordinate in ascending order\n", @@ -157,6 +161,7 @@ "user_expressions": [] }, "source": [ + "(complex-output-change-size)=\n", "## Dimensions that change size\n", "\n", "Imagine that you want the output to have the same dimension name `\"lat\"` i.e. applying`np.interp` changes the size of the `\"lat\"` dimension.\n", @@ -175,9 +180,6 @@ }, "outputs": [], "source": [ - "# minimize error message\n", - "%xmode Minimal\n", - "\n", "newlat = np.linspace(15, 75, 100)\n", "\n", "xr.apply_ufunc(\n", @@ -187,9 +189,7 @@ " air,\n", " input_core_dims=[[\"lat\"], [\"lat\"], [\"lat\"]],\n", " output_core_dims=[[\"lat\"]],\n", - ")\n", - "\n", - "%xmode Context" + ")" ] }, { diff --git a/advanced/apply_ufunc/example-interp.ipynb b/advanced/apply_ufunc/example-interp.ipynb index 1fd9cec6..878aabcf 100644 --- a/advanced/apply_ufunc/example-interp.ipynb +++ b/advanced/apply_ufunc/example-interp.ipynb @@ -66,7 +66,7 @@ "import xarray as xr\n", "import numpy as np\n", "\n", - "xr.set_options(display_style=\"html\") # fancy HTML repr\n", + "xr.set_options(display_expand_data=False) # fancy HTML repr\n", "\n", "air = (\n", " xr.tutorial.load_dataset(\"air_temperature\")\n", diff --git a/advanced/apply_ufunc/simple_dask_apply_ufunc.ipynb b/advanced/apply_ufunc/simple_dask_apply_ufunc.ipynb index 5a7c2561..8dce84b7 100644 --- a/advanced/apply_ufunc/simple_dask_apply_ufunc.ipynb +++ b/advanced/apply_ufunc/simple_dask_apply_ufunc.ipynb @@ -35,7 +35,9 @@ "\n", "import dask\n", "import numpy as np\n", - "import xarray as xr" + "import xarray as xr\n", + "\n", + "xr.set_options(display_expand_data=False)" ] }, { diff --git a/advanced/apply_ufunc/simple_numpy_apply_ufunc.ipynb b/advanced/apply_ufunc/simple_numpy_apply_ufunc.ipynb index 287ea77b..a30982eb 100644 --- a/advanced/apply_ufunc/simple_numpy_apply_ufunc.ipynb +++ b/advanced/apply_ufunc/simple_numpy_apply_ufunc.ipynb @@ -305,7 +305,7 @@ "Such functions involve the concept of \"core dimensions\". \n", "\n", "```{important}\n", - "One way to think about core dimensions is to consider the smallest dimensionality of data necessary to apply the function.\n", + "One way to think about core dimensions is to consider the smallest dimensionality of data that the function acts on.\n", "```\n", "\n", "For using more complex operations that consider some array values collectively,\n", @@ -315,7 +315,9 @@ "that core dimensions are needed is the presence of an `axis` argument on the\n", "corresponding NumPy function.\n", "\n", - "Let's write a function that computes the mean along `time` for a provided xarray object. This function requires one core dimension `time`. For `ds.air` note that `time` is the 0th axis." + "Let's write a function that computes the mean along `time` for a provided xarray object. \n", + "\n", + "This function requires one core dimension `time`. For `ds.air` note that `time` is the 0th axis." ] }, { @@ -328,6 +330,29 @@ "ds.air.dims" ] }, + { + "cell_type": "markdown", + "id": "f8edcfd8-3307-4417-bc38-19bda89df8e1", + "metadata": { + "tags": [], + "user_expressions": [] + }, + "source": [ + "`get_axis_num` is a useful method." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8abba2b4-a011-4dd6-846a-c174fb674233", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "ds.air.get_axis_num(\"time\")" + ] + }, { "cell_type": "code", "execution_count": null,