.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/plot_curvelets_in_fk.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_gallery_plot_curvelets_in_fk.py: 4. Curvelet Coefficients in the FK domain ========================================= This example shows the regions in the FK domain where each curvelet coefficient occupies. .. GENERATED FROM PYTHON SOURCE LINES 7-9 .. code-block:: default # sphinx_gallery_thumbnail_number = 5 .. GENERATED FROM PYTHON SOURCE LINES 10-16 .. code-block:: default import matplotlib as mpl import matplotlib.pyplot as plt import numpy as np from curvelops import FDCT2D .. GENERATED FROM PYTHON SOURCE LINES 17-19 Setup ===== .. GENERATED FROM PYTHON SOURCE LINES 21-24 .. code-block:: default nx, nz = 301, 201 data_empty = np.zeros((nx, nz)) .. GENERATED FROM PYTHON SOURCE LINES 25-29 .. code-block:: default nbscales = 4 nbangles_coarse = 8 allcurvelets = False .. GENERATED FROM PYTHON SOURCE LINES 30-37 .. code-block:: default Cop = FDCT2D( data_empty.shape, nbscales=nbscales, nbangles_coarse=nbangles_coarse, allcurvelets=allcurvelets, ) .. GENERATED FROM PYTHON SOURCE LINES 38-44 .. code-block:: default empty_fdct = Cop @ data_empty # Convert to a curvelet struct indexed by # [scale, wedge (angle), z, x] empty_fdct_struct = Cop.struct(empty_fdct) .. GENERATED FROM PYTHON SOURCE LINES 45-61 .. code-block:: default def create_dirac_wedge(Cop, scale, wedge): d = np.zeros(Cop.dims) wedge_only_fdct = Cop @ d wedge_only_fdct_struct = Cop.struct(wedge_only_fdct) normalization = np.sqrt(wedge_only_fdct_struct[scale][wedge].size) iz, ix = wedge_only_fdct_struct[scale][wedge].shape wedge_only_fdct_struct[scale][wedge][iz // 2, ix // 2] = normalization wedge_only_fdct = Cop.vect(wedge_only_fdct_struct) wedge_only = Cop.H @ wedge_only_fdct return wedge_only .. GENERATED FROM PYTHON SOURCE LINES 62-64 Plot Wedges of each Scale ========================= .. GENERATED FROM PYTHON SOURCE LINES 66-67 Colormap to be used in all plots below .. GENERATED FROM PYTHON SOURCE LINES 67-77 .. code-block:: default fig, ax = plt.subplots(figsize=(6, 1)) col_map = plt.get_cmap("turbo") mpl.colorbar.ColorbarBase( ax, cmap=col_map, orientation="horizontal", norm=mpl.colors.Normalize(vmin=0, vmax=1), ) fig.tight_layout() .. image-sg:: /gallery/images/sphx_glr_plot_curvelets_in_fk_001.png :alt: plot curvelets in fk :srcset: /gallery/images/sphx_glr_plot_curvelets_in_fk_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 78-117 .. code-block:: default wedge_fk_abs = np.zeros_like(data_empty) for j, fdct_scale in enumerate(empty_fdct_struct, start=1): rows = int(np.floor(np.sqrt(len(fdct_scale)))) fig, axes = plt.subplots( int(np.ceil(len(fdct_scale) / rows)), rows, figsize=(5 * rows, 3 * rows), ) fig.suptitle( f"Scale {j} ({len(fdct_scale)} wedge{'s' if len(fdct_scale) > 1 else ''})" ) axes = np.atleast_1d(axes).ravel() wedge_scale_fk_abs = np.zeros_like(data_empty) for iw, (fdct_wedge, ax) in enumerate(zip(fdct_scale, axes), start=1): dirac_wedge = create_dirac_wedge(Cop, j - 1, iw - 1) dirac_wedge_fk = np.fft.fftshift( np.fft.fft2(np.fft.ifftshift(dirac_wedge), norm="ortho") ) wedge_scale_fk_abs += np.abs(dirac_wedge_fk) ax.imshow(np.abs(dirac_wedge_fk).T, cmap="turbo", vmin=0, vmax=1) if len(fdct_scale) > 1: ax.set(title=f"Wedge {iw}") ax.axis("off") fig.tight_layout() wedge_fk_abs += wedge_scale_fk_abs if len(fdct_scale) > 1: fig, ax = plt.subplots(figsize=(5, 3)) fig.suptitle(f"Scale {j} (sum of all wedges)") ax.imshow(wedge_scale_fk_abs.T, cmap="turbo", vmin=0, vmax=1) ax.axis("off") fig.tight_layout() fig, ax = plt.subplots(figsize=(5, 3)) fig.suptitle("Sum of all wedges of all scales)") ax.imshow(wedge_fk_abs.T, cmap="turbo", vmin=0, vmax=1) ax.axis("off") fig.tight_layout() .. rst-class:: sphx-glr-horizontal * .. image-sg:: /gallery/images/sphx_glr_plot_curvelets_in_fk_002.png :alt: Scale 1 (1 wedge) :srcset: /gallery/images/sphx_glr_plot_curvelets_in_fk_002.png :class: sphx-glr-multi-img * .. image-sg:: /gallery/images/sphx_glr_plot_curvelets_in_fk_003.png :alt: Scale 2 (8 wedges), Wedge 1, Wedge 2, Wedge 3, Wedge 4, Wedge 5, Wedge 6, Wedge 7, Wedge 8 :srcset: /gallery/images/sphx_glr_plot_curvelets_in_fk_003.png :class: sphx-glr-multi-img * .. image-sg:: /gallery/images/sphx_glr_plot_curvelets_in_fk_004.png :alt: Scale 2 (sum of all wedges) :srcset: /gallery/images/sphx_glr_plot_curvelets_in_fk_004.png :class: sphx-glr-multi-img * .. image-sg:: /gallery/images/sphx_glr_plot_curvelets_in_fk_005.png :alt: Scale 3 (16 wedges), Wedge 1, Wedge 2, Wedge 3, Wedge 4, Wedge 5, Wedge 6, Wedge 7, Wedge 8, Wedge 9, Wedge 10, Wedge 11, Wedge 12, Wedge 13, Wedge 14, Wedge 15, Wedge 16 :srcset: /gallery/images/sphx_glr_plot_curvelets_in_fk_005.png :class: sphx-glr-multi-img * .. image-sg:: /gallery/images/sphx_glr_plot_curvelets_in_fk_006.png :alt: Scale 3 (sum of all wedges) :srcset: /gallery/images/sphx_glr_plot_curvelets_in_fk_006.png :class: sphx-glr-multi-img * .. image-sg:: /gallery/images/sphx_glr_plot_curvelets_in_fk_007.png :alt: Scale 4 (1 wedge) :srcset: /gallery/images/sphx_glr_plot_curvelets_in_fk_007.png :class: sphx-glr-multi-img * .. image-sg:: /gallery/images/sphx_glr_plot_curvelets_in_fk_008.png :alt: Sum of all wedges of all scales) :srcset: /gallery/images/sphx_glr_plot_curvelets_in_fk_008.png :class: sphx-glr-multi-img .. GENERATED FROM PYTHON SOURCE LINES 118-120 Plot Dirac in Space domain ========================== .. GENERATED FROM PYTHON SOURCE LINES 122-144 .. code-block:: default dirac_all_fdct_struct = Cop.struct(empty_fdct.copy()) for fdct_scale in dirac_all_fdct_struct: for fdct_wedge in fdct_scale: normalization = np.sqrt(fdct_wedge.size) iz, ix = fdct_wedge.shape fdct_wedge[iz // 2, ix // 2] = normalization * (1 + 1j) fdct_wedge[iz // 2 + 1, ix // 2] = normalization * (1 + 1j) fdct_wedge[iz // 2, ix // 2 + 1] = normalization * (1 + 1j) fdct_wedge[iz // 2 + 1, ix // 2 + 1] = normalization * (1 + 1j) data_dirac = Cop.H @ Cop.vect(dirac_all_fdct_struct) data_dirac = (data_dirac.real + data_dirac.imag) / np.sqrt(2) vmax = 0.5 * np.sqrt(data_dirac.size) fig, ax = plt.subplots(figsize=(5, 3)) ax.imshow(data_dirac.T, cmap="gray", vmin=-vmax, vmax=vmax) ax.set( xlim=(nx // 2 - 30, nx // 2 + 30), ylim=(nz // 2 + 30, nz // 2 - 30), title="Space domain magnified", ) fig.tight_layout() .. image-sg:: /gallery/images/sphx_glr_plot_curvelets_in_fk_009.png :alt: Space domain magnified :srcset: /gallery/images/sphx_glr_plot_curvelets_in_fk_009.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 5.146 seconds) .. _sphx_glr_download_gallery_plot_curvelets_in_fk.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_curvelets_in_fk.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_curvelets_in_fk.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_