Exemplo n.º 1
0
def fig_cos_dwarfs_images(outfil=None):

    from xastropy.obs import x_getsdssimg as xgs

    # Init COS-Dwarfs, COS-Halos 
    cos_dwarfs = COSDwarfs()
    cos_dwarfs.load_mega(skip_ions=True)
    cos_halos = COSHalos()
    cos_halos.load_mega(skip_ions=True)

    # Start the plot
    if outfil is None:
        outfil='fig_cos_dwarfs_images.pdf'
    pp = PdfPages(outfil)

    dx = 0.2
    dy = 0.40

    fig = plt.figure(figsize=(8, 5))
    fig.clf()
    # Setup for dark
    xpsimp.dark_bkgd(plt)
    gs = gridspec.GridSpec(1, 1)

    # Axes
    ax = plt.subplot(gs[0,0])
    ax.set_xlim(8.0, 11.7) 
    #ax.xaxis.set_major_locator(plt.MultipleLocator(300.))
    ax.set_ylim(-13,-8.2)
    ax.set_ylabel('sSFR')
    ax.set_xlabel('log M*')

    iend = -1
    #iend = 5
    imsize = 0.3 # arcmin
    for cgm_abs in cos_halos.cgm_abs[0:iend]:
        img, oBW = xgs.getimg(cgm_abs.galaxy.coord.ra.deg, 
            cgm_abs.galaxy.coord.dec.deg, imsize=imsize)
        # Figure out placement
        ximg = cgm_abs.galaxy.stellar_mass
        yimg = np.log10(cgm_abs.galaxy.sfr[1])-cgm_abs.galaxy.stellar_mass
        # Show
        scl=2.
        ax.imshow(img,extent=(ximg-dx/scl, ximg+dx/scl, yimg-dy/scl, yimg+dy/scl),aspect=dx/dy)

    iend = -1
    #iend = 5
    imsize = 0.8 # arcmin
    for cgm_abs in cos_dwarfs.cgm_abs[0:iend]:
        img, oBW = xgs.getimg(cgm_abs.galaxy.coord.ra.deg, 
            cgm_abs.galaxy.coord.dec.deg, imsize=imsize)
        # Figure out placement
        ximg = cgm_abs.galaxy.stellar_mass
        yimg = np.log10(cgm_abs.galaxy.sfr[1])-cgm_abs.galaxy.stellar_mass
        # Show
        scl=2.
        ax.imshow(img,extent=(ximg-dx/scl, ximg+dx/scl, yimg-dy/scl, yimg+dy/scl),aspect=dx/dy)



    xputils.set_fontsize(ax,17.)
    # Write
    fig.tight_layout(pad=0.2,h_pad=0.,w_pad=0.1)
    pp.savefig()
    plt.close()

    # Finish
    print('tlk_coshalos: Wrote {:s}'.format(outfil))
    pp.close()
