Instantly share code, notes, and snippets.

🎯
Focusing

# João Fariaj-faria

🎯
Focusing
• Sort options
Created Dec 12, 2018
Fit all the Gaussians
View gaussfit.py
 from scipy import optimize gauss = lambda x,p: p*exp(-(x-p)**2/(2*p**2)) + p gaussfit = lambda x,y,p0: optimize.leastsq(lambda p, x, y: gauss(x, p) - y, p0, args=(x, y))
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',
Created Nov 26, 2018
Find the common files between two directories
View commonfiles.sh
 # directories a and b comm -12 <(ls a) <(ls b)
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, scale=x).cdf(lims) - 0.01, invgamma(a=x, scale=x).sf(lims) - 0.01])**2
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 ....
Last active May 7, 2019
Calculate stellar mass and radius using the Torres calibration
View parameters_torres.py
 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 @jit def massTorres(teff, erteff, logg, erlogg, feh, erfeh, ntrials=10000, corrected=True, add_intrinsic=True): """
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
Last active Apr 20, 2018
Count the number of color pages in a pdf
View countcolor.sh
 gs -o - -sDEVICE=inkcov input.pdf | grep -v "^ 0.00000 0.00000 0.00000" | grep "^ " | wc -l
Created Mar 28, 2018
A port of https://bitbucket.org/petershinners/reimport to Python 3
View reimport.py
 # MIT Licensed # Copyright (c) 2009-2010 Peter Shinners # # Permission is hereby granted, free of charge, to any person # obtaining a copy of this software and associated documentation # files (the "Software"), to deal in the Software without # restriction, including without limitation the rights to use, # copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the # Software is furnished to do so, subject to the following
Created Mar 22, 2018
View F8.py
 import numpy as np from scipy.stats import binned_statistic from astropy.convolution import convolve, Box1DKernel def f8(time, flux): """ Calculate the F8 statistic, as in Bastien et al. Both `time` and `flux` should be numpy arrays. The 8-hour flicker (F8) is determined by performing a 16-point (8 hour) boxcar smoothing of the light curve, subtracting it from the original light curve
You can’t perform that action at this time.