Ejemplo n.º 1
0
def compY1Y3():
    f1 = fitsio.read('/Users/ashleyross/Dropbox/DESY3/Y1mag22.fits')
    fs_1 = fitsio.read('/Users/ashleyross/Dropbox/DESY3/Y3red_1.fits')
    fs_2 = fitsio.read('/Users/ashleyross/Dropbox/DESY3/Y3red_2.fits')
    maskf = open(
        '/Users/ashleyross/DESY1/mask_Y1redBAO_mean_z_bpz_VFF_4096ring.dat')
    npix = 12 * 4096 * 4096
    mask = []
    pixl1 = np.zeros(f1.size)
    pixl3_1 = np.zeros(fs_1.size)
    pixl3_2 = np.zeros(fs_2.size)
    for i in range(0, npix):
        mask.append(0)
    for line in maskf:
        pix = int(float(line.split()[0]))
        mask[pix] = 1
    print 'mask done'
    ng = 0
    ng3 = 0
    for i in range(0, f1.size):
        ra, dec = f1[i]['RA'], f1[i]['DEC']
        th, phi = radec2thphi(ra, dec)
        p = hp.ang2pix(4096, th, phi)
        if mask[int(p)] == 1:
            pixl1[i] = 1
    print 'f1 done'
    for i in range(0, fs_1.size):
        ra, dec = fs_1[i]['RA'], fs_1[i]['DEC']
        th, phi = radec2thphi(ra, dec)
        p = hp.ang2pix(4096, th, phi)
        if mask[int(p)] == 1:
            pixl3_1[i] = 1
    print 'f3_1 done'
    for i in range(0, fs_2.size):
        ra, dec = fs_2[i]['RA'], fs_2[i]['DEC']
        th, phi = radec2thphi(ra, dec)
        p = hp.ang2pix(4096, th, phi)
        if mask[int(p)] == 1:
            pixl3_2[i] = 1
    print 'f3_2 done'
    w1 = (pixl1 == 1) & (f1['MAG_AUTO_I'] - f1['MAG_AUTO_Z'] + 2. *
                         (f1['MAG_AUTO_R'] - f1['MAG_AUTO_I']) >
                         1.7) & (f1['MAG_AUTO_I'] > 17.5)
    f1m = f1[w1]
    w3_1 = (pixl3_1 == 1)
    f3_1m = fs_1[w3_1]
    w3_2 = (pixl3_2 == 1)
    f3_2m = fs_2[w3_2]
    print f1m.size, f3_1m.size + f3_2m.size
Ejemplo n.º 2
0
def mkgalmapY3ac(res,zr,gz='.gz',md='',fore='',wm='',syscut=''):
	gl = []
	for i in range(0,12*res*res):
		gl.append(0)
	#f = fitsio.read(dir+'dr1_lss_red_'+zr+'_v0_redux.fits.gz',ext=1)
	f = fitsio.read(dir+'test'+zr+mask+'.fits'+gz,ext=1)
	ngt = 0
	w = 1.
	zem = 0
	fw = ''
	if fore == 'fore':
		fw = '_fore'
	#if fore == 'auto':
	#	fw = '_auto'
	if md == 'nodepth':
		md = '_none'
	#else:
	#	md = '_'+md	
	for i in range(0,len(f)):
		ra,dec = f[i]['RA'],f[i]['DEC']
		
		#if f[i]['v0'+md+fw] == 1.:
		
		#if wm != '':
		#	w = float(ln[4])
		#if z > zmin and z < zmax:
		th,phi = radec2thphi(ra,dec)
		p = hp.ang2pix(res,th,phi,nest=True)
		gl[p] += w
		ngt += w
	print len(gl),ngt
	return gl
Ejemplo n.º 3
0
def mkgalmapY3ac(res, zr, gz='.gz', md='', fore='', wm='', syscut=''):
    gl = []
    for i in range(0, 12 * res * res):
        gl.append(0)
    #f = fitsio.read(dir+'dr1_lss_red_'+zr+'_v0_redux.fits.gz',ext=1)
    f = fitsio.read(dir + 'test' + zr + mask + '.fits' + gz, ext=1)
    ngt = 0
    w = 1.
    zem = 0
    fw = ''
    if fore == 'fore':
        fw = '_fore'
    #if fore == 'auto':
    #	fw = '_auto'
    if md == 'nodepth':
        md = '_none'
    #else:
    #	md = '_'+md
    for i in range(0, len(f)):
        ra, dec = f[i]['RA'], f[i]['DEC']

        #if f[i]['v0'+md+fw] == 1.:

        #if wm != '':
        #	w = float(ln[4])
        #if z > zmin and z < zmax:
        th, phi = radec2thphi(ra, dec)
        p = hp.ang2pix(res, th, phi, nest=True)
        gl[p] += w
        ngt += w
    print len(gl), ngt
    return gl
Ejemplo n.º 4
0
def compY1Y3():
	f1 = fitsio.read('/Users/ashleyross/Dropbox/DESY3/Y1mag22.fits')
	fs_1 = fitsio.read('/Users/ashleyross/Dropbox/DESY3/Y3red_1.fits')
	fs_2 = fitsio.read('/Users/ashleyross/Dropbox/DESY3/Y3red_2.fits')
	maskf = open('/Users/ashleyross/DESY1/mask_Y1redBAO_mean_z_bpz_VFF_4096ring.dat')
	npix = 12*4096*4096
	mask = []
	pixl1 = np.zeros(f1.size)
	pixl3_1 = np.zeros(fs_1.size)
	pixl3_2 = np.zeros(fs_2.size)
	for i in range(0,npix):
		mask.append(0)
	for line in maskf:
		pix = int(float(line.split()[0]))
		mask[pix] = 1
	print 'mask done'	
	ng = 0
	ng3 = 0
	for i in range(0,f1.size):
		ra,dec = f1[i]['RA'],f1[i]['DEC']
		th,phi = radec2thphi(ra,dec)
		p = hp.ang2pix(4096,th,phi)
		if mask[int(p)] == 1:
			pixl1[i] = 1
	print 'f1 done'
	for i in range(0,fs_1.size):
		ra,dec = fs_1[i]['RA'],fs_1[i]['DEC']
		th,phi = radec2thphi(ra,dec)
		p = hp.ang2pix(4096,th,phi)
		if mask[int(p)] == 1:
			pixl3_1[i] = 1
	print 'f3_1 done'		
	for i in range(0,fs_2.size):
		ra,dec = fs_2[i]['RA'],fs_2[i]['DEC']
		th,phi = radec2thphi(ra,dec)
		p = hp.ang2pix(4096,th,phi)
		if mask[int(p)] == 1:
			pixl3_2[i] = 1
	print 'f3_2 done'		
	w1 = (pixl1 == 1) & (f1['MAG_AUTO_I']-f1['MAG_AUTO_Z'] +2.*(f1['MAG_AUTO_R']-f1['MAG_AUTO_I'])>1.7) & (f1['MAG_AUTO_I'] >17.5)
	f1m = f1[w1]
	w3_1 = (pixl3_1 == 1)
	f3_1m = fs_1[w3_1]
	w3_2 = (pixl3_2 == 1)
	f3_2m = fs_2[w3_2]
	print f1m.size, f3_1m.size+f3_2m.size 
Ejemplo n.º 5
0
def ngvext(file, mask, res=256, mc=.8, extmax=.15, nbin=10):
    extmap = np.loadtxt('maps/healSFD_r_256_fullsky.dat')
    extc = 2.751
    h = healpix()
    ml = zeros((4096 * 4096 * 12))
    mask = fitsio.read(dir + mask + '.fits.gz')
    for i in range(0, len(mask)):
        ml[mask[i]['PIXEL']] = mask[i]['SIGNAL']
    data = fitsio.read(dir + file + '.fits.gz')
    ngl = np.zeros((12. * res * res))
    ngt = 0
    for i in range(0, len(data)):
        if data[i]['HPIX_4096'] > mc:
            th, phi = radec2thphi(data[i]['RA'], data[i]['DEC'])
            pix = h.ang2pix_nest(res, th, phi)
            ngl[pix] += 1.
            ngt += 1.
    print ngt, len(data)
    mlr = zeros((12. * res * res))
    for i in range(0, len(mask)):
        if mask[i]['SIGNAL'] > mc:
            th, phi = h.pix2ang_nest(4096, mask[i]['PIXEL'])
            pix = h.ang2pix_nest(res, th, phi)
            mlr[pix] += (res / 4096.)**2.
    ave = sum(ngl) / sum(mlr)
    print ave
    bing = zeros((nbin))
    binr = zeros((nbin))

    for i in range(0, 12 * res * res):
        extv = extmap[i] / extc
        if extv < extmax:
            bin = int(extv / extmax * nbin)
            bing[bin] += ngl[i]
            binr[bin] += mlr[i]
    print bing, binr, bing / (binr * ave)
    fo = open(dir + file + 'vsext.dat', 'w')
    for i in range(0, nbin):
        extv = i * extmax / float(nbin) + extmax / float(2. * nbin)
        fo.write(
            str(extv) + ' ' + str(bing[i] / (binr[i] * ave)) + ' ' +
            str(sqrt(bing[i]) / (binr[i] * ave)) + '\n')
    fo.close()
    return True
Ejemplo n.º 6
0
def ngvext(file,mask,res=256,mc=.8,extmax=.15,nbin=10):
	extmap = np.loadtxt('maps/healSFD_r_256_fullsky.dat')
	extc = 2.751
	h = healpix()
	ml = zeros((4096*4096*12))
	mask = fitsio.read(dir+mask+'.fits.gz')
	for i in range(0,len(mask)):
		ml[mask[i]['PIXEL']] = mask[i]['SIGNAL']
	data = fitsio.read(dir+file+'.fits.gz')
	ngl = np.zeros((12.*res*res))
	ngt = 0
	for i in range(0,len(data)):
		if data[i]['HPIX_4096'] > mc:
			th,phi = radec2thphi(data[i]['RA'],data[i]['DEC'])
			pix = h.ang2pix_nest(res,th,phi)
			ngl[pix] += 1.
			ngt += 1.
	print ngt, len(data)
	mlr = zeros((12.*res*res))
	for i in range(0,len(mask)):
		if 	mask[i]['SIGNAL'] > mc:
			th,phi = h.pix2ang_nest(4096,mask[i]['PIXEL'])
			pix = h.ang2pix_nest(res,th,phi)
			mlr[pix] += (res/4096.)**2.
	ave = sum(ngl)/sum(mlr)
	print ave
	bing = zeros((nbin))
	binr = zeros((nbin))
	
	for i in range(0,12*res*res):
		extv = extmap[i]/extc
		if extv < extmax:
			bin = int(extv/extmax*nbin) 		
			bing[bin] += ngl[i]
			binr[bin] += mlr[i]		
	print bing, binr,bing/(binr*ave)
	fo = open(dir+file+'vsext.dat','w')
	for i in range(0,nbin):
		extv = i*extmax/float(nbin)+extmax/float(2.*nbin)
		fo.write(str(extv)+' '+str(bing[i]/(binr[i]*ave))+' '+str(sqrt(bing[i])/(binr[i]*ave))+'\n')
	fo.close()
	return True
			
Ejemplo n.º 7
0
def plotMaghist2obs(band,ndraw = 1e5,nbin=100):
	#This randomly takes two ccd observations and find the coadded depth base on 1/noise^2tot = 1/(1/noise1^2+1/noise2^2)
	import fitsio
	from matplotlib import pyplot as plt
	from numpy import zeros,array
	from random import random
	readnoise = 10. # e-; 7.0 to 15.0 according to DECam Data Handbook
	p = 1.15 #value given in imaging requirements
	gain = 4.0 #from Dustin
	f = fitsio.read(dir+'/legacypipe-dir/decals-ccds.fits.gz')
	nr = len(f)
	NTl = []
	emin = 1000
	emax = 0
	msee = 0
	n = 0
	arcsec2pix = 1./.262 #from Dustin
	if band == 'g':
		zp0 = 25.08
		recm = 24.
		cor = 0.08
		extc = 3.303/2.751
	if band == 'r':
		zp0 = 25.29
		recm = 23.4
		cor = .16
		extc = 2.285/2.751
	if band == 'z':
		zp0 = 24.92
		recm = 22.5
		extc = 1.263/2.751
		cor = .29
	nd = 0
	nbr = 0	
	#for i in range(0,len(f)):
	while nd < ndraw:
		i = int(random()*nr)
		j = int(random()*nr)
		#j = i #this is used to test result when conditions are exactly the same on each ccd
		pid2 = f[j]['propid']
		pid = f[i]['propid']
		DS = 0
		DS2 = 0
		year = int(f[i]['date_obs'].split('-')[0])
		if year > 2014:
			if pid == '2014B-0404' or pid == '2013A-0741':
				DS = 1 #enforce 2015 data
		year2 = int(f[j]['date_obs'].split('-')[0])
		if year2 > 2014:
			if pid2 == '2014B-0404' or pid2 == '2013A-0741':
				DS2 = 1 #enforce 2015 data

		if f[i]['filter'] == band and f[j]['filter'] == band and DS == 1 and DS2 == 1:
			if f[i]['seeing'] != 99 and f[i]['ccdzpt'] != 99 and f[i]['fwhm'] != 99:
				if f[j]['seeing'] != 99 and f[j]['ccdzpt'] != 99 and f[j]['fwhm'] != 99:
					if f[j]['dec'] > -20 and f[j]['exptime'] >=30 and f[j]['ccdnmatch'] >= 20 and abs(f[j]['zpt'] - f[j]['ccdzpt']) <= 0.1 and f[j]['zpt'] >= zp0-.5 and f[j]['zpt'] <=zp0+.25:   
						if f[i]['dec'] > -20 and f[i]['exptime'] >=30 and f[i]['ccdnmatch'] >= 20 and abs(f[i]['zpt'] - f[i]['ccdzpt']) <= 0.1 and f[i]['zpt'] >= zp0-.5 and f[i]['zpt'] <=zp0+.25:   
							nd += 1
							ra,dec = f[i]['ra'],f[i]['dec']
							th,phi = radec2thphi(ra,dec)
							pix = hpix.ang2pix_nest(256,th,phi)
							ext = extmap[pix]*extc
							ra2,dec2 = f[j]['ra'],f[j]['dec']
							th,phi = radec2thphi(ra2,dec2)
							pix2 = hpix.ang2pix_nest(256,th,phi)
							ext2 = extmap[pix2]*extc

							avsky = f[i]['avsky']
							skysig = sqrt(avsky * gain + readnoise**2) / gain
							zpscale = zeropointToScale(f[i]['ccdzpt'] + 2.5*log(f[i]['exptime'],10.))
							skysig /= zpscale
							psf_sigma = f[i]['fwhm'] / 2.35
							avsky2 = f[j]['avsky']
							skysig2 = sqrt(avsky2 * gain + readnoise**2) / gain
							zpscale2 = zeropointToScale(f[j]['ccdzpt'] + 2.5*log(f[j]['exptime'],10.))
							skysig2 /= zpscale2
							psf_sigma2 = f[j]['fwhm'] / 2.35
							# point-source depth
							#psfnorm = 1./(2. * sqrt(pi) * psf_sigma) #1/Neff #for point source
							#detsig1 = skysig / psfnorm
							Np = ((4.*pi*psf_sigma**2.)**(1./p) + (8.91*(.45*arcsec2pix)**2. )**(1./p))**p #Neff in requirements doc
							Np2 = ((4.*pi*psf_sigma2**2.)**(1./p) + (8.91*(.45*arcsec2pix)**2. )**(1./p))**p #Neff in requirements doc
							Np = sqrt(Np) #square root necessary because Np gives sum of noise squared
							Np2 = sqrt(Np2)
							signalext = 1./10.**(-ext/2.5)
							signalext2 = 1./10.**(-ext2/2.5)
							detsig1 = skysig*Np #total noise
							detsig2 = skysig2*Np2
							detsigtot = sqrt(1./(1./(detsig1*signalext)**2.+1./(detsig2*signalext2)**2))
							m = nanomaggiesToMag(detsigtot * 5.)-cor#-(ext+ext2)/2.
							if m > 30 or m < 18:
								print skysig,avsky,f[i]['fwhm'],f[i]['ccdzpt'],f[i]['exptime']
							NTl.append(m)
							if f[i]['exptime'] > emax:
								emax = f[i]['exptime']
							if 	f[i]['exptime'] < emin:
								emin = f[i]['exptime']
							n += 1.
							msee += f[i]['seeing']	
							if m > recm:
								nbr += 1.
	msee = msee/n
	print msee,n
	print emin,emax
	minN = min(NTl)
	maxN = max(NTl)+.0001
	print minN,maxN
	hl = zeros((nbin))
	for i in range(0,len(NTl)):
		bin = int(nbin*(NTl[i]-minN)/(maxN-minN))
		hl[bin] += 1
	Nl = []
	for i in range(0,len(hl)):
		Nl.append(minN+i*(maxN-minN)/float(nbin)+0.5*(maxN-minN)/float(nbin))
	NTl = array(NTl)
	mean = sum(NTl)/float(len(NTl))
	std = sqrt(sum(NTl**2.)/float(len(NTl))-mean**2.)
	NTl.sort()
	if len(NTl)/2. != len(NTl)/2:
		med = NTl[len(NTl)/2+1]
	else:
		med = (NTl[len(NTl)/2+1]+NTl[len(NTl)/2])/2.
	print mean,med,std
	print 'percentage better than requirements '+str(nbr/float(nd))

	from matplotlib.backends.backend_pdf import PdfPages
	plt.clf()
	pp = PdfPages(localdir+'validationplots/DR2DECaLS'+band+'2exposures.pdf')	

	plt.plot(Nl,hl,'k-')
	plt.xlabel(r'5$\sigma$ '+band+ ' depth')
	plt.ylabel('# of ccds')
	plt.title('MC 2 exposure depth '+str(mean)[:5]+r'$\pm$'+str(std)[:4]+r', $f_{\rm pass}=$'+str(nbr/float(nd))[:5])
	#plt.xscale('log')
	pp.savefig()
	pp.close()
	return True
