Skip to content

Instantly share code, notes, and snippets.

Avatar

Johannes Buchner JohannesBuchner

View GitHub Profile
@JohannesBuchner
JohannesBuchner / sample_broken_powerlaw.py
Last active Dec 2, 2018
Draw random numbers from broken powerlaw (broken code ATM)
View sample_broken_powerlaw.py
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
@JohannesBuchner
JohannesBuchner / uncertaincolors.py
Created Apr 6, 2018
Make maps with uncertainties
View uncertaincolors.py
# 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
@JohannesBuchner
JohannesBuchner / smf-fit.py
Created May 16, 2017
Fitting of stellar mass function with only two, uncertain data points
View smf-fit.py
import matplotlib.pyplot as plt
import numpy
from numpy import log, exp
import scipy.misc
import scipy.optimize
# see Buchner et al (2015), Appendix A, for details on the method
# http://adsabs.harvard.edu/abs/2015ApJ...802...89B
Nsamples = 1000
@JohannesBuchner
JohannesBuchner / rsync_on_change.sh
Created Dec 15, 2015
rsync loop that updates remote directory when local directory changes (using inotify)
View rsync_on_change.sh
while true
do
rsync -avz ./ user@host:remote/directory/
inotifywait -r ./
done
@JohannesBuchner
JohannesBuchner / rsyncprogress.py
Last active Sep 1, 2020
Progress bar for rsync
View rsyncprogress.py
"""
Progress bar for rsync
========================
Shows file progress and total progress as a progress bar.
Usage
---------
Run rsync with -P and pipe into this program. Example::
@JohannesBuchner
JohannesBuchner / photo-panning-video.diascope
Created Oct 18, 2015
Diascope file to create Ken Burns effects (zoom&pan) and transitions across 5 nice photos.
View photo-panning-video.diascope
format pal quality=1 aspect=4:3 mpeg2sound=ac3 mpeg2=3,192
# later: quality=1 interlaced
set dur=sec
set resize=resize
set title_offset=20%,80% title_area=15%
# http://computoser.com/track/722
# http://computoser.com/track/6340
audio spacy.mp3
#set label=green
@JohannesBuchner
JohannesBuchner / methodchoice.rst
Last active Aug 29, 2015
Method decision tree for parameter estimation and model comparison
View methodchoice.rst

Method decision tree

  • Write down your problem mathematically/statistically; stripping out astronomy-specific details from your model (e.g. pre-compute redshifts, weights, etc.)
  • Ideally, shorten and simplify it down to primitives of math and statistics, which can be implemented in any language.

For the following decision tree, keep in mind that typically, one first thinks

  • I just want to quickly find the best fit on this.
View enumerate-list-demo.rst

Enumerated List Bug Demo

First

  1. foo (should be 1.)
  2. bar (should be 2.)

Second

@JohannesBuchner
JohannesBuchner / statistics-minimal.rst
Last active Jul 31, 2016
ArXiV minimal statistics checklist
View statistics-minimal.rst

ArXiV minimal statistics checklist

This checklist help you identify and fix common errors/misinterpretation in your analysis, or of a paper you are refereeing.

  1. If you use p-values (from a KS test, Pearson correlation, etc.).
  1. What do you think a low p-value says?
  1. You have absolutely disproved the null hypothesis (e.g. "no correlation" is ruled out, the data are not sampled from this model, there is no difference between the population means).
@JohannesBuchner
JohannesBuchner / console-progress.py
Last active Aug 29, 2015
Console progress bar -- takes stdin from arbitrary commands and plots a progress bar
View console-progress.py
"""
SYNOPSIS: ./myprog | python console-progress.py
example for myprog:
#!/bin/bash
echo 100
for i in $(seq 1 100)
do
sleep 1
You can’t perform that action at this time.