{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# 2D Smoothing\n\nThis example shows how to use the :py:class:`pylops.Smoothing2D` operator\nto smooth a multi-dimensional input signal along two given axes.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import matplotlib.pyplot as plt\nimport numpy as np\n\nimport pylops\n\nplt.close(\"all\")"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Define the input parameters: number of samples of input signal (``N`` and ``M``) and\nlenght of the smoothing filter regression coefficients\n($n_{smooth,1}$ and $n_{smooth,2}$). In this first case the input\nsignal is one at the center and zero elsewhere.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "N, M = 11, 21\nnsmooth1, nsmooth2 = 5, 3\nA = np.zeros((N, M))\nA[5, 10] = 1\n\nSop = pylops.Smoothing2D(nsmooth=[nsmooth1, nsmooth2], dims=[N, M], dtype=\"float64\")\nB = Sop * A"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "After applying smoothing, we will also try to invert it.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "Aest = (Sop / B.ravel()).reshape(Sop.dims)\n\nfig, axs = plt.subplots(1, 3, figsize=(10, 3))\nim = axs[0].imshow(A, interpolation=\"nearest\", vmin=0, vmax=1)\naxs[0].axis(\"tight\")\naxs[0].set_title(\"Model\")\nplt.colorbar(im, ax=axs[0])\nim = axs[1].imshow(B, interpolation=\"nearest\", vmin=0, vmax=1)\naxs[1].axis(\"tight\")\naxs[1].set_title(\"Data\")\nplt.colorbar(im, ax=axs[1])\nim = axs[2].imshow(Aest, interpolation=\"nearest\", vmin=0, vmax=1)\naxs[2].axis(\"tight\")\naxs[2].set_title(\"Estimated model\")\nplt.colorbar(im, ax=axs[2])\nplt.tight_layout()"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.9.15"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}