Extended sources in SPIRE maps

This notebook was originally written by Peter Hurley to investigate the possibility of using XID+ to get flux posterior distributions for resolved objects in the far infrared. This is to be done by using fitted profiles from optical images.


In [1]:
import warnings
from matplotlib.cbook import MatplotlibDeprecationWarning
warnings.simplefilter('ignore', MatplotlibDeprecationWarning)
warnings.simplefilter('ignore', UserWarning)
warnings.simplefilter('ignore', RuntimeWarning)
warnings.simplefilter('ignore',UnicodeWarning)
#warnings.simplefilter('ignore',VisibleDeprecationWarning)

import numpy as np
import scipy.stats as st
import pylab as plt
from pymoc import MOC

import xidplus
from xidplus.stan_fit import SPIRE
from xidplus import posterior_maps as postmaps

from astropy.io import fits
from astropy import wcs
from astropy.table import Table
from astropy.convolution import Gaussian2DKernel
from astropy.convolution import convolve
from astropy.coordinates import SkyCoord
from astropy import units as u

import pickle
import seaborn as sns
import pandas as pd
sns.set(color_codes=True)

%matplotlib inline
import aplpy

In [2]:
hdulist_250=fits.open('./data/XMM-LSS-NEST_image_250_SMAP_v6.0.fits')
im250phdu=hdulist_250[0].header
im250hdu=hdulist_250[1].header
im250=hdulist_250[1].data*1.0E3
nim250=hdulist_250[2].data*1.0E3
w_250 = wcs.WCS(hdulist_250[1].header)
pixsize250=3600.0*w_250.wcs.cd[1,1] #pixel size (in arcseconds)
#hdulist.close()

hdulist_350=fits.open('./data/XMM-LSS-NEST_image_350_SMAP_v6.0.fits')
im350phdu=hdulist_350[0].header
im350hdu=hdulist_350[1].header
im350=hdulist_350[1].data*1.0E3
nim350=hdulist_350[2].data*1.0E3
w_350 = wcs.WCS(hdulist_350[1].header)
pixsize350=3600.0*w_350.wcs.cd[1,1] #pixel size (in arcseconds)
#hdulist.close()

hdulist_500=fits.open('./data/XMM-LSS-NEST_image_500_SMAP_v6.0.fits')
im500phdu=hdulist_500[0].header
im500hdu=hdulist_500[1].header
im500=hdulist_500[1].data*1.0E3
nim500=hdulist_500[2].data*1.0E3
w_500 = wcs.WCS(hdulist_500[1].header)
pixsize500=3600.0*w_500.wcs.cd[1,1] #pixel size (in arcseconds)
#hdulist.close()

In [3]:
source=Table.read('./data/extended_source_test.xml')

In [4]:
IRAC_sources=Table.read('./data/UDS_PACSxID24_v1.fits')

In [5]:
IRAC_sources


Out[5]:
<Table length=69614>
XIDRADecF_PACS_100__A4F_PACS_100__A5F_PACS_100__A6F_PACS_100__A7F_PACS_100__A8F_PACS_100__A10F_PACS_100Ferr_PACS_100__A4Ferr_PACS_100__A5Ferr_PACS_100__A6Ferr_PACS_100__A7Ferr_PACS_100__A8Ferr_PACS_100__A10Ferr_PACS_100F_PACS_100__SKYF_PACS_160__A4F_PACS_160__A5F_PACS_160__A6F_PACS_160__A7F_PACS_160__A8F_PACS_160__A10F_PACS_160Ferr_PACS_160__A4Ferr_PACS_160__A5Ferr_PACS_160__A6Ferr_PACS_160__A7Ferr_PACS_160__A8Ferr_PACS_160__A10Ferr_PACS_160F_PACS_160__SKYHELP_ID
degdegmJymJymJymJymJymJymJymJymJymJymJymJymJymJymJy / pixmJymJymJymJymJymJymJymJymJymJymJymJymJymJymJy / pix
int32float64float64float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32str25
3516433.400427-3.532034nannannannannannannannannannannannannannan0.0nannannannannannannannannannannannannannan0.0XMM-PACSxID24-UDS-1-00001
6955933.402787-3.552514nannannannannannannannannannannannannannan0.0nannannannannannannannannannannannannannan0.0XMM-PACSxID24-UDS-1-00002
6961233.402787-3.529534nannannannannannannannannannannannannannan0.0nannannannannannannannannannannannannannan0.0XMM-PACSxID24-UDS-1-00003
3515133.407827-3.534404nannannannannannannannannannannannannannan0.0nannannannannannannannannannannannannannan0.0XMM-PACSxID24-UDS-1-00004
3514133.409607-3.534104nannannannannannannannannannannannannannan0.0nannannannannannannannannannannannannannan0.0XMM-PACSxID24-UDS-1-00005
3512633.412387-3.544484nannannannannannannannannannannannannannan0.0nannannannannannannannannannannannannannan0.0XMM-PACSxID24-UDS-1-00006
6954533.413037-3.555364nannannannannannannannannannannannannannan0.0nannannannannannannannannannannannannannan0.0XMM-PACSxID24-UDS-1-00007
6961333.421437-3.521034nannannannannannannannannannannannannannan0.0nannannannannannannannannannannannannannan0.0XMM-PACSxID24-UDS-1-00008
6955633.422047-3.545824nannannannannannannannannannannannannannan0.0nannannannannannannannannannannannannannan0.0XMM-PACSxID24-UDS-1-00009
......................................................................................................
3534637.189607-5.359364nannannannannannannannannannannannannannan0.0nannannannannannannannannannannannannannan0.0XMM-PACSxID24-UDS-1-69605
13937.191917-5.397384nannannannannannannannannannannannannannan0.0nannannannannannannannannannannannannannan0.0XMM-PACSxID24-UDS-1-69606
11837.192737-5.400864nannannannannannannannannannannannannannan0.0nannannannannannannannannannannannannannan0.0XMM-PACSxID24-UDS-1-69607
3531337.192897-5.372624nannannannannannannannannannannannannannan0.0nannannannannannannannannannannannannannan0.0XMM-PACSxID24-UDS-1-69608
22237.192937-5.360784nannannannannannannannannannannannannannan0.0nannannannannannannannannannannannannannan0.0XMM-PACSxID24-UDS-1-69609
3532537.194807-5.378524nannannannannannannannannannannannannannan0.0nannannannannannannannannannannannannannan0.0XMM-PACSxID24-UDS-1-69610
3532237.196767-5.379374nannannannannannannannannannannannannannan0.0nannannannannannannannannannannannannannan0.0XMM-PACSxID24-UDS-1-69611
3519837.199537-5.443994nannannannannannannannannannannannannannan0.0nannannannannannannannannannannannannannan0.0XMM-PACSxID24-UDS-1-69612
3518537.210767-5.442134nannannannannannannannannannannannannannan0.0nannannannannannannannannannannannannannan0.0XMM-PACSxID24-UDS-1-69613
4437.212207-5.434754nannannannannannannannannannannannannannan0.0nannannannannannannannannannannannannannan0.0XMM-PACSxID24-UDS-1-69614

In [6]:
WISE_sources=Table.read('./data/WXSC.phot.clean_all.fits')


WARNING: UnitsWarning: 'mag.asec' did not parse as fits unit: At col 4, Unit 'asec' not supported by the FITS standard. Did you mean arcsec? [astropy.units.core]
WARNING:astropy:UnitsWarning: 'mag.asec' did not parse as fits unit: At col 4, Unit 'asec' not supported by the FITS standard. Did you mean arcsec?
WARNING: UnitsWarning: 'dn' did not parse as fits unit: At col 0, Unit 'dn' not supported by the FITS standard. Did you mean dN or daN? [astropy.units.core]
WARNING:astropy:UnitsWarning: 'dn' did not parse as fits unit: At col 0, Unit 'dn' not supported by the FITS standard. Did you mean dN or daN?

In [7]:
#Set some color info

cmap=sns.cubehelix_palette(8, start=.5, rot=-.75,as_cmap=True)

vmin=-1.7E1/1.0E3
vmax=4.446e+01/1.0E3
ra_zoom=source['RAJ2000']
dec_zoom=source['DEJ2000']
radius=0.05

In [8]:
c = SkyCoord(ra=ra_zoom, dec=dec_zoom)  
catalog = SkyCoord(ra=WISE_sources['ra'], dec=WISE_sources['dec'])  
idx, d2d, d3d = c.match_to_catalog_sky(catalog)

In [9]:
WISE_sources[idx]


Out[9]:
<Table length=1>
desigradecw1bestw1berrw1fw2bestw2berrw2fw3bestw3berrw3fw4bestw4berrw4fW1snrW2snrW3snrW4snrtileRisoR2isoR3isoR4isobapaflux_1err_1mag_1merr_1flg1flux_2err_2mag_2merr_2flg2flux_3err_3mag_3merr_3flg3flux_4err_4mag_4merr_4flg4W1W2W1W2erW2W3W2W3erW1W3W1W3erW3W4W3W4ermeanSB_1meanSB_2meanSB_3meanSB_4sky_1sig_1sky_2sig_2sky_3sig_3sky_4sig_4SB_1SB_2SB_3SB_4scale_1ascale_1bbeta_1abeta_1bscale_2ascale_2bbeta_2abeta_2bscale_3ascale_3bbeta_3abeta+3bscale_4ascale_4bbeta_4abeta_4bRtot_1ftot_1ftoterr_1mtot_1mterr1Rtot_2ftot_2ftoterr_2mtot_2mterr2Rtot_3ftot_3ftoterr_3mtot_3mterr3Rtot_4ftot_4ftoterr_4mtot_4mterr4Reff_1SBeff_1con_1Reff_2SBeff_2con_2Reff_3SBeff_3con_3Reff_4SBeff_4con_4R1convW1convuW1convR2convW2convuW2convR3convW3convuW3convR4convW4convuW4convRinnerRouterw1zerow2zerow3zerow4zerow1mprodw1mprow1rchi2w2mprodw2mprow2rchi2w3mprodw3mprow3rchi2w4mprodw4mprow4rchi2Rw123w123dw123Rw222w222dw222Rw318w318dw318Rw4155w4155dw4155xscproxRmomentRminorRfuzzyRfuzz2Rfuzz3Rfuzz4vcsepmin
degdegmagmagmagmagmagmagmagmagarcsecarcsecarcsecarcsecdegmJymJymagmagmJymJymagmagmJymJymagmagmJymJymagmagmagmagmagmagmagmagmagmagmag.asecmag.asecmag.asecmag.asecdndndndndndndndnmag.asecmag.asecmag.asecmag.asecarcsecarcsecarcsecarcsecarcsecarcsecarcsecarcsecarcsecmJymJymagmagarcsecmJymJymagmagarcsecmJymJymagmagarcsecmJymJymagmagarcsecmag.asecarcsecmag.asecarcsecmag.asecarcsecmag.asecarcsecmagmagarcsecmagmagarcsecmagmagarcsecmagmagarcsecarcsecmagmagmagmagmagmagmagmagmagmagmagmagarcsecmagmagarcsecmagmagarcsecmagmagarcsecmagmagarcsecarcsecarcsecarcsecarcsecarcsecarcsecarcsec
str23float64float64float32float32int32float32float32int32float32float32int32float32float32int32float32float32float32float32str12float64float64float64float64float64float64float64float64float64float64int32float64float64float64float64int32float64float64float64float64int32float64float64float64float64int32float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float32float32float32float32float32float32float32float32float32float32float32float32float64float64float64float64float64float64float64int32float32
J022136.46-053116.635.40201-5.521238.9790.01108.9370.0205.5940.022103.9420.0481098.790.550.422.7S_tile_133122.19108.5793.5382.590.69116.979.3370.848.9790.011144.70.498.9550.0121152.261.765.7010.0131183.8883.694.0790.02210.0420.0173.2530.0173.2960.0171.6880.02717.29817.26314.38413.2132.1690.0565.9490.061345.360.7127.1820.0723.62422.53618.37115.8928.0546.920.730.617.9346.910.890.6110.0358.850.770.58.652.220.820.52183.2880.710.8318.960.011183.2845.4770.5628.9360.013218.77168.0423.3325.5940.022194.61208.5339.1723.9420.04840.618.5963.1439.518.5133.0845.415.4752.7248.213.9512.39122.198.9790.011108.578.9550.01293.535.7010.01399.03.9850.025153.2199.220.519.518.013.011.540.02365.1511.5530.02321.758.4970.0259.9856.4250.0560.2172113.858.9880.011101.128.9750.01285.445.7390.01274.294.1510.02110.430.925.930.430.834.570.5-1138.8

In [10]:
def extended_source(beta,r_e,x_0,y_0,x,y):
    source_grid=np.exp(-beta*((x-x_0)**2+(y-y_0)**2)/r_e)
    return source_grid

In [11]:
xx, yy = np.meshgrid(np.arange(0,101), np.arange(0,101), sparse=True)

The extended source as seen in optical, MIPS, WISE band 4, and the SPIRE bands


In [12]:
source


Out[12]:
<Table masked=True length=1>
FieldID2MASXRAJ2000DEJ2000supRAdegsupDEdegdensityr_K20eJ_K20ee_J_K20ef_J_K20eH_K20ee_H_K20ef_H_K20eK_K20ee_K_K20ef_K_K20eKb_aKpaSb_aSpar_extJ_exte_J_extH_exte_H_extK_exte_K_extcc
degdegdegdegarcsmagmagmagmagmagmagdegdegarcsmagmagmagmagmagmag
objectobjectfloat64float64float64float64float64float64float64float64int16float64float64int16float64float64int16float64int16float64int16float64float64float64float64float64float64float64object
XMM-LSS02213646-053117035.401958-5.521393999999999935.401961999999997-5.52137999999999972.549999999999999851.010.5239999999999990.02409.98700000000000010.04000000000000000109.68800000000000060.05099999999999999700.66000000000000003-600.47999999999999998-7086.95999999999999410.1450.0249.73499999999999940.0400000000000000019.40499999999999940.0509999999999999970

In [13]:
def sersic(alpha,beta,x_0,y_0,x,y):
    source_grid=np.exp(-1*((((x-x_0)**2+(y-y_0)**2)**0.5)/alpha)**(1/beta))
    return source_grid
    

def extended_source(beta,r_e,x_0,y_0,x,y):
    source_grid=np.exp(-beta*((x-x_0)**2+(y-y_0)**2)/r_e)
    return source_grid

In [14]:
bulge=sersic(WISE_sources[idx]['scale_1a'],WISE_sources[idx]['beta_1a'],50,50,xx,yy) #Raphael added first 50 to make it run
disc=sersic(WISE_sources[idx]['scale_1b'],WISE_sources[idx]['beta_1b'],50,50,xx,yy)

In [15]:
plt.imshow(disc)
plt.colorbar()


Out[15]:
<matplotlib.colorbar.Colorbar at 0x150d09518>

In [16]:
#pixsize array (size of pixels in arcseconds)
pixsize=np.array([pixsize250,pixsize350,pixsize500])
#point spread function for the three bands
prfsize=np.array([18.15,25.15,36.3])


##---------fit using Gaussian beam-----------------------
prf250=Gaussian2DKernel(prfsize[0]/2.355,x_size=101,y_size=101)
prf250.normalize(mode='peak')
prf350=Gaussian2DKernel(prfsize[1]/2.355,x_size=101,y_size=101)
prf350.normalize(mode='peak')
prf500=Gaussian2DKernel(prfsize[2]/2.355,x_size=101,y_size=101)
prf500.normalize(mode='peak')

pind250=np.arange(0,101,1)*1.0/pixsize[0] #get 250 scale in terms of pixel scale of map
pind350=np.arange(0,101,1)*1.0/pixsize[1] #get 350 scale in terms of pixel scale of map
pind500=np.arange(0,101,1)*1.0/pixsize[2] #get 500 scale in terms of pixel scale of map

#convolved250 = convolve(prf250)[::6,::6]

In [17]:
fig=plt.figure(figsize=(30,10))
plt.subplot(2,1,1)
plt.imshow(convolve(bulge,prf250.array)[::6,::6],interpolation='nearest')
plt.colorbar()
plt.subplot(2,1,2)
plt.imshow(convolve(disc,prf250.array)[::6,::6],interpolation='nearest')
plt.colorbar()


Out[17]:
<matplotlib.colorbar.Colorbar at 0x14faab630>

In [18]:
w_250.wcs_world2pix(ra_zoom,dec_zoom,0)


Out[18]:
[array([ 1605.60172062]), array([ 1167.31004696])]

In [19]:
def radial_profile(data, center):
    x, y = np.indices((data.shape))
    r = np.sqrt((x - center[0])**2 + (y - center[1])**2)
    r = r.astype(np.int)

    tbin = np.bincount(r.ravel(), data.ravel())
    nr = np.bincount(r.ravel())
    radialprofile = tbin / nr
    return radialprofile

In [20]:
rad_profile = radial_profile(hdulist_250[1].data,w_250.wcs_world2pix(ra_zoom,dec_zoom,0))

fig, ax = plt.subplots()
plt.plot(rad_profile[0:22], 'x-')


Out[20]:
[<matplotlib.lines.Line2D at 0x1509053c8>]

Fit extended source with XID+


In [21]:
RA=np.concatenate((IRAC_sources['RA'].__array__(),source['RAJ2000'].__array__()))
Dec=np.concatenate((IRAC_sources['Dec'].__array__(),source['DEJ2000'].__array__()))

In [22]:
source


Out[22]:
<Table masked=True length=1>
FieldID2MASXRAJ2000DEJ2000supRAdegsupDEdegdensityr_K20eJ_K20ee_J_K20ef_J_K20eH_K20ee_H_K20ef_H_K20eK_K20ee_K_K20ef_K_K20eKb_aKpaSb_aSpar_extJ_exte_J_extH_exte_H_extK_exte_K_extcc
degdegdegdegarcsmagmagmagmagmagmagdegdegarcsmagmagmagmagmagmag
objectobjectfloat64float64float64float64float64float64float64float64int16float64float64int16float64float64int16float64int16float64int16float64float64float64float64float64float64float64object
XMM-LSS02213646-053117035.401958-5.521393999999999935.401961999999997-5.52137999999999972.549999999999999851.010.5239999999999990.02409.98700000000000010.04000000000000000109.68800000000000060.05099999999999999700.66000000000000003-600.47999999999999998-7086.95999999999999410.1450.0249.73499999999999940.0400000000000000019.40499999999999940.0509999999999999970

In [23]:
prior_cat='IRAC'
#---prior250--------
prior250=xidplus.prior(im250,nim250,im250phdu,im250hdu)#Initialise with map, uncertianty map, wcs info and primary header
prior250.prior_cat(RA,Dec,prior_cat)#Set input catalogue
prior250.prior_bkg(-5.0,5)#Set prior on background (assumes Guassian pdf with mu and sigma)
#---prior350--------
prior350=xidplus.prior(im350,nim350,im350phdu,im350hdu)
prior350.prior_cat(RA,Dec,prior_cat)
prior350.prior_bkg(-5.0,5)

#---prior500--------
prior500=xidplus.prior(im500,nim500,im500phdu,im500hdu)
prior500.prior_cat(RA,Dec,prior_cat)
prior500.prior_bkg(-5.0,5)

In [24]:
#pixsize array (size of pixels in arcseconds)
pixsize=np.array([pixsize250,pixsize350,pixsize500])
#point response function for the three bands
prfsize=np.array([18.15,25.15,36.3])
#use Gaussian2DKernel to create prf (requires stddev rather than fwhm hence pfwhm/2.355)
from astropy.convolution import Gaussian2DKernel

##---------fit using Gaussian beam-----------------------
prf250=Gaussian2DKernel(prfsize[0]/2.355,x_size=101,y_size=101)
prf250.normalize(mode='peak')
prf350=Gaussian2DKernel(prfsize[1]/2.355,x_size=101,y_size=101)
prf350.normalize(mode='peak')
prf500=Gaussian2DKernel(prfsize[2]/2.355,x_size=101,y_size=101)
prf500.normalize(mode='peak')

pind250=np.arange(0,101,1)*1.0/pixsize[0] #get 250 scale in terms of pixel scale of map
pind350=np.arange(0,101,1)*1.0/pixsize[1] #get 350 scale in terms of pixel scale of map
pind500=np.arange(0,101,1)*1.0/pixsize[2] #get 500 scale in terms of pixel scale of map

prior250.set_prf(prf250.array,pind250,pind250)#requires psf as 2d grid, and x and y bins for grid (in pixel scale)
prior350.set_prf(prf350.array,pind350,pind350)
prior500.set_prf(prf500.array,pind500,pind500)

In [25]:
print( 'fitting ' + str(prior250.nsrc)+' sources \n')
print( 'using ' +  str(prior250.snpix)+', '+ str(prior250.snpix)+' and '+ str(prior500.snpix)+' pixels')


fitting 69615 sources 

using 3380938, 3380938 and 845235 pixels

In [26]:
moc=MOC()
moc.read('./data/extended_source_test_MOC_rad4.fits')
prior250.set_tile(moc)
prior350.set_tile(moc)
prior500.set_tile(moc)

In [27]:
print( 'fitting '+ str(prior250.nsrc)+' sources \n')
print( 'using ' +  str(prior250.snpix)+', '+ str(prior350.snpix)+' and '+ str(prior500.snpix)+' pixels')


fitting 127 sources 

using 5488, 2843 and 1372 pixels

In [28]:
prior250.get_pointing_matrix()
prior350.get_pointing_matrix()
prior500.get_pointing_matrix()

In [29]:
prior250.upper_lim_map()
prior350.upper_lim_map()
prior500.upper_lim_map()

In [30]:
fit=SPIRE.all_bands(prior250,prior350,prior500,iter=1500)


/XID+SPIRE found. Reusing

In [31]:
posterior=xidplus.posterior_stan(fit,[prior250,prior350,prior500])

In [32]:
hdurep_250=postmaps.make_fits_image(prior250,prior250.sim)
hdurep_350=postmaps.make_fits_image(prior350,prior350.sim)
hdurep_500=postmaps.make_fits_image(prior500,prior500.sim)

In [33]:
rep_maps=postmaps.replicated_maps([prior250, prior350, prior500],posterior,nrep=1000)

In [34]:
rep_maps


Out[34]:
[array([[ -95.15871186,    9.6646541 ,   34.23258716, ...,   29.78146418,
           40.43826205,    9.09151328],
        [  -4.14585848,   53.19359969,   45.58618774, ...,   -9.70311013,
           11.07712368,   12.44218295],
        [  35.50114991,   -3.95510777,   28.21229014, ...,   21.85292699,
           -9.18307466,  -51.6020461 ],
        ..., 
        [ -31.0917198 ,   -5.93654978,  -13.14994426, ...,   24.74482587,
          -30.42967735,   51.2439061 ],
        [  50.61248221,   43.46473732,  -39.25446508, ...,  -25.02145441,
          -83.14067442,   19.43890849],
        [  17.27912463,   81.72239003,   25.24546498, ...,  110.85676235,
           13.1622351 ,  -18.95470862]]),
 array([[ 16.42307081, -25.45516102,  24.95580806, ...,  33.55797915,
          17.08750418, -54.3404259 ],
        [ 15.94924226, -45.87654087, -20.24761076, ...,  32.45133213,
          61.57367422, -13.68679266],
        [ -7.16009502,  31.23172322, -76.75048209, ...,  48.1314199 ,
          38.24646324,  88.61126662],
        ..., 
        [-47.23930747,  22.22454012,   7.31458678, ..., -40.2586409 ,
          37.22097222, -16.20577322],
        [ 72.03396453, -42.73479083,   8.72486486, ...,  -1.85594061,
           4.11008603,  36.80021382],
        [ 20.45555516, -10.23825638,  47.70064361, ..., -14.50447209,
          45.90664751,  -2.77036094]]),
 array([[ 26.69663456, -16.2484859 , -24.24689994, ...,   4.9639774 ,
         -11.57080342,  50.47903241],
        [ 14.58037212,  10.06637155,  16.31457931, ...,  27.34074897,
           3.88030931,   3.68617382],
        [  7.77969679,  28.49685942,   1.75688749, ...,  -0.18588177,
          22.59218494,  18.54975983],
        ..., 
        [-11.05512648,   1.87946992,  20.98454472, ..., -23.86384642,
         -17.02219915,  -4.23556235],
        [-14.03490837, -11.83580302,  -9.94061683, ...,  10.27165706,
          -7.03002479,   5.46537351],
        [ 11.60228358,   6.09969554,  15.68069085, ...,   6.01661344,
          -5.97750738,   4.08881869]])]

In [35]:
mod_map_250 = rep_maps[0]
mod_map_350 = rep_maps[1]
mod_map_500 = rep_maps[2]
mod_map_array_250 = rep_maps[0]
mod_map_array_350 = rep_maps[1]
mod_map_array_500 = rep_maps[2]

In [ ]:
pval_250=np.empty_like(prior250.sim)
for i in range(0,prior250.snpix):
    ind=mod_map_array_250[i,:]<prior250.sim[i]
    pval_250[i]=st.norm.ppf(sum(ind)/np.float(mod_map_array_250.shape[1]))
pval_250[np.isposinf(pval_250)]=6
    
pval_350=np.empty_like(prior350.sim)
for i in range(0,prior350.snpix):
    ind=mod_map_array_350[i,:]<prior350.sim[i]
    pval_350[i]=st.norm.ppf(sum(ind)/np.float(mod_map_array_350.shape[1]))
pval_350[np.isposinf(pval_350)]=6
    
pval_500=np.empty_like(prior500.sim)
for i in range(0,prior500.snpix):
    ind=mod_map_array_500[i,:]<prior500.sim[i]
    pval_500[i]=st.norm.ppf(sum(ind)/np.float(mod_map_array_500.shape[1]))
pval_500[np.isposinf(pval_500)]=6

In [ ]:
cmap=sns.cubehelix_palette(8, start=.5, rot=-.75,as_cmap=True)

vmin=-1.7E1/1.0E3
vmax=4.446e+01/1.0E3
ra_zoom=source['RAJ2000']
dec_zoom=source['DEJ2000']
radius=0.05
fig = plt.figure(figsize=(30,30))
cfhtls=aplpy.FITSFigure('./data/W1+1+2.U.11023_11534_3064_3575.fits',figure=fig,subplot=(3,3,1))
cfhtls.show_colorscale(vmin=-10,vmax=200,cmap=cmap)
cfhtls.recenter(ra_zoom, dec_zoom, radius=radius)


mips=aplpy.FITSFigure('./data/wp4_xmm-lss_mips24_map_v1.0.fits.gz',figure=fig,subplot=(3,3,2))
mips.show_colorscale(vmin=-0.001,vmax=5,cmap=cmap)
mips.recenter(ra_zoom, dec_zoom, radius=radius)

wise_band4=aplpy.FITSFigure('./data/L3a-0349m061_ac51-0349m061_ac51-w4-int-3_ra35.401958_dec-5.5213939_asec600.000.fits',figure=fig,subplot=(3,3,3))
wise_band4.show_colorscale(vmin=202,vmax=204,cmap=cmap)
wise_band4.recenter(ra_zoom, dec_zoom, radius=radius)
wise_band4.show_ellipses(ra_zoom, dec_zoom,2*WISE_sources[idx]['Riso']/3600.0,2*WISE_sources[idx]['Riso']*WISE_sources[idx]['ba']/3600.0, angle=360.0-WISE_sources[idx]['pa'],edgecolor='white',linewidth=2.0)


real_250 = aplpy.FITSFigure(hdulist_250[1],figure=fig,subplot=(3,3,4))
real_250.show_colorscale(vmin=vmin,vmax=0.8,cmap=cmap)
#real_250.show_markers(ra_list,dec_list, edgecolor='white', facecolor='white',
                #marker='o', s=40, alpha=0.5)
real_250.show_markers(IRAC_sources['RA'],IRAC_sources['DEC'], edgecolor='yellow', facecolor='yellow',
                marker='o', s=40, alpha=0.5)
real_250.recenter(ra_zoom, dec_zoom, radius=radius)
real_250.show_ellipses(ra_zoom, dec_zoom,2*source['r_K20e']/3600.0,2*source['r_K20e']*source['Kb_a']/3600.0, angle=360.0-source['Spa'],edgecolor='white',linewidth=2.0)
real_250.show_ellipses(ra_zoom, dec_zoom,2*WISE_sources[idx]['Riso']/3600.0,2*WISE_sources[idx]['Riso']*WISE_sources[idx]['ba']/3600.0, angle=360.0-WISE_sources[idx]['pa'],edgecolor='white',linewidth=2.0)

real_250.add_colorbar()
#real_250.show_markers(WISE_sources['ra'],WISE_sources['dec'], edgecolor='red', facecolor='red',
#                marker='o', s=40, alpha=0.5)

real_350 = aplpy.FITSFigure(hdulist_350[1],figure=fig,subplot=(3,3,5))
real_350.show_colorscale(vmin=vmin,vmax=0.8,cmap=cmap)
real_350.show_ellipses(ra_zoom, dec_zoom,2*source['r_K20e']/3600.0,2*source['r_K20e']*source['Kb_a']/3600.0, angle=360.0-source['Spa'],edgecolor='white',linewidth=2.0)

#real_350.show_markers(prior250.sra, prior250.sdec, edgecolor='black', facecolor='black',
                #marker='o', s=40, alpha=0.5)
real_350.recenter(ra_zoom, dec_zoom, radius=radius)

real_500 = aplpy.FITSFigure(hdulist_500[1],figure=fig,subplot=(3,3,6))
real_500.show_colorscale(vmin=vmin,vmax=0.8,cmap=cmap)
#real_500.show_markers(prior250.sra, prior250.sdec, edgecolor='black', facecolor='black',
                #marker='o', s=40, alpha=0.5)
real_500.recenter(ra_zoom, dec_zoom, radius=radius)
real_500.show_ellipses(ra_zoom, dec_zoom,2*source['r_K20e']/3600.0,2*source['r_K20e']*source['Kb_a']/3600.0, angle=360.0-source['Spa'],edgecolor='white',linewidth=2.0)

vmin=-6
vmax=6
cmap=sns.diverging_palette(220, 20,as_cmap=True)

res250=aplpy.FITSFigure(hdurep_250[1],figure=fig,subplot=(3,3,7))
res250.show_colorscale(vmin=vmin,vmax=vmax,cmap=cmap)
res250.show_markers(prior250.sra, prior250.sdec, edgecolor='black', facecolor='black',
                marker='o', s=80, alpha=0.5)
res250.recenter(ra_zoom, dec_zoom, radius=radius)

res350=aplpy.FITSFigure(hdurep_350[1],figure=fig,subplot=(3,3,8))
res350.show_colorscale(vmin=vmin,vmax=vmax,cmap=cmap)
res350.show_markers(prior350.sra, prior350.sdec, edgecolor='black', facecolor='black',
                marker='o', s=80, alpha=0.5)
res350.recenter(ra_zoom, dec_zoom, radius=radius)


res500=aplpy.FITSFigure(hdurep_500[1],figure=fig,subplot=(3,3,9))
res500.show_colorscale(vmin=vmin,vmax=vmax,cmap=cmap)
res500.show_markers(prior500.sra, prior500.sdec, edgecolor='black', facecolor='black',
                marker='o', s=80, alpha=0.5)


res250._data[prior250.sy_pix-np.min(prior250.sy_pix)-1,prior250.sx_pix-np.min(prior250.sx_pix)-1]=pval_250
res350._data[prior350.sy_pix-np.min(prior350.sy_pix)-1,prior350.sx_pix-np.min(prior350.sx_pix)-1]=pval_350
res500._data[prior500.sy_pix-np.min(prior500.sy_pix)-1,prior500.sx_pix-np.min(prior500.sx_pix)-1]=pval_500
res500.recenter(ra_zoom, dec_zoom, radius=radius)
#res500.tick_labels.set_xformat('dd.dd')
#res500.tick_labels.set_yformat('dd.dd')


res250.show_colorscale(vmin=vmin,vmax=vmax,cmap=cmap)
res350.show_colorscale(vmin=vmin,vmax=vmax,cmap=cmap)
res500.show_colorscale(vmin=vmin,vmax=vmax,cmap=cmap)
res250.add_colorbar()
res250.colorbar.set_location('top')
res350.add_colorbar()
res350.colorbar.set_location('top')
res500.add_colorbar()
res500.colorbar.set_location('top')

In [ ]:
def ellipse(x,y,x0,y0,angle,a,b):
    dx=x-x0
    dy=y-y0
    rad=((dx*np.cos(angle)-dy*np.sin(angle))/a)**2 + ((dx*np.sin(angle)+dy*np.cos(angle))/b)**2
    rad[rad<1.0]=1.0
    rad[rad>1.0]=0.0
    return rad
                                                                 
from astropy.modeling.models import Sersic2D

mod = Sersic2D(amplitude = 1, r_eff = 25, n=4, x_0=50, y_0=50,
               ellip=.5, theta=-1)

In [ ]:


In [ ]:
wcs_temp = wcs.WCS(prior250.imhdu)
source_pix_x,source_pix_y=wcs_temp.all_world2pix(ra_zoom,dec_zoom,0)

In [ ]:
a=WISE_sources[idx]['Riso']/pixsize[0]
b=WISE_sources[idx]['ba']*a
xx, yy = np.meshgrid(np.arange(0,WISE_sources[idx]['Riso']*3), np.arange(0,WISE_sources[idx]['Riso']*3))

In [ ]:
import scipy.signal as signal
extended_source_SMAP=signal.convolve(ellipse(xx,yy,xx.shape[1]/2.0,yy.shape[0]/2.0,WISE_sources[idx]['pa']*np.pi/180.0,a*pixsize[0],b*pixsize[0]),prf250.array,mode='same')

In [ ]:
plt.imshow(extended_source_SMAP)

In [ ]:
from astropy.modeling.models import Ellipse2D
from astropy.coordinates import Angle

theta = Angle(-1*WISE_sources[idx]['pa'], 'deg')
e = Ellipse2D(amplitude=100., x_0=xx.shape[1]/2.0,y_0=yy.shape[0]/2.0, a=a*pixsize[0], b=b*pixsize[0],
              theta=theta.radian)
plt.imshow(signal.convolve(e(xx,yy),prf250.array,mode='same'))

In [ ]:
from astropy.modeling.models import Sersic2D

mod = Sersic2D(amplitude = 1.0, r_eff = WISE_sources[idx]['scale_1b'], n=WISE_sources[idx]['beta_1b']	,x_0=xx.shape[1]/2.0,y_0=yy.shape[0]/2.0,
               ellip=1.0-WISE_sources[idx]['ba'], theta=theta.radian)
plt.imshow(signal.convolve(mod(xx,yy),prf250.array,mode='same'))

In [ ]:
pind250_source=np.arange(0,WISE_sources[idx]['Riso']*3)*1.0/pixsize[0]

In [ ]:
ipx=source_pix_x+xx*1.0/pixsize[0]-pind250_source[-1]/2
ipy=source_pix_y+yy*1.0/pixsize[0]-pind250_source[-1]/2
from scipy import interpolate
atemp = interpolate.griddata((ipx.ravel(), ipy.ravel()),extended_source_SMAP.ravel(), (prior250.sx_pix,prior250.sy_pix),
                                             method='nearest')

In [ ]:
def add_sersic_source(prior,source_no,angle,scale,beta,ba):
    from astropy.modeling.models import Sersic2D
    from astropy.coordinates import Angle
    import scipy.signal as signal


    import scipy.signal as signal
    wcs_temp = wcs.WCS(prior.imhdu)
    source_pix_x=prior.sx[source_no]
    source_pix_y=prior.sy[source_no]
    pixsize=np.absolute(prior.imhdu['CD2_2']*3600.0)

    mesh_length=np.max([prior.pindx.size,scale*5])
    xx, yy = np.meshgrid(np.arange(0,mesh_length), np.arange(0,mesh_length))
    theta = Angle(-1*angle, 'deg')

    mod = Sersic2D(amplitude = 1.0, r_eff =scale, n=beta,x_0=xx.shape[1]/2.0,y_0=yy.shape[0]/2.0,
               ellip=1.0-ba, theta=theta.radian)
    extended_source_SMAP=signal.convolve(mod(xx,yy),prior.prf,mode='same')
    pind_source=np.arange(0,mesh_length)*1.0/pixsize
    ipx=source_pix_x+xx*1.0/pixsize-pind_source[-1]/2
    ipy=source_pix_y+yy*1.0/pixsize-pind_source[-1]/2
    from scipy import interpolate
    atemp = interpolate.griddata((ipx.ravel(), ipy.ravel()),extended_source_SMAP.ravel(), (prior.sx_pix,prior.sy_pix),
                                             method='nearest')
    ind=atemp>0.001
    ind_not_prev=prior.amat_col != source_no
    prior.amat_data=np.append(prior.amat_data[ind_not_prev],atemp[ind])
    prior.amat_col=np.append(prior.amat_col[ind_not_prev],np.full(ind.sum(),source_no))
    prior.amat_row=np.append(prior.amat_row[ind_not_prev],np.arange(0,prior.snpix,dtype=int)[ind])
    return prior

    
def add_extended_source(prior,source_no,angle,semi_major,semi_minor):
    import scipy.signal as signal
    wcs_temp = wcs.WCS(prior.imhdu)
    source_pix_x=prior.sx[source_no]
    source_pix_y=prior.sy[source_no]
    pixsize=np.absolute(prior.imhdu['CD2_2']*3600.0)
    a=semi_major/pixsize
    b=semi_minor/pixsize
    xx, yy = np.meshgrid(np.arange(0,semi_major*2.5), np.arange(0,semi_major*2.5))
    extended_source_SMAP=signal.convolve(ellipse(xx,yy,xx.shape[1]/2.0,yy.shape[0]/2.0,angle*np.pi/180.0,a*pixsize,b*pixsize),prior.prf,mode='same')
    pind_source=np.arange(0,semi_major*2.5)*1.0/pixsize
    ipx=source_pix_x+xx*1.0/pixsize-pind_source[-1]/2
    ipy=source_pix_y+yy*1.0/pixsize-pind_source[-1]/2
    from scipy import interpolate
    atemp = interpolate.griddata((ipx.ravel(), ipy.ravel()),extended_source_SMAP.ravel(), (prior.sx_pix,prior.sy_pix),
                                             method='nearest')
    ind=atemp>0.001
    ind_not_prev=prior.amat_col != source_no
    prior.amat_data=np.append(prior.amat_data[ind_not_prev],atemp[ind])
    prior.amat_col=np.append(prior.amat_col[ind_not_prev],np.full(ind.sum(),source_no))
    prior.amat_row=np.append(prior.amat_row[ind_not_prev],np.arange(0,prior.snpix,dtype=int)[ind])
    return prior

In [ ]:
prior250.pindx.size

In [ ]:
prior250.imhdu['CD2_2']*3600.0

In [ ]:
extended_source_conv=postmaps.make_fits_image(prior250,atemp)

In [ ]:
vmin=-1.7E1/1.0E3
vmax=4.446e+01/1.0E3
cmap=sns.cubehelix_palette(8, start=.5, rot=-.75,as_cmap=True)
real_250 = aplpy.FITSFigure(extended_source_conv[1])
real_250.show_colorscale(vmin=vmin,vmax=0.8,cmap=cmap)
#real_250.show_markers(ra_list,dec_list, edgecolor='white', facecolor='white',
                #marker='o', s=40, alpha=0.5)
real_250.show_ellipses(ra_zoom, dec_zoom,2*WISE_sources[idx]['Riso']/3600.0,2*WISE_sources[idx]['Riso']*WISE_sources[idx]['ba']/3600.0, angle=360.0-WISE_sources[idx]['pa'],edgecolor='white',linewidth=2.0)

real_250.show_markers(IRAC_sources['RA'],IRAC_sources['DEC'], edgecolor='yellow', facecolor='yellow',
                marker='o', s=40, alpha=0.5)
#real_250.recenter(ra_zoom, dec_zoom, radius=radius)
real_250.add_colorbar()

In [ ]:
prior250.amat_data

Fit with disc and bulge


In [ ]:
#Concatenate the extended source twice, once for bulge once for disc
RA=np.concatenate((np.concatenate((IRAC_sources['RA'].__array__(),source['RAJ2000'].__array__())),source['RAJ2000'].__array__()))
Dec=np.concatenate((np.concatenate((IRAC_sources['DEC'].__array__(),source['DEJ2000'].__array__())),source['DEJ2000'].__array__()))

In [ ]:
prior_cat='IRAC'
#---prior250--------
prior250=xidplus.prior(im250,nim250,im250phdu,im250hdu)#Initialise with map, uncertianty map, wcs info and primary header
prior250.prior_cat(RA,Dec,prior_cat)#Set input catalogue
prior250.prior_bkg(-5.0,5)#Set prior on background (assumes Guassian pdf with mu and sigma)
#---prior350--------
prior350=xidplus.prior(im350,nim350,im350phdu,im350hdu)
prior350.prior_cat(RA,Dec,prior_cat)
prior350.prior_bkg(-5.0,5)

#---prior500--------
prior500=xidplus.prior(im500,nim500,im500phdu,im500hdu)
prior500.prior_cat(RA,Dec,prior_cat)
prior500.prior_bkg(-5.0,5)

In [ ]:
#pixsize array (size of pixels in arcseconds)
pixsize=np.array([pixsize250,pixsize350,pixsize500])
#point response function for the three bands
prfsize=np.array([18.15,25.15,36.3])
#use Gaussian2DKernel to create prf (requires stddev rather than fwhm hence pfwhm/2.355)
from astropy.convolution import Gaussian2DKernel

##---------fit using Gaussian beam-----------------------
prf250=Gaussian2DKernel(prfsize[0]/2.355,x_size=101,y_size=101)
prf250.normalize(mode='peak')
prf350=Gaussian2DKernel(prfsize[1]/2.355,x_size=101,y_size=101)
prf350.normalize(mode='peak')
prf500=Gaussian2DKernel(prfsize[2]/2.355,x_size=101,y_size=101)
prf500.normalize(mode='peak')

pind250=np.arange(0,101,1)*1.0/pixsize[0] #get 250 scale in terms of pixel scale of map
pind350=np.arange(0,101,1)*1.0/pixsize[1] #get 350 scale in terms of pixel scale of map
pind500=np.arange(0,101,1)*1.0/pixsize[2] #get 500 scale in terms of pixel scale of map

prior250.set_prf(prf250.array,pind250,pind250)#requires psf as 2d grid, and x and y bins for grid (in pixel scale)
prior350.set_prf(prf350.array,pind350,pind350)
prior500.set_prf(prf500.array,pind500,pind500)

In [ ]:
print 'fitting '+ str(prior250.nsrc)+' sources \n'
print 'using ' +  str(prior250.snpix)+', '+ str(prior250.snpix)+' and '+ str(prior500.snpix)+' pixels'

In [ ]:
from pymoc import MOC
moc=MOC()
moc.read('./data/extended_source_test_MOC_rad4.fits')
prior250.set_tile(moc)
prior350.set_tile(moc)
prior500.set_tile(moc)

In [ ]:
prior250.get_pointing_matrix()
prior350.get_pointing_matrix()
prior500.get_pointing_matrix()

In [ ]:
print 'fitting '+ str(prior250.nsrc)+' sources \n'
print 'using ' +  str(prior250.snpix)+', '+ str(prior250.snpix)+' and '+ str(prior500.snpix)+' pixels'

In [ ]:
prior250.upper_lim_map()
prior350.upper_lim_map()
prior500.upper_lim_map()

In [ ]:
prior250=add_extended_source(prior250,419,source['Spa'],source['r_K20e'],source['r_K20e']*source['Kb_a'])
prior250=add_extended_source(prior250,420,WISE_sources[idx]['pa'],WISE_sources[idx]['Riso'],WISE_sources[idx]['Riso']*WISE_sources[idx]['ba'])
prior350=add_extended_source(prior350,419,source['Spa'],source['r_K20e'],source['r_K20e']*source['Kb_a'])
prior350=add_extended_source(prior350,420,WISE_sources[idx]['pa'],WISE_sources[idx]['Riso'],WISE_sources[idx]['Riso']*WISE_sources[idx]['ba'])
prior500=add_extended_source(prior500,419,source['Spa'],source['r_K20e'],source['r_K20e']*source['Kb_a'])
prior500=add_extended_source(prior500,420,WISE_sources[idx]['pa'],WISE_sources[idx]['Riso'],WISE_sources[idx]['Riso']*WISE_sources[idx]['ba'])

In [ ]:
prior250=add_sersic_source(prior250,419,WISE_sources[idx]['pa'],WISE_sources[idx]['scale_1a'],WISE_sources[idx]['beta_1a'],WISE_sources[idx]['ba'])
prior250=add_sersic_source(prior250,420,WISE_sources[idx]['pa'],WISE_sources[idx]['scale_1b'],WISE_sources[idx]['beta_1b'],WISE_sources[idx]['ba'])

prior350=add_sersic_source(prior350,419,WISE_sources[idx]['pa'],WISE_sources[idx]['scale_1a'],WISE_sources[idx]['beta_1a'],WISE_sources[idx]['ba'])
prior350=add_sersic_source(prior350,420,WISE_sources[idx]['pa'],WISE_sources[idx]['scale_1b'],WISE_sources[idx]['beta_1b'],WISE_sources[idx]['ba'])

prior500=add_sersic_source(prior500,419,WISE_sources[idx]['pa'],WISE_sources[idx]['scale_1a'],WISE_sources[idx]['beta_1a'],WISE_sources[idx]['ba'])
prior500=add_sersic_source(prior500,420,WISE_sources[idx]['pa'],WISE_sources[idx]['scale_1b'],WISE_sources[idx]['beta_1b'],WISE_sources[idx]['ba'])

In [ ]:
SDSS=Table.read('./data/SDSS_extended_example.csv',format='ascii.csv')
SDSS

In [ ]:
prior250=add_sersic_source(prior250,419,SDSS['expPhi_u'],SDSS['expRad_u'],1.0,SDSS['expAB_u'])
prior350=add_sersic_source(prior350,419,SDSS['expPhi_u'],SDSS['expRad_u'],1.0,SDSS['expAB_u'])

prior500=add_sersic_source(prior500,419,SDSS['expPhi_u'],SDSS['expRad_u'],1.0,SDSS['expAB_u'])

In [ ]:
from xidplus.stan_fit import SPIRE
fit=SPIRE.all_bands(prior250,prior350,prior500,iter=1000)

In [ ]:
posterior=xidplus.posterior_stan(fit,[prior250,prior350,prior500])

In [ ]:
from xidplus import posterior_maps as postmaps

hdurep_250=postmaps.make_fits_image(prior250,prior250.sim)
hdurep_350=postmaps.make_fits_image(prior350,prior350.sim)
hdurep_500=postmaps.make_fits_image(prior500,prior500.sim)

In [ ]:
mod_map=np.full((hdurep_250[1].data.shape[1],hdurep_250[1].data.shape[0],500),np.nan)
mod_map_array=np.empty((prior250.snpix,500))

for i in range(0,500):
    mod_map_array[:,i]= postmaps.ymod_map(prior250,posterior.stan_fit[i,0,0:prior250.nsrc]).reshape(-1)+posterior.stan_fit[i,0,prior250.nsrc]+np.random.normal(scale=np.sqrt(prior250.snim**2+posterior.stan_fit[i,0,(prior250.nsrc+1)*3]**2))         
    mod_map[prior250.sx_pix-np.min(prior250.sx_pix)-1,prior250.sy_pix-np.min(prior250.sy_pix)-1,i]=mod_map_array[:,i]

In [ ]:
mod_map_350=np.full((hdurep_350[1].data.shape[1],hdurep_350[1].data.shape[0],500),np.nan)
mod_map_array_350=np.empty((prior350.snpix,500))

for i in range(0,500):
    mod_map_array_350[:,i]= postmaps.ymod_map(prior350,posterior.stan_fit[i,0,prior350.nsrc+1:2*prior350.nsrc+1]).reshape(-1)+posterior.stan_fit[i,0,2*prior350.nsrc+1]+np.random.normal(scale=np.sqrt(prior350.snim**2+posterior.stan_fit[i,0,1+(prior350.nsrc+1)*3]**2))         
    mod_map_350[prior350.sx_pix-np.min(prior350.sx_pix)-1,prior350.sy_pix-np.min(prior350.sy_pix)-1,i]=mod_map_array_350[:,i]

In [ ]:
mod_map_500=np.full((hdurep_500[1].data.shape[1],hdurep_500[1].data.shape[0],500),np.nan)
mod_map_array_500=np.empty((prior500.snpix,500))

for i in range(0,500):
    mod_map_array_500[:,i]= postmaps.ymod_map(prior500,posterior.stan_fit[i,0,2*prior500.nsrc+2:3*prior350.nsrc+2]).reshape(-1)+posterior.stan_fit[i,0,3*prior500.nsrc+2]+np.random.normal(scale=np.sqrt(prior500.snim**2+posterior.stan_fit[i,0,2+(prior500.nsrc+1)*3]**2))         
    mod_map_500[prior500.sx_pix-np.min(prior500.sx_pix)-1,prior500.sy_pix-np.min(prior500.sy_pix)-1,i]=mod_map_array_500[:,i]

In [ ]:
import scipy.stats as st

pval_250=np.empty_like(prior250.sim)
for i in range(0,prior250.snpix):
    ind=mod_map_array[i,:]<prior250.sim[i]
    pval_250[i]=st.norm.ppf(sum(ind)/np.float(mod_map_array.shape[1]))
pval_250[np.isposinf(pval_250)]=6
    
pval_350=np.empty_like(prior350.sim)
for i in range(0,prior350.snpix):
    ind=mod_map_array_350[i,:]<prior350.sim[i]
    pval_350[i]=st.norm.ppf(sum(ind)/np.float(mod_map_array_350.shape[1]))
pval_350[np.isposinf(pval_350)]=6
    
pval_500=np.empty_like(prior500.sim)
for i in range(0,prior500.snpix):
    ind=mod_map_array_500[i,:]<prior500.sim[i]
    pval_500[i]=st.norm.ppf(sum(ind)/np.float(mod_map_array_500.shape[1]))
pval_500[np.isposinf(pval_500)]=6

In [ ]:


In [ ]:
cmap=sns.cubehelix_palette(8, start=.5, rot=-.75,as_cmap=True)

vmin=-1.7E1/1.0E3
vmax=4.446e+01/1.0E3
ra_zoom=source['RAJ2000']
dec_zoom=source['DEJ2000']
radius=0.05
fig = plt.figure(figsize=(30,30))
cfhtls=aplpy.FITSFigure('./data/W1+1+2.U.11023_11534_3064_3575.fits',figure=fig,subplot=(3,3,1))
cfhtls.show_colorscale(vmin=-10,vmax=200,cmap=cmap)
cfhtls.recenter(ra_zoom, dec_zoom, radius=radius)


mips=aplpy.FITSFigure('./data/wp4_xmm-lss_mips24_map_v1.0.fits',figure=fig,subplot=(3,3,2))
mips.show_colorscale(vmin=-0.001,vmax=5,cmap=cmap)
mips.recenter(ra_zoom, dec_zoom, radius=radius)

wise_band4=aplpy.FITSFigure('./data/L3a-0349m061_ac51-0349m061_ac51-w4-int-3_ra35.401958_dec-5.5213939_asec600.000.fits',figure=fig,subplot=(3,3,3))
wise_band4.show_colorscale(vmin=202,vmax=204,cmap=cmap)
wise_band4.recenter(ra_zoom, dec_zoom, radius=radius)
wise_band4.show_ellipses(ra_zoom, dec_zoom,2*WISE_sources[idx]['Riso']/3600.0,2*WISE_sources[idx]['Riso']*WISE_sources[idx]['ba']/3600.0, angle=360.0-WISE_sources[idx]['pa'],edgecolor='white',linewidth=2.0)


real_250 = aplpy.FITSFigure(hdulist_250[1],figure=fig,subplot=(3,3,4))
real_250.show_colorscale(vmin=vmin,vmax=0.8,cmap=cmap)
#real_250.show_markers(ra_list,dec_list, edgecolor='white', facecolor='white',
                #marker='o', s=40, alpha=0.5)
real_250.show_markers(IRAC_sources['RA'],IRAC_sources['DEC'], edgecolor='yellow', facecolor='yellow',
                marker='o', s=40, alpha=0.5)
real_250.recenter(ra_zoom, dec_zoom, radius=radius)
real_250.show_ellipses(ra_zoom, dec_zoom,2*source['r_K20e']/3600.0,2*source['r_K20e']*source['Kb_a']/3600.0, angle=360.0-source['Spa'],edgecolor='white',linewidth=2.0)
real_250.show_ellipses(ra_zoom, dec_zoom,2*WISE_sources[idx]['Riso']/3600.0,2*WISE_sources[idx]['Riso']*WISE_sources[idx]['ba']/3600.0, angle=360.0-WISE_sources[idx]['pa'],edgecolor='white',linewidth=2.0)

real_250.add_colorbar()
#real_250.show_markers(WISE_sources['ra'],WISE_sources['dec'], edgecolor='red', facecolor='red',
#                marker='o', s=40, alpha=0.5)

real_350 = aplpy.FITSFigure(hdulist_350[1],figure=fig,subplot=(3,3,5))
real_350.show_colorscale(vmin=vmin,vmax=0.8,cmap=cmap)
real_350.show_ellipses(ra_zoom, dec_zoom,2*source['r_K20e']/3600.0,2*source['r_K20e']*source['Kb_a']/3600.0, angle=360.0-source['Spa'],edgecolor='white',linewidth=2.0)

#real_350.show_markers(prior250.sra, prior250.sdec, edgecolor='black', facecolor='black',
                #marker='o', s=40, alpha=0.5)
real_350.recenter(ra_zoom, dec_zoom, radius=radius)

real_500 = aplpy.FITSFigure(hdulist_500[1],figure=fig,subplot=(3,3,6))
real_500.show_colorscale(vmin=vmin,vmax=0.8,cmap=cmap)
#real_500.show_markers(prior250.sra, prior250.sdec, edgecolor='black', facecolor='black',
                #marker='o', s=40, alpha=0.5)
real_500.recenter(ra_zoom, dec_zoom, radius=radius)
real_500.show_ellipses(ra_zoom, dec_zoom,2*source['r_K20e']/3600.0,2*source['r_K20e']*source['Kb_a']/3600.0, angle=360.0-source['Spa'],edgecolor='white',linewidth=2.0)

vmin=-6
vmax=6
cmap=sns.diverging_palette(220, 20,as_cmap=True)

res250=aplpy.FITSFigure(hdurep_250[1],figure=fig,subplot=(3,3,7))
res250.show_colorscale(vmin=vmin,vmax=vmax,cmap=cmap)
res250.show_markers(prior250.sra, prior250.sdec, edgecolor='black', facecolor='black',
                marker='o', s=80, alpha=0.5)
res250.recenter(ra_zoom, dec_zoom, radius=radius)

res350=aplpy.FITSFigure(hdurep_350[1],figure=fig,subplot=(3,3,8))
res350.show_colorscale(vmin=vmin,vmax=vmax,cmap=cmap)
res350.show_markers(prior350.sra, prior350.sdec, edgecolor='black', facecolor='black',
                marker='o', s=80, alpha=0.5)
res350.recenter(ra_zoom, dec_zoom, radius=radius)


res500=aplpy.FITSFigure(hdurep_500[1],figure=fig,subplot=(3,3,9))
res500.show_colorscale(vmin=vmin,vmax=vmax,cmap=cmap)
res500.show_markers(prior500.sra, prior500.sdec, edgecolor='black', facecolor='black',
                marker='o', s=80, alpha=0.5)


res250._data[prior250.sy_pix-np.min(prior250.sy_pix)-1,prior250.sx_pix-np.min(prior250.sx_pix)-1]=pval_250
res350._data[prior350.sy_pix-np.min(prior350.sy_pix)-1,prior350.sx_pix-np.min(prior350.sx_pix)-1]=pval_350
res500._data[prior500.sy_pix-np.min(prior500.sy_pix)-1,prior500.sx_pix-np.min(prior500.sx_pix)-1]=pval_500
res500.recenter(ra_zoom, dec_zoom, radius=radius)
#res500.tick_labels.set_xformat('dd.dd')
#res500.tick_labels.set_yformat('dd.dd')


res250.show_colorscale(vmin=vmin,vmax=vmax,cmap=cmap)
res350.show_colorscale(vmin=vmin,vmax=vmax,cmap=cmap)
res500.show_colorscale(vmin=vmin,vmax=vmax,cmap=cmap)
res250.add_colorbar()
res250.colorbar.set_location('top')
res350.add_colorbar()
res350.colorbar.set_location('top')
res500.add_colorbar()
res500.colorbar.set_location('top')

In [ ]:
plt.imshow(mod_map[:,:,1],interpolation='nearest')
plt.colorbar()

In [ ]:
plt.hist(posterior.stan_fit[:,:,420])

In [ ]:
prior250.nsrc

In [ ]:


In [ ]:
cmap=sns.cubehelix_palette(8, start=.5, rot=-.75,as_cmap=True)

vmin=-1.7E1/1.0E3
vmax=4.446e+01/1.0E3
ra_zoom=source['RAJ2000']
dec_zoom=source['DEJ2000']
radius=0.05
fig = plt.figure(figsize=(30,30))
cfhtls=aplpy.FITSFigure('./data/W1+1+2.U.11023_11534_3064_3575.fits',figure=fig,subplot=(3,3,1))
cfhtls.show_colorscale(vmin=-10,vmax=200,cmap=cmap)
cfhtls.recenter(ra_zoom, dec_zoom, radius=radius)


mips=aplpy.FITSFigure('./data/wp4_xmm-lss_mips24_map_v1.0.fits',figure=fig,subplot=(3,3,2))
mips.show_colorscale(vmin=-0.001,vmax=5,cmap=cmap)
mips.recenter(ra_zoom, dec_zoom, radius=radius)

wise_band4=aplpy.FITSFigure('./data/L3a-0349m061_ac51-0349m061_ac51-w4-int-3_ra35.401958_dec-5.5213939_asec600.000.fits',figure=fig,subplot=(3,3,3))
wise_band4.show_colorscale(vmin=202,vmax=204,cmap=cmap)
wise_band4.recenter(ra_zoom, dec_zoom, radius=radius)
wise_band4.show_ellipses(ra_zoom, dec_zoom,2*WISE_sources[idx]['Riso']/3600.0,2*WISE_sources[idx]['Riso']*WISE_sources[idx]['ba']/3600.0, angle=360.0-WISE_sources[idx]['pa'],edgecolor='white',linewidth=2.0)


real_250 = aplpy.FITSFigure(hdulist_250[1],figure=fig,subplot=(3,3,4))
real_250.show_colorscale(vmin=vmin,vmax=0.8,cmap=cmap,stretch='arcsinh')
#real_250.show_markers(ra_list,dec_list, edgecolor='white', facecolor='white',
                #marker='o', s=40, alpha=0.5)
real_250.show_markers(IRAC_sources['RA'],IRAC_sources['DEC'], edgecolor='yellow', facecolor='yellow',
                marker='o', s=40, alpha=0.5)
real_250.recenter(ra_zoom, dec_zoom, radius=radius)
real_250.show_ellipses(ra_zoom, dec_zoom,2*source['r_K20e']/3600.0,2*source['r_K20e']*source['Kb_a']/3600.0, angle=360.0-source['Spa'],edgecolor='white',linewidth=2.0)
real_250.show_ellipses(ra_zoom, dec_zoom,2*WISE_sources[idx]['Riso']/3600.0,2*WISE_sources[idx]['Riso']*WISE_sources[idx]['ba']/3600.0, angle=360.0-WISE_sources[idx]['pa'],edgecolor='white',linewidth=2.0)

real_250.add_colorbar()
#real_250.show_markers(WISE_sources['ra'],WISE_sources['dec'], edgecolor='red', facecolor='red',
#                marker='o', s=40, alpha=0.5)

real_350 = aplpy.FITSFigure(hdulist_350[1],figure=fig,subplot=(3,3,5))
real_350.show_colorscale(vmin=vmin,vmax=0.8,cmap=cmap,stretch='arcsinh')
real_350.show_ellipses(ra_zoom, dec_zoom,2*source['r_K20e']/3600.0,2*source['r_K20e']*source['Kb_a']/3600.0, angle=360.0-source['Spa'],edgecolor='white',linewidth=2.0)

#real_350.show_markers(prior250.sra, prior250.sdec, edgecolor='black', facecolor='black',
                #marker='o', s=40, alpha=0.5)
real_350.recenter(ra_zoom, dec_zoom, radius=radius)

real_500 = aplpy.FITSFigure(hdulist_500[1],figure=fig,subplot=(3,3,6))
real_500.show_colorscale(vmin=vmin,vmax=0.8,cmap=cmap,stretch='arcsinh')
#real_500.show_markers(prior250.sra, prior250.sdec, edgecolor='black', facecolor='black',
                #marker='o', s=40, alpha=0.5)
real_500.recenter(ra_zoom, dec_zoom, radius=radius)
real_500.show_ellipses(ra_zoom, dec_zoom,2*source['r_K20e']/3600.0,2*source['r_K20e']*source['Kb_a']/3600.0, angle=360.0-source['Spa'],edgecolor='white',linewidth=2.0)

vmin=-1.7E1
vmax=800.0
#cmap=sns.diverging_palette(220, 20,as_cmap=True)

res250=aplpy.FITSFigure(hdurep_250[1],figure=fig,subplot=(3,3,7))
res250.show_colorscale(vmin=vmin,vmax=vmax,cmap=cmap,stretch='arcsinh')
res250.show_markers(prior250.sra, prior250.sdec, edgecolor='black', facecolor='black',
                marker='o', s=80, alpha=0.5)
res250.recenter(ra_zoom, dec_zoom, radius=radius)

res350=aplpy.FITSFigure(hdurep_350[1],figure=fig,subplot=(3,3,8))
res350.show_colorscale(vmin=vmin,vmax=vmax,cmap=cmap,stretch='arcsinh')
res350.show_markers(prior350.sra, prior350.sdec, edgecolor='black', facecolor='black',
                marker='o', s=80, alpha=0.5)
res350.recenter(ra_zoom, dec_zoom, radius=radius)


res500=aplpy.FITSFigure(hdurep_500[1],figure=fig,subplot=(3,3,9))
res500.show_colorscale(vmin=vmin,vmax=vmax,cmap=cmap,stretch='arcsinh')
res500.show_markers(prior500.sra, prior500.sdec, edgecolor='black', facecolor='black',
                marker='o', s=80, alpha=0.5)


res250._data[prior250.sy_pix-np.min(prior250.sy_pix)-1,prior250.sx_pix-np.min(prior250.sx_pix)-1]=mod_map_array[:,50]
res350._data[prior350.sy_pix-np.min(prior350.sy_pix)-1,prior350.sx_pix-np.min(prior350.sx_pix)-1]=mod_map_array_350[:,50]
res500._data[prior500.sy_pix-np.min(prior500.sy_pix)-1,prior500.sx_pix-np.min(prior500.sx_pix)-1]=mod_map_array_500[:,50]
res500.recenter(ra_zoom, dec_zoom, radius=radius)
#res500.tick_labels.set_xformat('dd.dd')
#res500.tick_labels.set_yformat('dd.dd')


res250.show_colorscale(vmin=vmin,vmax=vmax,cmap=cmap,stretch='arcsinh')
res350.show_colorscale(vmin=vmin,vmax=vmax,cmap=cmap,stretch='arcsinh')
res500.show_colorscale(vmin=vmin,vmax=vmax,cmap=cmap,stretch='arcsinh')
res250.add_colorbar()
res250.colorbar.set_location('top')
res350.add_colorbar()
res350.colorbar.set_location('top')
res500.add_colorbar()
res500.colorbar.set_location('top')

In [ ]:
plt.scatter(posterior.stan_fit[:,:,419].flatten(),posterior.stan_fit[:,:,420].flatten())

In [ ]:
plt.hist(posterior.stan_fit[:,:,-4].flatten())

In [ ]:
prior250
extended_source_conv=postmaps.make_fits_image(prior250,atemp)

In [ ]:
prior250.amat_col == 419

In [ ]:
prior250.nsrc

In [ ]:
atemp=np.empty_like(prior250.sim)
atemp[:]=0.0
ind=prior250.amat_col == 420
atemp[prior250.amat_row[ind]]=prior250.amat_data[ind]
extended_source_conv=postmaps.make_fits_image(prior250,atemp)
cmap=sns.cubehelix_palette(8, start=.5, rot=-.75,as_cmap=True)
real_250 = aplpy.FITSFigure(extended_source_conv[1])
real_250.show_colorscale(cmap=cmap)
#real_250.show_markers(ra_list,dec_list, edgecolor='white', facecolor='white',
                #marker='o', s=40, alpha=0.5)
real_250.show_ellipses(ra_zoom, dec_zoom,2*WISE_sources[idx]['Riso']/3600.0,2*WISE_sources[idx]['Riso']*WISE_sources[idx]['ba']/3600.0, angle=360.0-WISE_sources[idx]['pa'],edgecolor='white',linewidth=2.0)

real_250.show_markers(IRAC_sources['RA'],IRAC_sources['DEC'], edgecolor='yellow', facecolor='yellow',
                marker='o', s=40, alpha=0.5)
#real_250.recenter(ra_zoom, dec_zoom, radius=radius)

In [ ]:
fit=SPIRE.all_bands(prior250,prior350,prior500,iter=1500)

In [ ]:
posterior=xidplus.posterior_stan(fit,[prior250,prior350,prior500])

In [ ]:
from xidplus import posterior_maps as postmaps

hdurep_250=postmaps.make_fits_image(prior250,prior250.sim)
hdurep_350=postmaps.make_fits_image(prior350,prior350.sim)
hdurep_500=postmaps.make_fits_image(prior500,prior500.sim)

In [ ]:
mod_map=np.full((hdurep_250[1].data.shape[1],hdurep_250[1].data.shape[0],500),np.nan)
mod_map_array=np.empty((prior250.snpix,500))

for i in range(0,500):
    mod_map_array[:,i]= postmaps.ymod_map(prior250,posterior.stan_fit[i,0,0:prior250.nsrc]).reshape(-1)+posterior.stan_fit[i,0,prior250.nsrc]+np.random.normal(scale=np.sqrt(prior250.snim**2+posterior.stan_fit[i,0,(prior250.nsrc+1)*3]**2))         
    mod_map[prior250.sx_pix-np.min(prior250.sx_pix)-1,prior250.sy_pix-np.min(prior250.sy_pix)-1,i]=mod_map_array[:,i]

In [ ]:
mod_map_350=np.full((hdurep_350[1].data.shape[1],hdurep_350[1].data.shape[0],500),np.nan)
mod_map_array_350=np.empty((prior350.snpix,500))

for i in range(0,500):
    mod_map_array_350[:,i]= postmaps.ymod_map(prior350,posterior.stan_fit[i,0,prior350.nsrc+1:2*prior350.nsrc+1]).reshape(-1)+posterior.stan_fit[i,0,2*prior350.nsrc+1]+np.random.normal(scale=np.sqrt(prior350.snim**2+posterior.stan_fit[i,0,1+(prior350.nsrc+1)*3]**2))         
    mod_map_350[prior350.sx_pix-np.min(prior350.sx_pix)-1,prior350.sy_pix-np.min(prior350.sy_pix)-1,i]=mod_map_array_350[:,i]

In [ ]:
mod_map_500=np.full((hdurep_500[1].data.shape[1],hdurep_500[1].data.shape[0],500),np.nan)
mod_map_array_500=np.empty((prior500.snpix,500))

for i in range(0,500):
    mod_map_array_500[:,i]= postmaps.ymod_map(prior500,posterior.stan_fit[i,0,2*prior500.nsrc+2:3*prior350.nsrc+2]).reshape(-1)+posterior.stan_fit[i,0,3*prior500.nsrc+2]+np.random.normal(scale=np.sqrt(prior500.snim**2+posterior.stan_fit[i,0,2+(prior500.nsrc+1)*3]**2))         
    mod_map_500[prior500.sx_pix-np.min(prior500.sx_pix)-1,prior500.sy_pix-np.min(prior500.sy_pix)-1,i]=mod_map_array_500[:,i]

In [ ]:
import scipy.stats as st

pval_250=np.empty_like(prior250.sim)
for i in range(0,prior250.snpix):
    ind=mod_map_array[i,:]<prior250.sim[i]
    pval_250[i]=st.norm.ppf(sum(ind)/np.float(mod_map_array.shape[1]))
pval_250[np.isposinf(pval_250)]=6
    
pval_350=np.empty_like(prior350.sim)
for i in range(0,prior350.snpix):
    ind=mod_map_array_350[i,:]<prior350.sim[i]
    pval_350[i]=st.norm.ppf(sum(ind)/np.float(mod_map_array_350.shape[1]))
pval_350[np.isposinf(pval_350)]=6
    
pval_500=np.empty_like(prior500.sim)
for i in range(0,prior500.snpix):
    ind=mod_map_array_500[i,:]<prior500.sim[i]
    pval_500[i]=st.norm.ppf(sum(ind)/np.float(mod_map_array_500.shape[1]))
pval_500[np.isposinf(pval_500)]=6

In [ ]:
cmap=sns.cubehelix_palette(8, start=.5, rot=-.75,as_cmap=True)

vmin=-1.7E1/1.0E3
vmax=4.446e+01/1.0E3
ra_zoom=source['RAJ2000']
dec_zoom=source['DEJ2000']
radius=0.05
fig = plt.figure(figsize=(30,30))
cfhtls=aplpy.FITSFigure('./data/W1+1+2.U.11023_11534_3064_3575.fits',figure=fig,subplot=(3,3,1))
cfhtls.show_colorscale(vmin=-10,vmax=200,cmap=cmap)
cfhtls.recenter(ra_zoom, dec_zoom, radius=radius)


mips=aplpy.FITSFigure('./data/wp4_xmm-lss_mips24_map_v1.0.fits',figure=fig,subplot=(3,3,2))
mips.show_colorscale(vmin=-0.001,vmax=5,cmap=cmap)
mips.recenter(ra_zoom, dec_zoom, radius=radius)

wise_band4=aplpy.FITSFigure('./data/L3a-0349m061_ac51-0349m061_ac51-w4-int-3_ra35.401958_dec-5.5213939_asec600.000.fits',figure=fig,subplot=(3,3,3))
wise_band4.show_colorscale(vmin=202,vmax=204,cmap=cmap)
wise_band4.recenter(ra_zoom, dec_zoom, radius=radius)
wise_band4.show_ellipses(ra_zoom, dec_zoom,2*WISE_sources[idx]['Riso']/3600.0,2*WISE_sources[idx]['Riso']*WISE_sources[idx]['ba']/3600.0, angle=360.0-WISE_sources[idx]['pa'],edgecolor='white',linewidth=2.0)


real_250 = aplpy.FITSFigure(hdulist_250[1],figure=fig,subplot=(3,3,4))
real_250.show_colorscale(vmin=vmin,vmax=0.8,cmap=cmap)
#real_250.show_markers(ra_list,dec_list, edgecolor='white', facecolor='white',
                #marker='o', s=40, alpha=0.5)
real_250.show_markers(IRAC_sources['RA'],IRAC_sources['DEC'], edgecolor='yellow', facecolor='yellow',
                marker='o', s=40, alpha=0.5)
real_250.recenter(ra_zoom, dec_zoom, radius=radius)
real_250.show_ellipses(ra_zoom, dec_zoom,2*source['r_K20e']/3600.0,2*source['r_K20e']*source['Kb_a']/3600.0, angle=360.0-source['Spa'],edgecolor='white',linewidth=2.0)
real_250.show_ellipses(ra_zoom, dec_zoom,2*WISE_sources[idx]['Riso']/3600.0,2*WISE_sources[idx]['Riso']*WISE_sources[idx]['ba']/3600.0, angle=360.0-WISE_sources[idx]['pa'],edgecolor='white',linewidth=2.0)

real_250.add_colorbar()
#real_250.show_markers(WISE_sources['ra'],WISE_sources['dec'], edgecolor='red', facecolor='red',
#                marker='o', s=40, alpha=0.5)

real_350 = aplpy.FITSFigure(hdulist_350[1],figure=fig,subplot=(3,3,5))
real_350.show_colorscale(vmin=vmin,vmax=0.8,cmap=cmap)
real_350.show_ellipses(ra_zoom, dec_zoom,2*source['r_K20e']/3600.0,2*source['r_K20e']*source['Kb_a']/3600.0, angle=360.0-source['Spa'],edgecolor='white',linewidth=2.0)

#real_350.show_markers(prior250.sra, prior250.sdec, edgecolor='black', facecolor='black',
                #marker='o', s=40, alpha=0.5)
real_350.recenter(ra_zoom, dec_zoom, radius=radius)

real_500 = aplpy.FITSFigure(hdulist_500[1],figure=fig,subplot=(3,3,6))
real_500.show_colorscale(vmin=vmin,vmax=0.8,cmap=cmap)
#real_500.show_markers(prior250.sra, prior250.sdec, edgecolor='black', facecolor='black',
                #marker='o', s=40, alpha=0.5)
real_500.recenter(ra_zoom, dec_zoom, radius=radius)
real_500.show_ellipses(ra_zoom, dec_zoom,2*source['r_K20e']/3600.0,2*source['r_K20e']*source['Kb_a']/3600.0, angle=360.0-source['Spa'],edgecolor='white',linewidth=2.0)

