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
View context_chdir.py
import contextlib
import os
@contextlib.contextmanager
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
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
j-faria / eso_access_phase3.sh
Created Sep 6, 2019
query and download reduced data from the ESO Archive
View eso_access_phase3.sh
#!/bin/sh
#***********************************************************************
#* ESO Science Archive Facility
#* Programmatic Access
#*
#* Script: eso_access_phase3.sh
#* Shell: bash
#* Date: 15-Jul-2015
#* Contact: archive@eso.org
#* Description: Script to query and download reduced data (Phase 3)
@j-faria
j-faria / journal_abbreviations.py
Created Jul 2, 2019
Simplified abbreviations of frequently used journals (according to A&A)
View journal_abbreviations.py
# https://www.aanda.org/67-author-information/frequent-abbreviations
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
j-faria / gist:fdc0a97a72023dca26b084ec28ac9939
Created Apr 15, 2019
ESO archive downloads in parallel
View gist:fdc0a97a72023dca26b084ec28ac9939
sh downloadRequestNNNNNNscript.sh -X "-P 8 -L 1"
@j-faria
j-faria / mass_function_solve_sympy.py
Created Feb 28, 2019
How to solve the binary mass function for m2, using sympy
View mass_function_solve_sympy.py
from sympy import *
from astropy.constants import G
import astropy.units as u
G = G.to(u.m**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
@j-faria
j-faria / kepler_solve_sympy.py
Last active Feb 27, 2019
How to solve Kepler's equation with sympy
View kepler_solve_sympy.py
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
@j-faria
j-faria / binit.py
Created Feb 11, 2019
Nightly bin a dataset of radial velocities
View binit.py
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!
@j-faria
j-faria / months.py
Created Feb 11, 2019
Month name to number
View months.py
months = {
'Jan': 1,
'Feb': 2,
'Mar': 3,
'Apr': 4,
'May': 5,
'Jun': 6,
'Jul': 7,
'Aug': 8,
'Sep': 9,
@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]
You can’t perform that action at this time.