Exemplo n.º 1
0
def mkgalodensY3ac4w(zr, res=256, tol=.2, md='', fore=''):
    from healpix import pix2ang_ring, thphi2radec
    np = 12 * res * res
    ml = []
    gl = []
    for i in range(0, np):
        ml.append(0)
        gl.append(0)

    mf = open(dir + 'Y3mask' + mask + 'lssred' + str(res) +
              'nest.dat').readlines()
    print 'mask read'
    for i in range(0, len(mf)):
        p = int(mf[i].split()[0])
        ml[p] = float(mf[i].split()[1])
    gl = mkgalmapY3ac(res, zr)  #,md,fore)

    ng = 0
    np = 0
    for i in range(0, len(gl)):
        if ml[i] > tol:
            m = 0
            #if maskst == 'y':
            #th,phi = pix2ang_ring(res,i)
            if m == 0:
                ng += gl[i]
                np += ml[i]
    print ng, np
    ave = ng / np
    print ave
    cw = ''
    fo = open(
        dir + 'galY3' + mask + 'lssred' + zr + str(res) + 'odenspczw.dat', 'w')
    ft = open(dir + 'galY3' + mask + 'lssred' + zr + str(res) + 'rdodens.dat',
              'w')
    no = 0
    for i in range(0, len(ml)):
        if ml[i] > tol:
            th, phi = hp.pix2ang(res, i, nest=True)
            m = 0
            #dec = -180./pi*th+90.
            ra, dec = thphi2radec(th, phi)
            if m == 0:
                sra = sin(phi)
                cra = cos(phi)
                sdec = sin(-1. * (th - pi / 2.))
                cdec = cos(-1. * (th - pi / 2.))
                od = gl[i] / (ave * ml[i]) - 1.
                fo.write(
                    str(sra) + ' ' + str(cra) + ' ' + str(sdec) + ' ' +
                    str(cdec) + ' ' + str(od) + ' ' + str(ml[i]) + '\n')
                ft.write(
                    str(th) + ' ' + str(phi) + ' ' + str(od) + ' ' +
                    str(ml[i]) + '\n')
    print no
    #ft.close()
    fo.close()
    return True
Exemplo n.º 2
0
def mkgalodensY3ac4w(zr,res=256,tol=.2,md='',fore=''):
	from healpix import pix2ang_ring,thphi2radec
	np = 12*res*res
	ml = []
	gl = []
	for i in range(0,np):
		ml.append(0)
		gl.append(0)
		
	mf = open(dir+'Y3mask'+mask+'lssred'+str(res)+'nest.dat').readlines()
	print 'mask read'
	for i in range(0,len(mf)):
		p = int(mf[i].split()[0])
		ml[p] = float(mf[i].split()[1])
	gl = mkgalmapY3ac(res,zr)#,md,fore)
		

	ng = 0
	np = 0 
	for i in range(0,len(gl)):
		if ml[i] > tol:
			m = 0
			#if maskst == 'y':
			#th,phi = pix2ang_ring(res,i)
			if m == 0:
				ng += gl[i]
				np += ml[i]
	print ng,np
	ave = ng/np
	print ave
	cw = ''
	fo = open(dir+'galY3'+mask+'lssred'+zr+str(res)+'odenspczw.dat','w')
	ft = open(dir+'galY3'+mask+'lssred'+zr+str(res)+'rdodens.dat','w')
	no = 0		
	for i in range(0,len(ml)):
		if ml[i] > tol:
			th,phi = hp.pix2ang(res,i,nest=True)
			m = 0
			#dec = -180./pi*th+90.
			ra,dec = thphi2radec(th,phi)
			if m == 0:
				sra = sin(phi)
				cra = cos(phi)
				sdec = sin(-1.*(th-pi/2.))
				cdec = cos(-1.*(th-pi/2.))
				od = gl[i]/(ave*ml[i]) -1.
				fo.write(str(sra)+' '+str(cra)+' '+str(sdec)+' '+str(cdec)+' '+str(od)+' '+str(ml[i])+'\n')
				ft.write(str(th)+' '+str(phi)+' '+str(od)+' '+str(ml[i])+'\n')
	print no
	#ft.close()
	fo.close()
	return True
