Skip to content

Commit

Permalink
small edits
Browse files Browse the repository at this point in the history
  • Loading branch information
dcherian committed Jun 23, 2023
1 parent a31526a commit ad40947
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 10 deletions.
12 changes: 6 additions & 6 deletions advanced/apply_ufunc/complex-output-numpy.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -187,9 +189,7 @@
" air,\n",
" input_core_dims=[[\"lat\"], [\"lat\"], [\"lat\"]],\n",
" output_core_dims=[[\"lat\"]],\n",
")\n",
"\n",
"%xmode Context"
")"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion advanced/apply_ufunc/example-interp.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 3 additions & 1 deletion advanced/apply_ufunc/simple_dask_apply_ufunc.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
]
},
{
Expand Down
29 changes: 27 additions & 2 deletions advanced/apply_ufunc/simple_numpy_apply_ufunc.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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."
]
},
{
Expand All @@ -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,
Expand Down

0 comments on commit ad40947

Please sign in to comment.