Skip to content

Instantly share code, notes, and snippets.


João Faria j-faria

Block or report user

Report or block j-faria

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
j-faria /
Created Sep 10, 2015
Bayesian correlation
# -*- coding: utf-8 -*-
# Written by Pedro Figueira.
# Original version can be found at
# Modified by João Faria
"""Bayesian Correlation.
j-faria /
Last active Jun 23, 2018
.rdb file reader
import numpy as np
import cStringIO
filename = 'example.rdb'
def read_rdb(filename):
""" Reads a .rdb file with possible comments '#' and header
col1 col2 col3
---- ---- ----
Returns a numpy record array
j-faria /
Created Mar 25, 2016
Query the ESO archive for HARPS data. Works with astroquery.eso version in my fork
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!')
j-faria /
Last active Apr 6, 2016
Convert a PDF file to black&white and display it
#!/usr/bin/env python
Convert a PDF file to black&white and display it.
Run as: python input.pdf
viewer = 'evince'
from contextlib import contextmanager
import tempfile
View gist:3c642e1fa69b00653a608232d86dffe6
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)
j-faria / kepler.cpp
Created Jan 16, 2017
C++ implementation of "A Practical Method for Solving the Kepler Equation"
View kepler.cpp
Calculates the eccentric anomaly at time t by solving Kepler's equation.
See "A Practical Method for Solving the Kepler Equation", Marc A. Murison, 2006
@param t the time at which to calculate the eccentric anomaly.
@param period the orbital period of the planet
@param ecc the eccentricity of the orbit
@param t_peri time of periastron passage
@return eccentric anomaly.
j-faria /
Created Feb 2, 2017
Mount a remote directory locally using `sshfs`
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
j-faria /
Last active Nov 15, 2017
A custom styler to make publication-ready matplotlib plots
# 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__)
j-faria /
Created May 10, 2017
Probability distribution for fraction of X, given the total sample size N, and the number of Xs in the sample, n. Follows the Appendix of Burgasser et al. (ApJ, 586:512, 2003)
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)
j-faria /
Created May 10, 2017
Calculate the mass and semi-major axis of a planet, from its orbital period, semi-amplitude and eccentricity
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
You can’t perform that action at this time.