Exemple #1
0
def make_SDSS_field_cutout(ra, dec, plate_num, width=3.1, scale=5.5):
    '''
    use gz2tools's image downloader

    width argument is *in degrees*, and download_sloan_im takes width and height in pixels (with scale in arcsec)

    NOTE: there seems to be an artificial limit of 2400*2400 pix. Current defaults seem to play nice, but be careful!
    '''

    plt.close('all')
    img = download_sloan_im(ra, dec, scale=scale, width=(width*3600.)//scale,
                            height=(width*3600.)//scale)
    print img.shape, (width*3600.)//scale
    ralims = [sum(i) for i in zip([ra, ] * 2, [width/2., -width/2.])]
    declims = [sum(i) for i in zip([dec, ] * 2, [-width/2., width/2.])]

    if (ralims[0] > 360.) & (ralims[1] < 360.):
        transform = True
        ralims = [i - 360. for i in ralims]
        ra -= 360.
    else:
        transform = False

    fig = plt.figure(figsize=(8.5, 8.), dpi=100)
    ax = fig.add_subplot(111)

    ax.imshow(img, origin='upper', aspect='equal',
              extent=ralims + declims)

    # add in plate shape and center post
    plate = plt.Circle((ra, dec), 1.49, color='w', fill=False)
    ax.add_artist(plate)

    # read in locations of objects on plate
    plate_objs = table.Table.read(str(plate_num) + '.csv', format='csv',
                                  comment='\#')

    if transform == True:
        plate_objs['ra'][plate_objs['ra'] > 180.] -= 360.

    stars = plate_objs[plate_objs['class'] == 'STAR']
    QSOs = plate_objs[plate_objs['class'] == 'QSO']
    galaxies = plate_objs[plate_objs['class'] == 'GALAXY']

    # add locations of objects on plate
    ax.scatter(stars['ra'], stars['dec'],
               marker='D', facecolor='none', edgecolor='b',
               label='Stars')
    ax.scatter(QSOs['ra'], QSOs['dec'],
               marker='o', facecolor='none', edgecolor='g',
               label='QSOs')
    ax.scatter(galaxies['ra'], galaxies['dec'],
               marker='v', facecolor='none', edgecolor='r',
               label='Galaxies')
    plt.legend(loc='best')

    # make everything look nice
    ax.set_xlabel('RA [deg]', size=20)
    ax.set_ylabel('Dec [deg]', size=20)
    ax.set_title('Plate {}'.format(plate_num), size=20)
    ax.set_xlim(ralims)
    ax.set_ylim(declims)

    ax.tick_params(axis='both', colors='white')
    ax.xaxis.set_tick_params(width=4, length=12)
    ax.yaxis.set_tick_params(width=4, length=12)
    for tick in ax.xaxis.get_major_ticks():
        tick.label.set_color('k')
        tick.label.set_fontsize(20)
    for tick in ax.yaxis.get_major_ticks():
        tick.label.set_color('k')
        tick.label.set_fontsize(20)

    plt.tight_layout()
    plt.savefig(str(plate_num) + '.png')
Exemple #2
0
def make_SDSS_field_mpld3(ra, dec, plate_num, width=3.1, scale=5.5):
    '''
    use gz2tools's image downloader to show SDSS field with fibers overlaid

    on click, opens the corresponding SDSS Explore page

    width argument is *in degrees*, and download_sloan_im takes width and height in pixels (with scale in arcsec)

    NOTE: there seems to be an artificial limit of 2400*2400 pix. Current defaults seem to play nice, but be careful!
    '''

    # Define some CSS to control our custom labels
    css = """
    table
    {
      border-collapse: collapse;
      width: 100%;
    }
    th
    {
      color: #ffffff;
      background-color: #000000;
    }
    td
    {
      background-color: #cccccc;
    }
    table, th, td
    {
      font-family:Arial, Helvetica, sans-serif;
      border: 1px solid black;
      text-align: right;
    }
    """

    plt.close('all')
    img = download_sloan_im(ra, dec, scale=scale, width=(width*3600.)//scale,
                            height=(width*3600.)//scale)
    # print img.shape, (width*3600.)//scale
    ralims = [sum(i) for i in zip([ra, ] * 2, [width/2., -width/2.])]
    declims = [sum(i) for i in zip([dec, ] * 2, [-width/2., width/2.])]

    if (ralims[0] > 360.) & (ralims[1] < 360.):
        transform = True
        ralims = [i - 360. for i in ralims]
        ra -= 360.
    else:
        transform = False

    fig = plt.figure(figsize=(8.5, 8.), dpi=100)
    ax = fig.add_subplot(111)

    ax.imshow(img, origin='upper', aspect='equal',
              extent=ralims + declims)

    # read in locations of objects on plate
    plate_objs = table.Table.read(str(plate_num) + '.csv', format='csv',
                                  comment='\#')
    plate_objs = pd.read_csv(str(plate_num) + '.csv', comment='#')

    url_base = \
        'http://skyserver.sdss.org/dr12/en/tools/explore/summary.aspx?id='

    plate_objs['urls'] = pd.Series(
        b + str(i) for (b, i) in zip(
            [url_base, ]*len(plate_objs), plate_objs['targetObjID']))

    if transform == True:
        plate_objs['ra'][plate_objs['ra'] > 180.] -= 360.

    stars = plate_objs[plate_objs['class'] == 'STAR']
    QSOs = plate_objs[plate_objs['class'] == 'QSO']
    galaxies = plate_objs[plate_objs['class'] == 'GALAXY']

    # add locations of objects on plate

    stars_points = ax.scatter(stars['ra'], stars['dec'],
                              marker='D', edgecolors='b', facecolors='none',
                              label='Stars')
    QSOs_points = ax.scatter(QSOs['ra'], QSOs['dec'],
                             marker='o', edgecolors='g', facecolors='none',
                             label='QSOs')
    galaxies_points = ax.scatter(galaxies['ra'], galaxies['dec'],
                                 marker='v', edgecolors='r', facecolors='none',
                                 label='Galaxies')
    points = ax.scatter(plate_objs['ra'], plate_objs['dec'],
                        edgecolors='none', facecolors='none')

    # make everything look nice
    ax.set_xlabel('RA [deg]', size=20)
    ax.set_ylabel('Dec [deg]', size=20)
    ax.set_title('Plate {}'.format(plate_num), size=20)
    ax.set_xlim(ralims)
    ax.set_ylim(declims)

    ax.tick_params(axis='both', colors='white')
    ax.xaxis.set_tick_params(width=4, length=12)
    ax.yaxis.set_tick_params(width=4, length=12)
    for tick in ax.xaxis.get_major_ticks():
        tick.label.set_color('k')
        tick.label.set_fontsize(20)
    for tick in ax.yaxis.get_major_ticks():
        tick.label.set_color('k')
        tick.label.set_fontsize(20)

    plt.tight_layout()

    labels = []
    for i in range(len(plate_objs)):
        label = plate_objs.iloc[i].T
        label = pd.DataFrame({'Row {0}'.format(i): label})
        # .to_html() is unicode; so make leading 'u' go away with str()
        labels.append(str(label.to_html()))

    tooltip = plugins.PointHTMLTooltip(points, labels, voffset=10, hoffset=10,
                                       css=css)
    plugins.connect(fig, tooltip)
    plugins.connect(fig, ClickInfo(points, list(plate_objs['urls'])))

    mpld3.save_html(fig, str(plate_num) + '.html')