This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
from astroquery.eso import Eso | |
eso = Eso() | |
# should use the default username | |
# and the keyring stored password | |
authentication = eso.login() | |
if not authentication: | |
raise RuntimeError('Something went wrong with authentication!') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
""" | |
Convert a PDF file to black&white and display it. | |
Run as: python bw.py input.pdf | |
""" | |
viewer = 'evince' | |
from contextlib import contextmanager | |
import tempfile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def fun(teff=None, mass=None): | |
if teff and mass: | |
# gave two parameters | |
pass # goto 1 | |
elif teff: | |
# don't have mass, have teff | |
mass = f(teff) | |
elif mass: | |
# don't have teff, have mass | |
# teff = f(mass) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ssh -N -f -L port:server2:22 user@server1 | |
# mount the directory locally | |
sshfs -C -p port user@localhost:remote_directory local_directory(must exist) | |
# unmount | |
sudo umount local_directory |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from scipy.optimize import bisect | |
from scipy.special import binom as binom_coeff | |
from scipy.integrate import quad | |
from functools import partial | |
def binom_function(N, n, p): | |
c = binom_coeff(N, n) | |
return c * p**n * (1.-p)**(N-n) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from astropy.constants import G | |
import astropy.units as u | |
# we assume m_planet << m_star | |
def get_planet_mass(P, K, e, star_mass=1.0): | |
""" | |
P in days, K in m/s, star_mass in solar masses | |
output is planet mass in Jupiter masses | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def develop(): | |
import reimport, os | |
mod = reimport.modified() | |
try: | |
mod.remove('__main__') | |
except ValueError: | |
pass | |
reimport.reimport(*mod) | |
print 'Done re-importing' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
""" | |
Print the acknowledgements sentence with all the project references! | |
See acknowledgements.py -h or run acknowledgements.py ? for help or simply use as | |
acknowledgements.py Author1 Author2 | |
""" | |
name = 'acknowledgements' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# matplotlib parameters for publication plots | |
import matplotlib.pyplot as plt | |
import matplotlib.ticker as ticker | |
from matplotlib import gridspec | |
import re | |
import os | |
this_folder = os.path.dirname(__file__) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from IPython import get_ipython | |
timer = lambda code: get_ipython().run_line_magic('timeit', '-o ' + code) | |
out = timer('pass') | |
out = timer('a = 0') |