Пример #1
0
def plot_vhs_tiles(table=None,ra=None, dec=None,
    wrap_ra24hr=False, PA=90.0, overplot=True, savefig=True):
    """

    table is astropy table
    ra, dec in degrees

    """

    plot_polygon=True

    if wrap_ra24hr:
        angle=Angle(xdata * u.deg)
        angle.wrap_at('180d', inplace=True)
        xdata=angle.degree

    # assumes filename is in table.meta
    print('plotting: ', table.meta['filename'])
    filename = table.meta['filename']

    if not plot_polygon:
      plt.plot(xdata, ydata, 's', ms=7.0,
       color='yellow', markeredgecolor='yellow',
       alpha=0.1,
       label='OB Progress (submitted)\n' + filename)

    if plot_polygon:
      plt.plot(xdata, ydata, '.', ms=7.0,
       color='yellow', markeredgecolor='yellow',
       alpha=0.1,
       label='OB Progress (submitted):' + filename)

      # filled polygon
      ra=xdata
      dec=ydata
      for i in range(len(ra)):
        if i==0 or i == len(ra): print('i: ', i)
        ra_poly, dec_poly=plt_tile.mk_polytile(ra_cen=ra[i], dec_cen=dec[i],
         coverage='twice', PA=PA)

        xypolygon=np.column_stack((ra_poly, dec_poly))
        if i==0 or i == len(ra):
          print('xypolygon.shape: ',   xypolygon.shape)
          print('xypolygon: ',xypolygon)

        polygon = Polygon(xypolygon, True, color='green', alpha=0.1)
        plt.gca().add_patch(polygon)

        #print(ob_table.meta)

      plt.suptitle(dqcfile_vhs)
      plt.legend(fontsize='small')

      figname='vhs_des_check_progress_vhs_obprogress_'+ datestamp + '.png'
      print('Saving: '+figname)
      plt.savefig(plotdir+figname)
      plt.suptitle('')
Пример #2
0
def aitoff_test(ra, dec):
    """

    """
    # aitoff example
    ra = ra * 15.0
    c = SkyCoord(ra=ra * u.degree, dec=dec * u.degree, frame='icrs')
    ra_rad = c.ra.wrap_at(180.0 * u.degree).radian
    dec_rad = c.dec.radian

    plt.figure(figsize=(8.0, 6.0))
    plt.clf()
    plt.subplot(111, projection="aitoff")
    plt.title("Aitoff projection of our random data")
    plt.grid(True)
    plt.plot(ra_rad, dec_rad, 'o', markersize=2, alpha=0.5)
    plt.subplots_adjust(top=0.90, bottom=0.0)
    figname = 'ob_progress_aitoff.png'
    print('Saving: ' + figname)
    plt.savefig(figname)

    print('Elapsed time(secs):', time.time() - t0)

    if showplot:
        plt.show()


    aitoff = True
    PA = 90.0
    color = 'blue'
    alpha = 1.0
    debug = False
    plt.figure(figsize=(8.0, 6.0))
    plt.subplot(111, projection="aitoff")
    plt.title("Aitoff projection of our random data")
    plt.grid(True)
    for i in range(len(ra)):
        if i == 0 or i == len(ra):
            print('i:', i)
        (ra_poly, dec_poly) = plt_tile.mk_polytile(
            ra_cen=ra[i], dec_cen=dec[i],
            coverage='twice', PA=PA)
        if debug:
            print('Elapsed time(secs): ', time.time() - t0)

        if aitoff:
            # convert to wrapped radians
            c = SkyCoord(ra=ra_poly, dec=dec_poly,
                         unit=(u.deg, u.deg), frame='icrs')
            ra_poly = c.ra.wrap_at(180 * u.deg).radian
            dec_poly = c.dec.radian
            if debug:
                print('ra_poly:', i, len(ra_poly), ra_poly)
                print('Elapsed time(secs):', time.time() - t0)

        xypolygon = np.column_stack((ra_poly, dec_poly))
        if i == 0 or i == len(ra):
            print('xypolygon.shape:', xypolygon.shape)
            print('xypolygon:', xypolygon)

        # http://matplotlib.org/api/patches_api.html#matplotlib.patches.Polygon
        polygon = Polygon(
            xypolygon, closed=True,
            edgecolor='none', facecolor=color, alpha=alpha)
        plt.gca().add_patch(polygon)
        # this does nothing
        plt.set_label = 'label test for polygon'

    plt.subplots_adjust(top=0.90, bottom=0.0)
    figname = 'ob_progress_aitoff_polygons.png'
    print('Saving:' + figname)
    plt.savefig('./' + figname)

    print('Elapsed time(secs):', time.time() - t0)

    print('Plotting the shaded tiles')

    if showplot:
        plt.show()
Пример #3
0
def plot_vista_tiles(table=None, ra=None, dec=None, PA=90.0,
                     raUnits='degree', wrap_ra24hr=False, aitoff=False,
                     filename=None,
                     title=None, xlabel=None, ylabel=None, label=None,
                     verbose=False, debug=False,
                     color=None, alpha=None,
                     overplot=False,
                     savefig=True, plotdir=None, figfile=None,
                     showplot=False, pause=False,
                     suffix=None,
                     rarange=[0.0, 24.0], decrange=[-90.0, 10.0],
                     figsize=(12.0, 6.0)):
    """
    see also librgm.plot_radec
    table is an astropy table
    INPUT: ra, dec in degrees

    """

    trace = traceback.extract_stack()[-2]
    print(os.path.basename(trace[0]), ':', str(trace[1]))
    trace = traceback.extract_stack()[-1]
    print(os.path.basename(trace[0]), ':', str(trace[1]))

    trace = traceback.extract_stack()
    print(trace)

    t0 = time.time()
    print('Elapsed time(secs): ', time.time() - t0)

    print('plot_vista_tiles: label;', label)
    plot_polygon = True

    # configure for aitoff
    if aitoff:
        raUnits = 'radian'
        wrap_ra24hr = False

    # matplotlib aitoff only support full sky
    if rarange is None and not aitoff:
        plt.xlim([0, 24.0])
        if raUnits == 'degree':
            plt.xlim([0, 360.0])
    if rarange is not None and not aitoff:
        plt.xlim(rarange)

    if decrange is None and not aitoff:
        plt.ylim([-90, 30])
    if decrange is not None and not aitoff:
        plt.ylim(decrange)

    print('rarange:  ', rarange)
    print('decrange: ', decrange)

    if alpha is None:
        alpha = 1.0
    if color is None:
        color = 'green'

    if not overplot:
        # plt.clf()
        plt.figure(num=None, figsize=figsize)
        if aitoff:
            plt.subplot(111, projection="aitoff")

    if raUnits == 'degree':
        plt.xlabel('RA (degree)')
    if raUnits == 'hour':
        plt.xlabel('RA (hour)')
    if xlabel is not None:
        plt.xlabel(xlabel)
    plt.ylabel('Declination (degree)')
    if ylabel is not None:
        plt.ylabel(ylabel)
    # if title != None: plt.title(title)

    xdata = ra
    ydata = dec
    ndata = len(ra)

    print('RA range: ', np.min(xdata), np.max(xdata))
    print('Dec range:', np.min(ydata), np.max(ydata))

    # convert to degrees for polygon and wrap calc
    if raUnits == 'hour':
        xdata = xdata * 15.0

    print('RA range: ', np.min(xdata), np.max(xdata))
    print('Dec range:', np.min(ydata), np.max(ydata))
    if wrap_ra24hr:
        angle = Angle(xdata * u.deg)
        angle.wrap_at('180d', inplace=True)
        xdata = angle.degree

    print('RA range: ', np.min(xdata), np.max(xdata))
    print('Dec range:', np.min(ydata), np.max(ydata))

    print('Elapsed time(secs): ', time.time() - t0)

    # assumes filename is in table.meta
    if table is None and filename is None:
        filename = ''
    if table is not None:
        filename = table.meta['filename']
        print('plotting: ', filename)

    if not plot_polygon:
        if raUnits == 'hour':
            xdata = xdata / 15.0
        plt.plot(xdata, ydata, 's', ms=7.0,
                 color='yellow', markeredgecolor='yellow',
                 alpha=alpha,
                 label='OB Progress (submitted):' + str(ndata))
    print('Elapsed time(secs):', time.time() - t0)

    # phantom  plot to get the label onto legend
    if plot_polygon:
        if label is None:
            label = ''
        else:
            label = label + ': ' + str(ndata)

        plt.plot([-999], [-999], 's', ms=0.1,
                 color=color, markeredgecolor=color,
                 alpha=alpha, label=label)
        plt.grid()

    # do not plot the polygon when color = 'none' as used for adding info
    # to the legend
    if plot_polygon and color != 'none':
        if raUnits == 'hour':
            xdata = xdata / 15.0

        # filled polygon
        ra = xdata
        dec = ydata
        if raUnits == 'hour':
            ra = ra * 15.0
        print('Elapsed time(secs): ', time.time() - t0)
        for i in range(len(ra)):
            if i == 0 or i == len(ra):
                print('i: ', i)
            ra_poly, dec_poly = plt_tile.mk_polytile(
                ra_cen=ra[i], dec_cen=dec[i],
                coverage='twice', PA=PA)

            if raUnits == 'hour':
                ivertex = -1
                if debug:
                    print('ra_poly: ', ra_poly)
                for vertex in ra_poly:
                    ivertex = ivertex + 1
                    ra_poly[ivertex] = ra_poly[ivertex] / 15.0
                if debug:
                    print('ra_poly: ', ra_poly)

            if debug:
                print('Elapsed time(secs): ', time.time() - t0)
            if aitoff:
                # convert to wrapped radians
                ivertex = -1
                if debug:
                    print('ra_poly: ', ra_poly)
                for vertex in ra_poly:
                    ivertex = ivertex + 1
                    c = SkyCoord(ra=ra_poly[ivertex],
                                 dec=dec_poly[ivertex], unit=(u.deg, u.deg),
                                 frame='icrs')
                    ra_poly[ivertex] = c.ra.wrap_at(180 * u.deg).radian
                    dec_poly[ivertex] = c.dec.radian
                if debug:
                    print('ra_poly: ', ra_poly)
                    print('Elapsed time(secs): ', time.time() - t0)

            xypolygon = np.column_stack((ra_poly, dec_poly))
            if i == 0 or i == len(ra):
                print('xypolygon.shape:', xypolygon.shape)
                print('xypolygon:', xypolygon)

            # http://matplotlib.org/api/patches_api.html#matplotlib.patches.Polygon
            polygon = Polygon(xypolygon, closed=True,
                              edgecolor='none', facecolor=color, alpha=alpha)
            plt.gca().add_patch(polygon)
            # this does nothing
            plt.set_label = 'label test for polygon'

    print('Elapsed time(secs):', time.time() - t0)

    plt.title(filename)
    plt.legend(fontsize='small', markerscale=50,
               scatterpoints=1, numpoints=1, ncol=2, loc='upper center',
               prop={'family': 'monospace', 'size': 'small'})
    plt.grid()


    if savefig:
        datestamp = time.strftime("%Y%m%d", gmtime())
        if plotdir is None:
            plotdir = ''
        plotid(progname=True)
        prefix = os.path.splitext(__file__)[0]
        if suffix is None:
            suffix = ''
        if suffix is not None:
            suffix = suffix + '_'
        suffix = os.path.basename(filename) + '_' + suffix
        figname = prefix + '_' + suffix + \
            'radec_vista_tiles_' + datestamp + '.png'
        print('Saving:' + figname)
        plt.savefig(plotdir + figname)

    if pause:
        raw_input("Enter any key to continue: ")

    if showplot:
        plt.show()
Пример #4
0
def plot_vhs_tiles(table=None,
                   ra=None,
                   dec=None,
                   wrap_ra24hr=False,
                   PA=90.0,
                   overplot=True,
                   savefig=True):
    """

    table is astropy table
    ra, dec in degrees

    """

    plot_polygon = True

    if wrap_ra24hr:
        angle = Angle(xdata * u.deg)
        angle.wrap_at('180d', inplace=True)
        xdata = angle.degree

    # assumes filename is in table.meta
    print('plotting: ', table.meta['filename'])
    filename = table.meta['filename']

    if not plot_polygon:
        plt.plot(xdata,
                 ydata,
                 's',
                 ms=7.0,
                 color='yellow',
                 markeredgecolor='yellow',
                 alpha=0.1,
                 label='OB Progress (submitted)\n' + filename)

    if plot_polygon:
        plt.plot(xdata,
                 ydata,
                 '.',
                 ms=7.0,
                 color='yellow',
                 markeredgecolor='yellow',
                 alpha=0.1,
                 label='OB Progress (submitted):' + filename)

        # filled polygon
        ra = xdata
        dec = ydata
        for i in range(len(ra)):
            if i == 0 or i == len(ra): print('i: ', i)
            ra_poly, dec_poly = plt_tile.mk_polytile(ra_cen=ra[i],
                                                     dec_cen=dec[i],
                                                     coverage='twice',
                                                     PA=PA)

            xypolygon = np.column_stack((ra_poly, dec_poly))
            if i == 0 or i == len(ra):
                print('xypolygon.shape: ', xypolygon.shape)
                print('xypolygon: ', xypolygon)

            polygon = Polygon(xypolygon, True, color='green', alpha=0.1)
            plt.gca().add_patch(polygon)

            #print(ob_table.meta)

        plt.suptitle(dqcfile_vhs)
        plt.legend(fontsize='small')

        figname = 'vhs_des_check_progress_vhs_obprogress_' + datestamp + '.png'
        print('Saving: ' + figname)
        plt.savefig(plotdir + figname)
        plt.suptitle('')
