Skip to content

Instantly share code, notes, and snippets.

View taldcroft's full-sized avatar

Tom Aldcroft taldcroft

View GitHub Profile
@taldcroft
taldcroft / eventfile.py
Created May 8, 2011 18:26
Read FITS X-ray event file and return binned image with WCS
import numpy as np
import pywcs
import pyfits
class EventFile(object):
def __init__(self, filename, hdu=1):
self.filename= filename
hdus = pyfits.open(filename)
self.header = hdus[hdu].header
self.hdus = hdus
@taldcroft
taldcroft / pairs.py
Last active September 27, 2015 06:38
Find quasar pairs using KDTree
import scipy.spatial
from astropy.table import Table
dat = Table.read('sources_ra_dec_z.fits')
ok = ((dat['z'] > 0)
& (dat['ra'] > 150.0) & (dat['ra'] < 151.0)
& (dat['dec'] > 2.0) & (dat['dec'] < 3.0))
datok = dat[ok]
@taldcroft
taldcroft / conf.py
Created September 25, 2011 19:47
Template sphinx documentation configuration
# -*- coding: utf-8 -*-
#
# Eng archive documentation build configuration file, created by
# sphinx-quickstart on Mon Nov 23 22:45:31 2009.
#
# This file is execfile()d with the current directory set to its containing dir.
#
# Note that not all possible configuration values are present in this
# autogenerated file.
#
@taldcroft
taldcroft / version.py
Created September 25, 2011 19:48
Template version file for Python packages
"""
Version numbering for this module. The `major`, `minor`, and `bugfix` variables
hold the respective parts of the version number (bugfix is '0' if absent). The
`release` variable is True if this is a release, and False if this is a
development version.
NOTE: this code copied from astropy.version and simplified. Any license restrictions
therein are applicable.
"""
@taldcroft
taldcroft / argparse.py
Created September 25, 2011 19:51
Template argparse configuration
def get_options():
parser = argparse.ArgumentParser()
parser.add_argument("filename",
help="Model file")
parser.add_argument("--days",
type=float,
default=15,
help="Number of days in fit interval (default=90")
parser.add_argument("--stop",
help="Stop time of fit interval (default=model values)")
@taldcroft
taldcroft / reorder_struct_array.py
Created November 16, 2011 22:37
Select and possibly re-order columns in a structured array
import asciitable
def structured_array(arr, colnames):
"""Select and possibly re-order columns from a structured array.
:param arr: numpy structured array
:param colnames: column names to include
"""
dtypes = [(x, arr[x].dtype, arr[x].shape[1:]) for x in colnames]
dat = np.ndarray(len(arr), dtype=dtypes)
@taldcroft
taldcroft / inconsistent_handler.py
Created November 29, 2011 21:55
Example asciitable inconsistent_handler routines
"""Provide examples of defining asciitable inconsistent_handler routines to
deal with tables that have rows that are inconsistent with the header
definition.
"""
import asciitable
DEBUG = True
def skip_bad_lines(self, str_vals, ncols):
@taldcroft
taldcroft / calc_dpa_trend.py
Created December 15, 2011 02:36
Calculate DPA max temperatures for different pitch and CCD configurations
import numpy as np
import xija
from Chandra.Time import DateTime
from Ska.Matplotlib import plot_cxctime
import Ska.DBI
import Ska.engarchive.fetch_sci as fetch
import matplotlib.pyplot as plt
db = Ska.DBI.DBI(server='sybase', dbi='sybase', user='aca_read')
@taldcroft
taldcroft / example.rst
Created January 23, 2012 20:37
Example RST doc

Main

blah balh

Section

blah blah blah

@taldcroft
taldcroft / calc_scatter.py
Created May 15, 2012 17:40
Calculate scattered intensity
import numpy as np
from numpy import pi, sin, cos, exp
from scipy.interpolate import interp1d
from multiprocessing import Pool
RAD2ARCSEC = 180. * 3600. / pi # convert to arcsec for better scale
class CalcScatter(object):