{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import dautil as dl\n",
    "import matplotlib.pyplot as plt\n",
    "import numpy as np\n",
    "from IPython.display import HTML"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "df = dl.data.Weather.load().dropna()\n",
    "df = dl.ts.groupby_yday(df).mean().dropna()\n",
    "ws_phase = dl.ts.instant_phase(df['WIND_SPEED'])\n",
    "wd_phase = dl.ts.instant_phase(df['WIND_DIR'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "%matplotlib inline\n",
    "dl.options.mimic_seaborn()\n",
    "context = dl.nb.Context('phase_synchrony')\n",
    "dl.nb.RcWidget(context)\n",
    "dl.nb.LabelWidget(2, 2, context)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "sp = dl.plotting.Subplotter(2, 2, context)\n",
    "cp = dl.plotting.CyclePlotter(sp.ax)\n",
    "cp.plot(df.index, dl.stats.zscores(df['WIND_DIR'].values),\n",
    "       label='Wind direction')\n",
    "cp.plot(df.index, dl.stats.zscores(df['WIND_SPEED'].values),\n",
    "       label='Wind speed')\n",
    "sp.label()\n",
    "\n",
    "cp = dl.plotting.CyclePlotter(sp.next_ax())\n",
    "cp.plot(df.index, ws_phase, label='Wind speed')\n",
    "cp.plot(df.index, wd_phase, label='Wind direction')\n",
    "sp.label()\n",
    "\n",
    "sp.label(advance=True)\n",
    "sp.ax.plot(np.correlate(df['WIND_SPEED'], df['WIND_DIR'], 'same'))\n",
    "\n",
    "sp.label(advance=True)\n",
    "sp.ax.plot(np.angle(np.fft.fft(df['WIND_SPEED'])/np.fft.fft(df['WIND_DIR'])))\n",
    "plt.tight_layout()\n",
    "HTML(sp.exit())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "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.4.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
