Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tiled layout w/ images for front page #123

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added content/_static/fractal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 19 additions & 9 deletions content/mooreslaw-tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -331,19 +331,29 @@ https://fivethirtyeight.com elements. Change the matplotlib style with
transistor_count_predicted = np.exp(B) * np.exp(A * year)
transistor_Moores_law = Moores_law(year)
plt.style.use("fivethirtyeight")
plt.semilogy(year, transistor_count, "s", label="MOS transistor count")
plt.semilogy(year, transistor_count_predicted, label="linear regression")
fig, ax = plt.subplots()
ax.semilogy(year, transistor_count, "s", label="MOS transistor count")
ax.semilogy(year, transistor_count_predicted, label="linear regression")


plt.plot(year, transistor_Moores_law, label="Moore's Law")
plt.title(
ax.plot(year, transistor_Moores_law, label="Moore's Law")
ax.set_title(
"MOS transistor count per microprocessor\n"
+ "every two years \n"
+ "Transistor count was x{:.2f} higher".format(np.exp(A * 2))
"every two years\n"
"Transistor count was x{:.2f} higher".format(np.exp(A * 2))
)
plt.xlabel("year introduced")
plt.legend(loc="center left", bbox_to_anchor=(1, 0.5))
plt.ylabel("# of transistors\nper microprocessor")
ax.legend(loc="center left", bbox_to_anchor=(1, 0.5))
ax.set_xlabel("year introduced")
ax.set_ylabel("# of transistors\nper microprocessor")
```

```{code-cell} ipython3
---
tags: [remove-cell]
---
# Create tutorial thumbnail
from myst_nb import glue
glue("thumb_mooreslaw", fig, display=False)
```

_A scatter plot of MOS transistor count per microprocessor every two years with a red line for the ordinary least squares prediction and an orange line for Moore's law._
Expand Down
12 changes: 11 additions & 1 deletion content/tutorial-deep-learning-on-mnist.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,19 @@ num_examples = 5
seed = 147197952744
rng = np.random.default_rng(seed)

fig, axes = plt.subplots(1, num_examples)
fig, axes = plt.subplots(1, num_examples, figsize=(15, 3))
for sample, ax in zip(rng.choice(x_train, size=num_examples, replace=False), axes):
ax.imshow(sample.reshape(28, 28), cmap="gray")
ax.axis("off")
```

```{code-cell} ipython3
---
tags: [remove-cell]
---
# Create tutorial thumbnail
from myst_nb import glue
glue("thumb_mnist", fig, display=False)
```

_Above are five images taken from the MNIST training set. Various hand-drawn
Expand Down
29 changes: 20 additions & 9 deletions content/tutorial-ma.md
Original file line number Diff line number Diff line change
Expand Up @@ -278,16 +278,27 @@ This plot is not so readable since the lines seem to be over each other, so let'
available, and show the cubic fit for unavailable data, using this fit to compute an estimate to the observed number of cases on January 28th 2020, 7 days after the beginning of the records:

```{code-cell}
plt.plot(t, china_total)
plt.plot(t[china_total.mask], cubic_fit[china_total.mask], "--", color="orange")
plt.plot(7, np.polyval(params, 7), "r*")
plt.xticks([0, 7, 13], dates[[0, 7, 13]])
plt.yticks([0, np.polyval(params, 7), 10000, 17500])
plt.legend(["Mainland China", "Cubic estimate", "7 days after start"])
plt.title(
"COVID-19 cumulative cases from Jan 21 to Feb 3 2020 - Mainland China\n"
"Cubic estimate for 7 days after start"
fig, ax = plt.subplots()
ax.plot(t, china_total)
ax.plot(t[china_total.mask], cubic_fit[china_total.mask], "--", color="orange")
ax.plot(7, np.polyval(params, 7), "r*")
ax.set_xticks([0, 7, 13], dates[[0, 7, 13]])
ax.set_yticks([0, np.polyval(params, 7), 10000, 17500])
ax.legend(["Mainland China", "Cubic estimate", "7 days after start"])
ax.set_title(
"COVID-19 cumulative cases from Jan 21 to Feb 3 2020\n"
"Mainland China Cubic estimate for 7 days after start"
)
fig.tight_layout()
```

```{code-cell}
---
tags: [remove-cell]
---
# Create a thumbnail for the notebook
from myst_nb import glue
glue("thumb_ma", fig, display=False)
```

## In practice
Expand Down
2 changes: 1 addition & 1 deletion content/tutorial-plotting-fractals.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ kernelspec:

+++

![Fractal picture](tutorial-plotting-fractals/fractal.png)
![Fractal picture](_static/fractal.png)

+++

Expand Down
Binary file removed content/tutorial-plotting-fractals/fractal.png
Binary file not shown.
16 changes: 13 additions & 3 deletions content/tutorial-static_equilibrium.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ Quiver plots will be used to demonstrate [three dimensional vectors](https://mat
```{code-cell}
fig = plt.figure()

d3 = fig.gca(projection="3d")
d3 = fig.add_subplot(111, projection="3d")

d3.set_xlim(-1, 1)
d3.set_ylim(-1, 1)
Expand All @@ -96,7 +96,7 @@ d3.quiver(x, y, z, u, v, w, color="r", label="forceA")
u, v, w = forceB
d3.quiver(x, y, z, u, v, w, color="b", label="forceB")

plt.legend()
d3.legend()
plt.show()
```

Expand All @@ -113,7 +113,7 @@ You can plot it to see the result.
```{code-cell}
fig = plt.figure()

d3 = fig.gca(projection="3d")
d3 = fig.add_subplot(111, projection="3d")

d3.set_xlim(-1, 1)
d3.set_ylim(-1, 1)
Expand All @@ -132,6 +132,16 @@ plt.legend()
plt.show()
```

```{code-cell} ipython3
---
tags: [remove-cell]
---
# Create thumbnail for tutorial
from myst_nb import glue
glue("thumb_static_eq", fig, display=False);
```


However, the goal is equilibrium.
This means that you want your sum of forces to be $(0, 0, 0)$ or else your object will experience acceleration.
Therefore, there needs to be another force that counteracts the prior ones.
Expand Down
22 changes: 21 additions & 1 deletion content/tutorial-svd.md
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,8 @@ approx_img.shape
which is not the right shape for showing the image. Finally, reordering the axes back to our original shape of `(768, 1024, 3)`, we can see our approximation:

```{code-cell}
plt.imshow(np.transpose(approx_img, (1, 2, 0)))
fig, ax = plt.subplots()
ax.imshow(np.transpose(approx_img, (1, 2, 0)))
plt.show()
```

Expand All @@ -382,3 +383,22 @@ terms of the norm of the difference. For more information, see *G. H. Golub and
- [SciPy Tutorial](https://docs.scipy.org/doc/scipy/reference/tutorial/index.html)
- [SciPy Lecture Notes](https://scipy-lectures.org)
- [A matlab, R, IDL, NumPy/SciPy dictionary](http://mathesaurus.sf.net/)

```{code-cell} ipython3
---
tags: [remove-cell]
---
# Create notebook thumbnail
from myst_nb import glue
fig, ax = plt.subplots(1, 2)
for a, im, ttl in zip(
ax,
(img_array, approx_img.transpose(1, 2, 0)),
("Original", f"Reconstructed from\n{k} principal components"),
):
a.imshow(im)
a.set_title(ttl)
a.axis("off")
fig.tight_layout()
glue("thumb_svd", fig, display=False)
```
24 changes: 18 additions & 6 deletions content/tutorial-x-ray-image-processing.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,15 +234,27 @@ Display the original X-ray and the one with the Laplacian-Gaussian filter:
```{code-cell}
fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(10, 10))

axes[0].set_title("Original")
axes[0].imshow(xray_image, cmap="gray")
axes[1].set_title("Laplacian-Gaussian (edges)")
axes[1].imshow(xray_image_laplace_gaussian, cmap="gray")
for i in axes:
i.axis("off")
for ax, img, title in zip(
axes,
(xray_image, xray_image_laplace_gaussian),
("Original", "Laplacian-Gaussian (edges)"),
):
ax.imshow(img, cmap="gray")
ax.set_title(title)
ax.axis("off")
fig.tight_layout()
plt.show()
```

```{code-cell} ipython3
---
tags: [remove-cell]
---
# Create tutorial thumbnail
from myst_nb import glue
glue("thumb_xray", fig, display=False)
```

### The Gaussian gradient magnitude method

Another method for edge detection that can be useful is the
Expand Down
1 change: 1 addition & 0 deletions site/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
extensions = [
'myst_nb',
'sphinx_copybutton',
'sphinx_panels',
]

# Add any paths that contain templates here, relative to this directory.
Expand Down
33 changes: 33 additions & 0 deletions site/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,39 @@ Remember to clear all outputs on your notebook before uploading it.
🎉 <b>Wait for review!</b>
</ul>

### Adding a tutorial thumbnail

You may add a thumbnail to the front page of the tutorials site with the
following procedure:

1. In `index.md`, find the `panels` directive for your tutorial's category
(e.g. `NumPy Features` or `NumPy Applications`). The `panels` directive
begins with ````` ````{panels}```` `````.
2. Add a new card to the bottom of the `panels`:

```
---

{doc}`<path-to-tutorial>`

+++

<thumbnail_img>
```

Where `<path-to-tutorial>` should be replaced with the path to the tutorial
(typically `content/<filename.md>`) and <thumbnail_img> should be replaced
with the image you'd like to use as the thumbnail.

This can either be a static image, in which case traditional markdown image
syntax will work, or a figure generated during the execution of your
tutorial. In the latter case, use [the glue feature of myst-nb][myst_nb_glue].

[myst_nb_glue]: https://myst-nb.readthedocs.io/en/latest/use/glue.html

Don't worry if you get stuck - a reviewer/maintainer can help with the
process of creating a thumbnail for your tutorial.

For more information about GitHub and its workflow, you can see
[this document][collab].

Expand Down
112 changes: 109 additions & 3 deletions site/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,124 @@ local copy of the `.ipynb` files, you can either
[clone this repository](https://docs.github.com/en/github/creating-cloning-and-archiving-repositories/cloning-a-repository)
or use the download icon in the upper-right corner of each tutorial.

## Content

```{toctree}
---
maxdepth: 2
hidden: true
---

features
applications
contributing
```

## NumPy Features

````{panels}

{doc}`content/tutorial-svd`
^^^^^^^^^^^^^^^^^^^^^^^^^^^

```{glue:} thumb_svd
```

+++

{badge}`numpy.linalg, badge-primary`

---

{doc}`content/tutorial-ma`
^^^^^^^^^^^^^^^^^^^^^^^^^^

```{glue:} thumb_ma
```

+++

{badge}`numpy.ma, badge-primary`
{badge}`numpy.polynomial, badge-primary`

---

{doc}`content/save-load-arrays`
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

![Default thumbnail: NumPy logo](_static/numpylogo.svg)

+++

{badge}`I/O, badge-primary`
````

## NumPy Applications

````{panels}

{doc}`content/mooreslaw-tutorial`
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

```{glue:} thumb_mooreslaw
```

---

{doc}`content/tutorial-deep-learning-on-mnist`
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

```{glue:} thumb_mnist
```

---

{doc}`content/tutorial-deep-reinforcement-learning-with-pong-from-pixels`
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

![Diagram showing the component operations of reinforcement learning detailed
in this tutorial](content/_static/tutorial-deep-reinforcement-learning-with-pong-from-pixels.png)

---

{doc}`content/tutorial-nlp-from-scratch`
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

![Overview of the model architecture, showing a series of animated boxes.
There are five identical boxes labeled A and receiving as input one of the
words in the phrase "life's a box of chocolates". Each box is highlighted in
turn, representing the memory blocks of the LSTM network as information passes
through them, ultimately reaching a "Positive" output value.](content/_static/lstm.gif)

---

{doc}`content/tutorial-x-ray-image-processing`
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

```{glue:} thumb_xray
```

---

{doc}`content/tutorial-static_equilibrium`
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

```{glue:} thumb_static_eq
```

---

{doc}`content/tutorial-plotting-fractals`
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

![An example of a fractal visualization from this tutorial](content/_static/fractal.png)

---

{doc}`content/tutorial-air-quality-analysis`
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

![A grid showing the India Gate in smog above and clear air below](content/_static/11-delhi-aqi.jpg)

````

## Useful links and resources

The following links may be useful:
Expand Down
1 change: 1 addition & 0 deletions site/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ sphinx
myst-nb
sphinx-book-theme
sphinx-copybutton
sphinx-panels