def plot(): cs = palettable.colorbrewer.qualitative.Set1_3.mpl_colors # Load parameter file with open('/home/lc585/qsosed/input.yml', 'r') as f: parfile = yaml.load(f) ebvmin = -0.075 ebvmax = 0.075 zmin = 1 zmax = 3.0 # Load stuff fittingobj = load(parfile) wavlen = fittingobj.get_wavlen() # Load data df = get_data() df = df[(df.z_HW >= zmin) & (df.z_HW <= zmax)] colmin, colmax = [], [] zs = np.arange(zmin, zmax + 0.025, 0.025) mycm = cm.get_cmap('Blues_r') mycm.set_under('w') cset = brewer2mpl.get_map('Blues', 'sequential', 9).mpl_colors mycm = truncate_colormap(mycm, 0.0, 0.8) fig = plt.figure(figsize=(figsize(1, vscale=0.8))) ax = fig.add_subplot(1, 1, 1) plt.tight_layout() #histogram definition xyrange = [[0., 3.0], [0, 3]] # data range bins = [100, 60] # number of bins thresh = 7 #density threshold #data definition xdat, ydat = df.z_HW, df.iVEGA - df.KVEGA # histogram the data hh, locx, locy = histogram2d(xdat, ydat, range=xyrange, bins=bins) posx = np.digitize(xdat, locx) posy = np.digitize(ydat, locy) #select points within the histogram ind = (posx > 0) & (posx <= bins[0]) & (posy > 0) & (posy <= bins[1]) hhsub = hh[posx[ind] - 1, posy[ind] - 1] # values of the histogram where the points are xdat1 = xdat[ind][hhsub < thresh] # low density points ydat1 = ydat[ind][hhsub < thresh] hh[hh < thresh] = np.nan # fill the areas with low density by NaNs im = ax.imshow(np.flipud(hh.T), cmap=mycm, extent=np.array(xyrange).flatten(), interpolation='none', aspect='auto', vmin=thresh, vmax=45) clb = fig.colorbar(im) clb.set_label('Number of Objects') ax.scatter(xdat1, ydat1, color=cset[-1], s=2) plt.ylim(0, 3.5) col = [] for z in zs: parfile['ext']['EBV'] = ebvmax magtmp, wavlentmp, fluxtmp = model(redshift=z, parfile=parfile) col.append(magtmp[3] - magtmp[8]) plt.plot(zs, col, label='E(B-V) = 0.075', color=cs[0], linewidth=1.0) upper_bound_1 = col[np.argmin(np.abs(zs - 1.0)):np.argmin(np.abs(zs - 1.5))] upper_bound_2 = col[np.argmin(np.abs(zs - 2.0)):np.argmin(np.abs(zs - 2.7))] col = [] for z in zs: parfile['ext']['EBV'] = ebvmin magtmp, wavlentmp, fluxtmp = model(redshift=z, parfile=parfile) col.append(magtmp[3] - magtmp[8]) plt.plot(zs, col, label='E(B-V) = -0.075', color=cs[0], linewidth=1.0) lower_bound_1 = col[np.argmin(np.abs(zs - 1.0)):np.argmin(np.abs(zs - 1.5))] lower_bound_2 = col[np.argmin(np.abs(zs - 2.0)):np.argmin(np.abs(zs - 2.7))] plt.fill_between(zs[np.argmin(np.abs(zs - 2.0)):np.argmin(np.abs(zs - 2.7))], lower_bound_2, upper_bound_2, facecolor='None', edgecolor=cs[0], linewidth=3.0) col = [] for z in zs: parfile['ext']['EBV'] = 0.0 magtmp, wavlentmp, fluxtmp = model(redshift=z, parfile=parfile) col.append(magtmp[3] - magtmp[8]) plt.plot(zs, col, label='E(B-V) = 0.0', color=cs[0], linewidth=1.0) plt.xlim(0.75, 3.5) plt.text(3.33821, 2.5, 'E(B-V)=', horizontalalignment='right', verticalalignment='center', color='black') plt.text(3.09608, 2.2, '0.075', horizontalalignment='left', verticalalignment='center', color='black') plt.text(3.09608, 1.2, '-0.075', horizontalalignment='left', verticalalignment='center', color='black') plt.text(3.09608, 1.7, '0.0', horizontalalignment='left', verticalalignment='center', color='black') plt.xlabel(r'Redshift $z$') plt.ylabel(r'$i$-$K$') plt.tight_layout() fig.savefig('/home/lc585/thesis/figures/chapter05/ik_versus_z_low_ext.pdf') plt.show() return None
def plot(): set_plot_properties() # change style cs = palettable.colorbrewer.qualitative.Set1_8.mpl_colors with open('/home/lc585/qsosed/input.yml', 'r') as f: parfile = yaml.load(f) fittingobj = load(parfile) wavlen = fittingobj.get_wavlen() lin = fittingobj.get_lin() galspc = fittingobj.get_galspc() ext = fittingobj.get_ext() galcnt = fittingobj.get_galcnt() ignmin = fittingobj.get_ignmin() ignmax = fittingobj.get_ignmax() ztran = fittingobj.get_ztran() lyatmp = fittingobj.get_lyatmp() lybtmp = fittingobj.get_lybtmp() lyctmp = fittingobj.get_lyctmp() whmin = fittingobj.get_whmin() whmax = fittingobj.get_whmax() qsomag = fittingobj.get_qsomag() flxcorr = fittingobj.get_flxcorr() cosmo = fittingobj.get_cosmo() params = Parameters() params.add('plslp1', value = -0.478) params.add('plslp2', value = -0.199) params.add('plbrk', value = 2.40250) params.add('bbt', value = 1.30626) params.add('bbflxnrm', value = 2.673) params.add('elscal', value = 1.240) params.add('scahal',value = 0.713) params.add('galfra',value = 0.0) params.add('bcnrm',value = 0.135) params.add('ebv',value = 0.0) params.add('imod',value = 18.0) # Load median magnitudes with open('/home/lc585/qsosed/sdss_ukidss_wise_medmag_ext.dat') as f: datz = np.loadtxt(f, usecols=(0,)) datz = datz[:-5] # Load filters ftrlst = fittingobj.get_ftrlst()[2:-2] lameff = fittingobj.get_lameff()[2:-2] bp = fittingobj.get_bp()[2:-2] # these are in ab and data is in vega dlam = fittingobj.get_bp()[2:-2] zromag = fittingobj.get_zromag()[2:-2] with open('ftgd_dr7.dat') as f: ftgd = np.loadtxt(f, skiprows=1, usecols=(1,2,3,4,5,6,7,8,9)) modarr = residual(params, parfile, wavlen, datz, lin, bp, dlam, zromag, galspc, ext, galcnt, ignmin, ignmax, ztran, lyatmp, lybtmp, lyctmp, ftrlst, whmin, whmax, cosmo, flxcorr, qsomag, ftgd) fname = '/home/lc585/qsosed/sdss_ukidss_wise_medmag_ext.dat' datarr = np.genfromtxt(fname, usecols=(5,7,9,11,13,15,17,19,21)) datarr[datarr < 0.0] = np.nan datarr = datarr[:-5, :] # remove less than lyman break col1 = np.arange(8) col2 = col1 + 1 col_label = ['$r$ - $i$', '$i$ - $z$', '$z$ - $Y$', '$Y$ - $J$', '$J$ - $H$', '$H$ - $K$', '$K$ - $W1$', '$W1$ - $W2$'] df = get_data() df = df[(df.z_HW > 1) & (df.z_HW < 3)] colstr1 = ['rVEGA', 'iVEGA', 'zVEGA', 'YVEGA', 'JVEGA', 'HVEGA', 'KVEGA', 'W1VEGA'] colstr2 = ['iVEGA', 'zVEGA', 'YVEGA', 'JVEGA', 'HVEGA', 'KVEGA', 'W1VEGA', 'W2VEGA'] ylims = [[0, 0.6], [-0.1, 0.5], [-0.1, 0.5], [-0.1, 0.5], [0.2, 0.9], [0.2, 0.9], [0.5, 1.6], [0.8, 1.5]] fig, axs = plt.subplots(4, 2, figsize=figsize(1, vscale=2), sharex=True) for i, ax in enumerate(axs.flatten()): #data definition ydat = datarr[:, col1[i]] - datarr[:, col2[i]] ax.scatter(datz, ydat, color='black', s=5, label='Data') ax.plot(datz, modarr[:,col1[i]] - modarr[:, col2[i]], color=cs[1], label='Model') # ax.scatter(df.z_HW, df[colstr1[i]] - df[colstr2[i]], s=1, alpha=0.1) ax.set_title(col_label[i], size=10) ax.set_ylim(ylims[i]) ax.set_xlim(0.75, 3.25) axs[0, 0].legend(bbox_to_anchor=(0.7, 0.99), bbox_transform=plt.gcf().transFigure, fancybox=True, shadow=True, scatterpoints=1, ncol=2) axs[3, 0].set_xlabel(r'Redshift $z$') axs[3, 1].set_xlabel(r'Redshift $z$') fig.tight_layout() fig.subplots_adjust(wspace=0.2, hspace=0.15, top=0.93) fig.savefig('/home/lc585/thesis/figures/chapter05/sed_color_plot.pdf') plt.show() return None
def plot(): plslp1 = 0.71 plslp2 = 0.05 plbrk = 2679.92 bbt = 1158.99 bbflxnrm = 0.25 galfra = 0.89 elscal = 0.72 imod = 18.0 scahal = 1.0 with open('input.yml', 'r') as f: parfile = yaml.load(f) # Load stuff fittingobj = load(parfile) wavlen = fittingobj.get_wavlen() flxcorr = np.array([1.0] * len(wavlen)) ik0, ik1, ik2 = [], [], [] zs = np.arange(2,4.01,0.01) for z in zs: print z magtmp, wavlentmp1, fluxtmp1 = model(plslp1, plslp2, plbrk, bbt, bbflxnrm, elscal, scahal, galfra, 0.0, imod, z, fittingobj, flxcorr, parfile) ik0.append( magtmp[3] - magtmp[8] ) magtmp, wavlentmp1, fluxtmp1 = model(plslp1, plslp2, plbrk, bbt, bbflxnrm, elscal, scahal, galfra, 0.1, imod, z, fittingobj, flxcorr, parfile) ik1.append( magtmp[3] - magtmp[8] ) magtmp, wavlentmp1, fluxtmp1 = model(plslp1, plslp2, plbrk, bbt, bbflxnrm, elscal, scahal, galfra, 0.2, imod, z, fittingobj, flxcorr, parfile) ik2.append( magtmp[3] - magtmp[8] ) datmag, sigma, datz, name, snr = loaddatraw('DR10', '/data/lc585/SDSS/DR10QSO_AllWISE_matched.v2.fits', True, 0, 23.0, 15.0, False, 0.1) fig = plt.figure(figsize=figsize(0.7)) ax = fig.add_subplot(111) ax.plot(zs,ik0,color='black',linewidth=2, zorder=1) ax.plot(zs,ik1,color='black',linewidth=2, zorder=1) ax.plot(zs,ik2,color='black',linewidth=2, zorder=1) ax.plot(datz, datmag[:,3] - datmag[:,8], marker='o', markersize=2, alpha=0.5, markeredgecolor='none', markerfacecolor='gray', linestyle='', zorder=0) textprops = dict(fontsize=10,ha='left',va='center', zorder=1, color='red') ax.text(3.5,0.646,'E(B-V) = 0.0', **textprops) ax.text(3.5,1.455,'E(B-V) = 0.1', **textprops) ax.text(3.5,2.285,'E(B-V) = 0.2', **textprops) ax.set_xlim(2,4) ax.set_ylim(-2,4) ax.set_xlabel(r'Redshift $z$') ax.set_ylabel(r'$i - K$') fig.tight_layout() fig.savefig('/home/lc585/thesis/figures/chapter06/ik_versus_z_high_ext.pdf') plt.show() return None
def plot(): mycm = cm.get_cmap('YlOrRd_r') mycm.set_under('w') mycm = truncate_colormap(mycm, 0.0, 0.8) cset = brewer2mpl.get_map('YlOrRd', 'sequential', 9).mpl_colors tab = Table.read('/data/lc585/QSOSED/Results/141031/sample1.fits') fig = plt.figure(figsize=figsize(0.7, vscale=1.5)) ax1 = fig.add_subplot(2,1,1) ax2 = fig.add_subplot(2,1,2) fig.subplots_adjust(wspace=0.0) fig.subplots_adjust(hspace=0.0) fig.subplots_adjust(top=0.99, bottom=0.2) #histogram definition xyrange = [[0.5,1.5],[-0.4,1.2]] # data range bins = [45,45] # number of bins thresh = 4 #density threshold #data definition w1mag = tab['W1MPRO_ALLWISE'] + 2.699 w2mag = tab['W2MPRO_ALLWISE'] + 3.339 z = tab['Z_HEWETT'] xdat, ydat = z, w1mag - w2mag # histogram the data hh, locx, locy = histogram2d(xdat, ydat, range=xyrange, bins=bins) posx = np.digitize(xdat, locx) posy = np.digitize(ydat, locy) #select points within the histogram ind = (posx > 0) & (posx <= bins[0]) & (posy > 0) & (posy <= bins[1]) hhsub = hh[posx[ind] - 1, posy[ind] - 1] # values of the histogram where the points are xdat1 = xdat[ind][hhsub < thresh] # low density points ydat1 = ydat[ind][hhsub < thresh] hh[hh < thresh] = np.nan # fill the areas with low density by NaNs im = ax1.imshow(np.flipud(hh.T),cmap=mycm,extent=np.array(xyrange).flatten(), interpolation='none',aspect='auto', vmin=thresh, vmax=45) ax1.scatter(xdat1, ydat1,color=cset[-1]) ax1.set_ylabel(r'$W1-W2$',fontsize=14) for tick in ax1.xaxis.get_major_ticks(): tick.label.set_fontsize(10) for tick in ax1.yaxis.get_major_ticks(): tick.label.set_fontsize(10) ax1.set_ylim(-0.4,1.2) ax1.set_xlim(0.25,1.7) im = ax2.imshow(np.flipud(hh.T),cmap=mycm,extent=np.array(xyrange).flatten(), interpolation='none',aspect='auto', vmin=thresh, vmax=45) ax2.scatter(xdat1, ydat1,color=cset[-1]) axcb = fig.add_axes([0.13,0.1,0.75,0.02]) clb = fig.colorbar(im, cax=axcb,orientation='horizontal') clb.set_label('Number of Objects',fontsize=12) clb.ax.tick_params(labelsize=10) ax2.set_xlabel(r'Redshift $z$',fontsize=14) ax2.set_ylabel(r'$W1-W2$',fontsize=14) for tick in ax2.xaxis.get_major_ticks(): tick.label.set_fontsize(10) for tick in ax2.yaxis.get_major_ticks(): tick.label.set_fontsize(10) ax2.set_ylim(ax1.get_ylim()) ax2.set_xlim(ax1.get_xlim()) tabtmp = tab tabtmp.sort('Z') #plt.tick_params(axis='both',which='major',labelsize=12) ax1.get_xaxis().set_ticks([]) ax1.set_yticklabels(['',0.0,0.2,0.4,0.6,0.8,1.0,1.2]) ax2.set_yticklabels([-0.4,-0.2,0.0,0.2,0.4,0.6,0.8,1.0]) #plt.scatter(z,w1mag-w2mag,c='grey',alpha=0.3) #xdat = z #ydat = w1mag - w2mag #zdat = tab['LOGLBOL'] # #plt.hexbin(xdat,ydat,C=tab['LUM_UV'],gridsize=10,cmap=mycm) #cb = plt.colorbar() #cb.set_label('UV Luminosity') #plt.ylim(-0.2,1.2) #plt.xlim(0.4,1.6) ##plt.savefig('/data/lc585/QSOSED/Results/141030/figure1.jpg') # #xyrange = [[0.5,1.5],[0,1.2]] # data range #bins = [10,6] # number of bins #thresh = 20 #hh, locx, locy = histogram2d(xdat, # ydat, # range=xyrange, # bins=bins) # # #print locy # #posx = np.digitize(xdat, locx) #posy = np.digitize(ydat, locy) # #grid = [] #for i in range(10): # row = [] # for j in range(6): # row.append(np.median(zdat[(posx == i+1) & (posy ==j+1)])) # grid.append(row) #ind = (posx > 0) & (posx <= bins[0]) & (posy > 0) & (posy <= bins[1]) #hhsub = hh[posx[ind] - 1, posy[ind] - 1] # values of the histogram where the points are #xdat1 = xdat[ind][hhsub < thresh] # low density points #ydat1 = ydat[ind][hhsub < thresh] #hh[hh < thresh] = np.nan # fill the areas with low density by NaNs #ax.scatter(z[ind],w1mag[ind]-w2mag[ind]) #im = ax.imshow(np.flipud(hh.T), # cmap=mycm, # extent=np.array(xyrange).flatten(), # interpolation='none', # aspect='auto',vmin=10) #ax.scatter(xdat1,ydat1) # loop over bins #for i in range(len(locx)): # for j in range(len(locy)): # print np.median(tab['LUM_UV'][ (posx == i) & (posy == j)]) #ax.hist2d(z, # w1mag-w2mag, # range=xyrange, # bins=bins, # cmap=mycm, # vmin=10.) with open('/home/lc585/Dropbox/IoA/QSOSED/Model/qsofit/input.yml', 'r') as f: parfile = yaml.load(f) fittingobj = load(parfile) wavlen = fittingobj.get_wavlen() with open('/data/lc585/QSOSED/Results/140811/allsample_2/fluxcorr.array','rb') as f: flxcorr = pickle.load(f) plslp1 = 0.46 plslp2 = 0.03 plbrk = 2822. bbt = 1216. bbflxnrm = 0.24 elscal = 0.71 scahal = 0.86 galfra = 0.31 ebv = 0.0 imod = 18.0 zs = np.arange(0.5,1.525,0.025) bbt = 1200. w1w2_model = [] for z in zs: magtmp, wavlentmp, fluxtmp = model(plslp1, plslp2, plbrk, bbt, bbflxnrm, elscal, scahal, galfra, ebv, imod, z, fittingobj, flxcorr, parfile) w1w2_model.append(magtmp[9] - magtmp[10]) print w1w2_model[0] ax1.plot(zs,w1w2_model,linewidth=2.0,color='black') bbt = 1100. w1w2_model = [] for z in zs: magtmp, wavlentmp, fluxtmp = model(plslp1, plslp2, plbrk, bbt, bbflxnrm, elscal, scahal, galfra, ebv, imod, z, fittingobj, flxcorr, parfile) w1w2_model.append(magtmp[9] - magtmp[10]) print w1w2_model[0] ax1.plot(zs,w1w2_model,linewidth=2.0,color='black') bbt = 1300. w1w2_model = [] for z in zs: magtmp, wavlentmp, fluxtmp = model(plslp1, plslp2, plbrk, bbt, bbflxnrm, elscal, scahal, galfra, ebv, imod, z, fittingobj, flxcorr, parfile) w1w2_model.append(magtmp[9] - magtmp[10]) print w1w2_model[0] ax1.plot(zs,w1w2_model,linewidth=2.0,color='black') bbt = 1400. w1w2_model = [] for z in zs: magtmp, wavlentmp, fluxtmp = model(plslp1, plslp2, plbrk, bbt, bbflxnrm, elscal, scahal, galfra, ebv, imod, z, fittingobj, flxcorr, parfile) w1w2_model.append(magtmp[9] - magtmp[10]) print w1w2_model[0] ax1.plot(zs,w1w2_model,linewidth=2.0,color='black') bbt = 1500. w1w2_model = [] for z in zs: magtmp, wavlentmp, fluxtmp = model(plslp1, plslp2, plbrk, bbt, bbflxnrm, elscal, scahal, galfra, ebv, imod, z, fittingobj, flxcorr, parfile) w1w2_model.append(magtmp[9] - magtmp[10]) print w1w2_model[0] ax1.plot(zs,w1w2_model,linewidth=2.0,color='black') bbt = 1000. w1w2_model = [] for z in zs: magtmp, wavlentmp, fluxtmp = model(plslp1, plslp2, plbrk, bbt, bbflxnrm, elscal, scahal, galfra, ebv, imod, z, fittingobj, flxcorr, parfile) w1w2_model.append(magtmp[9] - magtmp[10]) ax1.plot(zs,w1w2_model,linewidth=2.0,color='black') ax1.text(0.33,0.67,'1000K',fontsize=12,color='black') ax1.text(0.33,0.52,'1100K',fontsize=12,color='black') ax1.text(0.33,0.40,'1200K',fontsize=12,color='black') ax1.text(0.33,0.28,'1300K',fontsize=12,color='black') ax1.text(0.33,0.20,'1400K',fontsize=12,color='black') ax1.text(0.33,0.10,'1500K',fontsize=12) #plt.savefig('/home/lc585/Dropbox/IoA/HotDustPaper/w1w2_temp.pdf') bbt = 1216. bbflxnrm = 0.0 w1w2_model = [] for z in zs: magtmp, wavlentmp, fluxtmp = model(plslp1, plslp2, plbrk, bbt, bbflxnrm, elscal, scahal, galfra, ebv, imod, z, fittingobj, flxcorr, parfile) w1w2_model.append(magtmp[9] - magtmp[10]) ax2.plot(zs,w1w2_model,linewidth=2.0,color='black') bbflxnrm = 0.1 w1w2_model = [] for z in zs: magtmp, wavlentmp, fluxtmp = model(plslp1, plslp2, plbrk, bbt, bbflxnrm, elscal, scahal, galfra, ebv, imod, z, fittingobj, flxcorr, parfile) w1w2_model.append(magtmp[9] - magtmp[10]) ax2.plot(zs,w1w2_model,linewidth=2.0,color='black') bbflxnrm = 0.2 w1w2_model = [] for z in zs: magtmp, wavlentmp, fluxtmp = model(plslp1, plslp2, plbrk, bbt, bbflxnrm, elscal, scahal, galfra, ebv, imod, z, fittingobj, flxcorr, parfile) w1w2_model.append(magtmp[9] - magtmp[10]) ax2.plot(zs,w1w2_model,linewidth=2.0,color='black') bbflxnrm = 0.3 w1w2_model = [] for z in zs: magtmp, wavlentmp, fluxtmp = model(plslp1, plslp2, plbrk, bbt, bbflxnrm, elscal, scahal, galfra, ebv, imod, z, fittingobj, flxcorr, parfile) w1w2_model.append(magtmp[9] - magtmp[10]) ax2.plot(zs,w1w2_model,linewidth=2.0,color='black') bbflxnrm = 0.4 w1w2_model = [] for z in zs: magtmp, wavlentmp, fluxtmp = model(plslp1, plslp2, plbrk, bbt, bbflxnrm, elscal, scahal, galfra, ebv, imod, z, fittingobj, flxcorr, parfile) w1w2_model.append(magtmp[9] - magtmp[10]) ax2.plot(zs,w1w2_model,linewidth=2.0,color='black') #plt.xlim(0.2,1.8) ax2.text(1.55,-0.1,'0.17',fontsize=12,color='black') ax2.text(1.55,0.38,'0.28',fontsize=12,color='black') ax2.text(1.55,0.60,'0.40',fontsize=12,color='black') ax2.text(1.55,0.75,'0.52',fontsize=12,color='black') ax2.text(1.55,0.90,'0.64',fontsize=12,color='black') fig.savefig('/home/lc585/thesis/figures/chapter06/w1w2_versus_redshift.pdf') #plt.xlabel(r'$z$',fontsize=12) #plt.ylabel('$W1$-$W2$',fontsize=12) #plt.tight_layout() #plt.tick_params(axis='both',which='major',labelsize=10) #sns.set_style('ticks') #xdat = np.arange(0.1,1.2,0.2) #plt.savefig('/data/lc585/QSOSED/Results/141101/figure1.jpg') #fig, ax = plt.subplots() #for row in grid: # ax.plot(xdat,row) #ax.set_xlabel('W1-W2') #ax.set_ylabel('LUM BOL') #plt.savefig('/data/lc585/QSOSED/Results/141101/figure2.jpg') #plt.show() #plt.savefig('/home/lc585/Dropbox/IoA/HotDustPaper/w1w2_bbnorm.pdf') plt.show() return None
def plot(): import yaml from qsosed.load import load import numpy as np from qsosed.sedmodel import model import matplotlib.pyplot as plt from qsosed.pl import pl from qsosed.bb import bb import cosmolopy.distance as cd from PlottingTools.plot_setup_thesis import figsize, set_plot_properties import palettable from lmfit import Parameters from qsosed.qsrmod import qsrmod from qsosed.flx2mag import flx2mag set_plot_properties() # change style cs = palettable.colorbrewer.qualitative.Set1_9.mpl_colors plslp1 = 0.508 plslp2 = 0.068 plbrk = 2944.99 bbt = 1174.0 bbflxnrm = 0.208 galfra = 0.313 elscal = 0.624 imod = 18.0 ebv = 0.0 redshift = 2.0 scahal = 0.8 with open('/home/lc585/qsosed/input.yml', 'r') as f: parfile = yaml.load(f) fittingobj = load(parfile) wavlen = fittingobj.get_wavlen() flxcorr = np.array([1.0] * len(wavlen)) params = Parameters() params.add('plslp1', value=-0.478) params.add('plslp2', value=-0.199) params.add('plbrk', value=2.40250) params.add('bbt', value=1.30626) params.add('bbflxnrm', value=2.673) params.add('elscal', value=1.240) params.add('scahal', value=0.713) params.add('galfra', value=0.0) params.add('bcnrm', value=0.135) params.add('ebv', value=0.0) params.add('imod', value=18.0) lin = fittingobj.get_lin() galspc = fittingobj.get_galspc() ext = fittingobj.get_ext() galcnt = fittingobj.get_galcnt() ignmin = fittingobj.get_ignmin() ignmax = fittingobj.get_ignmax() bp = fittingobj.get_bp() dlam = fittingobj.get_dlam() zromag = fittingobj.get_zromag() ftrlst = fittingobj.get_ftrlst() ztran = fittingobj.get_ztran() lyatmp = fittingobj.get_lyatmp() lybtmp = fittingobj.get_lybtmp() lyctmp = fittingobj.get_lyctmp() whmin = fittingobj.get_whmin() whmax = fittingobj.get_whmax() qsomag = fittingobj.get_qsomag() cosmo = fittingobj.get_cosmo() nftr = len(bp) redshift = 0.5 wavlentmp, fluxtmp = qsrmod(params, parfile, wavlen, redshift, lin, galspc, ext, galcnt, ignmin, ignmax, ztran, lyatmp, lybtmp, lyctmp, whmin, whmax, cosmo, flxcorr, qsomag) magtmp = flx2mag(params, wavlentmp, fluxtmp, bp, dlam, zromag, ftrlst) fig = plt.figure(figsize=figsize(1, vscale=0.8)) ax1 = fig.add_subplot(111) ax1.loglog(wavlentmp, 0.5 * fluxtmp, color='black', label=r'$z=0.5$') redshift = 2.0 wavlentmp, fluxtmp = qsrmod(params, parfile, wavlen, redshift, lin, galspc, ext, galcnt, ignmin, ignmax, ztran, lyatmp, lybtmp, lyctmp, whmin, whmax, cosmo, flxcorr, qsomag) magtmp = flx2mag(params, wavlentmp, fluxtmp, bp, dlam, zromag, ftrlst) ax1.loglog(wavlentmp, 5 * fluxtmp, color='black', label=r'$z=2.0$') redshift = 3.5 wavlentmp, fluxtmp = qsrmod(params, parfile, wavlen, redshift, lin, galspc, ext, galcnt, ignmin, ignmax, ztran, lyatmp, lybtmp, lyctmp, whmin, whmax, cosmo, flxcorr, qsomag) magtmp = flx2mag(params, wavlentmp, fluxtmp, bp, dlam, zromag, ftrlst) ax1.loglog(wavlentmp, 50 * fluxtmp, color='black', label=r'$z=3.5$') ax1.set_xlabel(r'log $\lambda$ [${\rm \AA}$]') ax1.set_ylabel(r'log $F_{\lambda}$ [Arbitary Units]') # ax1.loglog(wavlentmp,1.e10/wavlentmp**2,linestyle='--') ax2 = ax1.twinx() ax2.set_yticks([]) labs = ['u', 'g', 'r', 'i', 'z', 'Y', 'J', 'H', 'K', 'W1', 'W2', 'W3'] xpos = fittingobj.get_lameff() xpos[:5] = xpos[:5] - 200.0 xpos[5] = 10405 xpos[6] = 12505 xpos[7] = 16411 xpos[8] = 21942 xpos[9] = 33500 xpos[10] = 46027 xpos[11] = 112684 ax2.text(19225, 3.923, r'$z=3.5$', ha='right') ax2.text(11674, 3.099, r'$z=2.0$', ha='right') ax2.text(6000, 2.135, r'$z=0.5$', ha='right') color_idx = np.linspace(0, 1, 12) from palettable.colorbrewer.diverging import Spectral_11_r for i in range(len(bp[:-1])): wavtmp = (bp[i][0, :]) flxtmp = bp[i][1, :] / np.max(bp[i][1, :]) ax2.plot(wavtmp, flxtmp, color=Spectral_11_r.mpl_colormap(color_idx[i])) # ax2.fill_between(wavtmp, flxtmp, alpha=0.2, facecolor=Spectral_11.mpl_colormap(color_idx[i])) ax2.text(xpos[i], 0.2, r'${}$'.format(labs[i]), ha='center') ax2.set_ylim(0, 5) ax1.set_ylim(1e-3, 200) ax1.set_xlim(2800, 190000) ax2.set_xlim(ax1.get_xlim()) plt.tight_layout() fig.savefig('/home/lc585/thesis/figures/chapter05/throughput.pdf') plt.show() return None
def plot(): redshift = 1 with open('/home/lc585/qsosed/input.yml', 'r') as f: parfile = yaml.load(f) # Load stuff fittingobj = load(parfile) lin = fittingobj.get_lin() qsomag = fittingobj.get_qsomag() whmin = fittingobj.get_whmin() whmax = fittingobj.get_whmax() ignmin = fittingobj.get_ignmin() ignmax = fittingobj.get_ignmax() galcnt = fittingobj.get_galcnt() galspc = fittingobj.get_galspc() wavlen = fittingobj.get_wavlen() fig, ax = plt.subplots(figsize=figsize(1, vscale=0.9)) # ax.plot(wavlen,wavlen*fluxtmp,color='black') # import lineid_plot # line_wave = [1216, # 1549, # 1909, # 2798, # 4861, # 6563, # 18744] # line_names = [r'Ly$\alpha$', # r'C\,{\sc iv}', # r'C\,{\sc iii}]', # r'Mg\,{\sc ii}', # r'H$\beta$', # r'H$\alpha$', # r'Pa$\alpha$'] # lineid_plot.plot_line_ids(wavlen, wavlen*fluxtmp, line_wave, line_names, ax=ax, arrow_tip=10000) plslp1 = -0.478 plslp2 = -0.199 plbrk = 2402 bbt = 1306 bbflxnrm = 3.673 elscal = 1.240 scahal = 0.713 galfra = 0.4 bcnrm = 0.135 ebv = 0.0 flux = np.zeros(len(wavlen), dtype=np.float) flxnrm = parfile['quasar']['flxnrm'] wavnrm = parfile['quasar']['wavnrm'] # Define normalisation constant to ensure continuity at wavbrk const2 = flxnrm / (wavnrm**(-plslp2)) const1 = const2 * ((plbrk**(-plslp2)) / (plbrk**(-plslp1))) wavnumbrk = wav2num(wavlen, plbrk) flux[:wavnumbrk] = flux[:wavnumbrk] + pl(wavlen[:wavnumbrk], plslp1, const1) flux[wavnumbrk:] = flux[wavnumbrk:] + pl(wavlen[wavnumbrk:], plslp2, const2) # Now add steeper power-law component for sub-Lyman-alpha wavelengths # Define normalisation constant to ensure continuity at wavbrk plbrk_tmp = parfile['quasar']['pl_steep']['brk'] plslp_tmp = plslp1 + parfile['quasar']['pl_steep']['step'] plbrknum_tmp = wav2num(wavlen, plbrk_tmp) const_tmp = flux[plbrknum_tmp] / (plbrk_tmp**-plslp_tmp) flux[:plbrknum_tmp] = pl(wavlen[:plbrknum_tmp], plslp_tmp, const_tmp) flux_pl = flux * 1.0 # Hot blackbody --------------------------------------------------- bbwavnrm = parfile['quasar']['bb']['wavnrm'] flux = flux + bb( wavlen * u.AA, bbt * u.K, bbflxnrm, bbwavnrm * u.AA, units='freq') flux_bb = bb(wavlen * u.AA, bbt * u.K, bbflxnrm, bbwavnrm * u.AA, units='freq') # Balmer continuum -------------------------------------------------- # Add Balmer Continuum and blur to simulate effect of bulk-velocity # shifts comparable to those present in emission lines # Determine height of power-law continuum at wavelength wbcnrm to allow # correct scaling of Balmer continuum contribution wbcnrm = parfile['quasar']['balmercont']['wbcnrm'] wbedge = parfile['quasar']['balmercont']['wbedge'] tbc = parfile['quasar']['balmercont']['tbc'] taube = parfile['quasar']['balmercont']['taube'] vfwhm = parfile['quasar']['balmercont']['vfwhm'] # mean wavelength increment winc = np.diff(wavlen).mean() cfact = flux[wav2num(wavlen, wbcnrm)] flux = flux / cfact flux_bc = bc(wavlen=wavlen * u.AA, tbb=tbc * u.K, fnorm=bcnrm, taube=taube, wavbe=wbedge * u.AA, wnorm=wbcnrm * u.AA) vsigma = vfwhm * (u.km / u.s) / 2.35 wsigma = wbedge * u.AA * vsigma / const.c wsigma = wsigma.to(u.AA) psigma = wsigma / (winc * u.AA) # Performs a simple Gaussian smooth with dispersion psigma pixels gauss = Gaussian1DKernel(stddev=psigma) flux_bc = convolve(flux_bc, gauss) flux = flux + flux_bc #----------------------------------------------------------------- # Now convert to flux per unit wavelength # Presumably the emission line spectrum and galaxy spectrum # are already in flux per unit wavelength. # c / lambda^2 conversion flux = flux * (u.erg / u.s / u.cm**2 / u.Hz) flux = flux.to(u.erg / u.s / u.cm**2 / u.AA, equivalencies=u.spectral_density(wavlen * u.AA)) scale = flux[wav2num(wavlen, wavnrm)] flux = flxnrm * flux / scale flux_pl = flux_pl * (u.erg / u.s / u.cm**2 / u.Hz) flux_pl = flux_pl.to(u.erg / u.s / u.cm**2 / u.AA, equivalencies=u.spectral_density(wavlen * u.AA)) flux_pl = flxnrm * flux_pl / scale flux_bb = flux_bb * (u.erg / u.s / u.cm**2 / u.Hz) flux_bb = flux_bb.to(u.erg / u.s / u.cm**2 / u.AA, equivalencies=u.spectral_density(wavlen * u.AA)) flux_bb = flxnrm * flux_bb / scale flux_bc = flux_bc * (u.erg / u.s / u.cm**2 / u.Hz) flux_bc = flux_bc.to(u.erg / u.s / u.cm**2 / u.AA, equivalencies=u.spectral_density(wavlen * u.AA)) flux_bc = flxnrm * flux_bc / scale # Emission lines ------------------------------------------------- linwav, linval, conval = lin[:, 0], lin[:, 1], lin[:, 2] # Normalise such that continuum flux at wavnrm equal to that # of the reference continuum at wavnrm inorm = wav2num(wavlen, wavnrm) scale = flux[inorm] flux = conval[inorm] * flux / scale flux_pl = conval[inorm] * flux_pl / scale flux_bb = conval[inorm] * flux_bb / scale flux_bc = conval[inorm] * flux_bc / scale # Calculate Baldwin Effect Scaling for Halpha zbenrm = parfile['quasar']['el']['zbenrm'] beslp = parfile['quasar']['el']['beslp'] # Line added to stop enormous BE evolution at low z zval = np.max([redshift, zbenrm]) # I think this is the absolute magnitude of the SDSS sample as # a function of redshift, which is not the same as how the # absolute magnitude of a object of a given flux changes # as a function of redshift qsomag_itp = interp1d(qsomag[:, 0], qsomag[:, 1]) # Absolute magnitude at redshift z minus # normalisation absolute magnitude vallum = qsomag_itp(zval) - qsomag_itp(zbenrm) # Convert to luminosity vallum = 10.0**(-0.4 * vallum) scabe = vallum**(-beslp) flux_el = np.zeros_like(flux) flux_el[:whmin] = linval[:whmin] * np.abs( elscal) * flux[:whmin] / conval[:whmin] flux_el[whmax:] = linval[whmax:] * np.abs( elscal) * flux[whmax:] / conval[whmax:] flux[:whmin] = flux[:whmin] + linval[:whmin] * np.abs( elscal) * flux[:whmin] / conval[:whmin] flux[whmax:] = flux[whmax:] + linval[whmax:] * np.abs( elscal) * flux[whmax:] / conval[whmax:] # Scaling for Ha with Baldwin effect scatmp = elscal * scahal / scabe flux_el[whmin:whmax] = linval[whmin:whmax] * np.abs( scatmp) * flux[whmin:whmax] / conval[whmin:whmax] flux[whmin:whmax] = flux[whmin:whmax] + \ linval[whmin:whmax] * np.abs(scatmp) * flux[whmin:whmax] / conval[whmin:whmax] gznorm = parfile['gal']['znrm'] gplind = parfile['gal']['plind'] # Determine fraction of galaxy sed to add to unreddened quasar SED qsocnt = np.sum(flux[ignmin:ignmax]) # Factor cscale just to bring input galaxy and quasar flux zero-points equal cscale = qsocnt / galcnt # Find absolute magnitude of quasar at redshift z vallum = qsomag_itp(redshift) # Find absolute magnitude of quasar at redshift gznorm galnrm = qsomag_itp(gznorm) # Subtract supplied normalisation absolute magnitude vallum = vallum - galnrm # Convert to a luminosity vallum = 10.0**(-0.4 * vallum) # Luminosity scaling scaval = vallum**(gplind - 1.0) scagal = (galfra / (1.0 - galfra)) * scaval flux_gal = cscale * scagal * galspc # flux = flux + cscale * scagal * galspc ax.plot(wavlen[:wavnumbrk], wavlen[:wavnumbrk] * flux_pl[:wavnumbrk], color=cs[1], label='Accretion Disc') # ax.fill_between(wavlen[:wavnumbrk], wavlen[:wavnumbrk]*flux_pl[:wavnumbrk], facecolor=cs[1], alpha=0.2) ax.plot(wavlen[wavnumbrk:], wavlen[wavnumbrk:] * flux_pl[wavnumbrk:], color=cs[0], label='Accretion Disc') # ax.fill_between(wavlen[wavnumbrk:], wavlen[wavnumbrk:]*flux_pl[wavnumbrk:], facecolor=cs[0], alpha=0.2) ax.plot(wavlen, wavlen * (flux_bc), color=cs[2], label='Balmer Continuum') # ax.fill_between(wavlen, wavlen*(flux_bc), facecolor=cs[2], alpha=0.2) ax.plot(wavlen, wavlen * (flux_bb), color=cs[4], label='Hot Dust') # ax.fill_between(wavlen, wavlen*(flux_bb), facecolor=cs[4], alpha=0.2) # ax.plot(wavlen, wavlen*(flux_gal), color=cs[3], label='Galaxy') # ax.fill_between(wavlen, wavlen*(flux_gal), facecolor=cs[3], alpha=0.2) ax.plot(wavlen, wavlen * flux, color='black', label='Total') ax.legend() ax.set_xlim(1216, 20000) ax.set_ylim(0, 10000) ax.set_ylabel(r'${\lambda}F_{\lambda}$ [Arbitary Units]') ax.set_xlabel(r'Wavelength $\lambda$ [${\rm \AA}$]') plt.tight_layout() plt.subplots_adjust(top=0.85) fig.savefig('/home/lc585/thesis/figures/chapter05/sed_model.pdf') plt.show() return None
def plot(): set_plot_properties() # change style with open('/home/lc585/qsosed/input.yml', 'r') as f: parfile = yaml.load(f) fittingobj = load(parfile) df = get_data() zs = np.linspace(1, 3.0, 100) wavlen = fittingobj.get_wavlen() uvintmin = np.argmin(np.abs(wavlen - 2000.)) uvintmax = np.argmin(np.abs(wavlen - 9000.)) irintmin = np.argmin(np.abs(wavlen - 10000.)) irintmax = np.argmin(np.abs(wavlen - 30000.)) def ratiogoal(rg): ratio = 0.0 bbflxnrm = 0.0 z = 2.0 bbt = 1306 plslp1 = -0.478 plslp2 = -0.199 plbrk = 2402.0 flxnrm = 1.0 wavnrm = 5500.0 bbwavnrm = 20000.0 # while ratio < rg: # flux = np.zeros(len(wavlen), dtype=np.float) # # Define normalisation constant to ensure continuity at wavbrk # const2 = flxnrm / (wavnrm**(-plslp2)) # const1 = const2 * ((plbrk**(-plslp2)) / (plbrk**(-plslp1))) # wavnumbrk = wav2num(wavlen, plbrk) # flux[:wavnumbrk] = flux[:wavnumbrk] + pl(wavlen[:wavnumbrk], plslp1, const1) # flux[wavnumbrk:] = flux[wavnumbrk:] + pl(wavlen[wavnumbrk:], plslp2, const2) # # Hot blackbody --------------------------------------------------- # bbflux = bb(wavlen*u.AA, # bbt*u.K, # bbflxnrm, # bbwavnrm*u.AA, # units='freq') # flux = flux*(u.erg / u.s / u.cm**2 / u.Hz) # flux = flux.to(u.erg / u.s / u.cm**2 / u.AA, # equivalencies=u.spectral_density(wavlen * u.AA)) # bbflux = bbflux*(u.erg / u.s / u.cm**2 / u.Hz) # bbflux = bbflux.to(u.erg / u.s / u.cm**2 / u.AA, # equivalencies=u.spectral_density(wavlen * u.AA)) # ratio = np.sum(bbflux[irintmin:irintmax]) / np.sum(flux[uvintmin:uvintmax]) # bbflxnrm = bbflxnrm + 0.01 # print ratio, bbflxnrm # parfile['quasar']['bb']['flxnrm'] = bbflxnrm print rg if rg == 0.5: parfile['quasar']['bb']['flxnrm'] = 4.47 elif rg == 0.4: parfile['quasar']['bb']['flxnrm'] = 3.58 elif rg == 0.3: parfile['quasar']['bb']['flxnrm'] = 2.69 elif rg == 0.2: parfile['quasar']['bb']['flxnrm'] = 1.8 elif rg == 0.1: parfile['quasar']['bb']['flxnrm'] = 0.91 elif rg == 0.0: parfile['quasar']['bb']['flxnrm'] = 0.0 cols = [] for z in zs: magtmp, wavlentmp, fluxtmp = model(redshift=z, parfile=parfile) cols.append(magtmp[9] - magtmp[10]) return cols fig, ax = plt.subplots(figsize=figsize(1.0, vscale=0.7)) mycm = cm.get_cmap('Blues_r') mycm.set_under('w') mycm = truncate_colormap(mycm, 0.0, 0.8) cset = brewer2mpl.get_map('Blues', 'sequential', 9).mpl_colors #histogram definition xyrange = [[1, 3], [0, 2]] # data range bins = [50, 50] # number of bins thresh = 4 #density threshold #data definition xdat, ydat = df.z_HW, df.W1VEGA - df.W2VEGA # histogram the data hh, locx, locy = histogram2d(xdat, ydat, range=xyrange, bins=bins) posx = np.digitize(xdat, locx) posy = np.digitize(ydat, locy) #select points within the histogram ind = (posx > 0) & (posx <= bins[0]) & (posy > 0) & (posy <= bins[1]) hhsub = hh[posx[ind] - 1, posy[ind] - 1] # values of the histogram where the points are xdat1 = xdat[ind][hhsub < thresh] # low density points ydat1 = ydat[ind][hhsub < thresh] hh[hh < thresh] = np.nan # fill the areas with low density by NaNs im = ax.imshow(np.flipud(hh.T), cmap=mycm, extent=np.array(xyrange).flatten(), interpolation='none', aspect='auto', vmin=thresh, vmax=45) cb = plt.colorbar(im) cb.set_label('Number of Objects') ax.scatter(xdat1, ydat1, color=cset[-1], s=3) cset = brewer2mpl.get_map('YlOrRd', 'sequential', 8).mpl_colors ax.plot(zs, ratiogoal(0.5), c=cset[7], linewidth=2.0, label=r'0.5') ax.plot(zs, ratiogoal(0.4), c=cset[6], linewidth=2.0, label=r'0.4') ax.plot(zs, ratiogoal(0.3), c=cset[5], linewidth=2.0, label=r'0.3') ax.plot(zs, ratiogoal(0.2), c=cset[4], linewidth=2.0, label=r'0.2') ax.plot(zs, ratiogoal(0.1), c=cset[3], linewidth=2.0, label=r'0.1') ax.plot(zs, ratiogoal(0.0), c=cset[2], linewidth=2.0, label=r'0.0') ax.set_xlabel(r'Redshift $z$') ax.set_ylabel(r'$W1-W2$') ax.set_xlim(1, 4) ax.set_ylim(0.2, 2) ax.text(0.72, 0.7, r'${\mathrm R_{\mathrm NIR/UV}}$', transform=ax.transAxes) plt.legend(frameon=False, loc=(0.7, 0.15)) plt.tight_layout() fig.savefig( '/home/lc585/thesis/figures/chapter05/w1w2_versus_redshift_ratio.pdf') plt.show() return None
def plot(): """ Generates residual plot using model parameters in input.yml """ set_plot_properties() # change style with open('/home/lc585/qsosed/input.yml', 'r') as f: parfile = yaml.load(f) fittingobj = load(parfile) wavlen = fittingobj.get_wavlen() lin = fittingobj.get_lin() galspc = fittingobj.get_galspc() ext = fittingobj.get_ext() galcnt = fittingobj.get_galcnt() ignmin = fittingobj.get_ignmin() ignmax = fittingobj.get_ignmax() ztran = fittingobj.get_ztran() lyatmp = fittingobj.get_lyatmp() lybtmp = fittingobj.get_lybtmp() lyctmp = fittingobj.get_lyctmp() whmin = fittingobj.get_whmin() whmax = fittingobj.get_whmax() qsomag = fittingobj.get_qsomag() flxcorr = fittingobj.get_flxcorr() cosmo = fittingobj.get_cosmo() # Load median magnitudes with open('/home/lc585/qsosed/sdss_ukidss_wise_medmag_ext.dat') as f: datz = np.loadtxt(f, usecols=(0,)) datz = datz[:-5] # Load filters ftrlst = fittingobj.get_ftrlst()[2:-2] lameff = fittingobj.get_lameff()[2:-2] bp = fittingobj.get_bp()[2:-2] # these are in ab and data is in vega dlam = fittingobj.get_bp()[2:-2] zromag = fittingobj.get_zromag()[2:-2] with open('ftgd_dr7.dat') as f: ftgd = np.loadtxt(f, skiprows=1, usecols=(1,2,3,4,5,6,7,8,9)) fname = '/home/lc585/qsosed/sdss_ukidss_wise_medmag_ext.dat' datarr = np.genfromtxt(fname, usecols=(5,7,9,11,13,15,17,19,21)) datarr[datarr < 0.0] = np.nan datarr = datarr[:-5, :] params = Parameters() params.add('plslp1', value = -0.478) params.add('plslp2', value = -0.199) params.add('plbrk', value = 2.40250) params.add('bbt', value = 1.30626) params.add('bbflxnrm', value = 2.673) params.add('elscal', value = 1.240) params.add('scahal',value = 0.713) params.add('galfra',value = 0.0) params.add('bcnrm',value = 0.135) params.add('ebv',value = 0.0) params.add('imod',value = 18.0) modarr = residual(params, parfile, wavlen, datz, lin, bp, dlam, zromag, galspc, ext, galcnt, ignmin, ignmax, ztran, lyatmp, lybtmp, lyctmp, ftrlst, whmin, whmax, cosmo, flxcorr, qsomag, ftgd) lameff = lameff.reshape( len(lameff), 1) lameff = np.repeat(lameff,len(datz),axis=1) datz = datz.reshape(1, len(datz) ) datz = np.repeat(datz,len(lameff),axis=0) lam = lameff / (1.0 + datz) res = np.ndarray.transpose(modarr - datarr) fig = plt.figure(figsize=figsize(1, 0.8)) ax = fig.add_subplot(1,1,1) colormap = plt.cm.Paired plt.gca().set_color_cycle([colormap(i) for i in np.linspace(0, 0.8, 9)]) labels = ['r','i','z','Y','J','H','K','W1','W2'] for i in range(9): ax.plot(lam[i,:], res[i,:], label=labels[i]) ax.grid() ax.set_xlim(1000,30000) ax.set_ylim(-0.3,0.3) ax.set_xlabel(r'Rest Frame Wavelength [${\rm \AA}$]') ax.set_ylabel(r'$m_{\rm mod} - m_{\rm dat}$') plt.legend(prop={'size':10}) plt.tick_params(axis='both',which='major') plt.tight_layout() plt.savefig('/home/lc585/thesis/figures/chapter05/model_residuals.pdf') plt.show() return None