Exemplo n.º 3
0
def mkgalodensY3ac4w_split(zr,res=256,tol=.2,splt=1.,md='',fore=''):
	from healpix import pix2ang_ring,thphi2radec
	np = 12*res*res
	ml = []
	gl = []
	for i in range(0,np):
		ml.append(0)
		gl.append(0)
		
	mf = open(dir+'Y3mask'+mask+'lssred'+str(res)+'nest.dat').readlines()
	print 'mask read'
	for i in range(0,len(mf)):
		p = int(mf[i].split()[0])
		ml[p] = float(mf[i].split()[1])
	gl = mkgalmapY3ac(res,zr)#,md,fore)
		

	ng = 0
	np = 0 
	for i in range(0,len(gl)):
		if ml[i] > tol:
			m = 0
			#if maskst == 'y':
			#th,phi = pix2ang_ring(res,i)
			if m == 0:
				ng += gl[i]
				np += ml[i]
	print ng,np
	ave = ng/np
	print ave
	gll = zeros((len(gl)))
	glh = zeros((len(gl)))
	ngl = 0
	ngh = 0
	for i in range(0,len(gl)):
		if ml[i] > tol:
			if gl[i]/ml[i] > ave*splt:
				glh[i] = gl[i]
				ngh += gl[i]
			else:
				gll[i] = gl[i]
				ngl += gl[i]
	avel = ngl/np
	aveh = ngh/np			
	cw = ''
	fol = open(dir+'galY3'+mask+'lssred'+zr+str(res)+'lowodenspczw.dat','w')
	ftl = open(dir+'galY3'+mask+'lssred'+zr+str(res)+'lowrdodens.dat','w')
	foh = open(dir+'galY3'+mask+'lssred'+zr+str(res)+'highodenspczw.dat','w')
	fth = open(dir+'galY3'+mask+'lssred'+zr+str(res)+'highrdodens.dat','w')
	no = 0		
	for i in range(0,len(ml)):
		if ml[i] > tol:
			th,phi = hp.pix2ang(res,i,nest=True)
			m = 0
			#dec = -180./pi*th+90.
			ra,dec = thphi2radec(th,phi)
			if m == 0:
				sra = sin(phi)
				cra = cos(phi)
				sdec = sin(-1.*(th-pi/2.))
				cdec = cos(-1.*(th-pi/2.))
				odl = gll[i]/(avel*ml[i]) -1.
				odh = glh[i]/(aveh*ml[i]) -1.
				fol.write(str(sra)+' '+str(cra)+' '+str(sdec)+' '+str(cdec)+' '+str(odl)+' '+str(ml[i])+'\n')
				ftl.write(str(th)+' '+str(phi)+' '+str(odl)+' '+str(ml[i])+'\n')
				foh.write(str(sra)+' '+str(cra)+' '+str(sdec)+' '+str(cdec)+' '+str(odh)+' '+str(ml[i])+'\n')
				fth.write(str(th)+' '+str(phi)+' '+str(odh)+' '+str(ml[i])+'\n')
	print no
	#ft.close()
	fol.close()
	foh.close()
	return True
