{ "cells": [ { "cell_type": "code", "execution_count": 12, "metadata": { "collapsed": true, "deletable": true, "editable": true }, "outputs": [], "source": [ "# URL of the TS viewer\n", "tsvBaseURL='https://proba-v-mep.esa.int/api/timeseries/v1.0/ts/'\n", "\n", "# Image ID\n", "imageId = 'PROBAV_L3_S10_TOC_NDVI_333M'\n", "\n", "# Point of interest (longitude, latitude)\n", "longitude = 11.0\n", "latitude = 11.0" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [], "source": [ "import requests\n", "import urlparse\n", "import datetime\n", "from datetime import date\n", "\n", "def pointTSRequest(coverageId, lon, lat, startDate = None, endDate = None):\n", " \n", " tsvURL = urlparse.urljoin(tsvBaseURL, coverageId + '/')\n", " tsvURL = urlparse.urljoin(tsvURL, 'point')\n", " \n", " payload = {\n", " 'lon': str(lon),\n", " 'lat': str(lat)\n", " } \n", " \n", " if startDate != None:\n", " payload['startDate'] = startDate.strftime('%Y-%m-%d')\n", " \n", " if endDate != None:\n", " payload['endDate'] = endDate.strftime('%Y-%m-%d')\n", " \n", " return requests.get(tsvURL, params=payload)\n", "\n", "def pointTS(coverageId, lon, lat, startDate = None, endDate = None):\n", " \n", " response = pointTSRequest(coverageId, lon, lat, startDate, endDate)\n", " timeSeries = response.json()['results'] \n", " timeSeries = map(lambda x:[datetime.datetime.strptime(x['date'], \"%Y-%m-%d\").date(),x['result']['average']], timeSeries)\n", " return timeSeries \n", " " ] }, { "cell_type": "code", "execution_count": 13, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [], "source": [ "# Get the point from the time series viewer\n", "ts = pointTS(imageId, longitude, latitude)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[33mThe directory '/home/driesj/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.\u001b[0m\r\n", "\u001b[33mThe directory '/home/driesj/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.\u001b[0m\r\n", "Requirement already satisfied: mpld3 in /home/driesj/.local/lib/python2.7/site-packages\r\n" ] } ], "source": [ "# Install some additional Python libraries\n", "import sys\n", "\n", "! pip27 install --user mpld3" ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "collapsed": false, "deletable": true, "editable": true, "scrolled": true }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\n", "
\n", "" ], "text/plain": [ "" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Plot the data\n", "\n", "%matplotlib inline\n", "\n", "import matplotlib.pyplot as plt\n", "import mpld3\n", "\n", "fig, ax = plt.subplots()\n", "fig.set_size_inches(12, 4, forward=True)\n", "timeStamps = map(lambda x:x[0], ts)\n", "values = map(lambda x:x[1], ts)\n", "\n", "scatter = ax.scatter(timeStamps, values)\n", "\n", "labels = ['{0} - {1}'.format(i[1],i[0]) for i in ts]\n", "tooltip = mpld3.plugins.PointLabelTooltip(scatter, labels=labels)\n", "mpld3.plugins.connect(fig, tooltip)\n", "\n", "mpld3.display(fig)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 2", "language": "python", "name": "python2" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.5" } }, "nbformat": 4, "nbformat_minor": 1 }