Ejemplo n.º 8
0
def plotMagMap(band,size=4):
	import fitsio
	from matplotlib import pyplot as plt
	import matplotlib.cm as cm
	from numpy import zeros,array
	readnoise = 10. # e-; 7.0 to 15.0 according to DECam Data Handbook
	p = 1.15 #value given in imaging requirements
	gain = 4.0 #from Dustin
	f = fitsio.read(dir+'/legacypipe-dir/decals-ccds.fits.gz')
	NTl = []
	emin = 1000
	emax = 0
	msee = 0
	n = 0
	arcsec2pix = 1./.262 #from Dustin

	if band == 'g':
		zp0 = 25.08
		recm = 24.
		cor = 0.08
		extc = 3.303/2.751
	if band == 'r':
		zp0 = 25.29
		recm = 23.4
		cor = .16
		extc = 2.285/2.751
	if band == 'z':
		zp0 = 24.92
		recm = 22.5
		extc = 1.263/2.751
		cor = .29
	nd = 0
	nbr = 0	
	ral = []
	decl = []
	for i in range(0,len(f)):
		pid = f[i]['propid']
		#if DS == '2014B-0404' or DS == '2013A-0741': #enforce DECaLS only
		#	DS = 1
		DS = 0
		year = int(f[i]['date_obs'].split('-')[0])
		if year > 2014:
			if pid == '2014B-0404' or pid == '2013A-0741':
				DS = 1 #enforce 2015 data
		if f[i]['filter'] == band:
			if f[i]['seeing'] != 99 and f[i]['ccdzpt'] != 99 and f[i]['fwhm'] != 99 and DS == 1:
				if f[i]['dec'] > -20 and f[i]['exptime'] >=30 and f[i]['ccdnmatch'] >= 20 and abs(f[i]['zpt'] - f[i]['ccdzpt']) <= 0.1 and f[i]['zpt'] >= zp0-.5 and f[i]['zpt'] <=zp0+.25:   
					ra,dec = f[i]['ra'],f[i]['dec']
					th,phi = radec2thphi(ra,dec)
					pix = hpix.ang2pix_nest(256,th,phi)
					ext = extmap[pix]*extc
					#if ext > 0.5:
					#	print ext,extc,ra,dec,pix
						#break
					avsky = f[i]['avsky']
					skysig = sqrt(avsky * gain + readnoise**2) / gain
					zpscale = zeropointToScale(f[i]['ccdzpt'] + 2.5*log(f[i]['exptime'],10.))
					skysig /= zpscale
					psf_sigma = f[i]['fwhm'] / 2.35
					# point-source depth
					#psfnorm = 1./(2. * sqrt(pi) * psf_sigma) #1/Neff #for point source
					#detsig1 = skysig / psfnorm
					Np = ((4.*pi*psf_sigma**2.)**(1./p) + (8.91*(.45*arcsec2pix)**2. )**(1./p))**p #Neff in requirements doc
					Np = sqrt(Np) #square root necessary because Np gives sum of noise squared
					detsig1 = skysig*Np #total noise
					m = nanomaggiesToMag(detsig1 * 5.)-cor-ext
					#if m > 30 or m < 18:
					#	print skysig,avsky,f[i]['fwhm'],f[i]['ccdzpt'],f[i]['exptime']
					NTl.append(m)
					ral.append(ra)
					decl.append(dec)
					if f[i]['exptime'] > emax:
						emax = f[i]['exptime']
					if 	f[i]['exptime'] < emin:
						emin = f[i]['exptime']
					n += 1.
					msee += f[i]['seeing']	
					if m > recm:
						nbr += 1.

	from matplotlib.backends.backend_pdf import PdfPages
	plt.clf()
	pp = PdfPages(localdir+'validationplots/DR2DECaLS'+band+'map.pdf')	

	#col = (NTl-min(NTl))/(max(NTl)-min(NTl))
	col = NTl
	map = plt.scatter(ral,decl,c=col,s=size,cmap=cm.rainbow,lw=0)
	cbar = plt.colorbar(map)
	cbar.set_label('depth', rotation=270)
	plt.xlabel('r.a. (degrees)')
	plt.ylabel('declination (degrees)')
	plt.title('Map of 1 exposure depth for DR2 '+band+'-band')
	#plt.show()
	#plt.xscale('log')
	pp.savefig()
	pp.close()
	return True
Ejemplo n.º 9
0
def plotMaghist(band,nbin=100):
	import fitsio
	from matplotlib import pyplot as plt
	from numpy import zeros,array
	readnoise = 10. # e-; 7.0 to 15.0 according to DECam Data Handbook
	p = 1.15 #value given in imaging requirements
	gain = 4.0 #from Dustin
	f = fitsio.read(dir+'/legacypipe-dir/decals-ccds.fits.gz')
	NTl = []
	emin = 1000
	emax = 0
	msee = 0
	n = 0
	arcsec2pix = 1./.262 #from Dustin

	if band == 'g':
		zp0 = 25.08
		recm = 24.
		cor = 0.07
		extc = 3.303/2.751
	if band == 'r':
		zp0 = 25.29
		recm = 23.4
		cor = .12
		extc = 2.285/2.751
	if band == 'z':
		zp0 = 24.92
		recm = 22.5
		extc = 1.263/2.751
		cor = .18
	nd = 0
	nbr = 0	
	for i in range(0,len(f)):
		pid = f[i]['propid']
		#if DS == '2014B-0404' or DS == '2013A-0741': #enforce DECaLS only
		#	DS = 1
		DS = 0
		year = int(f[i]['date_obs'].split('-')[0])
		if year > 2014:
			if pid == '2014B-0404' or pid == '2013A-0741':
				DS = 1 #enforce 2015 data
		if f[i]['filter'] == band:
			if f[i]['seeing'] != 99 and f[i]['ccdzpt'] != 99 and f[i]['fwhm'] != 99 and DS == 1:
				if f[i]['dec'] > -20 and f[i]['exptime'] >=30 and f[i]['ccdnmatch'] >= 20 and abs(f[i]['zpt'] - f[i]['ccdzpt']) <= 0.1 and f[i]['zpt'] >= zp0-.5 and f[i]['zpt'] <=zp0+.25:   
					ra,dec = f[i]['ra'],f[i]['dec']
					th,phi = radec2thphi(ra,dec)
					pix = hpix.ang2pix_nest(256,th,phi)
					ext = extmap[pix]*extc
					#if ext > 0.5:
					#	print ext,extc,ra,dec,pix
						#break
					avsky = f[i]['avsky']
					skysig = sqrt(avsky * gain + readnoise**2) / gain
					zpscale = zeropointToScale(f[i]['ccdzpt'] + 2.5*log(f[i]['exptime'],10.))
					skysig /= zpscale
					psf_sigma = f[i]['fwhm'] / 2.35
					# point-source depth
					#psfnorm = 1./(2. * sqrt(pi) * psf_sigma) #1/Neff #for point source
					#detsig1 = skysig / psfnorm
					Np = ((4.*pi*psf_sigma**2.)**(1./p) + (8.91*(.45*arcsec2pix)**2. )**(1./p))**p #Neff in requirements doc
					Np = sqrt(Np) #square root necessary because Np gives sum of noise squared
					detsig1 = skysig*Np #total noise
					signalext = 1./10.**(-ext/2.5)
					#signalext = 1.
					m = nanomaggiesToMag(detsig1 * 5.*signalext)-cor#-ext
					#if m > 30 or m < 18:
					#	print skysig,avsky,f[i]['fwhm'],f[i]['ccdzpt'],f[i]['exptime']
					NTl.append(m)
					if f[i]['exptime'] > emax:
						emax = f[i]['exptime']
					if 	f[i]['exptime'] < emin:
						emin = f[i]['exptime']
					n += 1.
					msee += f[i]['seeing']	
					if m > recm:
						nbr += 1.
	msee = msee/n
	print msee,n
	print emin,emax
	minN = min(NTl)
	maxN = max(NTl)+.0001
	print minN,maxN
	hl = zeros((nbin))
	for i in range(0,len(NTl)):
		bin = int(nbin*(NTl[i]-minN)/(maxN-minN))
		hl[bin] += 1
	Nl = []
	for i in range(0,len(hl)):
		Nl.append(minN+i*(maxN-minN)/float(nbin)+0.5*(maxN-minN)/float(nbin))
	NTl = array(NTl)
	mean = sum(NTl)/float(len(NTl))
	std = sqrt(sum(NTl**2.)/float(len(NTl))-mean**2.)
	NTl.sort()
	if len(NTl)/2. != len(NTl)/2:
		med = NTl[len(NTl)/2+1]
	else:
		med = (NTl[len(NTl)/2+1]+NTl[len(NTl)/2])/2.
	print mean,med,std
	print 'percentage better than requirements '+str(nbr/n)

	from matplotlib.backends.backend_pdf import PdfPages
	plt.clf()
	pp = PdfPages(localdir+'validationplots/DR2DECaLS'+band+'1exposure.pdf')	

	plt.plot(Nl,hl,'k-')
	plt.xlabel(r'5$\sigma$ '+band+ ' depth')
	plt.ylabel('# of ccds')
	plt.title('1 exposure depth '+str(mean)[:5]+r'$\pm$'+str(std)[:4]+r', $f_{\rm pass}=$'+str(nbr/float(n))[:5])
	#plt.xscale('log')
	pp.savefig()
	pp.close()
	return True
Ejemplo n.º 10
0
def plotMaghist_survey(band,ndraw = 1e5,nbin=100,magmin=0):
	#This takes random selections of 1,2,3,4 and 5 exposures in a fraction matching the expected coverage
	import fitsio
	from matplotlib import pyplot as plt
	from numpy import zeros,array
	from random import random
	Ftiles =  [0.02,0.26,0.76,0.98] #cumulative fraction of area
	readnoise = 10. # e-; 7.0 to 15.0 according to DECam Data Handbook
	p = 1.15 #value given in imaging requirements
	gain = 4.0 #from Dustin
	f = fitsio.read(dir+'/legacypipe-dir/decals-ccds.fits.gz')
	nr = len(f)
	NTl = []
	emin = 1000
	emax = 0
	msee = 0
	n = 0
	arcsec2pix = 1./.262 #from Dustin
	if band == 'g':
		zp0 = 25.08
		recm = 24.
		cor = 0.08
		extc = 3.303/2.751
	if band == 'r':
		zp0 = 25.29
		recm = 23.4
		cor = .16
		extc = 2.285/2.751
	if band == 'z':
		zp0 = 24.92
		recm = 22.5
		extc = 1.263/2.751
		cor = .29
	nd = 0	
	#for i in range(0,len(f)):
	nbr = 0
	nl = [] #to speed things up, first make list of noise, then do draws
	extl = [] #same for extinction
	for i in range(0,len(f)):
		pid = f[i]['propid']
		#if DS == '2014B-0404' or DS == '2013A-0741': #enforce DECaLS only
		#	DS = 1
		DS = 0
		year = int(f[i]['date_obs'].split('-')[0])
		if year > 2014:
			if pid == '2014B-0404' or pid == '2013A-0741':
				DS = 1 #enforce 2015 data
		if f[i]['filter'] == band:
			if f[i]['seeing'] != 99 and f[i]['ccdzpt'] != 99 and f[i]['fwhm'] != 99 and DS == 1:
				if f[i]['dec'] > -20 and f[i]['exptime'] >=30 and f[i]['ccdnmatch'] >= 20 and abs(f[i]['zpt'] - f[i]['ccdzpt']) <= 0.1 and f[i]['zpt'] >= zp0-.5 and f[i]['zpt'] <=zp0+.25:   
					ra,dec = f[i]['ra'],f[i]['dec']
					th,phi = radec2thphi(ra,dec)
					pix = hpix.ang2pix_nest(256,th,phi)
					ext = extmap[pix]*extc
					extl.append(ext)
					avsky = f[i]['avsky']
					skysig = sqrt(avsky * gain + readnoise**2) / gain
					zpscale = zeropointToScale(f[i]['ccdzpt'] + 2.5*log(f[i]['exptime'],10.))
					skysig /= zpscale
					psf_sigma = f[i]['fwhm'] / 2.35
					# point-source depth
					#psfnorm = 1./(2. * sqrt(pi) * psf_sigma) #1/Neff #for point source
					#detsig1 = skysig / psfnorm
					Np = ((4.*pi*psf_sigma**2.)**(1./p) + (8.91*(.45*arcsec2pix)**2. )**(1./p))**p #Neff in requirements doc
					Np = sqrt(Np) #square root necessary because Np gives sum of noise squared
					detsig1 = skysig*Np #total noise
					signalext = 1./10.**(-ext/2.5)
					m = nanomaggiesToMag(detsig1 * 5.)-cor-ext
					if m > magmin:
						nl.append(detsig1*signalext)
	ng = len(nl)
	print ng
	nbr3 = 0
	nbr6 = 0
	for nd in range(0,int(ndraw)):
		ran = random()
		if ran < Ftiles[0]:
			nexp = 1
		if ran > Ftiles[0] and ran < Ftiles[1]:
			nexp = 2
		if ran > Ftiles[1] and ran < Ftiles[2]:
			nexp = 3
		if ran > Ftiles[2] and ran < Ftiles[3]:
			nexp = 4
		if ran > Ftiles[3]:
			nexp = 5	
		detsigtoti = 0
		extsum = 0
		for j in range(0,nexp):
			k = int(random()*ng)
			detsigtoti += 1./nl[k]**2.
			extsum += extl[k]
		extcorr = extsum/float(nexp)
		detsigtot = sqrt(1./detsigtoti)	
		m = nanomaggiesToMag(detsigtot * 5.)-cor#-extcorr
		if m > recm:
			nbr += 1.	
		if m > recm-.3:
			nbr3 += 1.
		if m > recm-.6:
			nbr6 += 1.	
		NTl.append(m)
		n += 1.
	minN = min(NTl)
	maxN = max(NTl)+.0001
	print minN,maxN
	hl = zeros((nbin))
	for i in range(0,len(NTl)):
		bin = int(nbin*(NTl[i]-minN)/(maxN-minN))
		hl[bin] += 1
	Nl = []
	for i in range(0,len(hl)):
		Nl.append(minN+i*(maxN-minN)/float(nbin)+0.5*(maxN-minN)/float(nbin))
	NTl = array(NTl)
	mean = sum(NTl)/float(len(NTl))
	std = sqrt(sum(NTl**2.)/float(len(NTl))-mean**2.)
	nc = 0
	for i in range(0,len(hl)):
		nc += hl[i]
		if nc > .1*nd:
			m9 = Nl[i]
			break
	NTl.sort()
	if len(NTl)/2. != len(NTl)/2:
		med = NTl[len(NTl)/2+1]
	else:
		med = (NTl[len(NTl)/2+1]+NTl[len(NTl)/2])/2.
	print mean,med,std
	print 'percentage better than requirements '+str(nbr/float(nd))
	from matplotlib.backends.backend_pdf import PdfPages
	plt.clf()
	pp = PdfPages(localdir+'validationplots/DR2DECaLS'+band+'_simsurvey.pdf')	
	fig = plt.figure()
	ax = fig.add_subplot(111)
	ax.plot(Nl,hl,'k-')
	ax.set_xlabel(r'5$\sigma$ '+band+ ' depth')
	ax.set_ylabel('# of ccds')
	ax.set_title('MC survey depth '+str(mean)[:5]+r'$\pm$'+str(std)[:4]+r', $f_{r}=$'+str(nbr/float(nd))[:5]+r', $f_{r-0.3}=$'+str(nbr3/float(nd))[:5]+r', $f_{r-0.6}=$'+str(nbr6/float(nd))[:5])
	ax.text(.4,.9,r'90% depth '+str(m9)[:5], verticalalignment='bottom', horizontalalignment='right', transform=ax.transAxes,fontsize=15)
	#plt.xscale('log')
	pp.savefig()
	pp.close()
	return True
