{
 "metadata": {
  "name": "",
  "signature": "sha256:0e8d503473eadfa7f0014b3e356fe5d2798e4403e9b73ff6f88ebe2d9fc8ffc6"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "%pylab inline"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import ephem\n",
      "\n",
      "real_newton = ephem.newton\n",
      "\n",
      "def newton_wrapper(f, x0, x1, precision=ephem.default_newton_precision):\n",
      "    def wrapped_f(x):\n",
      "        y = f(x)\n",
      "        report(x, y)\n",
      "        return y\n",
      "    return real_newton(wrapped_f, x0, x1, precision)\n",
      "\n",
      "ephem.newton = newton_wrapper"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "def report(x, y):\n",
      "    print x, y\n",
      "    plot(x, y, 'ro')\n",
      "    axes().annotate('foo', xy=(x, y))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "northpole = ephem.Observer()\n",
      "northpole.lon = '0'\n",
      "northpole.lat = '90'\n",
      "northpole.elevation = 0\n",
      "\n",
      "sun = ephem.Sun()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "northpole.date = ephem.Date(datetime.datetime(1900, 4, 1))\n",
      "rise_time = northpole.previous_rising(sun)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "northpole.date = ephem.Date(datetime.datetime(1900, 3, 19))\n",
      "t0 = northpole.date\n",
      "\n",
      "dates = []\n",
      "altitudes = []\n",
      "\n",
      "for t in arange(t0, t0 + 2.0, 0.05):\n",
      "    northpole.date = t\n",
      "    sun.compute(northpole)\n",
      "    dates.append(northpole.date)\n",
      "    altitudes.append(sun.alt)\n",
      "\n",
      "plot(dates, altitudes, 'r.')"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [],
     "language": "python",
     "metadata": {},
     "outputs": []
    }
   ],
   "metadata": {}
  }
 ]
}