Пример #1
0
def col_mag(t1, col1, t2, col2):

	ids = np.where( (t1[col1] > 0.0) & (t1[col1] < 50.0) & (t2[col2] > 0.0) & (t2[col2] < 50.0) )[0]

	fig = plt.figure()
	ax = fig.add_subplot(111)
	plt.plot(t1[col1][ids]-t2[col2][ids], t1[col1][ids], "k.", ms = 2)
	plt.xlabel(col1 + "-" + col2, fontsize = "x-large")
	plt.ylabel(col1, fontsize = "x-large")
	plt.gca().invert_yaxis()
	plotid.plotid()
	info = "Number in table: " + str(len(t1)) + "\nNumber not in graph: " + str(len(t1) - len(ids))
	plt.text(0.05, 0.80, info, transform = ax.transAxes, bbox = dict(facecolor = "white", alpha = 0.7))
	plt.show()
Пример #2
0
def mag_hist(t, col, SG_col = "CLASS_STAR", SG_val = 1):

	stars = np.where( (t[SG_col] == SG_val) )[0]
	ids = np.where( (t[SG_col] == SG_val) & (t[col] > 0.0) & (t[col] < 50))[0]
	print "Number in table:", len(t)
	print "Number not in graph:", len(t) - len(ids)
	print "Number that satisfy classifier:", len(stars)
	print "Number that are junk:", - len(ids) + len(stars)
	fig = plt.figure()
	ax = fig.add_subplot(111)
	info = "Number in table: " + str(len(t)) + "\nNumber not in graph: " + str(len(t) - len(ids)) + "\nNumber that satisfy classifier: " + str(len(stars)) + "\nNumber that are junk: " + str(len(stars)-len(ids))
	plt.text(0.05, 0.80, info, transform = ax.transAxes, bbox = dict(facecolor = "white", alpha = 0.7))
	plt.hist(t[col][ids], bins = 100)
	plt.xlabel(col, fontsize = "x-large")
	plt.ylabel("Number", fontsize = "x-large")
	plotid.plotid()
	plt.show()
Пример #3
0
def fxy(tS,tY,x,y,xlab,ylab,figname,yinvert=False, lim=False,frad=False):
        plt.scatter(tS[x],tS[y],s=1,edgecolor='none',c='#2e64fe', label='SVA1')
        plt.scatter(tY[x],tY[y],s=1,edgecolor='none',c='#ff00a5',label='Y1A1')
        plt.xlabel(xlab,fontsize='17')
        plt.ylabel(ylab,fontsize='17')
        px=np.arange(min(tS[x]),max(tS[x])+1,0.1)
        plt.plot(px,px,c='k')
        if lim:
                plt.xlim(min(tS[x]),np.median(tS[x])+5*(np.std(tS[x])))
		plt.ylim(min(tS[x]),np.median(tS[x])+5*(np.std(tS[x])))
        if frad:
                #plt.xlim(np.median(t[x+'_G'])-(np.std(t[x+'_G'])),np.median(t[x+'_G'])+(np.std(t[x+'_G'])))
                plt.xlim(1.0,12)
		plt.ylim(1.0,12)
	if yinvert:
		plt.ylim(14,26)
                plt.gca().invert_yaxis()
        plt.title(tile)
        plotid()
        plt.legend(prop={'size':10})
        plt.show()
        #plt.savefig(figname)
        plt.clf()
