Skip to content

Commit 8e539b0

Browse files
committed
indexing
1 parent 340d080 commit 8e539b0

File tree

1 file changed

+41
-11
lines changed

1 file changed

+41
-11
lines changed

intermediate/hierarchical_computation.ipynb

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,36 @@
8484
"cell_type": "markdown",
8585
"id": "6",
8686
"metadata": {},
87+
"source": [
88+
"## Indexing\n",
89+
"\n",
90+
"Just like arithmetic, indexing is simply forwarded to the node datasets. The only difference is that nodes that don't have a certain coordinate / dimension are skipped instead of raising an error:"
91+
]
92+
},
93+
{
94+
"cell_type": "code",
95+
"execution_count": null,
96+
"id": "7",
97+
"metadata": {},
98+
"outputs": [],
99+
"source": [
100+
"tree.isel(lat=slice(None, 10))"
101+
]
102+
},
103+
{
104+
"cell_type": "code",
105+
"execution_count": null,
106+
"id": "8",
107+
"metadata": {},
108+
"outputs": [],
109+
"source": [
110+
"tree.sel(time=\"2013-11\")"
111+
]
112+
},
113+
{
114+
"cell_type": "markdown",
115+
"id": "9",
116+
"metadata": {},
87117
"source": [
88118
"## Reductions\n",
89119
"\n",
@@ -93,7 +123,7 @@
93123
{
94124
"cell_type": "code",
95125
"execution_count": null,
96-
"id": "7",
126+
"id": "10",
97127
"metadata": {},
98128
"outputs": [],
99129
"source": [
@@ -102,7 +132,7 @@
102132
},
103133
{
104134
"cell_type": "markdown",
105-
"id": "8",
135+
"id": "11",
106136
"metadata": {},
107137
"source": [
108138
"## Applying functions designed for `Dataset` with `map_over_datasets`\n",
@@ -113,7 +143,7 @@
113143
{
114144
"cell_type": "code",
115145
"execution_count": null,
116-
"id": "9",
146+
"id": "12",
117147
"metadata": {},
118148
"outputs": [],
119149
"source": [
@@ -122,7 +152,7 @@
122152
},
123153
{
124154
"cell_type": "markdown",
125-
"id": "10",
155+
"id": "13",
126156
"metadata": {},
127157
"source": [
128158
"Note how the result is a empty `Dataset`?\n",
@@ -133,7 +163,7 @@
133163
{
134164
"cell_type": "code",
135165
"execution_count": null,
136-
"id": "11",
166+
"id": "14",
137167
"metadata": {},
138168
"outputs": [],
139169
"source": [
@@ -142,7 +172,7 @@
142172
},
143173
{
144174
"cell_type": "markdown",
145-
"id": "12",
175+
"id": "15",
146176
"metadata": {},
147177
"source": [
148178
"We can also use a custom function to perform more complex operations, like subtracting a group mean:"
@@ -151,7 +181,7 @@
151181
{
152182
"cell_type": "code",
153183
"execution_count": null,
154-
"id": "13",
184+
"id": "16",
155185
"metadata": {},
156186
"outputs": [],
157187
"source": [
@@ -161,7 +191,7 @@
161191
},
162192
{
163193
"cell_type": "markdown",
164-
"id": "14",
194+
"id": "17",
165195
"metadata": {},
166196
"source": [
167197
"Applying that to the dataset raises an error, though:"
@@ -170,7 +200,7 @@
170200
{
171201
"cell_type": "code",
172202
"execution_count": null,
173-
"id": "15",
203+
"id": "18",
174204
"metadata": {},
175205
"outputs": [],
176206
"source": [
@@ -179,7 +209,7 @@
179209
},
180210
{
181211
"cell_type": "markdown",
182-
"id": "16",
212+
"id": "19",
183213
"metadata": {},
184214
"source": [
185215
"The reason for this error is that the root node does not have any variables, and thus in particular no `\"time\"` coordinate. To avoid the error, we have to skip computing the function for that node:"
@@ -188,7 +218,7 @@
188218
{
189219
"cell_type": "code",
190220
"execution_count": null,
191-
"id": "17",
221+
"id": "20",
192222
"metadata": {},
193223
"outputs": [],
194224
"source": [

0 commit comments

Comments
 (0)