The goal of this notebook is to document how we retrieve DR14 SDSS ugriz and unWISE W1-W4 (forced) photometry for the HST HizEA sample of galaxies.
The input catalog is
and the output (row-matched) catalog containing just the SDSS/unWISE photometry is
In [34]:
import os
import numpy as np
import matplotlib.pyplot as plt
In [35]:
import fitsio
from astropy.io import ascii
from astropy.table import Table
In [36]:
import astropy.units as u
from astropy.coordinates import SkyCoord
In [37]:
%matplotlib inline
In [20]:
def read_hizea():
cat = ascii.read( os.path.join( os.getenv('HIZEA_DIR'), 'etc', 'hst_sample.dat' ) )
return cat
In [21]:
hizea = read_hizea()
hizea
Out[21]:
In [27]:
def read_unwise():
unwisefile = os.path.join(os.getenv('IM_DATA_DIR'), 'unwise', 'specmatch-dr10.fits')
ff = fitsio.FITS(unwisefile)
columns = list( ('wise_ra', 'wise_dec') )
columns = columns + ['wise_{}_nanomaggies'.format(band) for band in ('w1', 'w2', 'w3', 'w4')]
columns = columns + ['wise_{}_nanomaggies_ivar'.format(band) for band in ('w1', 'w2', 'w3', 'w4')]
print('Reading {}'.format(unwisefile))
ww = ff[1].where("wise_ra > 0 && wise_dec > 0")
unwise = Table(ff[1].read(columns=columns, ext=1, rows=ww))
return unwise
In [28]:
unwise = read_unwise()
unwise
Out[28]:
In [57]:
unwisecoord = SkyCoord(ra=unwise['wise_ra']*u.deg, dec=unwise['wise_dec']*u.deg)
hizeacoord = SkyCoord(ra=hizea['ra']*u.deg, dec=hizea['dec']*u.deg)
idx, sep2d, d3d = hizeacoord.match_to_catalog_sky(unwisecoord, nthneighbor=1)
In [67]:
_ = plt.hist(3600*(unwise['wise_ra'][idx] - hizea['ra']).data)
In [54]:
def qa_sep(sep2d):
fig, ax = plt.subplots()
_, _, _ = ax.hist(sep2d.arcsec, bins=100, range=(0, 0.5), alpha=0.5)
ax.set_xlabel('Separation (arcsec)')
ax.set_ylabel('Number of Galaxies')
In [55]:
qa_sep(sep2d)
In [44]:
rad = 0.5 * u.arcsec
In [45]:
indx_unwise, indx_hizea, d2d, _ = hizeacoord.search_around_sky(unwisecoord, rad)
nmatch = len(indx_unwise)
print('Found {}/{} objects with matching unWISE photometry within {}'.format(nmatch, len(unwise), rad))
In [48]:
indx_hizea
Out[48]:
In [49]:
d2d
Out[49]:
In [46]:
unwise[indx_unwise]
Out[46]:
In [ ]:
In [2]:
def write_casjobs_file():
outfile = os.path.join(os.sep, 'Users', 'ioannis', 'Desktop', 'hizea_sample.tmp')
dat = ascii.read( os.path.join( os.getenv('HIZEA_DIR'), 'etc', 'hst_sample.dat' ) )
out = Table()
out['hizea_id'] = np.arange(len(dat))
out['hizea_ra'] = dat['ra']
out['hizea_dec'] = dat['dec']
print('Writing {}'.format(outfile))
out.write(outfile, format='ascii.commented_header', overwrite=True)
return out
In [3]:
out = write_casjobs_file()
out
Out[3]:
Unfortunately when you import a simple ASCII file, CasJobs does not keep the RA,Dec coordinates in double precision. So first create a table in the Query tab (using the Quick submission option) thusly:
CREATE TABLE hizea ( hizea_id int, hizea_ra float, hizea_dec float );
and then in the Import tab be sure to import the data directly into this table.
Next, gather the SDSS ObjID using the RA,Dec positions and a 1 arcsec search radius. In the Query tab be sure to set the Context to DR14 and then execute the following query.
SELECT
h.hizea_id,
h.hizea_ra,
h.hizea_dec,
p.objid,
p.ra,
p.dec,
p.run,
p.rerun,
p.camcol
INTO mydb.hizea_match FROM mydb.hizea AS h
OUTER APPLY dbo.fGetNearestObjEq( h.hizea_ra, h.hizea_dec, 0.01666) AS n
LEFT JOIN dr14.PhotoObj AS p ON n.objid=p.objid
ORDER BY h.hizea_id
Finally, we use the output of the previous step to retrieve the full set of SDSS (ugriz) and unWISE (W1W2) forced photometry by executing the following query (again, using the DR14 Context). Note that we call the output table (not creatively) hst_sample_sdssWISEphot.fits.
SELECT
h.hizea_id,
p.objid,
p.ra,
p.dec,
p.run,
p.rerun,
p.camcol,
p.field,
p.type,
p.petroflux_u,
p.petroflux_g,
p.petroflux_r,
p.petroflux_i,
p.petroflux_z,
p.petrofluxivar_u,
p.petrofluxivar_g,
p.petrofluxivar_r,
p.petrofluxivar_i,
p.petrofluxivar_z,
p.modelflux_u,
p.modelflux_g,
p.modelflux_r,
p.modelflux_i,
p.modelflux_z,
p.modelfluxivar_u,
p.modelfluxivar_g,
p.modelfluxivar_r,
p.modelfluxivar_i,
p.modelfluxivar_z,
p.cmodelflux_u,
p.cmodelflux_g,
p.cmodelflux_r,
p.cmodelflux_i,
p.cmodelflux_z,
p.cmodelfluxivar_u,
p.cmodelfluxivar_g,
p.cmodelfluxivar_r,
p.cmodelfluxivar_i,
p.cmodelfluxivar_z,
p.extinction_u,
p.extinction_g,
p.extinction_r,
p.extinction_i,
p.extinction_z,
p.petroR50_u,
p.petroR50_g,
p.petroR50_r,
p.petroR50_i,
p.petroR50_z,
f.w1_nanomaggies,
f.w1_nanomaggies_ivar,
f.w2_nanomaggies,
f.w2_nanomaggies_ivar
INTO mydb.hst_sample_sdssWISEphot from mydb.hizea_match as h
JOIN dr14.PhotoObj AS p ON h.objid=p.objid
JOIN dr14.wiseForcedTarget AS f ON h.objid=f.objid
ORDER BY h.hizea_id
In [ ]: