コード例 #1
0
def printratirhtml():
	
	#Reads in final magnitudes
	plotra, plotdec, plotrmag, plotrmagerr, plotimag, plotimagerr, plotzmag, plotzmagerr, plotymag, plotymagerr, plotJmag, plotJmagerr, plotHmag, plotHmagerr = np.loadtxt('./finalmags.txt', unpack=True)

	pl.figure()
	pl.xlim([15,22])
	pl.ylim([-0.01,0.2])
	pl.plot(plotrmag, plotrmagerr, marker='o',linestyle='None', label='r', color='purple')
	pl.plot(plotimag, plotimagerr, marker='o',linestyle='None', label='i', color='blue')
	pl.plot(plotzmag, plotzmagerr, marker='o',linestyle='None', label='z', color='aqua')
	pl.plot(plotymag, plotymagerr, marker='o',linestyle='None', label='y', color='green')
	pl.plot(plotJmag, plotJmagerr, marker='o',linestyle='None', label='J', color='orange')
	pl.plot(plotHmag, plotHmagerr, marker='o',linestyle='None', label='H', color='red')
	
	pl.xlabel('AB Magnitude')
	pl.ylabel(r"$\Delta$ Mag")
	pl.legend(loc='lower right')
	pl.savefig( 'photcomp.png', bbox_inches='tight')
	pl.clf()

	f = open( './ratir.html', 'w' )
	f.write( '<!DOCTYPE HTML>\n' )
	f.write( '<HTML>\n' )
	f.write( '<HEAD>\n' )
	f.write( '<TITLE>RATIR DATA</TITLE>\n' )
	f.write( '</HEAD>\n' )
	f.write( '<BODY BGCOLOR="#FFFFFF" TEXT="#003300">\n' )

	#Finds filter image files with green circles over sources and writes to HTML
	prefchar = 'coadd'
	zffiles = pplib.choosefiles( prefchar + '*_?.png' )

	im_wid = 400

	f.write( '<IMG SRC="./color.png" width="' + `im_wid` + '"><BR>\n' )
	for i in range(len(zffiles)):
	    f.write( '<IMG SRC="./' + zffiles[i] + '" width="' + `im_wid` + '">\n' )
	    if (i+1)%3 == 0:
	    	f.write( '<BR>\n' )

	f.write( '<BR><HR><FONT SIZE="+2" COLOR="#006600">AB System Photometry (sources within 1 arcmin):</FONT><BR>\n' )
	f.write( 'Notes: Non-zero magnitudes with uncertainty of zero are 3-sigma upper limits.  Sources with magnitudes of 0.0000 are unobserved.<BR>\n' )
	f.write( '		 Circles in images above match aperture size used in sextractor.<BR>\n' )
	f.write( '<br />\n' )

	#Writes table with all magnitudes
	f.write( '<table border="1" width="100%">\n' )
	f.write( '<tr><th>#</th><th>RA</th><th>DEC</th><th>r MAG</th><th>r MAG ERR</th><th>i MAG</th><th>i MAG ERR</th><th>z MAG</th><th>z MAG ERR</th><th>y MAG</th><th>y MAG ERR</th><th>J MAG</th><th>J MAG ERR</th><th>H MAG</th><th>H MAG ERR</th><tr>\n' )
	for i in range(len(plotra)):
	    f.write( '<tr><td>{:.0f}</td><td>{:.6f}</td><td>{:.6f}</td><td>{:.2f}</td><td>{:.2f}</td><td>{:.2f}</td><td>{:.2f}</td><td>{:.2f}</td><td>{:.2f}</td><td>{:.2f}</td><td>{:.2f}</td><td>{:.2f}</td><td>{:.2f}</td><td>{:.2f}</td><td>{:.2f}</td></tr>\n'.format(i,plotra[i],plotdec[i],plotrmag[i],plotrmagerr[i],plotimag[i],plotimagerr[i],plotzmag[i],plotzmagerr[i],plotymag[i],plotymagerr[i],plotJmag[i],plotJmagerr[i],plotHmag[i],plotHmagerr[i]) )
	f.write( '</table>\n' )

	f.write( '</PRE><BR><HR>\n' )
	f.write( '<IMG SRC="photcomp.png">\n' )
	f.write( '</PRE><BR><HR>\n' )

	f.write( '</BODY>\n' )
	f.write( '</HTML>\n' )
	f.close()
コード例 #2
0
ファイル: lmi_quickphot.py プロジェクト: jicapone/LMI-GSFC
def completephot(wildcardsearch):
	fitsfiles = pplib.choosefiles(wildcardsearch)
	
	f = open('photometrymultiple.txt','w')	
	
	for file in fitsfiles:
		[fitsfile, filter, mag, magerr, correrr] = quickphot(file)
		f.write(fitsfile + '\t' + filter + '\t' + ut + '\t' + str(mag) + '\t' + str(magerr) + '\t' + str(correrr) + '\n')
	
	f.close()
コード例 #3
0
ファイル: printhtml.py プロジェクト: cenko/RATIR-GSFC
def printhtml(filters, colnames):
	
	#Reads in final magnitudes
	colgrab = np.loadtxt('./finalmags.txt', unpack=True)
	
	#Store each column into dictionary based on colnames and create header for HTML header from colnames
	plotdict = {}
	t = '<tr><th>#</th>'
	for i in np.arange(len(colnames)):
		plotdict[colnames[i]] = colgrab[i,:]		
		t = t + '<th>' + colnames[i]+'</th>'
	
	t = t + '<tr>\n' 

	colors = ['black', 'purple','blue','aqua','green','orange','red','yellow', 'magenta']

	pl.figure()
	pl.xlim([15,22])
	pl.ylim([-0.01,0.2])
	
	#For each filter, plot mag vs. error for photocomp.png
	counter = 0
	for filter in filters:
		pl.plot(plotdict[filter+'mag'], plotdict[filter+'magerr'], marker='o',linestyle='None', label=filter, color=colors[counter])
		counter = counter + 1
	
	pl.xlabel('AB Magnitude')
	pl.ylabel(r"$\Delta$ Mag")
	pl.legend(loc='lower right')
	pl.savefig( 'photcomp.png', bbox_inches='tight')
	pl.clf()

	#Create html page that displays images made in plotphotom.py and values from finalmags.txt
	f = open( './photom.html', 'w' )
	f.write( '<!DOCTYPE HTML>\n' )
	f.write( '<HTML>\n' )
	f.write( '<HEAD>\n' )
	f.write( '<TITLE>PHOTOMETRY DATA</TITLE>\n' )
	f.write( '</HEAD>\n' )
	f.write( '<BODY BGCOLOR="#FFFFFF" TEXT="#003300">\n' )

	#Finds filter image files with green circles over sources and writes to HTML
	prefchar = 'coadd'
	zffiles = pplib.choosefiles( prefchar + '*_?.png' )

	im_wid = 400

	f.write( '<IMG SRC="./color.png" width="' + `im_wid` + '"><BR>\n' )
	for i in range(len(zffiles)):
	    f.write( '<IMG SRC="./' + zffiles[i] + '" width="' + `im_wid` + '">\n' )
	    if (i+1)%3 == 0:
	    	f.write( '<BR>\n' )

	f.write( '<BR><HR><FONT SIZE="+2" COLOR="#006600">AB System Photometry (sources within 1 arcmin):</FONT><BR>\n' )
	f.write( 'Notes: Non-zero magnitudes with uncertainty of zero are 3-sigma upper limits.  Sources with magnitudes of 0.0000 are unobserved.<BR>\n' )
	f.write( '		 Circles in images above match aperture size used in sextractor.<BR>\n' )
	f.write( '<br />\n' )


	#Writes table with all magnitudes
	f.write( '<table border="1" width="100%">\n' )
	
	f.write( t )
	for j in np.arange(len(plotdict[colnames[0]])):
		f.write('<tr><td>{:.0f}</td>'.format(j))
		for col in colnames:
			f.write('<td>{:.3f}</td>'.format(plotdict[col][j]))
		f.write('<tr>\n')
	f.write( '</table>\n' )
	
	f.write( '</PRE><BR><HR>\n' )
	f.write( '<IMG SRC="photcomp.png">\n' )
	f.write( '</PRE><BR><HR>\n' )

	f.write( '</BODY>\n' )
	f.write( '</HTML>\n' )
	f.close()
