diff --git a/_config.yml b/_config.yml index 00ef7d47..c2009490 100644 --- a/_config.yml +++ b/_config.yml @@ -60,3 +60,6 @@ bibtex_bibfiles: sphinx: config: bibtex_reference_style: author_year # or label, super, \supercite + extra_extensions: + - sphinx_exercise + - sphinx_togglebutton diff --git a/conda/environment-unpinned.yml b/conda/environment-unpinned.yml index debfa290..c4c36824 100644 --- a/conda/environment-unpinned.yml +++ b/conda/environment-unpinned.yml @@ -21,6 +21,7 @@ dependencies: - hvplot - matplotlib-base - netcdf4 + - pip - pint-xarray - pydap - python-graphviz @@ -29,3 +30,5 @@ dependencies: - scipy - xarray - zarr + - pip: + - sphinx-exercise diff --git a/fundamentals/02.3_aligning_data_objects.ipynb b/fundamentals/02.3_aligning_data_objects.ipynb index ba1c3a6b..e59a2772 100644 --- a/fundamentals/02.3_aligning_data_objects.ipynb +++ b/fundamentals/02.3_aligning_data_objects.ipynb @@ -377,9 +377,15 @@ }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "tags": [] + }, "source": [ - "**Exercise** Consider the following two arrays. Write down the `x` and `y` coordinate locations for `da1 - da2`" + "```{exercise-start}\n", + ":label: exercise-alignment\n", + "\n", + "Consider the following two arrays. Write down the `x` and `y` coordinate locations for `da1 - da2`\n", + "```" ] }, { @@ -388,6 +394,7 @@ "metadata": {}, "outputs": [], "source": [ + "# This code cell is executed by jupyterbook\n", "da1 = xr.DataArray(\n", " np.arange(12).reshape(3, 4),\n", " dims=(\"x\", \"y\"),\n", @@ -408,7 +415,15 @@ ] }, "source": [ - "**Answer** `x = [\"b\"], y=[0, 1, 2, 3]` . `da2` has been broadcasted to 2D (so dimension \"y\" has been inserted) and the two arrays are aligned using `join=\"inner\"` prior to subtraction." + "```{exercise-end}\n", + "```\n", + "\n", + "```{solution} exercise-alignment\n", + ":label: solution-alignment\n", + ":class: dropdown\n", + "\n", + "`x = [\"b\"], y=[0, 1, 2, 3]` . `da2` has been broadcasted to 2D (so dimension \"y\" has been inserted) and the two arrays are aligned using `join=\"inner\"` prior to subtraction.\n", + "```" ] }, { @@ -510,7 +525,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.12" + "version": "3.10.5" }, "widgets": { "application/vnd.jupyter.widget-state+json": {