.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plot_03_direction_disk.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_03_direction_disk.py: Multiscale Direction Disks ========================== This example shows how to use the UDCT curvelets transform to visualize multiscale preferrential directions in an image. Inspired by `Kymatio's Scattering disks `__. .. GENERATED FROM PYTHON SOURCE LINES 8-20 .. code-block:: Python # sphinx_gallery_thumbnail_number = 2 from __future__ import annotations import matplotlib.pyplot as plt import numpy as np from curvelets.numpy import UDCT from curvelets.plot import create_inset_axes_grid, overlay_arrows, overlay_disk from curvelets.utils import apply_along_wedges, normal_vector_field .. GENERATED FROM PYTHON SOURCE LINES 21-23 Input Data ########## .. GENERATED FROM PYTHON SOURCE LINES 23-30 .. code-block:: Python inputfile = "../testdata/sigmoid.npz" data = np.load(inputfile) data = data["sigmoid"][:120, :64] nx, nz = data.shape dx, dz = 0.005, 0.004 x, z = np.arange(nx) * dx, np.arange(nz) * dz .. GENERATED FROM PYTHON SOURCE LINES 31-44 .. code-block:: Python aspect = dz / dx figsize_aspect = aspect * nz / nx opts_space = { "extent": (x[0], x[-1], z[-1], z[0]), "cmap": "gray", "interpolation": "lanczos", "aspect": aspect, } vmax = 0.5 * np.max(np.abs(data)) fig, ax = plt.subplots(figsize=(8, figsize_aspect * 8)) ax.imshow(data.T, vmin=-vmax, vmax=vmax, **opts_space) ax.set(xlabel="Position [km]", ylabel="Depth [km]", title="Data") .. image-sg:: /auto_examples/images/sphx_glr_plot_03_direction_disk_001.png :alt: Data :srcset: /auto_examples/images/sphx_glr_plot_03_direction_disk_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none [Text(0.5, 34.64692810457516, 'Position [km]'), Text(53.972222222222214, 0.5, 'Depth [km]'), Text(0.5, 1.0, 'Data')] .. GENERATED FROM PYTHON SOURCE LINES 45-47 UDCT #### .. GENERATED FROM PYTHON SOURCE LINES 47-50 .. code-block:: Python Cop = UDCT(data.shape, num_scales=3, wedges_per_direction=3) d_c = Cop.forward(data) .. GENERATED FROM PYTHON SOURCE LINES 51-55 Normal Directions via FFT2D ########################### Compute average normal vector. This vector indicates the direction normal to the structures of the image .. GENERATED FROM PYTHON SOURCE LINES 55-58 .. code-block:: Python kvecs = normal_vector_field(data, 1, 1) kvecs *= 0.4 * min(x[-1] - x[0], z[-1] - z[0]) .. GENERATED FROM PYTHON SOURCE LINES 59-64 Scattering Disk via UDCT ######################## Now we compute the average energy of each curvelet "wedge". We will plot this on a multiscale disk to show the distribution of energies along different directions of the various scales in the data. .. GENERATED FROM PYTHON SOURCE LINES 64-66 .. code-block:: Python energy_c = apply_along_wedges(d_c, lambda w, *_: np.sqrt((np.abs(w) ** 2).mean())) .. GENERATED FROM PYTHON SOURCE LINES 67-73 .. code-block:: Python fig, ax = plt.subplots(figsize=(12, figsize_aspect * 8)) ax.imshow(data.T, vmin=-vmax, vmax=vmax, **opts_space) overlay_arrows(kvecs, ax, arrowprops={"edgecolor": "w", "facecolor": "k"}) ax_o = create_inset_axes_grid(ax, width=0.4, kwargs_inset_axes={"projection": "polar"}) overlay_disk(energy_c, ax=ax_o, vmin=0, cmap="turbo", linecolor="w", linewidth=5) ax.set(xlabel="Position [km]", ylabel="Depth [km]", title="Data") .. image-sg:: /auto_examples/images/sphx_glr_plot_03_direction_disk_002.png :alt: Data :srcset: /auto_examples/images/sphx_glr_plot_03_direction_disk_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none [Text(0.5, 8.26888888888889, 'Position [km]'), Text(181.12037037037038, 0.5, 'Depth [km]'), Text(0.5, 1.0, 'Data')] .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.330 seconds) .. _sphx_glr_download_auto_examples_plot_03_direction_disk.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_03_direction_disk.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_03_direction_disk.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_03_direction_disk.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_