Exemple #1
0
def main(inp, survey='2r', radec=None, deci=None, fpath=None, show_circ=True,
         EPOCH=0., DSS=None, BW=False, imsize=5.*astrou.arcmin, show_spec=False,
         OUT_TYPE='PDF', show_another=None):
    '''
    Parameters:
    ---------
    inp: Input
       string or List of strings or List of several items
       'ra_dec_list.txt' -- ASCII file with columns of Name,RA,DEC and RA,DEC are string or float (deg)
        ['NAME_OF_TARG', '10:31:38.87', '+25:59:02.3']
        ['NAME_OF_TARG', 124.24*u.deg, -23.244*u.deg]
        ['NAME_OF_TARG', SkyCoord]
    radec: integer (0) [DEPRECATED!]
       Flag indicating type of input
       0 = ASCII file with columns of Name,RA,DEC and RA,DEC are string or float (deg)
       1 = List of string ['Name', 'RA', 'DEC']  
       2 = ['Name', ra_deg, dec_deg]
    BW: bool (False)
       B&W image?
    show_circ: bool (True)
       Show a yellow circle on the target
    show_another : tuple, optional
       RA,DEC for another target to circle (e.g. offset star)
    show_spec: bool (False)
       Try to grab and show an SDSS spectrum 
    imsize: Quantity, optional
       Image size 
    OUT_TYPE: str, optional  
       File type -- 'PDF', 'PNG'
    '''
    reload(x_r)
    reload(xgs)
    import matplotlib.pyplot as plt
    import matplotlib.cm as cm

    # Init
    if fpath is None:
        fpath = './'
    try:
        imsize=imsize.to('arcmin').value
    except AttributeError:
        raise AttributeError('finder: Input imsize needs to be an Angle')
    cradius = imsize / 50. 

    # Read in the Target list
    if isinstance(inp,basestring):
        raise NotImplementedError("No longer implemented")
        #ra_tab = get_coord(targ_file, radec=radec)
    else:
        ira_tab = {}
        ira_tab['Name'] = inp[0]
        if isinstance(inp[1],basestring):
            ra, dec = x_r.stod1((inp[1],inp[2]))
            ira_tab['RA'] = ra
            ira_tab['DEC'] = dec
        elif isinstance(inp[1],float):
            ira_tab['RA'] = inp[1] * astrou.deg
            ira_tab['DEC'] = inp[2]* astrou.deg
        elif isinstance(inp[1],SkyCoord):
            ira_tab['RA'] = inp[1].ra.deg
            ira_tab['DEC'] = inp[1].dec.deg
        else: # Should check it is a Quantity
            ira_tab['RA'] = inp[1]
            ira_tab['DEC'] = inp[2]
        # Strings
        ras,decs = x_r.dtos1((ira_tab['RA'],ira_tab['DEC']))
        ira_tab['RAS'] = ras
        ira_tab['DECS'] = decs
        # Make a list
        ra_tab = [ira_tab]

    # Grab ra, dec in decimal degrees
    if deci is not None: 
        return

    #xdb.set_trace()
    #x_r.stod(ra_tab) #ra_tab['RA'][q], ra_tab['DEC'][q], TABL)

    # Precess (as necessary)
    if EPOCH > 1000.:
        from astropy import units as u
        from astropy.coordinates import FK5
        from astropy.time import Time
        # Precess to 2000.
        tEPOCH = Time(EPOCH, format='jyear', scale='utc')
        # Load into astropy
        fk5c = FK5(ra=ra_tab['RA'], dec=ra_tab['DEC'], equinox=tEPOCH, unit=(u.degree,u.degree))
        # Precess
        newEPOCH = Time(2000., format='jyear', scale='utc')
        newfk5 = fk5c.precess_to(newEPOCH)
        # Save
        ra_tab['RA'] = newfk5.ra.degree
        ra_tab['DEC'] = newfk5.dec.degree
        # Strings too?
        ra_tab['RAS'] = str(newfk5.ra.to_string(unit=u.hour,sep=':'))
        ra_tab['DECS'] = str(newfk5.dec.to_string(unit=u.hour,sep=':'))
            
    
    ## 
    # Main Loop
    for obj in ra_tab: 

        # Outfil
        nm = "".join(obj['Name'].split()) 
        if OUT_TYPE=='PNG':
            outfil = fpath+ nm + '.png'
        else:
            outfil = fpath+ nm + '.pdf'
        print(outfil)

        # Grab the Image
        reload(xgs)
        img, oBW = xgs.getimg(obj['RA'], obj['DEC'], imsize, BW=BW,DSS=DSS)

        # Generate the plot
        plt.clf()
        fig = plt.figure(dpi=1200)
        fig.set_size_inches(8.0,10.5)

        # Font
        plt.rcParams['font.family']= 'times new roman'
        ticks_font = matplotlib.font_manager.FontProperties(family='times new roman', 
           style='normal', size=16, weight='normal', stretch='normal')
        ax = plt.gca()
        for label in ax.get_yticklabels() :
            label.set_fontproperties(ticks_font)
        for label in ax.get_xticklabels() :
            label.set_fontproperties(ticks_font)

        # Image
        if oBW == 1: 
            cmm = cm.Greys_r
        else: 
            cmm = None 
        plt.imshow(img,cmap=cmm,aspect='equal',extent=(-imsize/2., imsize/2, -imsize/2.,imsize/2))

        # Axes
        plt.xlim(-imsize/2., imsize/2.)
        plt.ylim(-imsize/2., imsize/2.)

        # Label
        plt.xlabel('Relative ArcMin', fontsize=20)
        xpos = 0.12*imsize
        ypos = 0.02*imsize
        plt.text(-imsize/2.-xpos, 0., 'EAST', rotation=90.,fontsize=20)
        plt.text(0.,imsize/2.+ypos, 'NORTH', fontsize=20, horizontalalignment='center')

        #import pdb; pdb.set_trace()

        # Circle
        if show_circ:
            circle=plt.Circle((0,0),cradius,color='y', fill=False)
            plt.gca().add_artist(circle)

        # Second Circle
        if show_another is not None:
            # Coordinates
            cobj = x_r.to_coord((obj['RA'],obj['DEC']))
            canother = x_r.to_coord(show_another)
            # Offsets
            off, PA = x_r.offsets(cobj, canother)
            xanother = -1*off[0].to('arcmin').value
            yanother = off[1].to('arcmin').value
            square=matplotlib.patches.Rectangle((xanother-cradius,
                                                 yanother-cradius),
                                                cradius*2,cradius*2,color='cyan', fill=False)
            plt.gca().add_artist(square)
            plt.text(0.5, 1.24, str(nm), fontsize=32,
                 horizontalalignment='center',transform=ax.transAxes)
            plt.text(0.5, 1.18, 'RA (J2000) = '+str(obj['RAS'])+
                     '  DEC (J2000) = '+str(obj['DECS']), fontsize=22,
                     horizontalalignment='center',transform=ax.transAxes)
            plt.text(0.5, 1.12, 'RA(offset) = {:s}  DEC(offset) = {:s}'.format(
                     canother.ra.to_string(unit=astrou.hour,pad=True,sep=':', precision=2),
                     canother.dec.to_string(pad=True, alwayssign=True, sep=':', precision=1)),
                     fontsize=22, horizontalalignment='center',transform=ax.transAxes,
                     color='blue')
            plt.text(0.5, 1.06, 'RA(offset to obj) = {:g}  DEC(offset to obj) = {:g}'.format(
                     -1*off[0].to('arcsec'), -1*off[1].to('arcsec')),
                      fontsize=18, horizontalalignment='center',transform=ax.transAxes)
        else:
            # Title
            plt.text(0.5,1.24, str(nm), fontsize=32,
                     horizontalalignment='center',transform=ax.transAxes)
            plt.text(0.5,1.16, 'RA (J2000) = '+str(obj['RAS']), fontsize=28,
                     horizontalalignment='center',transform=ax.transAxes)
            plt.text(0.5,1.10, 'DEC (J2000) = '+str(obj['DECS']), fontsize=28,
                     horizontalalignment='center',transform=ax.transAxes)

        # Spectrum??
        if show_spec:
            spec_img = xgs.get_spec_img(obj['RA'], obj['DEC']) 
            plt.imshow(spec_img,extent=(-imsize/2.1, imsize*(-0.1), -imsize/2.1, imsize*(-0.2)))

        # Write
        if show_spec:
            plt.savefig(outfil, dpi=300)
        else:
            plt.savefig(outfil)
        print 'finder: Wrote '+outfil
        plt.close()
        #xdb.set_trace()

    print 'finder: All done.'
    return oBW
