I will demonstrate the use of cross-correlation to measure redshift using a Sloan template.


In [19]:
# get the data
import urllib
import astropy.io.fits as pyfits
lrgurl = 'http://www.sdss.org/dr5/algorithms/spectemplates/spDR2-028.fit'
urllib.urlretrieve(lrgurl,'spDR2-028.fit')
lrgobj = ('spDR2-028.fit')
lrgdata = pyfits.getdata(lrgobj)

In [32]:
spectrum = lrgdata[1,:] # 1 is "continuum-subtracted"

In [33]:
plot(spectrum)


Out[33]:
[<matplotlib.lines.Line2D at 0x108b90710>]

In [34]:
# sigh... can't really go on unless I have wavelength axis

In [35]:
import image_registration.iterative_zoom as iz

In [36]:
import scipy.signal

In [37]:
xc = scipy.signal.correlate(spectrum,spectrum,'full')

In [38]:
plot(xc)


Out[38]:
[<matplotlib.lines.Line2D at 0x108c2f0d0>]

In [78]:
reload(iz)
zoomed, zf, center = iz.iterative_zoom_1d(xc,minmax=np.max,mindiff=1e-10,verbose=True,return_zoomed=True,zoomshape=[50,],zoomstep=5)


Zoom factor      5, center =                           3554, offset=                             0, minpos=                          3554, mindiff=                   3.55271e-14

In [79]:
plot(zoomed)


Out[79]:
[<matplotlib.lines.Line2D at 0x10d189350>]

In [50]:



Out[50]:
-41.440239

In [ ]: