Skip to content

Instantly share code, notes, and snippets.


João Faria j-faria

View GitHub Profile
import contextlib
import os
def working_directory(path):
A context manager which changes the working directory to the given
path, and then changes it back to its previous value on exit.
prev_cwd = os.getcwd()
j-faria / ExoPlanetCurves
Last active Dec 5, 2019
The Keplerian and transit curves
View ExoPlanetCurves
Two small demonstration notebooks of how the Keplerian and transit curves respond to a change in the parameters.
j-faria /
Created Sep 6, 2019
query and download reduced data from the ESO Archive
#* ESO Science Archive Facility
#* Programmatic Access
#* Script:
#* Shell: bash
#* Date: 15-Jul-2015
#* Contact:
#* Description: Script to query and download reduced data (Phase 3)
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 / 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 Jul 2, 2019
Simplified abbreviations of frequently used journals (according to A&A)
name_abbrv = {
'Astronomy and Astrophysics': 'A&A',
'Astronomy & Astrophysics': 'A&A',
'Monthly Notices of the Royal Astronomical Society': 'MNRAS',
'The Astrophysical Journal': 'ApJ',
'The Astronomical Journal': 'AJ',
'Publications of the Astronomical Society of the Pacific': 'PASP',
'Annual Review of Astronomy and Astrophysics': 'ARA&A' ,
j-faria /
Last active May 7, 2019
Calculate stellar mass and radius using the Torres calibration
import numpy as np
try: # numba will provide a ~2x speedup
from numba import jit
except ImportError: # but we can do without it
jit = lambda fn: fn
def massTorres(teff, erteff, logg, erlogg, feh, erfeh,
ntrials=10000, corrected=True, add_intrinsic=True):
j-faria / gist:fdc0a97a72023dca26b084ec28ac9939
Created Apr 15, 2019
ESO archive downloads in parallel
View gist:fdc0a97a72023dca26b084ec28ac9939
sh -X "-P 8 -L 1"
j-faria /
Created Feb 28, 2019
How to solve the binary mass function for m2, using sympy
from sympy import *
from astropy.constants import G
import astropy.units as u
G =**3 / (u.solMass * u.s**2))
f_rhs = lambda P, K, e: (P * K**3 * (1 - e**2)**(3/2)) / (2 * pi * G.value)
f_lhs = lambda m1, m2, i: (m2**3 * sin(i)) / (m1 + m2)**2
# the earth
You can’t perform that action at this time.