Exemplo n.º 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'):
    '''
    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_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):
        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')

        # 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)
        #import pdb; pdb.set_trace()

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

        # 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
Exemplo n.º 3
0
def main(targ_file, survey='2r', radec=None, deci=None, fpath=None,
         EPOCH=0., DSS=None, BW=False, imsize=5., show_spec=False):
    '''
    Parameters:
    ---------
    targ_file: string or List of string
       ASCII file for targets (Name, RA, DEC)
       or a List 
       Colon separated RA, DEC expected
    radec: integer (0)
       Flag indicating type of input
       0 = ASCII file
       1 = List or ['Name', 'RA', 'DEC']  
    BW: bool (False)
       B&W image?
    show_spec: bool (False)
       Try to grab and show an SDSS spectrum 
    '''
    import radec as x_r
    reload(x_r)
    import matplotlib.pyplot as plt
    import matplotlib.cm as cm

    # Init
    if fpath is None:
        fpath = './'
    cradius = imsize / 50. 

    # Read in the Target list
    ra_tab = get_coord(targ_file, radec=radec)

    # Grab ra, dec in decimal degrees
    if deci != None: 
        return
    # Convert to decimal degress 

    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['RAD'], dec=ra_tab['DECD'], equinox=tEPOCH, unit=(u.degree,u.degree))
        # Precess
        newEPOCH = Time(2000., format='jyear', scale='utc')
        newfk5 = fk5c.precess_to(newEPOCH)
        # Save
        ra_tab['RAD'] = newfk5.ra.degree
        ra_tab['DECD'] = newfk5.dec.degree
        # Strings too?
        ra_tab['RA'] = str(newfk5.ra.to_string(unit=u.hour,sep=':'))
        ra_tab['DEC'] = str(newfk5.dec.to_string(unit=u.hour,sep=':'))
            

    
    ## 
    # Main Loop
    nobj = len(ra_tab) 
    for qq in range(nobj):

        # Outfil
        outfil = fpath+ra_tab['Name'][qq]+'.pdf'
        print(outfil)

        # Grab the Image
        from xastropy.obs import x_getsdssimg as xgs
        reload(xgs)
        img, oBW = xgs.getimg(ra_tab['RAD'][qq], ra_tab['DECD'][qq], 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')

        # Title
        plt.text(0.5,1.24, str(ra_tab['Name'][qq]), fontsize=32, 
        horizontalalignment='center',transform=ax.transAxes)
        plt.text(0.5,1.16, 'RA (J2000) = '+str(ra_tab['RA'][qq]), fontsize=28, 
        horizontalalignment='center',transform=ax.transAxes)
        plt.text(0.5,1.10, 'DEC (J2000) = '+str(ra_tab['DEC'][qq]), fontsize=28, 
        horizontalalignment='center',transform=ax.transAxes)
        #import pdb; pdb.set_trace()

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

        # Spectrum??
        if show_spec:
            spec_img = xgs.get_spec_img(ra_tab['RAD'][qq], ra_tab['DECD'][qq]) 
            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
        #xdb.set_trace()

    print 'finder: All done.'
    return
Exemplo n.º 4
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
Exemplo n.º 5
0
def fig_images(outfil=None):

    from xastropy.obs import x_getsdssimg as xgs

    # Init COS-Halos sightline
    cos_halos = COSHalos()
    cos_halos.load_mega(skip_ions=True)
    #xdb.set_trace()

    # Start the plot
    if outfil is None:
        outfil = 'fig_coshalo_images.pdf'
    pp = PdfPages(outfil)

    dx = 0.2
    dy = 0.55
    imsize = 1.2

    for ss in range(5):
        fig = plt.figure(figsize=(8, 5))
        fig.clf()
        # Setup for dark
        xpsimp.dark_bkgd(plt)
        gs = gridspec.GridSpec(1, 1)

        # Axes
        ax = plt.subplot(gs[0, 0])
        ax.set_xlim(9.4, 11.7)
        #ax.xaxis.set_major_locator(plt.MultipleLocator(300.))
        ax.set_ylim(-13, -9)
        ax.set_ylabel('sSFR')
        ax.set_xlabel('log M*')

        # Plot
        if ss == 0:
            mstar = [
                cgm_abs.galaxy.stellar_mass for cgm_abs in cos_halos.cgm_abs
            ]
            sSFR = [
                np.log10(cgm_abs.galaxy.sfr[1]) - cgm_abs.galaxy.stellar_mass
                for cgm_abs in cos_halos.cgm_abs
            ]
            ax.scatter(mstar, sSFR)
        elif ss == 1:  # Show our first one
            cgm_abs = cos_halos[('J0950+4831', '177_27')]
            img, oBW = xgs.getimg(cgm_abs.galaxy.coord.ra.deg,
                                  cgm_abs.galaxy.coord.dec.deg,
                                  imsize=imsize)
            # Figure out placement
            ximg = cgm_abs.galaxy.stellar_mass
            yimg = np.log10(
                cgm_abs.galaxy.sfr[1]) - cgm_abs.galaxy.stellar_mass
            # Show
            ax.imshow(img,
                      extent=(ximg - dx, ximg + dx, yimg - dy, yimg + dy),
                      aspect=dx / dy)
        elif ss == 2:  # Show two
            cgm_list = [('J0950+4831', '177_27'), ('J1245+3356', '236_36')]
            for icgm in cgm_list:
                cgm_abs = cos_halos[icgm]
                img, oBW = xgs.getimg(cgm_abs.galaxy.coord.ra.deg,
                                      cgm_abs.galaxy.coord.dec.deg,
                                      imsize=imsize)
                # Figure out placement
                ximg = cgm_abs.galaxy.stellar_mass
                yimg = np.log10(
                    cgm_abs.galaxy.sfr[1]) - cgm_abs.galaxy.stellar_mass
                # Show
                ax.imshow(img,
                          extent=(ximg - dx, ximg + dx, yimg - dy, yimg + dy),
                          aspect=dx / dy)
        elif ss >= 3:  # Show half
            if ss == 3:
                iend = 20
            else:
                iend = -1
            for cgm_abs in cos_halos.cgm_abs[0:iend]:
                img, oBW = xgs.getimg(cgm_abs.galaxy.coord.ra.deg,
                                      cgm_abs.galaxy.coord.dec.deg,
                                      imsize=1.2)
                # Figure out placement
                ximg = cgm_abs.galaxy.stellar_mass
                yimg = np.log10(
                    cgm_abs.galaxy.sfr[1]) - cgm_abs.galaxy.stellar_mass
                # Show
                scl = 2.
                ax.imshow(img,
                          extent=(ximg - dx / scl, ximg + dx / scl,
                                  yimg - dy / scl, yimg + dy / scl),
                          aspect=dx / dy)

        xputils.set_fontsize(ax, 17.)
        # Write
        fig.tight_layout(pad=0.2, h_pad=0., w_pad=0.1)
        pp.savefig()
        plt.close()

    # Finish
    print('tlk_coshalos: Wrote {:s}'.format(outfil))
    pp.close()
Exemplo n.º 6
0
def main(inp,
         survey='2r',
         radec=None,
         deci=None,
         fpath=None,
         EPOCH=0.,
         DSS=None,
         BW=False,
         imsize=5.,
         show_spec=False):
    '''
    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]
    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_spec: bool (False)
       Try to grab and show an SDSS spectrum 
    imsize: float
       Image size in arcmin
    '''
    reload(x_r)
    reload(xgs)
    import matplotlib.pyplot as plt
    import matplotlib.cm as cm

    # Init
    if fpath is None:
        fpath = './'
    cradius = imsize / 50.

    # Read in the Target list
    if isinstance(inp, basestring):
        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
        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())
        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')

        # 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)
        #import pdb; pdb.set_trace()

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

        # 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
        #xdb.set_trace()

    print 'finder: All done.'
    return oBW
Exemplo n.º 7
0
def main(targ_file,
         survey='2r',
         radec=None,
         deci=None,
         fpath=None,
         EPOCH=0.,
         DSS=None,
         BW=False,
         imsize=5.,
         show_spec=False):
    '''
    Parameters:
    ---------
    targ_file: string or List of string
       ASCII file for targets (Name, RA, DEC)
       or a List 
       Colon separated RA, DEC expected
    radec: integer (0)
       Flag indicating type of input
       0 = ASCII file
       1 = List or ['Name', 'RA', 'DEC']  
    BW: bool (False)
       B&W image?
    show_spec: bool (False)
       Try to grab and show an SDSS spectrum 
    imsize: float
       Image size in arcmin
    '''
    import radec as x_r
    #reload(x_r)
    reload(xgs)
    import matplotlib.pyplot as plt
    import matplotlib.cm as cm

    # Init
    if fpath is None:
        fpath = './'
    cradius = imsize / 50.

    # Read in the Target list
    ra_tab = get_coord(targ_file, radec=radec)

    # Grab ra, dec in decimal degrees
    if deci != None:
        return
    # Convert to decimal degress

    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
    nobj = len(ra_tab)
    for qq in range(nobj):

        # Outfil
        nm = "".join(ra_tab['Name'][qq].split())
        outfil = fpath + nm + '.pdf'
        print(outfil)

        # Grab the Image
        reload(xgs)
        img, oBW = xgs.getimg(ra_tab['RA'][qq],
                              ra_tab['DEC'][qq],
                              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')

        # 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(ra_tab['RAS'][qq]),
                 fontsize=28,
                 horizontalalignment='center',
                 transform=ax.transAxes)
        plt.text(0.5,
                 1.10,
                 'DEC (J2000) = ' + str(ra_tab['DECS'][qq]),
                 fontsize=28,
                 horizontalalignment='center',
                 transform=ax.transAxes)
        #import pdb; pdb.set_trace()

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

        # Spectrum??
        if show_spec:
            spec_img = xgs.get_spec_img(ra_tab['RA'][qq], ra_tab['DEC'][qq])
            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
        #xdb.set_trace()

    print 'finder: All done.'
    return oBW
Exemplo n.º 8
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()