Ejemplo n.º 11
0
def compSOFMA():
	fma = fitsio.read('/Users/ashleyross/Dropbox/DESY3/allgal22magauto_1.fits')
	fs = fitsio.read('/Users/ashleyross/Dropbox/DESY3/allgal22_1.fits')
	f1 = fitsio.read('/Users/ashleyross/Dropbox/DESY3/Y1mag22.fits')
	facs = 5.3
	facm = 6.
	fac1 = 3.
	print np.mean(fma['SOF_CM_MAG_CORRECTED_I']),np.mean(fma['MAG_AUTO_I']-1.569*fma['EBV_SFD98'])
	print fma.size*facm,fs.size*facs,f1.size*fac1,f1.size
	wa = (fma['SOF_CM_MAG_CORRECTED_I']-fma['SOF_CM_MAG_CORRECTED_Z'] +2.*(fma['SOF_CM_MAG_CORRECTED_R']-fma['SOF_CM_MAG_CORRECTED_I'])>1.7) & (fma['SOF_CM_MAG_CORRECTED_I']>17.5)
	ws =  (fs['SOF_CM_MAG_CORRECTED_I']-fs['SOF_CM_MAG_CORRECTED_Z'] +2.*(fs['SOF_CM_MAG_CORRECTED_R']-fs['SOF_CM_MAG_CORRECTED_I'])>1.7) & (fs['SOF_CM_MAG_CORRECTED_I']>17.5)
	w1 = (f1['MAG_AUTO_I']-f1['MAG_AUTO_Z'] +2.*(f1['MAG_AUTO_R']-f1['MAG_AUTO_I'])>1.7) & (f1['MAG_AUTO_I'] >17.5)
	print fma[wa].size*6.,fs[ws].size*facs,f1[w1].size*fac1,f1[w1].size
	wa = (fma['SOF_CM_MAG_CORRECTED_I']-fma['SOF_CM_MAG_CORRECTED_Z'] +2.*(fma['SOF_CM_MAG_CORRECTED_R']-fma['SOF_CM_MAG_CORRECTED_I'])>1.7) & (fma['SOF_CM_MAG_CORRECTED_I']>17.5)\
	& ((fma['SOF_CM_MAG_CORRECTED_G'] - fma['SOF_CM_MAG_CORRECTED_R'])>-1.) & ((fma['SOF_CM_MAG_CORRECTED_G'] - fma['SOF_CM_MAG_CORRECTED_R'])<3.)
	ws =  (fs['SOF_CM_MAG_CORRECTED_I']-fs['SOF_CM_MAG_CORRECTED_Z'] +2.*(fs['SOF_CM_MAG_CORRECTED_R']-fs['SOF_CM_MAG_CORRECTED_I'])>1.7) & (fs['SOF_CM_MAG_CORRECTED_I']>17.5)\
	& ((fs['SOF_CM_MAG_CORRECTED_G'] - fs['SOF_CM_MAG_CORRECTED_R'])>-1.) & ((fs['SOF_CM_MAG_CORRECTED_G'] - fs['SOF_CM_MAG_CORRECTED_R'])<3.)

	w1 = (f1['MAG_AUTO_I']-f1['MAG_AUTO_Z'] +2.*(f1['MAG_AUTO_R']-f1['MAG_AUTO_I'])>1.7) & (f1['MAG_AUTO_I'] >17.5)\
	& ((f1['MAG_AUTO_G'] - f1['MAG_AUTO_R'])>-1.) & ((f1['MAG_AUTO_G'] - f1['MAG_AUTO_R'])<3.)

	print fma[wa].size*6.,fs[ws].size*facs,f1[w1].size*fac1,f1[w1].size

	wa = (fma['SOF_CM_MAG_CORRECTED_I']-fma['SOF_CM_MAG_CORRECTED_Z'] +2.*(fma['SOF_CM_MAG_CORRECTED_R']-fma['SOF_CM_MAG_CORRECTED_I'])>1.7) & (fma['SOF_CM_MAG_CORRECTED_I']>17.5)\
	& ((fma['SOF_CM_MAG_CORRECTED_G'] - fma['SOF_CM_MAG_CORRECTED_R'])>-1.) & ((fma['SOF_CM_MAG_CORRECTED_G'] - fma['SOF_CM_MAG_CORRECTED_R'])<3.)\
	& ((fma['SOF_CM_MAG_CORRECTED_R'] - fma['SOF_CM_MAG_CORRECTED_I'])>-1.) & ((fma['SOF_CM_MAG_CORRECTED_R'] - fma['SOF_CM_MAG_CORRECTED_I'])<2.5)

	ws =  (fs['SOF_CM_MAG_CORRECTED_I']-fs['SOF_CM_MAG_CORRECTED_Z'] +2.*(fs['SOF_CM_MAG_CORRECTED_R']-fs['SOF_CM_MAG_CORRECTED_I'])>1.7) & (fs['SOF_CM_MAG_CORRECTED_I']>17.5)\
	& ((fs['SOF_CM_MAG_CORRECTED_G'] - fs['SOF_CM_MAG_CORRECTED_R'])>-1.) & ((fs['SOF_CM_MAG_CORRECTED_G'] - fs['SOF_CM_MAG_CORRECTED_R'])<3.)\
	& ((fs['SOF_CM_MAG_CORRECTED_R'] - fs['SOF_CM_MAG_CORRECTED_I'])>-1.) & ((fs['SOF_CM_MAG_CORRECTED_R'] - fs['SOF_CM_MAG_CORRECTED_I'])<2.5)

	w1 = (f1['MAG_AUTO_I']-f1['MAG_AUTO_Z'] +2.*(f1['MAG_AUTO_R']-f1['MAG_AUTO_I'])>1.7) & (f1['MAG_AUTO_I'] >17.5)\
	& ((f1['MAG_AUTO_G'] - f1['MAG_AUTO_R'])>-1.) & ((f1['MAG_AUTO_G'] - f1['MAG_AUTO_R'])<3.)\
	& ((f1['MAG_AUTO_R'] - f1['MAG_AUTO_I'])>-1.) & ((f1['MAG_AUTO_R'] - f1['MAG_AUTO_I'])<2.5)
	print fma[wa].size*6.,fs[ws].size*facs,f1[w1].size*fac1,f1[w1].size

	wa = (fma['SOF_CM_MAG_CORRECTED_I']-fma['SOF_CM_MAG_CORRECTED_Z'] +2.*(fma['SOF_CM_MAG_CORRECTED_R']-fma['SOF_CM_MAG_CORRECTED_I'])>1.7) & (fma['SOF_CM_MAG_CORRECTED_I']>17.5)\
	& ((fma['SOF_CM_MAG_CORRECTED_G'] - fma['SOF_CM_MAG_CORRECTED_R'])>-1.) & ((fma['SOF_CM_MAG_CORRECTED_G'] - fma['SOF_CM_MAG_CORRECTED_R'])<3.)\
	& ((fma['SOF_CM_MAG_CORRECTED_R'] - fma['SOF_CM_MAG_CORRECTED_I'])>-1.) & ((fma['SOF_CM_MAG_CORRECTED_R'] - fma['SOF_CM_MAG_CORRECTED_I'])<2.5)\
	& ((fma['SOF_CM_MAG_CORRECTED_I'] - fma['SOF_CM_MAG_CORRECTED_Z'])>-1.) & ((fma['SOF_CM_MAG_CORRECTED_I'] - fma['SOF_CM_MAG_CORRECTED_Z'])<2.)
	
	ws =  (fs['SOF_CM_MAG_CORRECTED_I']-fs['SOF_CM_MAG_CORRECTED_Z'] +2.*(fs['SOF_CM_MAG_CORRECTED_R']-fs['SOF_CM_MAG_CORRECTED_I'])>1.7) & (fs['SOF_CM_MAG_CORRECTED_I']>17.5)\
	& ((fs['SOF_CM_MAG_CORRECTED_G'] - fs['SOF_CM_MAG_CORRECTED_R'])>-1.) & ((fs['SOF_CM_MAG_CORRECTED_G'] - fs['SOF_CM_MAG_CORRECTED_R'])<3.)\
	& ((fs['SOF_CM_MAG_CORRECTED_R'] - fs['SOF_CM_MAG_CORRECTED_I'])>-1.) & ((fs['SOF_CM_MAG_CORRECTED_R'] - fs['SOF_CM_MAG_CORRECTED_I'])<2.5)\
	& ((fs['SOF_CM_MAG_CORRECTED_I'] - fs['SOF_CM_MAG_CORRECTED_Z'])>-1.) & ((fs['SOF_CM_MAG_CORRECTED_I'] - fs['SOF_CM_MAG_CORRECTED_Z'])<2.)

	f1 = fitsio.read('/Users/ashleyross/Dropbox/DESY3/Y1mag22_chbpz.fits')

	w1 = (f1['mag_auto_i']-f1['mag_auto_z'] +2.*(f1['mag_auto_r']-f1['mag_auto_i'])>1.7) & (f1['mag_auto_i'] >17.5)\
	& ((f1['mag_auto_g'] - f1['mag_auto_r'])>-1.) & ((f1['mag_auto_g'] - f1['mag_auto_r'])<3.)\
	& ((f1['mag_auto_r'] - f1['mag_auto_i'])>-1.) & ((f1['mag_auto_r'] - f1['mag_auto_i'])<2.5)\
	& ((f1['mag_auto_i'] - f1['mag_auto_z'])>-1.) & ((f1['mag_auto_i'] - f1['mag_auto_z'])<2.)
	print fma[wa].size*6.,fs[ws].size*facs,f1[w1].size*fac1,f1[w1].size
	fmaw = fma[wa]
	fsw = fs[ws]
	f1w = f1[w1]
	maskf = open('/Users/ashleyross/DESY1/mask_Y1redBAO_mean_z_bpz_VFF_4096ring.dat')
	npix = 12*4096*4096
	mask = []
	for i in range(0,npix):
		mask.append(0)
	for line in maskf:
		pix = int(float(line.split()[0]))
		mask[pix] = 1
	ng = 0
	ng3 = 0
	for i in range(0,f1w.size):
		ra,dec = f1w[i]['ra'],f1w[i]['dec']
		th,phi = radec2thphi(ra,dec)
		p = hp.ang2pix(4096,th,phi)
		if mask[int(p)] == 1:
			ng += 1.
	for i in range(0,fsw.size):
		ra,dec = fsw[i]['RA'],fsw[i]['DEC']
		th,phi = radec2thphi(ra,dec)
		p = hp.ang2pix(4096,th,phi)
		if mask[int(p)] == 1:
			ng3 += 1.

	print ng,ng3

	



	ws = (fsw['SOF_CM_MAG_CORRECTED_I']<19.+(3*fsw['DNF_ZMEAN_SOF']))
	w1 = (f1w['mag_auto_i'] < 19.+(3.*f1w['mean_z_bpz']))
	print fsw[ws].size*facs,f1w[w1].size*fac1,f1w[w1].size

	ws = (fsw['SOF_CM_MAG_CORRECTED_I']<19.+(3*fsw['DNF_ZMEAN_SOF'])) & (fsw['DNF_ZMEAN_SOF'] > 0.6) & (fsw['DNF_ZMEAN_SOF'] < 1.)
	w1 = (f1w['mag_auto_i'] < 19.+(3.*f1w['mean_z_bpz']))  & (f1w['mean_z_bpz']>0.6) & (f1w['mean_z_bpz']<1.)
	print fsw[ws].size*facs,f1w[w1].size*fac1,f1w[w1].size

	wa = (fma['DNF_ZMEAN_SOF'] > 0.6) & (fma['DNF_ZMEAN_SOF'] < 1.0)
	ws = (fs['DNF_ZMEAN_SOF'] > 0.6) & (fs['DNF_ZMEAN_SOF'] < 1.0)

	print fma[wa].size*6.,fs[ws].size*facs
	wa = (fma['DNF_ZMEAN_SOF'] > 0.6) & (fma['DNF_ZMEAN_SOF'] < 1.0) & (fma['SOF_CM_MAG_CORRECTED_I']-fma['SOF_CM_MAG_CORRECTED_Z'] +2.*(fma['SOF_CM_MAG_CORRECTED_R']-fma['SOF_CM_MAG_CORRECTED_I'])>1.7)
	ws = (fs['DNF_ZMEAN_SOF'] > 0.6) & (fs['DNF_ZMEAN_SOF'] < 1.0) & (fs['SOF_CM_MAG_CORRECTED_I']-fs['SOF_CM_MAG_CORRECTED_Z'] +2.*(fs['SOF_CM_MAG_CORRECTED_R']-fs['SOF_CM_MAG_CORRECTED_I'])>1.7)
	print fma[wa].size*6.,fs[ws].size*facs
	wa = (fma['DNF_ZMEAN_SOF'] > 0.6) & (fma['DNF_ZMEAN_SOF'] < 1.0) & (fma['SOF_CM_MAG_CORRECTED_I']-fma['SOF_CM_MAG_CORRECTED_Z'] +2.*(fma['SOF_CM_MAG_CORRECTED_R']-fma['SOF_CM_MAG_CORRECTED_I'])>1.7)\
	& (fma['MAG_AUTO_I']-1.569*fma['EBV_SFD98'] <19.+(3*fma['DNF_ZMEAN_SOF']))
	ws = (fs['DNF_ZMEAN_SOF'] > 0.6) & (fs['DNF_ZMEAN_SOF'] < 1.0) & (fs['SOF_CM_MAG_CORRECTED_I']-fs['SOF_CM_MAG_CORRECTED_Z'] +2.*(fs['SOF_CM_MAG_CORRECTED_R']-fs['SOF_CM_MAG_CORRECTED_I'])>1.7)\
	& (fs['SOF_CM_MAG_CORRECTED_I']<19.+(3*fs['DNF_ZMEAN_SOF']))
	print fma[wa].size*6.,fs[ws].size*facs
	print np.mean(fma['SOF_CM_MAG_CORRECTED_I'][wa]),np.mean(fma['MAG_AUTO_I'][wa]-1.569*fma['EBV_SFD98'][wa])