コード例 #4
0
ファイル: plotphotom.py プロジェクト: cenko/RATIR-GSFC
def plotphotom(prefchar='coadd'):

	#Initialize arrays
    filters = ['r','i','z','y','J','H']
    arr_size = 10000
    
    #Creates a list of names: ['ra', 'dec', '(FILTER)mag', '(FILTER)magerr'] including
    #all filters in filters list
    #Also initializes filter index dictionary for use later
    names = ['ra', 'dec']
    ifiltdict = {}
    for filter in filters:
    	names.extend([filter+'mag', filter+'magerr'])
    	ifiltdict[filter] = -1

    #Create dictionary with keys from names list and all set to np.zeros(arr_size)
    #easily changed for other filters
    plotdict = {}
    for name in names:
    	plotdict[name] = np.zeros(arr_size)

    # retrieve detection files
    zffiles = pplib.choosefiles( prefchar+'*_?.ref.multi.fits' )

    #Save filter and data from each file into arrays and find overlapping stars
    #between filter files using final photometry file (comparing distances from RA and DEC)
    cfilterarr = []
    imgarr = []
    harr   = []

    for i in range(len(zffiles)):
    
    	#Find filter of each file and make sure that has the right capitalization
        cfilter = zffiles[i].split('_')[1].split('.')[0]
        if cfilter == 'Z' or cfilter == 'Y':
            cfilter = cfilter.lower()
        cfilterarr.append(cfilter)
        
        #Save data scaled by scale factor to imgarr
        ifile = zffiles[i]
        hdulist = pf.open(ifile)
        h = hdulist[0].header
        img = hdulist[0].data
        im_size = np.shape(img)
        scalefactor = 1.
        img = zoom( img, 1./scalefactor, order=0 )
        imgarr.append(img)
        harr.append(h)
        
        #Read in finalphot[FILTER].am which has the instrument corrected photometry
        pfile = 'finalphot' + cfilter + '.am'
        x, y, ra, dec, mag, magerr = np.loadtxt(pfile, unpack=True)
        
        clen = len(mag)
        
        #For first file initialize variables for following files, use temporary variables
        #for comparison
        if i == 0:
            plotdict['ra'][0:clen]  = ra
            plotdict['dec'][0:clen] = dec
            
            plotdict[cfilter+'mag'][0:clen]    = mag
            plotdict[cfilter+'magerr'][0:clen] = magerr
            nstars = clen
        else:
            compra     = ra
            compdec    = dec
            compmag    = mag
            compmagerr = magerr
            
            #For each source in file find any sources that are within 1 arcsecond
            #if these exist then store information in same index but different filter's magnitude
            #array.  If these don't exist, put on the end of filter's (and position) arrays
            #to signify a new source

            for j in range(len(compra)):
                smatch = pplib.nearest( compra[j]*np.cos(compdec[j]*np.pi/180.), compdec[j], 
                						plotdict['ra']*np.cos(plotdict['dec']*np.pi/180.), plotdict['dec'], maxdist=1./3600. )
                
                if any(smatch):
                	plotdict[cfilter+'mag'][smatch]    = compmag[j]
                	plotdict[cfilter+'magerr'][smatch] = compmagerr[j]
                else:
                    plotdict['ra'][nstars]  = compra[j]
                    plotdict['dec'][nstars] = compdec[j]
                    plotdict[cfilter+'mag'][nstars]    = compmag[j]
                    plotdict[cfilter+'magerr'][nstars] = compmagerr[j]
                    nstars += 1
    
    imgarr = np.array(imgarr)
	
	#Save stars to finalmags.txt with correct format and removes zeros
    store = np.zeros(nstars)
    for name in names:
    	store = np.vstack( (store,plotdict[name][:nstars]) )
    
    store = store[1:, :] #Removes 0's from initialization

    #Finds sources that are cut off on at least one filter using weight maps
    #and checking if 25% of the number of pixels in a 10 pixel radius circle
    #are 0 in the weight map of each filter (i.e. cut off)
    sra = store[0]
    sdec = store[1]   
    removesource = []
    
    for s in np.arange(len(sra)):
    	for file in zffiles:
    		nzero = 0
    		wmultifile = file[:-4]+'weight.fits'
    		hlist = pf.open(wmultifile)
    		wdata = hlist[0].data
    		wh    = hlist[0].header
    		w     = wcs.WCS(wh)
    		spix  = w.wcs_world2pix(sra[s],sdec[s], 1)
    		
    		wcir  = pplib.circle(spix[0],spix[1],10)
    		ncir  = len(wcir)
    		for coord in wcir:
    			if (wh['NAXIS1'] > coord[0] > 0) & (wh['NAXIS2'] > coord[1] > 0):
    				if wdata[int(coord[1])][int(coord[0])] == 0: nzero += 1
    			else:
    				ncir -= 1
    		if nzero >= 0.25*ncir: 
    			removesource.append(s)
    			break    

    store = np.delete(store, removesource, axis=1)
    np.savetxt('finalmags.txt', store.T, fmt='%12.6f')
    
    #Find the index of the file that corresponds to each filter and save 
    #to ifiltdict (initialized to -1)
    for item in ifiltdict:
    	try:
    		ifiltdict[item] = cfilterarr.index(item)
    	except ValueError:
    		pass

	#Determines colors based on which filters are present.  
	#Red = J/H, green = z/y, blue = r/i
	#If neither filter present, set to 0, if one present, use imgarr of data from that filter
	#if both present use half from imgarr of data from each filter	
	def fcolor(filt1, filt2, ifiltdict, imgarr):
	
		if filt1 and filt2 in ifiltdict:
			if ifiltdict[filt1] >= 0 and ifiltdict[filt2] >= 0:
				x = imgarr[ifiltdict[filt1],:,:] * 0.5 + imgarr[ifiltdict[filt2],:,:] * 0.5
			if ifiltdict[filt1] >= 0 and ifiltdict[filt2] < 0:
				x = imgarr[ifiltdict[filt1],:,:]
			if ifiltdict[filt2] >= 0 and ifiltdict[filt1] < 0:
				x = imgarr[ifiltdict[filt2],:,:]
			if ifiltdict[filt2] < 0 and ifiltdict[filt1] < 0:
				x = 0
		else:
			print 'Valid filters were not supplied, set color to 0'
			x = 0
			
		return x 
        
    red   = fcolor('J', 'H', ifiltdict, imgarr)    
    green = fcolor('z', 'y', ifiltdict, imgarr) 
    blue  = fcolor('r', 'i', ifiltdict, imgarr)

	#Determine image size base on if color filter exists (priority: red, green, blue in that order)
    if np.size(red) > 1:
        im_size = np.shape(red)
    elif np.size(green) > 1:
        im_size = np.shape(green)
    elif np.size(blue) > 1:
        im_size = np.shape(blue)

    def bytearr( x, y, z ):
        return np.zeros((x,y,z)).astype(np.uint8)
    
    #Create color of image and save to color.png    
    color = bytearr( im_size[0], im_size[1], 3 )     
        
    #Changes color into bytescale range and saves to color array
    if np.size(blue) > 1:
        blue  = bytescale(blue,  0, 8, 250)
        color[:,:,2] = blue * 0.5
    if np.size(green) > 1:
        green = bytescale(green, 0, 8, 250)
        color[:,:,1] = green * 0.5
    if np.size(red) > 1:
        red   = bytescale(red,   0, 8, 250)
        color[:,:,0] = red * 0.5
        
    color = color[::-1,:]
    fig = pl.figure('color image')
    pl.axis('off')
    pl.imshow( color, interpolation='None', origin='lower' )
    sp.misc.imsave( 'color.png', color )
    
    #Find aperture size to make circles around sources that match sextractor aperture
    pline=''
    sfile = open('ratir_weighted.sex', 'r')
    for line in sfile:
    	if 'PHOT_APERTURES' in line: pline=line
    sfile.close()
    
    bpline = pline.split()	
    
    if len(bpline) != 0:
    	aper = int(bpline[1])/2.0 #radius
    else:
    	aper = 10
    
    objra  = store[0]
    objdec = store[1]
    
    #Plot each image with circles on star identification
    for i in range(len(zffiles)):
    	ifile   = zffiles[i]
    	img     = imgarr[i]
    	h       = harr[i]
    	cfilter = cfilterarr[i]
    	
    	scale   = bytescale(img, 0, 10, 255)
    	dpi     = 72. # px per inch
    	figsize = (np.array(img.shape)/dpi)[::-1]
    	fig     = pl.figure(i)
    	
    	pl.imshow( scale, interpolation='None', cmap=pl.cm.gray, origin='lower' )
    	xlims   = pl.xlim()
    	ylims   = pl.ylim()
    	
    	# Parse the WCS keywords in the primary HDU    	
    	w       = wcs.WCS(h)
    	world   = np.transpose([objra, objdec])
    	pixcrd  = w.wcs_world2pix(world, 1)
    	
    	fs = 20
    	fw = 'normal'
    	lw = 2
    	
    	#For each star create a circle and plot in green
    	#If pixel coordinates of star (from WCS conversion of RA and DEC) and within the 
    	#x and y limits, then put text on right side, otherwise put on left
    	for j in range(len(objra)):
    		ctemp = pplib.circle( pixcrd[j][0]/scalefactor, pixcrd[j][1]/scalefactor, aper ).T
    		pl.plot( ctemp[0], ctemp[1], c='#00ff00', lw=lw )
    		if pixcrd[j][0]/scalefactor+40 < xlims[1] and pixcrd[j][1]/scalefactor+20 < ylims[1]:
    			pl.text( pixcrd[j][0]/scalefactor+15, pixcrd[j][1]/scalefactor, `j`, color='#00ff00', fontsize=fs, fontweight=fw )
    		else:
    			pl.text( pixcrd[j][0]/scalefactor-45, pixcrd[j][1]/scalefactor-20, `j`, color='#00ff00', fontsize=fs, fontweight=fw )
    			
    	#Label plot and remove axes, save to filename+.png
    	pl.text( 0.2*xlims[1], 0.9*ylims[1], cfilter+'-Band', color='r', fontsize=fs, fontweight=fw )
        a = pl.gca()
        a.set_frame_on(False)
        a.set_xticks([]); a.set_yticks([])
        pl.axis('off')
        pl.xlim(xlims)
        pl.ylim(ylims)
        fig.set_size_inches(figsize[0], figsize[1])
        ofile = ifile.split('.')[0] + '.png'
        pl.savefig( ofile, bbox_inches='tight', pad_inches=0, transparent=True, dpi=dpi )
        pl.close()
   		
    #Create HTML to do quick look at data
    printhtml.printhtml(filters, names)
コード例 #5
0
def plotphotom(prefchar='coadd'):

    #Initialize arrays
    filters = ['r', 'i', 'z', 'y', 'J', 'H']
    arr_size = 10000

    #Creates a list of names: ['ra', 'dec', '(FILTER)mag', '(FILTER)magerr'] including
    #all filters in filters list
    #Also initializes filter index dictionary for use later
    names = ['ra', 'dec']
    ifiltdict = {}
    for filter in filters:
        names.extend([filter + 'mag', filter + 'magerr'])
        ifiltdict[filter] = -1

    #Create dictionary with keys from names list and all set to np.zeros(arr_size)
    #easily changed for other filters
    plotdict = {}
    for name in names:
        plotdict[name] = np.zeros(arr_size)

    # retrieve detection files
    zffiles = pplib.choosefiles(prefchar + '*_?.ref.multi.fits')

    #Save filter and data from each file into arrays and find overlapping stars
    #between filter files using final photometry file (comparing distances from RA and DEC)
    cfilterarr = []
    imgarr = []
    harr = []

    for i in range(len(zffiles)):

        #Find filter of each file and make sure that has the right capitalization
        cfilter = zffiles[i].split('_')[1].split('.')[0]
        if cfilter == 'Z' or cfilter == 'Y':
            cfilter = cfilter.lower()
        cfilterarr.append(cfilter)

        #Save data scaled by scale factor to imgarr
        ifile = zffiles[i]
        hdulist = pf.open(ifile)
        h = hdulist[0].header
        img = hdulist[0].data
        im_size = np.shape(img)
        scalefactor = 1.
        img = zoom(img, 1. / scalefactor, order=0)
        imgarr.append(img)
        harr.append(h)

        #Read in finalphot[FILTER].am which has the instrument corrected photometry
        pfile = 'finalphot' + cfilter + '.am'
        x, y, ra, dec, mag, magerr = np.loadtxt(pfile, unpack=True)

        clen = len(mag)

        #For first file initialize variables for following files, use temporary variables
        #for comparison
        if i == 0:
            plotdict['ra'][0:clen] = ra
            plotdict['dec'][0:clen] = dec

            plotdict[cfilter + 'mag'][0:clen] = mag
            plotdict[cfilter + 'magerr'][0:clen] = magerr
            nstars = clen
        else:
            compra = ra
            compdec = dec
            compmag = mag
            compmagerr = magerr

            #For each source in file find any sources that are within 1 arcsecond
            #if these exist then store information in same index but different filter's magnitude
            #array.  If these don't exist, put on the end of filter's (and position) arrays
            #to signify a new source

            for j in range(len(compra)):
                smatch = pplib.nearest(
                    compra[j] * np.cos(compdec[j] * np.pi / 180.),
                    compdec[j],
                    plotdict['ra'] * np.cos(plotdict['dec'] * np.pi / 180.),
                    plotdict['dec'],
                    maxdist=1. / 3600.)

                if any(smatch):
                    plotdict[cfilter + 'mag'][smatch] = compmag[j]
                    plotdict[cfilter + 'magerr'][smatch] = compmagerr[j]
                else:
                    plotdict['ra'][nstars] = compra[j]
                    plotdict['dec'][nstars] = compdec[j]
                    plotdict[cfilter + 'mag'][nstars] = compmag[j]
                    plotdict[cfilter + 'magerr'][nstars] = compmagerr[j]
                    nstars += 1

    imgarr = np.array(imgarr)

    #Save stars to finalmags.txt with correct format and removes zeros
    store = np.zeros(nstars)
    for name in names:
        store = np.vstack((store, plotdict[name][:nstars]))

    store = store[1:, :]  #Removes 0's from initialization

    #Finds sources that are cut off on at least one filter using weight maps
    #and checking if 25% of the number of pixels in a 10 pixel radius circle
    #are 0 in the weight map of each filter (i.e. cut off)
    sra = store[0]
    sdec = store[1]
    removesource = []

    for s in np.arange(len(sra)):
        for file in zffiles:
            nzero = 0
            wmultifile = file[:-4] + 'weight.fits'
            hlist = pf.open(wmultifile)
            wdata = hlist[0].data
            wh = hlist[0].header
            w = wcs.WCS(wh)
            spix = w.wcs_world2pix(sra[s], sdec[s], 1)

            wcir = pplib.circle(spix[0], spix[1], 10)
            ncir = len(wcir)
            for coord in wcir:
                if (wh['NAXIS1'] > coord[0] > 0) & (wh['NAXIS2'] > coord[1] >
                                                    0):
                    if wdata[int(coord[1])][int(coord[0])] == 0: nzero += 1
                else:
                    ncir -= 1
            if nzero >= 0.25 * ncir:
                removesource.append(s)
                break

    store = np.delete(store, removesource, axis=1)
    np.savetxt('finalmags.txt', store.T, fmt='%12.6f')

    #Find the index of the file that corresponds to each filter and save
    #to ifiltdict (initialized to -1)
    for item in ifiltdict:
        try:
            ifiltdict[item] = cfilterarr.index(item)
        except ValueError:
            pass

#Determines colors based on which filters are present.
#Red = J/H, green = z/y, blue = r/i
#If neither filter present, set to 0, if one present, use imgarr of data from that filter
#if both present use half from imgarr of data from each filter

        def fcolor(filt1, filt2, ifiltdict, imgarr):

            if filt1 and filt2 in ifiltdict:
                if ifiltdict[filt1] >= 0 and ifiltdict[filt2] >= 0:
                    x = imgarr[ifiltdict[filt1], :, :] * 0.5 + imgarr[
                        ifiltdict[filt2], :, :] * 0.5
                if ifiltdict[filt1] >= 0 and ifiltdict[filt2] < 0:
                    x = imgarr[ifiltdict[filt1], :, :]
                if ifiltdict[filt2] >= 0 and ifiltdict[filt1] < 0:
                    x = imgarr[ifiltdict[filt2], :, :]
                if ifiltdict[filt2] < 0 and ifiltdict[filt1] < 0:
                    x = 0
            else:
                print 'Valid filters were not supplied, set color to 0'
                x = 0

            return x

    red = fcolor('J', 'H', ifiltdict, imgarr)
    green = fcolor('z', 'y', ifiltdict, imgarr)
    blue = fcolor('r', 'i', ifiltdict, imgarr)

    #Determine image size base on if color filter exists (priority: red, green, blue in that order)
    if np.size(red) > 1:
        im_size = np.shape(red)
    elif np.size(green) > 1:
        im_size = np.shape(green)
    elif np.size(blue) > 1:
        im_size = np.shape(blue)

    def bytearr(x, y, z):
        return np.zeros((x, y, z)).astype(np.uint8)

    #Create color of image and save to color.png
    color = bytearr(im_size[0], im_size[1], 3)

    #Changes color into bytescale range and saves to color array
    if np.size(blue) > 1:
        blue = bytescale(blue, 0, 8, 250)
        color[:, :, 2] = blue * 0.5
    if np.size(green) > 1:
        green = bytescale(green, 0, 8, 250)
        color[:, :, 1] = green * 0.5
    if np.size(red) > 1:
        red = bytescale(red, 0, 8, 250)
        color[:, :, 0] = red * 0.5

    color = color[::-1, :]
    fig = pl.figure('color image')
    pl.axis('off')
    pl.imshow(color, interpolation='None', origin='lower')
    sp.misc.imsave('color.png', color)

    #Find aperture size to make circles around sources that match sextractor aperture
    pline = ''
    sfile = open('ratir_weighted.sex', 'r')
    for line in sfile:
        if 'PHOT_APERTURES' in line: pline = line
    sfile.close()

    bpline = pline.split()

    if len(bpline) != 0:
        aper = int(bpline[1]) / 2.0  #radius
    else:
        aper = 10

    objra = store[0]
    objdec = store[1]

    #Plot each image with circles on star identification
    for i in range(len(zffiles)):
        ifile = zffiles[i]
        img = imgarr[i]
        h = harr[i]
        cfilter = cfilterarr[i]

        scale = bytescale(img, 0, 10, 255)
        dpi = 72.  # px per inch
        figsize = (np.array(img.shape) / dpi)[::-1]
        fig = pl.figure(i)

        pl.imshow(scale, interpolation='None', cmap=pl.cm.gray, origin='lower')
        xlims = pl.xlim()
        ylims = pl.ylim()

        # Parse the WCS keywords in the primary HDU
        w = wcs.WCS(h)
        world = np.transpose([objra, objdec])
        pixcrd = w.wcs_world2pix(world, 1)

        fs = 20
        fw = 'normal'
        lw = 2

        #For each star create a circle and plot in green
        #If pixel coordinates of star (from WCS conversion of RA and DEC) and within the
        #x and y limits, then put text on right side, otherwise put on left
        for j in range(len(objra)):
            ctemp = pplib.circle(pixcrd[j][0] / scalefactor,
                                 pixcrd[j][1] / scalefactor, aper).T
            pl.plot(ctemp[0], ctemp[1], c='#00ff00', lw=lw)
            if pixcrd[j][0] / scalefactor + 40 < xlims[
                    1] and pixcrd[j][1] / scalefactor + 20 < ylims[1]:
                pl.text(pixcrd[j][0] / scalefactor + 15,
                        pixcrd[j][1] / scalefactor, ` j `,
                        color='#00ff00',
                        fontsize=fs,
                        fontweight=fw)
            else:
                pl.text(pixcrd[j][0] / scalefactor - 45,
                        pixcrd[j][1] / scalefactor - 20, ` j `,
                        color='#00ff00',
                        fontsize=fs,
                        fontweight=fw)

        #Label plot and remove axes, save to filename+.png
        pl.text(0.2 * xlims[1],
                0.9 * ylims[1],
                cfilter + '-Band',
                color='r',
                fontsize=fs,
                fontweight=fw)
        a = pl.gca()
        a.set_frame_on(False)
        a.set_xticks([])
        a.set_yticks([])
        pl.axis('off')
        pl.xlim(xlims)
        pl.ylim(ylims)
        fig.set_size_inches(figsize[0], figsize[1])
        ofile = ifile.split('.')[0] + '.png'
        pl.savefig(ofile,
                   bbox_inches='tight',
                   pad_inches=0,
                   transparent=True,
                   dpi=dpi)
        pl.close()

    #Create HTML to do quick look at data
    printhtml.printhtml(filters, names)
