Skip to content

Instantly share code, notes, and snippets.

View astrofrog's full-sized avatar

Thomas Robitaille astrofrog

View GitHub Profile
$ make html
sphinx-build-2.7 -b html -d _build/doctrees . _build/html
Making output directory...
Running Sphinx v1.1.2
loading pickled environment... not yet created
loading intersphinx inventory from http://docs.python.org/objects.inv...
loading intersphinx inventory from http://docs.scipy.org/doc/scipy/reference/objects.inv...
loading intersphinx inventory from http://docs.scipy.org/doc/numpy/objects.inv...
loading intersphinx inventory from http://matplotlib.sourceforge.net/objects.inv...
[autosummary] generating autosummary for: ascii/ascii_api.rst, ascii/base_classes.rst, ascii/fixed_width_gallery.rst, ascii/index.rst, ascii/read.rst, ascii/write.rst, configs.rst, development/building_packaging.rst, development/codeguide.rst, development/codeguide_emacs.rst, ..., wcs/api.rst, wcs/api_distortion.rst, wcs/api_sip.rst, wcs/api_units.rst, wcs/api_wcs.rst, wcs/api_wcsprm.rst, wcs/examples.rst, wcs/history.rst, wcs/index.rst, wcs/relax.rst
from astropy.config import messaging
print '=' * 78
print "By default, only messages with level INFO and above are shown:"
print '-' * 78
messaging.debug("Nothing much here")
messaging.info("For information")
messaging.warn("Be careful")
messaging.error("Big time problem!")
@astrofrog
astrofrog / test_astropy_logger.py
Created April 6, 2012 21:08
Demonstration of the proposed Astropy logger implementation
import warnings
from astropy.config import logger
print '=' * 78
print "By default, only messages with level INFO and above are shown:"
print '-' * 78
logger.debug("Nothing much here")
logger.info("For information")
@astrofrog
astrofrog / custom_scalar_mappable.py
Created April 12, 2012 12:07
Using a custom scalarmappable
import matplotlib.pyplot as plt
import numpy as np
values = np.random.poisson(10., 100)
s = plt.cm.ScalarMappable()
s.set_clim(0., 20.)
s.set_cmap(plt.cm.RdBu)
s.set_array(values)
@astrofrog
astrofrog / simultaneous_fitting.py
Created April 13, 2012 10:01
Simultaneously fitting pixels in an image
from scipy.optimize import curve_fit
import numpy as np
# Define images
image1 = np.random.random((100, 200))
image2 = np.random.random((100, 200))
image3 = np.random.random((100, 200))
# Combine into a 3D cube
@astrofrog
astrofrog / merge_structured_arrays.py
Created April 29, 2012 19:32
Merge Numpy structured arrays
import numpy as np
def merge_structured_arrays(array1, array2):
n1 = len(array1)
n2 = len(array2)
array_out = array1.copy()
array_out.resize(n1 + n2)
array_out[n1:] = array2
return array_out
@astrofrog
astrofrog / rbf.py
Created May 9, 2012 15:12
Radial Basis Function Interpolation
# How to interpolate values from scattered points onto a grid
import numpy as np
from scipy.interpolate import Rbf
np.random.seed(2)
# Generate fake data (replace with real data)
N = 10
x = np.random.random(N) * 2. - 1.
@astrofrog
astrofrog / spherical_distance.py
Created May 15, 2012 13:44
spherical distance on sky
import numpy as np
def distance(ra1, dec1, ra2, dec2):
return np.degrees(np.arccos(np.sin(np.radians(dec1))
* np.sin(np.radians(dec2))
+ np.cos(np.radians(dec1))
* np.cos(np.radians(dec2))
* np.cos(np.radians(ra1) - np.radians(ra2))))
def distance_approx(ra1, dec1, ra2, dec2):
@astrofrog
astrofrog / performance.py
Created June 2, 2012 14:33
photutils performance
import time
import numpy as np
import photutils
from collections import OrderedDict
c = OrderedDict()
name = "Small data, single small aperture"
c[name] = {}
@astrofrog
astrofrog / ukidss.py
Created June 25, 2012 13:32
Querying UKIDSS database
import cookielib,urllib2,urllib,htmllib,formatter,os,sys
import pyfits
from math import cos,radians
import multiprocessing as mp
import time
class LinksExtractor(htmllib.HTMLParser): # derive new HTML parser
def __init__(self, formatter) : # class constructor
htmllib.HTMLParser.__init__(self, formatter) # base class constructor