.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/plot_sigmoid_coefficients.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_sigmoid_coefficients.py: 3. Visualizing Curvelet Coefficients ==================================== This example shows the how to visualize curvelet coefficients of an image, using as example a typical subsurface structure. .. GENERATED FROM PYTHON SOURCE LINES 7-9 .. code-block:: Python # sphinx_gallery_thumbnail_number = 3 .. GENERATED FROM PYTHON SOURCE LINES 10-15 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from curvelops import FDCT2D, apply_along_wedges, curveshow .. GENERATED FROM PYTHON SOURCE LINES 16-18 Input data ========== .. GENERATED FROM PYTHON SOURCE LINES 20-28 .. code-block:: Python inputfile = "../testdata/sigmoid.npz" d = np.load(inputfile) d = d["sigmoid"] nx, nt = d.shape dx, dt = 0.005, 0.004 x, t = np.arange(nx) * dx, np.arange(nt) * dt .. GENERATED FROM PYTHON SOURCE LINES 29-43 .. code-block:: Python aspect = dt / dx opts_plot = dict( extent=(x[0], x[-1], t[-1], t[0]), cmap="gray", interpolation="lanczos", aspect=aspect, ) vmax = 0.5 * np.max(np.abs(d)) figsize_aspect = aspect * nt / nx fig, ax = plt.subplots(figsize=(8, figsize_aspect * 8), sharey=True, sharex=True) ax.imshow(d.T, vmin=-vmax, vmax=vmax, **opts_plot) ax.set(xlabel="Position [m]", ylabel="Time [s]", title=f"Data shape {d.shape}") fig.tight_layout() .. image-sg:: /gallery/images/sphx_glr_plot_sigmoid_coefficients_001.png :alt: Data shape (256, 200) :srcset: /gallery/images/sphx_glr_plot_sigmoid_coefficients_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 44-46 Create Curvelet Transform ========================= .. GENERATED FROM PYTHON SOURCE LINES 46-50 .. code-block:: Python nbscales = 4 nbangles_coarse = 8 allcurvelets = False # Last scale will be a wavelet transform .. GENERATED FROM PYTHON SOURCE LINES 51-58 .. code-block:: Python Cop = FDCT2D( d.shape, nbscales=nbscales, nbangles_coarse=nbangles_coarse, allcurvelets=allcurvelets, ) .. GENERATED FROM PYTHON SOURCE LINES 59-60 Convert to a list of lists of ndarrays. .. GENERATED FROM PYTHON SOURCE LINES 60-62 .. code-block:: Python d_fdct_struct = Cop.struct(Cop @ d) .. GENERATED FROM PYTHON SOURCE LINES 63-68 Real part of FDCT coefficients ============================== Curvelet coefficients are essentially directionally-filtered, shrunk versions of the original signal. Note that the "shrinking" does not preserve aspect ratio. .. GENERATED FROM PYTHON SOURCE LINES 70-94 .. code-block:: Python for j, c_scale in enumerate(d_fdct_struct, start=1): nangles = len(c_scale) rows = int(np.floor(np.sqrt(nangles))) cols = int(np.ceil(nangles / rows)) fig, axes = plt.subplots( rows, cols, figsize=(5 * rows, figsize_aspect * 5 * rows), ) fig.suptitle(f"Scale {j} ({len(c_scale)} wedge{'s' if len(c_scale) > 1 else ''})") axes = np.atleast_1d(axes).ravel() vmax = 0.5 * max(np.abs(Cweg).max() for Cweg in c_scale) for iw, (fdct_wedge, ax) in enumerate(zip(c_scale, axes), start=1): # Note that wedges are transposed in comparison to the input vector. # This is due to the underlying implementation of the transform. In # order to plot in the same manner as the data, we must first # transpose the wedge. We will using the transpose of the wedge for # visualization. c = fdct_wedge.real.T ax.imshow(c.T, vmin=-vmax, vmax=vmax, **opts_plot) ax.set(title=f"Wedge {iw} shape {c.shape}") ax.axis("off") fig.tight_layout() .. rst-class:: sphx-glr-horizontal * .. image-sg:: /gallery/images/sphx_glr_plot_sigmoid_coefficients_002.png :alt: Scale 1 (1 wedge), Wedge 1 shape (43, 33) :srcset: /gallery/images/sphx_glr_plot_sigmoid_coefficients_002.png :class: sphx-glr-multi-img * .. image-sg:: /gallery/images/sphx_glr_plot_sigmoid_coefficients_003.png :alt: Scale 2 (8 wedges), Wedge 1 shape (39, 67), Wedge 2 shape (39, 67), Wedge 3 shape (87, 31), Wedge 4 shape (87, 31), Wedge 5 shape (39, 67), Wedge 6 shape (39, 67), Wedge 7 shape (87, 31), Wedge 8 shape (87, 31) :srcset: /gallery/images/sphx_glr_plot_sigmoid_coefficients_003.png :class: sphx-glr-multi-img * .. image-sg:: /gallery/images/sphx_glr_plot_sigmoid_coefficients_004.png :alt: Scale 3 (16 wedges), Wedge 1 shape (71, 67), Wedge 2 shape (71, 67), Wedge 3 shape (71, 67), Wedge 4 shape (71, 67), Wedge 5 shape (87, 55), Wedge 6 shape (87, 55), Wedge 7 shape (87, 55), Wedge 8 shape (87, 55), Wedge 9 shape (71, 67), Wedge 10 shape (71, 67), Wedge 11 shape (71, 67), Wedge 12 shape (71, 67), Wedge 13 shape (87, 55), Wedge 14 shape (87, 55), Wedge 15 shape (87, 55), Wedge 16 shape (87, 55) :srcset: /gallery/images/sphx_glr_plot_sigmoid_coefficients_004.png :class: sphx-glr-multi-img * .. image-sg:: /gallery/images/sphx_glr_plot_sigmoid_coefficients_005.png :alt: Scale 4 (1 wedge), Wedge 1 shape (256, 200) :srcset: /gallery/images/sphx_glr_plot_sigmoid_coefficients_005.png :class: sphx-glr-multi-img .. GENERATED FROM PYTHON SOURCE LINES 95-99 Imaginagy part of FDCT coefficients =================================== Curvelops includes much of the above logic wrapped in the following :py:class:`curvelops.plot.cuveshow`. Since we .. GENERATED FROM PYTHON SOURCE LINES 99-103 .. code-block:: Python # Normalize each coefficient by max abs y_norm = apply_along_wedges(d_fdct_struct, lambda w, *_: w / np.abs(w).max()) .. GENERATED FROM PYTHON SOURCE LINES 104-109 .. code-block:: Python figs = curveshow( y_norm, real=False, kwargs_imshow={**opts_plot, "vmin": -0.5, "vmax": 0.5}, ) .. rst-class:: sphx-glr-horizontal * .. image-sg:: /gallery/images/sphx_glr_plot_sigmoid_coefficients_006.png :alt: Scale 0 (1 wedge) :srcset: /gallery/images/sphx_glr_plot_sigmoid_coefficients_006.png :class: sphx-glr-multi-img * .. image-sg:: /gallery/images/sphx_glr_plot_sigmoid_coefficients_007.png :alt: Scale 1 (8 wedges), Wedge 0, Wedge 1, Wedge 2, Wedge 3, Wedge 4, Wedge 5, Wedge 6, Wedge 7 :srcset: /gallery/images/sphx_glr_plot_sigmoid_coefficients_007.png :class: sphx-glr-multi-img * .. image-sg:: /gallery/images/sphx_glr_plot_sigmoid_coefficients_008.png :alt: Scale 2 (16 wedges), Wedge 0, 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 :srcset: /gallery/images/sphx_glr_plot_sigmoid_coefficients_008.png :class: sphx-glr-multi-img * .. image-sg:: /gallery/images/sphx_glr_plot_sigmoid_coefficients_009.png :alt: Scale 3 (1 wedge) :srcset: /gallery/images/sphx_glr_plot_sigmoid_coefficients_009.png :class: sphx-glr-multi-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 12.052 seconds) .. _sphx_glr_download_gallery_plot_sigmoid_coefficients.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_sigmoid_coefficients.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_sigmoid_coefficients.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_sigmoid_coefficients.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_