コード例 #6
0
def printhtml(filters, colnames, omitted_colnames, headers, headers_names):
    #Reads in final magnitudes
    colgrab = np.loadtxt('./finalmags.txt', unpack=True)

    #Store each column into dictionary based on colnames and create header for HTML header from colnames
    plotdict = {}
    t = '<tr><th>#</th>'
    for i in np.arange(len(colnames)):
        plotdict[colnames[i]] = colgrab[i, :]
        if not (colnames[i] in omitted_colnames):
            t = t + '<th>' + colnames[i] + '</th>'
    t = t + '</tr>\n'

    colors = [
        'black', 'purple', 'blue', 'aqua', 'green', 'orange', 'red', 'yellow',
        'magenta'
    ]
    print 'Plotting AB Magnitude comparison'
    plot_mag(filters, plotdict, colors)
    print 'Plotting SEDs'
    plot_seds(filters)

    #Create html page that displays images made in plotphotom.py and values from finalmags.txt
    f = open('./photom.html', 'w')
    f.write('<!DOCTYPE HTML>\n')
    f.write('<HTML>\n')
    f.write('<HEAD>\n')
    f.write('<TITLE>PHOTOMETRY DATA</TITLE>\n')
    f.write('</HEAD>\n')
    f.write('<BODY BGCOLOR="#FFFFFF" TEXT="#003300">\n')

    #Finds filter image files with green circles over sources and writes to HTML
    prefchar = 'coadd'
    zffiles = pplib.choosefiles(prefchar + '*_?.png')

    im_wid = 400

    f.write('<IMG SRC="./color.png" width="' + ` im_wid ` + '"><BR>\n')
    for i in range(len(zffiles)):
        f.write('<IMG SRC="./' + zffiles[i] + '" width="' + ` im_wid ` +
                '">\n')
        if (i + 1) % 3 == 0:
            f.write('<BR>\n')

    #Write table with header info from each image
    f.write('<BR>\n')
    f.write(generate_headers_table(headers, headers_names))
    f.write('<BR>\n')

    f.write(
        '<BR><HR><FONT SIZE="+2" COLOR="#006600">AB System Photometry (sources within 1 arcmin):</FONT><BR>\n'
    )
    f.write(
        'Notes: Non-zero magnitudes with uncertainty of zero are 3-sigma upper limits.  Sources with magnitudes of 0.0000 are unobserved.<BR>\n'
    )
    f.write(
        '       Circles in images above match aperture size used in sextractor.<BR>\n'
    )
    f.write('<BR>\n')

    #Writes table with all magnitudes
    f.write('<table border="1" width="100%">\n')

    f.write(t)
    for j in np.arange(len(plotdict[colnames[0]])):
        f.write('<tr><td>{:.0f}</td>'.format(j))
        for col in colnames:
            if not (col in omitted_colnames):
                f.write('<td>{:.3f}</td>'.format(plotdict[col][j]))
        f.write('<tr>\n')
    f.write('</table>\n')

    f.write('<BR><HR>\n')
    f.write(
        '<table><tbody><tr><td><IMG SRC="photcomp.plot.png"/></td></tr></tbody></table>\n'
    )
    f.write('<BR><HR>\n')

    f.write('</BODY>\n')
    f.write('</HTML>\n')
    f.close()
