{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Imag\n\nThis example shows how to use the :py:class:`pylops.basicoperators.Imag`\noperator.\nThis operator returns the imaginary part of the data as a real value in\nforward mode, and the real part of the model as an imaginary value in\nadjoint mode (with zero real part).\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 Imag operator $\\mathbf{\\Im}$ to extract the imaginary\ncomponent of the input.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "M = 5\nx = np.arange(M) + 1j * np.arange(M)[::-1]\nRop = pylops.basicoperators.Imag(M, dtype=\"complex128\")\n\ny = Rop * x\nxadj = Rop.H * y\n\n_, axs = plt.subplots(1, 3, figsize=(10, 4))\naxs[0].plot(np.real(x), lw=2, label=\"Real\")\naxs[0].plot(np.imag(x), lw=2, label=\"Imag\")\naxs[0].legend()\naxs[0].set_title(\"Input\")\naxs[1].plot(np.real(y), lw=2, label=\"Real\")\naxs[1].plot(np.imag(y), lw=2, label=\"Imag\")\naxs[1].legend()\naxs[1].set_title(\"Forward of Input\")\naxs[2].plot(np.real(xadj), lw=2, label=\"Real\")\naxs[2].plot(np.imag(xadj), lw=2, label=\"Imag\")\naxs[2].legend()\naxs[2].set_title(\"Adjoint of Forward\")\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
}