def make_cutouts_multiband(bands='r', detband='detr', 
  imagefiles=None, 
  listfile=None, format='region', width_arcsecs=10.0, 
  catfiles=None):

  """


  """

  import os, sys
  import time

  import pyfits
  import pyregion
  import cutout

  #import fits2png

  import matplotlib.pyplot as plt
  #if not interactive: matplotlib.use('Agg')

  import aplpy

  import plotid

  t0=time.time()

  base=os.path.basename(listfile)
  id=os.path.splitext(base)[0]

  weightmap = False


  # open ds9 region 
  if format == 'region':
    region = pyregion.open(listfile)

    irow=-1
    # print out the cordinates in degrees
    for rows in region:  # iterate over table rows
      irow=irow+1
      print irow+1, region[irow].coord_list[0], region[irow].coord_list[1]
  
    nrows=len(region)

  if format == 'ozdes':
    table= pyfits.getdata(listfile,1)
    ralist = table['RA']
    declist = table['Dec']
    object = table['object']
    comment = table['comment']
    redshift = table['z_fin']
    print 'ralist range: ', min(ralist), max(ralist)
    print 'declist range: ', min(declist), max(declist)
    nrows=len(ralist)

  # Read extension 2 of the catalog file
  ext=2
  catalog = pyfits.getdata(catalog_path+catalog_filename,ext)
  ra_catalog = catalog['alphawin_j2000']
  dec_catalog = catalog['deltawin_j2000']

  title=imagefiles 
  #plt.text(.5, .95, title, horizontalalignment='center') 

  # leave some space to add annotation at the top of the page
  plt.rc('figure.subplot', left=0.05, right=0.95, bottom=0.05, top=0.95, 
   wspace=0.0, hspace=0.0)

  fig=plt.figure(figsize=(12.0, 10.0))

  fig.text(0.1, 0.97, title, horizontalalignment='left', 
   color='blue', transform = plt.gcf().transFigure) 

  plt.xticks=[]
  plt.yticks=[]
  label=os.path.basename(__file__)
  plotid.plotid(label=label)

  nxplots=5
  nyplots=6

  irow=-1
  iplot=0
  

  #print plt.get_gca()
  #print plt.get_gcf()
  isource=0
  ifig=1
  #for rows in region:  # iterate over table rows

  for rows in ralist:  # iterate over table rows
    print 'Elpased time: %.2f seconds' %(time.time() - t0)
    irow=irow+1
    isource=isource+1
    print irow, ' of ', nrows
    #if irow > nxplots*nyplots: break

    if format == 'region':
      ra=region[irow].coord_list[0]
      dec=region[irow].coord_list[1]

    if format == 'ozdes':
      ra=ralist[irow]
      dec=declist[irow]

    iband=-1
    for band in bands:  # iterate over the bands  
      iband=iband+1
      iplot=iplot+1
      outfile='cutout' + str(irow+1) + band + '.fits'
      outfile=None
      verbose=True
      xc=ra
      yc=dec
      imagefile=imagefiles[iband]
      print 'input image: ', imagefile

      # width in arcsecs
      width_arcsecs=10.0
      # convert to semi-width in degrees
      xw=(0.5*width_arcsecs)/3600.0 
      yw=(0.5*width_arcsecs)/3600.0 
    
      # create cutout FITS file
      imagefile=imagefiles[iband]
      image=cutout.cutout(imagefile, xc, yc, xw=xw, yw=yw, units='wcs', 
       outfile=outfile, clobber=True, 
       useMontage=False, coordsys='celestial', verbose=verbose)
      image = image.data

      ax=fig.add_subplot(nxplots,nyplots,iplot,
       frameon=True, xticks=[], yticks=[])
      ax.imshow(image)

      if iband == 0: ax.text(0.1, 0.80, str(isource), 
       transform=plt.gca().transAxes)

      ax.text(0.9, 0.80, band, transform=plt.gca().transAxes)

      if format == 'ozdes':
        annotation=object[isource-1].strip()
        if iband == 0: ax.text(0.1, 0.02, annotation, 
          verticalalignment='baseline',
          transform=plt.gca().transAxes)

        annotation=comment[isource-1].strip()
        if iband == 0: ax.text(0.1, 0.1, annotation, 
          transform=plt.gca().transAxes)

        annotation=str(redshift[isource-1]).strip()
        if iband == 0: ax.text(0.5, 0.1, annotation, 
          transform=plt.gca().transAxes)


      if iplot == nxplots*nyplots:
        print 'nxplots, nyplots, iplot, isource: ', \
         nxplots, nyplots, iplot, isource
        iplot=0
        strfigno= '%4.4d' % (ifig)
        #plt.savefig(id+'_cutouts_multiband_' + str(ifig) + '.png', dpi=150)
        #plt.savefig(id+'_cutouts_multiband_' + strfigno + '.png', dpi=150)
        plt.savefig(id+'_cutouts_multiband_' + strfigno + '.png', dpi=100)

        if ifig == 1: plt.show()
        ifig=ifig+1
        fig=plt.figure(ifig,figsize=(12.0, 10.0))
        plotid.plotid(label=label)

  print 'nxplots, nyplots, iplot, isource: ', \
         nxplots, nyplots, iplot, isource
  iplot=0
  strfigno= '%4.4d' % (ifig)
  #plt.savefig(id+'_cutouts_multiband_' + str(ifig) + '.png', dpi=150)
  #plt.savefig(id+'_cutouts_multiband_' + strfigno + '.png', dpi=150)
  plt.savefig(id+'_cutouts_multiband_' + strfigno + '.png', dpi=100)
