{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\nPadding\n=======\nThis example shows how to use the :py:class:`pylops.Pad` operator to zero-pad a\nmodel\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import numpy as np\nimport matplotlib.pyplot as plt\nimport matplotlib.gridspec as pltgs\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.\ny = Pop*x\nxadj = Pop.H*y\n\nprint('x = %s ' % x)\nprint('P*x = %s ' % y)\nprint('P\\'*y = %s ' % 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.).reshape(dims)\ny = Pop*x.ravel()\nxadj = Pop.H*y\n\ny = y.reshape(Pop.dimsd)\nxadj = xadj.reshape(dims)\n\nfig, axs = plt.subplots(1, 3, figsize=(10, 2))\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')"
      ]
    }
  ],
  "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.6.8"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}