Skip to content

Instantly share code, notes, and snippets.

@willismonroe
Created September 12, 2020 00:42
Show Gist options
  • Save willismonroe/ae49480cd4cb1c21c5a214a70eb6f3d6 to your computer and use it in GitHub Desktop.
Save willismonroe/ae49480cd4cb1c21c5a214a70eb6f3d6 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Ephem\n",
"New moons for the year -500"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"import ephem"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"New moons for year -500:\n",
"1/22\n",
"2/21\n",
"3/22\n",
"3/23\n",
"4/21\n",
"5/20\n",
"5/21\n",
"6/19\n",
"7/19\n",
"8/17\n",
"8/18\n",
"9/16\n",
"10/16\n",
"11/14\n",
"12/14\n"
]
}
],
"source": [
"tau = 2.0 * ephem.pi\n",
"\n",
"babylon = ephem.Observer()\n",
"babylon.epoch = '-500'\n",
"babylon.lat, babylon.lon = \"32.535164526\", \"44.41916499\"\n",
"babylon.date = ephem.date('-500/1/1')\n",
"\n",
"sun = ephem.Sun()\n",
"moon = ephem.Moon()\n",
"print(\"New moons for year -500:\")\n",
"while babylon.date < ephem.date('-499/1/1'):\n",
" sun.compute(babylon.date)\n",
" moon.compute(babylon.date)\n",
" sunlon = ephem.Ecliptic(sun).lon\n",
" moonlon = ephem.Ecliptic(moon).lon\n",
"\n",
" angle = (moonlon - sunlon) % tau\n",
" phase = angle * 30\n",
" if (6 < phase < 14):\n",
" year, month, day, _, _, _ = babylon.date.tuple()\n",
" print(f\"{month}/{day}\",)\n",
" babylon.date += 1"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Skyfield\n",
"New moons for the year -500"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [],
"source": [
"from skyfield.api import load, Topos"
]
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"New moons for year -500:\n",
"1/27\n",
"2/26\n",
"4/26\n",
"5/26\n",
"6/24\n",
"7/24\n",
"9/21\n",
"11/19\n"
]
}
],
"source": [
"planets = load('de422.bsp')\n",
"babylon = Topos(\"32.535164526 N\", \"44.41916499 E\")\n",
"ts = load.timescale()\n",
"t = ts.utc(-500, 1, 1)\n",
"sun, moon, earth = planets['sun'], planets['moon'], planets['earth']\n",
"\n",
"r = ts.ut1(-500, 1, range(1, 365))\n",
"print(\"New moons for year -500:\")\n",
"for ti in r:\n",
" e = earth.at(ti)\n",
" _, slon, _ = e.observe(sun).apparent().ecliptic_latlon()\n",
" _, mlon, _ = e.observe(moon).apparent().ecliptic_latlon()\n",
" phase = (mlon.degrees - slon.degrees) % 360.0\n",
" if (6 < phase < 14):\n",
" print(f\"{ti.utc.month}/{ti.utc.day}\")"
]
}
],
"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.8.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment