SEP

Wouldn't it be nice to be able to use just parts of Source Extractor?

  • Customize analysis
    • e.g., use detection part, do your own galaxy model fitting
  • Increase clarity of pipelines

SEP:

  • "Source Extractor as a library"
  • (Fork of stable parts of Source Extractor)
  • Roughly as fast as Source Extractor (that is to say: very)
  • C API and Python API
  • Avoid writing "sex tractor"

Docs: http://sep.readthedocs.org/

Source: https://github.com/kbarbary/sep

Demo

In [48]:
%matplotlib inline
import numpy as np
from fitsio import read
import sep
from matplotlib import pyplot as plt
In [49]:
data = read("/home/kyle/code/sep/data/image.fits")
In [57]:
fig = plt.figure(figsize=(10., 10.))
plt.imshow(data, cmap='gray', vmin=6500., vmax=7000., interpolation='nearest')
Out[57]:
<matplotlib.image.AxesImage at 0x7f5a0bc3f350>

Background

In [52]:
bkg = sep.Background(data)  # measure background
In [53]:
bkg.globalback, bkg.globalrms  # global statistics
Out[53]:
(6852.04931640625, 65.46165466308594)
In [54]:
bkgim = bkg.back()  # evaluate background
In [56]:
# plot background
fig = plt.figure(figsize=(10., 10.))
plt.imshow(bkgim, cmap='gray')
Out[56]:
<matplotlib.image.AxesImage at 0x7f5a0bc8e190>
In [58]:
bkg.subfrom(data)  # subtract background directly from data; no intermediate array

Detection

In [59]:
# detect objects
objects = sep.extract(data, 1.5 * bkg.globalrms)
In [60]:
# objects is a numpy structured array
len(objects)
Out[60]:
68
In [61]:
# position of 31st object
objects[30]['x'], objects[30]['y']
Out[61]:
(203.10133747668789, 109.06059750535223)
In [65]:
# fields available
objects.dtype.names
Out[65]:
('thresh',
 'npix',
 'tnpix',
 'xmin',
 'xmax',
 'ymin',
 'ymax',
 'x',
 'y',
 'x2',
 'y2',
 'xy',
 'a',
 'b',
 'theta',
 'cxx',
 'cyy',
 'cxy',
 'cflux',
 'flux',
 'cpeak',
 'peak',
 'xcpeak',
 'ycpeak',
 'xpeak',
 'ypeak',
 'flag')

Aperture photometry

In [63]:
# circular aperture photometry: radius=3 pixels, background annulus between 5 pixels and 8 pixels
flux, fluxerr, flags = sep.sum_circle(data, objects['x'], objects['y'], 3.0, bkgann=(5., 8.))
In [64]:
flux
Out[64]:
array([  2.25162955e+03,   2.63499737e+03,   5.85444320e+03,
         1.54784760e+03,   7.23583530e+04,   3.48852711e+03,
         6.19788935e+03,   2.51417800e+03,   2.64760126e+03,
         2.12978985e+04,   3.08757445e+03,   2.04251755e+03,
         2.61945684e+05,   4.16982015e+03,   2.42981474e+03,
         8.89787522e+03,   5.38766212e+03,   3.20622673e+03,
         1.69873525e+03,   2.03206650e+04,  -4.20566764e+04,
         2.78799318e+05,   2.23787136e+03,   2.27466906e+03,
         6.79528314e+03,   3.92706969e+03,   9.16830804e+03,
         1.06439412e+04,   2.16200605e+03,   5.35435465e+03,
         4.73560624e+03,   5.19578108e+03,   1.32791559e+04,
         1.11125971e+04,   2.79747792e+04,   3.69602560e+03,
         2.08565462e+03,   3.90868263e+03,   3.68388091e+03,
         3.43891467e+04,   1.10106128e+04,   2.27018763e+03,
         1.88817606e+04,   3.76533368e+03,   8.57008294e+02,
         1.05448205e+04,   1.58804410e+03,   3.50120488e+03,
         2.84574912e+03,   1.15526799e+04,   2.57541326e+04,
         1.18293712e+04,   1.10796543e+04,   8.87838402e+05,
         4.48077651e+03,   2.20192678e+03,   4.20277833e+03,
         2.43338897e+03,   1.73740612e+03,   2.75873052e+03,
         2.04678617e+03,   1.08465547e+04,   3.93292709e+03,
         2.71444324e+03,   3.53545672e+03,   2.89052764e+03,
         3.01581170e+03,   4.61238214e+03])

Speed

In [68]:
!cd /home/kyle/code/sep/ && bench.py
test image shape: (1024, 1024)
test image dtype: float32
measure background:  21.80 ms
subtract background:   3.59 ms
background array:   4.48 ms
rms array:   3.84 ms
extract:  57.08 ms  [1168 objects]

sep version:       0.3.0
photutils version: 0.0.dev134

| test                    | sep             | photutils       | ratio  |
|-------------------------|-----------------|-----------------|--------|
| 1024^2 image background |        24.18 ms |       993.36 ms |  41.09 |
| circles  r= 5  subpix=5 |    3.81 us/aper |  102.99 us/aper |  27.02 |
| circles  r= 5  exact    |    4.48 us/aper |  107.00 us/aper |  23.88 |
| ellipses r= 5  subpix=5 |    4.77 us/aper |  113.27 us/aper |  23.73 |
| ellipses r= 5  exact    |   14.23 us/aper |  135.94 us/aper |   9.55 |
In [ ]: