|
17 | 17 | "source": [
|
18 | 18 | "## Overview\n",
|
19 | 19 | "\n",
|
20 |
| - "In the previous notebooks, we learned basic forms of indexing with xarray (positional and name based dimensions, integer and label based indexing), Datetime Indexing, and nearest neighbor lookups. In this tutorial, we will lean how Xarray indexing is different from Numpy and how to do vectorized/pointwise indexing using Xarray. \n", |
| 20 | + "In the previous notebooks, we learned basic forms of indexing with xarray (positional and name based dimensions, integer and label based indexing), Datetime Indexing, and nearest neighbor lookups. In this tutorial, we will learn how Xarray indexing is different from Numpy and how to do vectorized/pointwise indexing using Xarray. \n", |
21 | 21 | "First, let's import packages needed for this repository: "
|
22 | 22 | ]
|
23 | 23 | },
|
|
107 | 107 | "da.sel(lat=target_lat, lon=target_lon, method=\"nearest\") # -- orthogonal indexing"
|
108 | 108 | ]
|
109 | 109 | },
|
| 110 | + { |
| 111 | + "cell_type": "code", |
| 112 | + "execution_count": null, |
| 113 | + "metadata": {}, |
| 114 | + "outputs": [], |
| 115 | + "source": [ |
| 116 | + "target_lat = xr.DataArray([31, 41, 42, 42], dims=\"degrees_north\")\n", |
| 117 | + "target_lon = xr.DataArray([200, 201, 202, 205], dims=\"degrees_east\")\n", |
| 118 | + "\n", |
| 119 | + "da.sel(lat=target_lat, lon=target_lon, method=\"nearest\") # -- orthogonal indexing" |
| 120 | + ] |
| 121 | + }, |
110 | 122 | {
|
111 | 123 | "cell_type": "markdown",
|
112 | 124 | "metadata": {},
|
|
229 | 241 | "```"
|
230 | 242 | ]
|
231 | 243 | },
|
232 |
| - { |
233 |
| - "cell_type": "markdown", |
234 |
| - "metadata": {}, |
235 |
| - "source": [ |
236 |
| - "Analogously, label-based pointwise-indexing is also possible by the `.sel()` method:" |
237 |
| - ] |
238 |
| - }, |
239 |
| - { |
240 |
| - "cell_type": "code", |
241 |
| - "execution_count": null, |
242 |
| - "metadata": { |
243 |
| - "tags": [] |
244 |
| - }, |
245 |
| - "outputs": [], |
246 |
| - "source": [ |
247 |
| - "da = xr.DataArray(\n", |
248 |
| - " np.random.rand(4, 3),\n", |
249 |
| - " [\n", |
250 |
| - " (\"time\", pd.date_range(\"2000-01-01\", periods=4)),\n", |
251 |
| - " (\"space\", [\"IA\", \"IL\", \"IN\"]),\n", |
252 |
| - " ],\n", |
253 |
| - ")\n", |
254 |
| - "times = xr.DataArray(pd.to_datetime([\"2000-01-03\", \"2000-01-02\", \"2000-01-01\"]), dims=\"new_time\")\n", |
255 |
| - "\n", |
256 |
| - "\n", |
257 |
| - "# -- get data for each state and each time:\n", |
258 |
| - "da.sel(space=xr.DataArray([\"IA\", \"IL\", \"IN\"], dims=[\"new_time\"]), time=times)" |
259 |
| - ] |
260 |
| - }, |
261 | 244 | {
|
262 | 245 | "cell_type": "markdown",
|
263 | 246 | "metadata": {},
|
|
0 commit comments