{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Padding\nThis example shows how to use the :py:class:`pylops.Pad` operator to zero-pad a\nmodel\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": [
        "Let's define a pad operator ``Pop`` for one dimensional data\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "dims = 10\npad = (2, 3)\n\nPop = pylops.Pad(dims, pad)\n\nx = np.arange(dims) + 1.0\ny = Pop * x\nxadj = Pop.H * y\n\nprint(f\"x = {x}\")\nprint(f\"P*x = {y}\")\nprint(f\"P'*y = {xadj}\")"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "We move now to a multi-dimensional case. We pad the input model\nwith different extents along both dimensions\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "dims = (5, 4)\npad = ((1, 0), (3, 4))\n\nPop = pylops.Pad(dims, pad)\n\nx = (np.arange(np.prod(np.array(dims))) + 1.0).reshape(dims)\ny = Pop * x\nxadj = Pop.H * y\n\nfig, axs = plt.subplots(1, 3, figsize=(10, 4))\nfig.suptitle(\"Pad for 2d data\", fontsize=14, fontweight=\"bold\", y=1.15)\naxs[0].imshow(x, cmap=\"rainbow\", vmin=0, vmax=np.prod(np.array(dims)) + 1)\naxs[0].set_title(r\"$x$\")\naxs[0].axis(\"tight\")\naxs[1].imshow(y, cmap=\"rainbow\", vmin=0, vmax=np.prod(np.array(dims)) + 1)\naxs[1].set_title(r\"$y = P x$\")\naxs[1].axis(\"tight\")\naxs[2].imshow(xadj, cmap=\"rainbow\", vmin=0, vmax=np.prod(np.array(dims)) + 1)\naxs[2].set_title(r\"$x_{adj} = P^{H} y$\")\naxs[2].axis(\"tight\")\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
}