.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plot_01_zone_plate.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_plot_01_zone_plate.py: Zone Plate ========== .. GENERATED FROM PYTHON SOURCE LINES 5-10 .. code-block:: Python # sphinx_gallery_thumbnail_number = 2 from __future__ import annotations .. GENERATED FROM PYTHON SOURCE LINES 11-19 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from matplotlib import ticker from curvelets.numpy import UDCT from curvelets.plot import create_colorbar, despine from curvelets.utils import make_zone_plate .. GENERATED FROM PYTHON SOURCE LINES 20-22 Setup ##### .. GENERATED FROM PYTHON SOURCE LINES 22-28 .. code-block:: Python shape = (256, 256) zone_plate = make_zone_plate(shape) cfg = np.array([[3, 3], [6, 6], [12, 6]]) C = UDCT(shape=shape, angular_wedges_config=cfg) .. GENERATED FROM PYTHON SOURCE LINES 29-31 Uniform Discrete Curvelet Transform Round Trip ############################################## .. GENERATED FROM PYTHON SOURCE LINES 31-35 .. code-block:: Python coeffs = C.forward(zone_plate) zone_plate_inv = C.backward(coeffs) .. GENERATED FROM PYTHON SOURCE LINES 36-47 .. code-block:: Python vmax = np.abs(zone_plate).max() opts = {"aspect": "equal", "cmap": "gray", "vmin": -vmax, "vmax": vmax} fig, ax = plt.subplots(figsize=(4, 3)) im = ax.imshow(zone_plate.T, **opts) _, cb = create_colorbar(im=im, ax=ax) fmt = ticker.FuncFormatter(lambda x, _: f"{x:.0e}") cb.ax.yaxis.set_major_formatter(fmt) despine(ax) ax.set(title="Input") .. image-sg:: /auto_examples/images/sphx_glr_plot_01_zone_plate_001.png :alt: Input :srcset: /auto_examples/images/sphx_glr_plot_01_zone_plate_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none [Text(0.5, 1.0, 'Input')] .. GENERATED FROM PYTHON SOURCE LINES 48-55 .. code-block:: Python fig, ax = plt.subplots(figsize=(4, 3)) im = ax.imshow(zone_plate_inv.T, **opts) _, cb = create_colorbar(im=im, ax=ax) cb.ax.yaxis.set_major_formatter(fmt) despine(ax) ax.set(title="UDCT Round Trip") .. image-sg:: /auto_examples/images/sphx_glr_plot_01_zone_plate_002.png :alt: UDCT Round Trip :srcset: /auto_examples/images/sphx_glr_plot_01_zone_plate_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none [Text(0.5, 1.0, 'UDCT Round Trip')] .. GENERATED FROM PYTHON SOURCE LINES 56-67 .. code-block:: Python opts["vmax"] = np.abs(zone_plate - zone_plate_inv).max() opts["vmin"] = -opts["vmax"] fig, ax = plt.subplots(figsize=(4, 3)) im = ax.imshow((zone_plate - zone_plate_inv).T, **opts) _, cb = create_colorbar(im=im, ax=ax) cb.ax.yaxis.set_major_formatter(fmt) despine(ax) ax.set(title=f"Error (max = {opts['vmax']:.2g})") print(f"Max Error: {opts['vmax']:.2g}") # noqa: T201 .. image-sg:: /auto_examples/images/sphx_glr_plot_01_zone_plate_003.png :alt: Error (max = 1.4e-15) :srcset: /auto_examples/images/sphx_glr_plot_01_zone_plate_003.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none Max Error: 1.4e-15 .. GENERATED FROM PYTHON SOURCE LINES 68-70 Curvelet Coefficients: Amplitude and Phase ########################################## .. GENERATED FROM PYTHON SOURCE LINES 70-115 .. code-block:: Python for ires, _ in enumerate(coeffs): for idir, _ in enumerate(coeffs[ires]): for iang, _ in enumerate(coeffs[ires][idir]): z = coeffs[ires][idir][iang] opts["vmax"] = np.abs(z).max() opts["vmin"] = 0 opts["cmap"] = "gray" fig, axs = plt.subplots(1, 2, figsize=(8, 3)) im = axs[0].imshow(np.abs(z).T, **opts) _, cb = create_colorbar(im=im, ax=axs[0]) fmt = ticker.FuncFormatter(lambda x, _: f"{x:.0e}") cb.ax.yaxis.set_major_formatter(fmt) opts["vmax"] = 180 opts["vmin"] = -opts["vmax"] opts["cmap"] = "hsv" im = axs[1].imshow(np.angle(z, deg=True).T, **opts) _, cb = create_colorbar(im=im, ax=axs[1]) cb.ax.yaxis.set_major_locator(ticker.MultipleLocator(45)) cb.ax.yaxis.set_major_formatter(lambda x, _: f"{x:.0f}°") axs[0].set(title="Amplitude") axs[1].set(title="Phase") fig.suptitle(f"Scale {ires} | Direction {idir} | Angle {iang}") fig.tight_layout() # # %% # # Curvelet Coefficients: Real and Imaginary # # ######################################### # opts["cmap"] = "gray" # for ires, _ in enumerate(coeffs): # for idir, _ in enumerate(coeffs[ires]): # for iang, _ in enumerate(coeffs[ires][idir]): # z = coeffs[ires][idir][iang] # opts["vmax"] = np.abs(z).max() # opts["vmin"] = -opts["vmax"] # fig, axs = plt.subplots(1, 2, figsize=(8, 3)) # for ax, img in zip(axs.ravel(), [z.real, z.imag]): # im = ax.imshow(img.T, **opts) # _, cb = create_colorbar(im=im, ax=ax) # fmt = ticker.FuncFormatter(lambda x, _: f"{x:.0e}") # cb.ax.yaxis.set_major_formatter(fmt) # axs[0].set(title="Real") # axs[1].set(title="Imaginary") # fig.suptitle(f"Scale {ires} | Direction {idir} | Angle {iang}") # fig.tight_layout() .. rst-class:: sphx-glr-horizontal * .. image-sg:: /auto_examples/images/sphx_glr_plot_01_zone_plate_004.png :alt: Scale 0 | Direction 0 | Angle 0, Amplitude, Phase :srcset: /auto_examples/images/sphx_glr_plot_01_zone_plate_004.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/images/sphx_glr_plot_01_zone_plate_005.png :alt: Scale 1 | Direction 0 | Angle 0, Amplitude, Phase :srcset: /auto_examples/images/sphx_glr_plot_01_zone_plate_005.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/images/sphx_glr_plot_01_zone_plate_006.png :alt: Scale 1 | Direction 0 | Angle 1, Amplitude, Phase :srcset: /auto_examples/images/sphx_glr_plot_01_zone_plate_006.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/images/sphx_glr_plot_01_zone_plate_007.png :alt: Scale 1 | Direction 0 | Angle 2, Amplitude, Phase :srcset: /auto_examples/images/sphx_glr_plot_01_zone_plate_007.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/images/sphx_glr_plot_01_zone_plate_008.png :alt: Scale 1 | Direction 1 | Angle 0, Amplitude, Phase :srcset: /auto_examples/images/sphx_glr_plot_01_zone_plate_008.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/images/sphx_glr_plot_01_zone_plate_009.png :alt: Scale 1 | Direction 1 | Angle 1, Amplitude, Phase :srcset: /auto_examples/images/sphx_glr_plot_01_zone_plate_009.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/images/sphx_glr_plot_01_zone_plate_010.png :alt: Scale 1 | Direction 1 | Angle 2, Amplitude, Phase :srcset: /auto_examples/images/sphx_glr_plot_01_zone_plate_010.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/images/sphx_glr_plot_01_zone_plate_011.png :alt: Scale 2 | Direction 0 | Angle 0, Amplitude, Phase :srcset: /auto_examples/images/sphx_glr_plot_01_zone_plate_011.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/images/sphx_glr_plot_01_zone_plate_012.png :alt: Scale 2 | Direction 0 | Angle 1, Amplitude, Phase :srcset: /auto_examples/images/sphx_glr_plot_01_zone_plate_012.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/images/sphx_glr_plot_01_zone_plate_013.png :alt: Scale 2 | Direction 0 | Angle 2, Amplitude, Phase :srcset: /auto_examples/images/sphx_glr_plot_01_zone_plate_013.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/images/sphx_glr_plot_01_zone_plate_014.png :alt: Scale 2 | Direction 0 | Angle 3, Amplitude, Phase :srcset: /auto_examples/images/sphx_glr_plot_01_zone_plate_014.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/images/sphx_glr_plot_01_zone_plate_015.png :alt: Scale 2 | Direction 0 | Angle 4, Amplitude, Phase :srcset: /auto_examples/images/sphx_glr_plot_01_zone_plate_015.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/images/sphx_glr_plot_01_zone_plate_016.png :alt: Scale 2 | Direction 0 | Angle 5, Amplitude, Phase :srcset: /auto_examples/images/sphx_glr_plot_01_zone_plate_016.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/images/sphx_glr_plot_01_zone_plate_017.png :alt: Scale 2 | Direction 1 | Angle 0, Amplitude, Phase :srcset: /auto_examples/images/sphx_glr_plot_01_zone_plate_017.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/images/sphx_glr_plot_01_zone_plate_018.png :alt: Scale 2 | Direction 1 | Angle 1, Amplitude, Phase :srcset: /auto_examples/images/sphx_glr_plot_01_zone_plate_018.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/images/sphx_glr_plot_01_zone_plate_019.png :alt: Scale 2 | Direction 1 | Angle 2, Amplitude, Phase :srcset: /auto_examples/images/sphx_glr_plot_01_zone_plate_019.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/images/sphx_glr_plot_01_zone_plate_020.png :alt: Scale 2 | Direction 1 | Angle 3, Amplitude, Phase :srcset: /auto_examples/images/sphx_glr_plot_01_zone_plate_020.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/images/sphx_glr_plot_01_zone_plate_021.png :alt: Scale 2 | Direction 1 | Angle 4, Amplitude, Phase :srcset: /auto_examples/images/sphx_glr_plot_01_zone_plate_021.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/images/sphx_glr_plot_01_zone_plate_022.png :alt: Scale 2 | Direction 1 | Angle 5, Amplitude, Phase :srcset: /auto_examples/images/sphx_glr_plot_01_zone_plate_022.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/images/sphx_glr_plot_01_zone_plate_023.png :alt: Scale 3 | Direction 0 | Angle 0, Amplitude, Phase :srcset: /auto_examples/images/sphx_glr_plot_01_zone_plate_023.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/images/sphx_glr_plot_01_zone_plate_024.png :alt: Scale 3 | Direction 0 | Angle 1, Amplitude, Phase :srcset: /auto_examples/images/sphx_glr_plot_01_zone_plate_024.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/images/sphx_glr_plot_01_zone_plate_025.png :alt: Scale 3 | Direction 0 | Angle 2, Amplitude, Phase :srcset: /auto_examples/images/sphx_glr_plot_01_zone_plate_025.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/images/sphx_glr_plot_01_zone_plate_026.png :alt: Scale 3 | Direction 0 | Angle 3, Amplitude, Phase :srcset: /auto_examples/images/sphx_glr_plot_01_zone_plate_026.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/images/sphx_glr_plot_01_zone_plate_027.png :alt: Scale 3 | Direction 0 | Angle 4, Amplitude, Phase :srcset: /auto_examples/images/sphx_glr_plot_01_zone_plate_027.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/images/sphx_glr_plot_01_zone_plate_028.png :alt: Scale 3 | Direction 0 | Angle 5, Amplitude, Phase :srcset: /auto_examples/images/sphx_glr_plot_01_zone_plate_028.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/images/sphx_glr_plot_01_zone_plate_029.png :alt: Scale 3 | Direction 1 | Angle 0, Amplitude, Phase :srcset: /auto_examples/images/sphx_glr_plot_01_zone_plate_029.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/images/sphx_glr_plot_01_zone_plate_030.png :alt: Scale 3 | Direction 1 | Angle 1, Amplitude, Phase :srcset: /auto_examples/images/sphx_glr_plot_01_zone_plate_030.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/images/sphx_glr_plot_01_zone_plate_031.png :alt: Scale 3 | Direction 1 | Angle 2, Amplitude, Phase :srcset: /auto_examples/images/sphx_glr_plot_01_zone_plate_031.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/images/sphx_glr_plot_01_zone_plate_032.png :alt: Scale 3 | Direction 1 | Angle 3, Amplitude, Phase :srcset: /auto_examples/images/sphx_glr_plot_01_zone_plate_032.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/images/sphx_glr_plot_01_zone_plate_033.png :alt: Scale 3 | Direction 1 | Angle 4, Amplitude, Phase :srcset: /auto_examples/images/sphx_glr_plot_01_zone_plate_033.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/images/sphx_glr_plot_01_zone_plate_034.png :alt: Scale 3 | Direction 1 | Angle 5, Amplitude, Phase :srcset: /auto_examples/images/sphx_glr_plot_01_zone_plate_034.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/images/sphx_glr_plot_01_zone_plate_035.png :alt: Scale 3 | Direction 1 | Angle 6, Amplitude, Phase :srcset: /auto_examples/images/sphx_glr_plot_01_zone_plate_035.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/images/sphx_glr_plot_01_zone_plate_036.png :alt: Scale 3 | Direction 1 | Angle 7, Amplitude, Phase :srcset: /auto_examples/images/sphx_glr_plot_01_zone_plate_036.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/images/sphx_glr_plot_01_zone_plate_037.png :alt: Scale 3 | Direction 1 | Angle 8, Amplitude, Phase :srcset: /auto_examples/images/sphx_glr_plot_01_zone_plate_037.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/images/sphx_glr_plot_01_zone_plate_038.png :alt: Scale 3 | Direction 1 | Angle 9, Amplitude, Phase :srcset: /auto_examples/images/sphx_glr_plot_01_zone_plate_038.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/images/sphx_glr_plot_01_zone_plate_039.png :alt: Scale 3 | Direction 1 | Angle 10, Amplitude, Phase :srcset: /auto_examples/images/sphx_glr_plot_01_zone_plate_039.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/images/sphx_glr_plot_01_zone_plate_040.png :alt: Scale 3 | Direction 1 | Angle 11, Amplitude, Phase :srcset: /auto_examples/images/sphx_glr_plot_01_zone_plate_040.png :class: sphx-glr-multi-img .. rst-class:: sphx-glr-script-out .. code-block:: none /home/docs/checkouts/readthedocs.org/user_builds/curvelets/checkouts/stable/examples/plot_01_zone_plate.py:77: RuntimeWarning: More than 20 figures have been opened. Figures created through the pyplot interface (`matplotlib.pyplot.figure`) are retained until explicitly closed and may consume too much memory. (To control this warning, see the rcParam `figure.max_open_warning`). Consider using `matplotlib.pyplot.close()`. fig, axs = plt.subplots(1, 2, figsize=(8, 3)) .. GENERATED FROM PYTHON SOURCE LINES 116-118 Curvelet Coefficients: Concatenated ######################################### .. GENERATED FROM PYTHON SOURCE LINES 118-139 .. code-block:: Python # coeffs_vec = C.vect(coeffs=coeffs) # coeffs_img = [] # for i in range(0, len(coeffs_vec) - zone_plate.size, zone_plate.size): # coeffs_img.append(coeffs_vec[i : i + zone_plate.size].reshape(1, *zone_plate.shape)) # if len(coeffs_vec) % zone_plate.size != 0: # coeffs_img.append(np.zeros((1, *zone_plate.shape), dtype=coeffs_vec.dtype)) # coeffs_img[-1].flat[ # len(coeffs_vec) - zone_plate.size : len(coeffs_vec) # ] = coeffs_vec[len(coeffs_vec) - zone_plate.size :] # coeffs_img = np.concatenate(coeffs_img, axis=0) _coeffs_vec = [] for c in coeffs[:2]: for d in c: for a in d: _coeffs_vec.append(a.ravel()) coeffs_vec = np.concatenate(_coeffs_vec) coeffs_img = np.zeros((1, *zone_plate.shape), dtype=coeffs_vec.dtype) coeffs_img.flat[: len(coeffs_vec)] = coeffs_vec[: len(coeffs_vec)] .. GENERATED FROM PYTHON SOURCE LINES 140-149 .. code-block:: Python fig, ax = plt.subplots(figsize=(12, 12)) opts["vmax"] = np.abs(coeffs_vec).max() opts["vmin"] = 0 opts["cmap"] = "gray" opts["aspect"] = "auto" im = ax.imshow(np.abs(np.concatenate(coeffs_img, axis=0))[:50, :].T, **opts) _, cb = create_colorbar(im=im, ax=ax) fmt = ticker.FuncFormatter(lambda x, _: f"{x:.0e}") cb.ax.yaxis.set_major_formatter(fmt) .. image-sg:: /auto_examples/images/sphx_glr_plot_01_zone_plate_041.png :alt: plot 01 zone plate :srcset: /auto_examples/images/sphx_glr_plot_01_zone_plate_041.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 8.137 seconds) .. _sphx_glr_download_auto_examples_plot_01_zone_plate.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_01_zone_plate.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_01_zone_plate.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_01_zone_plate.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_