transform=plt.gcf().transFigure
transform=plt.gca().transAxes


info='Top Title'*5
def toptitle(text):
  """ 
  Add some text to the top of the page 
  It is added as part of the first subplot 
  """
  plt.text(0.5, 1.10, text, transform=plt.gca().transAxes)

noticks=True

plotid.plotid()

nx=4
ny=5
iplot=0
for iy in range (ny):
  for ix in range (nx):
    iplot += 1  
    if noticks: plt.subplot(nx,ny,iplot,frameon=True, xticks=[], yticks=[])
    #subplot(2,2,1)
    
    if iplot == 1: toptitle(info)     
    if iplot == nx*ny: plotid.plotid() 

    plt.text(0.1, 0.9, str(iplot), transform=plt.gca().transAxes)
Пример #6
0
def multihist(table=None, colname_prefix=None, tile=None, release=None,
        figname=None, lim=False, thetas=False, frad=False):
    """


    """

    plt.subplots_adjust(bottom=0.2, wspace=0.25)
    plt.title(tile + ' ' + release)

    xmin = np.nanmin(table[colname_prefix + '_G'])
    xmax = np.nanmax(table[colname_prefix + '_G'])
    print('column name prefix:', colname_prefix)
    print('minimum (G):', xmin)
    print('maximum (G):', xmax)
    print('range(G):', xmax - xmin)
    print('mean(G):    ', np.nanmean(table[colname_prefix + '_G']))
    print('median(G):  ', np.nanmedian(table[colname_prefix + '_G']))

    binfactor = 20
    if thetas:
        bins = np.arange(np.nanmin(table[colname_prefix + '_G']),
                         np.nanmax(table[colname_prefix + '_G']),
                         np.abs(np.nanmean(table[colname_prefix + '_G'])))
    else:
        bins = np.arange(np.nanmin(table[colname_prefix + '_G']),
                         np.nanmax(table[colname_prefix + '_G']),
                         np.abs(np.nanmean(table[colname_prefix + '_G'])/binfactor))

    bins = 100
    xdata = table[colname_prefix + '_G']
    xdata = xdata[~np.isnan(xdata)]
    plt.hist(xdata, bins,
             histtype='step', color='#2e64fe', label='g')

    # lazy fix
    t = table
    x = colname_prefix
    # bins=np.arange(min(t[x+'_R']),max(t[x+'_R']),np.mean(t[x+'_G'])/10)
    print('Overplotting r')
    xdata = table[colname_prefix + '_R']
    xdata = xdata[~np.isnan(xdata)]
    plt.hist(xdata, bins,
             histtype='step', color='#92cd00',label='r')
    # bins=np.arange(min(t[x+'_I']),max(t[x+'_I']),np.mean(t[x+'_G'])/10)
    print('Overplotting i')
    xdata = table[colname_prefix + '_I']
    xdata = xdata[~np.isnan(xdata)]
    plt.hist(xdata, bins,
             histtype='step', color='#ffbf00', label='i')
    # bins=np.arange(min(t[x+'_Z']),max(t[x+'_Z']),np.mean(t[x+'_G'])/10)
    print('Overplotting z')
    xdata = table[colname_prefix + '_Z']
    xdata = xdata[~np.isnan(xdata)]
    plt.hist(xdata, bins,
             histtype='step', color='#eb7a3c', label='z')
    # bins=np.arange(min(t[x+'_Y']),max(t[x+'_Y']),np.mean(t[x+'_Y'])/10)
    print('Overplotting Y')
    xdata = table[colname_prefix + '_Y']
    xdata = xdata[~np.isnan(xdata)]
    plt.hist(xdata, bins,
             histtype='step', color='#cc0084',label='Y')
    plt.xlabel(x)
    plotid()

    if lim:
                plt.xlim(min(t[x+'_G']),np.median(t[x+'_G'])+5*(np.std(t[x+'_G'])))
    if frad:
                #plt.xlim(np.median(t[x+'_G'])-(np.std(t[x+'_G'])),np.median(t[x+'_G'])+(np.std(t[x+'_G'])))
                plt.xlim(0.0,10)

    plt.legend(prop={'size':10}, loc='upper center',
               bbox_to_anchor=(0.5, -0.15), fancybox=True, shadow=False, ncol=5)

    # plt.show()
    print('Save:', figname)
    plt.savefig(figname)
    plt.clf()