{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "# Test different Contouring options"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "outputs": [],
   "source": [
    "import Magics.macro as magics\n",
    "\n",
    "projection = magics.mmap(\n",
    "    subpage_map_library_area = \"on\",\n",
    "    subpage_map_area_name    = \"central_europe\",\n",
    "    page_id_line             = \"off\"\n",
    ")\n",
    "\n",
    "coast = magics.mcoast()\n",
    "\n",
    "legend = magics.mlegend(legend_display_type   = 'continuous')\n",
    "\n",
    "# Different meteorological parameters we will plot in this notebook\n",
    "temperature   = magics.mgrib(grib_input_file_name = \"t850.grib\")\n",
    "geopotential  = magics.mgrib(grib_input_file_name = \"z500.grib\")\n",
    "precipitation = magics.mgrib(grib_input_file_name = \"total_precipitation.grib\")\n",
    "\n",
    "from IPython.core.interactiveshell import InteractiveShell\n",
    "\n",
    "InteractiveShell.ast_node_interactivity = \"all\" "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "Default"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 87656 characters]\n",
      "text/plain": [
       "<IPython.core.display.Image object>"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "z_cont = magics.mcont(contour_threads = 1)\n",
    "\n",
    "magics.plot(projection, geopotential, z_cont, coast)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Simple contouring..."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 99300 characters]\n",
      "text/plain": [
       "<IPython.core.display.Image object>"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "z_cont = magics.mcont( \n",
    "    contour_line_colour         = \"navy\",\n",
    "    contour_line_thickness      = 2,\n",
    "    contour_highlight_colour    = \"navy\",\n",
    "    contour_highlight_thickness = 6,\n",
    "    legend                      = \"off\",\n",
    "    contour_threads              = 1\n",
    "   \n",
    "    )\n",
    "\n",
    "magics.plot(projection, geopotential, z_cont, coast)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "dash, different colour for highlight, interval"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 129516 characters]\n",
      "text/plain": [
       "<IPython.core.display.Image object>"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "z_cont = magics.mcont(\n",
    "    contour_level_selection_type = \"interval\",\n",
    "    contour_reference_level      = 500,\n",
    "    contour_interval             = 4.00,\n",
    "    contour_line_style           = \"dash\",\n",
    "    contour_line_colour          = \"evergreen\",\n",
    "    contour_line_thickness       = 3,\n",
    "    contour_label                = \"on\",\n",
    "    contour_threads              = 1,\n",
    "    contour_label_colour         = \"contour_line_colour\",\n",
    "    contour_label_height         = 0.50,\n",
    "    contour_highlight_frequency  = 5,\n",
    "    contour_highlight_colour     = \"navy\",\n",
    "    contour_highlight_thickness  = 4,\n",
    "    legend                       = \"on\"\n",
    ")\n",
    "\n",
    "magics.plot(projection, geopotential, z_cont, coast)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 129420 characters]\n",
      "text/plain": [
       "<IPython.core.display.Image object>"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "z_cont = magics.mcont(\n",
    "    contour_level_selection_type = \"interval\",\n",
    "    contour_reference_level      = 500,\n",
    "    contour_interval             = 4.00,\n",
    "    contour_line_style           = \"dash\",\n",
    "    contour_line_colour          = \"evergreen\",\n",
    "    contour_line_thickness       = 3,\n",
    "    contour_threads              = 1,\n",
    "    contour_label                = \"on\",\n",
    "    contour_label_colour         = \"contour_line_colour\",\n",
    "    contour_label_type           = \"text\",\n",
    "    contour_label_text           = \"some text\",\n",
    "    contour_label_height         = 0.50,\n",
    "    contour_highlight_frequency  = 2,\n",
    "    contour_highlight_colour     = \"navy\",\n",
    "    contour_highlight_thickness  = 2,\n",
    "    legend                       = \"on\"\n",
    ")\n",
    "\n",
    "magics.plot(projection, geopotential, z_cont, coast)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Displaying the grid values\n",
    "\n",
    "In this example we will see how to display grid values together with isolines. Instead of value we could also plot a marker, or both.\n",
    "\n",
    "For the isolines, we will use **'level_list'** as a type, and then provide customized list."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 144784 characters]\n",
      "text/plain": [
       "<IPython.core.display.Image object>"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tp_cont = magics.mcont(\n",
    "    contour_grid_value_plot          = \"on\",\n",
    "    contour_grid_value_height        = 0.50,\n",
    "    contour_grid_value_plot_type     = \"both\",\n",
    "    contour_grid_value_format        = \"(i4)\",\n",
    "    contour_grid_value_colour        = \"black\",\n",
    "    contour_grid_value_marker_height = 0.5,\n",
    "    contour_grid_value_marker_colour = \"evergreen\",\n",
    "    contour_grid_value_lon_frequency = 3,\n",
    "    contour_grid_value_lat_frequency = 3,\n",
    "    contour_highlight                = \"off\",\n",
    "    contour_line_colour              = \"grey\",\n",
    "    contour_line_thickness           = 2,\n",
    "    contour_level_selection_type     = \"level_list\",\n",
    "    contour_level_list               = [0.5, 2, 4, 10, 20, 30, 50, 100, 250],\n",
    "    contour_label                    = \"off\",\n",
    "    legend                           = \"off\"\n",
    ")\n",
    "\n",
    "magics.plot(projection, precipitation, tp_cont, coast)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 200716 characters]\n",
      "text/plain": [
       "<IPython.core.display.Image object>"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "projection = magics.mmap(\n",
    "    subpage_map_library_area = \"on\",\n",
    "    subpage_map_area_name    = \"central_europe\",\n",
    "    subpage_clipping         = \"on\",\n",
    "    page_id_line             = \"off\"\n",
    ")\n",
    "\n",
    "tp_cont = magics.mcont(\n",
    "    contour_grid_value_plot          = \"on\",\n",
    "    contour_grid_value_height        = 0.50,\n",
    "    contour_grid_value_plot_type     = \"both\",\n",
    "    contour_grid_value_format        = \"(f4.2)\",\n",
    "    contour_grid_value_colour        = \"charcoal\",\n",
    "    contour_grid_value_marker_height = 0.8,\n",
    "    contour_grid_value_marker_colour = \"red\",\n",
    "    contour_grid_value_lon_frequency = 2,\n",
    "    contour_grid_value_lat_frequency = 2,\n",
    "    contour_grid_value_vertical_align = \"bottom\",\n",
    "    contour_grid_value_justification = 'left',\n",
    "    contour_grid_value_marker_index  = 15,\n",
    "    contour_highlight                = \"off\",\n",
    "    contour_line_colour              = \"beige\",\n",
    "    contour_line_thickness           = 2,\n",
    "    contour_level_selection_type     = \"level_list\",\n",
    "    contour_level_list               = [0.5, 2, 4, 10, 20, 30, 50, 100, 250],\n",
    "    contour_label                    = \"off\",\n",
    "    legend                           = \"off\"\n",
    ")\n",
    "\n",
    "magics.plot(projection, precipitation, tp_cont, coast)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Rainbow method to colour the isolines (computing a range of colours)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 214428 characters]\n",
      "text/plain": [
       "<IPython.core.display.Image object>"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "t_cont = magics.mcont(\n",
    "    contour_label                                = \"on\",\n",
    "    contour_label_height                         = 0.5,\n",
    "    legend                                       = \"on\",\n",
    "    contour_level_selection_type                 = \"interval\",\n",
    "    contour_interval                             = 1.00,\n",
    "    contour_line_thickness                       = 3,\n",
    "    contour_line_colour_rainbow                  = \"on\",\n",
    "    contour_line_colour_rainbow_method           = \"calculate\",\n",
    "    contour_line_colour_rainbow_max_level_colour = \"evergreen\",\n",
    "    contour_line_colour_rainbow_min_level_colour = \"turquoise\",\n",
    "    contour_line_colour_rainbow_direction        = \"anti_clockwise\",\n",
    "    contour_line_thickness_rainbow_list          = [4,2,2,2,2],\n",
    "    contour_line_thickness_rainbow_list_policy   = \"cycle\",\n",
    "    contour_line_style_rainbow_list              = [\"solid\",\"dot\",\"dash\",\"dash\",\"dash\"],\n",
    "    contour_line_style_rainbow_list_policy       = \"cycle\",\n",
    "    contour_threads                              = 1,\n",
    ")\n",
    "\n",
    "cream_coast = magics.mcoast(\n",
    "    map_coastline_colour            = \"grey\",\n",
    "    map_coastline_resolution        = \"medium\",\n",
    "    map_coastline_thickness         = 2,\n",
    "    map_coastline_land_shade        = \"on\",\n",
    "    map_coastline_land_shade_colour = \"cream\",\n",
    "    map_coastline_sea_shade         = \"on\",\n",
    "    map_coastline_sea_shade_colour  = \"sky\",\n",
    "    map_grid_line_style             = \"dash\",\n",
    "    map_grid_colour                 = \"grey\"\n",
    ")\n",
    "\n",
    "magics.plot(projection, cream_coast, temperature, t_cont, legend)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Rainbow method to colour the isolines (list of colours and thickness)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 214504 characters]\n",
      "text/plain": [
       "<IPython.core.display.Image object>"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "t_cont = magics.mcont(\n",
    "    contour_threads                            = 1,\n",
    "    contour_label                              = \"on\",\n",
    "    legend                                     = \"on\",\n",
    "    contour_level_selection_type               = \"count\",\n",
    "    contour_level_count                        = 41,\n",
    "    contour_min_level                          = -20,\n",
    "    contour_max_level                          = 20,\n",
    "    contour_hilo                               = \"on\",\n",
    "    contour_hilo_height                        = 0.4,\n",
    "    contour_lo_colour                          = \"cyan\",\n",
    "    contour_hi_colour                          = \"red\",\n",
    "    contour_lo_max_value                       = 0,\n",
    "    contour_hi_min_value                       = 0,    \n",
    "    contour_line_thickess                      = 2,\n",
    "    contour_line_colour_rainbow                = \"on\",\n",
    "    contour_line_colour_rainbow_method         = \"list\",\n",
    "    contour_line_colour_rainbow_colour_list    = ['#053061', '#0c3d73', '#134a86', '#1a5899', '#2166ac', \n",
    "                                                  '#2b71b2', '#347cb8', '#3c88bd', '#4393c3', '#5a9fca', \n",
    "                                                  '#6eacd1', '#80b8d7', '#92c5de', '#a2cde3', '#b2d5e7',\n",
    "                                                  '#c2ddec', '#d1e5f0', '#dbe9f2', '#e4eef4', '#eef2f5', \n",
    "                                                  '#f7f7f7', '#f9f0eb', '#fbe9df', '#fce2d3', '#fddbc7', \n",
    "                                                  '#fccdb5', '#fac0a4', '#f7b293', '#f4a582', '#ed9474', \n",
    "                                                  '#e68367', '#de725a', '#d6604d', '#cd5144', '#c4413c', \n",
    "                                                  '#bb2f33', '#b2182b', '#9f1128', '#8c0a25', '#790422',\n",
    "                                                  '#67001f'],\n",
    "    contour_line_thickness_rainbow_list        = [4,1,1,1,1,2,1,1,1,1],\n",
    "    contour_line_thickness_rainbow_list_policy = \"cycle\"\n",
    ")\n",
    "\n",
    "\n",
    "black_coast = magics.mcoast(\n",
    "    map_coastline_colour            = \"grey\",\n",
    "    map_coastline_resolution        = \"medium\",\n",
    "    map_coastline_thickness         = 2,\n",
    "    map_coastline_land_shade        = \"on\",\n",
    "    map_coastline_land_shade_colour = \"RGB(0.25,0.25,0.25)\",\n",
    "    map_coastline_sea_shade         = \"on\",\n",
    "    map_coastline_sea_shade_colour  = \"black\",\n",
    "    map_grid_line_style             = \"dash\",\n",
    "    map_grid_colour                 = \"grey\"\n",
    ")\n",
    "\n",
    "magics.plot(projection, black_coast, temperature, t_cont, legend)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 223496 characters]\n",
      "text/plain": [
       "<IPython.core.display.Image object>"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "z_cont = magics.mcont( \n",
    "    contour_line_colour         = \"black\",\n",
    "    contour_line_thickness      = 2,\n",
    "    contour_highlight_colour    = \"charcoal\",\n",
    "    contour_highlight_thickness = 6,\n",
    "    contour_label               = \"off\",\n",
    "    legend                      = \"off\",\n",
    "    contour_level_selection_type= \"interval\",\n",
    "    contour_interval            = 3,\n",
    "    contour_highlight_style     = \"chain_dash\",\n",
    "    contour_hilo                = \"on\",\n",
    "    contour_reference_level     = 540,\n",
    "    contour_hilo_height         = 0.4,\n",
    "    contour_lo_colour           = \"navy\",\n",
    "    contour_hi_colour           = \"burgundy\",\n",
    "    contour_lo_max_value        = 560,\n",
    "    contour_hi_min_value        = 530,\n",
    "    )\n",
    "\n",
    "europe = magics.mmap(\n",
    "    subpage_map_library_area = \"on\",\n",
    "    subpage_map_area_name    = \"europe\",\n",
    "    page_id_line             = \"off\"\n",
    ")\n",
    "\n",
    "magics.plot(europe, coast, geopotential, z_cont)"
   ]
  }
 ],
 "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.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
