{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# How to make a Logo\n",
    "\n",
    "### first import good tools"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-05-28T21:11:20.798899Z",
     "start_time": "2021-05-28T21:11:19.534153Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "    ========================\n",
      "          SPIKE\n",
      "    ========================\n",
      "    Version     : 0.99.21\n",
      "    Date        : 23-02-2021\n",
      "    Revision Id : 490\n",
      "    ========================\n",
      "*** zoom3D not loaded ***\n",
      "plugins loaded:\n",
      "Fitter,  Linear_prediction,  Peaks,  bcorr,  fastclean,  gaussenh,  rem_ridge,  sane,  sg,  test,  urQRd, \n",
      "\n",
      "spike.plugins.report() for a short description of each plugins\n",
      "spike.plugins.report('module_name') for complete documentation on one plugin\n",
      "plugins loaded:\n",
      "Bruker_NMR_FT,  Bucketing,  Integrate,  PALMA,  apmin, \n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "import spike\n",
    "import spike.NMR"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### import (or *simulate*) a nice time-signal\n",
    "for instance a 1 sec FID sampled at 1kHz - with a multiplet structure"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-05-28T21:11:20.924306Z",
     "start_time": "2021-05-28T21:11:20.800088Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1D data-set\n",
       "Axis F1 :NMR axis at 400.000000 MHz, 1000 complex pairs,  from 0.000000 ppm (0.000000 Hz) to 2.500000 ppm  (1000.000000 Hz)\n",
       "data-set is complex"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 16044 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# set-up scene\n",
    "sw = 1000.0    # spectral width in Hz\n",
    "w = 314.15926  # line position in Hz\n",
    "J = 1.3        # coupling in Hz\n",
    "tau = 0.9      # damping in second\n",
    "\n",
    "# generate main frequency\n",
    "t = np.arange(1000)/sw\n",
    "fid = (np.cos(2*np.pi*w*t)+1j*np.sin(2*np.pi*w*t))*np.exp(-t/tau)\n",
    "\n",
    "# add a pattern - here a heptuplet.\n",
    "for i in range(6):\n",
    "    fid *= np.cos(2*np.pi*J*t)\n",
    "\n",
    "# load into spike\n",
    "data = spike.NMR.NMRData(buffer=fid) \n",
    "data.axis1.specwidth = sw\n",
    "data.set_unit('sec').display()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# And process\n",
    "Here, comparing a simple FFT to a apodisation with a shifted sine-bell"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-05-28T21:11:20.930502Z",
     "start_time": "2021-05-28T21:11:20.925810Z"
    }
   },
   "outputs": [],
   "source": [
    "# compute\n",
    "d1 = data.copy().zf(16).fft()\n",
    "d2 = data.copy().apod_sin().zf(16).fft()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### and draw the picture with nice settings"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-05-28T21:11:21.069737Z",
     "start_time": "2021-05-28T21:11:20.931793Z"
    },
    "lines_to_next_cell": 2,
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "findfont: Font family ['xkcd', 'xkcd Script', 'Humor Sans', 'Comic Neue', 'Comic Sans MS'] not found. Falling back to DejaVu Sans.\n",
      "findfont: Font family ['open sans'] not found. Falling back to DejaVu Sans.\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 32004 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# define zoom and draw\n",
    "z = (w+30, w-30)\n",
    "darkblue = '#0A2B3D'\n",
    "with plt.xkcd(length=150):   # add some effect\n",
    "    d1.set_unit('Hz').display(zoom=z, linewidth=3, color='#3995C8')\n",
    "    d2.set_unit('Hz').display(zoom=z, linewidth=3, color='orange', new_fig=False) #figure=d1.mplfigure) # other possibility\n",
    "# add some text\n",
    "fd = {'fontfamily': 'open sans',\n",
    "      'color':  darkblue,\n",
    "      'weight': 'semibold',\n",
    "      'size': 110}\n",
    "plt.text(w+28,15,'SP', fontdict=fd)\n",
    "plt.text(w-5,15,'KE',  fontdict=fd)\n",
    "# clean picture and change axes\n",
    "plt.yticks([])\n",
    "plt.ylabel('')\n",
    "plt.xlabel('')\n",
    "gca = plt.gca()\n",
    "for side in ['top','left','right']:\n",
    "    gca.spines[side].set_color('white')\n",
    "gca.spines['bottom'].set_color(darkblue)\n",
    "gca.xaxis.set_tick_params(color=darkblue, labelcolor=darkblue)\n",
    "# and save\n",
    "plt.savefig('Logo.png')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "jupytext": {
   "formats": "ipynb,py:percent"
  },
  "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.8.5"
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