Exemplo n.º 4
0
def plotPropertyMap(band,
                    vmin=21.0,
                    vmax=24.0,
                    mjdmax='',
                    prop='ivar',
                    op='total',
                    survey='surveyname',
                    nside='1024',
                    oversamp='1'):
    import fitsio
    from matplotlib import pyplot as plt
    import matplotlib.cm as cm
    from numpy import zeros, array
    import healpix

    from healpix import pix2ang_ring, thphi2radec
    import healpy as hp

    fname = localdir + survey + mjdmax + '/nside' + nside + '_oversamp' + oversamp + '/' + survey + mjdmax + '_band_' + band + '_nside' + nside + '_oversamp' + oversamp + '_' + prop + '__' + op + '.fits.gz'
    f = fitsio.read(fname)

    ral = []
    decl = []
    val = f['SIGNAL']
    pix = f['PIXEL']

    # Obtain values to plot
    if (prop == 'ivar'):
        myval = []
        mylabel = 'depth'
        print 'Converting ivar to depth.'
        print 'Plotting depth'

        below = 0
        for i in range(0, len(val)):
            depth = nanomaggiesToMag(sqrt(1. / val[i]) * 5.)
            if (depth < vmin):
                below = below + 1
            else:
                myval.append(depth)
                th, phi = hp.pix2ang(int(nside), pix[i])
                ra, dec = thphi2radec(th, phi)
                ral.append(ra)
                decl.append(dec)

    npix = len(f)
    print 'Min and Max values of ', mylabel, ' values is ', min(myval), max(
        myval)
    print 'Number of pixels is ', npix
    print 'Number of pixels offplot with ', mylabel, ' < ', vmin, ' is', below
    print 'Area is ', npix / (float(nside)**2. *
                              12) * 360 * 360. / pi, ' sq. deg.'

    map = plt.scatter(ral,
                      decl,
                      c=myval,
                      cmap=cm.rainbow,
                      s=2.,
                      vmin=vmin,
                      vmax=vmax,
                      lw=0,
                      edgecolors='none')
    cbar = plt.colorbar(map)
    plt.xlabel('r.a. (degrees)')
    plt.ylabel('declination (degrees)')
    plt.title('Map of ' + mylabel + ' for ' + survey + ' ' + band + '-band')
    plt.xlim(0, 360)
    plt.ylim(-30, 90)
    plt.savefig(localdir + mylabel + '_' + band + '_' + survey + str(nside) +
                '.png')
    plt.close()
    #plt.show()
    #cbar.set_label(r'5$\sigma$ galaxy depth', rotation=270,labelpad=1)
    #plt.xscale('log')
    return True
