Skip to content

Instantly share code, notes, and snippets.

View j-faria's full-sized avatar
🎯
Focusing

João Faria j-faria

🎯
Focusing
View GitHub Profile
@j-faria
j-faria / natsort.py
Created January 29, 2019 17:42
Natural sort in Python
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 / matrix_exponential.cpp
Last active December 4, 2022 13:16
C++ and pybind11 code for matrix exponential
#include <iostream>
#include <mkl.h>
#include <math.h>
#include <pybind11/pybind11.h>
#include <pybind11/numpy.h>
namespace py = pybind11;
using namespace pybind11::literals;
using namespace std;
@j-faria
j-faria / kepler.cpp
Created January 16, 2017 19:19
C++ implementation of "A Practical Method for Solving the Kepler Equation"
/**
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
j-faria / howto.md
Last active October 7, 2020 13:20
Auto-reload modules in IPython
  1. Create a file ~/.pythonrc.py
  2. Add
try:
    from IPython import get_ipython
    get_ipython().run_line_magic('load_ext', 'autoreload')
    get_ipython().run_line_magic('autoreload', '2')
except AttributeError:
 pass
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 December 5, 2019 14:52
The Keplerian and transit curves
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 September 6, 2019 16:48
query and download reduced data from the ESO Archive
#!/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 / BayesCorr.py
Created September 10, 2015 10:42
Bayesian correlation
#!/usr/env/python
# -*- coding: utf-8 -*-
# Written by Pedro Figueira.
# Original version can be found at https://pedrofigueira@bitbucket.org/pedrofigueira/bayesiancorrelation
# Modified by João Faria
"""Bayesian Correlation.
Usage:
@j-faria
j-faria / journal_abbreviations.py
Created July 2, 2019 19:00
Simplified abbreviations of frequently used journals (according to A&A)
# 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' ,