{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from py4xs.hdf import h5xs,h5exp,lsh5\n",
    "import pylab as plt\n",
    "import warnings\n",
    "\n",
    "warnings.filterwarnings('ignore')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##<br>\n",
    "First the detector configuration needs to be associated with the scattering patterns. This information\n",
    "is typically saved in the exp.h5 file in the data directory"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "dexp = h5exp(\"data/exp.h5\") \n",
    "dh5 = h5xs(\"data/AgBH-2020Aug16.h5\", [dexp.detectors, dexp.qgrid])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##<br>\n",
    "Display the SAXS data, overlayed with rings that mark the expected position of diffraction peak from silver behenate."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 174876 characters]\n",
      "text/plain": [
       "<Figure size 432x432 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.figure(figsize=(6,6))\n",
    "ax = plt.gca()\n",
    "dh5.show_data(ax=ax, det_ext=\"_SAXS\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##\n",
    "Display the WAXS data, overlayed with rings that mark the expected position of diffraction peak from silver behenate."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 279292 characters]\n",
      "text/plain": [
       "<Figure size 432x432 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.figure(figsize=(6,6))\n",
    "ax = plt.gca()\n",
    "dh5.show_data(ax=ax, det_ext=\"_WAXS2\", clim=[30,500])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##<br>\n",
    "Display the data from all detectors, after converting them into reciprocal space, using $(q_x, q_y)$ coordinates (in the plane perpendicular to the beam direction)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 123896 characters]\n",
      "text/plain": [
       "<Figure size 432x432 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.figure(figsize=(6,6))\n",
    "ax = plt.gca()\n",
    "dh5.show_data_qxy(ax=ax, clim=(0.04, 400), dq=0.004, showMask=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##<br>\n",
    "Display the data from all detectors, after converting them into reciprocal space, using $(q, \\phi)$ coordinates."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 76128 characters]\n",
      "text/plain": [
       "<Figure size 432x432 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.figure(figsize=(6,6))\n",
    "ax = plt.gca()\n",
    "dh5.show_data_qphi(ax=ax, clim=(0.04, 400), Nphi=180, Nq=300, \n",
    "                   showMask=True, apply_symmetry=True, fill_gap=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "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.7.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
