Skip to content

Instantly share code, notes, and snippets.

🎯
Focusing

João Faria j-faria

🎯
Focusing
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
j-faria / sinefit.py
Created Jan 31, 2019
Fit all the sines
View sinefit.py
from numpy import sin
from scipy import optimize
sine = lambda t, p: p[0] * sin(1. / p[1] * t + p[2]) + p[3]
sinefit = lambda t, y, ye, p0, **kwargs: optimize.leastsq(lambda p, t, y, ye: (sine(t, p) - y)/ye, p0, args=(t, y, ye), **kwargs)[0]
@j-faria
j-faria / natsort.py
Created Jan 29, 2019
Natural sort in Python
View natsort.py
from re import split
from glob import glob
natsort = lambda s: [int(t) if t.isdigit() else t.lower() for t in split(r'(\d+)', s)]
files = sorted(glob(path), key=natsort)
@j-faria
j-faria / continuum.py
Last active Jan 9, 2019
Trying to emulate IRAF's noao.onedspec.continuum
View continuum.py
import matplotlib.pyplot as plt
import numpy as np
from scipy.interpolate import LSQUnivariateSpline
def continuum(wave, flux, type='ratio', order=1, low_reject=2, high_reject=0,
niter=10):
m1 = np.ones_like(wave, dtype=np.bool) # use all points at first
m1 &= flux!=0 # but remove those where flux = 0
@j-faria
j-faria / gaussfit.py
Created Dec 12, 2018
Fit all the Gaussians
View gaussfit.py
from scipy import optimize
gauss = lambda x,p: p[0]*exp(-(x-p[1])**2/(2*p[2]**2)) + p[3]
gaussfit = lambda x,y,p0: optimize.leastsq(lambda p, x, y: gauss(x, p) - y, p0, args=(x, y))[0]
@j-faria
j-faria / etc.py
Last active Dec 6, 2018
Query the ESPRESSO ETC
View etc.py
import re
import requests
from itertools import product
import numpy as np
url = 'https://www.eso.org/observing/etc/bin/simu/espresso'
form_data = {
'almanac_time_option': 'almanac_time_option_ut_time',
@j-faria
j-faria / commonfiles.sh
Created Nov 26, 2018
Find the common files between two directories
View commonfiles.sh
# directories a and b
comm -12 <(ls a) <(ls b)
@j-faria
j-faria / fitInvGamma.py
Created Nov 2, 2018
Find shape and scale of InvGamma distribution
View fitInvGamma.py
# how to do the same as Michael Betancourt in
# https://betanalpha.github.io/assets/case_studies/gp_part3/part3.html
import numpy as np
from scipy.stats import invgamma
from scipy.optimize import minimize
f = lambda x, lims: \
(np.array([invgamma(a=x[0], scale=x[1]).cdf(lims[0]) - 0.01,
invgamma(a=x[0], scale=x[1]).sf(lims[1]) - 0.01])**2
@j-faria
j-faria / consts.py
Created Aug 29, 2018
How to get those constants in the exoplanet RV amplitude / mass equations!
View consts.py
import astropy.constants as c
import astropy.units as u
from math import pi
C = (2*pi*c.G)**(1/3)
# K [m/s] = C1 ....
C1 = C.to( (u.meter/u.second) * u.year**(1/3.) * (1/u.M_jup) * u.M_sun**(2/3.) ).value
# mp sini [Mjup] = C2 ....
@j-faria
j-faria / read_rdb.py
Last active Jun 23, 2018
.rdb file reader
View read_rdb.py
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
j-faria / fast.py
Created Jun 20, 2018
Three slightly different ways to do get stellar mass using the Torres calibration
View fast.py
def massTorres(teff, erteff, logg, erlogg, feh, erfeh,
ntrials=10000, corrected=True):
randomteff = teff + erteff * np.random.randn(ntrials)
randomlogg = logg + erlogg * np.random.randn(ntrials)
randomfeh = feh + erfeh * np.random.randn(ntrials)
# Parameters for the Torres calibration
a1 = 1.5689
a2 = 1.3787
a3 = 0.4243
You can’t perform that action at this time.