Ejemplo n.º 12
0
def mkRMmap(zmin, zmax, res=4096, pixmin=0, pixmax=False, wm='', wo=''):
    if pixmax == False:
        npix = 12 * res * res - pixmin
    else:
        npix = 1 + pixmax - pixmin
    pixl = np.zeros((npix))
    f = fitsio.read(inputdir + samp + '_sample.fits.gz')
    if wo != '':
        fo = open('Y1redmagic' + str(zmin) + str(zmax) + wm + '.dat', 'w')
    if wm != '':
        sysb = wm.split('_')
        if sysb[0] == 'seerw':
            seemap = mkmap('r', 'FWHM_MEAN', pixmin=pixmin, pixmax=pixmax)
            sys = sysb[1]
            band = sysb[2]
            b, m = findlinmb(band, sys, zmin, zmax)
            if sys == 'maglimit3':
                tp = '_'
                pr = 1.
            if sys == 'EXPTIME':
                tp = '_total'
                pr = 0.5
            sysmap = mkmap(band, sys, tp, pixmin=pixmin, pixmax=pixmax, pr=pr)

        else:
            sys = sysb[0]
            band = sysb[1]
            b, m = findlinmb(band, sys, zmin, zmax)
            if sys == 'maglimit3':
                tp = '_'
                pr = 1.
            if sys == 'EXPTIME':
                tp = '_total'
                pr = 0.5
            sysmap = mkmap(band, sys, tp, pixmin=pixmin, pixmax=pixmax, pr=pr)
    A = 0.505
    bs = 5.2
    sig = .7
    for i in range(0, len(f)):
        z = f[i]['ZREDMAGIC']
        w = 1.
        if z > zmin and z <= zmax:
            ra, dec = f[i]['RA'], f[i]['DEC']
            th, phi = radec2thphi(ra, dec)
            p = hp.ang2pix(res, th, phi) - pixmin

            if wm != '':
                if sysb[0] == 'seerw':
                    see = seemap[p]
                    sys = sysmap[p]
                    rsee = A * (1. - erf((see - bs) / sig))
                    rsys = m * sys + b
                    w = 1. / (rsee * rsys)
                else:
                    sys = sysmap[p]
                    w = 1. / (m * sys + b)
            pixl[p] += w
        if wo != '':
            fo.write(
                str(f[i]['RA']) + ' ' + str(f[i]['DEC']) + ' ' + str(z) + ' ' +
                str(w) + '\n')
    fo.close()
    return pixl
