This file contains 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
#!/bin/bash | |
# how to identify the processes to STOP/CONT | |
# this is any part of process command line | |
PROCESS="myscript.py" | |
# run this in one terminal: | |
# it tries to resume the processes every so often | |
while sleep 10m; do | |
pgrep -f "${PROCESS}"|xargs -rt kill -CONT |
This file contains 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
""" | |
If you ever made a plot of "fractions" or "rates" with symmetric error | |
bars, like in the plot shown, this mini-tutorial is for you. Here is how | |
to compute correct error bars, so that uncertainties in the fractions | |
do not go below 0% or above 100%. | |
If you have a histogram for | |
instance, and you detected k objects in a given bin. What is the rate | |
underlying at quantiles q=0.1, 0.5(median), 0.9? | |
""" |
This file contains 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 | |
def mcmc(logfunction, x0, nsteps, sigma_p): | |
samples = np.empty((nsteps, len(x0))) | |
logL0 = logfunction(x0) | |
naccepts = 0 | |
for i in range(nsteps): | |
x1 = np.random.normal(x0, sigma_p) | |
logL1 = logfunction(x1) | |
if logL1 - logL0 > np.log(np.random.uniform()): |
This file contains 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 sys | |
import numpy | |
import h5py | |
filename = sys.argv[1] | |
outfilename = filename.replace('.npy', '').replace('.gz', '').replace('.csv', '') + '.h5' | |
if filename.endswith('.npy'): | |
print('loading NPY...') | |
data = numpy.load(filename) | |
else: |
This file contains 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
""" | |
Download custom spectrum from http://www.swift.ac.uk/, programmatically | |
How to use: | |
$ python fetchswiftspectrum.py grbid timeslicespec | |
$ wget -nc --continue $(cat customspec.url)/a.tar.gz | |
""" |
This file contains 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
wget -nc http://cdn.gea.esac.esa.int/Gaia/gdr2/gaia_source/csv/ | |
grep -Eo GaiaSource_.*.csv.gz index.html | while read i; do | |
if [ -e $i ]; then | |
true | |
else | |
wget "http://cdn.gea.esac.esa.int/Gaia/gdr2/gaia_source/csv/$i" -O - | zcat | LC_ALL=C awk -F, '{print $2,$6,$8,sqrt($7**2+$9**2),$48}' | tail -n +2 | gzip > $i.tmp && mv $i.tmp $i | |
fi |
This file contains 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
#!/bin/bash | |
# Author: Johannes Buchner (C) 2013 | |
# tool for publishing sphinx documentation on github | |
# and releasing packages on PyPI | |
case "$1" in | |
doc) | |
# see https://help.github.com/articles/creating-project-pages-manually | |
make -C doc/ html && | |
git checkout gh-pages && |
This file contains 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
# To submit just at the right time (deadline 14:00 EST), | |
# | |
# How to use: | |
# - Make sure your clock is synced to https://arxiv.org/localtime | |
# - Prepare arxiv submission up to last page, move cursor over submission button | |
# - execute below function which will produce a left-button mouse click at 14:00 | |
# - if too early, unsubmit, fix clock, try again the next day | |
# | |
# Hopefully one day arxiv will randomize their submission ordering. |
This file contains 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 | |
# Sampling from a broken powerlaw or powerlaw segments | |
# Reference material: | |
# http://mathworld.wolfram.com/RandomNumber.html | |
# The strategy is to draw from each powerlaw segment, and make sure the proportions are right based on the segment integrals | |
# This code does not work correctly, improvements are welcome |
This file contains 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
# based on http://spatial-analyst.net/wiki/index.php?title=Uncertainty_visualization | |
import numpy | |
import colorsys | |
from matplotlib.colors import hsv_to_rgb | |
def to_rgb(value, error): | |
z = value | |
f1 = -90 - z*300 |