Skip to content

Instantly share code, notes, and snippets.

@koma5
Created January 22, 2017 13:11
Show Gist options
  • Select an option

  • Save koma5/1a1f1e108d5a04a525dd5942f8048e7a to your computer and use it in GitHub Desktop.

Select an option

Save koma5/1a1f1e108d5a04a525dd5942f8048e7a to your computer and use it in GitHub Desktop.

Revisions

  1. koma5 created this gist Jan 22, 2017.
    230 changes: 230 additions & 0 deletions ephemSunsetSunrise.ipynb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,230 @@
    {
    "cells": [
    {
    "cell_type": "code",
    "execution_count": 1,
    "metadata": {
    "collapsed": false
    },
    "outputs": [],
    "source": [
    "import ephem, arrow"
    ]
    },
    {
    "cell_type": "code",
    "execution_count": 2,
    "metadata": {
    "collapsed": false
    },
    "outputs": [],
    "source": [
    "vorderthal = ephem.Observer()\n",
    "vorderthal.date = '2017/1/21 01:00:00'\n",
    "vorderthal.pressure = 0\n",
    "vorderthal.horizon = '-0:34'\n",
    "vorderthal.lat, vorderthal.long = '47.120548', '8.901111'"
    ]
    },
    {
    "cell_type": "code",
    "execution_count": 3,
    "metadata": {
    "collapsed": false
    },
    "outputs": [],
    "source": [
    "nextRise = arrow.get(vorderthal.next_rising(ephem.Sun()).datetime())\n",
    "nextTransit = arrow.get(vorderthal.next_transit(ephem.Sun()).datetime())\n",
    "nextSet = arrow.get(vorderthal.next_setting(ephem.Sun()).datetime())"
    ]
    },
    {
    "cell_type": "code",
    "execution_count": 4,
    "metadata": {
    "collapsed": false
    },
    "outputs": [
    {
    "name": "stdout",
    "output_type": "stream",
    "text": [
    "2017/1/21 01:01:15\n",
    "2017/1/21 06:21:00\n",
    "2017/1/21 11:34:28\n"
    ]
    }
    ],
    "source": [
    "print(vorderthal.next_rising(ephem.Moon()))\n",
    "print(vorderthal.next_transit(ephem.Moon()))\n",
    "print(vorderthal.next_setting(ephem.Moon()))"
    ]
    },
    {
    "cell_type": "code",
    "execution_count": 5,
    "metadata": {
    "collapsed": false
    },
    "outputs": [],
    "source": [
    "vorderthal.horizon = '-6' #Civil twilight\n",
    "civilStart = arrow.get(vorderthal.next_rising(ephem.Sun(), use_center=True).datetime())\n",
    "civilEnd = arrow.get(vorderthal.next_setting(ephem.Sun(), use_center=True).datetime())"
    ]
    },
    {
    "cell_type": "code",
    "execution_count": 6,
    "metadata": {
    "collapsed": false
    },
    "outputs": [],
    "source": [
    "vorderthal.horizon = '-12' #Nautical twilight\n",
    "nauticalStart = arrow.get(vorderthal.next_rising(ephem.Sun(), use_center=True).datetime())\n",
    "nauticalEnd = arrow.get(vorderthal.next_setting(ephem.Sun(), use_center=True).datetime())"
    ]
    },
    {
    "cell_type": "code",
    "execution_count": 7,
    "metadata": {
    "collapsed": false
    },
    "outputs": [],
    "source": [
    "vorderthal.horizon = '-18' #Astronomical twilight\n",
    "astronomicalStart = arrow.get(vorderthal.next_rising(ephem.Sun(), use_center=True).datetime())\n",
    "astronomicalEnd = arrow.get(vorderthal.next_setting(ephem.Sun(), use_center=True).datetime())"
    ]
    },
    {
    "cell_type": "code",
    "execution_count": 8,
    "metadata": {
    "collapsed": false
    },
    "outputs": [
    {
    "name": "stdout",
    "output_type": "stream",
    "text": [
    "Vorderthal 21.01.2017\n",
    "Astronomical twilight 06:14\n",
    "Nautical twilight 06:50\n",
    "Civil twilight 07:27\n",
    "Sunrise 08:01\n",
    "Sun Transit 12:35\n",
    "Sunset 17:10\n",
    "Civil twilight 17:44\n",
    "Nautical twilight 18:21\n",
    "Astronomical twilight 18:57\n"
    ]
    }
    ],
    "source": [
    "selectedDay = arrow.get(vorderthal.date.datetime())\n",
    "print (\"\"\"\\\n",
    "Vorderthal {}\n",
    "Astronomical twilight {}\n",
    "Nautical twilight {}\n",
    "Civil twilight {}\n",
    "Sunrise {}\n",
    "Sun Transit {}\n",
    "Sunset {}\n",
    "Civil twilight {}\n",
    "Nautical twilight {}\n",
    "Astronomical twilight {}\"\"\".format(selectedDay.format('DD.MM.YYYY'),\n",
    " astronomicalStart.to('CET').format('HH:mm'),\n",
    " nauticalStart.to('CET').format('HH:mm'),\n",
    " civilStart.to('CET').format('HH:mm'),\n",
    " nextRise.to('CET').format('HH:mm'),\n",
    " nextTransit.to('CET').format('HH:mm'),\n",
    " nextSet.to('CET').format('HH:mm'),\n",
    " civilEnd.to('CET').format('HH:mm'),\n",
    " nauticalEnd.to('CET').format('HH:mm'),\n",
    " astronomicalEnd.to('CET').format('HH:mm')))"
    ]
    },
    {
    "cell_type": "code",
    "execution_count": null,
    "metadata": {
    "collapsed": true
    },
    "outputs": [],
    "source": [
    "\"\"\"\n",
    "Vorderthal 16.02.2015\n",
    "Astronomical twilight 05:45\n",
    "Nautical twilight 06:21\n",
    "Civil twilight 06:56\n",
    "Sunrise 07:28\n",
    "Sun Transit 12:38\n",
    "Sunset 17:49\n",
    "Civil twilight 18:20\n",
    "Nautical twilight 18:56\n",
    "Astronomical twilight 19:31\n",
    "\"\"\""
    ]
    },
    {
    "cell_type": "code",
    "execution_count": null,
    "metadata": {
    "collapsed": true
    },
    "outputs": [],
    "source": [
    "\"\"\"\n",
    "my results \n",
    "Einsedeln 15.02.15\n",
    "Astronomical twilight 05:48\n",
    "Nautical twilight\t 06:23\n",
    "Civil twilight\t\t 06:59\n",
    "Sunrise\t\t\t 07:30\n",
    "Sun Transit\t\t 12:39\n",
    "Sunset\t\t 17:48\n",
    "Civil twilight\t 18:19\n",
    "Nautical twilight 18:55\n",
    "Astronomical twilight 19:31\n",
    "\n",
    "Einsiedeln 15.02.15 in CET from (http://www.timeanddate.com/astronomy/switzerland/einsiedeln)\n",
    "Night 00:00 – 05:48\n",
    "Astro. Twilight\t 05:48 – 06:23\n",
    "Nautical Twilight 06:23 – 06:59\n",
    "Civil Twilight\t 06:59 – 07:30\n",
    "Daylight 07:30 – 17:48\n",
    "Civil Twilight 17:48 – 18:20\n",
    "Nautical Twilight 18:20 – 18:56\n",
    "Astro. Twilight\t 18:56 – 19:31\n",
    "Night 19:31 – 23:59\n",
    "\"\"\""
    ]
    }
    ],
    "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.0"
    }
    },
    "nbformat": 4,
    "nbformat_minor": 0
    }