Skip to content

Commit da26b73

Browse files
authored
Bump to Jupyter Book v1.0 (#270)
* jbook1, drop sphinx-exercise * update exercise format * pin numpy<2
1 parent b8573b5 commit da26b73

19 files changed

+4604
-4415
lines changed

.prettierignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
conda/**
1+
conda/

_config.yml

-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ sphinx:
6868
# maintain old paths and redirect them (so google results dont go to 404)
6969
# https://github.com/wpilibsuite/sphinxext-rediraffe
7070
- sphinxext.rediraffe
71-
- sphinx_exercise
7271
config:
7372
language: en # accessibility
7473
# application/vnd.holoviews_load.v0+json, application/vnd.holoviews_exec.v0+json

advanced/apply_ufunc/automatic-vectorizing-numpy.ipynb

+6-7
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,17 @@
6363
" out[index, :] = np.interp(..., array[index, :], ...)\n",
6464
"```\n",
6565
"\n",
66-
"\n",
67-
"```{exercise}\n",
68-
":label: coreloopdims\n",
69-
"\n",
66+
"::::{admonition} Exercise\n",
67+
":class: tip\n",
7068
"Consider the example problem of interpolating a 2D array with dimensions `space` and `time` along the `time` dimension.\n",
7169
"Which dimension is the core dimension, and which is the \"loop dimension\"?\n",
72-
"```\n",
73-
"```{solution} coreloopdims\n",
70+
"\n",
71+
":::{admonition} Solution\n",
7472
":class: dropdown\n",
7573
"\n",
7674
"`time` is the core dimension, and `space` is the loop dimension.\n",
77-
"```\n",
75+
":::\n",
76+
"::::\n",
7877
"\n",
7978
"## Vectorization\n",
8079
"\n",

advanced/apply_ufunc/complex-output-numpy.ipynb

+12-11
Original file line numberDiff line numberDiff line change
@@ -138,19 +138,20 @@
138138
"tags": []
139139
},
140140
"source": [
141-
"```{exercise}\n",
142-
":label: newdim\n",
141+
"::::{admonition} Exercise\n",
142+
":class: tip\n",
143143
"\n",
144144
"Apply the following function using `apply_ufunc`. It adds a new dimension to the input array, let's call it `newdim`. Specify the new dimension using `output_core_dims`. Do you need any `input_core_dims`?\n",
145145
"\n",
146146
"```python\n",
147147
"def add_new_dim(array):\n",
148148
" return np.expand_dims(array, axis=-1)\n",
149149
"```\n",
150-
"````{solution} newdim\n",
150+
"\n",
151+
":::{admonition} Solution\n",
151152
":class: dropdown\n",
152153
"\n",
153-
"``` python\n",
154+
"```python\n",
154155
"def add_new_dim(array):\n",
155156
" return np.expand_dims(array, axis=-1)\n",
156157
"\n",
@@ -161,7 +162,8 @@
161162
" output_core_dims=[[\"newdim\"]],\n",
162163
")\n",
163164
"```\n",
164-
"````"
165+
":::\n",
166+
"::::"
165167
]
166168
},
167169
{
@@ -327,8 +329,8 @@
327329
"tags": []
328330
},
329331
"source": [
330-
"````{exercise}\n",
331-
":label: generalize\n",
332+
"::::{admonition} Exercise\n",
333+
":class: tip\n",
332334
"\n",
333335
"We presented the concept of \"core dimensions\" as the \"smallest unit of data the function could handle.\" Do you understand how the above use of `apply_ufunc` generalizes to an array with more than one dimension? \n",
334336
"\n",
@@ -337,9 +339,8 @@
337339
"air3d = xr.tutorial.load_dataset(\"air_temperature\").air)\n",
338340
"``` \n",
339341
"Your goal is to have a minimum and maximum value of temperature across all latitudes for a given time and longitude.\n",
340-
"````\n",
341342
"\n",
342-
"````{solution} generalize\n",
343+
":::{admonition} Solution\n",
343344
":class: dropdown\n",
344345
"\n",
345346
"We want to use `minmax` to compute the minimum and maximum along the \"lat\" dimension always, regardless of how many dimensions are on the input. So we specify `input_core_dims=[[\"lat\"]]`. The output does not contain the \"lat\" dimension, but we expect two returned variables. So we pass an empty list `[]` for each returned array, so `output_core_dims=[[], []]` just as before.\n",
@@ -352,8 +353,8 @@
352353
" input_core_dims=[[\"lat\"]],\n",
353354
" output_core_dims=[[],[]],\n",
354355
")\n",
355-
"```\n",
356-
"````"
356+
":::\n",
357+
"::::"
357358
]
358359
}
359360
],

advanced/apply_ufunc/core-dimensions.ipynb

+5-5
Original file line numberDiff line numberDiff line change
@@ -335,13 +335,12 @@
335335
"tags": []
336336
},
337337
"source": [
338-
"```{exercise}\n",
339-
":label: trapezoid\n",
338+
"::::{admonition} Exercise\n",
339+
":class: tip\n",
340340
"\n",
341341
"Use `apply_ufunc` to apply `scipy.integrate.trapezoid` along the `time` axis.\n",
342-
"```\n",
343342
"\n",
344-
"````{solution} trapezoid\n",
343+
":::{admonition} Solution\n",
345344
":class: dropdown\n",
346345
"\n",
347346
"```python\n",
@@ -350,7 +349,8 @@
350349
"\n",
351350
"xr.apply_ufunc(scipy.integrate.trapezoid, ds, input_core_dims=[[\"time\"]], kwargs={\"axis\": -1})\n",
352351
"```\n",
353-
"````"
352+
":::\n",
353+
"::::"
354354
]
355355
}
356356
],

advanced/apply_ufunc/dask_apply_ufunc.ipynb

+14-13
Original file line numberDiff line numberDiff line change
@@ -267,15 +267,15 @@
267267
"Such functions involve the concept of \"core dimensions\". This concept is independent of the underlying array type, and is a property of the applied function. See the [core dimensions with NumPy](core-dimensions) tutorial for more.\n",
268268
"\n",
269269
"\n",
270-
"```{exercise}\n",
271-
":label: daskmean\n",
270+
"::::{admonition} Exercise\n",
271+
":class: tip\n",
272272
"\n",
273273
"Use `dask.array.mean` as an example of a function that can handle dask\n",
274274
"arrays and uses an `axis` kwarg. \n",
275-
"```\n",
276275
"\n",
277-
"````{solution} daskmean\n",
276+
":::{admonition} Solution\n",
278277
":class: dropdown\n",
278+
"\n",
279279
"```python\n",
280280
"def time_mean(da):\n",
281281
" return xr.apply_ufunc(\n",
@@ -285,10 +285,11 @@
285285
" dask=\"allowed\",\n",
286286
" kwargs={\"axis\": -1}, # core dimensions are moved to the end\n",
287287
" )\n",
288-
"\n",
289-
"\n",
288+
" \n",
290289
"time_mean(ds.air)\n",
291-
"````\n"
290+
"```\n",
291+
":::\n",
292+
"::::\n"
292293
]
293294
},
294295
{
@@ -493,12 +494,11 @@
493494
"tags": []
494495
},
495496
"source": [
496-
"```{exercise} \n",
497-
":label: rechunk\n",
497+
"::::{admonition} Exercise\n",
498+
":class: tip\n",
498499
"Apply the integrate function to `ds` after rechunking to have a different chunksize along `lon` using `ds.chunk(lon=4)` (for example). What happens?\n",
499-
"```\n",
500500
"\n",
501-
"```{solution} rechunk\n",
501+
":::{admonition} Solution\n",
502502
":class: dropdown\n",
503503
"\n",
504504
"`apply_ufunc` complains that it cannot automatically parallelize because the dataset `ds` is now chunked along the core dimension `lon`. You should see the following error:\n",
@@ -509,7 +509,8 @@
509509
" ``.chunk(dict(lon=-1))``, or pass ``allow_rechunk=True`` in ``dask_gufunc_kwargs`` \n",
510510
" but beware that this may significantly increase memory usage.\n",
511511
"\n",
512-
"```"
512+
":::\n",
513+
"::::"
513514
]
514515
},
515516
{
@@ -652,7 +653,7 @@
652653
"source": [
653654
"### Adding new dimensions\n",
654655
"\n",
655-
"We use the [expand_dims example](newdim) that changes the size of the input along a single dimension.\n",
656+
"We use the `np.expand_dims` to change the size of the input along a single dimension.\n",
656657
"\n",
657658
"```python\n",
658659
"def add_new_dim(array):\n",

advanced/apply_ufunc/numba-vectorization.ipynb

+8-7
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
"tags": []
88
},
99
"source": [
10-
"<img src=\"https://numba.pydata.org/_static/numba-blue-horizontal-rgb.svg\" width=\"40%\" align=\"right\">\n",
10+
"# Fast vectorization with Numba\n",
1111
"\n",
12-
"# Fast vectorization with Numba"
12+
"<img src=\"https://numba.pydata.org/_static/numba-blue-horizontal-rgb.svg\" width=\"40%\" align=\"right\">"
1313
]
1414
},
1515
{
@@ -241,12 +241,12 @@
241241
"id": "18",
242242
"metadata": {},
243243
"source": [
244-
"```{exercise}\n",
245-
":label: g\n",
244+
"::::{admonition} Exercise\n",
245+
":class: tip\n",
246246
"\n",
247247
"Apply `g` to `da_dask`\n",
248-
"```\n",
249-
"````{solution} g\n",
248+
"\n",
249+
":::{admonition} Solution\n",
250250
":class: dropdown\n",
251251
"\n",
252252
"```python\n",
@@ -259,7 +259,8 @@
259259
" dask=\"parallelized\",\n",
260260
")\n",
261261
"```\n",
262-
"````"
262+
":::\n",
263+
"::::"
263264
]
264265
},
265266
{

0 commit comments

Comments
 (0)