Exemple #2
0
def main(inp,
         survey='2r',
         radec=None,
         deci=None,
         fpath=None,
         show_circ=True,
         EPOCH=0.,
         DSS=None,
         BW=False,
         imsize=5. * astrou.arcmin,
         show_spec=False,
         OUT_TYPE='PDF',
         show_another=None):
    '''
    Parameters:
    ---------
    inp: Input
       string or List of strings or List of several items
       'ra_dec_list.txt' -- ASCII file with columns of Name,RA,DEC and RA,DEC are string or float (deg)
        ['NAME_OF_TARG', '10:31:38.87', '+25:59:02.3']
        ['NAME_OF_TARG', 124.24*u.deg, -23.244*u.deg]
        ['NAME_OF_TARG', SkyCoord]
    radec: integer (0) [DEPRECATED!]
       Flag indicating type of input
       0 = ASCII file with columns of Name,RA,DEC and RA,DEC are string or float (deg)
       1 = List of string ['Name', 'RA', 'DEC']  
       2 = ['Name', ra_deg, dec_deg]
    BW: bool (False)
       B&W image?
    show_circ: bool (True)
       Show a yellow circle on the target
    show_another : tuple, optional
       RA,DEC for another target to circle (e.g. offset star)
    show_spec: bool (False)
       Try to grab and show an SDSS spectrum 
    imsize: Quantity, optional
       Image size 
    OUT_TYPE: str, optional  
       File type -- 'PDF', 'PNG'
    '''
    reload(x_r)
    reload(xgs)
    import matplotlib.pyplot as plt
    import matplotlib.cm as cm

    # Init
    if fpath is None:
        fpath = './'
    try:
        imsize = imsize.to('arcmin').value
    except AttributeError:
        raise AttributeError('finder: Input imsize needs to be an Angle')
    cradius = imsize / 50.

    # Read in the Target list
    if isinstance(inp, basestring):
        raise NotImplementedError("No longer implemented")
        #ra_tab = get_coord(targ_file, radec=radec)
    else:
        ira_tab = {}
        ira_tab['Name'] = inp[0]
        if isinstance(inp[1], basestring):
            ra, dec = x_r.stod1((inp[1], inp[2]))
            ira_tab['RA'] = ra
            ira_tab['DEC'] = dec
        elif isinstance(inp[1], float):
            ira_tab['RA'] = inp[1] * astrou.deg
            ira_tab['DEC'] = inp[2] * astrou.deg
        elif isinstance(inp[1], SkyCoord):
            ira_tab['RA'] = inp[1].ra.deg
            ira_tab['DEC'] = inp[1].dec.deg
        else:  # Should check it is a Quantity
            ira_tab['RA'] = inp[1]
            ira_tab['DEC'] = inp[2]
        # Strings
        ras, decs = x_r.dtos1((ira_tab['RA'], ira_tab['DEC']))
        ira_tab['RAS'] = ras
        ira_tab['DECS'] = decs
        # Make a list
        ra_tab = [ira_tab]

    # Grab ra, dec in decimal degrees
    if deci is not None:
        return

    #xdb.set_trace()
    #x_r.stod(ra_tab) #ra_tab['RA'][q], ra_tab['DEC'][q], TABL)

    # Precess (as necessary)
    if EPOCH > 1000.:
        from astropy import units as u
        from astropy.coordinates import FK5
        from astropy.time import Time
        # Precess to 2000.
        tEPOCH = Time(EPOCH, format='jyear', scale='utc')
        # Load into astropy
        fk5c = FK5(ra=ra_tab['RA'],
                   dec=ra_tab['DEC'],
                   equinox=tEPOCH,
                   unit=(u.degree, u.degree))
        # Precess
        newEPOCH = Time(2000., format='jyear', scale='utc')
        newfk5 = fk5c.precess_to(newEPOCH)
        # Save
        ra_tab['RA'] = newfk5.ra.degree
        ra_tab['DEC'] = newfk5.dec.degree
        # Strings too?
        ra_tab['RAS'] = str(newfk5.ra.to_string(unit=u.hour, sep=':'))
        ra_tab['DECS'] = str(newfk5.dec.to_string(unit=u.hour, sep=':'))

    ##
    # Main Loop
    for obj in ra_tab:

        # Outfil
        nm = "".join(obj['Name'].split())
        if OUT_TYPE == 'PNG':
            outfil = fpath + nm + '.png'
        else:
            outfil = fpath + nm + '.pdf'
        print(outfil)

        # Grab the Image
        reload(xgs)
        img, oBW = xgs.getimg(obj['RA'], obj['DEC'], imsize, BW=BW, DSS=DSS)

        # Generate the plot
        plt.clf()
        fig = plt.figure(dpi=1200)
        fig.set_size_inches(8.0, 10.5)

        # Font
        plt.rcParams['font.family'] = 'times new roman'
        ticks_font = matplotlib.font_manager.FontProperties(
            family='times new roman',
            style='normal',
            size=16,
            weight='normal',
            stretch='normal')
        ax = plt.gca()
        for label in ax.get_yticklabels():
            label.set_fontproperties(ticks_font)
        for label in ax.get_xticklabels():
            label.set_fontproperties(ticks_font)

        # Image
        if oBW == 1:
            cmm = cm.Greys_r
        else:
            cmm = None
        plt.imshow(img,
                   cmap=cmm,
                   aspect='equal',
                   extent=(-imsize / 2., imsize / 2, -imsize / 2., imsize / 2))

        # Axes
        plt.xlim(-imsize / 2., imsize / 2.)
        plt.ylim(-imsize / 2., imsize / 2.)

        # Label
        plt.xlabel('Relative ArcMin', fontsize=20)
        xpos = 0.12 * imsize
        ypos = 0.02 * imsize
        plt.text(-imsize / 2. - xpos, 0., 'EAST', rotation=90., fontsize=20)
        plt.text(0.,
                 imsize / 2. + ypos,
                 'NORTH',
                 fontsize=20,
                 horizontalalignment='center')

        #import pdb; pdb.set_trace()

        # Circle
        if show_circ:
            circle = plt.Circle((0, 0), cradius, color='y', fill=False)
            plt.gca().add_artist(circle)

        # Second Circle
        if show_another is not None:
            # Coordinates
            cobj = x_r.to_coord((obj['RA'], obj['DEC']))
            canother = x_r.to_coord(show_another)
            # Offsets
            off, PA = x_r.offsets(cobj, canother)
            xanother = -1 * off[0].to('arcmin').value
            yanother = off[1].to('arcmin').value
            square = matplotlib.patches.Rectangle(
                (xanother - cradius, yanother - cradius),
                cradius * 2,
                cradius * 2,
                color='cyan',
                fill=False)
            plt.gca().add_artist(square)
            plt.text(0.5,
                     1.24,
                     str(nm),
                     fontsize=32,
                     horizontalalignment='center',
                     transform=ax.transAxes)
            plt.text(0.5,
                     1.18,
                     'RA (J2000) = ' + str(obj['RAS']) + '  DEC (J2000) = ' +
                     str(obj['DECS']),
                     fontsize=22,
                     horizontalalignment='center',
                     transform=ax.transAxes)
            plt.text(0.5,
                     1.12,
                     'RA(offset) = {:s}  DEC(offset) = {:s}'.format(
                         canother.ra.to_string(unit=astrou.hour,
                                               pad=True,
                                               sep=':',
                                               precision=2),
                         canother.dec.to_string(pad=True,
                                                alwayssign=True,
                                                sep=':',
                                                precision=1)),
                     fontsize=22,
                     horizontalalignment='center',
                     transform=ax.transAxes,
                     color='blue')
            plt.text(
                0.5,
                1.06,
                'RA(offset to obj) = {:g}  DEC(offset to obj) = {:g}'.format(
                    -1 * off[0].to('arcsec'), -1 * off[1].to('arcsec')),
                fontsize=18,
                horizontalalignment='center',
                transform=ax.transAxes)
        else:
            # Title
            plt.text(0.5,
                     1.24,
                     str(nm),
                     fontsize=32,
                     horizontalalignment='center',
                     transform=ax.transAxes)
            plt.text(0.5,
                     1.16,
                     'RA (J2000) = ' + str(obj['RAS']),
                     fontsize=28,
                     horizontalalignment='center',
                     transform=ax.transAxes)
            plt.text(0.5,
                     1.10,
                     'DEC (J2000) = ' + str(obj['DECS']),
                     fontsize=28,
                     horizontalalignment='center',
                     transform=ax.transAxes)

        # Spectrum??
        if show_spec:
            spec_img = xgs.get_spec_img(obj['RA'], obj['DEC'])
            plt.imshow(spec_img,
                       extent=(-imsize / 2.1, imsize * (-0.1), -imsize / 2.1,
                               imsize * (-0.2)))

        # Write
        if show_spec:
            plt.savefig(outfil, dpi=300)
        else:
            plt.savefig(outfil)
        print 'finder: Wrote ' + outfil
        plt.close()
        #xdb.set_trace()

    print 'finder: All done.'
    return oBW