Ejemplo n.º 13
0
def mkRMmap(zmin,zmax,res=4096,pixmin=0,pixmax=False,wm='',wo=''):
	if pixmax == False:
		npix = 12*res*res- pixmin
	else:
		npix = 1+pixmax-pixmin	
	pixl = np.zeros((npix))
	f = fitsio.read(inputdir+samp+'_sample.fits.gz')
	if wo != '':
		fo = open('Y1redmagic'+str(zmin)+str(zmax)+wm+'.dat','w')
	if wm != '':		
		sysb = wm.split('_')
		if sysb[0] == 'seerw':
			seemap = mkmap('r','FWHM_MEAN',pixmin=pixmin,pixmax=pixmax)
			sys = sysb[1]
			band = sysb[2]
			b,m = findlinmb(band,sys,zmin,zmax)
			if sys == 'maglimit3':
				tp = '_'
				pr = 1.
			if sys == 'EXPTIME':
				tp = '_total'
				pr = 0.5
			sysmap = mkmap(band,sys,tp,pixmin=pixmin,pixmax=pixmax,pr=pr)
			
		else:
			sys = sysb[0]
			band = sysb[1]
			b,m = findlinmb(band,sys,zmin,zmax)
			if sys == 'maglimit3':
				tp = '_'
				pr = 1.
			if sys == 'EXPTIME':
				tp = '_total'
				pr = 0.5
			sysmap = mkmap(band,sys,tp,pixmin=pixmin,pixmax=pixmax,pr=pr)
	A = 0.505
	bs = 5.2
	sig = .7
	for i in range(0,len(f)):
		z = f[i]['ZREDMAGIC']
		w = 1.
		if z > zmin and z <= zmax:
			ra,dec = f[i]['RA'],f[i]['DEC']
			th,phi = radec2thphi(ra,dec)
			p = hp.ang2pix(res,th,phi)-pixmin
			
			if wm != '':
				if sysb[0] == 'seerw':
					see = seemap[p]
					sys = sysmap[p]
					rsee = A*(1.-erf((see-bs)/sig))
					rsys = m*sys+b
					w = 1./(rsee*rsys)
				else:
					sys = sysmap[p]
					w = 1./(m*sys+b)
			pixl[p] += w
		if wo != '':
			fo.write(str(f[i]['RA'])+' '+str(f[i]['DEC'])+' '+str(z)+' '+str(w)+'\n')
	fo.close()	
	return pixl