Exemplo n.º 5
0
def plotPhotometryMap(band,
                      vmin=0.0,
                      vmax=1.0,
                      mjdmax='',
                      prop='zptvar',
                      op='min',
                      rel='DR0',
                      survey='surveyname',
                      nside='1024',
                      oversamp='1'):
    import fitsio
    from matplotlib import pyplot as plt
    import matplotlib.cm as cm
    from numpy import zeros, array
    import healpix

    from healpix import pix2ang_ring, thphi2radec
    import healpy as hp

    # Survey inputs
    mjdw = mjdmax
    if rel == 'DR2':
        fname = inputdir + 'decals-ccds-annotated.fits'
        catalogue_name = 'DECaLS_DR2' + mjdw

    if rel == 'DR3':
        inputdir = '/project/projectdirs/cosmo/data/legacysurvey/dr3/'  # where I get my data
        fname = inputdir + 'ccds-annotated-decals.fits.gz'
        catalogue_name = 'DECaLS_DR3' + mjdw

    if rel == 'DR4':
        inputdir = '/global/projecta/projectdirs/cosmo/work/dr4/'
        if (band == 'g' or band == 'r'):
            fname = inputdir + 'ccds-annotated-dr4-90prime.fits.gz'
            catalogue_name = '90prime_DR4' + mjdw
        if band == 'z':
            fname = inputdir + 'ccds-annotated-dr4-mzls.fits.gz'
            catalogue_name = 'MZLS_DR4' + mjdw

    fname = localdir + catalogue_name + '/nside' + nside + '_oversamp' + oversamp + '/' + catalogue_name + '_band_' + band + '_nside' + nside + '_oversamp' + oversamp + '_' + prop + '__' + op + '.fits.gz'
    f = fitsio.read(fname)

    ral = []
    decl = []
    val = f['SIGNAL']
    pix = f['PIXEL']

    # -------------- plot of values ------------------
    if (prop == 'zptvar' and opt == 'min'):

        print 'Plotting min zpt rms'
        myval = []
        for i in range(0, len(val)):

            myval.append(1.086 *
                         np.sqrt(val[i]))  #1.086 converts dm into d(flux)
            th, phi = hp.pix2ang(int(nside), pix[i])
            ra, dec = thphi2radec(th, phi)
            ral.append(ra)
            decl.append(dec)

        mylabel = 'min-zpt-rms-flux'
        vmin = 0.0  #min(myval)
        vmax = 0.03  #max(myval)
        npix = len(myval)
        below = 0
        print 'Min and Max values of ', mylabel, ' values is ', min(
            myval), max(myval)
        print 'Number of pixels is ', npix
        print 'Number of pixels offplot with ', mylabel, ' < ', vmin, ' is', below
        print 'Area is ', npix / (float(nside)**2. *
                                  12) * 360 * 360. / pi, ' sq. deg.'

        map = plt.scatter(ral,
                          decl,
                          c=myval,
                          cmap=cm.rainbow,
                          s=2.,
                          vmin=vmin,
                          vmax=vmax,
                          lw=0,
                          edgecolors='none')
        cbar = plt.colorbar(map)
        plt.xlabel('r.a. (degrees)')
        plt.ylabel('declination (degrees)')
        plt.title('Map of ' + mylabel + ' for ' + catalogue_name + ' ' + band +
                  '-band')
        plt.xlim(0, 360)
        plt.ylim(-30, 90)
        plt.savefig(localdir + mylabel + '_' + band + '_' + catalogue_name +
                    str(nside) + '.png')
        plt.close()

    # -------------- plot of status in udgrade maps of 1.406 deg pix size  ------------------

    #Bands inputs
    if band == 'g':
        phreq = 0.01
    if band == 'r':
        phreq = 0.01
    if band == 'z':
        phreq = 0.02

    # Obtain values to plot
    if (prop == 'zptvar' and opt == 'min'):

        nside2 = 64  # 1.40625 deg per pixel
        npix2 = hp.nside2npix(nside2)
        myreq = np.zeros(
            npix2
        )  # 0 off footprint, 1 at least one pass requirement, -1 none pass requirement
        ral = np.zeros(npix2)
        decl = np.zeros(npix2)
        mylabel = 'photometric-pixels'
        print 'Plotting photometric requirement'

        for i in range(0, len(val)):
            th, phi = hp.pix2ang(int(nside), pix[i])
            ipix = hp.ang2pix(nside2, th, phi)
            dF = 1.086 * (sqrt(val[i])
                          )  # 1.086 converts d(magnitudes) into d(flux)

            if (dF < phreq):
                myreq[ipix] = 1
            else:
                if (myreq[ipix] == 0): myreq[ipix] = -1

        for i in range(0, len(myreq)):
            th, phi = hp.pix2ang(int(nside2), pix[i])
            ra, dec = thphi2radec(th, phi)
            ral[i] = ra
            decl[i] = dec

        #myval = np.zeros(npix2)
        #mycount = np.zeros(pix2)
        #myval[ipix] += dF
        #mycount[ipix] += 1.

        below = sum(x for x in myreq if x < phreq)

        print 'Number of pixels offplot with ', mylabel, ' < ', phreq, ' is', below

        vmin = min(myreq)
        vmax = max(myreq)
        map = plt.scatter(ral,
                          decl,
                          c=myreq,
                          cmap=cm.rainbow,
                          s=5.,
                          vmin=vmin,
                          vmax=vmax,
                          lw=0,
                          edgecolors='none')
        cbar = plt.colorbar(map)
        plt.xlabel('r.a. (degrees)')
        plt.ylabel('declination (degrees)')
        plt.title('Map of ' + mylabel + ' for ' + catalogue_name + ' ' + band +
                  '-band')
        plt.xlim(0, 360)
        plt.ylim(-30, 90)
        plt.savefig(localdir + mylabel + '_' + band + '_' + catalogue_name +
                    str(nside) + '.png')
        plt.close()
        #plt.show()
        #cbar.set_label(r'5$\sigma$ galaxy depth', rotation=270,labelpad=1)
        #plt.xscale('log')

    return True