Exemple #3
0
def hectospec_targets(field, outfil=None):

    # Init
    fcoord = SkyCoord(ra=field[1],dec=field[2])
    if outfil is None:
        outfil = xcasu.get_filename(field,'HECTO_TARG_FIG')
    # Load field
    lfield = xcasl.load_field(field)
    targ_coord = SkyCoord(ra=lfield.targets['TARG_RA']*u.deg,
        dec=lfield.targets['TARG_DEC']*u.deg)
    all_pa = fcoord.position_angle(targ_coord)
    all_sep = fcoord.separation(targ_coord).to('arcmin')

    # Start the plot
    if outfil is not None: 
        pp = PdfPages(outfil)

    # Targets only
    plt.figure(figsize=(8, 4.5))
    plt.clf()
    gs = gridspec.GridSpec(1,2)

    plt.suptitle('{:s}: Hectospec Targets (from SDSS imaging)'.format(field[0])
        ,fontsize=19.)
    ##
    # Hectospec first
    for tt in range(2):
        ax_hecto = plt.subplot(gs[tt])

        # Read SDSS Image
        if tt == 0:
            imsize=60. # arcmin
        else:
            imsize=10. # arcmin

        #Configs
        if tt == 0:
            hecto_obs = lfield.observing[np.where(
                lfield.observing['INSTR']=='HECTOSPEC')[0]]
            unimsk = np.unique(np.array(hecto_obs['MASK_NAME']))
            for msk in unimsk:
                mt = np.where(hecto_obs['MASK_NAME'] == msk)[0]
                if not hecto_obs['DATE_OBS'].mask[mt[0]]:
                    # RA,DEC
                    rd_off, PA = xra.offsets(fcoord, 
                        (hecto_obs['MASK_RA'][mt[0]],
                        hecto_obs['MASK_DEC'][mt[0]]),verbose=False)
                    # Plot
                    circ = plt.Circle((rd_off[0].to('arcmin').value,
                        rd_off[1].to('arcmin').value), 30., 
                        color='y', fill=False, alpha=0.5)
                    ax_hecto.add_artist(circ)

        # Plot SDSS image
        sdss_img, _ = xosdss.getimg(field[1],field[2], imsize)
        ax_hecto.imshow(sdss_img,aspect='equal',
            extent=(imsize/2., -imsize/2, -imsize/2.,imsize/2))

        # Targets
        hecto_targ = np.where(lfield.targets['INSTR'] == 'HECTOSPEC')[0]
        ddec = all_sep[hecto_targ]*np.cos(all_pa[hecto_targ])
        dra = all_sep[hecto_targ]*np.sin(all_pa[hecto_targ])
        #xdb.set_trace()
        ax_hecto.scatter(dra,ddec, marker='o',color='gray',s=10.,
            facecolor='none',linewidth=0.3, alpha=0.5)
        # Observed
        obs_targ_tab, obs_dict, obs_idx = lfield.get_observed(imsize*u.arcmin,
            subtab=lfield.targets[hecto_targ])
        ax_hecto.scatter(dra[obs_idx],ddec[obs_idx], marker='o',color='gray',s=10.,
            facecolor='none',linewidth=0.3)

        # Labels
        ax_hecto.set_xlabel('Relative ArcMin', fontsize=13)
        ax_hecto.set_ylabel('Relative ArcMin', fontsize=13)
        ax_hecto.set_xlim(imsize/2., -imsize/2.)
        ax_hecto.set_ylim(-imsize/2., imsize/2.)

    plt.tight_layout(pad=0.2,h_pad=0.3,w_pad=0.0)
    if outfil is not None:
        pp.savefig()
        print('Wrote figure: {:s}'.format(outfil))
        pp.close()
    else: 
        plt.show()