Skip to content

Commit 0c9b805

Browse files
committed
Update example to show selection along multiple dims.
1 parent 4a388e4 commit 0c9b805

File tree

1 file changed

+58
-1
lines changed

1 file changed

+58
-1
lines changed

doc/examples/introduction.ipynb

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,32 @@
8080
" (\"nlat\", \"nlon\"),\n",
8181
" np.ones((20, 30)) * 15,\n",
8282
" {\"coordinates\": \"TLONG TLAT\"},\n",
83-
")\n"
83+
")\n",
84+
"pop"
85+
]
86+
},
87+
{
88+
"cell_type": "markdown",
89+
"metadata": {},
90+
"source": [
91+
"This synthetic dataset has multiple `X` and `Y` coords. An example would be model output on a staggered grid."
92+
]
93+
},
94+
{
95+
"cell_type": "code",
96+
"execution_count": null,
97+
"metadata": {},
98+
"outputs": [],
99+
"source": [
100+
"multiple = xr.Dataset()\n",
101+
"multiple.coords[\"x1\"] = (\"x1\", range(30), {\"axis\": \"X\"})\n",
102+
"multiple.coords[\"y1\"] = (\"y1\", range(20), {\"axis\": \"Y\"})\n",
103+
"multiple.coords[\"x2\"] = (\"x2\", range(10), {\"axis\": \"X\"})\n",
104+
"multiple.coords[\"y2\"] = (\"y2\", range(5), {\"axis\": \"Y\"})\n",
105+
"\n",
106+
"multiple[\"v1\"] = ((\"x1\", \"y1\"), np.ones((30, 20)) * 15)\n",
107+
"multiple[\"v2\"] = ((\"x2\", \"y2\"), np.ones((10, 5)) * 15)\n",
108+
"multiple"
84109
]
85110
},
86111
{
@@ -148,6 +173,22 @@
148173
"pop.cf.describe()"
149174
]
150175
},
176+
{
177+
"cell_type": "markdown",
178+
"metadata": {},
179+
"source": [
180+
"For `multiple`, multiple `X` and `Y` coordinates are detected"
181+
]
182+
},
183+
{
184+
"cell_type": "code",
185+
"execution_count": null,
186+
"metadata": {},
187+
"outputs": [],
188+
"source": [
189+
"multiple.cf.describe()"
190+
]
191+
},
151192
{
152193
"cell_type": "markdown",
153194
"metadata": {},
@@ -245,6 +286,22 @@
245286
"ds.air.cf.isel(T=1)"
246287
]
247288
},
289+
{
290+
"cell_type": "markdown",
291+
"metadata": {},
292+
"source": [
293+
"Slicing works will expand a single key like `X` to multiple dimensions if those dimensions are tagged with `axis: X`"
294+
]
295+
},
296+
{
297+
"cell_type": "code",
298+
"execution_count": null,
299+
"metadata": {},
300+
"outputs": [],
301+
"source": [
302+
"multiple.cf.isel(X=1, Y=1)"
303+
]
304+
},
248305
{
249306
"cell_type": "markdown",
250307
"metadata": {},

0 commit comments

Comments
 (0)