Пример #5
0
def plot_sadt_tile(sadtfile=None,
                   sadtfiles=None,
                   sadtfile_path=None,
                   xlimits=None,
                   ylimits=None,
                   raUnits=None,
                   color='orange'):
    """

  """

    from astropy.table import vstack

    print('plot_sadt_file:')
    if xlimits is None: xlimits = (-180.0, 180.0)
    if ylimits is None: ylimits = (-90.0, 2.0)
    print('xlimits: ', xlimits)
    print('ylimits: ', ylimits)

    print('sadtfile:', sadtfile)
    print('sadtfiles:', sadtfiles)
    print('sadtfile_path:', sadtfile_path)

    raw_input("Enter any key to continue: ")

    # read a single sadtfile
    if sadtfile_path is None and sadtfiles is None:
        sadt = rd_sadt(infile=sadtfile, csv=False)
        print('Path: ', os.path.dirname(sadtfile))
        sadt.meta['inpath'] = os.path.dirname(sadtfile)
        sadt.meta['filename'] = sadtfile

    if sadtfile_path is not None or sadtfiles is not None:

        if sadtfiles is None:
            filelist = os.listdir(sadtfile_path)
        if sadtfiles is not None:
            filelist = sadtfiles

        print('sadtfile_path: ', sadtfile_path)
        print('filelist:', filelist)
        ifile = 0
        for file in filelist:
            ifile = ifile + 1
            print('reading file: ', file)
            #if sadtfile_path is not None:
            #    sadtfile = sadtfile_path + '/' + file
            #if sadtfile_path is None:
            #   sadtfile = file
            sadtfile = file

            if ifile == 1: sadt = rd_sadt(infile=sadtfile, csv=False)
            print('Number of SADT tiles: ', len(sadt))
            if ifile > 1:
                temp = rd_sadt(infile=sadtfile, csv=False)
                print('Number of SADT tiles: ', len(temp))
                sadt = vstack([sadt, temp])
                print('Number of SADT tiles: ', len(sadt))
                del temp

            print('Path: ', os.path.dirname(sadtfile))
            sadt.meta['inpath'] = os.path.dirname(sadtfile)
            sadt.meta['filename' + str(ifile)] = sadtfile

    print('Number of SADT tiles: ', len(sadt))
    print(sadt.colnames)

    raw_input("Enter any key to continue: ")

    xdata = sadt['ra']
    ydata = sadt['dec']
    print('xrange: ', np.min(xdata), np.max(xdata))
    print('yrange: ', np.min(ydata), np.max(ydata))
    print('ndata: ', len(xdata))

    ntiles = len(xdata)
    plt.plot(xdata, ydata, '+k', ms=1.0, label='SADT Tiles: ' + str(ntiles))
    plt.title(desfile)
    plt.suptitle(sadtfile)
    plotid(progname=True)
    plt.grid()
    plt.legend(markerscale=2.0, fontsize='medium')

    # filled polygon
    ra = xdata
    dec = ydata
    for i in range(len(ra)):
        if i == 0 or i == len(ra): print('i: ', i)

        ra_poly, dec_poly = plt_tile.mk_polytile(ra_cen=ra[i],
                                                 dec_cen=dec[i],
                                                 coverage='twice')

        xypolygon = np.column_stack((ra_poly, dec_poly))
        if i == 0 or i == len(ra):
            print('xypolygon.shape: ', xypolygon.shape)
            print('xypolygon: ', xypolygon)

        polygon = Polygon(xypolygon, True, color=color, alpha=0.2)
        plt.gca().add_patch(polygon)

        ra_poly, dec_poly = plt_tile.mk_polytile(ra_cen=ra[i],
                                                 dec_cen=dec[i],
                                                 coverage='single')

        xypolygon = np.column_stack((ra_poly, dec_poly))
        if i == 0 or i == len(ra):
            print('xypolygon.shape: ', xypolygon.shape)
            print('xypolygon: ', xypolygon)

        polygon = Polygon(xypolygon, True, color=color, alpha=0.1)
        plt.gca().add_patch(polygon)

    plt.xlim(xlimits)
    plt.ylim(ylimits)

    print('xlimits: ', xlimits)
    print('ylimits: ', ylimits)

    plotdir = './'
    figname = 'vhs_des_check' + '_sadt_' + datestamp + '.png'
    print('Saving: ' + figname)
    plt.savefig(plotdir + figname)
