From 48ee34d2319aa68a319a3d2994ae6b3ee1d71a13 Mon Sep 17 00:00:00 2001 From: Scott Henderson Date: Fri, 17 Jun 2022 15:31:43 -0700 Subject: [PATCH 1/2] try out sphinx-exercise --- _config.yml | 3 ++ fundamentals/02.3_aligning_data_objects.ipynb | 35 ++++++++++++++++--- 2 files changed, 34 insertions(+), 4 deletions(-) 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/fundamentals/02.3_aligning_data_objects.ipynb b/fundamentals/02.3_aligning_data_objects.ipynb index ba1c3a6b..5d9ddd27 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", + "```" ] }, { @@ -403,12 +409,33 @@ { "cell_type": "markdown", "metadata": { + "jupyter": { + "source_hidden": true + }, + "tags": [] + }, + "source": [ + "```{exercise-end}\n", + "```" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "jupyter": { + "source_hidden": true + }, "tags": [ "hide-input" ] }, "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." + "```{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 +537,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.12" + "version": "3.10.5" }, "widgets": { "application/vnd.jupyter.widget-state+json": { From 0ce4fe8784da5de325c7b1d057cfbcad134f0890 Mon Sep 17 00:00:00 2001 From: Scott Henderson Date: Fri, 17 Jun 2022 15:43:23 -0700 Subject: [PATCH 2/2] small cleanup, add pip package --- conda/environment-unpinned.yml | 3 +++ fundamentals/02.3_aligning_data_objects.ipynb | 22 +++++-------------- 2 files changed, 8 insertions(+), 17 deletions(-) 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 5d9ddd27..e59a2772 100644 --- a/fundamentals/02.3_aligning_data_objects.ipynb +++ b/fundamentals/02.3_aligning_data_objects.ipynb @@ -384,7 +384,7 @@ "```{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", + "Consider the following two arrays. Write down the `x` and `y` coordinate locations for `da1 - da2`\n", "```" ] }, @@ -394,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", @@ -409,27 +410,14 @@ { "cell_type": "markdown", "metadata": { - "jupyter": { - "source_hidden": true - }, - "tags": [] - }, - "source": [ - "```{exercise-end}\n", - "```" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "jupyter": { - "source_hidden": true - }, "tags": [ "hide-input" ] }, "source": [ + "```{exercise-end}\n", + "```\n", + "\n", "```{solution} exercise-alignment\n", ":label: solution-alignment\n", ":class: dropdown\n",