Ejemplo n.º 14
0
def compSOFMA():
    fma = fitsio.read('/Users/ashleyross/Dropbox/DESY3/allgal22magauto_1.fits')
    fs = fitsio.read('/Users/ashleyross/Dropbox/DESY3/allgal22_1.fits')
    f1 = fitsio.read('/Users/ashleyross/Dropbox/DESY3/Y1mag22.fits')
    facs = 5.3
    facm = 6.
    fac1 = 3.
    print np.mean(
        fma['SOF_CM_MAG_CORRECTED_I']), np.mean(fma['MAG_AUTO_I'] -
                                                1.569 * fma['EBV_SFD98'])
    print fma.size * facm, fs.size * facs, f1.size * fac1, f1.size
    wa = (fma['SOF_CM_MAG_CORRECTED_I'] - fma['SOF_CM_MAG_CORRECTED_Z'] + 2. *
          (fma['SOF_CM_MAG_CORRECTED_R'] - fma['SOF_CM_MAG_CORRECTED_I']) >
          1.7) & (fma['SOF_CM_MAG_CORRECTED_I'] > 17.5)
    ws = (fs['SOF_CM_MAG_CORRECTED_I'] - fs['SOF_CM_MAG_CORRECTED_Z'] + 2. *
          (fs['SOF_CM_MAG_CORRECTED_R'] - fs['SOF_CM_MAG_CORRECTED_I']) >
          1.7) & (fs['SOF_CM_MAG_CORRECTED_I'] > 17.5)
    w1 = (f1['MAG_AUTO_I'] - f1['MAG_AUTO_Z'] + 2. *
          (f1['MAG_AUTO_R'] - f1['MAG_AUTO_I']) > 1.7) & (f1['MAG_AUTO_I'] >
                                                          17.5)
    print fma[wa].size * 6., fs[ws].size * facs, f1[w1].size * fac1, f1[
        w1].size
    wa = (fma['SOF_CM_MAG_CORRECTED_I']-fma['SOF_CM_MAG_CORRECTED_Z'] +2.*(fma['SOF_CM_MAG_CORRECTED_R']-fma['SOF_CM_MAG_CORRECTED_I'])>1.7) & (fma['SOF_CM_MAG_CORRECTED_I']>17.5)\
    & ((fma['SOF_CM_MAG_CORRECTED_G'] - fma['SOF_CM_MAG_CORRECTED_R'])>-1.) & ((fma['SOF_CM_MAG_CORRECTED_G'] - fma['SOF_CM_MAG_CORRECTED_R'])<3.)
    ws =  (fs['SOF_CM_MAG_CORRECTED_I']-fs['SOF_CM_MAG_CORRECTED_Z'] +2.*(fs['SOF_CM_MAG_CORRECTED_R']-fs['SOF_CM_MAG_CORRECTED_I'])>1.7) & (fs['SOF_CM_MAG_CORRECTED_I']>17.5)\
    & ((fs['SOF_CM_MAG_CORRECTED_G'] - fs['SOF_CM_MAG_CORRECTED_R'])>-1.) & ((fs['SOF_CM_MAG_CORRECTED_G'] - fs['SOF_CM_MAG_CORRECTED_R'])<3.)

    w1 = (f1['MAG_AUTO_I']-f1['MAG_AUTO_Z'] +2.*(f1['MAG_AUTO_R']-f1['MAG_AUTO_I'])>1.7) & (f1['MAG_AUTO_I'] >17.5)\
    & ((f1['MAG_AUTO_G'] - f1['MAG_AUTO_R'])>-1.) & ((f1['MAG_AUTO_G'] - f1['MAG_AUTO_R'])<3.)

    print fma[wa].size * 6., fs[ws].size * facs, f1[w1].size * fac1, f1[
        w1].size

    wa = (fma['SOF_CM_MAG_CORRECTED_I']-fma['SOF_CM_MAG_CORRECTED_Z'] +2.*(fma['SOF_CM_MAG_CORRECTED_R']-fma['SOF_CM_MAG_CORRECTED_I'])>1.7) & (fma['SOF_CM_MAG_CORRECTED_I']>17.5)\
    & ((fma['SOF_CM_MAG_CORRECTED_G'] - fma['SOF_CM_MAG_CORRECTED_R'])>-1.) & ((fma['SOF_CM_MAG_CORRECTED_G'] - fma['SOF_CM_MAG_CORRECTED_R'])<3.)\
    & ((fma['SOF_CM_MAG_CORRECTED_R'] - fma['SOF_CM_MAG_CORRECTED_I'])>-1.) & ((fma['SOF_CM_MAG_CORRECTED_R'] - fma['SOF_CM_MAG_CORRECTED_I'])<2.5)

    ws =  (fs['SOF_CM_MAG_CORRECTED_I']-fs['SOF_CM_MAG_CORRECTED_Z'] +2.*(fs['SOF_CM_MAG_CORRECTED_R']-fs['SOF_CM_MAG_CORRECTED_I'])>1.7) & (fs['SOF_CM_MAG_CORRECTED_I']>17.5)\
    & ((fs['SOF_CM_MAG_CORRECTED_G'] - fs['SOF_CM_MAG_CORRECTED_R'])>-1.) & ((fs['SOF_CM_MAG_CORRECTED_G'] - fs['SOF_CM_MAG_CORRECTED_R'])<3.)\
    & ((fs['SOF_CM_MAG_CORRECTED_R'] - fs['SOF_CM_MAG_CORRECTED_I'])>-1.) & ((fs['SOF_CM_MAG_CORRECTED_R'] - fs['SOF_CM_MAG_CORRECTED_I'])<2.5)

    w1 = (f1['MAG_AUTO_I']-f1['MAG_AUTO_Z'] +2.*(f1['MAG_AUTO_R']-f1['MAG_AUTO_I'])>1.7) & (f1['MAG_AUTO_I'] >17.5)\
    & ((f1['MAG_AUTO_G'] - f1['MAG_AUTO_R'])>-1.) & ((f1['MAG_AUTO_G'] - f1['MAG_AUTO_R'])<3.)\
    & ((f1['MAG_AUTO_R'] - f1['MAG_AUTO_I'])>-1.) & ((f1['MAG_AUTO_R'] - f1['MAG_AUTO_I'])<2.5)
    print fma[wa].size * 6., fs[ws].size * facs, f1[w1].size * fac1, f1[
        w1].size

    wa = (fma['SOF_CM_MAG_CORRECTED_I']-fma['SOF_CM_MAG_CORRECTED_Z'] +2.*(fma['SOF_CM_MAG_CORRECTED_R']-fma['SOF_CM_MAG_CORRECTED_I'])>1.7) & (fma['SOF_CM_MAG_CORRECTED_I']>17.5)\
    & ((fma['SOF_CM_MAG_CORRECTED_G'] - fma['SOF_CM_MAG_CORRECTED_R'])>-1.) & ((fma['SOF_CM_MAG_CORRECTED_G'] - fma['SOF_CM_MAG_CORRECTED_R'])<3.)\
    & ((fma['SOF_CM_MAG_CORRECTED_R'] - fma['SOF_CM_MAG_CORRECTED_I'])>-1.) & ((fma['SOF_CM_MAG_CORRECTED_R'] - fma['SOF_CM_MAG_CORRECTED_I'])<2.5)\
    & ((fma['SOF_CM_MAG_CORRECTED_I'] - fma['SOF_CM_MAG_CORRECTED_Z'])>-1.) & ((fma['SOF_CM_MAG_CORRECTED_I'] - fma['SOF_CM_MAG_CORRECTED_Z'])<2.)

    ws =  (fs['SOF_CM_MAG_CORRECTED_I']-fs['SOF_CM_MAG_CORRECTED_Z'] +2.*(fs['SOF_CM_MAG_CORRECTED_R']-fs['SOF_CM_MAG_CORRECTED_I'])>1.7) & (fs['SOF_CM_MAG_CORRECTED_I']>17.5)\
    & ((fs['SOF_CM_MAG_CORRECTED_G'] - fs['SOF_CM_MAG_CORRECTED_R'])>-1.) & ((fs['SOF_CM_MAG_CORRECTED_G'] - fs['SOF_CM_MAG_CORRECTED_R'])<3.)\
    & ((fs['SOF_CM_MAG_CORRECTED_R'] - fs['SOF_CM_MAG_CORRECTED_I'])>-1.) & ((fs['SOF_CM_MAG_CORRECTED_R'] - fs['SOF_CM_MAG_CORRECTED_I'])<2.5)\
    & ((fs['SOF_CM_MAG_CORRECTED_I'] - fs['SOF_CM_MAG_CORRECTED_Z'])>-1.) & ((fs['SOF_CM_MAG_CORRECTED_I'] - fs['SOF_CM_MAG_CORRECTED_Z'])<2.)

    f1 = fitsio.read('/Users/ashleyross/Dropbox/DESY3/Y1mag22_chbpz.fits')

    w1 = (f1['mag_auto_i']-f1['mag_auto_z'] +2.*(f1['mag_auto_r']-f1['mag_auto_i'])>1.7) & (f1['mag_auto_i'] >17.5)\
    & ((f1['mag_auto_g'] - f1['mag_auto_r'])>-1.) & ((f1['mag_auto_g'] - f1['mag_auto_r'])<3.)\
    & ((f1['mag_auto_r'] - f1['mag_auto_i'])>-1.) & ((f1['mag_auto_r'] - f1['mag_auto_i'])<2.5)\
    & ((f1['mag_auto_i'] - f1['mag_auto_z'])>-1.) & ((f1['mag_auto_i'] - f1['mag_auto_z'])<2.)
    print fma[wa].size * 6., fs[ws].size * facs, f1[w1].size * fac1, f1[
        w1].size
    fmaw = fma[wa]
    fsw = fs[ws]
    f1w = f1[w1]
    maskf = open(
        '/Users/ashleyross/DESY1/mask_Y1redBAO_mean_z_bpz_VFF_4096ring.dat')
    npix = 12 * 4096 * 4096
    mask = []
    for i in range(0, npix):
        mask.append(0)
    for line in maskf:
        pix = int(float(line.split()[0]))
        mask[pix] = 1
    ng = 0
    ng3 = 0
    for i in range(0, f1w.size):
        ra, dec = f1w[i]['ra'], f1w[i]['dec']
        th, phi = radec2thphi(ra, dec)
        p = hp.ang2pix(4096, th, phi)
        if mask[int(p)] == 1:
            ng += 1.
    for i in range(0, fsw.size):
        ra, dec = fsw[i]['RA'], fsw[i]['DEC']
        th, phi = radec2thphi(ra, dec)
        p = hp.ang2pix(4096, th, phi)
        if mask[int(p)] == 1:
            ng3 += 1.

    print ng, ng3

    ws = (fsw['SOF_CM_MAG_CORRECTED_I'] < 19. + (3 * fsw['DNF_ZMEAN_SOF']))
    w1 = (f1w['mag_auto_i'] < 19. + (3. * f1w['mean_z_bpz']))
    print fsw[ws].size * facs, f1w[w1].size * fac1, f1w[w1].size

    ws = (fsw['SOF_CM_MAG_CORRECTED_I'] < 19. + (3 * fsw['DNF_ZMEAN_SOF'])) & (
        fsw['DNF_ZMEAN_SOF'] > 0.6) & (fsw['DNF_ZMEAN_SOF'] < 1.)
    w1 = (f1w['mag_auto_i'] < 19. + (3. * f1w['mean_z_bpz'])) & (
        f1w['mean_z_bpz'] > 0.6) & (f1w['mean_z_bpz'] < 1.)
    print fsw[ws].size * facs, f1w[w1].size * fac1, f1w[w1].size

    wa = (fma['DNF_ZMEAN_SOF'] > 0.6) & (fma['DNF_ZMEAN_SOF'] < 1.0)
    ws = (fs['DNF_ZMEAN_SOF'] > 0.6) & (fs['DNF_ZMEAN_SOF'] < 1.0)

    print fma[wa].size * 6., fs[ws].size * facs
    wa = (fma['DNF_ZMEAN_SOF'] > 0.6) & (fma['DNF_ZMEAN_SOF'] < 1.0) & (
        fma['SOF_CM_MAG_CORRECTED_I'] - fma['SOF_CM_MAG_CORRECTED_Z'] + 2. *
        (fma['SOF_CM_MAG_CORRECTED_R'] - fma['SOF_CM_MAG_CORRECTED_I']) > 1.7)
    ws = (fs['DNF_ZMEAN_SOF'] > 0.6) & (fs['DNF_ZMEAN_SOF'] < 1.0) & (
        fs['SOF_CM_MAG_CORRECTED_I'] - fs['SOF_CM_MAG_CORRECTED_Z'] + 2. *
        (fs['SOF_CM_MAG_CORRECTED_R'] - fs['SOF_CM_MAG_CORRECTED_I']) > 1.7)
    print fma[wa].size * 6., fs[ws].size * facs
    wa = (fma['DNF_ZMEAN_SOF'] > 0.6) & (fma['DNF_ZMEAN_SOF'] < 1.0) & (fma['SOF_CM_MAG_CORRECTED_I']-fma['SOF_CM_MAG_CORRECTED_Z'] +2.*(fma['SOF_CM_MAG_CORRECTED_R']-fma['SOF_CM_MAG_CORRECTED_I'])>1.7)\
    & (fma['MAG_AUTO_I']-1.569*fma['EBV_SFD98'] <19.+(3*fma['DNF_ZMEAN_SOF']))
    ws = (fs['DNF_ZMEAN_SOF'] > 0.6) & (fs['DNF_ZMEAN_SOF'] < 1.0) & (fs['SOF_CM_MAG_CORRECTED_I']-fs['SOF_CM_MAG_CORRECTED_Z'] +2.*(fs['SOF_CM_MAG_CORRECTED_R']-fs['SOF_CM_MAG_CORRECTED_I'])>1.7)\
    & (fs['SOF_CM_MAG_CORRECTED_I']<19.+(3*fs['DNF_ZMEAN_SOF']))
    print fma[wa].size * 6., fs[ws].size * facs
    print np.mean(
        fma['SOF_CM_MAG_CORRECTED_I'][wa]), np.mean(fma['MAG_AUTO_I'][wa] -
                                                    1.569 *
                                                    fma['EBV_SFD98'][wa])