Skip to content

Instantly share code, notes, and snippets.

@dfm
dfm / slider.js
Created September 12, 2012 20:41
Making bounding sliders with d3... see http://broiler.astrometry.net/s82/stars for a demo
(function () {
var root = this;
root.Slider = function (target, min, max, on_finish, on_change) {
var _this = this;
var w = 260, h = 20, margin = 10, radius = 5;
// On change event.
this.on_change = function () {};
@dfm
dfm / gist:3803041
Created September 29, 2012 03:15
Get the Thresher up and running on broiler
cd ~
git clone https://github.com/davidwhogg/TheThresher.git
cd TheThresher
virtualenv venv --distribute
. venv/bin/activate
pip install numpy
pip install -r requirements.txt
@dfm
dfm / imf-pgm.py
Created October 14, 2012 17:26
imf-pgm
#!/usr/bin/env python
from matplotlib import rc
rc("font", family="serif", size=12)
rc("text", usetex=True)
import daft
pgm = daft.PGM([3.5, 3], origin=[0, -0.5])
@dfm
dfm / LICENSE
Last active September 9, 2023 23:56
XKCD-style plots in d3
Copyright (c) 2012–2013 Daniel Foreman-Mackey
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
@dfm
dfm / README.md
Created October 19, 2012 20:15
Maximum likelihood parameter estimation for the skew normal based on samples

Usage

import sn

samples = np.array([...])  # Some numpy array of samples.

pars = sn.fit_skew_normal(samples)
@dfm
dfm / rs.py
Created October 31, 2012 03:49
Saving random state between steps in emcee
import cPickle as pickle
for pos, lnprob, rstate in sampler.sample(pos0, iterations=500, storechain=False):
# First save the positions as you usually would. Following: http://dfm.io/RrU8w8
# Save the current state.
with open("state.pkl", "w") as f:
pickle.dump([pos, lnprob, rstate], f, -1)
#
@dfm
dfm / README.md
Created November 15, 2012 16:19
Get some stars.

First install the Python module:

pip install casjobs

Then set the environment variables:

export CAS_DR9_WSID="1234567890" # get yours here: http://skyserver.sdss3.org/CasJobs/ChangeDetails.aspx
@dfm
dfm / damnit.py
Created November 20, 2012 22:45
y u suck so much?
fs = []
for i in range(10):
fs.append(lambda: i)
print [f() for f in fs]
@dfm
dfm / jsick.py
Created November 29, 2012 22:52
for jsick
import numpy as np
import emcee
def lnprob(x, ivar):
return -0.5 * np.array([np.sum(ivar * x ** 2), ])
ndim, nwalkers = 10, 100
ivar = 1. / np.random.rand(ndim)
p0 = [np.random.rand(ndim) for i in range(nwalkers)]
@dfm
dfm / README.md
Created November 30, 2012 14:56
Strange mpi4py error.

The script works.py runs fine and give reasonable results but the script notworking.py throws a cPickle.UnpicklingError and then stalls. The only difference is the line:

nwalkers = 100  # Works.
nwalkers = 150  # Doesn't work.