We want to look for lenses by colour and spatial extent, in SDSS DR10 + WISE. We can grab this data from the SDSS skyserver SQL server from python, using the mechanize
web browser, and then manipulate the catalog with pandas
.
In [1]:
# Querying skyserver, using code from Eduardo Martin's blog post at
# http://balbuceosastropy.blogspot.com/2013/10/an-easy-way-to-make-sql-queries-from.html
import pandas as pd
def SDSS_select(sql):
from StringIO import StringIO # To read a string like a file
import mechanize
url = "http://skyserver.sdss3.org/dr10/en/tools/search/sql.aspx"
br = mechanize.Browser()
br.open(url)
br.select_form(name="sql")
br['cmd'] = sql
br['format']=['csv']
response = br.submit()
file_like = StringIO(response.get_data())
return pd.read_csv(file_like, skiprows=1)
We want a sample of galaxies and their 5-band photometry, positions and sizes. Let's focus on the photometric catalog, which goes deeper than SQLS.
In [4]:
galaxies = "SELECT top 1000 \
objid, ra, dec, \
dered_u AS mag_u, \
dered_g AS mag_g, \
dered_r AS mag_r, \
dered_i AS mag_i, \
dered_z AS mag_z \
FROM Galaxy"
print galaxies
This SQL checks out at the SkyServer SQL box, which has a syntax checking option.
In [5]:
data = SDSS_select(galaxies)
data
Out[5]:
Let's look for some structure in the color distribution. Initial plotting code from Josh Bloom's AstroHackWeek 2014 lecture.
In [6]:
# For pretty plotting
!pip install --upgrade seaborn
In [7]:
%pylab inline
import seaborn
seaborn.set()
import copy
First let's see the i-band magnitude distribution.
In [9]:
bins = hist(data['mag_i'].values,bins=100) ; xlabel("redshift") ; ylabel("N")
Out[9]:
Now let's look at everything else, colored by magnitude.
In [11]:
import matplotlib as mpl
import matplotlib.cm as cm
data = data[(data['mag_r'] > -9999)]
## truncate the color at 22 just to keep some contrast.
norm = mpl.colors.Normalize(vmin=min(data['mag_i'].values), vmax=22)
cmap = cm.jet_r
m = cm.ScalarMappable(norm=norm, cmap=cmap)
rez = pd.scatter_matrix(data[0:2000], alpha=0.2,figsize=[15,15],color=m.to_rgba(data['mag_i'].values))
Save this for future use.
In [8]:
data.to_csv('galaxies.clean.csv')
In [ ]: