Skip to content

Instantly share code, notes, and snippets.

View davidgardenier's full-sized avatar

David Gardenier davidgardenier

View GitHub Profile
@davidgardenier
davidgardenier / beautiful_bokeh.py
Created November 23, 2017 19:32
Beautiful Bokeh Plots
from bokeh.io import save, export_svgs
from bokeh.plotting import figure, output_file, show
filename = "test.svg"
p = figure(plot_width=971, plot_height=600)
p.circle([1,2,3,4,5], [2,5,8,2,7], size=10)
# Set axis titles
p.xaxis.axis_label = "Important"
@davidgardenier
davidgardenier / parallel_planets.py
Last active September 25, 2017 14:53
Perfect Parallel Planets
import subprocess
import numpy as np
template = 'python ../code/mySpitzerTransit/4_finalPipelineMCMC.py '
template += '{0} {1} {2} {3} {4} {5} {6} > outfile_{7}.txt'
planets = ['Hatp32b',
'XO1b',
'Hatp1b',
'Wasp17b',
@davidgardenier
davidgardenier / unzip.sh
Last active September 23, 2017 14:15
Recursively unzip zip files
for f in `find ./ -name "*.zip"` ; do p=`pwd`; d=`dirname $f`; cd $d; b=`basename $f`; unzip -o $b; cd $p; done;
find . -name *.txt -exec rm -rf {} \;
for f in `find ./ -name "*.py"` ; do p=`pwd`; d=`dirname $f`; cd $d; b=`basename $f`; code2pdf -l -s a4 $b; cd $p; done
for f in */; do p=`pwd`; d=`dirname $f`; cd $d; pdftk "$f"*.pdf output "$p"/"${f::-1}".pdf; cd $p; done
import sys
import time
# main
parms = sys.argv
for p in parms:
time.sleep(5)
@davidgardenier
davidgardenier / parallel_claire
Last active September 18, 2017 13:05
For Claire
import subprocess
template = 'python script.py {0} {1} {2} {3} > file_{0}_{1}_{2}_{3}.txt'
args = [[1, 2, 3, 4], [5, 6, 7, 8]]
# Run commands in parallel
processes = []
for arg in args:
@davidgardenier
davidgardenier / parallel_bash_from_python.py
Created September 18, 2017 12:55
Run parallel bash scripts from python
import subprocess
template = 'python script.py {} {} {} {}'
args = [[1, 2, 3, 4], [5, 6, 7, 8]]
# Run commands in parallel
processes = []
for arg in args:
@davidgardenier
davidgardenier / t_sky.py
Created July 21, 2017 10:42
Sky temperature
def load_T_sky():
"""
Read the Haslam sky temperature map into a list from which temperatures can
be retrieved. The temperature sky map is given in the weird units of
HealPix, and despite looking up info on this coordinate system, I don't
have the foggiest idea of how to transform these to galactic coordinates. I
have therefore directly copied the following code from psrpoppy in the
assumption Sam Bates managed to figure it out.
Returns:
t_sky_list (list): List of sky temperatures in HealPix? coordinates?
@davidgardenier
davidgardenier / log.py
Created May 2, 2017 10:19
Logger implementation for frbpoppy
import logging
import logging.config
import os
import sys
class Log(object):
"""Setting default logging styles. Only really helpful when invoking as
>>> logger = Log().logger()
def sky_frac(beam_size):
"""
Calculate which fraction of the sky a beam covers
Args:
beam_size (float): In square degrees
Returns:
frac (float): Fraction of the sky that the beam covers
"""
@davidgardenier
davidgardenier / sky_frac.py
Created April 20, 2017 12:43
Calculate area/fraction on sky
def test_sky_frac(self):
frac = go.sky_frac(-90, 90, 0, 360)
self.assertTrue(frac > 0.99999999999)
frac = go.sky_frac(0, 90, 0, 360)
self.assertTrue(0.49 < frac < 0.51)
frac = go.sky_frac(0, 90, 0, 90)
self.assertTrue(0.124 < frac < 0.126)