Exemplo n.º 6
0
def val3p4c_depthfromIvar(sample):
    """
       Requirement V3.4
       90% filled to g=24, r=23.4 and z=22.5 and 95% and 98% at 0.3/0.6 mag shallower.

       Produces extinction correction magnitude maps for visual inspection

       MARCM stable version, improved from AJR quick hack 
       This now included extinction from the exposures
       Uses quicksip subroutines from Boris, corrected 
       for a bug I found for BASS and MzLS ccd orientation
    """
    nside = 1024  # Resolution of output maps
    nsidesout = None  # if you want full sky degraded maps to be written
    ratiores = 1  # Superresolution/oversampling ratio, simp mode doesn't allow anything other than 1
    mode = 1  # 1: fully sequential, 2: parallel then sequential, 3: fully parallel
    pixoffset = 0  # How many pixels are being removed on the edge of each CCD? 15 for DES.
    oversamp = '1'  # ratiores in string format
    nsideSTR = '1024'  # same as nside but in string format

    band = sample.band
    catalogue_name = sample.catalog
    fname = sample.ccds
    localdir = sample.localdir
    outroot = localdir
    extc = sample.extc

    #Read ccd file
    tbdata = pyfits.open(fname)[1].data

    # ------------------------------------------------------
    # Obtain indices
    auxstr = 'band_' + band
    sample_names = [auxstr]
    if (sample.DR == 'DR3'):
        inds = np.where((tbdata['filter'] == band)
                        & (tbdata['photometric'] == True)
                        & (tbdata['blacklist_ok'] == True))
    elif (sample.DR == 'DR4'):
        inds = np.where((tbdata['filter'] == band)
                        & (tbdata['photometric'] == True)
                        & (tbdata['bitmask'] == 0))

    #Read data
    #obtain invnoisesq here, including extinction
    nmag = Magtonanomaggies(tbdata['galdepth'] - extc * tbdata['EBV']) / 5.
    ivar = 1. / nmag**2.

    # What properties do you want mapped?
    # Each each tuple has [(quantity to be projected, weighting scheme, operation),(etc..)]
    propertiesandoperations = [
        ('ivar', '', 'total'),
    ]

    # What properties to keep when reading the images?
    # Should at least contain propertiesandoperations and the image corners.
    # MARCM - actually no need for ra dec image corners.
    # Only needs ra0 ra1 ra2 ra3 dec0 dec1 dec2 dec3 only if fast track appropriate quicksip subroutines were implemented
    propertiesToKeep = [ 'filter', 'AIRMASS', 'FWHM','mjd_obs'] \
     + ['RA', 'DEC', 'crval1', 'crval2', 'crpix1', 'crpix2', 'cd1_1', 'cd1_2', 'cd2_1', 'cd2_2','width','height']

    # Create big table with all relevant properties.

    tbdata = np.core.records.fromarrays(
        [tbdata[prop] for prop in propertiesToKeep] + [ivar],
        names=propertiesToKeep + ['ivar'])

    # Read the table, create Healtree, project it into healpix maps, and write these maps.
    # Done with Quicksip library, note it has quite a few hardcoded values (use new version by MARCM for BASS and MzLS)
    # project_and_write_maps_simp(mode, propertiesandoperations, tbdata, catalogue_name, outroot, sample_names, inds, nside)
    project_and_write_maps(mode, propertiesandoperations, tbdata,
                           catalogue_name, outroot, sample_names, inds, nside,
                           ratiores, pixoffset, nsidesout)

    # Read Haelpix maps from quicksip
    prop = 'ivar'
    op = 'total'
    vmin = 21.0
    vmax = 24.0

    fname2=localdir+catalogue_name+'/nside'+nsideSTR+'_oversamp'+oversamp+'/'+\
           catalogue_name+'_band_'+band+'_nside'+nsideSTR+'_oversamp'+oversamp+'_'+prop+'__'+op+'.fits.gz'
    f = fitsio.read(fname2)

    # HEALPIX DEPTH MAPS
    # convert ivar to depth
    import healpy as hp
    from healpix import pix2ang_ring, thphi2radec

    ral = []
    decl = []
    val = f['SIGNAL']
    pix = f['PIXEL']

    # Obtain values to plot
    if (prop == 'ivar'):
        myval = []
        mylabel = 'depth'

        below = 0
        for i in range(0, len(val)):
            depth = nanomaggiesToMag(sqrt(1. / val[i]) * 5.)
            if (depth < vmin):
                below = below + 1
            else:
                myval.append(depth)
                th, phi = hp.pix2ang(int(nside), pix[i])
                ra, dec = thphi2radec(th, phi)
                ral.append(ra)
                decl.append(dec)

    npix = len(f)

    print 'Area is ', npix / (float(nside)**2. *
                              12) * 360 * 360. / pi, ' sq. deg.'
    print below, 'of ', npix, ' pixels are not plotted as their ', mylabel, ' < ', vmin
    print 'Within the plot, min ', mylabel, '= ', min(
        myval), ' and max ', mylabel, ' = ', max(myval)

    # Plot depth
    from matplotlib import pyplot as plt
    import matplotlib.cm as cm

    map = plt.scatter(ral,
                      decl,
                      c=myval,
                      cmap=cm.rainbow,
                      s=2.,
                      vmin=vmin,
                      vmax=vmax,
                      lw=0,
                      edgecolors='none')
    cbar = plt.colorbar(map)
    plt.xlabel('r.a. (degrees)')
    plt.ylabel('declination (degrees)')
    plt.title('Map of ' + mylabel + ' for ' + catalogue_name + ' ' + band +
              '-band')
    plt.xlim(0, 360)
    plt.ylim(-30, 90)
    mapfile = localdir + mylabel + '_' + band + '_' + catalogue_name + str(
        nside) + '.png'
    print 'saving plot to ', mapfile
    plt.savefig(mapfile)
    plt.close()
    #plt.show()
    #cbar.set_label(r'5$\sigma$ galaxy depth', rotation=270,labelpad=1)
    #plt.xscale('log')

    return mapfile