コード例 #7
0
ファイル: photom.py プロジェクト: aancheta/RATIR-GSFC
def photom():

	#Identify files (must have same number of images files as weight files)
	prefchar    = 'coadd'
	zffiles     = pplib.choosefiles(prefchar + '*_?.fits')
	weightfiles = pplib.choosefiles(prefchar + '*_?.weight.fits')
	
	if len(zffiles) > len(weightfiles):
		print 'Must have matching weight file to each image file to run automatic crop.'
		print 'To use manual crop user manualcrop keyword and change crop values by hand'
		return -1
		
	numfiles = len(zffiles)
		
	#Resample all images using SWarp to a reference image called multicolor using weight files
	swarpstr = ''
	for i in range(numfiles):		
		swarpstr = swarpstr + zffiles[i] + ' '

	stackcmd = 'swarp ' + swarpstr + '-DELETE_TMPFILES N -WRITE_XML N -SUBTRACT_BACK N -WEIGHT_TYPE MAP_WEIGHT -IMAGEOUT_NAME multicolor.fits -WEIGHTOUT_NAME multicolor.weight.fits'
	stackcmd = stackcmd + ' -COPY_KEYWORDS OBJECT,TARGNAME,TELESCOP,FILTER,INSTRUME,OBSERVAT,PIXSCALE,ORIGIN,CCD_TYPE,JD,DATE-OBS,AIRMASS,FLATFLD,FLATTYPE,SEEPIX,ABSZPT,ABSZPTSC,ABSZPRMS'
	print stackcmd
	os.system( stackcmd )

	#Rename all the resampled files to crop files
	for i in range(numfiles):
		tmp = zffiles[i].split('.')[0]
		ifile = tmp + '.resamp.fits'
		ofile = tmp + '.ref.fits'
		mvcmd = 'mv -f ' + ifile + ' ' + ofile
		os.system(mvcmd)
		
		ifile = tmp + '.resamp.weight.fits'
		ofile = tmp + '.ref.weight.fits'
		mvcmd = 'mv -f ' + ifile + ' ' + ofile
		os.system(mvcmd)

	#CHANGE FOR RIMAS
	coaddfiles = pplib.choosefiles('coadd*_?.ref.fits')

	ra1arr  = []
	dec1arr = []
	ra2arr  = []
	dec2arr = []

	#Finds the RA and DEC of the first and the last pixel of each cropped coadded file
	for files in coaddfiles:

		fitsfile = pf.open(files)
		fitsheader = fitsfile[0].header
		data = fitsfile[0].data
	
		imSize = shape(data)
	
		#Converts pixel value to RA and DEC using header information (AstroPy function)
		w = wcs.WCS(fitsheader)
		pixcrd = [[0.,0.], [imSize[1]-1.0, imSize[0]-1.0]]
		[[ra1,dec1],[ra2,dec2]] = w.wcs_pix2world(pixcrd, 0)
	
		#Stores information into arrays
		ra1arr.append(ra1)
		dec1arr.append(dec1)
		ra2arr.append(ra2)
		dec2arr.append(dec2)

	#Finds the coordinates that fit all of the data
	raleft  = min(ra1arr)
	raright = max(ra2arr)
	decbot  = max(dec1arr)
	dectop  = min(dec2arr)

	#Crops data so the size of every filter image matches and saves to file 'coadd*.multi.fits'
	#Same for weight file
	for files in coaddfiles:

		newfile = files[:-4]+'multi.fits'
		fitsfile = pf.open(files)
		fitsheader = fitsfile[0].header
		data = fitsfile[0].data
	
		w = wcs.WCS(fitsheader)
		[[x1,y1],[x2,y2]] = w.wcs_world2pix([[raleft, decbot], [raright, dectop]], 0)
		
		pplib.hextractlite(newfile, data, fitsheader, x1+1, x2, y1+1, y2)
		
		wnewfile = files[:-4]+'multi.weight.fits'
		wfitsfile = pf.open(files[:-4]+'weight.fits')
		wfitsheader = wfitsfile[0].header
		wdata = wfitsfile[0].data
	
		w = wcs.WCS(wfitsheader)
		[[x1,y1],[x2,y2]] = w.wcs_world2pix([[raleft, decbot], [raright, dectop]], 0)
		
		pplib.hextractlite(wnewfile, wdata, wfitsheader, x1+1, x2, y1+1, y2)

	#Crops the multicolor (data file and weight) fits files to match the same coordinates
	mixfile = 'multicolor.fits'
	mixfitsfile = pf.open(mixfile)
	mixfitsheader = mixfitsfile[0].header
	mixdata = mixfitsfile[0].data

	mixw = wcs.WCS(mixfitsheader)
	[[mx1,my1],[mx2,my2]] = mixw.wcs_world2pix([[raleft, decbot], [raright, dectop]], 0)
	pplib.hextractlite(mixfile, mixdata, mixfitsheader, mx1+1, mx2, my1+1, my2)

	wmixfile = mixfile[:-4]+'weight.fits'
	wmixfitsfile = pf.open(wmixfile)
	wmixfitsheader = wmixfitsfile[0].header
	wmixdata = wmixfitsfile[0].data

	wmixw = wcs.WCS(wmixfitsheader)
	[[wmx1,wmy1],[wmx2,wmy2]] = mixw.wcs_world2pix([[raleft, decbot], [raright, dectop]], 0)
	pplib.hextractlite(wmixfile, wmixdata, wmixfitsheader, wmx1+1, wmx2, wmy1+1, wmy2)	

	#Find directory where this python code is located
	propath = os.path.dirname(os.path.realpath(__file__))
	
	#Make sure configuration file is in current working directory, if not copy it from
	#location where this code is stored
	if not os.path.exists('ratir_weighted.sex'): 
		os.system('cp '+propath+'/defaults/ratir_weighted.sex .')
	
	if not os.path.exists('weightedtemp.param'): 
		os.system('cp '+propath+'/defaults/weightedtemp.param .')
		
	if not os.path.exists('ratir.conv'): 
		os.system('cp '+propath+'/defaults/ratir.conv .')
				
	if not os.path.exists('ratir_nir.nnw'): 
		os.system('cp '+propath+'/defaults/ratir_nir.nnw .')

	#Uses sextractor to find the magnitude and location of sources for each file
	#Saves this information into 'fluxes_*.txt' files
	for files in coaddfiles:

		hdr = pf.getheader(files)
		filter = hdr['FILTER']
		abszpt = hdr['ABSZPT']
		abszprms = hdr['ABSZPRMS']
		pixscale = hdr['PIXSCALE']

		#Finds filter name and makes sure it is capitalized correctly		
		filter = files.split('_')[1].split('.')[0]
	
		if filter.lower() in ('j','h','k'):
			filter = filter.upper()
		else:
			filter = filter.lower()
		
		compfile = files[:-4]+'multi.fits'

		#Call to sextractor in double image mode (image1 used for detection of sources, image2 only for measurements - must be same size) 
		#"sex image1,image2 -c configuration file" uses multicolor file for source detection and filter file for magnitude measurements
		os.system('sex ' + mixfile + ',' + compfile + ' -WEIGHT_IMAGE '+ wmixfile+','+compfile[:-4]+'weight.fits' + \
			' -c ratir_weighted.sex -SEEING_FWHM 1.5 -PIXEL_SCALE '+str(pixscale)+' -DETECT_THRESH 3.0 -ANALYSIS_THRESH 3.0 -PHOT_APERTURES ' + \
			str(hdr['SEEPIX']*1.38)+ ' -MAG_ZEROPOINT ' + str(hdr['ABSZPT']))
		os.system('mv -f temp.cat fluxes_'+filter+'.txt')
		
		#Columns unpacked for fluxes*.txt are: (x,y,ra,dec,mag,magerr,e,fwhm,flags)
		sexout = np.loadtxt('fluxes_'+filter+'.txt', unpack=True)
		
		magcol = 4
		magerrcol = 5
		
		tout = np.transpose(sexout[0:6,:]) #Only include through magerr
		for i in np.arange(len(tout[:,magerrcol])):
			tout[i,magerrcol] = max(tout[i,magerrcol], 0.01)
		
		tout[:,magerrcol] = np.sqrt(tout[:,magerrcol]**2 + abszprms**2)

		tsorted =  tout[np.argsort(tout[:,magcol])]
			
		#Creates Absolute Magnitude file with coordinates
		amfile = 'finalphot'+filter+'.am'		
		np.savetxt(amfile, tsorted, fmt='%15.6f', 
			header='X\t Y\t RA\t DEC\t CAL_MAG\t CAL_MAG_ERR\t')