vmin=-6
vmax=6
cmap=sns.diverging_palette(220, 20,as_cmap=True)

res250=aplpy.FITSFigure(hdurep_250[1],figure=fig,subplot=(3,3,7))
res250.show_colorscale(vmin=vmin,vmax=vmax,cmap=cmap)
res250.show_markers(prior250.sra, prior250.sdec, edgecolor='black', facecolor='black',
                marker='o', s=80, alpha=0.5)
res250.recenter(ra_zoom, dec_zoom, radius=radius)

res350=aplpy.FITSFigure(hdurep_350[1],figure=fig,subplot=(3,3,8))
res350.show_colorscale(vmin=vmin,vmax=vmax,cmap=cmap)
res350.show_markers(prior350.sra, prior350.sdec, edgecolor='black', facecolor='black',
                marker='o', s=80, alpha=0.5)
res350.recenter(ra_zoom, dec_zoom, radius=radius)


res500=aplpy.FITSFigure(hdurep_500[1],figure=fig,subplot=(3,3,9))
res500.show_colorscale(vmin=vmin,vmax=vmax,cmap=cmap)
res500.show_markers(prior500.sra, prior500.sdec, edgecolor='black', facecolor='black',
                marker='o', s=80, alpha=0.5)


res250._data[prior250.sy_pix-np.min(prior250.sy_pix)-1,prior250.sx_pix-np.min(prior250.sx_pix)-1]=pval_250
res350._data[prior350.sy_pix-np.min(prior350.sy_pix)-1,prior350.sx_pix-np.min(prior350.sx_pix)-1]=pval_350
res500._data[prior500.sy_pix-np.min(prior500.sy_pix)-1,prior500.sx_pix-np.min(prior500.sx_pix)-1]=pval_500
res500.recenter(ra_zoom, dec_zoom, radius=radius)
#res500.tick_labels.set_xformat('dd.dd')
#res500.tick_labels.set_yformat('dd.dd')


res250.show_colorscale(vmin=vmin,vmax=vmax,cmap=cmap)
res350.show_colorscale(vmin=vmin,vmax=vmax,cmap=cmap)
res500.show_colorscale(vmin=vmin,vmax=vmax,cmap=cmap)
res250.add_colorbar()
res250.colorbar.set_location('top')
res350.add_colorbar()
res350.colorbar.set_location('top')
res500.add_colorbar()
res500.colorbar.set_location('top')

In [ ]:
cmap=sns.cubehelix_palette(8, start=.5, rot=-.75,as_cmap=True)

vmin=-1.7E1/1.0E3
vmax=4.446e+01/1.0E3
ra_zoom=source['RAJ2000']
dec_zoom=source['DEJ2000']
radius=0.05
fig = plt.figure(figsize=(30,30))
cfhtls=aplpy.FITSFigure('./data/W1+1+2.U.11023_11534_3064_3575.fits',figure=fig,subplot=(3,3,1))
cfhtls.show_colorscale(vmin=-10,vmax=200,cmap=cmap)
cfhtls.recenter(ra_zoom, dec_zoom, radius=radius)


mips=aplpy.FITSFigure('./data/wp4_xmm-lss_mips24_map_v1.0.fits',figure=fig,subplot=(3,3,2))
mips.show_colorscale(vmin=-0.001,vmax=5,cmap=cmap)
mips.recenter(ra_zoom, dec_zoom, radius=radius)

wise_band4=aplpy.FITSFigure('./data/L3a-0349m061_ac51-0349m061_ac51-w4-int-3_ra35.401958_dec-5.5213939_asec600.000.fits',figure=fig,subplot=(3,3,3))
wise_band4.show_colorscale(vmin=202,vmax=204,cmap=cmap)
wise_band4.recenter(ra_zoom, dec_zoom, radius=radius)
wise_band4.show_ellipses(ra_zoom, dec_zoom,2*WISE_sources[idx]['Riso']/3600.0,2*WISE_sources[idx]['Riso']*WISE_sources[idx]['ba']/3600.0, angle=360.0-WISE_sources[idx]['pa'],edgecolor='white',linewidth=2.0)


real_250 = aplpy.FITSFigure(hdulist_250[1],figure=fig,subplot=(3,3,4))
real_250.show_colorscale(vmin=vmin,vmax=0.8,cmap=cmap,stretch='arcsinh')
#real_250.show_markers(ra_list,dec_list, edgecolor='white', facecolor='white',
                #marker='o', s=40, alpha=0.5)
real_250.show_markers(IRAC_sources['RA'],IRAC_sources['DEC'], edgecolor='yellow', facecolor='yellow',
                marker='o', s=40, alpha=0.5)
real_250.recenter(ra_zoom, dec_zoom, radius=radius)
real_250.show_ellipses(ra_zoom, dec_zoom,2*source['r_K20e']/3600.0,2*source['r_K20e']*source['Kb_a']/3600.0, angle=360.0-source['Spa'],edgecolor='white',linewidth=2.0)
real_250.show_ellipses(ra_zoom, dec_zoom,2*WISE_sources[idx]['Riso']/3600.0,2*WISE_sources[idx]['Riso']*WISE_sources[idx]['ba']/3600.0, angle=360.0-WISE_sources[idx]['pa'],edgecolor='white',linewidth=2.0)

real_250.add_colorbar()
#real_250.show_markers(WISE_sources['ra'],WISE_sources['dec'], edgecolor='red', facecolor='red',
#                marker='o', s=40, alpha=0.5)

real_350 = aplpy.FITSFigure(hdulist_350[1],figure=fig,subplot=(3,3,5))
real_350.show_colorscale(vmin=vmin,vmax=0.8,cmap=cmap,stretch='arcsinh')
real_350.show_ellipses(ra_zoom, dec_zoom,2*source['r_K20e']/3600.0,2*source['r_K20e']*source['Kb_a']/3600.0, angle=360.0-source['Spa'],edgecolor='white',linewidth=2.0)

#real_350.show_markers(prior250.sra, prior250.sdec, edgecolor='black', facecolor='black',
                #marker='o', s=40, alpha=0.5)
real_350.recenter(ra_zoom, dec_zoom, radius=radius)

real_500 = aplpy.FITSFigure(hdulist_500[1],figure=fig,subplot=(3,3,6))
real_500.show_colorscale(vmin=vmin,vmax=0.8,cmap=cmap,stretch='arcsinh')
#real_500.show_markers(prior250.sra, prior250.sdec, edgecolor='black', facecolor='black',
                #marker='o', s=40, alpha=0.5)
real_500.recenter(ra_zoom, dec_zoom, radius=radius)
real_500.show_ellipses(ra_zoom, dec_zoom,2*source['r_K20e']/3600.0,2*source['r_K20e']*source['Kb_a']/3600.0, angle=360.0-source['Spa'],edgecolor='white',linewidth=2.0)

vmin=-1.7E1
vmax=800.0
#cmap=sns.diverging_palette(220, 20,as_cmap=True)

res250=aplpy.FITSFigure(hdurep_250[1],figure=fig,subplot=(3,3,7))
res250.show_colorscale(vmin=vmin,vmax=vmax,cmap=cmap,stretch='arcsinh')
res250.show_markers(prior250.sra, prior250.sdec, edgecolor='black', facecolor='black',
                marker='o', s=80, alpha=0.5)
res250.recenter(ra_zoom, dec_zoom, radius=radius)

res350=aplpy.FITSFigure(hdurep_350[1],figure=fig,subplot=(3,3,8))
res350.show_colorscale(vmin=vmin,vmax=vmax,cmap=cmap,stretch='arcsinh')
res350.show_markers(prior350.sra, prior350.sdec, edgecolor='black', facecolor='black',
                marker='o', s=80, alpha=0.5)
res350.recenter(ra_zoom, dec_zoom, radius=radius)


res500=aplpy.FITSFigure(hdurep_500[1],figure=fig,subplot=(3,3,9))
res500.show_colorscale(vmin=vmin,vmax=vmax,cmap=cmap,stretch='arcsinh')
res500.show_markers(prior500.sra, prior500.sdec, edgecolor='black', facecolor='black',
                marker='o', s=80, alpha=0.5)


res250._data[prior250.sy_pix-np.min(prior250.sy_pix)-1,prior250.sx_pix-np.min(prior250.sx_pix)-1]=mod_map_array[:,50]
res350._data[prior350.sy_pix-np.min(prior350.sy_pix)-1,prior350.sx_pix-np.min(prior350.sx_pix)-1]=mod_map_array_350[:,50]
res500._data[prior500.sy_pix-np.min(prior500.sy_pix)-1,prior500.sx_pix-np.min(prior500.sx_pix)-1]=mod_map_array_500[:,50]
res500.recenter(ra_zoom, dec_zoom, radius=radius)
#res500.tick_labels.set_xformat('dd.dd')
#res500.tick_labels.set_yformat('dd.dd')


res250.show_colorscale(vmin=vmin,vmax=vmax,cmap=cmap,stretch='arcsinh')
res350.show_colorscale(vmin=vmin,vmax=vmax,cmap=cmap,stretch='arcsinh')
res500.show_colorscale(vmin=vmin,vmax=vmax,cmap=cmap,stretch='arcsinh')
res250.add_colorbar()
res250.colorbar.set_location('top')
res350.add_colorbar()
res350.colorbar.set_location('top')
res500.add_colorbar()
res500.colorbar.set_location('top')

In [ ]:
plt.scatter(posterior.stan_fit[:,:,421*2-1].flatten(),posterior.stan_fit[:,:,421*2].flatten())

In [ ]:
vmin=-1.7E1/1.0E3
vmax=4.446e+01/1.0E3
cmap=sns.cubehelix_palette(8, start=.5, rot=-.75,as_cmap=True)
real_250 = aplpy.FITSFigure(extended_source_conv[1])
real_250.show_colorscale(cmap=cmap)
#real_250.show_markers(ra_list,dec_list, edgecolor='white', facecolor='white',
                #marker='o', s=40, alpha=0.5)
real_250.show_ellipses(ra_zoom, dec_zoom,2*WISE_sources[idx]['Riso']/3600.0,2*WISE_sources[idx]['Riso']*WISE_sources[idx]['ba']/3600.0, angle=360.0-WISE_sources[idx]['pa'],edgecolor='white',linewidth=2.0)

real_250.show_markers(IRAC_sources['RA'],IRAC_sources['DEC'], edgecolor='yellow', facecolor='yellow',
                marker='o', s=40, alpha=0.5)
#real_250.recenter(ra_zoom, dec_zoom, radius=radius)
real_250.add_colorbar()

In [ ]: