Skip to content

Instantly share code, notes, and snippets.

View hannorein's full-sized avatar

Hanno Rein hannorein

View GitHub Profile
#!/usr/bin/python
from selenium import webdriver
import unittest, time, re
from random import choice
correctanswers = []
def tryitnow ():
# Copy and paste the module url below, including the key:
@hannorein
hannorein / gist:5638999
Last active March 26, 2017 06:51
The functions parameters are: gjd - geocentric JD based on UTC ra - right ascension (J2000) de - declination The function returns heliocentric correction helcor. Using helcor, you can computed Heliocentric JD from Geocentric JD. The relation is: HJD = GJD + helcor. We do not compute Barycentric JD (BJD).
function computeHELCOR($gjd, $ra, $de) {
// $eps=23.45*Pi()/180;
$ra = EREgI_Replace(" ", "", $ra);
$de = EREgI_Replace(" ", "", $de);
$ra_hh = IntVal(substr($ra, 0, 2));
$ra_mm = IntVal(substr($ra, 2, 2));
$ra_vv = DoubleVal(substr($ra, 4, 4));
$de_dd = IntVal(substr($de, 0, 3));
$de_mm = IntVal(substr($de, 3, 2));
@hannorein
hannorein / gist:2a069763cf114f66641c
Created May 14, 2014 22:08
Yes, it's that simple. Querying the Open Exoplanet Catalogue.
#!/usr/bin/python
import xml.etree.ElementTree as ET, urllib, gzip, io
url = "https://github.com/OpenExoplanetCatalogue/oec_gzip/raw/master/systems.xml.gz"
oec = ET.parse(gzip.GzipFile(fileobj=io.BytesIO(urllib.urlopen(url).read())))
# Output mass and radius of all planets
for planet in oec.findall(".//planet"):
print [planet.findtext("mass"), planet.findtext("radius")]
# Find all circumbinary planets
with open('somefile.txt', 'a') as f:
N = len(a)
for i in xrange(N):
f.write("%e %e %e\n" %(a[i],b[i],c[i]))
import struct
with open('somefile.txt', 'a') as f:
N = len(a)
for i in xrange(N):
f.write(struct.pack("f", a[i]))
f.write(struct.pack("f", b[i]))
f.write(struct.pack("f", c[i]))
@hannorein
hannorein / gist:7f633cd769c390aa0dc4
Created April 11, 2015 22:39
REBOUND installation using pip
# Create a directory to work in
mkdir rebound
cd rebound
# Create a virtual environment to work in
# (not required, but keeps your python installation clean)
virtualenv venv
source venv/bin/activate
# Install rebound
import json
import sys
if len(sys.argv)!=2:
print "Usage: ipynb2py.py FILENAME"
exit(1)
with open(sys.argv[1]) as data_file:
ipynb = json.load(data_file)
code = ""
/**
* A.S. This is my planetesimal disk with special integrator for close encounters.
* Particle id's: 0 = star, 1 = massive body, 2 = planetesimal, 3 = CLOSE ENCOUNTER
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <math.h>
#include <time.h>
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
%matplotlib inline
import matplotlib
import numpy as np
import matplotlib.pyplot as plt
m = np.array([1.0, 3.0404326480226416e-06, 0.0009547919152112404, 0.0002858856727222417])
r = np.array([[0.0, 0.0, 0.0], [-0.5774742940580093, 0.7974401660237153, -2.611328235294271e-05], [-5.2320819021823235, 1.4130269395522546, 0.11120655650204452], [-3.5888816588976513, -9.343800743805208, 0.30528182406879745]])
v = np.array([[0.0, 0.0, 0.0], [-0.8263301482607002, -0.5903562644526552, 2.5048741249552767e-05], [-0.11971493094874505, -0.40317587415621225, 0.00435283234131933], [0.28498977476287424, -0.11757835716481167, -0.009305024058343627]])
plt.xlim([-6,6])
plt.ylim([-6,6])
plt.plot(r[:,0:1],"o",label=["sun"]);