Skip to content

Instantly share code, notes, and snippets.

@jiffyclub
jiffyclub / jdutil.py
Created October 18, 2011 02:03
Functions for converting dates to/from JD and MJD
"""
Functions for converting dates to/from JD and MJD. Assumes dates are historical
dates, including the transition from the Julian calendar to the Gregorian
calendar in 1582. No support for proleptic Gregorian/Julian calendars.
:Author: Matt Davis
:Website: http://github.com/jiffyclub
"""
@jiffyclub
jiffyclub / msky.py
Created October 25, 2011 00:29
Find modal sky on an array.
import numpy, pylab, scipy
from scipy import optimize
# Uses MEANCLIP from above
from meanclip import meanclip
def msky(inarray, do_plot=0, verbose=0, ptitle='', func=0):
"""
Find modal sky on an array.
@jiffyclub
jiffyclub / mytotal.py
Created October 25, 2011 00:32
Collapse 2-D array into one dimension.
import numpy
# Uses MEANCLIP from above
from meanclip import meanclip
def mytotal(inarray, axis, type='meanclip'):
"""
Collapse 2-D array in one dimension.
.. note:: MYTOTAL routine from ACS library.
@jiffyclub
jiffyclub / meanclip.py
Created October 25, 2011 00:34
Computes an iteratively sigma-clipped mean on a data set. Clipping is done about median, but mean is returned.
import numpy
def meanclip(indata, clipsig=3.0, maxiter=5, converge_num=0.02, verbose=0):
"""
Computes an iteratively sigma-clipped mean on a
data set. Clipping is done about median, but mean
is returned.
.. note:: MYMEANCLIP routine from ACS library.
@jiffyclub
jiffyclub / gist:1310949
Created October 25, 2011 00:36
Calculate a resistant estimate of the dispersion of a distribution. For an uncontaminated distribution, this is identical to the standard deviation.
import numpy
def robust_sigma(in_y, zero=0):
"""
Calculate a resistant estimate of the dispersion of
a distribution. For an uncontaminated distribution,
this is identical to the standard deviation.
Use the median absolute deviation as the initial
estimate, then weight points using Tukey Biweight.
@jiffyclub
jiffyclub / gausspsf2d.py
Created October 25, 2011 00:40
Simpler version of `PSF_GAUSSIAN` in IDL.
"""
Simpler version of `PSF_GAUSSIAN` in IDL.
:Authors: Pey Lian Lim (Python)
:Organization: Space Telescope Science Institute
:History:
* 2010/08/17 PLL converted from IDL to Python.
"""
# External modules
import numpy
@jiffyclub
jiffyclub / homework5-3.py
Created November 18, 2011 00:02
AI Class Homework 5.3 Demo in Python
"""
This script models the behavior of the agent in AI Class
Homework 5, Problem 3: http://youtu.be/212NkM6UCBc
The script prints the model grid and the total number of times a square was
visited by the agent over some number of simulations.
No actual TD-learning takes place in this script, the agent simply tries to
move from the start to the goal by moving to road squares on its preset path.
@jiffyclub
jiffyclub / hedit.py
Created November 25, 2011 21:47
Python 2.7+ compatible script for adding and modifying FITS header values. Can work on multiple files. This is a wrapper around pyfits.setval to make it accessible from the command line.
#!/usr/bin/env python
"""
Add or modify a header value. Type hedit -h for help.
Requires pyfits and Python 2.7+.
Author
------
@jiffyclub
git.io/jiffyclub
@jiffyclub
jiffyclub / imhead.py
Created November 25, 2011 21:54
Python 2.7+ script for printing a FITS header. Accepts multiple files and, optionally, keywords. This is a wrapper around pyfits.getheader to make it accessible from the command line.
#!/usr/bin/env python
"""
Print a FITS header or keyword. Type imhead -h for help.
Requires pyfits and Python 2.7+.
Author
------
@jiffyclub
git.io/jiffyclub
@jiffyclub
jiffyclub / hedit.py
Created November 28, 2011 19:33
Python 2.3+ compatible script for adding and modifying FITS header values. Can work on multiple files. This is a wrapper around pyfits.setval to make it accessible from the command line.
#!/usr/bin/env python
"""
Add or modify a header value. Type hedit.py -h for help.
Requires pyfits.
Author
------
@jiffyclub
git.io/jiffyclub