This file contains hidden or 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 sympy import symbols, sin, nsolve | |
| E = symbols('E') | |
| def eccentric_anomaly(M, ecc, prec=15): | |
| return nsolve(E - e*sin(E) - M, M, prec=prec) | |
| import mpmath as mp |
This file contains hidden or 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 | |
| ############################################################################### | |
| # the following is mostly a copy of the scipy implementation of | |
| # binned_statistic and binned_statistic_dd | |
| # but allowing for a weights parameter | |
| from scipy._lib.six import callable, xrange | |
| from scipy._lib._numpy_compat import suppress_warnings | |
| ## careful here! |
This file contains hidden or 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
| months = { | |
| 'Jan': 1, | |
| 'Feb': 2, | |
| 'Mar': 3, | |
| 'Apr': 4, | |
| 'May': 5, | |
| 'Jun': 6, | |
| 'Jul': 7, | |
| 'Aug': 8, | |
| 'Sep': 9, |
This file contains hidden or 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 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] |
This file contains hidden or 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 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) |
This file contains hidden or 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 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 |
This file contains hidden or 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 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] |
This file contains hidden or 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 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', |
This file contains hidden or 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
| # directories a and b | |
| comm -12 <(ls a) <(ls b) |
This file contains hidden or 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
| # 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 |