From a660336f8e5b738c2700c889642470af22488f76 Mon Sep 17 00:00:00 2001 From: Ross Barnowski Date: Fri, 12 Jan 2024 15:11:51 -0800 Subject: [PATCH 1/8] Replace scipy.misc.face with scipy.datasets.face. --- content/tutorial-svd.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/content/tutorial-svd.md b/content/tutorial-svd.md index a1fe60a4..6912d7a4 100644 --- a/content/tutorial-svd.md +++ b/content/tutorial-svd.md @@ -35,12 +35,12 @@ After this tutorial, you should be able to: ## Content -In this tutorial, we will use a [matrix decomposition](https://en.wikipedia.org/wiki/Matrix_decomposition) from linear algebra, the Singular Value Decomposition, to generate a compressed approximation of an image. We'll use the `face` image from the [scipy.misc](https://docs.scipy.org/doc/scipy/reference/misc.html#module-scipy.misc) module: +In this tutorial, we will use a [matrix decomposition](https://en.wikipedia.org/wiki/Matrix_decomposition) from linear algebra, the Singular Value Decomposition, to generate a compressed approximation of an image. We'll use the `face` image from the [scipy.datasets](https://docs.scipy.org/doc/scipy/reference/datasets.html) module: ```{code-cell} -from scipy import misc +from scipy import datasets -img = misc.face() +img = datasets.face() ``` **Note**: If you prefer, you can use your own image as you work through this tutorial. In order to transform your image into a NumPy array that can be manipulated, you can use the `imread` function from the [matplotlib.pyplot](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.html#module-matplotlib.pyplot) submodule. Alternatively, you can use the [imageio.imread](https://imageio.readthedocs.io/en/stable/userapi.html#imageio.imread) function from the `imageio` library. Be aware that if you use your own image, you'll likely need to adapt the steps below. For more information on how images are treated when converted to NumPy arrays, see [A crash course on NumPy for images](https://scikit-image.org/docs/stable/user_guide/numpy_images.html) from the `scikit-image` documentation. @@ -91,7 +91,7 @@ img[:, :, 0] ``` From the output above, we can see that every value in `img[:, :, 0]` is an integer value between 0 and 255, representing the level of red in each corresponding image pixel (keep in mind that this might be different if you -use your own image instead of [scipy.misc.face](https://docs.scipy.org/doc/scipy/reference/generated/scipy.misc.face.html#scipy.misc.face)). +use your own image instead of [scipy.datasets.face](https://docs.scipy.org/doc/scipy/reference/generated/scipy.datasets.face.html)). As expected, this is a 768x1024 matrix: From 684a08a782883c2e277956c6c3bf28bc39af9e5e Mon Sep 17 00:00:00 2001 From: Ross Barnowski Date: Fri, 12 Jan 2024 15:12:24 -0800 Subject: [PATCH 2/8] Properly write ipython magic. --- content/save-load-arrays.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/save-load-arrays.md b/content/save-load-arrays.md index 434c7370..6768d938 100644 --- a/content/save-load-arrays.md +++ b/content/save-load-arrays.md @@ -127,7 +127,7 @@ print(load_xy.files) ``` ```{code-cell} -whos +%whos ``` ## Reassign the NpzFile arrays to `x` and `y` From 1dcfbf2c35121d7328b27dd5eaacdac003f8ed12 Mon Sep 17 00:00:00 2001 From: Ross Barnowski Date: Fri, 12 Jan 2024 15:15:16 -0800 Subject: [PATCH 3/8] Use string literals for LaTeX strings in fractals tutorial. --- content/tutorial-plotting-fractals.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/content/tutorial-plotting-fractals.md b/content/tutorial-plotting-fractals.md index e97b0cbe..373cd16f 100644 --- a/content/tutorial-plotting-fractals.md +++ b/content/tutorial-plotting-fractals.md @@ -301,14 +301,14 @@ For example, setting $c = \frac{\pi}{10}$ gives us a very elegant cloud shape, w ```{code-cell} ipython3 output = julia(mesh, c=np.pi/10, num_iter=20) -kwargs = {'title': 'f(z) = z^2 + \dfrac{\pi}{10}', 'cmap': 'plasma'} +kwargs = {'title': r'f(z) = z^2 + \dfrac{\pi}{10}', 'cmap': 'plasma'} plot_fractal(output, **kwargs); ``` ```{code-cell} ipython3 output = julia(mesh, c=-0.75 + 0.4j, num_iter=20) -kwargs = {'title': 'f(z) = z^2 - \dfrac{3}{4} + 0.4i', 'cmap': 'Greens_r'} +kwargs = {'title': r'f(z) = z^2 - \dfrac{3}{4} + 0.4i', 'cmap': 'Greens_r'} plot_fractal(output, **kwargs); ``` @@ -419,7 +419,7 @@ p.deriv() ```{code-cell} ipython3 output = newton_fractal(mesh, p, p.deriv(), num_iter=15, r=2) -kwargs = {'title': 'f(z) = z - \dfrac{(z^8 + 15z^4 - 16)}{(8z^7 + 60z^3)}', 'cmap': 'copper'} +kwargs = {'title': r'f(z) = z - \dfrac{(z^8 + 15z^4 - 16)}{(8z^7 + 60z^3)}', 'cmap': 'copper'} plot_fractal(output, **kwargs) ``` @@ -443,7 +443,7 @@ def d_tan(z): ```{code-cell} ipython3 output = newton_fractal(mesh, f_tan, d_tan, num_iter=15, r=50) -kwargs = {'title': 'f(z) = z - \dfrac{sin(z)cos(z)}{2}', 'cmap': 'binary'} +kwargs = {'title': r'f(z) = z - \dfrac{sin(z)cos(z)}{2}', 'cmap': 'binary'} plot_fractal(output, **kwargs); ``` From 5996bd6185b06ec0ebd18b49f64b6257d61de2bb Mon Sep 17 00:00:00 2001 From: Ross Barnowski Date: Fri, 12 Jan 2024 16:41:50 -0800 Subject: [PATCH 4/8] Add optional pooch dep for scipy.datasets. --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index 0ec30181..dd03cc89 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,7 @@ # For the tutorials numpy scipy +pooch # for scipy.datasets matplotlib pandas imageio From 8fed7137cba7233a1c702dbf769e72f24e53ef08 Mon Sep 17 00:00:00 2001 From: Ross Barnowski Date: Fri, 12 Jan 2024 16:50:08 -0800 Subject: [PATCH 5/8] Handle SyntaxWarnings from invalid escape sequences. --- content/tutorial-plotting-fractals.md | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/content/tutorial-plotting-fractals.md b/content/tutorial-plotting-fractals.md index 373cd16f..a1921cea 100644 --- a/content/tutorial-plotting-fractals.md +++ b/content/tutorial-plotting-fractals.md @@ -334,7 +334,7 @@ def mandelbrot(mesh, num_iter=10, radius=2): ```{code-cell} ipython3 output = mandelbrot(mesh, num_iter=50) -kwargs = {'title': 'Mandelbrot \ set', 'cmap': 'hot'} +kwargs = {'title': 'Mandelbrot \\ set', 'cmap': 'hot'} plot_fractal(output, **kwargs); ``` @@ -370,8 +370,6 @@ for deg, ax in enumerate(axes.ravel()): diverge_len = general_julia(mesh, f=power, num_iter=15) ax.imshow(diverge_len, extent=[-2, 2, -2, 2], cmap='binary') ax.set_title(f'$f(z) = z^{degree} -1$') - -fig.tight_layout(); ``` Needless to say, there is a large amount of exploring that can be done by fiddling with the inputted function, value of $c$, number of iterations, radius and even the density of the mesh and choice of colours. @@ -475,7 +473,7 @@ We will denote this one 'Wacky fractal', as its equation would not be fun to try ```{code-cell} ipython3 output = newton_fractal(small_mesh, sin_sum, d_sin_sum, num_iter=10, r=1) -kwargs = {'title': 'Wacky \ fractal', 'figsize': (6, 6), 'extent': [-1, 1, -1, 1], 'cmap': 'terrain'} +kwargs = {'title': 'Wacky \\ fractal', 'figsize': (6, 6), 'extent': [-1, 1, -1, 1], 'cmap': 'terrain'} plot_fractal(output, **kwargs) ``` @@ -550,7 +548,7 @@ def accident(z): ```{code-cell} ipython3 output = general_julia(mesh, f=accident, num_iter=15, c=0, radius=np.pi) -kwargs = {'title': 'Accidental \ fractal', 'cmap': 'Blues'} +kwargs = {'title': 'Accidental \\ fractal', 'cmap': 'Blues'} plot_fractal(output, **kwargs); ``` From 8382ba04130f14aafe140dde0dbf655a5054b0c9 Mon Sep 17 00:00:00 2001 From: Ross Barnowski Date: Fri, 12 Jan 2024 20:54:36 -0800 Subject: [PATCH 6/8] Add pooch to conda deps too. --- content/x_y-squared.npz | Bin 670 -> 670 bytes environment.yml | 1 + 2 files changed, 1 insertion(+) diff --git a/content/x_y-squared.npz b/content/x_y-squared.npz index 6c32f1968769df4a983cb5b1006af0279ba4f009..e32d05c4b91f4b6b67416452fcdb58203176b834 100644 GIT binary patch delta 89 zcmbQoI*(N Date: Fri, 19 Jan 2024 08:34:18 -0800 Subject: [PATCH 7/8] Try/except imports to deal with scipy datasets. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Brigitta Sipőcz --- content/tutorial-svd.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/content/tutorial-svd.md b/content/tutorial-svd.md index 6912d7a4..3798636a 100644 --- a/content/tutorial-svd.md +++ b/content/tutorial-svd.md @@ -38,9 +38,13 @@ After this tutorial, you should be able to: In this tutorial, we will use a [matrix decomposition](https://en.wikipedia.org/wiki/Matrix_decomposition) from linear algebra, the Singular Value Decomposition, to generate a compressed approximation of an image. We'll use the `face` image from the [scipy.datasets](https://docs.scipy.org/doc/scipy/reference/datasets.html) module: ```{code-cell} -from scipy import datasets +# TODO: Rm try-except with scipy 1.10 is the minimum supported version +try: + from scipy.datasets import face +except ImportError: # Data was in scipy.misc prior to scipy v1.10 + from scipy.misc import face -img = datasets.face() +img = face() ``` **Note**: If you prefer, you can use your own image as you work through this tutorial. In order to transform your image into a NumPy array that can be manipulated, you can use the `imread` function from the [matplotlib.pyplot](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.html#module-matplotlib.pyplot) submodule. Alternatively, you can use the [imageio.imread](https://imageio.readthedocs.io/en/stable/userapi.html#imageio.imread) function from the `imageio` library. Be aware that if you use your own image, you'll likely need to adapt the steps below. For more information on how images are treated when converted to NumPy arrays, see [A crash course on NumPy for images](https://scikit-image.org/docs/stable/user_guide/numpy_images.html) from the `scikit-image` documentation. From db5a326f43e7734262603bbd9277fbf651853b8c Mon Sep 17 00:00:00 2001 From: Ross Barnowski Date: Fri, 19 Jan 2024 20:26:13 -0800 Subject: [PATCH 8/8] Revert changes to npz data file. --- content/x_y-squared.npz | Bin 670 -> 670 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/content/x_y-squared.npz b/content/x_y-squared.npz index e32d05c4b91f4b6b67416452fcdb58203176b834..6c32f1968769df4a983cb5b1006af0279ba4f009 100644 GIT binary patch delta 68 zcmbQoI**k#z?+#xWU@Sy_(Yj6(jp8Hpva(;*pP4m$N^z41`&qJiSlbF-(YlM7GVad KHU-n+Ozr^S*bV0Z delta 89 zcmbQoI*(N