def plot_stone_ap_vs_psf(): """ make a plot comparing S/N and observed mag for reg and sub photometry for SN stone, by DS and SR """ from astropy.io import ascii import numpy as np from matplotlib import pyplot as pl from pytools import plotsetup plotsetup.presfig( figsize=[10,10]) dat = ascii.read( 'photcompare_stone.dat', format='commented_header', header_start=-1, data_start=0) iapSRbigreg = np.where( (dat['PHOTTYPE']=='apSR') & (dat['SKYANN']=='big') & (dat['IMTYPE']=='reg') ) iapSRsmallreg = np.where( (dat['PHOTTYPE']=='apSR') & (dat['SKYANN']=='small') & (dat['IMTYPE']=='reg') ) iapSRbigsub = np.where( (dat['PHOTTYPE']=='apSR') & (dat['SKYANN']=='big') & (dat['IMTYPE']=='sub') ) iapSRsmallsub = np.where( (dat['PHOTTYPE']=='apSR') & (dat['SKYANN']=='small') & (dat['IMTYPE']=='sub') ) iapDSreg = np.where( (dat['PHOTTYPE']=='apDS') & (dat['IMTYPE']=='reg') ) iapDSsub = np.where( (dat['PHOTTYPE']=='apDS') & (dat['IMTYPE']=='sub') ) ipsfDSreg = np.where( (dat['PHOTTYPE']=='psfDS') & (dat['IMTYPE']=='reg') ) ipsfDSsub = np.where( (dat['PHOTTYPE']=='psfDS') & (dat['IMTYPE']=='sub') ) mag = dat['MAG'] magerr = dat['MAGERR'] flux = dat['FLUX'] fluxerr = dat['FLUXERR'] SNR = np.abs( flux / fluxerr ) plotargs = {'alpha':0.8, 'mew':0 } pl.plot( mag[iapSRbigsub], mag[iapSRbigreg] - mag[iapSRbigsub], 'ro', label='ap big sky ann. (SR)', **plotargs ) pl.plot( mag[iapSRsmallsub], mag[iapSRsmallreg] - mag[iapSRsmallsub], 'go', label='ap small sky ann. (SR)', **plotargs ) pl.plot( mag[iapDSsub], mag[iapDSreg] - mag[iapDSsub], 'mD', label='ap (DS)', **plotargs ) pl.plot( mag[ipsfDSsub], mag[ipsfDSreg] - mag[ipsfDSsub], 'cD', label='psf (DS)', **plotargs ) ax1 = pl.gca() ax1.set_xlabel('sub mag [AB]') ax1.set_ylabel('observed difference : reg mag - sub mag') ax1.axhline( 0.0, ls='--', color='0.5') ax1.legend( loc='upper left') ax1.invert_yaxis() ax1.text( 26.8, -0.02, 'SN appears brighter in reg than in sub', color='0.3', ha='right', va='bottom',fontsize=12) ax1.text( 26.8, 0.02, 'SN appears fainter in reg than in sub', color='0.3', ha='right', va='top',fontsize=12) ax1.set_ylim( 0.4, -0.4) ax1.set_xlim( 25, 27.7)
def plotLightCurve( name='colfax'): """ plot the ACS, UVIS and IR light curves :param name: :return: """ import sncosmo # from sncosmost import hstbandpasses from astropy.io import ascii import numpy as np from matplotlib import pyplot as pl from pytools import plotsetup plotsetup.presfig( figsize = [20,12]) fig = pl.gcf() pl.clf() sndat = ascii.read( 'HST_CANDELS4_%s.sncosmo.dat'%(name), format='commented_header', header_start=-1, data_start=0 ) filterlist = np.unique( [ filt for filt in sndat['FILTER'] ] ) naxes = len(filterlist) nrow = int( np.sqrt( naxes ) ) ncol = ( naxes / nrow ) + 1 for filt, iax in zip( filterlist, range(1,naxes+1) ) : ax = fig.add_subplot( nrow, ncol, iax ) ifilt = np.where( sndat['FILTER'] == filt ) mjd = sndat['MJD'][ifilt] flux = sndat['FLUX'][ifilt] fluxerr = sndat['FLUXERR'][ifilt] mag = sndat['MAG'][ifilt] magerr = sndat['MAGERR'][ifilt] if filt.startswith('f1') : color='r' marker='D' elif filt.startswith('f3') : color='k' marker='o' else : color='g' marker='s' ax.errorbar( mjd, flux, fluxerr, marker=marker, color=color, ls='-' ) ax.set_xlabel('MJD') ax.set_ylabel('FLUX') ax.text( 0.02, 0.95, filt.upper(), fontsize=20, ha='left', va='top',transform=ax.transAxes ) # ax.invert_yaxis() ax.axhline( 0, ls='--', color='0.5') fig.subplots_adjust( wspace=0.2, hspace=0.2, left=0.08, right=0.95, bottom=0.12, top=0.92 ) fig.suptitle( name.upper() ) pl.draw()
def plotSNRcompare() : from astropy.io import ascii import numpy as np from matplotlib import pyplot as pl from pytools import plotsetup fig = plotsetup.presfig() psfdat = ascii.read( 'psfphot3.dat', format='fixed_width') isub = np.where(psfdat['image']=='sub')[0] oSNRetc = psfdat['optSNRetc'][isub] SNRetc = psfdat['SNRetc'][isub] SNRpsf = psfdat['SNRpsf'][isub] psfmag = psfdat['stack'][isub] band = psfdat['band'][isub] iwide = np.array([ i for i in range(len(band)) if band[i].endswith('w')] ) imed = np.array([ i for i in range(len(band)) if band[i].endswith('m')] ) pl.clf() ax = pl.subplot( 2, 2,1 ) ax.plot( oSNRetc[iwide], SNRpsf[iwide], color='darkorange', marker='d', ls=' ', alpha=0.5, mew=0.5, ms=8, label='wide band subs' ) ax.plot( oSNRetc[imed], SNRpsf[imed], 'mo', ls=' ', alpha=0.7, mew=0.5, ms=8, label='med band subs', ) ax.plot( [0,200], [0,200], 'k-' ) ax.set_xlim( 0, 45 ) ax.set_ylim( 0, 45 ) ax.set_xlabel( 'Optimal S/N from ETC' ) ax.set_ylabel( 'Observed S/N from PSF drops' ) ax.legend( numpoints=1, loc='lower right' ) ax = pl.subplot( 2,2,2 ) ax.plot( oSNRetc[iwide], SNRpsf[iwide], color='darkorange', marker='d', ls=' ', alpha=0.5, mew=0.5, ms=8 ) ax.plot( oSNRetc[imed], SNRpsf[imed], 'mo', ls=' ', alpha=0.7, mew=0.5, label='med band subs', ms=8) ax.plot( [0,100], [0,100], 'k-' ) ax.set_xlim( 0, 15 ) ax.set_ylim( 0, 15 ) ax.set_xlabel( 'Optimal S/N from ETC' ) ax.set_ylabel( 'Observed S/N from PSF drops' ) ax = pl.subplot( 2, 2, 3 ) ax.plot( SNRetc[iwide], SNRpsf[iwide], color='darkred', marker='d', ls=' ', alpha=0.5, mew=0.5, ms=8, label='wide band subs' ) ax.plot( SNRetc[imed], SNRpsf[imed], 'co', ls=' ', alpha=0.7, mew=0.5, ms=8, label='med band subs' ) ax.plot( [0,200], [0,200], 'k-' ) ax.set_xlim( 0, 45 ) ax.set_ylim( 0, 45 ) ax.set_xlabel( 'Aperture S/N from ETC' ) ax.set_ylabel( 'Observed S/N from PSF drops' ) ax.legend( numpoints=1, loc='lower right' ) ax = pl.subplot( 2,2,4 ) ax.plot( SNRetc[iwide], SNRpsf[iwide], color='darkred', marker='d', ls=' ', alpha=0.5, mew=0.5, ms=8) ax.plot( SNRetc[imed], SNRpsf[imed], 'co', ls=' ', alpha=0.7, mew=0.5, ms=8) ax.plot( [0,100], [0,100], 'k-' ) ax.set_xlim( 0, 15 ) ax.set_ylim( 0, 15 ) ax.set_xlabel( 'Aperture S/N from ETC' ) ax.set_ylabel( 'Observed S/N from PSF drops' ) pl.draw()
def plotSNR_vs_mag() : """ make a plot comparing S/N vs mag for wide and med bands :return: """ from astropy.io import ascii import numpy as np from matplotlib import pyplot as pl from pytools import plotsetup fig = plotsetup.presfig() psfdat = ascii.read( 'psfphot3.dat', format='fixed_width') isub = np.where(psfdat['image']=='sub')[0] oSNRetc = psfdat['optSNRetc'][isub] SNRetc = psfdat['SNRetc'][isub] SNRpsf = psfdat['SNRpsf'][isub] psfmag = psfdat['stack'][isub] band = psfdat['band'][isub] iwide = np.array([ i for i in range(len(band)) if band[i].endswith('w')] ) imed = np.array([ i for i in range(len(band)) if band[i].endswith('m')] ) pl.clf() ax = pl.subplot( 1,1,1 ) ax.plot( psfmag[iwide], SNRpsf[iwide], color='darkorange', marker='d', ls=' ', alpha=0.8, mew=0.5, ms=8, label='wide band subs' ) ax.plot( psfmag[imed], SNRpsf[imed], 'mo', ls=' ', alpha=0.8, mew=0.5, ms=8, label='med band subs' ) ax.set_xlim( 25, 30) ax.set_ylim( 0, 30) ax.set_xlabel( 'Observed PSF-fitting mag (AB)' ) ax.set_ylabel( 'Observed S/N from PSF drops' ) ax.legend( numpoints=1, loc='upper right' ) pl.draw()
def plot_stone_newap(): """ make a plot comparing S/N and observed mag for reg and sub in hostless """ from astropy.io import ascii import numpy as np from matplotlib import pyplot as pl from pytools import plotsetup psfdat = ascii.read( 'psfphot_stonemod.dat', format='fixed_width') snlist = psfdat['sn'] bandlist = psfdat['band'] imagelist = psfdat['image'] epochlist = psfdat['epoch'] aplist = psfdat['aperture'] aperrlist = psfdat['aperr'] fig = plotsetup.presfig() isub = np.where( imagelist=='sub' )[0] ireg = np.where( imagelist=='reg' )[0] ax1 = pl.subplot( 1,1,1 ) ax1.errorbar( aplist[isub], aplist[ireg], aperrlist[ireg], aperrlist[isub], ls=' ', marker='o', color='cyan', ms=10, capsize=0, alpha=0.5 ) ax1.set_xlabel('sub image') ax1.set_ylabel('reg image') ax1.plot( [25,28],[25,28], 'k-')
def plotComparison( name='colfax' ): """ Make a comparison plot showing the light curves from each of the four photometry flavors. :param sn: :return: """ import sncosmo # from sncosmost import hstbandpasses from astropy.io import ascii import numpy as np from matplotlib import pyplot as pl from pytools import plotsetup plotsetup.presfig( figsize = [20,12]) fig = pl.gcf() pl.clf() for phottype, iphot, color, marker in zip( ['ap','psf'], [2,4], ['r','g'], ['D','o'] ): sndat = ascii.read( 'HST_CANDELS%i_%s.sncosmo.dat'%(iphot,name), format='commented_header', header_start=-1, data_start=0 ) filterlist = np.unique( [ filt for filt in sndat['filter'] if filt.lower().startswith('f1') ] ) naxes = len(filterlist) nrow = int( np.sqrt( naxes ) ) ncol = ( naxes / nrow ) + 1 for filt, iax in zip( filterlist, range(1,naxes+1) ) : ax = fig.add_subplot( nrow, ncol, iax ) ifilt = np.where( sndat['filter'] == filt ) mjd = sndat['mjd'][ifilt] + iphot flux = sndat['flux'][ifilt] fluxerr = sndat['fluxerr'][ifilt] ax.errorbar( mjd, flux, fluxerr, marker=marker, color=color, ls='-', label=phottype ) ax.set_xlabel('mjd') ax.set_ylabel('flux') ax.text( 0.02, 0.95, filt.upper(), fontsize=14, ha='left', va='top',transform=ax.transAxes ) ax.axhline( 0, ls='--', color='0.5') fig.subplots_adjust( wspace=0.2, hspace=0.2, left=0.08, right=0.95, bottom=0.12, top=0.92 ) ax.legend( loc='upper right', numpoints=1, bbox_to_anchor=[1.05,1.05] ) fig.suptitle( name.upper() ) pl.draw()
def plotSNR_vs_mag(): """ make a plot comparing S/N vs mag for wide and med bands :return: """ from astropy.io import ascii import numpy as np from matplotlib import pyplot as pl from pytools import plotsetup fig = plotsetup.presfig() psfdat = ascii.read('psfphot3.dat', format='fixed_width') isub = np.where(psfdat['image'] == 'sub')[0] oSNRetc = psfdat['optSNRetc'][isub] SNRetc = psfdat['SNRetc'][isub] SNRpsf = psfdat['SNRpsf'][isub] psfmag = psfdat['stack'][isub] band = psfdat['band'][isub] iwide = np.array([i for i in range(len(band)) if band[i].endswith('w')]) imed = np.array([i for i in range(len(band)) if band[i].endswith('m')]) pl.clf() ax = pl.subplot(1, 1, 1) ax.plot(psfmag[iwide], SNRpsf[iwide], color='darkorange', marker='d', ls=' ', alpha=0.8, mew=0.5, ms=8, label='wide band subs') ax.plot(psfmag[imed], SNRpsf[imed], 'mo', ls=' ', alpha=0.8, mew=0.5, ms=8, label='med band subs') ax.set_xlim(25, 30) ax.set_ylim(0, 30) ax.set_xlabel('Observed PSF-fitting mag (AB)') ax.set_ylabel('Observed S/N from PSF drops') ax.legend(numpoints=1, loc='upper right') pl.draw()
def plot_stone_newap(): """ make a plot comparing S/N and observed mag for reg and sub in hostless """ from astropy.io import ascii import numpy as np from matplotlib import pyplot as pl from pytools import plotsetup psfdat = ascii.read('psfphot_stonemod.dat', format='fixed_width') snlist = psfdat['sn'] bandlist = psfdat['band'] imagelist = psfdat['image'] epochlist = psfdat['epoch'] aplist = psfdat['aperture'] aperrlist = psfdat['aperr'] fig = plotsetup.presfig() isub = np.where(imagelist == 'sub')[0] ireg = np.where(imagelist == 'reg')[0] ax1 = pl.subplot(1, 1, 1) ax1.errorbar(aplist[isub], aplist[ireg], aperrlist[ireg], aperrlist[isub], ls=' ', marker='o', color='cyan', ms=10, capsize=0, alpha=0.5) ax1.set_xlabel('sub image') ax1.set_ylabel('reg image') ax1.plot([25, 28], [25, 28], 'k-')
def plothostless_compare(): """ make a plot comparing S/N and observed mag for reg and sub in hostless """ from astropy.io import ascii import numpy as np from matplotlib import pyplot as pl from pytools import plotsetup psfdat = ascii.read( 'psfphot3.dat', format='fixed_width') snlist = psfdat['sn'] bandlist = psfdat['band'] imagelist = psfdat['image'] epochlist = psfdat['epoch'] fig = plotsetup.presfig() pl.clf() ax1 = pl.subplot( 1,2,1 ) ax2 = pl.subplot( 1,2,2 ) for thissn,color in zip( ['stone'], ['red'] ) : SNRsub, magsub, SNRreg, magreg, bandmatch = [],[],[],[], [] for row in psfdat : sn = row['sn'] if thissn=='hosted' and sn in ['stone','dawes'] : continue if thissn!='hosted' and sn != thissn : continue band = row['band'] epoch = row['epoch'] image = row['image'] if image=='reg' : continue imatch = np.where( (bandlist==band) & (snlist==sn) & (epochlist==epoch) & (imagelist=='reg'))[0] if len(imatch) == 1 : SNRsub.append( row['SNRpsf']) # magsub.append( row['stack']) magsub.append( row['aperture']) SNRreg.append( psfdat['SNRpsf'][imatch[0]]) # magreg.append( psfdat['stack'][imatch[0]]) magreg.append( psfdat['aperture'][imatch[0]]) bandmatch.append( band ) SNRsub, magsub, SNRreg, magreg, bandmatch = np.array(SNRsub), np.array(magsub), np.array(SNRreg), np.array(magreg), np.array(bandmatch) # imed = np.array([ i for i in range(len(bandmatch)) if bandmatch[i].endswith('m')]) # iwide = np.array([ i for i in range(len(bandmatch)) if bandmatch[i].endswith('w')]) imed = np.array([ i for i in range(len(bandmatch)) if bandmatch[i]=='f125w']) iwide = np.array([ i for i in range(len(bandmatch)) if bandmatch[i]!='f125w']) ax1.plot( magsub[iwide], magreg[iwide]-magsub[iwide], color=color, marker='d', ls=' ', alpha=0.8, mew=0.5, ms=8, label='%s other'%thissn ) if len(imed) : ax1.plot( magsub[imed], magreg[imed]-magsub[imed], color=color, marker='o', ls=' ', alpha=0.8, mew=0.5, ms=12, label='%s f125w'%thissn ) ax1.set_xlim( 24.8, 28.1) ax1.set_ylim( 1.1, -1.1) ax1.set_ylabel( 'observed difference : reg mag - sub mag' ) ax1.set_xlabel( 'sub mag (AB)' ) ax2.plot( SNRsub[iwide], SNRreg[iwide]-SNRsub[iwide], color=color, marker='d', ls=' ', alpha=0.8, mew=0.5, ms=8, label='other' ) if len(imed) : ax2.plot( SNRsub[imed], SNRreg[imed]-SNRsub[imed], color=color, marker='o', ls=' ', alpha=0.8, mew=0.5, ms=12, label='f125w' ) ax2.set_xlim( 0, 25) ax2.set_ylim( -5, 11) ax2.set_ylabel( 'observed difference : reg S/N - sub S/N' ) ax2.set_xlabel( 'sub S/N' ) ax1.text( 28, -0.02, 'SN appears brighter in reg than in sub', color='0.3', ha='right', va='bottom',fontsize=12) ax1.text( 28, 0.02, 'SN appears fainter in reg than in sub', color='0.3', ha='right', va='top',fontsize=12) ax1.axhline( 0, color='0.5', ls='--', ) ax2.axhline( 0, color='0.5', ls='--', ) ax2.text( 25, 0.5, 'S/N is better in reg than in sub', color='0.3', ha='right', va='bottom',fontsize=12) ax2.text( 25, -0.5, 'S/N is worse in reg than in sub', color='0.3', ha='right', va='top',fontsize=12) ax1.legend( numpoints=1, loc='lower left') pl.draw()
def plotLightCurve(name='colfax'): """ plot the ACS, UVIS and IR light curves :param name: :return: """ import sncosmo # from sncosmost import hstbandpasses from astropy.io import ascii import numpy as np from matplotlib import pyplot as pl from pytools import plotsetup plotsetup.presfig(figsize=[20, 12]) fig = pl.gcf() pl.clf() sndat = ascii.read('HST_CANDELS4_%s.sncosmo.dat' % (name), format='commented_header', header_start=-1, data_start=0) filterlist = np.unique([filt for filt in sndat['FILTER']]) naxes = len(filterlist) nrow = int(np.sqrt(naxes)) ncol = (naxes / nrow) + 1 for filt, iax in zip(filterlist, range(1, naxes + 1)): ax = fig.add_subplot(nrow, ncol, iax) ifilt = np.where(sndat['FILTER'] == filt) mjd = sndat['MJD'][ifilt] flux = sndat['FLUX'][ifilt] fluxerr = sndat['FLUXERR'][ifilt] mag = sndat['MAG'][ifilt] magerr = sndat['MAGERR'][ifilt] if filt.startswith('f1'): color = 'r' marker = 'D' elif filt.startswith('f3'): color = 'k' marker = 'o' else: color = 'g' marker = 's' ax.errorbar(mjd, flux, fluxerr, marker=marker, color=color, ls='-') ax.set_xlabel('MJD') ax.set_ylabel('FLUX') ax.text(0.02, 0.95, filt.upper(), fontsize=20, ha='left', va='top', transform=ax.transAxes) # ax.invert_yaxis() ax.axhline(0, ls='--', color='0.5') fig.subplots_adjust(wspace=0.2, hspace=0.2, left=0.08, right=0.95, bottom=0.12, top=0.92) fig.suptitle(name.upper()) pl.draw()
def plotComparison(name='colfax'): """ Make a comparison plot showing the light curves from each of the four photometry flavors. :param sn: :return: """ import sncosmo # from sncosmost import hstbandpasses from astropy.io import ascii import numpy as np from matplotlib import pyplot as pl from pytools import plotsetup plotsetup.presfig(figsize=[20, 12]) fig = pl.gcf() pl.clf() for phottype, iphot, color, marker in zip(['ap', 'psf'], [2, 4], ['r', 'g'], ['D', 'o']): sndat = ascii.read('HST_CANDELS%i_%s.sncosmo.dat' % (iphot, name), format='commented_header', header_start=-1, data_start=0) filterlist = np.unique([ filt for filt in sndat['filter'] if filt.lower().startswith('f1') ]) naxes = len(filterlist) nrow = int(np.sqrt(naxes)) ncol = (naxes / nrow) + 1 for filt, iax in zip(filterlist, range(1, naxes + 1)): ax = fig.add_subplot(nrow, ncol, iax) ifilt = np.where(sndat['filter'] == filt) mjd = sndat['mjd'][ifilt] + iphot flux = sndat['flux'][ifilt] fluxerr = sndat['fluxerr'][ifilt] ax.errorbar(mjd, flux, fluxerr, marker=marker, color=color, ls='-', label=phottype) ax.set_xlabel('mjd') ax.set_ylabel('flux') ax.text(0.02, 0.95, filt.upper(), fontsize=14, ha='left', va='top', transform=ax.transAxes) ax.axhline(0, ls='--', color='0.5') fig.subplots_adjust(wspace=0.2, hspace=0.2, left=0.08, right=0.95, bottom=0.12, top=0.92) ax.legend(loc='upper right', numpoints=1, bbox_to_anchor=[1.05, 1.05]) fig.suptitle(name.upper()) pl.draw()
def plot_stone_deltaflux(): """ make a plot showing sky value variations for sn stone """ from astropy.io import ascii import numpy as np from matplotlib import pyplot as pl from pytools import plotsetup plotsetup.presfig( figsize=[10,10]) dat = ascii.read( 'stone_skyMMM_phot.dat', format='commented_header', header_start=-1, data_start=0) fig1 = pl.figure(1) pl.clf() # ax1 = pl.subplot(1,1,1) for filt,color,apcor ,irow in zip( ['F125W','F160W'],['b','r'],[0.185,0.194],[0,1]) : fapcor = 10**(-0.4*apcor) for marker,skyann in zip( ['^','s','o','D'], [ 0.5,6.0 ] ): # ,0.6,1.0, 6.0 ]) : # 0.5,0.6,1.0,6.0]) : #ibig = np.where( (dat['SKYANN']==6.0) & (dat['FILTER']==filt) & (dat['IMTYPE']=='reg')) #ismall = np.where( (dat['SKYANN']==skyann) & (dat['FILTER']==filt) & (dat['IMTYPE']=='reg') ) if skyann==0.5 : fig1 = pl.figure(1) fig = fig1 else : fig2 = pl.figure(2) fig = fig2 ireg = np.where( (dat['SKYANN']==skyann) & (dat['FILTER']==filt) & (dat['IMTYPE']=='reg') & (dat['MJD']>56400) ) isub = np.where( (dat['SKYANN']==skyann) & (dat['FILTER']==filt) & (dat['IMTYPE']=='sub') & (dat['MJD']>56400) ) itmp = np.where( (dat['SKYANN']==skyann) & (dat['FILTER']==filt) & (dat['IMTYPE']=='reg') & (dat['MJD']<56400) )[0] mjd = dat['MJD'][ireg] skyreg = dat['SKY'][ireg] skysub = dat['SKY'][isub] skytmp = dat['SKY'][itmp] skyerrreg = dat['SKYERR'][ireg] skyerrsub = dat['SKYERR'][isub] skyerrtmp = dat['SKYERR'][itmp] fluxreg = dat['FLUX'][ireg] fluxsub = dat['FLUX'][isub] fluxtmp = dat['FLUX'][itmp] fluxerrreg = dat['FLUXERR'][ireg] fluxerrsub = dat['FLUXERR'][isub] fluxerrtmp = dat['FLUXERR'][itmp] # area = np.pi * ( 0.4 / 0.09 )**2 area = 62.0562 ftottmp = fluxtmp + skytmp * area ftotreg = fluxreg + skyreg * area ftotsub = fluxsub + skysub * area deltaftot = ftotsub + ftottmp - ftotreg #ftoterr = fluxerrtmp + skyerrtmp * area # import pdb; pdb.set_trace() ftotsub = fluxsub + (skysub*area) + fluxtmp + skytmp * area ftotreg = fluxreg + (skyreg*area) deltaflux = fluxsub - fluxreg deltafluxerr = np.sqrt( fluxerrsub**2 + fluxerrreg**2 ) plotargs = {'alpha':0.5, 'mew':0 } print( ' "source" Flux in template = %.3f (filter=%s, skyann=%.1f)'%(fluxtmp,filt,skyann)) print( ' "sky" Flux in template = %.3f (filter=%s, skyann=%.1f)'%(skytmp,filt,skyann)) # pl.errorbar( mjd+skyann*10, deltaflux, deltafluxerr, # Difference between reg and (sub+template) source flux: #pl.errorbar( mjd+skyann, fluxreg-fluxsub-fluxtmp, fluxerrreg, ls='-', # marker=marker,color=color, # label=filt+' %.1f'%skyann, **plotargs ) mjdbins = np.arange(len(mjd))*3 # np.append( mjd, mjd[-1]+5 ) ax1 = fig.add_subplot(2,2,irow*2 + 1 ) # total flux in the reg images ax1.bar( mjdbins-1, fluxreg, width=1, color='darkorange', label='reg', alpha=0.5 ) # total pre-sub flux in the diff images ax1.bar( mjdbins, fluxsub, width=1, label='sub', color='b', alpha=0.5 ) ax1.bar( mjdbins, np.zeros(len(mjd))+fluxtmp, bottom=fluxsub, width=1, color='r', label='tmp', alpha=0.5 ) ax1.set_title( 'measured "source" flux in %s'%filt ) ax2 = fig.add_subplot(2,2,irow*2 + 2 ) ax2.bar( mjdbins-1, skyreg, width=1, color='darkorange', label='reg', alpha=0.5 ) ax2.bar( mjdbins, skysub, width=1, color='b', label='sub', alpha=0.5 ) ax2.bar( mjdbins, np.zeros(len(mjd))+skytmp, bottom=skysub, width=1, color='r', label='tmp', alpha=0.5 ) ax2.set_title( 'measured sky in %s'%filt ) for fig in [fig1,fig2]: ax = fig.add_subplot( 2, 2, 1 ) ax.legend( loc='upper left', frameon=False, fontsize='small') fig1.suptitle('Sky annulus = [0.5",1.0"]') fig1.subplots_adjust(left=0.12, bottom=0.12, top=0.88, right=0.95, wspace=0.25, hspace=0.25) fig2.suptitle('Sky annulus = [6.0",12.0"]') fig2.subplots_adjust(left=0.12, bottom=0.12, top=0.88, right=0.95, wspace=0.25, hspace=0.25) # pl.xlabel( 'MJD' ) # pl.ylabel( '$\Delta$Flux [sub-reg] / TemplateFlux' ) pl.draw()
def mkhubblefig(datfile='ps1union.dat', ageaxis=True, highz='rodney', bigtext=False): """ construct the hubble residual plot """ from pytools import plotsetup, cosmo, colorpalette as cp from matplotlib import patches, ticker from mpl_toolkits.axes_grid1 import host_subplot from astropy.io import ascii import numpy as np from matplotlib import pyplot as pl from scipy.interpolate import interp1d plotsetup.presfig(wide=True) pl.clf() fig = pl.gcf() if highz == 'Malmquist': zlim = [0, 2.58] elif highz == 'rodney': zlim = [0, 3.49] if bigtext: zlim = [0, 3.53] else: zlim = [0, 2.45] # bottomAxeslim = [ 0.14, 0.14, 0.72, 0.72 ] # ax1 = fig.add_axes( bottomAxeslim, frameon=True, alpha=0.0, label='axes1') ax1 = host_subplot(111) fig.subplots_adjust(left=0.11, bottom=0.16, right=0.89, top=0.84) # read in redshifts and distances hubbledat, H0, Om, MB = gethubbledat(datfile) lensfactor = 0.093 hubbledat['muerr'] = np.sqrt(hubbledat['muerr']**2 + (lensfactor * hubbledat['z'])**2) # plot ground data colordict = { 'low-z': cp.purple, 'sdss': cp.lightblue, 'ps1': cp.darkblue, 'snls': cp.darkgreen, 'hstacs': cp.darkorange, 'hstwfc3a': cp.medred, 'hstwfc3b': cp.darkred, 'jwst': cp.darkgrey, } elw = 0.75 cs = 0 for survey in ['low-z', 'sdss', 'snls', 'ps1', 'hstacs', 'hstwfc3']: isurvey = where((hubbledat['survey'] == survey) & (hubbledat['spec'] > 0)) ax1.errorbar(hubbledat['z'][isurvey], hubbledat['mu'][isurvey], hubbledat['muerr'][isurvey], hubbledat['zerr'][isurvey], marker='o', ls=' ', mew=0, markersize=5, color=colordict[survey], mfc=colordict[survey], ecolor=colordict[survey], elinewidth=elw, capsize=cs, alpha=0.7) if highz: # get the high-z SN fits from Dan labeldict = {#'primo':'Rodney+ 2012', #'wilson':'Jones, Rodney+ 2013', 'stone':'GND13Sto', 'colfax':'GND12Col', } if highz == 'rodney': labeldict = { 'primo': 'Rodney+ 2012', 'wilson': 'Jones, Rodney+ 2013', 'stone': 'Rodney+ in prep', 'colfax': 'Rodney+ in prep', } for survey, namelist in zip( ['hstwfc3a', 'hstwfc3b'], [['primo', 'wilson'], ['stone', 'colfax']]): color = colordict[survey] for name in namelist: if name not in hubbledat['name']: continue iname = np.where(hubbledat['name'] == name)[0][0] z, zerr = hubbledat['z'][iname], hubbledat['zerr'][iname] mu, muerr = hubbledat['mu'][iname], hubbledat['muerr'][iname] if name == 'colfax': icol = np.where( [n.startswith('col') for n in hubbledat['name']])[0] # lensing correction for mu=1.04 +-0.03 : 0.0426 +- 0.031 mag mucol = interp1d(hubbledat['z'][icol], hubbledat['mu'][icol] + 0.0426) muerr = np.sqrt(muerr**2 + 0.031**2) ax1.plot([2.16, 2.19, 2.25, 2.28], mucol([2.16, 2.19, 2.25, 2.28]), color=color, lw=0.75, ls='-') ax1.errorbar(2.22, mucol(2.22), muerr, marker='D', ls=' ', mew=0, markersize=8, color=color, mfc=color, ecolor=color, elinewidth=elw, capsize=cs, alpha=1) z = 2.1 mu = mucol(2.1) else: if name == 'stone': mu = mu + 0.0215 muerr = np.sqrt(muerr**2 + 0.02**2) ax1.errorbar(z, mu, muerr, zerr, marker='D', ls=' ', mew=0, markersize=8, color=color, mfc=color, ecolor=color, elinewidth=elw, capsize=cs, alpha=1) if highzlabels and name in labeldict: ax1.text( z + 0.02, mu - 0.6, labeldict[name], color=color, # backgroundcolor='w', fontsize='small', va='top', ha='center', rotation=90) # plot the lcdm cosmology ax1.axhline(0, color='0.4', ls='-') # plot extreme w' zLCDM = np.arange(0.01, 5, 0.05) muLCDM = cosmo.mu(zLCDM, H0=H0, Om=Om, Ode=(1 - Om), w0=-1., wa=0) #muextremeDE = cosmo.mu( z, H0=_H0, Om=_Om, Ode=(1-_Om), w0=-0.7, wa=-2) mu1 = cosmo.mu(zLCDM, H0=H0, Om=Om - 0.015, Ode=(1 - Om + 0.015), w0=-1.2, wa=0.7) mu2 = cosmo.mu(zLCDM, H0=H0, Om=Om + 0.055, Ode=(1 - Om - 0.055), w0=-0.65, wa=-2.2) ax1.fill_between(zLCDM, mu1, mu2, color='k', alpha=0.2, lw=0, zorder=10) ax1.text(0.3, 35, 'low-z', fontsize='large', ha='center', color=colordict['low-z']) ax1.text(0.4, 37.5, 'SDSS', fontsize='large', ha='center', color=colordict['sdss']) ax1.text(0.7, 40, 'PS1', fontsize='large', ha='center', color=colordict['ps1']) ax1.text(1.0, 42, 'SNLS', fontsize='large', ha='center', color=colordict['snls']) ax1.text(1.4, 46, 'HST+ACS', fontsize='large', ha='right', color=colordict['hstacs']) ax1.text(1.83, 47, 'HST+WFC3', fontsize='large', ha='center', color=colordict['hstwfc3b']) ax1.text(3.0, 46, '( JWST )', fontsize='large', ha='center', color=colordict['jwst']) ax1.set_xlabel('Redshift', fontsize='large') ax1.set_ylabel(r'Distance Modulus', fontsize='large') mulim = array([33, 49.5]) muresidlim = array([-1.05, 1.05]) ax1.xaxis.set_ticks([ 0.1, ] + np.arange(0.5, zlim[-1], 0.5).tolist()) ax1.set_xlim(zlim) ax1.set_ylim(mulim) ax1.yaxis.set_major_locator(ticker.MultipleLocator(4)) ax1.yaxis.set_minor_locator(ticker.MultipleLocator(1)) if ageaxis: ax2 = ax1.twin() if highz == 'rodney': # ax1top.set_xlabel( 'age of Universe (Gyr)',fontsize='large',x=0.15,ha='left') ageticks = np.array([13, 9, 6, 4, 3, 2]) else: ageticks = np.array([13, 9, 6, 4, 3]) ax2.set_xlim(zlim) ztickloctop = cosmo.zfromt(ageticks) ax2.xaxis.set_ticks(ztickloctop) ax2.xaxis.set_ticklabels(ageticks) ax2.yaxis.set_major_locator(ticker.MultipleLocator(4)) ax2.yaxis.set_minor_locator(ticker.MultipleLocator(1)) ax2.yaxis.set_ticklabels([ '%i' % round(float(tick) + MB) for tick in ax1.yaxis.get_majorticklocs() ]) ax2.set_xlabel('Age of Universe (Gyr)', fontsize='large') ax2.set_ylabel('Peak Magnitude', fontsize='large', rotation=-90, labelpad=27) pl.draw()
def mkresidplot(datfile='ps1union.dat', ageaxis=True, highz='Malmquist', highzlabels=True, lensfactor=0.093, presfig=False, bigtext=False): """ construct the hubble residual plot """ from pytools import plotsetup, cosmo, colorpalette as cp from matplotlib import patches import numpy as np from matplotlib import pyplot as pl from scipy.interpolate import interp1d if presfig: plotsetup.presfig(wide=True) else: plotsetup.fullpaperfig([8.5, 4.5], bigtext=bigtext) clf() highz = highz.lower() if highz == 'malmquist': zlim = [0, 2.78] elif highz == 'rodney': zlim = [0, 3.49] if presfig: zlim = [0, 3.78] else: zlim = [0, 2.45] fig = gcf() if presfig: bottomAxeslim = [0.13, 0.18, 0.85, 0.65] else: bottomAxeslim = [0.09, 0.12, 0.88, 0.75] ax1 = fig.add_axes(bottomAxeslim, frameon=True, alpha=0.0, label='axes1') ax1top = ax1.twiny() # read in redshifts and distances hubbledat, H0, Om, MB = gethubbledat(datfile) if lensfactor: # muerr = 0.093z : Holz & Linder, 2005 # muerr = 0.055z : Jonsson+ 2012 hubbledat['muerr'] = np.sqrt(hubbledat['muerr']**2 + (lensfactor * hubbledat['z'])**2) # plot ground data colordict = { 'low-z': cp.purple, 'sdss': cp.lightblue, 'ps1': cp.darkblue, 'snls': cp.darkgreen, 'hstacs': cp.darkorange, 'hstwfc3': cp.medred, 'hstwfc3a': cp.medred, 'hstwfc3b': cp.darkred, 'jwst': cp.darkgrey, } elw = 0.75 cs = 0 for survey in ['low-z', 'sdss', 'snls', 'ps1', 'hstacs']: isurvey = where((hubbledat['survey'] == survey) & (hubbledat['spec'] > 0)) ax1.errorbar(hubbledat['z'][isurvey], hubbledat['mures'][isurvey], hubbledat['muerr'][isurvey], hubbledat['zerr'][isurvey], marker='o', ls=' ', mew=0.01, markersize=5, color=colordict[survey], mfc=colordict[survey], ecolor=colordict[survey], elinewidth=elw, capsize=cs, alpha=0.7) if highz: # get the high-z SN fits from Dan labeldict = {#'primo':'Rodney+ 2012', #'wilson':'Jones, Rodney+ 2013', 'stone':'GND13Sto', 'colfax':'GND12Col', } if highz == 'rodney': labeldict = { 'primo': 'Rodney+ 2012', 'wilson': 'Jones, Rodney+ 2013', 'stone': 'Rodney+ in prep', 'colfax': 'Rodney+ in prep', } for survey, namelist in zip( ['hstwfc3a', 'hstwfc3b'], [['primo', 'wilson'], ['stone', 'colfax']]): color = colordict[survey] for name in namelist: if name not in hubbledat['name']: continue iname = np.where(hubbledat['name'] == name)[0][0] z, zerr = hubbledat['z'][iname], hubbledat['zerr'][iname] mu, muerr = hubbledat['mures'][iname], hubbledat['muerr'][ iname] if name == 'colfax': # Not applying a lensing correction for mu=1.04 +-0.03 : 0.0426 +- 0.031 mag icol = np.where( [n.startswith('col') for n in hubbledat['name']])[0] mucol = interp1d(hubbledat['z'][icol], hubbledat['mures'][icol]) ax1.plot([2.16, 2.19, 2.21, 2.24, 2.26, 2.28], mucol([2.16, 2.19, 2.21, 2.24, 2.26, 2.28]), color=color, lw=0.75, ls='-') ax1.errorbar(2.26, mucol(2.26), muerr, marker='D', ls=' ', mew=0.01, markersize=8, color=color, mfc=color, ecolor=color, elinewidth=elw, capsize=cs, alpha=1) z = 2.26 mu = mucol(2.26) elif name == 'stone': # not applying a lensing correction for stone: # mu = mu + 0.0215; muerr = np.sqrt( muerr**2 + 0.02**2 ) isto = np.where( [n.startswith('stone') for n in hubbledat['name']])[0] musto = interp1d(hubbledat['z'][isto], hubbledat['mures'][isto]) ax1.plot(np.arange(1.66, 2.01, 0.02), musto(np.arange(1.66, 2.01, 0.02)), color=color, lw=0.75, ls='--') ax1.errorbar(1.80, musto(1.80), muerr, zerr, marker='D', ls=' ', mew=0.01, markersize=8, color=color, mfc=color, ecolor=color, elinewidth=elw, capsize=cs, alpha=1) z = 1.80 mu = musto(1.80) else: ax1.errorbar(z, mu, muerr, zerr, marker='D', ls=' ', mew=0.01, markersize=8, color=color, mfc=color, ecolor=color, elinewidth=elw, capsize=cs, alpha=1) if highzlabels and name in labeldict: # ax1.text( z-0.035, mu+0.07, labeldict[name], if name == 'primo': ax1.text( z - 0.05, mu + 0.035, labeldict[name], color=color, # backgroundcolor='w', va='bottom', ha='center', rotation=90) else: ax1.text( z, mu + muerr + 0.07, labeldict[name], color=color, # backgroundcolor='w', va='bottom', ha='center', rotation=90) # plot the lcdm cosmology ax1.axhline(0, color='0.4', ls='-') # plot extreme w' zLCDM = np.arange(0.01, 5, 0.05) muLCDM = cosmo.mu(zLCDM, H0=H0, Om=Om, Ode=(1 - Om), w0=-1., wa=0) #muextremeDE = cosmo.mu( z, H0=_H0, Om=_Om, Ode=(1-_Om), w0=-0.7, wa=-2) mu1 = cosmo.mu(zLCDM, H0=H0, Om=Om - 0.015, Ode=(1 - Om + 0.015), w0=-1.2, wa=0.7) mu2 = cosmo.mu(zLCDM, H0=H0, Om=Om + 0.055, Ode=(1 - Om - 0.055), w0=-0.65, wa=-2.2) ax1.fill_between(zLCDM, mu1 - muLCDM, mu2 - muLCDM, color='k', alpha=0.2, lw=0.01, zorder=10) if not presfig: ax1.text(0.08, -0.8, 'low-z', fontsize=(presfig and 'small') or 10.5, ha='center', color=colordict['low-z']) ax1.text(0.25, -0.85, 'SDSS', fontsize=(presfig and 'small') or 10.5, ha='center', color=colordict['sdss']) ax1.text(0.5, -0.9, 'PS1', fontsize=(presfig and 'small') or 10.5, ha='center', color=colordict['ps1']) ax1.text(0.75, -0.95, 'SNLS', fontsize=(presfig and 'small') or 10.5, ha='center', color=colordict['snls']) ax1.text(1.25, -0.8, 'HST+ACS', fontsize=(presfig and 'small') or 10.5, ha='center', color=colordict['hstacs']) ax1.text(1.95, -0.95, 'HST+WFC3', fontsize=(presfig and 'small') or 10.5, ha='center', color=colordict['hstwfc3b']) lowzRect = patches.Rectangle([0.0, -0.85], 0.08, 0.03, fill=True, lw=0, alpha=0.3, color=colordict['low-z']) sdssRect = patches.Rectangle([0.06, -0.9], 0.34, 0.03, fill=True, lw=0, alpha=0.3, color=colordict['sdss']) ps1Rect = patches.Rectangle([0.1, -0.95], 0.5, 0.03, fill=True, lw=0, alpha=0.3, color=colordict['ps1']) snlsRect = patches.Rectangle([0.15, -1.0], 0.9, 0.03, fill=True, lw=0, alpha=0.3, color=colordict['snls']) acsRect = patches.Rectangle([0.60, -0.85], 1.15, 0.03, fill=True, lw=0, alpha=0.3, color=colordict['hstacs']) wfc3Rect = patches.Rectangle([1.20, -1.0], 1.1, 0.03, fill=True, lw=0, alpha=0.3, color=colordict['hstwfc3b']) ax1.add_patch(lowzRect) ax1.add_patch(sdssRect) ax1.add_patch(ps1Rect) ax1.add_patch(snlsRect) ax1.add_patch(acsRect) ax1.add_patch(wfc3Rect) if highz == 'rodney': if not presfig: #ffsnRect = patches.Rectangle( [2.30,-1.0], 0.7, 0.03, fill=False,lw=1, alpha=1.0, color=colordict['hstwfc3b'] ) jwstRect = patches.Rectangle([2.00, -0.85], 2.0, 0.03, fill=False, lw=1, alpha=1.0, color=colordict['jwst']) #ax1.add_patch( ffsnRect ) ax1.add_patch(jwstRect) #ax1.text( 2.5, -0.95, '+ lensing',fontsize=10.5, ha='center', color=colordict['hstwfc3b'] ) ax1.text(3.0, -0.78, 'JWST', fontsize=(presfig and 'medium') or 10.5, ha='center', color=colordict['jwst']) color = cp.bluegray ax1.arrow(2.5, 0.15, 0.3, 0.0, fc=color, ec=color, head_width=0.05, head_length=0.0, overhang=0.0) ax1.plot(2.5, 0.15, marker='o', mfc='w', mec=color) ax1.text(2.49, 0.19, '0.3 Gyr', ha='left', va='bottom', color=color) ax1.text(2.82, 0.15, 'z=2.8', ha='left', va='center', color=color) color = cp.teal ax1.arrow(2.5, 0.45, 0.55, 0.0, fc=color, ec=color, head_width=0.05, head_length=0.08, overhang=0.25, length_includes_head=True) ax1.plot(2.5, 0.45, marker='o', mfc='w', mec=color) ax1.text(2.6, 0.48, '1 Gyr', ha='left', va='bottom', color=color) ax1.text(3.08, 0.45, 'z=3.8', ha='left', va='center', color=color) color = cp.coral ax1.arrow(2.5, 0.7, 0.75, 0.0, fc=color, ec=color, head_width=0.05, head_length=0.08, overhang=0.25, length_includes_head=True) ax1.plot(2.5, 0.7, marker='o', mfc='w', mec=color) ax1.text(2.7, 0.72, '2 Gyr', ha='left', va='bottom', color=color) ax1.text(3.28, 0.7, 'z=8.3', ha='left', va='center', color=color) if not presfig: ax1.text(2.5, 0.7, 'z=2.5', ha='center', va='bottom', color='0.4') ax1.text(2.5, 0.8, 'explosion', ha='center', va='bottom', color='0.3') #, fontsize=10.5 ) ax1.text(2.85, 0.8, 'delay', ha='center', va='bottom', color='0.3') #, fontsize=10.5 ) ax1.text(3.15, 0.8, 'formation', ha='left', va='bottom', color='0.3') #, fontsize=10.5 ) if presfig: ax1.text( 0.82, 0.46, 'flat $\Lambda$CDM', color='0.1', ha='right', va='top', transform=ax1.transAxes) # , fontsize=10.5, backgroundcolor='w' ) else: ax1.text( 0.99, 0.56, 'flat $\Lambda$CDM', color='0.1', ha='right', va='top', transform=ax1.transAxes) # , fontsize=10.5, backgroundcolor='w' ) ax1.text(0.99, 0.46, '$\pm$95\% conf. \non $w_0 , w_a$', color='0.4', ha='right', va='top', transform=ax1.transAxes) # , fontsize=10.5,backgroundcolor='w' ) # ax1.text( 0.95, 0.95, 'Open Symbols:\n no spec. confirmation', color='0.5', transform=ax1.transAxes, ha='right',va='top' ) ax1.set_xlabel('Redshift', fontsize='large') # ax1.set_ylabel('$\mu_{observed}$ - $\mu_{\Lambda CDM}$') if highz == 'rodney': ax1.set_ylabel(r'$m_B^{\prime} - m_{\Lambda CDM}$', fontsize='large') else: ax1.set_ylabel(r'$m_B + \alpha x_1 - \beta c - m_{\Lambda CDM}$', fontsize='large') if presfig: ax1.yaxis.set_label_coords(-0.08, 0.65) # mulim = array( [33,46.5] ) muresidlim = array([-1.05, 1.05]) # zlim = array( [0.0,3.49] ) ax1.xaxis.set_ticks([ 0.1, ] + np.arange(0.5, zlim[-1], 0.5).tolist()) ax1.set_xlim(zlim) ax1.set_ylim(muresidlim) from pytools import colorpalette as cp if highz.lower() == 'malmquist': # z, dm, tvis = get_visibility_time_grid( 0.5, x1=0., c=0. ) # contourlevels = [50] # ax1.contour( z, dm, tvis, levels=contourlevels, colors=cp.darkbluegray, linestyles='dashed' ) z5050, dm5050 = get_visibility_time_line(tvislim=50, deteff_threshold=0.5, x1=0, c=0, zrange=[1.0, 3.0]) ax1.fill_between(z5050, dm5050, np.ones(len(z5050)) * muresidlim[1] + 0.05, color=cp.bluegray, zorder=-200, alpha=0.3) # ax1.plot( z5050, dm5050, color='0.8') z050, dm050 = get_visibility_time_line(tvislim=0.01, deteff_threshold=0.5, x1=0, c=0, zrange=[1.7, 3.0]) ax1.fill_between(z050, dm050, np.ones(len(z050)) * muresidlim[1] + 0.05, color=cp.darkbluegray, zorder=-100, alpha=0.3) ax1.text(1.53, 0.92, 't$_{\\rm vis}<$50 days', ha='left', va='top', color=cp.darkgrey) ax1.text(2.75, 0.92, 'undetectable', ha='right', va='top', color=cp.darkgrey) if highz == 'evolution': # plot SNIa evolution minmassdict = progenitorMinMassLines(zform=11) z = minmassdict['z'] for key, color in zip(['mm25', 'mm15', 'mm04'], ['r', 'g', 'b']): minmass = minmassdict[key] mavez = Mave(_MAXMASS, minmass) ax1.plot(z, (mavez - mavez[0]) * _DMUDMASS, ls='-', color=color) ax1.text(2.5, -0.95, '+ lensing', fontsize=10.5, ha='center', color=colordict['hstwfc3b']) ax1.text(3.0, -0.78, 'JWST', fontsize=10.5, ha='center', color=colordict['jwst']) color = cp.bluegray ax1.arrow(2.5, 0.25, 0.3, 0.0, fc=color, ec=color, head_width=0.05, head_length=0.0, overhang=0.0) ax1.plot(2.5, 0.25, marker='o', mfc='w', mec=color) ax1.text(2.55, 0.27, '0.3 Gyr', ha='left', va='bottom', color=color) ax1.text(2.82, 0.25, 'z=2.8', ha='left', va='center', color=color) color = cp.teal ax1.arrow(2.5, 0.45, 0.55, 0.0, fc=color, ec=color, head_width=0.05, head_length=0.08, overhang=0.25, length_includes_head=True) ax1.plot(2.5, 0.45, marker='o', mfc='w', mec=color) ax1.text(2.65, 0.47, '1 Gyr', ha='left', va='bottom', color=color) ax1.text(3.08, 0.45, 'z=3.8', ha='left', va='center', color=color) color = cp.coral ax1.arrow(2.5, 0.65, 0.75, 0.0, fc=color, ec=color, head_width=0.05, head_length=0.08, overhang=0.25, length_includes_head=True) ax1.plot(2.5, 0.65, marker='o', mfc='w', mec=color) ax1.text(2.75, 0.67, '2 Gyr', ha='left', va='bottom', color=color) ax1.text(3.28, 0.65, 'z=8.3', ha='left', va='center', color=color) ax1.text(2.5, 0.7, 'z=2.5', ha='center', va='bottom', color='0.4') ax1.text(2.5, 0.8, 'explosion', ha='center', va='bottom', color='0.3', fontsize=10.5) ax1.text(2.85, 0.8, 'delay', ha='center', va='bottom', color='0.3', fontsize=10.5) ax1.text(3.15, 0.8, 'formation', ha='left', va='bottom', color='0.3', fontsize=10.5) if ageaxis: if highz == 'rodney': # ax1top.set_xlabel( 'age of Universe (Gyr)',fontsize='large',x=0.15,ha='left') ageticks = np.array([13, 9, 6, 4, 3, 2]) else: ageticks = np.array([13, 9, 6, 4, 3]) ax1top.set_xlabel('Age of Universe (Gyr)', fontsize='large') ax1top.set_xlim(zlim) ztickloctop = cosmo.zfromt(ageticks) ax1top.xaxis.set_ticks(ztickloctop) ax1top.xaxis.set_ticklabels(ageticks) pl.draw()
def sncosmoplot(sn, fit, res): from pytools import plotsetup plotsetup.presfig() sncosmo.plot_lc(sn, model=fit, errors=res.errors)
def plot_stone_deltaflux(): """ make a plot showing sky value variations for sn stone """ from astropy.io import ascii import numpy as np from matplotlib import pyplot as pl from pytools import plotsetup plotsetup.presfig(figsize=[10, 10]) dat = ascii.read('stone_skyMMM_phot.dat', format='commented_header', header_start=-1, data_start=0) fig1 = pl.figure(1) pl.clf() # ax1 = pl.subplot(1,1,1) for filt, color, apcor, irow in zip(['F125W', 'F160W'], ['b', 'r'], [0.185, 0.194], [0, 1]): fapcor = 10**(-0.4 * apcor) for marker, skyann in zip( ['^', 's', 'o', 'D'], [0.5, 6.0]): # ,0.6,1.0, 6.0 ]) : # 0.5,0.6,1.0,6.0]) : #ibig = np.where( (dat['SKYANN']==6.0) & (dat['FILTER']==filt) & (dat['IMTYPE']=='reg')) #ismall = np.where( (dat['SKYANN']==skyann) & (dat['FILTER']==filt) & (dat['IMTYPE']=='reg') ) if skyann == 0.5: fig1 = pl.figure(1) fig = fig1 else: fig2 = pl.figure(2) fig = fig2 ireg = np.where((dat['SKYANN'] == skyann) & (dat['FILTER'] == filt) & (dat['IMTYPE'] == 'reg') & (dat['MJD'] > 56400)) isub = np.where((dat['SKYANN'] == skyann) & (dat['FILTER'] == filt) & (dat['IMTYPE'] == 'sub') & (dat['MJD'] > 56400)) itmp = np.where((dat['SKYANN'] == skyann) & (dat['FILTER'] == filt) & (dat['IMTYPE'] == 'reg') & (dat['MJD'] < 56400))[0] mjd = dat['MJD'][ireg] skyreg = dat['SKY'][ireg] skysub = dat['SKY'][isub] skytmp = dat['SKY'][itmp] skyerrreg = dat['SKYERR'][ireg] skyerrsub = dat['SKYERR'][isub] skyerrtmp = dat['SKYERR'][itmp] fluxreg = dat['FLUX'][ireg] fluxsub = dat['FLUX'][isub] fluxtmp = dat['FLUX'][itmp] fluxerrreg = dat['FLUXERR'][ireg] fluxerrsub = dat['FLUXERR'][isub] fluxerrtmp = dat['FLUXERR'][itmp] # area = np.pi * ( 0.4 / 0.09 )**2 area = 62.0562 ftottmp = fluxtmp + skytmp * area ftotreg = fluxreg + skyreg * area ftotsub = fluxsub + skysub * area deltaftot = ftotsub + ftottmp - ftotreg #ftoterr = fluxerrtmp + skyerrtmp * area # import pdb; pdb.set_trace() ftotsub = fluxsub + (skysub * area) + fluxtmp + skytmp * area ftotreg = fluxreg + (skyreg * area) deltaflux = fluxsub - fluxreg deltafluxerr = np.sqrt(fluxerrsub**2 + fluxerrreg**2) plotargs = {'alpha': 0.5, 'mew': 0} print( ' "source" Flux in template = %.3f (filter=%s, skyann=%.1f)' % (fluxtmp, filt, skyann)) print(' "sky" Flux in template = %.3f (filter=%s, skyann=%.1f)' % (skytmp, filt, skyann)) # pl.errorbar( mjd+skyann*10, deltaflux, deltafluxerr, # Difference between reg and (sub+template) source flux: #pl.errorbar( mjd+skyann, fluxreg-fluxsub-fluxtmp, fluxerrreg, ls='-', # marker=marker,color=color, # label=filt+' %.1f'%skyann, **plotargs ) mjdbins = np.arange(len(mjd)) * 3 # np.append( mjd, mjd[-1]+5 ) ax1 = fig.add_subplot(2, 2, irow * 2 + 1) # total flux in the reg images ax1.bar(mjdbins - 1, fluxreg, width=1, color='darkorange', label='reg', alpha=0.5) # total pre-sub flux in the diff images ax1.bar(mjdbins, fluxsub, width=1, label='sub', color='b', alpha=0.5) ax1.bar(mjdbins, np.zeros(len(mjd)) + fluxtmp, bottom=fluxsub, width=1, color='r', label='tmp', alpha=0.5) ax1.set_title('measured "source" flux in %s' % filt) ax2 = fig.add_subplot(2, 2, irow * 2 + 2) ax2.bar(mjdbins - 1, skyreg, width=1, color='darkorange', label='reg', alpha=0.5) ax2.bar(mjdbins, skysub, width=1, color='b', label='sub', alpha=0.5) ax2.bar(mjdbins, np.zeros(len(mjd)) + skytmp, bottom=skysub, width=1, color='r', label='tmp', alpha=0.5) ax2.set_title('measured sky in %s' % filt) for fig in [fig1, fig2]: ax = fig.add_subplot(2, 2, 1) ax.legend(loc='upper left', frameon=False, fontsize='small') fig1.suptitle('Sky annulus = [0.5",1.0"]') fig1.subplots_adjust(left=0.12, bottom=0.12, top=0.88, right=0.95, wspace=0.25, hspace=0.25) fig2.suptitle('Sky annulus = [6.0",12.0"]') fig2.subplots_adjust(left=0.12, bottom=0.12, top=0.88, right=0.95, wspace=0.25, hspace=0.25) # pl.xlabel( 'MJD' ) # pl.ylabel( '$\Delta$Flux [sub-reg] / TemplateFlux' ) pl.draw()
def plot_stone_template_tests(): """ make a plot comparing S/N and observed mag for reg and sub photometry for SN stone, by DS and SR """ from astropy.io import ascii import numpy as np from matplotlib import pyplot as pl from pytools import plotsetup plotsetup.presfig(figsize=[10, 10]) dat = ascii.read('stone_template_phot.dat', format='commented_header', header_start=-1, data_start=0) iapSRbigreg = np.where((dat['PHOTTYPE'] == 'apSR') & (dat['SKYANN'] == 'big') & (dat['IMTYPE'] == 'reg')) iapSRsmallreg = np.where((dat['PHOTTYPE'] == 'apSR') & (dat['SKYANN'] == 'small') & (dat['IMTYPE'] == 'reg')) iapSRbigsub = np.where((dat['PHOTTYPE'] == 'apSR') & (dat['SKYANN'] == 'big') & (dat['IMTYPE'] == 'sub')) iapSRsmallsub = np.where((dat['PHOTTYPE'] == 'apSR') & (dat['SKYANN'] == 'small') & (dat['IMTYPE'] == 'sub')) iapSRbigreg10 = np.where((dat['EPOCH'] < 20) & (dat['SKYANN'] == 'big') & (dat['IMTYPE'] == 'reg')) iapSRsmallreg10 = np.where((dat['EPOCH'] < 20) & (dat['SKYANN'] == 'small') & (dat['IMTYPE'] == 'reg')) iapSRbigreg20 = np.where((dat['EPOCH'] >= 20) & (dat['EPOCH'] < 30) & (dat['SKYANN'] == 'big') & (dat['IMTYPE'] == 'reg')) iapSRsmallreg20 = np.where((dat['EPOCH'] >= 20) & (dat['EPOCH'] < 30) & (dat['SKYANN'] == 'small') & (dat['IMTYPE'] == 'reg')) iapSRbigreg30 = np.where((dat['EPOCH'] < 40) & (dat['EPOCH'] >= 30) & (dat['SKYANN'] == 'big') & (dat['IMTYPE'] == 'reg')) iapSRsmallreg30 = np.where((dat['EPOCH'] < 40) & (dat['EPOCH'] >= 30) & (dat['SKYANN'] == 'small') & (dat['IMTYPE'] == 'reg')) iapSRbigreg40 = np.where((dat['EPOCH'] >= 40) & (dat['SKYANN'] == 'big') & (dat['IMTYPE'] == 'reg')) iapSRsmallreg40 = np.where((dat['EPOCH'] >= 40) & (dat['SKYANN'] == 'small') & (dat['IMTYPE'] == 'reg')) iapSRbigsub10 = np.where((dat['EPOCH'] < 20) & (dat['SKYANN'] == 'big') & (dat['IMTYPE'] == 'sub')) iapSRsmallsub10 = np.where((dat['EPOCH'] < 20) & (dat['SKYANN'] == 'small') & (dat['IMTYPE'] == 'sub')) iapSRbigsub20 = np.where((dat['EPOCH'] >= 20) & (dat['EPOCH'] < 30) & (dat['SKYANN'] == 'big') & (dat['IMTYPE'] == 'sub')) iapSRsmallsub20 = np.where((dat['EPOCH'] >= 20) & (dat['EPOCH'] < 30) & (dat['SKYANN'] == 'small') & (dat['IMTYPE'] == 'sub')) iapSRbigsub30 = np.where((dat['EPOCH'] < 40) & (dat['EPOCH'] >= 30) & (dat['SKYANN'] == 'big') & (dat['IMTYPE'] == 'sub')) iapSRsmallsub30 = np.where((dat['EPOCH'] < 40) & (dat['EPOCH'] >= 30) & (dat['SKYANN'] == 'small') & (dat['IMTYPE'] == 'sub')) #iapSRbigsub40 = np.where( (dat['EPOCH']>=40) & (dat['SKYANN']=='big') & (dat['IMTYPE']=='sub') ) #iapSRsmallsub40 = np.where( (dat['EPOCH']>=40) & (dat['SKYANN']=='small') & (dat['IMTYPE']=='sub') ) sky = dat['SKY'] skyerr = dat['SKYERR'] flux = dat['FLUX'] fluxerr = dat['FLUXERR'] SNR = np.abs(flux / fluxerr) plotargs = {'alpha': 0.8, 'mew': 0, 'ls': ' '} #fig1 = pl.figure(1) #pl.clf() # ax1 = pl.subplot(1,1,1) # pl.errorbar( sky[iapSRsmallreg10], sky[iapSRbigreg10] , skyerr[iapSRbigreg10], skyerr[iapSRsmallreg10],'bo', label='1 visit', **plotargs ) # pl.errorbar( sky[iapSRsmallreg20], sky[iapSRbigreg20] , skyerr[iapSRbigreg20], skyerr[iapSRsmallreg20],'go', label='2 visits', **plotargs ) # pl.errorbar( sky[iapSRsmallreg30], sky[iapSRbigreg30] , skyerr[iapSRbigreg30], skyerr[iapSRsmallreg30],'ro', label='3 visits', **plotargs ) # pl.errorbar( sky[iapSRsmallreg40], sky[iapSRbigreg40] , skyerr[iapSRbigreg40], skyerr[iapSRsmallreg40],'kD', label='4 visits', **plotargs ) # pl.plot( [-10,10],[-10,10],'k--') # ax1.axhline(0.0,color='k',ls=':') # ax1.set_xlim(0.45,0.7) # ax1.set_ylim(0.45,0.7) # ax1.set_xlabel('sky in alt template reg image (big annulus)') # ax1.set_ylabel('sky in alt template reg image (small annulus)') # ax1.legend( loc='upper left') # ax1.set_title('alternate drizzle combinations for stone template') # # fig2 = pl.figure(2) # pl.clf() # pl.errorbar( sky[iapSRsmallreg10] - sky[iapSRbigreg10] , sky[iapSRsmallsub10]-sky[iapSRbigsub10], skyerr[iapSRsmallreg10], skyerr[iapSRbigreg10], 'bo', label='1 visit', **plotargs ) # pl.errorbar( sky[iapSRsmallreg20] - sky[iapSRbigreg20] , sky[iapSRsmallsub20]-sky[iapSRbigsub20], skyerr[iapSRsmallreg20], skyerr[iapSRbigreg20], 'go', label='2 visits', **plotargs ) # pl.errorbar( sky[iapSRsmallreg30] - sky[iapSRbigreg30] , sky[iapSRsmallsub30]-sky[iapSRbigsub30], skyerr[iapSRsmallreg30], skyerr[iapSRbigreg30], 'ro', label='3 visits', **plotargs ) # # pl.errorbar( sky[iapSRsmallreg40] - sky[iapSRbigreg40] , sky[iapSRsmallsub40]-sky[iapSRbigsub40], skyerr[iapSRsmallreg40], skyerr[iapSRbigreg40], 'kD', label='4 visits', **plotargs ) # pl.ylabel( 'Fsky[small] - Fsky[big] from alt template diff images' ) # pl.xlabel( 'Fsky[small] - Fsky[big] from alt template reg images' ) import numpy as np A = np.pi * (0.3 / 0.09)**2 trueflux = flux + sky * A fig3 = pl.figure(3) pl.clf() # pl.errorbar( sky[iapSRsmallreg10] - sky[iapSRbigreg10] , trueflux[iapSRsmallreg10]-trueflux[iapSRbigreg10] , fluxerr[iapSRsmallreg10], skyerr[iapSRsmallreg10], color='b',marker='o', label='1 visit', **plotargs ) # pl.errorbar( sky[iapSRsmallreg20] - sky[iapSRbigreg20] , trueflux[iapSRsmallreg20]-trueflux[iapSRbigreg20] , fluxerr[iapSRsmallreg20], skyerr[iapSRsmallreg20], color='g',marker='o', label='2 visits', **plotargs ) # pl.errorbar( sky[iapSRsmallreg30] - sky[iapSRbigreg30] , trueflux[iapSRsmallreg30]-trueflux[iapSRbigreg30] , fluxerr[iapSRsmallreg30], skyerr[iapSRsmallreg30], color='r',marker='o', label='3 visits', **plotargs ) # pl.errorbar( sky[iapSRsmallreg40] - sky[iapSRbigreg40] , trueflux[iapSRsmallreg40]-trueflux[iapSRbigreg40] , fluxerr[iapSRsmallreg40], skyerr[iapSRsmallreg40], color='k',marker='D', label='4 visits', **plotargs ) pl.plot(-(sky[iapSRsmallreg10] - sky[iapSRbigreg10]) * A, (flux[iapSRsmallreg10] - flux[iapSRbigreg10]) / 1.22074468, color='b', marker='o', label='1 visit', **plotargs) pl.plot(-(sky[iapSRsmallreg20] - sky[iapSRbigreg20]) * A, (flux[iapSRsmallreg20] - flux[iapSRbigreg20]) / 1.22074468, color='g', marker='o', label='2 visits', **plotargs) pl.plot(-(sky[iapSRsmallreg30] - sky[iapSRbigreg30]) * A, (flux[iapSRsmallreg30] - flux[iapSRbigreg30]) / 1.22074468, color='r', marker='o', label='3 visits', **plotargs) pl.plot(-(sky[iapSRsmallreg40] - sky[iapSRbigreg40]) * A, (flux[iapSRsmallreg40] - flux[iapSRbigreg40]) / 1.22074468, color='k', marker='D', label='4 visits', **plotargs) pl.plot([-0.35, -0.05], [-0.35, -0.05])
def plot_stone_ap_vs_psf(): """ make a plot comparing S/N and observed mag for reg and sub photometry for SN stone, by DS and SR """ from astropy.io import ascii import numpy as np from matplotlib import pyplot as pl from pytools import plotsetup plotsetup.presfig(figsize=[10, 10]) dat = ascii.read('photcompare_stone.dat', format='commented_header', header_start=-1, data_start=0) iapSRbigreg = np.where((dat['PHOTTYPE'] == 'apSR') & (dat['SKYANN'] == 'big') & (dat['IMTYPE'] == 'reg')) iapSRsmallreg = np.where((dat['PHOTTYPE'] == 'apSR') & (dat['SKYANN'] == 'small') & (dat['IMTYPE'] == 'reg')) iapSRbigsub = np.where((dat['PHOTTYPE'] == 'apSR') & (dat['SKYANN'] == 'big') & (dat['IMTYPE'] == 'sub')) iapSRsmallsub = np.where((dat['PHOTTYPE'] == 'apSR') & (dat['SKYANN'] == 'small') & (dat['IMTYPE'] == 'sub')) iapDSreg = np.where((dat['PHOTTYPE'] == 'apDS') & (dat['IMTYPE'] == 'reg')) iapDSsub = np.where((dat['PHOTTYPE'] == 'apDS') & (dat['IMTYPE'] == 'sub')) ipsfDSreg = np.where((dat['PHOTTYPE'] == 'psfDS') & (dat['IMTYPE'] == 'reg')) ipsfDSsub = np.where((dat['PHOTTYPE'] == 'psfDS') & (dat['IMTYPE'] == 'sub')) mag = dat['MAG'] magerr = dat['MAGERR'] flux = dat['FLUX'] fluxerr = dat['FLUXERR'] SNR = np.abs(flux / fluxerr) plotargs = {'alpha': 0.8, 'mew': 0} pl.plot(mag[iapSRbigsub], mag[iapSRbigreg] - mag[iapSRbigsub], 'ro', label='ap big sky ann. (SR)', **plotargs) pl.plot(mag[iapSRsmallsub], mag[iapSRsmallreg] - mag[iapSRsmallsub], 'go', label='ap small sky ann. (SR)', **plotargs) pl.plot(mag[iapDSsub], mag[iapDSreg] - mag[iapDSsub], 'mD', label='ap (DS)', **plotargs) pl.plot(mag[ipsfDSsub], mag[ipsfDSreg] - mag[ipsfDSsub], 'cD', label='psf (DS)', **plotargs) ax1 = pl.gca() ax1.set_xlabel('sub mag [AB]') ax1.set_ylabel('observed difference : reg mag - sub mag') ax1.axhline(0.0, ls='--', color='0.5') ax1.legend(loc='upper left') ax1.invert_yaxis() ax1.text(26.8, -0.02, 'SN appears brighter in reg than in sub', color='0.3', ha='right', va='bottom', fontsize=12) ax1.text(26.8, 0.02, 'SN appears fainter in reg than in sub', color='0.3', ha='right', va='top', fontsize=12) ax1.set_ylim(0.4, -0.4) ax1.set_xlim(25, 27.7)
def plot_stone_template_tests(): """ make a plot comparing S/N and observed mag for reg and sub photometry for SN stone, by DS and SR """ from astropy.io import ascii import numpy as np from matplotlib import pyplot as pl from pytools import plotsetup plotsetup.presfig( figsize=[10,10]) dat = ascii.read( 'stone_template_phot.dat', format='commented_header', header_start=-1, data_start=0) iapSRbigreg = np.where( (dat['PHOTTYPE']=='apSR') & (dat['SKYANN']=='big') & (dat['IMTYPE']=='reg') ) iapSRsmallreg = np.where( (dat['PHOTTYPE']=='apSR') & (dat['SKYANN']=='small') & (dat['IMTYPE']=='reg') ) iapSRbigsub = np.where( (dat['PHOTTYPE']=='apSR') & (dat['SKYANN']=='big') & (dat['IMTYPE']=='sub') ) iapSRsmallsub = np.where( (dat['PHOTTYPE']=='apSR') & (dat['SKYANN']=='small') & (dat['IMTYPE']=='sub') ) iapSRbigreg10 = np.where( (dat['EPOCH']<20) & (dat['SKYANN']=='big') & (dat['IMTYPE']=='reg') ) iapSRsmallreg10 = np.where( (dat['EPOCH']<20) & (dat['SKYANN']=='small') & (dat['IMTYPE']=='reg') ) iapSRbigreg20 = np.where( (dat['EPOCH']>=20) & (dat['EPOCH']<30) & (dat['SKYANN']=='big') & (dat['IMTYPE']=='reg') ) iapSRsmallreg20 = np.where( (dat['EPOCH']>=20) & (dat['EPOCH']<30) & (dat['SKYANN']=='small') & (dat['IMTYPE']=='reg') ) iapSRbigreg30 = np.where( (dat['EPOCH']<40) & (dat['EPOCH']>=30) & (dat['SKYANN']=='big') & (dat['IMTYPE']=='reg') ) iapSRsmallreg30 = np.where( (dat['EPOCH']<40) & (dat['EPOCH']>=30) & (dat['SKYANN']=='small') & (dat['IMTYPE']=='reg') ) iapSRbigreg40 = np.where( (dat['EPOCH']>=40) & (dat['SKYANN']=='big') & (dat['IMTYPE']=='reg') ) iapSRsmallreg40 = np.where( (dat['EPOCH']>=40) & (dat['SKYANN']=='small') & (dat['IMTYPE']=='reg') ) iapSRbigsub10 = np.where( (dat['EPOCH']<20) & (dat['SKYANN']=='big') & (dat['IMTYPE']=='sub') ) iapSRsmallsub10 = np.where( (dat['EPOCH']<20) & (dat['SKYANN']=='small') & (dat['IMTYPE']=='sub') ) iapSRbigsub20 = np.where( (dat['EPOCH']>=20) & (dat['EPOCH']<30) & (dat['SKYANN']=='big') & (dat['IMTYPE']=='sub') ) iapSRsmallsub20 = np.where( (dat['EPOCH']>=20) & (dat['EPOCH']<30) & (dat['SKYANN']=='small') & (dat['IMTYPE']=='sub') ) iapSRbigsub30 = np.where( (dat['EPOCH']<40) & (dat['EPOCH']>=30) & (dat['SKYANN']=='big') & (dat['IMTYPE']=='sub') ) iapSRsmallsub30 = np.where( (dat['EPOCH']<40) & (dat['EPOCH']>=30) & (dat['SKYANN']=='small') & (dat['IMTYPE']=='sub') ) #iapSRbigsub40 = np.where( (dat['EPOCH']>=40) & (dat['SKYANN']=='big') & (dat['IMTYPE']=='sub') ) #iapSRsmallsub40 = np.where( (dat['EPOCH']>=40) & (dat['SKYANN']=='small') & (dat['IMTYPE']=='sub') ) sky = dat['SKY'] skyerr = dat['SKYERR'] flux = dat['FLUX'] fluxerr = dat['FLUXERR'] SNR = np.abs( flux / fluxerr ) plotargs = {'alpha':0.8, 'mew':0, 'ls':' '} #fig1 = pl.figure(1) #pl.clf() # ax1 = pl.subplot(1,1,1) # pl.errorbar( sky[iapSRsmallreg10], sky[iapSRbigreg10] , skyerr[iapSRbigreg10], skyerr[iapSRsmallreg10],'bo', label='1 visit', **plotargs ) # pl.errorbar( sky[iapSRsmallreg20], sky[iapSRbigreg20] , skyerr[iapSRbigreg20], skyerr[iapSRsmallreg20],'go', label='2 visits', **plotargs ) # pl.errorbar( sky[iapSRsmallreg30], sky[iapSRbigreg30] , skyerr[iapSRbigreg30], skyerr[iapSRsmallreg30],'ro', label='3 visits', **plotargs ) # pl.errorbar( sky[iapSRsmallreg40], sky[iapSRbigreg40] , skyerr[iapSRbigreg40], skyerr[iapSRsmallreg40],'kD', label='4 visits', **plotargs ) # pl.plot( [-10,10],[-10,10],'k--') # ax1.axhline(0.0,color='k',ls=':') # ax1.set_xlim(0.45,0.7) # ax1.set_ylim(0.45,0.7) # ax1.set_xlabel('sky in alt template reg image (big annulus)') # ax1.set_ylabel('sky in alt template reg image (small annulus)') # ax1.legend( loc='upper left') # ax1.set_title('alternate drizzle combinations for stone template') # # fig2 = pl.figure(2) # pl.clf() # pl.errorbar( sky[iapSRsmallreg10] - sky[iapSRbigreg10] , sky[iapSRsmallsub10]-sky[iapSRbigsub10], skyerr[iapSRsmallreg10], skyerr[iapSRbigreg10], 'bo', label='1 visit', **plotargs ) # pl.errorbar( sky[iapSRsmallreg20] - sky[iapSRbigreg20] , sky[iapSRsmallsub20]-sky[iapSRbigsub20], skyerr[iapSRsmallreg20], skyerr[iapSRbigreg20], 'go', label='2 visits', **plotargs ) # pl.errorbar( sky[iapSRsmallreg30] - sky[iapSRbigreg30] , sky[iapSRsmallsub30]-sky[iapSRbigsub30], skyerr[iapSRsmallreg30], skyerr[iapSRbigreg30], 'ro', label='3 visits', **plotargs ) # # pl.errorbar( sky[iapSRsmallreg40] - sky[iapSRbigreg40] , sky[iapSRsmallsub40]-sky[iapSRbigsub40], skyerr[iapSRsmallreg40], skyerr[iapSRbigreg40], 'kD', label='4 visits', **plotargs ) # pl.ylabel( 'Fsky[small] - Fsky[big] from alt template diff images' ) # pl.xlabel( 'Fsky[small] - Fsky[big] from alt template reg images' ) import numpy as np A = np.pi * (0.3/0.09)**2 trueflux = flux + sky * A fig3 = pl.figure(3) pl.clf() # pl.errorbar( sky[iapSRsmallreg10] - sky[iapSRbigreg10] , trueflux[iapSRsmallreg10]-trueflux[iapSRbigreg10] , fluxerr[iapSRsmallreg10], skyerr[iapSRsmallreg10], color='b',marker='o', label='1 visit', **plotargs ) # pl.errorbar( sky[iapSRsmallreg20] - sky[iapSRbigreg20] , trueflux[iapSRsmallreg20]-trueflux[iapSRbigreg20] , fluxerr[iapSRsmallreg20], skyerr[iapSRsmallreg20], color='g',marker='o', label='2 visits', **plotargs ) # pl.errorbar( sky[iapSRsmallreg30] - sky[iapSRbigreg30] , trueflux[iapSRsmallreg30]-trueflux[iapSRbigreg30] , fluxerr[iapSRsmallreg30], skyerr[iapSRsmallreg30], color='r',marker='o', label='3 visits', **plotargs ) # pl.errorbar( sky[iapSRsmallreg40] - sky[iapSRbigreg40] , trueflux[iapSRsmallreg40]-trueflux[iapSRbigreg40] , fluxerr[iapSRsmallreg40], skyerr[iapSRsmallreg40], color='k',marker='D', label='4 visits', **plotargs ) pl.plot( -(sky[iapSRsmallreg10] - sky[iapSRbigreg10])*A, (flux[iapSRsmallreg10]-flux[iapSRbigreg10])/1.22074468 , color='b',marker='o', label='1 visit', **plotargs ) pl.plot( -(sky[iapSRsmallreg20] - sky[iapSRbigreg20])*A, (flux[iapSRsmallreg20]-flux[iapSRbigreg20])/1.22074468 , color='g',marker='o', label='2 visits', **plotargs ) pl.plot( -(sky[iapSRsmallreg30] - sky[iapSRbigreg30])*A, (flux[iapSRsmallreg30]-flux[iapSRbigreg30])/1.22074468 , color='r',marker='o', label='3 visits', **plotargs ) pl.plot( -(sky[iapSRsmallreg40] - sky[iapSRbigreg40])*A, (flux[iapSRsmallreg40]-flux[iapSRbigreg40])/1.22074468 , color='k',marker='D', label='4 visits', **plotargs ) pl.plot([-0.35,-0.05],[-0.35,-0.05])
def plotSNRcompare(): from astropy.io import ascii import numpy as np from matplotlib import pyplot as pl from pytools import plotsetup fig = plotsetup.presfig() psfdat = ascii.read('psfphot3.dat', format='fixed_width') isub = np.where(psfdat['image'] == 'sub')[0] oSNRetc = psfdat['optSNRetc'][isub] SNRetc = psfdat['SNRetc'][isub] SNRpsf = psfdat['SNRpsf'][isub] psfmag = psfdat['stack'][isub] band = psfdat['band'][isub] iwide = np.array([i for i in range(len(band)) if band[i].endswith('w')]) imed = np.array([i for i in range(len(band)) if band[i].endswith('m')]) pl.clf() ax = pl.subplot(2, 2, 1) ax.plot(oSNRetc[iwide], SNRpsf[iwide], color='darkorange', marker='d', ls=' ', alpha=0.5, mew=0.5, ms=8, label='wide band subs') ax.plot( oSNRetc[imed], SNRpsf[imed], 'mo', ls=' ', alpha=0.7, mew=0.5, ms=8, label='med band subs', ) ax.plot([0, 200], [0, 200], 'k-') ax.set_xlim(0, 45) ax.set_ylim(0, 45) ax.set_xlabel('Optimal S/N from ETC') ax.set_ylabel('Observed S/N from PSF drops') ax.legend(numpoints=1, loc='lower right') ax = pl.subplot(2, 2, 2) ax.plot(oSNRetc[iwide], SNRpsf[iwide], color='darkorange', marker='d', ls=' ', alpha=0.5, mew=0.5, ms=8) ax.plot(oSNRetc[imed], SNRpsf[imed], 'mo', ls=' ', alpha=0.7, mew=0.5, label='med band subs', ms=8) ax.plot([0, 100], [0, 100], 'k-') ax.set_xlim(0, 15) ax.set_ylim(0, 15) ax.set_xlabel('Optimal S/N from ETC') ax.set_ylabel('Observed S/N from PSF drops') ax = pl.subplot(2, 2, 3) ax.plot(SNRetc[iwide], SNRpsf[iwide], color='darkred', marker='d', ls=' ', alpha=0.5, mew=0.5, ms=8, label='wide band subs') ax.plot(SNRetc[imed], SNRpsf[imed], 'co', ls=' ', alpha=0.7, mew=0.5, ms=8, label='med band subs') ax.plot([0, 200], [0, 200], 'k-') ax.set_xlim(0, 45) ax.set_ylim(0, 45) ax.set_xlabel('Aperture S/N from ETC') ax.set_ylabel('Observed S/N from PSF drops') ax.legend(numpoints=1, loc='lower right') ax = pl.subplot(2, 2, 4) ax.plot(SNRetc[iwide], SNRpsf[iwide], color='darkred', marker='d', ls=' ', alpha=0.5, mew=0.5, ms=8) ax.plot(SNRetc[imed], SNRpsf[imed], 'co', ls=' ', alpha=0.7, mew=0.5, ms=8) ax.plot([0, 100], [0, 100], 'k-') ax.set_xlim(0, 15) ax.set_ylim(0, 15) ax.set_xlabel('Aperture S/N from ETC') ax.set_ylabel('Observed S/N from PSF drops') pl.draw()
def mkresidplot( datfile='ps1union.dat', ageaxis=True, highz='Malmquist', highzlabels=True, lensfactor=0.093, presfig=False, bigtext=False ) : """ construct the hubble residual plot """ from pytools import plotsetup, cosmo, colorpalette as cp from matplotlib import patches import numpy as np from matplotlib import pyplot as pl from scipy.interpolate import interp1d if presfig : plotsetup.presfig( wide=True ) else : plotsetup.fullpaperfig( [8.5,4.5], bigtext=bigtext) clf() highz= highz.lower() if highz=='malmquist': zlim=[0,2.78] elif highz=='rodney': zlim=[0,3.49] if presfig : zlim=[0,3.78] else : zlim=[0,2.45] fig = gcf() if presfig : bottomAxeslim = [ 0.13, 0.18, 0.85, 0.65 ] else : bottomAxeslim = [ 0.09, 0.12, 0.88, 0.75 ] ax1 = fig.add_axes( bottomAxeslim, frameon=True, alpha=0.0, label='axes1') ax1top = ax1.twiny() # read in redshifts and distances hubbledat, H0, Om, MB = gethubbledat( datfile ) if lensfactor : # muerr = 0.093z : Holz & Linder, 2005 # muerr = 0.055z : Jonsson+ 2012 hubbledat['muerr'] = np.sqrt( hubbledat['muerr']**2 + (lensfactor*hubbledat['z'])**2 ) # plot ground data colordict = {'low-z':cp.purple, 'sdss':cp.lightblue, 'ps1':cp.darkblue, 'snls':cp.darkgreen, 'hstacs':cp.darkorange, 'hstwfc3':cp.medred, 'hstwfc3a':cp.medred, 'hstwfc3b':cp.darkred, 'jwst':cp.darkgrey, } elw=0.75 cs=0 for survey in ['low-z','sdss','snls','ps1','hstacs']: isurvey = where( (hubbledat['survey']==survey) & (hubbledat['spec']>0) ) ax1.errorbar( hubbledat['z'][isurvey], hubbledat['mures'][isurvey], hubbledat['muerr'][isurvey], hubbledat['zerr'][isurvey], marker='o', ls=' ',mew=0.01, markersize=5, color=colordict[survey], mfc=colordict[survey], ecolor=colordict[survey], elinewidth=elw, capsize=cs, alpha=0.7 ) if highz : # get the high-z SN fits from Dan labeldict = {#'primo':'Rodney+ 2012', #'wilson':'Jones, Rodney+ 2013', 'stone':'GND13Sto', 'colfax':'GND12Col', } if highz=='rodney': labeldict = {'primo':'Rodney+ 2012', 'wilson':'Jones, Rodney+ 2013', 'stone':'Rodney+ in prep', 'colfax':'Rodney+ in prep', } for survey, namelist in zip( ['hstwfc3a','hstwfc3b'], [['primo','wilson'],['stone','colfax']] ): color=colordict[survey] for name in namelist : if name not in hubbledat['name'] : continue iname = np.where( hubbledat['name'] == name )[0][0] z,zerr = hubbledat['z'][iname], hubbledat['zerr'][iname] mu,muerr = hubbledat['mures'][iname],hubbledat['muerr'][iname] if name=='colfax' : # Not applying a lensing correction for mu=1.04 +-0.03 : 0.0426 +- 0.031 mag icol = np.where( [n.startswith('col') for n in hubbledat['name']] )[0] mucol = interp1d( hubbledat['z'][icol], hubbledat['mures'][icol] ) ax1.plot( [2.16,2.19,2.21,2.24,2.26,2.28], mucol([2.16,2.19,2.21,2.24,2.26,2.28]), color=color, lw=0.75, ls='-' ) ax1.errorbar( 2.26, mucol(2.26), muerr, marker='D', ls=' ',mew=0.01, markersize=8, color=color, mfc=color, ecolor=color, elinewidth=elw, capsize=cs, alpha=1 ) z = 2.26 mu = mucol(2.26) elif name=='stone' : # not applying a lensing correction for stone: # mu = mu + 0.0215; muerr = np.sqrt( muerr**2 + 0.02**2 ) isto = np.where( [n.startswith('stone') for n in hubbledat['name']] )[0] musto = interp1d( hubbledat['z'][isto], hubbledat['mures'][isto] ) ax1.plot( np.arange(1.66,2.01,0.02), musto(np.arange(1.66,2.01,0.02)), color=color, lw=0.75, ls='--' ) ax1.errorbar( 1.80, musto(1.80), muerr, zerr, marker='D', ls=' ',mew=0.01, markersize=8, color=color, mfc=color, ecolor=color, elinewidth=elw, capsize=cs, alpha=1 ) z = 1.80 mu = musto(1.80) else : ax1.errorbar( z, mu, muerr, zerr, marker='D', ls=' ',mew=0.01, markersize=8, color=color, mfc=color, ecolor=color, elinewidth=elw, capsize=cs, alpha=1 ) if highzlabels and name in labeldict : # ax1.text( z-0.035, mu+0.07, labeldict[name], if name=='primo': ax1.text( z-0.05, mu+0.035, labeldict[name], color=color, # backgroundcolor='w', va='bottom', ha='center', rotation=90 ) else : ax1.text( z, mu+muerr+0.07, labeldict[name], color=color, # backgroundcolor='w', va='bottom', ha='center', rotation=90 ) # plot the lcdm cosmology ax1.axhline( 0, color='0.4', ls='-' ) # plot extreme w' zLCDM = np.arange( 0.01, 5, 0.05) muLCDM = cosmo.mu( zLCDM, H0=H0, Om=Om, Ode=(1-Om), w0=-1., wa=0) #muextremeDE = cosmo.mu( z, H0=_H0, Om=_Om, Ode=(1-_Om), w0=-0.7, wa=-2) mu1 = cosmo.mu( zLCDM, H0=H0, Om=Om-0.015, Ode=(1-Om+0.015), w0=-1.2, wa=0.7) mu2 = cosmo.mu( zLCDM, H0=H0, Om=Om+0.055, Ode=(1-Om-0.055), w0=-0.65, wa=-2.2) ax1.fill_between( zLCDM, mu1-muLCDM, mu2-muLCDM, color='k', alpha=0.2, lw=0.01, zorder=10 ) if not presfig : ax1.text( 0.08, -0.8, 'low-z', fontsize=(presfig and 'small') or 10.5, ha='center', color=colordict['low-z'] ) ax1.text( 0.25, -0.85, 'SDSS', fontsize=(presfig and 'small') or 10.5, ha='center', color=colordict['sdss'] ) ax1.text( 0.5 , -0.9, 'PS1', fontsize=(presfig and 'small') or 10.5, ha='center', color=colordict['ps1'] ) ax1.text( 0.75, -0.95, 'SNLS', fontsize=(presfig and 'small') or 10.5, ha='center', color=colordict['snls'] ) ax1.text( 1.25, -0.8, 'HST+ACS', fontsize=(presfig and 'small') or 10.5, ha='center', color=colordict['hstacs'] ) ax1.text( 1.95, -0.95, 'HST+WFC3', fontsize=(presfig and 'small') or 10.5, ha='center', color=colordict['hstwfc3b'] ) lowzRect = patches.Rectangle( [0.0,-0.85], 0.08, 0.03, fill=True, lw=0, alpha=0.3, color=colordict['low-z'] ) sdssRect = patches.Rectangle( [0.06,-0.9], 0.34, 0.03, fill=True, lw=0, alpha=0.3, color=colordict['sdss'] ) ps1Rect = patches.Rectangle( [0.1,-0.95], 0.5, 0.03, fill=True, lw=0, alpha=0.3, color=colordict['ps1'] ) snlsRect = patches.Rectangle( [0.15,-1.0], 0.9, 0.03, fill=True, lw=0, alpha=0.3, color=colordict['snls'] ) acsRect = patches.Rectangle( [0.60,-0.85], 1.15, 0.03, fill=True, lw=0, alpha=0.3, color=colordict['hstacs'] ) wfc3Rect = patches.Rectangle( [1.20,-1.0], 1.1, 0.03, fill=True, lw=0, alpha=0.3, color=colordict['hstwfc3b'] ) ax1.add_patch( lowzRect ) ax1.add_patch( sdssRect ) ax1.add_patch( ps1Rect ) ax1.add_patch( snlsRect ) ax1.add_patch( acsRect ) ax1.add_patch( wfc3Rect ) if highz=='rodney': if not presfig : #ffsnRect = patches.Rectangle( [2.30,-1.0], 0.7, 0.03, fill=False,lw=1, alpha=1.0, color=colordict['hstwfc3b'] ) jwstRect = patches.Rectangle( [2.00,-0.85],2.0, 0.03, fill=False,lw=1, alpha=1.0, color=colordict['jwst'] ) #ax1.add_patch( ffsnRect ) ax1.add_patch( jwstRect ) #ax1.text( 2.5, -0.95, '+ lensing',fontsize=10.5, ha='center', color=colordict['hstwfc3b'] ) ax1.text( 3.0, -0.78, 'JWST', fontsize=(presfig and 'medium') or 10.5, ha='center', color=colordict['jwst'] ) color = cp.bluegray ax1.arrow( 2.5, 0.15, 0.3, 0.0, fc=color, ec=color, head_width=0.05, head_length=0.0, overhang=0.0 ) ax1.plot( 2.5, 0.15, marker='o', mfc='w', mec=color ) ax1.text( 2.49, 0.19, '0.3 Gyr', ha='left', va='bottom', color=color) ax1.text( 2.82, 0.15, 'z=2.8', ha='left', va='center', color=color) color = cp.teal ax1.arrow( 2.5, 0.45, 0.55, 0.0, fc=color, ec=color, head_width=0.05, head_length=0.08, overhang=0.25, length_includes_head=True ) ax1.plot( 2.5, 0.45, marker='o', mfc='w', mec=color ) ax1.text( 2.6, 0.48, '1 Gyr', ha='left', va='bottom', color=color) ax1.text( 3.08, 0.45, 'z=3.8', ha='left', va='center', color=color) color = cp.coral ax1.arrow( 2.5, 0.7, 0.75, 0.0, fc=color, ec=color, head_width=0.05, head_length=0.08, overhang=0.25, length_includes_head=True ) ax1.plot( 2.5, 0.7, marker='o', mfc='w', mec=color ) ax1.text( 2.7, 0.72, '2 Gyr', ha='left', va='bottom', color=color) ax1.text( 3.28, 0.7, 'z=8.3', ha='left', va='center', color=color) if not presfig : ax1.text( 2.5, 0.7, 'z=2.5', ha='center', va='bottom', color='0.4' ) ax1.text( 2.5, 0.8, 'explosion', ha='center', va='bottom', color='0.3' )#, fontsize=10.5 ) ax1.text( 2.85, 0.8, 'delay', ha='center', va='bottom', color='0.3' )#, fontsize=10.5 ) ax1.text( 3.15, 0.8, 'formation', ha='left', va='bottom', color='0.3' )#, fontsize=10.5 ) if presfig : ax1.text( 0.82, 0.46, 'flat $\Lambda$CDM', color='0.1', ha='right', va='top', transform=ax1.transAxes )# , fontsize=10.5, backgroundcolor='w' ) else : ax1.text( 0.99, 0.56, 'flat $\Lambda$CDM', color='0.1', ha='right', va='top', transform=ax1.transAxes )# , fontsize=10.5, backgroundcolor='w' ) ax1.text( 0.99, 0.46, '$\pm$95\% conf. \non $w_0 , w_a$', color='0.4', ha='right', va='top', transform=ax1.transAxes )# , fontsize=10.5,backgroundcolor='w' ) # ax1.text( 0.95, 0.95, 'Open Symbols:\n no spec. confirmation', color='0.5', transform=ax1.transAxes, ha='right',va='top' ) ax1.set_xlabel('Redshift',fontsize='large') # ax1.set_ylabel('$\mu_{observed}$ - $\mu_{\Lambda CDM}$') if highz=='rodney' : ax1.set_ylabel(r'$m_B^{\prime} - m_{\Lambda CDM}$', fontsize='large') else : ax1.set_ylabel(r'$m_B + \alpha x_1 - \beta c - m_{\Lambda CDM}$', fontsize='large') if presfig : ax1.yaxis.set_label_coords( -0.08, 0.65 ) # mulim = array( [33,46.5] ) muresidlim = array( [-1.05,1.05] ) # zlim = array( [0.0,3.49] ) ax1.xaxis.set_ticks( [0.1,] + np.arange(0.5,zlim[-1],0.5).tolist() ) ax1.set_xlim( zlim ) ax1.set_ylim( muresidlim ) from pytools import colorpalette as cp if highz.lower()=='malmquist' : # z, dm, tvis = get_visibility_time_grid( 0.5, x1=0., c=0. ) # contourlevels = [50] # ax1.contour( z, dm, tvis, levels=contourlevels, colors=cp.darkbluegray, linestyles='dashed' ) z5050, dm5050 = get_visibility_time_line( tvislim=50, deteff_threshold=0.5, x1=0, c=0, zrange=[1.0,3.0] ) ax1.fill_between( z5050, dm5050, np.ones(len(z5050))*muresidlim[1]+0.05, color=cp.bluegray, zorder=-200, alpha=0.3) # ax1.plot( z5050, dm5050, color='0.8') z050, dm050 = get_visibility_time_line( tvislim=0.01, deteff_threshold=0.5, x1=0, c=0, zrange=[1.7,3.0] ) ax1.fill_between( z050, dm050, np.ones(len(z050))*muresidlim[1]+0.05, color=cp.darkbluegray, zorder=-100, alpha=0.3) ax1.text( 1.53, 0.92, 't$_{\\rm vis}<$50 days', ha='left', va='top', color=cp.darkgrey ) ax1.text( 2.75, 0.92, 'undetectable', ha='right', va='top', color=cp.darkgrey ) if highz=='evolution' : # plot SNIa evolution minmassdict = progenitorMinMassLines( zform=11 ) z = minmassdict['z'] for key,color in zip( ['mm25','mm15','mm04'], ['r','g','b'] ): minmass = minmassdict[key] mavez = Mave( _MAXMASS, minmass ) ax1.plot( z, (mavez-mavez[0]) * _DMUDMASS, ls='-', color=color ) ax1.text( 2.5, -0.95, '+ lensing',fontsize=10.5, ha='center', color=colordict['hstwfc3b'] ) ax1.text( 3.0, -0.78, 'JWST', fontsize=10.5, ha='center', color=colordict['jwst'] ) color = cp.bluegray ax1.arrow( 2.5, 0.25, 0.3, 0.0, fc=color, ec=color, head_width=0.05, head_length=0.0, overhang=0.0 ) ax1.plot( 2.5, 0.25, marker='o', mfc='w', mec=color ) ax1.text( 2.55, 0.27, '0.3 Gyr', ha='left', va='bottom', color=color) ax1.text( 2.82, 0.25, 'z=2.8', ha='left', va='center', color=color) color = cp.teal ax1.arrow( 2.5, 0.45, 0.55, 0.0, fc=color, ec=color, head_width=0.05, head_length=0.08, overhang=0.25, length_includes_head=True ) ax1.plot( 2.5, 0.45, marker='o', mfc='w', mec=color ) ax1.text( 2.65, 0.47, '1 Gyr', ha='left', va='bottom', color=color) ax1.text( 3.08, 0.45, 'z=3.8', ha='left', va='center', color=color) color = cp.coral ax1.arrow( 2.5, 0.65, 0.75, 0.0, fc=color, ec=color, head_width=0.05, head_length=0.08, overhang=0.25, length_includes_head=True ) ax1.plot( 2.5, 0.65, marker='o', mfc='w', mec=color ) ax1.text( 2.75, 0.67, '2 Gyr', ha='left', va='bottom', color=color) ax1.text( 3.28, 0.65, 'z=8.3', ha='left', va='center', color=color) ax1.text( 2.5, 0.7, 'z=2.5', ha='center', va='bottom', color='0.4' ) ax1.text( 2.5, 0.8, 'explosion', ha='center', va='bottom', color='0.3', fontsize=10.5 ) ax1.text( 2.85, 0.8, 'delay', ha='center', va='bottom', color='0.3', fontsize=10.5 ) ax1.text( 3.15, 0.8, 'formation', ha='left', va='bottom', color='0.3', fontsize=10.5 ) if ageaxis : if highz=='rodney': # ax1top.set_xlabel( 'age of Universe (Gyr)',fontsize='large',x=0.15,ha='left') ageticks = np.array( [13, 9, 6, 4, 3, 2 ] ) else : ageticks = np.array( [13, 9, 6, 4, 3 ] ) ax1top.set_xlabel( 'Age of Universe (Gyr)',fontsize='large') ax1top.set_xlim( zlim ) ztickloctop = cosmo.zfromt( ageticks ) ax1top.xaxis.set_ticks( ztickloctop ) ax1top.xaxis.set_ticklabels( ageticks ) pl.draw()
def plothostless_compare(): """ make a plot comparing S/N and observed mag for reg and sub in hostless """ from astropy.io import ascii import numpy as np from matplotlib import pyplot as pl from pytools import plotsetup psfdat = ascii.read('psfphot3.dat', format='fixed_width') snlist = psfdat['sn'] bandlist = psfdat['band'] imagelist = psfdat['image'] epochlist = psfdat['epoch'] fig = plotsetup.presfig() pl.clf() ax1 = pl.subplot(1, 2, 1) ax2 = pl.subplot(1, 2, 2) for thissn, color in zip(['stone'], ['red']): SNRsub, magsub, SNRreg, magreg, bandmatch = [], [], [], [], [] for row in psfdat: sn = row['sn'] if thissn == 'hosted' and sn in ['stone', 'dawes']: continue if thissn != 'hosted' and sn != thissn: continue band = row['band'] epoch = row['epoch'] image = row['image'] if image == 'reg': continue imatch = np.where((bandlist == band) & (snlist == sn) & (epochlist == epoch) & (imagelist == 'reg'))[0] if len(imatch) == 1: SNRsub.append(row['SNRpsf']) # magsub.append( row['stack']) magsub.append(row['aperture']) SNRreg.append(psfdat['SNRpsf'][imatch[0]]) # magreg.append( psfdat['stack'][imatch[0]]) magreg.append(psfdat['aperture'][imatch[0]]) bandmatch.append(band) SNRsub, magsub, SNRreg, magreg, bandmatch = np.array(SNRsub), np.array( magsub), np.array(SNRreg), np.array(magreg), np.array(bandmatch) # imed = np.array([ i for i in range(len(bandmatch)) if bandmatch[i].endswith('m')]) # iwide = np.array([ i for i in range(len(bandmatch)) if bandmatch[i].endswith('w')]) imed = np.array( [i for i in range(len(bandmatch)) if bandmatch[i] == 'f125w']) iwide = np.array( [i for i in range(len(bandmatch)) if bandmatch[i] != 'f125w']) ax1.plot(magsub[iwide], magreg[iwide] - magsub[iwide], color=color, marker='d', ls=' ', alpha=0.8, mew=0.5, ms=8, label='%s other' % thissn) if len(imed): ax1.plot(magsub[imed], magreg[imed] - magsub[imed], color=color, marker='o', ls=' ', alpha=0.8, mew=0.5, ms=12, label='%s f125w' % thissn) ax1.set_xlim(24.8, 28.1) ax1.set_ylim(1.1, -1.1) ax1.set_ylabel('observed difference : reg mag - sub mag') ax1.set_xlabel('sub mag (AB)') ax2.plot(SNRsub[iwide], SNRreg[iwide] - SNRsub[iwide], color=color, marker='d', ls=' ', alpha=0.8, mew=0.5, ms=8, label='other') if len(imed): ax2.plot(SNRsub[imed], SNRreg[imed] - SNRsub[imed], color=color, marker='o', ls=' ', alpha=0.8, mew=0.5, ms=12, label='f125w') ax2.set_xlim(0, 25) ax2.set_ylim(-5, 11) ax2.set_ylabel('observed difference : reg S/N - sub S/N') ax2.set_xlabel('sub S/N') ax1.text(28, -0.02, 'SN appears brighter in reg than in sub', color='0.3', ha='right', va='bottom', fontsize=12) ax1.text(28, 0.02, 'SN appears fainter in reg than in sub', color='0.3', ha='right', va='top', fontsize=12) ax1.axhline( 0, color='0.5', ls='--', ) ax2.axhline( 0, color='0.5', ls='--', ) ax2.text(25, 0.5, 'S/N is better in reg than in sub', color='0.3', ha='right', va='bottom', fontsize=12) ax2.text(25, -0.5, 'S/N is worse in reg than in sub', color='0.3', ha='right', va='top', fontsize=12) ax1.legend(numpoints=1, loc='lower left') pl.draw()
def mkhubblefig( datfile='ps1union.dat', ageaxis=True, highz='rodney', bigtext=False ) : """ construct the hubble residual plot """ from pytools import plotsetup, cosmo, colorpalette as cp from matplotlib import patches, ticker from mpl_toolkits.axes_grid1 import host_subplot from astropy.io import ascii import numpy as np from matplotlib import pyplot as pl from scipy.interpolate import interp1d plotsetup.presfig(wide=True) pl.clf() fig = pl.gcf() if highz=='Malmquist': zlim=[0,2.58] elif highz=='rodney': zlim=[0,3.49] if bigtext : zlim=[0,3.53] else : zlim=[0,2.45] # bottomAxeslim = [ 0.14, 0.14, 0.72, 0.72 ] # ax1 = fig.add_axes( bottomAxeslim, frameon=True, alpha=0.0, label='axes1') ax1 = host_subplot(111) fig.subplots_adjust( left=0.11, bottom=0.16, right=0.89, top=0.84 ) # read in redshifts and distances hubbledat, H0, Om, MB = gethubbledat( datfile ) lensfactor=0.093 hubbledat['muerr'] = np.sqrt( hubbledat['muerr']**2 + (lensfactor*hubbledat['z'])**2 ) # plot ground data colordict = {'low-z':cp.purple, 'sdss':cp.lightblue, 'ps1':cp.darkblue, 'snls':cp.darkgreen, 'hstacs':cp.darkorange, 'hstwfc3a':cp.medred, 'hstwfc3b':cp.darkred, 'jwst':cp.darkgrey, } elw=0.75 cs=0 for survey in ['low-z','sdss','snls','ps1','hstacs','hstwfc3']: isurvey = where( (hubbledat['survey']==survey) & (hubbledat['spec']>0) ) ax1.errorbar( hubbledat['z'][isurvey], hubbledat['mu'][isurvey], hubbledat['muerr'][isurvey], hubbledat['zerr'][isurvey], marker='o', ls=' ',mew=0, markersize=5, color=colordict[survey], mfc=colordict[survey], ecolor=colordict[survey], elinewidth=elw, capsize=cs, alpha=0.7 ) if highz : # get the high-z SN fits from Dan labeldict = {#'primo':'Rodney+ 2012', #'wilson':'Jones, Rodney+ 2013', 'stone':'GND13Sto', 'colfax':'GND12Col', } if highz=='rodney': labeldict = {'primo':'Rodney+ 2012', 'wilson':'Jones, Rodney+ 2013', 'stone':'Rodney+ in prep', 'colfax':'Rodney+ in prep', } for survey, namelist in zip( ['hstwfc3a','hstwfc3b'], [['primo','wilson'],['stone','colfax']] ): color=colordict[survey] for name in namelist : if name not in hubbledat['name'] : continue iname = np.where( hubbledat['name'] == name )[0][0] z,zerr = hubbledat['z'][iname], hubbledat['zerr'][iname] mu,muerr = hubbledat['mu'][iname],hubbledat['muerr'][iname] if name=='colfax' : icol = np.where( [n.startswith('col') for n in hubbledat['name']] )[0] # lensing correction for mu=1.04 +-0.03 : 0.0426 +- 0.031 mag mucol = interp1d( hubbledat['z'][icol], hubbledat['mu'][icol]+0.0426) muerr = np.sqrt( muerr**2 + 0.031**2 ) ax1.plot( [2.16,2.19,2.25,2.28], mucol([2.16,2.19,2.25,2.28]), color=color, lw=0.75, ls='-' ) ax1.errorbar( 2.22, mucol(2.22), muerr, marker='D', ls=' ',mew=0, markersize=8, color=color, mfc=color, ecolor=color, elinewidth=elw, capsize=cs, alpha=1 ) z = 2.1 mu = mucol(2.1) else : if name=='stone': mu = mu + 0.0215 muerr = np.sqrt( muerr**2 + 0.02**2 ) ax1.errorbar( z, mu, muerr, zerr, marker='D', ls=' ',mew=0, markersize=8, color=color, mfc=color, ecolor=color, elinewidth=elw, capsize=cs, alpha=1 ) if highzlabels and name in labeldict : ax1.text( z+0.02, mu-0.6, labeldict[name], color=color, # backgroundcolor='w', fontsize='small', va='top', ha='center', rotation=90 ) # plot the lcdm cosmology ax1.axhline( 0, color='0.4', ls='-' ) # plot extreme w' zLCDM = np.arange( 0.01, 5, 0.05) muLCDM = cosmo.mu( zLCDM, H0=H0, Om=Om, Ode=(1-Om), w0=-1., wa=0) #muextremeDE = cosmo.mu( z, H0=_H0, Om=_Om, Ode=(1-_Om), w0=-0.7, wa=-2) mu1 = cosmo.mu( zLCDM, H0=H0, Om=Om-0.015, Ode=(1-Om+0.015), w0=-1.2, wa=0.7) mu2 = cosmo.mu( zLCDM, H0=H0, Om=Om+0.055, Ode=(1-Om-0.055), w0=-0.65, wa=-2.2) ax1.fill_between( zLCDM, mu1, mu2, color='k', alpha=0.2, lw=0, zorder=10 ) ax1.text( 0.3, 35, 'low-z', fontsize='large', ha='center', color=colordict['low-z'] ) ax1.text( 0.4, 37.5, 'SDSS', fontsize='large', ha='center', color=colordict['sdss'] ) ax1.text( 0.7, 40, 'PS1', fontsize='large', ha='center', color=colordict['ps1'] ) ax1.text( 1.0, 42, 'SNLS', fontsize='large', ha='center', color=colordict['snls'] ) ax1.text( 1.4, 46, 'HST+ACS', fontsize='large', ha='right', color=colordict['hstacs'] ) ax1.text( 1.83, 47, 'HST+WFC3', fontsize='large', ha='center', color=colordict['hstwfc3b'] ) ax1.text( 3.0, 46, '( JWST )', fontsize='large', ha='center', color=colordict['jwst'] ) ax1.set_xlabel('Redshift',fontsize='large') ax1.set_ylabel(r'Distance Modulus', fontsize='large') mulim = array( [33, 49.5] ) muresidlim = array( [-1.05,1.05] ) ax1.xaxis.set_ticks( [0.1,] + np.arange(0.5,zlim[-1],0.5).tolist() ) ax1.set_xlim( zlim ) ax1.set_ylim( mulim ) ax1.yaxis.set_major_locator( ticker.MultipleLocator( 4 ) ) ax1.yaxis.set_minor_locator( ticker.MultipleLocator( 1 ) ) if ageaxis : ax2 = ax1.twin() if highz=='rodney': # ax1top.set_xlabel( 'age of Universe (Gyr)',fontsize='large',x=0.15,ha='left') ageticks = np.array( [13, 9, 6, 4, 3, 2 ] ) else : ageticks = np.array( [13, 9, 6, 4, 3 ] ) ax2.set_xlim( zlim ) ztickloctop = cosmo.zfromt( ageticks ) ax2.xaxis.set_ticks( ztickloctop ) ax2.xaxis.set_ticklabels( ageticks ) ax2.yaxis.set_major_locator( ticker.MultipleLocator( 4 ) ) ax2.yaxis.set_minor_locator( ticker.MultipleLocator( 1 ) ) ax2.yaxis.set_ticklabels( [ '%i'%round(float(tick)+MB) for tick in ax1.yaxis.get_majorticklocs()] ) ax2.set_xlabel( 'Age of Universe (Gyr)',fontsize='large') ax2.set_ylabel( 'Peak Magnitude',fontsize='large',rotation=-90, labelpad=27) pl.draw()
def sncosmoplot( sn, fit, res ): from pytools import plotsetup plotsetup.presfig() sncosmo.plot_lc( sn, model=fit, errors=res.errors )