{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [
    {
     "ename": "ModuleNotFoundError",
     "evalue": "No module named 'requests'",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mModuleNotFoundError\u001b[0m                       Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-4-5c98f64a6aa5>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m      1\u001b[0m \u001b[0;31m# Load required libraries\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      2\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 3\u001b[0;31m \u001b[0;32mimport\u001b[0m \u001b[0mrequests\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m      4\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mnumpy\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      5\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mos\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mModuleNotFoundError\u001b[0m: No module named 'requests'"
     ]
    }
   ],
   "source": [
    "# Load required libraries\n",
    "\n",
    "import requests\n",
    "import numpy as np\n",
    "import os\n",
    "\n",
    "from Magics import toolbox as magics\n",
    "from ipywidgets import interact\n",
    "import ipywidgets as widgets\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true,
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "0652ed68a0e04acd9a9bf1202bfb30f5"
      }
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "<function __main__.graph>"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\n",
    "def graph (lat, lon, param, color, style) :\n",
    "    url_fmt = 'http://earthserver.ecmwf.int/rasdaman/ows?service=WCS&version=2.0.1' \\\n",
    "          '&request=ProcessCoverages' \\\n",
    "          '&query=for c in (%s) return encode(c[Lat(%s), Long(%s), ansi(\"%s\":\"%s\")], \"csv\") '\n",
    "\n",
    "    url = url_fmt%(param, lat, lon, \"2000-01-01T00:00:00+00:00\",\"2005-12-31T00:00:00+00:00\")\n",
    "    \n",
    "    #r= requests.get(url,\n",
    "                    #proxies={'http':None}\n",
    "                    #)\n",
    "\n",
    "    #r.raise_for_status()\n",
    "\n",
    "    # Store the requested data in a numpy array\n",
    "    yy = np.array(eval(r.text.replace('{','[').replace('}',']')))\n",
    "    xx =  range(len(yy))\n",
    "   \n",
    "    \n",
    "    \n",
    "    return magics.graph(xx, yy, \n",
    "            title = \"Time series %s at %d/%d\" % ( param , lat, lon), \n",
    "            graph = { \"graph_line_colour\" : color, \"graph_line_style\" : style },\n",
    "           )\n",
    "    \n",
    "\n",
    "\n",
    "interact(graph, lon=widgets.IntSlider(min=-180,max=180,step=1,value=10,continuous_update=False),\n",
    "         lat=widgets.IntSlider(min=-90,max=90,step=1,value=10,continuous_update=False),\n",
    "         param = widgets.Dropdown(\n",
    "            options=['temp2m', 'precipitation', ],\n",
    "            value='temp2m',\n",
    "        ),\n",
    "        color = widgets.Dropdown(\n",
    "            options=[ \"ecmwf_blue\", 'navy', 'evergreen', ],\n",
    "            value='ecmwf_blue',),\n",
    "        style = widgets.Dropdown(\n",
    "            options=[ \"solid\", 'dash', 'dot', ],\n",
    "            value='solid',) \n",
    "         )\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true,
    "deletable": true,
    "editable": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true,
    "deletable": true,
    "editable": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true,
    "deletable": true,
    "editable": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "celltoolbar": "Edit 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.6.1"
  },
  "widgets": {
   "state": {
    "e2ad91f584b549f08bcd6ff26212b574": {
     "views": [
      {
       "cell_index": 1
      }
     ]
    }
   },
   "version": "1.2.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