Пример #6
0
def plot_sadt_tile(sadtfile=None, sadtfiles=None, sadtfile_path=None,
                   xlimits=None, ylimits=None, raUnits=None,
                   color='orange'):
  """

  """

  from astropy.table import vstack

  print('plot_sadt_file:')
  if xlimits is None: xlimits=(-180.0,180.0)
  if ylimits is None: ylimits=(-90.0,2.0)
  print('xlimits: ', xlimits)
  print('ylimits: ', ylimits)


  print('sadtfile:', sadtfile)
  print('sadtfiles:', sadtfiles)
  print('sadtfile_path:', sadtfile_path)

  raw_input("Enter any key to continue: ")

  # read a single sadtfile
  if sadtfile_path is None and sadtfiles is None :
    sadt = rd_sadt(infile=sadtfile, csv=False)
    print('Path: ', os.path.dirname(sadtfile))
    sadt.meta['inpath']=os.path.dirname(sadtfile)
    sadt.meta['filename']=sadtfile

  if sadtfile_path is not None or sadtfiles is not None:

    if sadtfiles is None:
        filelist = os.listdir(sadtfile_path)
    if sadtfiles is not None:
        filelist = sadtfiles

    print('sadtfile_path: ', sadtfile_path)
    print('filelist:', filelist)
    ifile=0
    for file in filelist:
      ifile=ifile+1
      print('reading file: ', file)
      #if sadtfile_path is not None:
      #    sadtfile = sadtfile_path + '/' + file
      #if sadtfile_path is None:
      #   sadtfile = file
      sadtfile = file


      if ifile == 1: sadt=rd_sadt(infile=sadtfile, csv=False)
      print('Number of SADT tiles: ', len(sadt))
      if ifile > 1:
          temp=rd_sadt(infile=sadtfile, csv=False)
          print('Number of SADT tiles: ', len(temp))
          sadt=vstack([sadt, temp])
          print('Number of SADT tiles: ', len(sadt))
          del temp

      print('Path: ', os.path.dirname(sadtfile))
      sadt.meta['inpath']=os.path.dirname(sadtfile)
      sadt.meta['filename'+str(ifile)]=sadtfile


  print('Number of SADT tiles: ', len(sadt))
  print(sadt.colnames)

  raw_input("Enter any key to continue: ")

  xdata=sadt['ra']
  ydata=sadt['dec']
  print('xrange: ', np.min(xdata), np.max(xdata))
  print('yrange: ', np.min(ydata), np.max(ydata))
  print('ndata: ', len(xdata))

  ntiles=len(xdata)
  plt.plot(xdata, ydata, '+k', ms=1.0, label='SADT Tiles: ' + str(ntiles))
  plt.title(desfile)
  plt.suptitle(sadtfile)
  plotid(progname=True)
  plt.grid()
  plt.legend(markerscale=2.0, fontsize='medium')

  # filled polygon
  ra=xdata
  dec=ydata
  for i in range(len(ra)):
      if i==0 or i == len(ra): print('i: ', i)

      ra_poly, dec_poly=plt_tile.mk_polytile(ra_cen=ra[i], dec_cen=dec[i],
       coverage='twice')

      xypolygon=np.column_stack((ra_poly, dec_poly))
      if i==0 or i == len(ra):
        print('xypolygon.shape: ',   xypolygon.shape)
        print('xypolygon: ',xypolygon)

      polygon = Polygon(xypolygon, True, color=color, alpha=0.2)
      plt.gca().add_patch(polygon)

      ra_poly, dec_poly=plt_tile.mk_polytile(ra_cen=ra[i], dec_cen=dec[i],
       coverage='single')

      xypolygon=np.column_stack((ra_poly, dec_poly))
      if i==0 or i == len(ra):
        print('xypolygon.shape: ',   xypolygon.shape)
        print('xypolygon: ',xypolygon)

      polygon = Polygon(xypolygon, True, color=color, alpha=0.1)
      plt.gca().add_patch(polygon)

  plt.xlim(xlimits)
  plt.ylim(ylimits)


  print('xlimits: ', xlimits)
  print('ylimits: ', ylimits)


  plotdir='./'
  figname='vhs_des_check'+ '_sadt_'+ datestamp + '.png'
  print('Saving: '+figname)
  plt.savefig(plotdir+figname)