{
 "metadata": {
  "name": ""
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Preparation"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "% pylab\n",
      "import matplotlib.pyplot as plt\n",
      "import matplotlib.transforms as mtransforms\n",
      "import matplotlib.patches as mpatches\n",
      "plt.rc('text', usetex=True)\n",
      "plt.rc('font', **{'family': 'serif', 'serif': ['Computer Modern']})\n",
      "\n",
      "def draw_bbox_fancy(ax, bb, bbBol, fbBol, BoxS, Ec, Fc,lw=1.,ls='solid',zorder=1):\n",
      "    # ax = axe\n",
      "    # bb = bbox instance\n",
      "    # bbBol, fbBol = Booleans, if true the bbox itself and/or the fancybox is plotted\n",
      "    # BoxSDic = boxstyle dictionary to be used for the fancybox\n",
      "    \n",
      "    if bbBol:\n",
      "        p_bbox = mpatches.FancyBboxPatch((bb.xmin, bb.ymin), abs(bb.width), abs(bb.height),\n",
      "                                boxstyle=\"square,pad=0.\", ec=\"k\", fc=\"none\", zorder=10.,lw=lw,ls=ls)\n",
      "        ax.add_patch(p_bbox)\n",
      "        \n",
      "    if fbBol:\n",
      "        p_fbbox = mpatches.FancyBboxPatch((bb.xmin, bb.ymin), abs(bb.width), abs(bb.height),boxstyle=BoxS,ec=Ec,fc=Fc, zorder=zorder,lw=lw,ls=ls)\n",
      "        ax.add_patch(p_fbbox)\n",
      "        plt.draw()\n",
      "        return p_fbbox\n",
      "\n",
      "\n",
      "def common_bbox(ax, txt):\n",
      "    # ax = axe\n",
      "    # txt = list of text instances\n",
      "    \n",
      "    plt.draw()\n",
      "    Xmin, Ymin, Xmax, Ymax = [], [], [], []\n",
      "    for Tx in txt:\n",
      "        try:\n",
      "            Txw = Tx.get_window_extent(renderer=None,dpi=None)\n",
      "        except TypeError:\n",
      "            Txw = Tx.patch.get_bbox()\n",
      "        TxwData = Txw.transformed(ax.transData.inverted())\n",
      "        Xmin.append(TxwData.xmin)\n",
      "        Ymin.append(TxwData.ymin)\n",
      "        Xmax.append(TxwData.xmax)\n",
      "        Ymax.append(TxwData.ymax)\n",
      "  \n",
      "    Xmin, Ymin, Xmax, Ymax = min(Xmin), min(Ymin), max(Xmax), max(Ymax)\n",
      "    bb = mtransforms.Bbox([[Xmin, Ymin], [Xmax, Ymax]])\n",
      "    return bb\n",
      "\n",
      "\n",
      "def link_fancyArrow(ax, bb1, Coordbb1, bb2, Coordbb2, arrowprops):\n",
      "    # ax = axe\n",
      "    # bb1, bb2 = bbox or patch instance\n",
      "    # Coordbb1, Coordbb2 = (x,y) tuple normalised coordinates (with respect to x/ymax and x/ymin of bb1/bb2)\n",
      "    \n",
      "    if isinstance(bb1,matplotlib.patches.FancyBboxPatch):\n",
      "        print('The input args should be Bbox instances, not patches!\\n Associated Bbox used instead')\n",
      "        bb1, bb2 = bb1.get_bbox(), bb2.get_bbox()\n",
      "        \n",
      "    if isinstance(bb1,matplotlib.transforms.Bbox):\n",
      "        x1, y1 = Coordbb1[0]*(bb1.xmax-bb1.xmin)+bb1.xmin, Coordbb1[1]*(bb1.ymax-bb1.ymin)+bb1.ymin\n",
      "        x2, y2 = Coordbb2[0]*(bb2.xmax-bb2.xmin)+bb2.xmin, Coordbb2[1]*(bb2.ymax-bb2.ymin)+bb2.ymin\n",
      "    \n",
      "    p_a = mpatches.FancyArrowPatch((x1,y1),(x2,y2),**arrowprops)\n",
      "    ax.add_patch(p_a)\n",
      "    return p_a\n",
      "    \n",
      "def hide_image(patch, ax, Dict):\n",
      "    Txw = patch.get_bbox()\n",
      "    TxwData = Txw.transformed(ax.transData.inverted())\n",
      "    Pts = TxwData.get_points()\n",
      "    xy, W, H = Pts[0,:], np.diff(Pts,axis=0)[0,0], np.diff(Pts,axis=0)[0,1]\n",
      "    p_a = mpatches.Rectangle( xy, W, H, zorder=100, **Dict)\n",
      "    ax.add_patch(p_a)\n",
      "    return p_a\n",
      "    "
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Using matplotlib backend: MacOSX\n",
        "Populating the interactive namespace from numpy and matplotlib\n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Exercice Type de schema"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "figW, figH = 8, 5\n",
      "figdpi = 80\n",
      "fig = plt.figure(facecolor=\"w\",figsize=(figW,figH), dpi=figdpi)\n",
      "axcolor = 'w'\n",
      "ax = plt.axes([0, 0, 1, 1],frameon=False, axisbg=axcolor)\n",
      "ax.axis('off')\n",
      "\n",
      "BoxS, Fc, Ec, Alpha = \"round,pad=0.01\", (1.,0.5,1.,0.2), (1.,0.2,1.,1.), 0.5\n",
      "ConnectStyle = 'angle3,angleA=90,angleB=0'\n",
      "arrowprops = dict(arrowstyle=\"fancy,head_length=1,head_width=1,tail_width=0.5\",connectionstyle=ConnectStyle,color='k',mutation_scale=10)\n",
      "Name_tparams={'ha':'center', 'va':'bottom', 'family':'sans-serif','fontweight':'bold','fontstyle':'italic'}\n",
      "\n",
      "Fle = ax.text(0.2,0.4,\"bla\", color='k', size=20, zorder=10., **Name_tparams)\n",
      "Tx = ax.text(0.4,0.3, \"Bli\", color='k', size=12, zorder=11., **Name_tparams)\n",
      "\n",
      "Fle2 = ax.text(0.6,0.8,\"bla\", color='k', size=20, zorder=10., **Name_tparams)\n",
      "Tx2 = ax.text(0.7,0.2, \"Bli\", color='k', size=12, zorder=11., **Name_tparams)\n",
      "\n",
      "Txt = [Fle, Tx]\n",
      "Txt2 = [Fle2, Tx2]\n",
      "bb1 = common_bbox(ax, Txt)\n",
      "bb2 = common_bbox(ax, Txt2)\n",
      "fb1 = draw_bbox_fancy(ax, bb1, True, True, BoxS, Ec, Fc)\n",
      "fb2 = draw_bbox_fancy(ax, bb2, False, True, BoxS, Ec, Fc)\n",
      "\n",
      "A1 = link_fancyArrow(ax, fb1, (0.5,1.), fb2, (0.,0.5), arrowprops)\n",
      "draw()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The input args should be Bbox instances, not patches!\n",
        " Associated Bbox used instead\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Droit de la Guerre"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "figW, figH = 7, 2.5\n",
      "figdpi = 80\n",
      "fig = plt.figure(facecolor=\"w\",figsize=(figW,figH), dpi=figdpi)\n",
      "axcolor = 'w'\n",
      "ax = plt.axes([0, 0, 1, 1],frameon=False, axisbg=axcolor)\n",
      "ax.axis('off')\n",
      "\n",
      "BoxS, Fc, Ec, Alpha = \"round,pad=0.02\", (1.,0.5,1.,0.2), (1.,0.2,1.,1.), 0.5\n",
      "Title_tparams={'size':15,'ha':'center', 'va':'bottom', 'family':'sans-serif','fontweight':'bold','fontstyle':'italic'}\n",
      "Title_tparams2={'size':12,'ha':'center', 'va':'bottom', 'family':'sans-serif','fontweight':'bold','fontstyle':'italic'}\n",
      "Com_tparams = {'size':10,'ha':'left', 'va':'top', 'family':'sans-serif','fontweight':'normal','fontstyle':'italic'}\n",
      "arrowprops = dict(arrowstyle=\"fancy,head_length=1,head_width=1,tail_width=0.5\",mutation_scale=2)\n",
      "arrowprops2 = dict(arrowstyle=\"fancy,head_length=1,head_width=1,tail_width=0.5\",mutation_scale=5)\n",
      "\n",
      "\n",
      "Title, Com, Pos, Color, Box, Tparams, Arrw = [], [], [], [], [], [], []\n",
      "\n",
      "######################\n",
      "\n",
      "Title.append(\"Droit de la Guerre\")\n",
      "Com.append(\"\")\n",
      "Pos.append((0.5,0.9)), Color.append((0.,0.,0.,1.)), Box.append(False), Tparams.append(Title_tparams), Arrw.append(arrowprops2)\n",
      "\n",
      "Title.append(\"Jus ad bellum ou DSI\")\n",
      "Com.append(\"Regit recours a force armee\\nMais DSI inclut aussi droit des alliances en paix\")\n",
      "Pos.append((0.25,0.65)), Color.append((0.,0.,0.,1.)), Box.append(True), Tparams.append(Title_tparams), Arrw.append(arrowprops2)\n",
      "\n",
      "Title.append(\"Jus in bello ou DIH\")\n",
      "Com.append(\"Regit usage de force armee\\nMais DIH inclut aussi droit humanitaire en paix\")\n",
      "Pos.append((0.75,0.65)), Color.append((0.,0.,0.,1.)), Box.append(True), Tparams.append(Title_tparams), Arrw.append(arrowprops2)\n",
      "\n",
      "Title.append(\"Troubles internes\")\n",
      "Com.append(\"\")\n",
      "Pos.append((0.25,0.35)), Color.append((0.,0.,0.,1.)), Box.append(True), Tparams.append(Title_tparams2), Arrw.append(arrowprops)\n",
      "\n",
      "Title.append(\"CANI\")\n",
      "Com.append(\"\")\n",
      "Pos.append((0.15,0.15)), Color.append((0.,0.,0.,1.)), Box.append(True), Tparams.append(Title_tparams2), Arrw.append(arrowprops)\n",
      "\n",
      "Title.append(\"CAI\")\n",
      "Com.append(\"\")\n",
      "Pos.append((0.35,0.15)), Color.append((0.,0.,0.,1.)), Box.append(True), Tparams.append(Title_tparams2), Arrw.append(arrowprops)\n",
      "\n",
      "TxTitle, TxCom, bb, fb = [], [], [], []\n",
      "for i in range(0,len(Title)):\n",
      "    TxTitle.append(ax.text(Pos[i][0],Pos[i][1], Title[i], color=Color[i], **Tparams[i]))\n",
      "    TxCom.append(ax.text(Pos[i][0],Pos[i][1]-0.01, Com[i], color=Color[i], **Com_tparams))\n",
      "    \n",
      "plt.draw()\n",
      "ListBox = []\n",
      "for i in range(0,len(Title)):\n",
      "    Txpatch = TxCom[i].get_window_extent()   \n",
      "    Lim = Txpatch.transformed(ax.transData.inverted())\n",
      "    DX = Lim.xmax-Lim.xmin\n",
      "    TxCom[i].set_x(Pos[i][0]-DX/2.)\n",
      "    bb.append(common_bbox(ax, [TxTitle[i], TxCom[i]]))\n",
      "    fb.append(draw_bbox_fancy(ax, bb[i], False, Box[i], BoxS, Color[i], 'w'))\n",
      " \n",
      "ArCol, ArAng, ArBox, ArPos = [], [], [], []\n",
      "\n",
      "ArB = [0, 0, 3, 3, 4, 4, 5, 5]\n",
      "ArCol.append(Color[0]), ArBox.append([bb[0],bb[1]]), ArAng.append((20,40)), ArPos.append([(0.2,0.),(0.8,1.)])\n",
      "ArCol.append(Color[0]), ArBox.append([bb[0],bb[2]]), ArAng.append((-20,-40)), ArPos.append([(0.8,0.),(0.2,1.)])\n",
      "ArCol.append(Color[3]), ArBox.append([bb[3],bb[4]]), ArAng.append((20,90)), ArPos.append([(0.,0.5),(0.5,1.)])\n",
      "ArCol.append(Color[3]), ArBox.append([bb[3],bb[5]]), ArAng.append((-80,-40)), ArPos.append([(0.8,0.),(0.2,1.)])\n",
      "ArCol.append(Color[4]), ArBox.append([bb[4],bb[3]]), ArAng.append((40,80)), ArPos.append([(0.8,1.),(0.2,0.)])\n",
      "ArCol.append(Color[4]), ArBox.append([bb[4],bb[5]]), ArAng.append((-20,20)), ArPos.append([(1.,0.2),(0.,0.2)])\n",
      "ArCol.append(Color[5]), ArBox.append([bb[5],bb[3]]), ArAng.append((90,-20)), ArPos.append([(0.5,1.),(1.,0.5)])\n",
      "ArCol.append(Color[5]), ArBox.append([bb[5],bb[4]]), ArAng.append((-20,20)), ArPos.append([(0.,0.8),(1.,0.8)])\n",
      "\n",
      "Ar = []\n",
      "for i in range(0,len(ArCol)):\n",
      "    arrowpropsi = Arrw[ArB[i]]\n",
      "    arrowpropsi['color'] = ArCol[i]\n",
      "    arrowpropsi['connectionstyle'] = 'angle3,angleA=' + str(ArAng[i][0]) + ',angleB=' + str(ArAng[i][1])\n",
      "    Ar.append(link_fancyArrow(ax, ArBox[i][0], ArPos[i][0], ArBox[i][1], ArPos[i][1], arrowpropsi))\n",
      "    \n",
      "plt.draw()  \n",
      "\n",
      "#fig.savefig('Schema_DDLG.png', bbox_inches=0)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 3
    },
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Trois niveaux de conflictualit\u00e9"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "figW, figH = 9, 6\n",
      "figdpi = 80\n",
      "fig = plt.figure(facecolor=\"w\",figsize=(figW,figH), dpi=figdpi)\n",
      "axcolor = 'w'\n",
      "ax = plt.axes([0, 0, 1, 1],frameon=False, axisbg=axcolor)\n",
      "ax.axis('off')\n",
      "\n",
      "BoxS, Fc, Ec, Alpha = \"round,pad=0.01\", (1.,0.5,1.,0.2), (1.,0.2,1.,1.), 0.5\n",
      "Title_tparams={'size':15,'ha':'center', 'va':'bottom', 'family':'sans-serif','fontweight':'bold','fontstyle':'italic'}\n",
      "Com_tparams = {'size':10,'ha':'left', 'va':'top', 'family':'sans-serif','fontweight':'normal','fontstyle':'italic'}\n",
      "Ar_tparams1 = {'size':10,'ha':'center', 'va':'center', 'family':'sans-serif','fontweight':'normal','fontstyle':'italic'}\n",
      "Ar_tparams2 = {'size':10,'ha':'center', 'va':'bottom', 'family':'sans-serif','fontweight':'normal','fontstyle':'italic'}\n",
      "Ar_tparams3 = {'size':10,'ha':'center', 'va':'bottom', 'family':'sans-serif','fontweight':'normal','fontstyle':'italic'}\n",
      "arrowprops = dict(arrowstyle=\"fancy,head_length=1,head_width=1,tail_width=0.5\",mutation_scale=10)\n",
      "\n",
      "Title, Com, Pos, Color, Box = [], [], [], [], []\n",
      "\n",
      "Title.append(\"TTI (droit interne)\")\n",
      "Com.append(\"Emeutes, greves\\nViolences (isoles, peu structures)\\nMesures administratives et judiciaire\")\n",
      "Pos.append((0.5,0.9)), Color.append((0.,0.,0.,1.)), Box.append(True)\n",
      "\n",
      "Title.append(\"CANI\")\n",
      "Com.append(\"Confine au territoire d'un Etat\\nArmee reguliere vs Insurrection\\nGuerre civile\")\n",
      "Pos.append((0.15,0.2)), Color.append((0.,0.,1.,1.)), Box.append(True)\n",
      "\n",
      "Title.append(\"CAI\")\n",
      "Com.append(\"Guerre inter-etatique\\nLutte de liberation\\n(coloniale, post-coloniale, apartheid)\\nArmee vs entite non-etatique\")\n",
      "Pos.append((0.85,0.2)), Color.append((1.,0.,0.,1.)), Box.append(True)\n",
      "\n",
      "TxTitle, TxCom, bb, fb = [], [], [], []\n",
      "for i in range(0,len(Title)):\n",
      "    TxTitle.append(ax.text(Pos[i][0],Pos[i][1], Title[i], color=Color[i], **Title_tparams))\n",
      "    TxCom.append(ax.text(Pos[i][0],Pos[i][1]-0.01, Com[i], color=Color[i], **Com_tparams))\n",
      "    \n",
      "plt.draw()\n",
      "for i in range(0,len(Title)):\n",
      "    Txpatch = TxCom[i].get_window_extent()   \n",
      "    Lim = Txpatch.transformed(ax.transData.inverted())\n",
      "    DX = Lim.xmax-Lim.xmin\n",
      "    TxCom[i].set_x(Pos[i][0]-DX/2.)\n",
      "    bb.append(common_bbox(ax, [TxTitle[i], TxCom[i]]))\n",
      "    fb.append(draw_bbox_fancy(ax, bb[i], False, True, BoxS, Color[i], 'w'))\n",
      " \n",
      "ArCol, ArAng, ArBox, ArPos = [], [], [], []\n",
      "\n",
      "ArCol.append(Color[0]), ArBox.append([bb[0],bb[1]]), ArAng.append((40,90)), ArPos.append([(0.,0.5),(0.5,1.)])\n",
      "ArCol.append(Color[0]), ArBox.append([bb[0],bb[2]]), ArAng.append((-80,-40)), ArPos.append([(0.8,0.),(0.2,1.)])\n",
      "ArCol.append(Color[1]), ArBox.append([bb[1],bb[0]]), ArAng.append((40,80)), ArPos.append([(0.8,1.),(0.2,0.)])\n",
      "ArCol.append(Color[1]), ArBox.append([bb[1],bb[2]]), ArAng.append((-20,20)), ArPos.append([(1.,0.2),(0.,0.2)])\n",
      "ArCol.append(Color[2]), ArBox.append([bb[2],bb[0]]), ArAng.append((90,-40)), ArPos.append([(0.5,1.),(1.,0.5)])\n",
      "ArCol.append(Color[2]), ArBox.append([bb[2],bb[1]]), ArAng.append((-20,20)), ArPos.append([(0.,0.8),(1.,0.8)])\n",
      "\n",
      "Ar = []\n",
      "for i in range(0,len(ArCol)):\n",
      "    arrowpropsi = arrowprops\n",
      "    arrowpropsi['color'] = ArCol[i]\n",
      "    arrowpropsi['connectionstyle'] = 'angle3,angleA=' + str(ArAng[i][0]) + ',angleB=' + str(ArAng[i][1])\n",
      "    Ar.append(link_fancyArrow(ax, ArBox[i][0], ArPos[i][0], ArBox[i][1], ArPos[i][1], arrowpropsi))\n",
      "    \n",
      "    \n",
      "bboxstyle = dict(boxstyle=\"round4,pad=0.5,rounding_size=0.2\", fc=\"w\", ec=\"w\", lw=1)\n",
      "TransTrCANI = ax.text(0.21,0.55, \"Reconnaissance CANI par Etat ou CSNU\\n(Repression brutale, insurrection)\", \n",
      "                      color=Color[0], rotation=60., bbox=bboxstyle, **Ar_tparams1)\n",
      "TransCANITr = ax.text(0.35,0.50, \"Dissolution groupes armes\\nAccord de paix\\nCessez-le-feu\", \n",
      "                      color=Color[1], rotation=60., bbox=bboxstyle, **Ar_tparams1)\n",
      "TransCANICAI = ax.text(0.5,0.08, \"IME / ONU coerc.\\nInsur. control. par Etat tiers.\\nEntite non-etat. depuis ter. etran.\\nSecession\", \n",
      "                       color=Color[1], rotation=0., bbox=bboxstyle, **Ar_tparams1)\n",
      "TransCAICANI = ax.text(0.5,0.26, \"Discorde interieure\\nAccord paix avec etranger\", \n",
      "                       color=Color[2], rotation=0., bbox=bboxstyle, **Ar_tparams1)\n",
      "TransCAITr = ax.text(0.8,0.55, \"Discorde interieure\\n Accord paix avec etranger\", \n",
      "                     color=Color[2], rotation=-60, bbox=bboxstyle, **Ar_tparams1)\n",
      "TransTrCAI = ax.text(0.65,0.50, \"IME / ONU coerc.\\nEntit. non-etat. dep. ter. etran.\\nInsur. pilotes par etran.\", \n",
      "                     color=Color[0], rotation=-60, bbox=bboxstyle, **Ar_tparams1)   \n",
      "    \n",
      "plt.draw()  \n",
      "\n",
      "#fig.savefig('Schema_Conflictualite.png', bbox_inches=0)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 4
    },
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Frises Chronologiques"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "######## Th\u00e9orie des RI : Vue d'ensemble ###########\n",
      "\n",
      "figW, figH = 17, 8\n",
      "figdpi = 80\n",
      "fig = plt.figure(facecolor=\"w\",figsize=(figW,figH), dpi=figdpi)\n",
      "axcolor = 'w'\n",
      "ax = plt.axes([0, 0, 1, 1],frameon=False, axisbg=axcolor)\n",
      "ax.axis('off')\n",
      "\n",
      "Xmin, Xmax = 1900,2014\n",
      "Ymin, Ymax = 0, 10\n",
      "DX, DY = Xmax-Xmin, Ymax-Ymin\n",
      "LimY1 = Ymax-DY/4.\n",
      "ax.set_xlim(Xmin,Xmax)\n",
      "ax.set_ylim(Ymin,Ymax)\n",
      "\n",
      "Ec = [(1.,1.,1.,1.), (0.,0.,0.,1.), (0.8,0.8,0.8,1.) ]\n",
      "Fc = [(1.,1.,1.,1.), (0.,0.,0.,1.), (0.8,0.8,0.8,1.), (1.,0.8,0.8,1.), (0.8,1.,0.8,1.), (0.8,0.8,1.,1.), (0.,0.8,0.8,1.), (0.8,0.,0.8,1.), (0.8,0.8,0.,1.) ] \n",
      "Boxstyle = [\"square,pad=0.0\", \"round,pad=0.0,rounding_size=0.5\", \"round,pad=0.5,rounding_size=0.5\"]\n",
      "FSize = [8, 10, 12, 15, 18, 20]\n",
      "FontDict = {'va':'center','ha':'center'}\n",
      "\n",
      "################## Debats\n",
      "RotDeb = 60.\n",
      "X1, X2, Y1, Y2 = 1918, 1939, LimY1, Ymax\n",
      "Bb_Deb = mtransforms.Bbox([[X1, Y1], [X2, Y2]])\n",
      "p_Deb = mpatches.FancyBboxPatch((Bb_Deb.xmin, Bb_Deb.ymin), abs(Bb_Deb.width), abs(Bb_Deb.height),boxstyle=Boxstyle[0],ec=Ec[1],fc=Fc[2], zorder=1.)\n",
      "t_Deb = ax.text((X1+X2)/2.,(Y1+Y2)/2.,r'\\underline{$1^{ier}$ debat :}\\\\\"Pourquoi ?\"\\\\$=>$ Realistes vs Idealistes', size=FSize[2], color='k', rotation=RotDeb,**FontDict)\n",
      "ax.add_patch(p_Deb)\n",
      "\n",
      "X1, X2, Y1, Y2 = 1955, 1965, LimY1, Ymax\n",
      "Bb_Deb = mtransforms.Bbox([[X1, Y1], [X2, Y2]])\n",
      "p_Deb = mpatches.FancyBboxPatch((Bb_Deb.xmin, Bb_Deb.ymin), abs(Bb_Deb.width), abs(Bb_Deb.height),boxstyle=Boxstyle[0],ec=Ec[1],fc=Fc[2], zorder=1.)\n",
      "t_Deb = ax.text((X1+X2)/2.,(Y1+Y2)/2.,r'\\underline{$2^{ieme}$ debat :}\\\\\"Comment ?\"\\\\$=>$ Behaviouralistes', size=FSize[2], color='k', rotation=RotDeb,**FontDict)\n",
      "ax.add_patch(p_Deb)\n",
      "\n",
      "X1, X2, Y1, Y2 = 1970, 1980, LimY1, Ymax\n",
      "Bb_Deb = mtransforms.Bbox([[X1, Y1], [X2, Y2]])\n",
      "p_Deb = mpatches.FancyBboxPatch((Bb_Deb.xmin, Bb_Deb.ymin), abs(Bb_Deb.width), abs(Bb_Deb.height),boxstyle=Boxstyle[0],ec=Ec[1],fc=Fc[2], zorder=1.)\n",
      "t_Deb = ax.text((X1+X2)/2.,(Y1+Y2)/2.,r'\\underline{$3^{ieme}$ debat :}\\\\\"Sur quoi ?\"\\\\$=>$ Neo-Realistes vs Globalistes', size=FSize[2], color='k', rotation=RotDeb,**FontDict)\n",
      "ax.add_patch(p_Deb)\n",
      "\n",
      "X1, X2, Y1, Y2 = 1995, 2005, LimY1, Ymax\n",
      "Bb_Deb = mtransforms.Bbox([[X1, Y1], [X2, Y2]])\n",
      "p_Deb = mpatches.FancyBboxPatch((Bb_Deb.xmin, Bb_Deb.ymin), abs(Bb_Deb.width), abs(Bb_Deb.height),boxstyle=Boxstyle[0],ec=Ec[1],fc=Fc[2], zorder=1.)\n",
      "t_Deb = ax.text((X1+X2)/2.,(Y1+Y2)/2.,r'\\underline{$4^{ieme}$ debat :}\\\\\"Faisable ?\"\\\\$=>$ (Post-)positivistes', size=FSize[2], color='k', rotation=RotDeb,**FontDict)\n",
      "ax.add_patch(p_Deb)\n",
      "\n",
      "###################### Courants\n",
      "Inc = DY/10.\n",
      "X1, X2, Y1, Y2 = 1900, 2014, LimY1-Inc, LimY1\n",
      "Bb_Deb = mtransforms.Bbox([[X1, Y1], [X2, Y2]])\n",
      "p_Deb = mpatches.FancyBboxPatch((Bb_Deb.xmin, Bb_Deb.ymin), abs(Bb_Deb.width), abs(Bb_Deb.height),boxstyle=Boxstyle[0],ec=Ec[1],fc=Fc[3], zorder=1.)\n",
      "t_Deb = ax.text((X1+X2)/2.,(Y1+Y2)/2.,r'\\underline{Realisme :}', size=FSize[2], color='k', rotation=0,**FontDict)\n",
      "ax.add_patch(p_Deb)\n",
      "\n",
      "X1, X2, Y1, Y2 = 1918, 2014, LimY1-2.*Inc, LimY1-Inc\n",
      "Bb_Deb = mtransforms.Bbox([[X1, Y1], [X2, Y2]])\n",
      "p_Deb = mpatches.FancyBboxPatch((Bb_Deb.xmin, Bb_Deb.ymin), abs(Bb_Deb.width), abs(Bb_Deb.height),boxstyle=Boxstyle[0],ec=Ec[1],fc=Fc[4], zorder=1.)\n",
      "t_Deb = ax.text((X1+X2)/2.,(Y1+Y2)/2.,r'\\underline{Liberalisme :}', size=FSize[2], color='k', rotation=0,**FontDict)\n",
      "ax.add_patch(p_Deb)\n",
      "\n",
      "X1, X2, Y1, Y2 = 1970, 2014, LimY1-3.*Inc, LimY1-2.*Inc\n",
      "Bb_Deb = mtransforms.Bbox([[X1, Y1], [X2, Y2]])\n",
      "p_Deb = mpatches.FancyBboxPatch((Bb_Deb.xmin, Bb_Deb.ymin), abs(Bb_Deb.width), abs(Bb_Deb.height),boxstyle=Boxstyle[0],ec=Ec[1],fc=Fc[5], zorder=1.)\n",
      "t_Deb = ax.text((X1+X2)/2.,(Y1+Y2)/2.,r'\\underline{Transnationalisme :}', size=FSize[2], color='k', rotation=0,**FontDict)\n",
      "ax.add_patch(p_Deb)\n",
      "\n",
      "X1, X2, Y1, Y2 = 1970, 2014, LimY1-4.*Inc, LimY1-3.*Inc\n",
      "Bb_Deb = mtransforms.Bbox([[X1, Y1], [X2, Y2]])\n",
      "p_Deb = mpatches.FancyBboxPatch((Bb_Deb.xmin, Bb_Deb.ymin), abs(Bb_Deb.width), abs(Bb_Deb.height),boxstyle=Boxstyle[0],ec=Ec[1],fc=Fc[6], zorder=1.)\n",
      "t_Deb = ax.text((X1+X2)/2.,(Y1+Y2)/2.,r'\\underline{Marxisme :}', size=FSize[2], color='k', rotation=0,**FontDict)\n",
      "ax.add_patch(p_Deb)\n",
      "\n",
      "X1, X2, Y1, Y2 = 1990, 2014, LimY1-5.*Inc, LimY1-4.*Inc\n",
      "Bb_Deb = mtransforms.Bbox([[X1, Y1], [X2, Y2]])\n",
      "p_Deb = mpatches.FancyBboxPatch((Bb_Deb.xmin, Bb_Deb.ymin), abs(Bb_Deb.width), abs(Bb_Deb.height),boxstyle=Boxstyle[0],ec=Ec[1],fc=Fc[7], zorder=1.)\n",
      "t_Deb = ax.text((X1+X2)/2.,(Y1+Y2)/2.,r'\\underline{Approches radicales :}', size=FSize[2], color='k', rotation=0,**FontDict)\n",
      "ax.add_patch(p_Deb)\n",
      "\n",
      "X1, X2, Y1, Y2 = 2000, 2014, LimY1-6.*Inc, LimY1-5.*Inc\n",
      "Bb_Deb = mtransforms.Bbox([[X1, Y1], [X2, Y2]])\n",
      "p_Deb = mpatches.FancyBboxPatch((Bb_Deb.xmin, Bb_Deb.ymin), abs(Bb_Deb.width), abs(Bb_Deb.height),boxstyle=Boxstyle[0],ec=Ec[1],fc=Fc[8], zorder=1.)\n",
      "t_Deb = ax.text((X1+X2)/2.,(Y1+Y2)/2.,r'\\underline{Constructivisme :}', size=FSize[2], color='k', rotation=0,**FontDict)\n",
      "ax.add_patch(p_Deb)\n",
      "\n",
      "X1, X2, Y1, Y2 = 1914, 1918, Ymax-2.*DY/3., LimY1\n",
      "Bb_Deb = mtransforms.Bbox([[X1, Y1], [X2, Y2]])\n",
      "p_Deb = mpatches.FancyBboxPatch((Bb_Deb.xmin, Bb_Deb.ymin), abs(Bb_Deb.width), abs(Bb_Deb.height),boxstyle=Boxstyle[0],ec=Ec[1],fc='y', zorder=1.)\n",
      "t_Deb = ax.text((X1+X2)/2.,(Y1+Y2)/2.,r'\\underline{$1^{iere}$ Guerre Mondiale}', size=FSize[3], color='k', rotation=80.,**FontDict)\n",
      "ax.add_patch(p_Deb)\n",
      "\n",
      "X1, X2, Y1, Y2 = 1939, 1945, Ymax-2.*DY/3., LimY1\n",
      "Bb_Deb = mtransforms.Bbox([[X1, Y1], [X2, Y2]])\n",
      "p_Deb = mpatches.FancyBboxPatch((Bb_Deb.xmin, Bb_Deb.ymin), abs(Bb_Deb.width), abs(Bb_Deb.height),boxstyle=Boxstyle[0],ec=Ec[1],fc='y', zorder=1.)\n",
      "t_Deb = ax.text((X1+X2)/2.,(Y1+Y2)/2.,r'\\underline{$2^{ieme}$ Guerre Mondiale}', size=FSize[3], color='k', rotation=80.,**FontDict)\n",
      "ax.add_patch(p_Deb)\n",
      "\n",
      "\n",
      "####### Auteurs ##########\n",
      "\n",
      "class Auteurs():\n",
      "    def __init__(self,Name,Birth,Death,Publis):\n",
      "        self.Name, self.BD, self.Publis = Name, Birth+\"-\"+Death, Publis\n",
      "\n",
      "class Publis():\n",
      "    def __init__(self,Title,Trend,Year):\n",
      "        self.Title, self.Trend, self.Year = Title, Trend, Year\n",
      "        \n",
      "HM1 = Publis(\"In Defense of the National Interest\",\"Realiste\",1951)\n",
      "HM = Auteurs(\"H. Morgenthau\",\"1904\",\"1980\",[HM1])\n",
      "RA1 = Publis(\"Qu'est-ce qu'une th\u00e9orie des Relations Internationales\",\"Realiste-Liberal\",1967)\n",
      "RA = Auteurs(\"R. Aron\",\"1905\",\"1983\",[RA1])\n",
      "KW1 = Publis(\"Theory of international politics\", \"Neo-Realiste\", 1971)   \n",
      "KW = Auteurs(\"K. Waltz\",\"1924\",\"2013\",[KW1])\n",
      "JM1 = Publis(\"The tragedy of Great Power Politics\",\"Realiste offensif\",2001)\n",
      "JM = Auteurs(\"J. Mearsheimer\",\"1947\",\"...\",[JM1])\n",
      "RG1 = Publis(\"War and Change in World Politics\",\"Neo-Realiste\",1981)\n",
      "RG = Auteurs(\"R. Gilpin\",\"1930\",\"...\",[RG1])\n",
      "\n",
      "Aut = [HM,RA,KW,JM,RG]    \n",
      "Ar = dict(arrowstyle=\"-\",connectionstyle=\"arc3,rad=0.0\")\n",
      "for Au in Aut:\n",
      "    for Pub in Au.Publis:\n",
      "        ax.plot(Pub.Year,(Ymax+Ymin)/2.,marker=\"o\",color=\"k\")\n",
      "        YT = Ymax-5*DY/6.-DY/100.\n",
      "        t = ax.text(Pub.Year,YT,Au.Name+\" (\"+str(Pub.Year)+\")\",rotation=30.,ha=\"right\",va=\"top\")\n",
      "        ax.annotate(\"\", xy=(1.,1.), xycoords=t, xytext=(Pub.Year,(Ymin+Ymax)/2.), textcoords='data',arrowprops=Ar)\n",
      "\n",
      "plt.draw()\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 108
    },
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "ToFu"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# Global picture, v1\n",
      "\n",
      "from matplotlib._png import read_png\n",
      "from matplotlib.cbook import get_sample_data\n",
      "from matplotlib.offsetbox import TextArea, DrawingArea, OffsetImage, AnnotationBbox\n",
      "\n",
      "figW, figH = 14.5, 9\n",
      "figdpi = 80\n",
      "fig = plt.figure(facecolor=\"w\",figsize=(figW,figH), dpi=figdpi)\n",
      "axcolor = 'w'\n",
      "ax = plt.axes([0, 0, 1, 1],frameon=False, axisbg=axcolor)\n",
      "ax.axis('off')\n",
      "\n",
      "BoxS, BoxToFu, Fc, Ec, Alpha = \"round,pad=0.01\", \"round,pad=0.02\", (1.,0.5,1.,0.2), (1.,0.2,1.,1.), 0.5\n",
      "Title_tparams = {'size':15,'ha':'center', 'va':'bottom', 'family':'sans-serif','fontweight':'bold','fontstyle':'italic'}\n",
      "Com_tparams = {'size':10,'ha':'center', 'va':'top', 'family':'sans-serif','fontweight':'normal','fontstyle':'italic'}\n",
      "Ann_tparams = {'size':13,'ha':'center', 'va':'bottom', 'family':'sans-serif','fontweight':'normal','fontstyle':'italic'}\n",
      "Ar_tparams1 = {'size':10,'ha':'center', 'va':'center', 'family':'sans-serif','fontweight':'normal','fontstyle':'italic'}\n",
      "Ar_tparams2 = {'size':10,'ha':'center', 'va':'bottom', 'family':'sans-serif','fontweight':'normal','fontstyle':'italic'}\n",
      "Ar_tparams3 = {'size':10,'ha':'center', 'va':'bottom', 'family':'sans-serif','fontweight':'normal','fontstyle':'italic'}\n",
      "arrowprops = dict(arrowstyle=\"fancy,head_length=1,head_width=1,tail_width=0.5\",mutation_scale=10)\n",
      "\n",
      "Title, Com, Pos, Color, Box, ls = [], [], [], [], [], []       \n",
      "\n",
      "Title.append(r\"ToFu\\_Geom v0.1\")\n",
      "Com.append(\"3D geometry of the diagnostic\\nComputes geometrical quantities\\nProvides visualisation tools\")\n",
      "Pos.append((0.27,0.85)), Color.append((0.,0.,0.,1.)), Box.append(True), ls.append('solid')\n",
      "\n",
      "Title.append(r\"ToFu\\_Mesh v0.1\")\n",
      "Com.append(\"B-splines + variable mesh\\nProvides visualisation tools\")\n",
      "Pos.append((0.26,0.46)), Color.append((0.,0.,0.,1.)), Box.append(True), ls.append('solid')\n",
      "\n",
      "Title.append(r\"ToFu\\_MatComp v0.1\")\n",
      "Com.append(\"Geometry matrix computation\\n3D or LOS approach\\nFitting tools for synthetic diag.\\nProvides visualisation tools\")\n",
      "Pos.append((0.45,0.65)), Color.append((0.,0.,0.,1.)), Box.append(True), ls.append('solid')\n",
      "\n",
      "Title.append(r\"ToFu\\_Inv v0\")\n",
      "Com.append(\"Various algorithms available\\nProvides visualisation tools\")\n",
      "Pos.append((0.58,0.45)), Color.append((0.,0.,0.,1.)), Box.append(True), ls.append('solid')\n",
      "\n",
      "Title.append(r\"ToFu\\_Data\")\n",
      "Com.append(\"Data treatment\\nVisualisation\")\n",
      "Pos.append((0.60,0.60)), Color.append((0.,0.,0.,1.)), Box.append(True), ls.append('solid')\n",
      "\n",
      "Title.append(r\"General\\_Geom v0.1\")\n",
      "Com.append(\"Provides general geometry tools\")\n",
      "Pos.append((0.27,0.63)), Color.append((0.,0.,0.,1.)), Box.append(True), ls.append('dashed')\n",
      "\n",
      "Title.append(r\"Pigasus / CAID\")\n",
      "Com.append(\"Advanced adaptative mesh\")\n",
      "Pos.append((0.35,0.30)), Color.append((0.,1.,0.,1.)), Box.append(True), ls.append('solid')\n",
      "\n",
      "Title.append(r\"Experimental measurements\")\n",
      "Com.append(\"+ constraints (e.g: magnetic field)\")\n",
      "Pos.append((0.90,0.55)), Color.append((0.,0.,1.,1.)), Box.append(True), ls.append('solid')\n",
      "\n",
      "Title.append(r\"Simulated emissivity\")\n",
      "Com.append(\"Impurity transport (TRANSP...)\\nMHD code (JOREK...)\\nGirokinetics (GYSELA...)\\nFast electrons (LUKE...)\\nOthers...\")\n",
      "Pos.append((0.40,0.15)), Color.append((0.,0.,1.,1.)), Box.append(True), ls.append('solid')\n",
      "\n",
      "Title.append(r\"Inversions + GUI\")\n",
      "Com.append(\"(from experiment)\")\n",
      "Pos.append((0.64,0.23)), Color.append((1.,0.,0.,1.)), Box.append(True), ls.append('solid')\n",
      "\n",
      "Title.append(r\"Synthetic measurements\")\n",
      "Com.append(\"(from simulated emissivity)\")\n",
      "Pos.append((0.90,0.86)), Color.append((1.,0.,0.,1.)), Box.append(True), ls.append('solid')\n",
      "\n",
      "Title.append(r\"Input geometry\")\n",
      "Com.append(\"(position of all detectors)\")\n",
      "Pos.append((0.09,0.85)), Color.append((0.,0.,1.,1.)), Box.append(True), ls.append('solid')\n",
      "\n",
      "Title.append(r\"Discretisation\")\n",
      "Com.append(\"(mesh + basis functions)\")\n",
      "Pos.append((0.09,0.45)), Color.append((0.,0.,1.,1.)), Box.append(True), ls.append('solid')\n",
      "\n",
      "Title.append(r\"Choice of inversion method\")\n",
      "Com.append(\"(Phillips-Tikhonov type)\")\n",
      "Pos.append((0.90,0.42)), Color.append((0.,0.,1.,1.)), Box.append(True), ls.append('solid')\n",
      "\n",
      "Title.append(r\"ToFu\\_PathFile\")\n",
      "Com.append(\"(small module handling paths/files\\nmay be called by any module)\")\n",
      "Pos.append((0.63,0.94)), Color.append((0.,0.,0.,1.)), Box.append(True), ls.append('dashed')\n",
      "\n",
      "Title.append(r\"ToFu\\_Default\")\n",
      "Com.append(\"(Default parameters storage\\nfor computation and plotting)\")\n",
      "Pos.append((0.63,0.84)), Color.append((0.,0.,0.,1.)), Box.append(True), ls.append('dashed')\n",
      "\n",
      "Title.append(r\"ToFu\\_Load\")\n",
      "Com.append(\"Tokamak-specific\\ndata loading\\n(AUG\\nJET\\nWEST\\nCompass...)\")\n",
      "Pos.append((0.72,0.64)), Color.append((0.,0.,0.,1.)), Box.append(True), ls.append('solid')\n",
      "\n",
      "TxTitle, TxCom, bb, fb = [], [], [], []\n",
      "Zorder = [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,101]\n",
      "for i in range(0,len(Title)):\n",
      "    TxTitle.append(ax.text(Pos[i][0],Pos[i][1], Title[i], color=Color[i], zorder=Zorder[i], **Title_tparams))\n",
      "    TxCom.append(ax.text(Pos[i][0],Pos[i][1]-0.01, Com[i], color=Color[i], zorder=Zorder[i], **Com_tparams))\n",
      "\n",
      "plt.draw()\n",
      "\n",
      "RootPath = \"/Users/didiervezinet/Documents/Travail/Fusion/PostDoc_AUG/Python_ToFu/Figures/\"\n",
      "imf = [RootPath+\"Tutor_Geom.png\",RootPath+\"Tutor_Mesh.png\",RootPath+\"Tutor_Emiss.png\", RootPath+\"Tutor_Emiss.png\", RootPath+\"Tutor_Meas.png\", RootPath+\"Tutor_Meas.png\"]\n",
      "imz = [0.16, 0.16, 0.2, 0.2, 0.3, 0.3]\n",
      "imP = [(0.37,0.84), (0.35,0.45), (0.52,0.11), (0.63,0.11), (0.89,0.77), (0.89,0.64)]\n",
      "\n",
      "imb, ab = [], []\n",
      "for ii in range(0,len(imf)):\n",
      "    fn = get_sample_data(imf[ii], asfileobj=False)\n",
      "    arr_lena = read_png(fn)\n",
      "    imb.append(OffsetImage(arr_lena, zoom=imz[ii]))\n",
      "    ab.append(AnnotationBbox(imb[ii], imP[ii],xybox=imP[ii],xycoords='data',boxcoords=\"data\",pad=0., bboxprops={'ls':None,'ec':'w'}))\n",
      "    ax.add_artist(ab[ii])\n",
      "\n",
      "Im = [[ab[0]],[ab[1]],[],[],[],[],[],[ab[5]],[ab[2]],[ab[3]],[ab[4]],[],[],[],[],[],[]]\n",
      "Zorder = [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,100]\n",
      "for i in range(0,len(Title)):\n",
      "    Txpatch = TxCom[i].get_window_extent()   \n",
      "    Lim = Txpatch.transformed(ax.transData.inverted())\n",
      "    DX = Lim.xmax-Lim.xmin\n",
      "    #TxCom[i].set_x(Pos[i][0]-DX/2.)\n",
      "    bb.append(common_bbox(ax, [TxTitle[i], TxCom[i]]+Im[i]))\n",
      "    fb.append(draw_bbox_fancy(ax, bb[i], False, True, BoxS, Color[i], 'w', ls=ls[i],zorder=Zorder[i]))\n",
      "    \n",
      "TxToFu = ax.text(0.45,0.92, r\"ToFu\", color='k', size=30,ha='center',va='bottom') \n",
      "bbToFu = common_bbox(ax, [TxToFu]+TxTitle[:6]+TxCom[:6]+TxTitle[14:16]+TxCom[14:16]+ab[:2])\n",
      "fbToFu = draw_bbox_fancy(ax, bbToFu, False, True, BoxToFu, 'k', 'w',lw=2.,zorder=0)    \n",
      "\n",
      "ArCol, ArAng, ArBox, ArPos = [], [], [], []\n",
      "\n",
      "ArCol.append('k'), ArBox.append([bb[5],bb[0]]), ArAng.append((55,80)), ArPos.append([(0.5,1.),(0.5,0.)])\n",
      "#ArCol.append('k'), ArBox.append([bb[5],bb[1]]), ArAng.append((-55,100)), ArPos.append([(0.5,0.),(0.5,1.)])\n",
      "ArCol.append('k'), ArBox.append([bb[5],bb[2]]), ArAng.append((10,170)), ArPos.append([(1.,0.5),(0.,0.5)])\n",
      "ArCol.append(Color[0]), ArBox.append([bb[0],bb[2]]), ArAng.append((-20,110)), ArPos.append([(1.,0.5),(0.2,1.)])\n",
      "ArCol.append('r'), ArBox.append([bb[0],bb[10]]), ArAng.append((-20,180)), ArPos.append([(1.,0.1),(0.,0.3)])\n",
      "ArCol.append(Color[1]), ArBox.append([bb[1],bb[2]]), ArAng.append((20,-110)), ArPos.append([(1.,0.5),(0.2,0.)])\n",
      "ArCol.append(Color[2]), ArBox.append([bb[2],bb[3]]), ArAng.append((-20,110)), ArPos.append([(1.,0.3),(0.3,1.)])\n",
      "ArCol.append(Color[7]), ArBox.append([bb[7],bb[4]]), ArAng.append((160,20)), ArPos.append([(0.,0.6),(1.,0.6)])\n",
      "ArCol.append(Color[4]), ArBox.append([bb[4],bb[3]]), ArAng.append((-140,90)), ArPos.append([(0.5,0.),(0.6,1.)])\n",
      "ArCol.append('r'), ArBox.append([bb[4],bb[7]]), ArAng.append((-20,-160)), ArPos.append([(1.,0.4),(0.,0.4)])\n",
      "ArCol.append('r'), ArBox.append([bb[3],bb[9]]), ArAng.append((-100,130)), ArPos.append([(0.5,0.),(0.4,1.)])\n",
      "ArCol.append('r'), ArBox.append([bb[2],bb[10]]), ArAng.append((40,-180)), ArPos.append([(1.,0.7),(0.,0.3)])\n",
      "ArCol.append('b'), ArBox.append([bb[11],bb[0]]), ArAng.append((0,160)), ArPos.append([(1.,0.5),(0.,0.5)])\n",
      "ArCol.append('b'), ArBox.append([bb[12],bb[1]]), ArAng.append((0,160)), ArPos.append([(1.,0.5),(0.,0.5)])\n",
      "ArCol.append('b'), ArBox.append([bb[8],bb[2]]), ArAng.append((100,-130)), ArPos.append([(0.35,1.),(0.5,0.)])\n",
      "ArCol.append('b'), ArBox.append([bb[8],bb[1]]), ArAng.append((150,-120)), ArPos.append([(0.,0.5),(0.4,0.)])\n",
      "ArCol.append('b'), ArBox.append([bb[13],bb[3]]), ArAng.append((160,20)), ArPos.append([(0.,0.5),(1.,0.5)])\n",
      "ArCol.append('b'), ArBox.append([bb[8],bb[0]]), ArAng.append((163,-148)), ArPos.append([(0.,0.5),(0.,0.1)])\n",
      "\n",
      "Ar = []\n",
      "for i in range(0,len(ArCol)):\n",
      "    arrowpropsi = arrowprops\n",
      "    arrowpropsi['color'] = ArCol[i]\n",
      "    arrowpropsi['connectionstyle'] = 'angle3,angleA=' + str(ArAng[i][0]) + ',angleB=' + str(ArAng[i][1])\n",
      "    Ar.append(link_fancyArrow(ax, ArBox[i][0], ArPos[i][0], ArBox[i][1], ArPos[i][1], arrowpropsi))\n",
      "    \n",
      "fb[6].set_zorder(100)\n",
      "TxTitle[6].set_zorder(101)\n",
      "TxCom[6].set_zorder(102)    \n",
      "\n",
      "In, In2 = ax.text(0.9,0.1, r\"Inputs\", color='b', **Title_tparams), ax.text(0.80,0.1, r\"R\", color='w', **Title_tparams)\n",
      "Out, Out2 = ax.text(0.9,0.05, r\"Outputs\", color='r', **Title_tparams), ax.text(0.80,0.05, r\"R\", color='w', **Title_tparams)\n",
      "arrowpropsi = arrowprops\n",
      "arrowpropsi['color'] = 'b'\n",
      "arrowpropsi['connectionstyle'] = 'angle3,angleA=' + str(170) + ',angleB=' + str(10)\n",
      "link_fancyArrow(ax, common_bbox(ax,[In]), (0.,0.5), common_bbox(ax,[In2]), (1.,0.5), arrowpropsi)\n",
      "arrowpropsi['color'] = 'r'\n",
      "arrowpropsi['connectionstyle'] = 'angle3,angleA=' + str(10) + ',angleB=' + str(170)\n",
      "link_fancyArrow(ax, common_bbox(ax,[Out2]), (1.,0.5), common_bbox(ax,[Out]), (0.,0.5), arrowpropsi)\n",
      "\n",
      "bbox_props = dict(boxstyle=\"round,pad=0.2\", fc=\"w\", ec=\"w\", lw=None)\n",
      "ax.text(0.125,0.23, r\"Direct\", color='b', bbox=bbox_props, **Ann_tparams)\n",
      "ax.text(0.19,0.23, r\"or\", color='b', bbox=bbox_props, **Ann_tparams)\n",
      "ax.text(0.27,0.223, r\"Projected\", color='b', bbox=bbox_props, **Ann_tparams)\n",
      "ax.text(0.34,0.23, r\"or\", color='b', bbox=bbox_props, **Ann_tparams)\n",
      "ax.text(0.40,0.23, r\"Built-in\", color='b', bbox=bbox_props, **Ann_tparams)\n",
      "\n",
      "plt.draw()  \n",
      "fig.savefig(\"/Users/didiervezinet/Documents/Travail/Fusion/PostDoc_AUG/Python_ToFu/Figures/Fig_Tutor_BigPicture_General.pdf\",frameon=None,bbox_inches=0)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 34
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# Global picture, v2 (Synthetic diagnostic)\n",
      "\n",
      "from matplotlib._png import read_png\n",
      "from matplotlib.cbook import get_sample_data\n",
      "from matplotlib.offsetbox import TextArea, DrawingArea, OffsetImage, AnnotationBbox\n",
      "\n",
      "figW, figH = 14.5, 9\n",
      "figdpi = 80\n",
      "fig = plt.figure(facecolor=\"w\",figsize=(figW,figH), dpi=figdpi)\n",
      "axcolor = 'w'\n",
      "ax = plt.axes([0, 0, 1, 1],frameon=False, axisbg=axcolor)\n",
      "ax.axis('off')\n",
      "\n",
      "BoxS, BoxToFu, Fc, Ec, Alpha = \"round,pad=0.01\", \"round,pad=0.02\", (1.,0.5,1.,0.2), (1.,0.2,1.,1.), 0.5\n",
      "Title_tparams = {'size':15,'ha':'center', 'va':'bottom', 'family':'sans-serif','fontweight':'bold','fontstyle':'italic'}\n",
      "Com_tparams = {'size':10,'ha':'center', 'va':'top', 'family':'sans-serif','fontweight':'normal','fontstyle':'italic'}\n",
      "Ann_tparams = {'size':13,'ha':'center', 'va':'bottom', 'family':'sans-serif','fontweight':'normal','fontstyle':'italic'}\n",
      "Ar_tparams1 = {'size':10,'ha':'center', 'va':'center', 'family':'sans-serif','fontweight':'normal','fontstyle':'italic'}\n",
      "Ar_tparams2 = {'size':10,'ha':'center', 'va':'bottom', 'family':'sans-serif','fontweight':'normal','fontstyle':'italic'}\n",
      "Ar_tparams3 = {'size':10,'ha':'center', 'va':'bottom', 'family':'sans-serif','fontweight':'normal','fontstyle':'italic'}\n",
      "arrowprops = dict(arrowstyle=\"fancy,head_length=1,head_width=1,tail_width=0.5\",mutation_scale=10)\n",
      "\n",
      "Title, Com, Pos, Color, Box, ls = [], [], [], [], [], []\n",
      "Grey = (0.9,0.9,0.9,1.)\n",
      "\n",
      "Title.append(r\"ToFu\\_Geom v0.1\")\n",
      "Com.append(\"3D geometry of the diagnostic\\nComputes geometrical quantities\\nProvides visualisation tools\")\n",
      "Pos.append((0.27,0.85)), Color.append((0.,0.,0.,1.)), Box.append(True), ls.append('solid')\n",
      "\n",
      "Title.append(r\"ToFu\\_Mesh v0.1\")\n",
      "Com.append(\"B-splines + variable mesh\\nProvides visualisation tools\")\n",
      "Pos.append((0.26,0.46)), Color.append((0.,0.,0.,1.)), Box.append(True), ls.append('solid')\n",
      "\n",
      "Title.append(r\"ToFu\\_MatComp v0.1\")\n",
      "Com.append(\"Geometry matrix computation\\n3D or LOS approach\\nFitting tools for synthetic diag.\\nProvides visualisation tools\")\n",
      "Pos.append((0.45,0.65)), Color.append((0.,0.,0.,1.)), Box.append(True), ls.append('solid')\n",
      "\n",
      "Title.append(r\"ToFu\\_Inv v0\")\n",
      "Com.append(\"Various algorithms available\\nProvides visualisation tools\")\n",
      "Pos.append((0.58,0.45)), Color.append(Grey), Box.append(True), ls.append('solid')\n",
      "\n",
      "Title.append(r\"ToFu\\_Data\")\n",
      "Com.append(\"Data treatment\\nVisualisation\")\n",
      "Pos.append((0.60,0.60)), Color.append((0.,0.,0.,1.)), Box.append(True), ls.append('solid')\n",
      "\n",
      "Title.append(r\"General\\_Geom v0.1\")\n",
      "Com.append(\"Provides general geometry tools\")\n",
      "Pos.append((0.27,0.63)), Color.append(Grey), Box.append(True), ls.append('dashed')\n",
      "\n",
      "Title.append(r\"Pigasus / CAID\")\n",
      "Com.append(\"Advanced adaptative mesh\")\n",
      "Pos.append((0.35,0.30)), Color.append((0.,1.,0.,1.)), Box.append(True), ls.append('solid')\n",
      "\n",
      "Title.append(r\"Experimental measurements\")\n",
      "Com.append(\"+ constraints (e.g: magnetic field)\")\n",
      "Pos.append((0.90,0.55)), Color.append((0.,0.,1.,1.)), Box.append(True), ls.append('solid')\n",
      "\n",
      "Title.append(r\"Simulated emissivity\")\n",
      "Com.append(\"Impurity transport (TRANSP...)\\nMHD code (JOREK...)\\nGirokinetics (GYSELA...)\\nFast electrons (LUKE...)\\nOthers...\")\n",
      "Pos.append((0.40,0.15)), Color.append((0.,0.,1.,1.)), Box.append(True), ls.append('solid')\n",
      "\n",
      "Title.append(r\"Inversions + GUI\")\n",
      "Com.append(\"(from experiment)\")\n",
      "Pos.append((0.64,0.23)), Color.append(Grey), Box.append(True), ls.append('solid')\n",
      "\n",
      "Title.append(r\"Synthetic measurements\")\n",
      "Com.append(\"(from simulated emissivity)\")\n",
      "Pos.append((0.90,0.86)), Color.append((1.,0.,0.,1.)), Box.append(True), ls.append('solid')\n",
      "\n",
      "Title.append(r\"Input geometry\")\n",
      "Com.append(\"(position of all detectors)\")\n",
      "Pos.append((0.09,0.85)), Color.append(Grey), Box.append(True), ls.append('solid')\n",
      "\n",
      "Title.append(r\"Discretisation\")\n",
      "Com.append(\"(mesh + basis functions)\")\n",
      "Pos.append((0.09,0.45)), Color.append(Grey), Box.append(True), ls.append('solid')\n",
      "\n",
      "Title.append(r\"Choice of inversion method\")\n",
      "Com.append(\"(Phillips-Tikhonov type)\")\n",
      "Pos.append((0.90,0.42)), Color.append(Grey), Box.append(True), ls.append('solid')\n",
      "\n",
      "Title.append(r\"ToFu\\_PathFile\")\n",
      "Com.append(\"(small module handling paths/files\\nmay be called by any module)\")\n",
      "Pos.append((0.63,0.94)), Color.append(Grey), Box.append(True), ls.append('dashed')\n",
      "\n",
      "Title.append(r\"ToFu\\_Default\")\n",
      "Com.append(\"(Default parameters storage\\nfor computation and plotting)\")\n",
      "Pos.append((0.63,0.84)), Color.append(Grey), Box.append(True), ls.append('dashed')\n",
      "\n",
      "Title.append(r\"ToFu\\_Load\")\n",
      "Com.append(\"Tokamak-specific\\ndata loading\\n(AUG\\nJET\\nWEST\\nCompass...)\")\n",
      "Pos.append((0.72,0.64)), Color.append((0.,0.,0.,1.)), Box.append(True), ls.append('solid')\n",
      "\n",
      "TxTitle, TxCom, bb, fb = [], [], [], []\n",
      "Zorder = [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,201]\n",
      "for i in range(0,len(Title)):\n",
      "    TxTitle.append(ax.text(Pos[i][0],Pos[i][1], Title[i], color=Color[i], **Title_tparams))\n",
      "    TxCom.append(ax.text(Pos[i][0],Pos[i][1]-0.01, Com[i], color=Color[i], **Com_tparams))\n",
      "\n",
      "plt.draw()\n",
      "\n",
      "RootPath = \"/Users/didiervezinet/Documents/Travail/Fusion/PostDoc_AUG/Python_ToFu/Figures/\"\n",
      "imf = [RootPath+\"Tutor_Geom.png\",RootPath+\"Tutor_Mesh.png\",RootPath+\"Tutor_Emiss.png\", RootPath+\"Tutor_Emiss.png\", RootPath+\"Tutor_Meas.png\", RootPath+\"Tutor_Meas.png\"]\n",
      "imz = [0.16, 0.16, 0.2, 0.2, 0.3, 0.3]\n",
      "imP = [(0.37,0.84), (0.35,0.45), (0.52,0.11), (0.63,0.11), (0.89,0.77), (0.89,0.64)]\n",
      "\n",
      "imb, ab = [], []\n",
      "for ii in range(0,len(imf)):\n",
      "    fn = get_sample_data(imf[ii], asfileobj=False)\n",
      "    arr_lena = read_png(fn)\n",
      "    imb.append(OffsetImage(arr_lena, zoom=imz[ii]))\n",
      "    ab.append(AnnotationBbox(imb[ii], imP[ii],xybox=imP[ii],xycoords='data',boxcoords=\"data\",pad=0., bboxprops={'ls':None,'ec':'w'}))\n",
      "    ax.add_artist(ab[ii])\n",
      "\n",
      "plt.draw()\n",
      "Patchdict = dict(alpha=0.9, ec='w', fc='w', visible=True)\n",
      "bla = hide_image(ab[0].patch, ax, Patchdict)\n",
      "bla = hide_image(ab[3].patch, ax, Patchdict)\n",
      "\n",
      "Im = [[ab[0]],[ab[1]],[],[],[],[],[],[ab[5]],[ab[2]],[ab[3]],[ab[4]],[],[],[],[],[],[]]\n",
      "Zorder = [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,200]\n",
      "for i in range(0,len(Title)):\n",
      "    Txpatch = TxCom[i].get_window_extent()   \n",
      "    Lim = Txpatch.transformed(ax.transData.inverted())\n",
      "    DX = Lim.xmax-Lim.xmin\n",
      "    #TxCom[i].set_x(Pos[i][0]-DX/2.)\n",
      "    bb.append(common_bbox(ax, [TxTitle[i], TxCom[i]]+Im[i]))\n",
      "    fb.append(draw_bbox_fancy(ax, bb[i], False, True, BoxS, Color[i], 'w', ls=ls[i]))\n",
      "    \n",
      "TxToFu = ax.text(0.45,0.92, r\"ToFu\", color='k', size=30,ha='center',va='bottom')\n",
      "bbToFu = common_bbox(ax, [TxToFu]+TxTitle[:6]+TxCom[:6]+TxTitle[14:16]+TxCom[14:16]+ab[:2])\n",
      "fbToFu = draw_bbox_fancy(ax, bbToFu, False, True, BoxToFu, 'k', 'w',lw=2.,zorder=0)    \n",
      "\n",
      "ArCol, ArAng, ArBox, ArPos = [], [], [], []\n",
      "\n",
      "ArCol.append(Grey), ArBox.append([bb[5],bb[0]]), ArAng.append((55,80)), ArPos.append([(0.5,1.),(0.5,0.)])\n",
      "#ArCol.append(Grey), ArBox.append([bb[5],bb[1]]), ArAng.append((-55,100)), ArPos.append([(0.5,0.),(0.5,1.)])\n",
      "ArCol.append(Grey), ArBox.append([bb[5],bb[2]]), ArAng.append((10,170)), ArPos.append([(1.,0.5),(0.,0.5)])\n",
      "ArCol.append(Grey), ArBox.append([bb[0],bb[2]]), ArAng.append((-20,110)), ArPos.append([(1.,0.5),(0.2,1.)])\n",
      "ArCol.append('r'), ArBox.append([bb[0],bb[10]]), ArAng.append((-20,180)), ArPos.append([(1.,0.1),(0.,0.3)])\n",
      "ArCol.append('k'), ArBox.append([bb[1],bb[2]]), ArAng.append((20,-110)), ArPos.append([(1.,0.5),(0.2,0.)])\n",
      "ArCol.append(Grey), ArBox.append([bb[2],bb[3]]), ArAng.append((-20,110)), ArPos.append([(1.,0.3),(0.3,1.)])\n",
      "ArCol.append(Color[7]), ArBox.append([bb[7],bb[4]]), ArAng.append((160,20)), ArPos.append([(0.,0.6),(1.,0.6)])\n",
      "ArCol.append(Grey), ArBox.append([bb[4],bb[3]]), ArAng.append((-140,90)), ArPos.append([(0.5,0.),(0.6,1.)])\n",
      "ArCol.append('r'), ArBox.append([bb[4],bb[7]]), ArAng.append((-20,-160)), ArPos.append([(1.,0.4),(0.,0.4)])\n",
      "ArCol.append(Grey), ArBox.append([bb[3],bb[9]]), ArAng.append((-100,130)), ArPos.append([(0.5,0.),(0.4,1.)])\n",
      "ArCol.append('r'), ArBox.append([bb[2],bb[10]]), ArAng.append((40,-180)), ArPos.append([(1.,0.7),(0.,0.3)])\n",
      "ArCol.append(Grey), ArBox.append([bb[11],bb[0]]), ArAng.append((0,160)), ArPos.append([(1.,0.5),(0.,0.5)])\n",
      "ArCol.append(Grey), ArBox.append([bb[12],bb[1]]), ArAng.append((0,160)), ArPos.append([(1.,0.5),(0.,0.5)])\n",
      "ArCol.append('b'), ArBox.append([bb[8],bb[2]]), ArAng.append((100,-130)), ArPos.append([(0.35,1.),(0.5,0.)])\n",
      "ArCol.append('b'), ArBox.append([bb[8],bb[1]]), ArAng.append((150,-120)), ArPos.append([(0.,0.5),(0.4,0.)])\n",
      "ArCol.append(Grey), ArBox.append([bb[13],bb[3]]), ArAng.append((160,20)), ArPos.append([(0.,0.5),(1.,0.5)])\n",
      "ArCol.append('b'), ArBox.append([bb[8],bb[0]]), ArAng.append((163,-148)), ArPos.append([(0.,0.5),(0.,0.1)])\n",
      "\n",
      "Ar = []\n",
      "for i in range(0,len(ArCol)):\n",
      "    arrowpropsi = arrowprops\n",
      "    arrowpropsi['color'] = ArCol[i]\n",
      "    arrowpropsi['connectionstyle'] = 'angle3,angleA=' + str(ArAng[i][0]) + ',angleB=' + str(ArAng[i][1])\n",
      "    Ar.append(link_fancyArrow(ax, ArBox[i][0], ArPos[i][0], ArBox[i][1], ArPos[i][1], arrowpropsi))\n",
      "    \n",
      "fb[6].set_zorder(100)\n",
      "TxTitle[6].set_zorder(101)\n",
      "TxCom[6].set_zorder(102)    \n",
      "fb[16].set_zorder(200)\n",
      "TxTitle[16].set_zorder(201)\n",
      "TxCom[16].set_zorder(202) \n",
      "\n",
      "In, In2 = ax.text(0.9,0.1, r\"Inputs\", color='b', **Title_tparams), ax.text(0.80,0.1, r\"R\", color='w', **Title_tparams)\n",
      "Out, Out2 = ax.text(0.9,0.05, r\"Outputs\", color='r', **Title_tparams), ax.text(0.80,0.05, r\"R\", color='w', **Title_tparams)\n",
      "arrowpropsi = arrowprops\n",
      "arrowpropsi['color'] = 'b'\n",
      "arrowpropsi['connectionstyle'] = 'angle3,angleA=' + str(170) + ',angleB=' + str(10)\n",
      "link_fancyArrow(ax, common_bbox(ax,[In]), (0.,0.5), common_bbox(ax,[In2]), (1.,0.5), arrowpropsi)\n",
      "arrowpropsi['color'] = 'r'\n",
      "arrowpropsi['connectionstyle'] = 'angle3,angleA=' + str(10) + ',angleB=' + str(170)\n",
      "link_fancyArrow(ax, common_bbox(ax,[Out2]), (1.,0.5), common_bbox(ax,[Out]), (0.,0.5), arrowpropsi)\n",
      "\n",
      "bbox_props = dict(boxstyle=\"round,pad=0.2\", fc=\"w\", ec=\"w\", lw=None)\n",
      "ax.text(0.125,0.23, r\"Direct\", color='b', bbox=bbox_props, **Ann_tparams)\n",
      "ax.text(0.19,0.23, r\"or\", color='b', bbox=bbox_props, **Ann_tparams)\n",
      "ax.text(0.27,0.223, r\"Projected\", color='b', bbox=bbox_props, **Ann_tparams)\n",
      "ax.text(0.34,0.23, r\"or\", color='b', bbox=bbox_props, **Ann_tparams)\n",
      "ax.text(0.40,0.23, r\"Built-in\", color='b', bbox=bbox_props, **Ann_tparams)\n",
      "\n",
      "plt.draw()  \n",
      "fig.savefig(\"/Users/didiervezinet/Documents/Travail/Fusion/PostDoc_AUG/Python_ToFu/Figures/Fig_Tutor_BigPicture_SynthDiag.pdf\",frameon=None,bbox_inches=0)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 38
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# Global picture, v3 (Tomography)\n",
      "\n",
      "from matplotlib._png import read_png\n",
      "from matplotlib.cbook import get_sample_data\n",
      "from matplotlib.offsetbox import TextArea, DrawingArea, OffsetImage, AnnotationBbox\n",
      "\n",
      "figW, figH = 14.5, 9\n",
      "figdpi = 80\n",
      "fig = plt.figure(facecolor=\"w\",figsize=(figW,figH), dpi=figdpi)\n",
      "axcolor = 'w'\n",
      "ax = plt.axes([0, 0, 1, 1],frameon=False, axisbg=axcolor)\n",
      "ax.axis('off')\n",
      "\n",
      "BoxS, BoxToFu, Fc, Ec, Alpha = \"round,pad=0.01\", \"round,pad=0.02\", (1.,0.5,1.,0.2), (1.,0.2,1.,1.), 0.5\n",
      "Title_tparams = {'size':15,'ha':'center', 'va':'bottom', 'family':'sans-serif','fontweight':'bold','fontstyle':'italic'}\n",
      "Com_tparams = {'size':10,'ha':'center', 'va':'top', 'family':'sans-serif','fontweight':'normal','fontstyle':'italic'}\n",
      "Ann_tparams = {'size':13,'ha':'center', 'va':'bottom', 'family':'sans-serif','fontweight':'normal','fontstyle':'italic'}\n",
      "Ar_tparams1 = {'size':10,'ha':'center', 'va':'center', 'family':'sans-serif','fontweight':'normal','fontstyle':'italic'}\n",
      "Ar_tparams2 = {'size':10,'ha':'center', 'va':'bottom', 'family':'sans-serif','fontweight':'normal','fontstyle':'italic'}\n",
      "Ar_tparams3 = {'size':10,'ha':'center', 'va':'bottom', 'family':'sans-serif','fontweight':'normal','fontstyle':'italic'}\n",
      "arrowprops = dict(arrowstyle=\"fancy,head_length=1,head_width=1,tail_width=0.5\",mutation_scale=10)\n",
      "\n",
      "Title, Com, Pos, Color, Box, ls = [], [], [], [], [], []\n",
      "Grey = (0.9,0.9,0.9,1.)\n",
      "\n",
      "Title.append(r\"ToFu\\_Geom v0.1\")\n",
      "Com.append(\"3D geometry of the diagnostic\\nComputes geometrical quantities\\nProvides visualisation tools\")\n",
      "Pos.append((0.27,0.85)), Color.append(Grey), Box.append(True), ls.append('solid')\n",
      "\n",
      "Title.append(r\"ToFu\\_Mesh v0.1\")\n",
      "Com.append(\"B-splines + variable mesh\\nProvides visualisation tools\")\n",
      "Pos.append((0.26,0.46)), Color.append(Grey), Box.append(True), ls.append('solid')\n",
      "\n",
      "Title.append(r\"ToFu\\_MatComp v0.1\")\n",
      "Com.append(\"Geometry matrix computation\\n3D or LOS approach\\nFitting tools for synthetic diag.\\nProvides visualisation tools\")\n",
      "Pos.append((0.45,0.65)), Color.append((0.,0.,0.,1.)), Box.append(True), ls.append('solid')\n",
      "\n",
      "Title.append(r\"ToFu\\_Inv v0\")\n",
      "Com.append(\"Various algorithms available\\nProvides visualisation tools\")\n",
      "Pos.append((0.58,0.45)), Color.append((0.,0.,0.,1.)), Box.append(True), ls.append('solid')\n",
      "\n",
      "Title.append(r\"ToFu\\_Data\")\n",
      "Com.append(\"Data treatment\\n Visualisation\")\n",
      "Pos.append((0.60,0.60)), Color.append((0.,0.,0.,1.)), Box.append(True), ls.append('solid')\n",
      "\n",
      "Title.append(r\"General\\_Geom v0.1\")\n",
      "Com.append(\"Provides general geometry tools\")\n",
      "Pos.append((0.27,0.63)), Color.append(Grey), Box.append(True), ls.append('dashed')\n",
      "\n",
      "Title.append(r\"Pigasus / CAID\")\n",
      "Com.append(\"Advanced adaptative mesh\")\n",
      "Pos.append((0.35,0.30)), Color.append(Grey), Box.append(True), ls.append('solid')\n",
      "\n",
      "Title.append(r\"Experimental measurements\")\n",
      "Com.append(\"+ constraints (e.g: magnetic field)\")\n",
      "Pos.append((0.90,0.55)), Color.append((0.,0.,1.,1.)), Box.append(True), ls.append('solid')\n",
      "\n",
      "Title.append(r\"Simulated emissivity\")\n",
      "Com.append(\"Impurity transport (TRANSP...)\\nMHD code (JOREK...)\\nGirokinetics (GISELA...)\\nFast electrons (LUKE...)\\nOthers...\")\n",
      "Pos.append((0.40,0.15)), Color.append((0.,0.,1.,1.)), Box.append(True), ls.append('solid')\n",
      "\n",
      "Title.append(r\"Inversions + GUI\")\n",
      "Com.append(\"(from experiment)\")\n",
      "Pos.append((0.64,0.23)), Color.append((1.,0.,0.,1.)), Box.append(True), ls.append('solid')\n",
      "\n",
      "Title.append(r\"Synthetic measurements\")\n",
      "Com.append(\"(from simulated emissivity)\")\n",
      "Pos.append((0.90,0.86)), Color.append(Grey), Box.append(True), ls.append('solid')\n",
      "\n",
      "Title.append(r\"Input geometry\")\n",
      "Com.append(\"(position of all detectors)\")\n",
      "Pos.append((0.09,0.85)), Color.append(Grey), Box.append(True), ls.append('solid')\n",
      "\n",
      "Title.append(r\"Discretisation\")\n",
      "Com.append(\"(mesh + basis functions)\")\n",
      "Pos.append((0.09,0.45)), Color.append(Grey), Box.append(True), ls.append('solid')\n",
      "\n",
      "Title.append(r\"Choice of inversion method\")\n",
      "Com.append(\"(Phillips-Tikhonov type)\")\n",
      "Pos.append((0.90,0.42)), Color.append((0.,0.,1.,1.)), Box.append(True), ls.append('solid')\n",
      "\n",
      "Title.append(r\"ToFu\\_PathFile\")\n",
      "Com.append(\"(small module handling paths/files\\nmay be called by any module)\")\n",
      "Pos.append((0.63,0.94)), Color.append(Grey), Box.append(True), ls.append('dashed')\n",
      "\n",
      "Title.append(r\"ToFu\\_Default\")\n",
      "Com.append(\"(Default parameters storage\\nfor computation and plotting)\")\n",
      "Pos.append((0.63,0.84)), Color.append(Grey), Box.append(True), ls.append('dashed')\n",
      "\n",
      "Title.append(r\"ToFu\\_Load\")\n",
      "Com.append(\"Tokamak-specific\\ndata loading\\n(AUG\\nJET\\nWEST\\nCompass...)\")\n",
      "Pos.append((0.72,0.64)), Color.append((0.,0.,0.,1.)), Box.append(True), ls.append('solid')\n",
      "\n",
      "TxTitle, TxCom, bb, fb = [], [], [], []\n",
      "for i in range(0,len(Title)):\n",
      "    TxTitle.append(ax.text(Pos[i][0],Pos[i][1], Title[i], color=Color[i], **Title_tparams))\n",
      "    TxCom.append(ax.text(Pos[i][0],Pos[i][1]-0.01, Com[i], color=Color[i], **Com_tparams))\n",
      "    \n",
      "plt.draw()\n",
      "\n",
      "RootPath = \"/Users/didiervezinet/Documents/Travail/Fusion/PostDoc_AUG/Python_ToFu/Figures/\"\n",
      "imf = [RootPath+\"Tutor_Geom.png\",RootPath+\"Tutor_Mesh.png\",RootPath+\"Tutor_Emiss.png\", RootPath+\"Tutor_Emiss.png\", RootPath+\"Tutor_Meas.png\", RootPath+\"Tutor_Meas.png\"]\n",
      "imz = [0.16, 0.16, 0.2, 0.2, 0.3, 0.3]\n",
      "imP = [(0.37,0.84), (0.35,0.45), (0.52,0.11), (0.63,0.11), (0.89,0.77), (0.89,0.64)]\n",
      "\n",
      "imb, ab = [], []\n",
      "for ii in range(0,len(imf)):\n",
      "    fn = get_sample_data(imf[ii], asfileobj=False)\n",
      "    arr_lena = read_png(fn)\n",
      "    imb.append(OffsetImage(arr_lena, zoom=imz[ii]))\n",
      "    ab.append(AnnotationBbox(imb[ii], imP[ii],xybox=imP[ii],xycoords='data',boxcoords=\"data\",pad=0., bboxprops={'ls':None,'ec':'w'}))\n",
      "    ax.add_artist(ab[ii])\n",
      "\n",
      "plt.draw()\n",
      "Patchdict = dict(alpha=0.9, ec='w', fc='w', visible=True)\n",
      "bla = hide_image(ab[0].patch, ax, Patchdict)\n",
      "bla = hide_image(ab[1].patch, ax, Patchdict)\n",
      "bla = hide_image(ab[4].patch, ax, Patchdict)\n",
      "\n",
      "Im = [[ab[0]],[ab[1]],[],[],[],[],[],[ab[5]],[ab[2]],[ab[3]],[ab[4]],[],[],[],[],[],[]]\n",
      "\n",
      "for i in range(0,len(Title)):\n",
      "    Txpatch = TxCom[i].get_window_extent()   \n",
      "    Lim = Txpatch.transformed(ax.transData.inverted())\n",
      "    DX = Lim.xmax-Lim.xmin\n",
      "    #TxCom[i].set_x(Pos[i][0]-DX/2.)\n",
      "    bb.append(common_bbox(ax, [TxTitle[i], TxCom[i]]+Im[i]))\n",
      "    fb.append(draw_bbox_fancy(ax, bb[i], False, True, BoxS, Color[i], 'w', ls=ls[i]))\n",
      "    \n",
      "TxToFu = ax.text(0.45,0.92, r\"ToFu\", color='k', size=30,ha='center',va='bottom')\n",
      "bbToFu = common_bbox(ax, [TxToFu]+TxTitle[:6]+TxCom[:6]+TxTitle[14:16]+TxCom[14:16]+ab[:2])\n",
      "fbToFu = draw_bbox_fancy(ax, bbToFu, False, True, BoxToFu, 'k', 'w',lw=2.,zorder=0)    \n",
      "\n",
      "ArCol, ArAng, ArBox, ArPos = [], [], [], []\n",
      "\n",
      "ArCol.append(Grey), ArBox.append([bb[5],bb[0]]), ArAng.append((55,80)), ArPos.append([(0.5,1.),(0.5,0.)])\n",
      "#ArCol.append(Grey), ArBox.append([bb[5],bb[1]]), ArAng.append((-55,100)), ArPos.append([(0.5,0.),(0.5,1.)])\n",
      "ArCol.append(Grey), ArBox.append([bb[5],bb[2]]), ArAng.append((10,170)), ArPos.append([(1.,0.5),(0.,0.5)])\n",
      "ArCol.append(Grey), ArBox.append([bb[0],bb[2]]), ArAng.append((-20,110)), ArPos.append([(1.,0.5),(0.2,1.)])\n",
      "ArCol.append(Grey), ArBox.append([bb[0],bb[10]]), ArAng.append((-20,180)), ArPos.append([(1.,0.1),(0.,0.3)])\n",
      "ArCol.append(Grey), ArBox.append([bb[1],bb[2]]), ArAng.append((20,-110)), ArPos.append([(1.,0.5),(0.2,0.)])\n",
      "ArCol.append('k'), ArBox.append([bb[2],bb[3]]), ArAng.append((-20,110)), ArPos.append([(1.,0.3),(0.3,1.)])\n",
      "ArCol.append(Color[7]), ArBox.append([bb[7],bb[4]]), ArAng.append((160,20)), ArPos.append([(0.,0.6),(1.,0.6)])\n",
      "ArCol.append('k'), ArBox.append([bb[4],bb[3]]), ArAng.append((-140,90)), ArPos.append([(0.5,0.),(0.6,1.)])\n",
      "ArCol.append(Grey), ArBox.append([bb[4],bb[7]]), ArAng.append((-20,-160)), ArPos.append([(1.,0.4),(0.,0.4)])\n",
      "ArCol.append('r'), ArBox.append([bb[3],bb[9]]), ArAng.append((-100,130)), ArPos.append([(0.5,0.),(0.4,1.)])\n",
      "ArCol.append(Grey), ArBox.append([bb[2],bb[10]]), ArAng.append((40,-180)), ArPos.append([(1.,0.7),(0.,0.3)])\n",
      "ArCol.append(Grey), ArBox.append([bb[11],bb[0]]), ArAng.append((0,160)), ArPos.append([(1.,0.5),(0.,0.5)])\n",
      "ArCol.append(Grey), ArBox.append([bb[12],bb[1]]), ArAng.append((0,160)), ArPos.append([(1.,0.5),(0.,0.5)])\n",
      "ArCol.append(Grey), ArBox.append([bb[8],bb[2]]), ArAng.append((100,-130)), ArPos.append([(0.35,1.),(0.5,0.)])\n",
      "ArCol.append(Grey), ArBox.append([bb[8],bb[1]]), ArAng.append((150,-120)), ArPos.append([(0.,0.5),(0.4,0.)])\n",
      "ArCol.append('b'), ArBox.append([bb[13],bb[3]]), ArAng.append((160,20)), ArPos.append([(0.,0.5),(1.,0.5)])\n",
      "ArCol.append(Grey), ArBox.append([bb[8],bb[0]]), ArAng.append((163,-148)), ArPos.append([(0.,0.5),(0.,0.1)])\n",
      "\n",
      "Ar = []\n",
      "for i in range(0,len(ArCol)):\n",
      "    arrowpropsi = arrowprops\n",
      "    arrowpropsi['color'] = ArCol[i]\n",
      "    arrowpropsi['connectionstyle'] = 'angle3,angleA=' + str(ArAng[i][0]) + ',angleB=' + str(ArAng[i][1])\n",
      "    Ar.append(link_fancyArrow(ax, ArBox[i][0], ArPos[i][0], ArBox[i][1], ArPos[i][1], arrowpropsi))\n",
      "    \n",
      "fb[6].set_zorder(100)\n",
      "TxTitle[6].set_zorder(101)\n",
      "TxCom[6].set_zorder(102)    \n",
      "fb[16].set_zorder(200)\n",
      "TxTitle[16].set_zorder(201)\n",
      "TxCom[16].set_zorder(202)\n",
      "\n",
      "In, In2 = ax.text(0.9,0.1, r\"Inputs\", color='b', **Title_tparams), ax.text(0.80,0.1, r\"R\", color='w', **Title_tparams)\n",
      "Out, Out2 = ax.text(0.9,0.05, r\"Outputs\", color='r', **Title_tparams), ax.text(0.80,0.05, r\"R\", color='w', **Title_tparams)\n",
      "arrowpropsi = arrowprops\n",
      "arrowpropsi['color'] = 'b'\n",
      "arrowpropsi['connectionstyle'] = 'angle3,angleA=' + str(170) + ',angleB=' + str(10)\n",
      "link_fancyArrow(ax, common_bbox(ax,[In]), (0.,0.5), common_bbox(ax,[In2]), (1.,0.5), arrowpropsi)\n",
      "arrowpropsi['color'] = 'r'\n",
      "arrowpropsi['connectionstyle'] = 'angle3,angleA=' + str(10) + ',angleB=' + str(170)\n",
      "link_fancyArrow(ax, common_bbox(ax,[Out2]), (1.,0.5), common_bbox(ax,[Out]), (0.,0.5), arrowpropsi)\n",
      "\n",
      "bbox_props = dict(boxstyle=\"round,pad=0.2\", fc=\"w\", ec=\"w\", lw=None)\n",
      "ax.text(0.125,0.23, r\"Direct\", color=Grey, bbox=bbox_props, **Ann_tparams)\n",
      "ax.text(0.19,0.23, r\"or\", color=Grey, bbox=bbox_props, **Ann_tparams)\n",
      "ax.text(0.27,0.223, r\"Projected\", color=Grey, bbox=bbox_props, **Ann_tparams)\n",
      "ax.text(0.34,0.23, r\"or\", color=Grey, bbox=bbox_props, **Ann_tparams)\n",
      "ax.text(0.40,0.23, r\"Built-in\", color=Grey, bbox=bbox_props, **Ann_tparams)\n",
      "\n",
      "plt.draw()  \n",
      "fig.savefig(\"/Users/didiervezinet/Documents/Travail/Fusion/PostDoc_AUG/Python_ToFu/Figures/Fig_Tutor_BigPicture_Tomo.png\",frameon=None,bbox_inches=0)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 43
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 233
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [],
     "language": "python",
     "metadata": {},
     "outputs": []
    }
   ],
   "metadata": {}
  }
 ]
}