コード例 #8
0
ファイル: photom.py プロジェクト: ancheetah/RATIR-GSFC
def photom():

    #Identify files (must have same number of images files as weight files)
    prefchar = 'coadd'
    zffiles = pplib.choosefiles(prefchar + '*_?.fits')
    weightfiles = pplib.choosefiles(prefchar + '*_?.weight.fits')

    if len(zffiles) > len(weightfiles):
        print 'Must have matching weight file to each image file to run automatic crop.'
        print 'To use manual crop user manualcrop keyword and change crop values by hand'
        return -1

    numfiles = len(zffiles)

    #Resample all images using SWarp to a reference image called multicolor using weight files
    swarpstr = ''
    for i in range(numfiles):
        swarpstr = swarpstr + zffiles[i] + ' '

    stackcmd = 'swarp ' + swarpstr + '-DELETE_TMPFILES N -WRITE_XML N -SUBTRACT_BACK N -WEIGHT_TYPE MAP_WEIGHT -IMAGEOUT_NAME multicolor.fits -WEIGHTOUT_NAME multicolor.weight.fits'
    stackcmd = stackcmd + ' -COPY_KEYWORDS OBJECT,TARGNAME,TELESCOP,FILTER,INSTRUME,OBSERVAT,PIXSCALE,ORIGIN,CCD_TYPE,JD,DATE-OBS,AIRMASS,FLATFLD,FLATTYPE,SEEPIX,ABSZPT,ABSZPTSC,ABSZPRMS'
    print stackcmd
    os.system(stackcmd)

    #Rename all the resampled files to crop files
    for i in range(numfiles):
        tmp = zffiles[i].split('.')[0]
        ifile = tmp + '.resamp.fits'
        ofile = tmp + '.ref.fits'
        mvcmd = 'mv -f ' + ifile + ' ' + ofile
        os.system(mvcmd)

        ifile = tmp + '.resamp.weight.fits'
        ofile = tmp + '.ref.weight.fits'
        mvcmd = 'mv -f ' + ifile + ' ' + ofile
        os.system(mvcmd)

    #CHANGE FOR RIMAS
    coaddfiles = pplib.choosefiles('coadd*_?.ref.fits')

    ra1arr = []
    dec1arr = []
    ra2arr = []
    dec2arr = []

    #Finds the RA and DEC of the first and the last pixel of each cropped coadded file
    for files in coaddfiles:

        fitsfile = pf.open(files)
        fitsheader = fitsfile[0].header
        data = fitsfile[0].data

        imSize = shape(data)

        #Converts pixel value to RA and DEC using header information (AstroPy function)
        w = wcs.WCS(fitsheader)
        pixcrd = [[0., 0.], [imSize[1] - 1.0, imSize[0] - 1.0]]
        [[ra1, dec1], [ra2, dec2]] = w.wcs_pix2world(pixcrd, 0)

        #Stores information into arrays
        ra1arr.append(ra1)
        dec1arr.append(dec1)
        ra2arr.append(ra2)
        dec2arr.append(dec2)

    #Finds the coordinates that fit all of the data
    raleft = min(ra1arr)
    raright = max(ra2arr)
    decbot = max(dec1arr)
    dectop = min(dec2arr)

    #Crops data so the size of every filter image matches and saves to file 'coadd*.multi.fits'
    #Same for weight file
    for files in coaddfiles:

        newfile = files[:-4] + 'multi.fits'
        fitsfile = pf.open(files)
        fitsheader = fitsfile[0].header
        data = fitsfile[0].data

        w = wcs.WCS(fitsheader)
        [[x1, y1],
         [x2, y2]] = w.wcs_world2pix([[raleft, decbot], [raright, dectop]], 0)

        pplib.hextractlite(newfile, data, fitsheader, x1 + 1, x2, y1 + 1, y2)

        wnewfile = files[:-4] + 'multi.weight.fits'
        wfitsfile = pf.open(files[:-4] + 'weight.fits')
        wfitsheader = wfitsfile[0].header
        wdata = wfitsfile[0].data

        w = wcs.WCS(wfitsheader)
        [[x1, y1],
         [x2, y2]] = w.wcs_world2pix([[raleft, decbot], [raright, dectop]], 0)

        pplib.hextractlite(wnewfile, wdata, wfitsheader, x1 + 1, x2, y1 + 1,
                           y2)

    #Crops the multicolor (data file and weight) fits files to match the same coordinates
    mixfile = 'multicolor.fits'
    mixfitsfile = pf.open(mixfile)
    mixfitsheader = mixfitsfile[0].header
    mixdata = mixfitsfile[0].data

    mixw = wcs.WCS(mixfitsheader)
    [[mx1, my1],
     [mx2, my2]] = mixw.wcs_world2pix([[raleft, decbot], [raright, dectop]], 0)
    pplib.hextractlite(mixfile, mixdata, mixfitsheader, mx1 + 1, mx2, my1 + 1,
                       my2)

    wmixfile = mixfile[:-4] + 'weight.fits'
    wmixfitsfile = pf.open(wmixfile)
    wmixfitsheader = wmixfitsfile[0].header
    wmixdata = wmixfitsfile[0].data

    wmixw = wcs.WCS(wmixfitsheader)
    [[wmx1, wmy1],
     [wmx2, wmy2]] = mixw.wcs_world2pix([[raleft, decbot], [raright, dectop]],
                                        0)
    pplib.hextractlite(wmixfile, wmixdata, wmixfitsheader, wmx1 + 1, wmx2,
                       wmy1 + 1, wmy2)

    #Find directory where this python code is located
    propath = os.path.dirname(os.path.realpath(__file__))

    #Make sure configuration file is in current working directory, if not copy it from
    #location where this code is stored
    if not os.path.exists('ratir_weighted.sex'):
        os.system('cp ' + propath + '/defaults/ratir_weighted.sex .')

    if not os.path.exists('weightedtemp.param'):
        os.system('cp ' + propath + '/defaults/weightedtemp.param .')

    if not os.path.exists('ratir.conv'):
        os.system('cp ' + propath + '/defaults/ratir.conv .')

    if not os.path.exists('ratir_nir.nnw'):
        os.system('cp ' + propath + '/defaults/ratir_nir.nnw .')

    #Uses sextractor to find the magnitude and location of sources for each file
    #Saves this information into 'fluxes_*.txt' files
    for files in coaddfiles:

        hdr = pf.getheader(files)
        filter = hdr['FILTER']
        abszpt = hdr['ABSZPT']
        abszprms = hdr['ABSZPRMS']
        pixscale = hdr['PIXSCALE']

        #Finds filter name and makes sure it is capitalized correctly
        filter = files.split('_')[1].split('.')[0]

        if filter.lower() in ('j', 'h', 'k'):
            filter = filter.upper()
        else:
            filter = filter.lower()

        compfile = files[:-4] + 'multi.fits'

        #Call to sextractor in double image mode (image1 used for detection of sources, image2 only for measurements - must be same size)
        #"sex image1,image2 -c configuration file" uses multicolor file for source detection and filter file for magnitude measurements
        os.system('sex ' + mixfile + ',' + compfile + ' -WEIGHT_IMAGE '+ wmixfile+','+compfile[:-4]+'weight.fits' + \
         ' -c ratir_weighted.sex -SEEING_FWHM 1.5 -PIXEL_SCALE '+str(pixscale)+' -DETECT_THRESH 3.0 -ANALYSIS_THRESH 3.0 -PHOT_APERTURES ' + \
         str(hdr['SEEPIX']*1.38)+ ' -MAG_ZEROPOINT ' + str(hdr['ABSZPT']))
        os.system('mv -f temp.cat fluxes_' + filter + '.txt')

        #Columns unpacked for fluxes*.txt are: (x,y,ra,dec,mag,magerr,e,fwhm,flags)
        sexout = np.loadtxt('fluxes_' + filter + '.txt', unpack=True)

        magcol = 4
        magerrcol = 5

        tout = np.transpose(sexout[0:6, :])  #Only include through magerr
        for i in np.arange(len(tout[:, magerrcol])):
            tout[i, magerrcol] = max(tout[i, magerrcol], 0.01)

        tout[:, magerrcol] = np.sqrt(tout[:, magerrcol]**2 + abszprms**2)

        tsorted = tout[np.argsort(tout[:, magcol])]

        #Creates Absolute Magnitude file with coordinates
        amfile = 'finalphot' + filter + '.am'
        np.savetxt(amfile,
                   tsorted,
                   fmt='%15.6f',
                   header='X\t Y\t RA\t DEC\t CAL_MAG\t CAL_MAG_ERR\t')
コード例 #9
0
def printhtml(filters, colnames):

    #Reads in final magnitudes
    colgrab = np.loadtxt('./finalmags.txt', unpack=True)

    #Store each column into dictionary based on colnames and create header for HTML header from colnames
    plotdict = {}
    t = '<tr><th>#</th>'
    for i in np.arange(len(colnames)):
        plotdict[colnames[i]] = colgrab[i, :]
        t = t + '<th>' + colnames[i] + '</th>'

    t = t + '<tr>\n'

    colors = [
        'black', 'purple', 'blue', 'aqua', 'green', 'orange', 'red', 'yellow',
        'magenta'
    ]

    pl.figure()
    pl.xlim([15, 22])
    pl.ylim([-0.01, 0.2])

    #For each filter, plot mag vs. error for photocomp.png
    counter = 0
    for filter in filters:
        pl.plot(plotdict[filter + 'mag'],
                plotdict[filter + 'magerr'],
                marker='o',
                linestyle='None',
                label=filter,
                color=colors[counter])
        counter = counter + 1

    pl.xlabel('AB Magnitude')
    pl.ylabel(r"$\Delta$ Mag")
    pl.legend(loc='lower right')
    pl.savefig('photcomp.png', bbox_inches='tight')
    pl.clf()

    #Create html page that displays images made in plotphotom.py and values from finalmags.txt
    f = open('./photom.html', 'w')
    f.write('<!DOCTYPE HTML>\n')
    f.write('<HTML>\n')
    f.write('<HEAD>\n')
    f.write('<TITLE>PHOTOMETRY DATA</TITLE>\n')
    f.write('</HEAD>\n')
    f.write('<BODY BGCOLOR="#FFFFFF" TEXT="#003300">\n')

    #Finds filter image files with green circles over sources and writes to HTML
    prefchar = 'coadd'
    zffiles = pplib.choosefiles(prefchar + '*_?.png')

    im_wid = 400

    f.write('<IMG SRC="./color.png" width="' + ` im_wid ` + '"><BR>\n')
    for i in range(len(zffiles)):
        f.write('<IMG SRC="./' + zffiles[i] + '" width="' + ` im_wid ` +
                '">\n')
        if (i + 1) % 3 == 0:
            f.write('<BR>\n')

    f.write(
        '<BR><HR><FONT SIZE="+2" COLOR="#006600">AB System Photometry (sources within 1 arcmin):</FONT><BR>\n'
    )
    f.write(
        'Notes: Non-zero magnitudes with uncertainty of zero are 3-sigma upper limits.  Sources with magnitudes of 0.0000 are unobserved.<BR>\n'
    )
    f.write(
        '		 Circles in images above match aperture size used in sextractor.<BR>\n'
    )
    f.write('<br />\n')

    #Writes table with all magnitudes
    f.write('<table border="1" width="100%">\n')

    f.write(t)
    for j in np.arange(len(plotdict[colnames[0]])):
        f.write('<tr><td>{:.0f}</td>'.format(j))
        for col in colnames:
            f.write('<td>{:.3f}</td>'.format(plotdict[col][j]))
        f.write('<tr>\n')
    f.write('</table>\n')

    f.write('</PRE><BR><HR>\n')
    f.write('<IMG SRC="photcomp.png">\n')
    f.write('</PRE><BR><HR>\n')

    f.write('</BODY>\n')
    f.write('</HTML>\n')
    f.close()