Exemplo n.º 7
0
def mkgalodensY3ac4w_split(zr, res=256, tol=.2, splt=1., md='', fore=''):
    from healpix import pix2ang_ring, thphi2radec
    np = 12 * res * res
    ml = []
    gl = []
    for i in range(0, np):
        ml.append(0)
        gl.append(0)

    mf = open(dir + 'Y3mask' + mask + 'lssred' + str(res) +
              'nest.dat').readlines()
    print 'mask read'
    for i in range(0, len(mf)):
        p = int(mf[i].split()[0])
        ml[p] = float(mf[i].split()[1])
    gl = mkgalmapY3ac(res, zr)  #,md,fore)

    ng = 0
    np = 0
    for i in range(0, len(gl)):
        if ml[i] > tol:
            m = 0
            #if maskst == 'y':
            #th,phi = pix2ang_ring(res,i)
            if m == 0:
                ng += gl[i]
                np += ml[i]
    print ng, np
    ave = ng / np
    print ave
    gll = zeros((len(gl)))
    glh = zeros((len(gl)))
    ngl = 0
    ngh = 0
    for i in range(0, len(gl)):
        if ml[i] > tol:
            if gl[i] / ml[i] > ave * splt:
                glh[i] = gl[i]
                ngh += gl[i]
            else:
                gll[i] = gl[i]
                ngl += gl[i]
    avel = ngl / np
    aveh = ngh / np
    cw = ''
    fol = open(
        dir + 'galY3' + mask + 'lssred' + zr + str(res) + 'lowodenspczw.dat',
        'w')
    ftl = open(
        dir + 'galY3' + mask + 'lssred' + zr + str(res) + 'lowrdodens.dat',
        'w')
    foh = open(
        dir + 'galY3' + mask + 'lssred' + zr + str(res) + 'highodenspczw.dat',
        'w')
    fth = open(
        dir + 'galY3' + mask + 'lssred' + zr + str(res) + 'highrdodens.dat',
        'w')
    no = 0
    for i in range(0, len(ml)):
        if ml[i] > tol:
            th, phi = hp.pix2ang(res, i, nest=True)
            m = 0
            #dec = -180./pi*th+90.
            ra, dec = thphi2radec(th, phi)
            if m == 0:
                sra = sin(phi)
                cra = cos(phi)
                sdec = sin(-1. * (th - pi / 2.))
                cdec = cos(-1. * (th - pi / 2.))
                odl = gll[i] / (avel * ml[i]) - 1.
                odh = glh[i] / (aveh * ml[i]) - 1.
                fol.write(
                    str(sra) + ' ' + str(cra) + ' ' + str(sdec) + ' ' +
                    str(cdec) + ' ' + str(odl) + ' ' + str(ml[i]) + '\n')
                ftl.write(
                    str(th) + ' ' + str(phi) + ' ' + str(odl) + ' ' +
                    str(ml[i]) + '\n')
                foh.write(
                    str(sra) + ' ' + str(cra) + ' ' + str(sdec) + ' ' +
                    str(cdec) + ' ' + str(odh) + ' ' + str(ml[i]) + '\n')
                fth.write(
                    str(th) + ' ' + str(phi) + ' ' + str(odh) + ' ' +
                    str(ml[i]) + '\n')
    print no
    #ft.close()
    fol.close()
    foh.close()
    return True