Exemplo n.º 1
0
    def cenque(self, cenque, **mkwargs):
        ''' 
        Plot stellar mass to halo mass ratio of input CenQue object
        '''

        if self.kwargs == {}:
            kwargs = mkwargs.copy()
        else:
            kwargs = (self.kwargs).copy()
            kwargs.update(mkwargs)

        if 'label' in kwargs:
            label = kwargs['label']
        else:
            label = 'z = ' + str(cenque.zsnap)

        if 'color' in kwargs:
            color = kwargs['color']
        else:
            try:
                color = self.pretty_colors[cenque.nsnap]
            except TypeError:
                color = 'black'

        bovy.scatterplot(cenque.halo_mass,
                         cenque.mass,
                         scatter=True,
                         color=color,
                         s=3,
                         xrange=[10.0, 15.0],
                         yrange=[9.0, 12.0],
                         ylabel='\mathtt{M_*}',
                         xlabel='\mathtt{M_{Halo}}')

        return None
Exemplo n.º 2
0
    def cenque(self, cq_obj, scatter=False, bovyplot=True, **mkwargs):
        '''
        Plot SF-MS (M* vs SFR) for CenQue object
        '''

        if self.kwargs == {}:
            self.kwargs = mkwargs.copy()
        else:
            self.kwargs = (self.kwargs).copy()
            self.kwargs.update(mkwargs)

        if 'label' in self.kwargs:
            label = self.kwargs['label']
        else:
            label = 'z = ' + str(cq_obj.zsnap)

        if 'color' in self.kwargs:
            color = self.kwargs['color']
        else:
            try:
                color = self.pretty_colors[cq_obj.nsnap]
                self.cenque_nsnap = cq_obj.nsnap
            except TypeError:
                color = 'black'

        if 'justsf' in self.kwargs:
            if self.kwargs['justsf']:
                justsf = np.where(cq_obj.gal_type == 'star-forming')

                cq_mass = cq_obj.mass[justsf]
                cq_sfr = cq_obj.sfr[justsf]
            else:
                cq_mass = cq_obj.mass
                cq_sfr = cq_obj.sfr
        else:
            cq_mass = cq_obj.mass
            cq_sfr = cq_obj.sfr

        if scatter:
            self.sub.scatter(cq_mass, cq_sfr, color=color, s=3)
            self.sub.set_xlim([9.0, 12.0])
            self.sub.set_ylim([-5.0, 2.0])
            self.sub.set_xlabel(r'$\mathtt{M_*}$')
            self.sub.set_ylabel(r'$\mathtt{log\;SFR}$')
            self.scatter = True

        else:
            bovy.scatterplot(cq_mass,
                             cq_sfr,
                             scatter=True,
                             color=color,
                             s=3,
                             xrange=[9.0, 12.0],
                             yrange=[-5.0, 2.0],
                             xlabel='\mathtt{M_*}',
                             ylabel='\mathtt{log\;SFR}')
            self.scatter = False

        return None
def plot_mhalo_mstar(i_nsnap = 1, **kwargs): 
    ''' Plot Mhalo versus M* of galaxies for CenQue file 

    '''
    prettyplot() 
    pretty_colors = prettycolors() 

    # import evolved snapshot 
    if i_nsnap == 13: 
        snap = cq.CenQue() 
        snap.readin(nsnap=i_nsnap, file_type='sf assign', **kwargs) 
    else: 
        snap = cq.CenQue() 
        snap.readin(nsnap=i_nsnap, file_type='evol from 13', **kwargs) 

    mhalo = snap.halo_mass 
    mstar = snap.mass
    
    bovy.scatterplot(mstar, mhalo, scatter=True, color=pretty_colors[1], s=3, 
            xrange=[9.0, 11.5], 
            xlabel='\mathtt{M_*}', ylabel='\mathtt{M_{Halo}}')

    # figure file name ------------------------------------------------------------
    # tau specifier
    if kwargs['tau'] == 'discrete': 
        tau_str = '_'.join( [str("%.1f" % t) for t in kwargs['tau_param']] )+'tau'
    elif kwargs['tau'] == 'linefit':
        tau_str = '_'.join( [str("%.2f" % t) for t in kwargs['tau_param']] )+'tau'
    else: 
        tau_str = kwargs['tau']+'tau'
    
    # Stellar mass specifier 
    if kwargs['stellmass'].lower() == 'integrated': 
        mass_str = '_integ'
    elif kwargs['stellmass'].lower() == 'sham': 
        mass_str = '_sham'
    else: 
        raise NotImplementedError('asdfalkjlkjasdf') 

    # SFR specifier
    if kwargs['sfr'] == 'sfr_avg': 
        file_type_str = mass_str+'_sfravg'
    elif kwargs['sfr'] == 'sfr_func': 
        file_type_str = mass_str+'_sfrfunc'
    else: 
        raise NotImplementedError('asdfasdflkjasdf;lkjasdf') 
    
    fig_name1 = ''.join(['figure/', 
        'cenque_mstar_mhalo_snapshot', str(i_nsnap), tau_str, file_type_str, 
        '_scatter.png'])
    plt.savefig(fig_name1, bbox_inches='tight')
def plot_cenque_sfms(i_nsnap, **kwargs): 
    ''' Plot SF-MS for CenQue 

    '''
    prettyplot()                        #make things pretty 
    pretty_colors = prettycolors() 

    if i_nsnap < 13: 
        snap = cq.CenQue() 
        snap.readin(nsnap=i_nsnap, file_type='evol from 13', **kwargs) 
    else: 
        snap = cq.CenQue() 
        snap.readin(nsnap=13, file_type='sf assign', **kwargs) 

    sf_index = np.where(snap.gal_type == 'star-forming')    # only keep star forming galaxies
    mass = (snap.mass)[sf_index]
    sfr = (snap.sfr)[sf_index]
    
    # scatter plot with contours!
    bovy.scatterplot(mass, sfr, scatter=True, color=pretty_colors[1], s=3, 
            xlabel=r'$\mathtt{M_*}$', ylabel=r'$\mathtt{SFR}$')

    # figure file name ------------------------------------------------------------
    # tau specifier
    if kwargs['tau'] == 'discrete': 
        tau_str = '_'.join( [str("%.1f" % t) for t in kwargs['tau_param']] )+'tau'
    elif kwargs['tau'] == 'linefit':
        tau_str = '_'.join( [str("%.2f" % t) for t in kwargs['tau_param']] )+'tau'
    else: 
        tau_str = kwargs['tau']+'tau'
    
    # Stellar mass specifier 
    if kwargs['stellmass'].lower() == 'integrated': 
        mass_str = '_integ'
    elif kwargs['stellmass'].lower() == 'sham': 
        mass_str = '_sham'
    else: 
        raise NotImplementedError('asdfalkjlkjasdf') 

    # SFR specifier
    if kwargs['sfr'] == 'sfr_avg': 
        file_type_str = mass_str+'_sfravg'
    elif kwargs['sfr'] == 'sfr_func': 
        file_type_str = mass_str+'_sfrfunc'
    else: 
        raise NotImplementedError('asdfasdflkjasdf;lkjasdf') 
    
    fig_name = ''.join(['figure/cenque_sfms', tau_str, file_type_str, '.png'])
    plt.savefig(fig_name, bbox_inches='tight')
    plt.show() 
def test_photoz(catalog_name): 
    """ Test that the assigned photometric redshifts in photoz correction 
    method reproduce the CMASS photometric redshifts. 
    """

    catdict = {'name': catalog_name, 'n_mock': 20}
    corrdict = {'name': 'photoz'}
    cat_corr = {'catalog': catdict, 'correction': corrdict}

    dataclass = Data('data', cat_corr) 
    dataclass.read()
    
    # only consider galaxies with photometric redshifts 
    hasphotoz = np.where( 
            dataclass.photoz > -999.
            ) 

    deltaz_z = (dataclass.z[hasphotoz] - dataclass.photoz[hasphotoz]) / (1.0 + dataclass.z[hasphotoz])

    prettyplot()                        
    pretty_colors = prettycolors()

    plt.figure(figsize=(8,8))
            
    bovy.scatterplot(
            dataclass.z[hasphotoz], 
            deltaz_z, 
            scatter = True, 
            levels = [0.68, 0.95, 0.997], 
            color = pretty_colors[1], 
            s = 3,
            xrange = [0.43, 0.7], 
            yrange = [-0.3, 0.3], 
            xlabel = '\mathtt{z_{spec}}', 
            ylabel = r'\mathtt{\frac{|z_{spec} - z_{photo}|}{1 + z_{spec}}}' 
            )

    plt.show()
            
    # save figure to file  
    fig_dir = '/home/users/hahn/powercode/FiberCollisions/figure/'
    fig_file = ''.join([
        fig_dir, 
        catalog_name, '_deltaz_zspec_zphoto.png'
        ]) 
    plt.savefig(fig_file, bbox_inches='tight') 

    plt.close()
    
    return None
Exemplo n.º 6
0
def plot_sfms_groupcat(Mrcut=18, writeout=True):
    ''' StarForming Main Sequence (mass vs SFR) of Star-Forming SDSS group catalog  

    Parameters
    ----------
    Mrcut : Absolute magnitude cut off of SDSS group catalog 

    '''
    # star-forming central galaxies from the SDSS group catalog
    sf_cen = sf_centrals(Mrcut=Mrcut) 

    #prettyplot()        
    pretty_colors = prettycolors() 

    #mass_bin = util.simple_mass_bin()       # mass bin 
    bovy.scatterplot(
            sf_cen.mass,
            sf_cen.sfr,
            scatter = True,
            levels = [0.68, 0.95, 0.997],
            color = pretty_colors[1],
            s = 3,
            xrange = [9.5, 12.0],
            yrange = [-1.5, 1.5],
            xlabel = 'log \; M_{*}',
            ylabel = 'log \; SFR'
            )

    #fig = plt.figure(figsize = (8,8))
    #sub = fig.add_subplot(111)

    #sub.hist2d(
    #        sf_cen.mass, 
    #        sf_cen.sfr, 
    #        bins = [30, 50]
    #        )

    #sub.set_xlim([9.5, 12.0])
    #sub.set_ylim([-1.5, 1.5])
    #sub.set_xlabel(r'$\mathtt{log \; M_{*}}$', fontsize=20)
    #sub.set_ylabel(r'$\mathtt{log \; SFR}$', fontsize=20)
    
    if writeout: 
        fig_name = ''.join([
            'figure/', 
            'sfms_SDSS_groupcat_', str(Mrcut), '.png'
            ])
        plt.savefig(fig_name, bbox_inches='tight')

    return None
Exemplo n.º 7
0
    def central_subhalos(self, centsub, **mkwargs):
        '''
        Plot the stellar mass to halo mass relation for CentralSubhalos object
        '''

        if self.kwargs == {}:
            kwargs = mkwargs.copy()
        else:
            kwargs = (self.kwargs).copy()
            kwargs.update(mkwargs)

        if 'label' in kwargs:
            label = kwargs['label']
        else:
            label = ''.join(
                ['z =',
                 str(round(util.get_z_nsnap(centsub.snapshot), 2))])
            print label

        if 'color' in kwargs:
            color = kwargs['color']
        else:
            try:
                color = self.pretty_colors[centsub.snapshot]
            except TypeError:
                color = 'black'

        halo_mass = getattr(centsub, 'halo.m.max')

        relevant_mstar_range = np.where(centsub.mass > 9.0)
        #print len(halo_mass[relevant_mstar_range])

        bovy.scatterplot(halo_mass[relevant_mstar_range],
                         centsub.mass[relevant_mstar_range],
                         scatter=True,
                         color=color,
                         s=3,
                         xrange=[10.0, 15.0],
                         yrange=[9.0, 12.0],
                         ylabel='\mathtt{M_*}',
                         xlabel='\mathtt{M_{Halo}}',
                         levels=[0.68, 0.95])
        #self.subs.scatter(
        #        halo_mass,
        #        centsub.mass,
        #        color = color,
        #        label = label
        #        )

        return None
Exemplo n.º 8
0
def plot_sfms_groupcat(Mrcut=18, writeout=True):
    ''' StarForming Main Sequence (mass vs SFR) of Star-Forming SDSS group catalog  

    Parameters
    ----------
    Mrcut : Absolute magnitude cut off of SDSS group catalog 

    '''
    # star-forming central galaxies from the SDSS group catalog
    sf_cen = sf_centrals(Mrcut=Mrcut)

    #prettyplot()
    pretty_colors = prettycolors()

    #mass_bin = util.simple_mass_bin()       # mass bin
    bovy.scatterplot(sf_cen.mass,
                     sf_cen.sfr,
                     scatter=True,
                     levels=[0.68, 0.95, 0.997],
                     color=pretty_colors[1],
                     s=3,
                     xrange=[9.5, 12.0],
                     yrange=[-1.5, 1.5],
                     xlabel='log \; M_{*}',
                     ylabel='log \; SFR')

    #fig = plt.figure(figsize = (8,8))
    #sub = fig.add_subplot(111)

    #sub.hist2d(
    #        sf_cen.mass,
    #        sf_cen.sfr,
    #        bins = [30, 50]
    #        )

    #sub.set_xlim([9.5, 12.0])
    #sub.set_ylim([-1.5, 1.5])
    #sub.set_xlabel(r'$\mathtt{log \; M_{*}}$', fontsize=20)
    #sub.set_ylabel(r'$\mathtt{log \; SFR}$', fontsize=20)

    if writeout:
        fig_name = ''.join(
            ['figure/', 'sfms_SDSS_groupcat_',
             str(Mrcut), '.png'])
        plt.savefig(fig_name, bbox_inches='tight')

    return None
Exemplo n.º 9
0
    def plot(self, stellarmass=None, halomass=None, bovyplot=True, **mkwargs):
        ''' Plot SMHM ratio of input stellar mass and halo mass
        '''
        if stellarmass is None or halomass is None: 
            raise ValueError

        if self.kwargs == {}: 
            kwargs = mkwargs.copy() 
        else: 
            kwargs = (self.kwargs).copy()
            kwargs.update(mkwargs)
    
        if 'label' in kwargs: 
            label = kwargs['label']
        else: 
            label = None 

        if 'color' in kwargs: 
            if isinstance(kwargs['color'], str):
                color = kwargs['color']
            elif isinstance(kwargs['color'], int): 
                color = self.pretty_colors[kwargs['color']]
        else: 
            color = 'black'
        
        if bovyplot: 
            bovy.scatterplot(
                    halomass, 
                    stellarmass,
                    scatter=True, 
                    color=color, 
                    s=3, 
                    xrange=[10.0, 15.0],
                    yrange=[9.0, 12.0], 
                    ylabel='\mathtt{M_*}', 
                    xlabel='\mathtt{M_{Halo}}'
                    )
        else: 
            self.sub.scatter(
                    halomass, 
                    stellarmass,
                    color=color,
                    s=3, 
                    label=label)
        return None   
Exemplo n.º 10
0
    def bloodline(self, bloodline, snapshot, **mkwargs):
        '''
        '''
        descendant = getattr(bloodline, 'descendant_cq_snapshot'+str(snapshot))

        if self.kwargs == {}: 
            kwargs = mkwargs.copy() 
        else: 
            kwargs = (self.kwargs).copy()
            kwargs.update(mkwargs)
    
        if 'label' in kwargs: 
            label = kwargs['label']
        else: 
            label = ''.join([
                'z =', 
                str(round(util.get_z_nsnap(descendant.nsnap), 2))
                ])
            print label
        
        if 'color' in kwargs: 
            color = kwargs['color']
        else: 
            try: 
                color = self.pretty_colors[descendant.nsnap]
            except TypeError: 
                color = 'black'

        bovy.scatterplot(
                descendant.mass, 
                descendant.sfr, 
                scatter=True, 
                color=color, 
                s=3, 
                xrange=[9.0, 12.0], 
                yrange=[-3.0, 3.0], 
                xlabel='\mathtt{M_*}', 
                ylabel='\mathtt{log\;SFR}'
                )

        return None   
Exemplo n.º 11
0
def plot_mhalo_mstar_snapshotSHAM(i_nsnap=1, scatter=0.0): 
    ''' Plot M_halo versus SHAM stellar mass for TreePM --> SHAM snapshot

    Parameters
    ----------
    i_nsnap : snapshot # 
    scatter : set scatter of M_halo-M* in SHAM code 

    Notes
    -----
    * Essentially for testing TreePM and SHAM 


    '''
    prettyplot() 
    pretty_colors = prettycolors() 
    
    # import TreePM-->SHAM output 
    if scatter == 0.0: 
        snapshot_file = ''.join(['dat/wetzel_tree/', 
            'subhalo_sham_centrals_snapshot', str(i_nsnap), '.hdf5' 
            ]) 
    else: 
        snapshot_file = ''.join(['dat/wetzel_tree/', 
            'subhalo_sham_centrals_snapshot', str(i_nsnap), '_scatter', str(scatter), '.hdf5' 
            ]) 
    print snapshot_file 
    f = h5py.File(snapshot_file, 'r') # read snapshot file
    grp = f['cenque_data']

    mhalo = grp['halo.m.max'][:]
    mstar = grp['mass'][:]
    
    bovy.scatterplot(mstar, mhalo, scatter=True, color=pretty_colors[1], s=3, 
        xrange = [9.0, 11.5], 
        xlabel=r'$\mathtt{M_{SHAM}}$', ylabel=r'$\mathtt{M_{Halo}}$') 

    fig_name = ''.join(['figure/', 
        'subhalo_sham_centrals_snapshot', str(i_nsnap), '_scatter', str(scatter), '.png'])
    plt.savefig(fig_name, bbox_inches='tight')
Exemplo n.º 12
0
    def bloodline(self, bloodline, snapshot, **mkwargs):
        '''
        '''
        descendant = getattr(bloodline,
                             'descendant_cq_snapshot' + str(snapshot))

        if self.kwargs == {}:
            kwargs = mkwargs.copy()
        else:
            kwargs = (self.kwargs).copy()
            kwargs.update(mkwargs)

        if 'label' in kwargs:
            label = kwargs['label']
        else:
            label = ''.join(
                ['z =',
                 str(round(util.get_z_nsnap(descendant.nsnap), 2))])
            print label

        if 'color' in kwargs:
            color = kwargs['color']
        else:
            try:
                color = self.pretty_colors[descendant.nsnap]
            except TypeError:
                color = 'black'

        bovy.scatterplot(descendant.mass,
                         descendant.sfr,
                         scatter=True,
                         color=color,
                         s=3,
                         xrange=[9.0, 12.0],
                         yrange=[-3.0, 3.0],
                         xlabel='\mathtt{M_*}',
                         ylabel='\mathtt{log\;SFR}')

        return None
Exemplo n.º 13
0
def plot_d_stellmass_snapshot(i_nsnap=1, **kwargs): 
    ''' Plot the difference betwen integrated mass and SHAM mass versus SHAM mass for 
    CenQue model  

    '''
    prettyplot() 
    pretty_colors = prettycolors()  

    # import evolved snapshot 
    if i_nsnap == 13: 
        snap = cq.CenQue() 
        snap.readin(nsnap=i_nsnap, file_type='sf assign', **kwargs) 
    else: 
        snap = cq.CenQue() 
        snap.readin(nsnap=i_nsnap, file_type='evol from 13', **kwargs) 
    
    gal_type = snap.gal_type 
    mass = (snap.mass)[gal_type == 'star-forming']
    sham = (snap.sham_mass)[gal_type == 'star-forming']
    bovy.scatterplot(sham, sham-mass, scatter=True, color=pretty_colors[1], 
            xlabel=r'$\mathtt{M_{SHAM}}$', ylabel=r'$\mathtt{\Delta M (M_{SHAM}- M_*)}$', 
            xrange=[9.0, 11.5])

    # tau specifier
    if kwargs['tau'] == 'discrete': 
        tau_str = '_'.join( [str("%.1f" % t) for t in kwargs['tau_param']] )+'tau'
    elif kwargs['tau'] == 'linefit':
        tau_str = '_'.join( [str("%.2f" % t) for t in kwargs['tau_param']] )+'tau'
    else: 
        tau_str = kwargs['tau']+'tau'
    
    # SFR specifier
    file_type_str = kwargs['sfr']
    
    fig_name = ''.join(['figure/', 
        'cenque_d_mstellmass_snapshot', str(i_nsnap), tau_str, file_type_str, '.png'])
    plt.savefig(fig_name, bbox_inches='tight')
Exemplo n.º 14
0
def qaplot_sfms_groupcat_fitting(Mrcut=18, sfq_test=True):
    """ Function tests the SF-MS fitting functions and examines the 
    SF-MS of group catalog altogether as a sanity check. 

    If sfq_test is specified, then SFR(M*,z) cutoff for SF/Q classification
    is plotted on top of the SF-MS plots
    """

    # star-forming central galaxies from the SDSS group catalog
    sf_cen = sf_centrals(Mrcut=Mrcut) 

    #prettyplot()        
    pretty_colors = prettycolors() 

    bovy.scatterplot(
            sf_cen.mass,
            sf_cen.sfr,
            scatter = True,
            levels = [0.68, 0.95, 0.997],
            color = pretty_colors[1],
            s = 3,
            xrange = [9.5, 12.0],
            yrange = [-1.5, 1.5],
            xlabel = 'log \; M_{*}',
            ylabel = 'log \; SFR'
            )

    # SDSS group catalog best fit 
    gc_zmid, gc_slope, gc_yint = get_bestfit_sfms_groupcat(Mrcut=Mrcut, clobber=True)

    mass_bin = np.arange(9.0, 12.0, 0.25)       # mass bin 

    plt.plot(
            mass_bin, 
            gc_slope * (mass_bin-10.5) + gc_yint, 
            c='k', 
            lw=6, 
            ls='--'
            ) 

    # Envcount catalog best fit 
    ec_zmid, ec_slope, ec_yint = get_bestfit_sfms_envcount()

    for i_z in xrange(len(ec_zmid)):
        plt.plot(
                mass_bin, 
                ec_slope[i_z] * (mass_bin-10.5) + ec_yint[i_z], 
                c = pretty_colors[i_z+3], 
                lw = 4, 
                label = str(ec_zmid[i_z])
                ) 

    avg_sfrs, sig_sfrs, ngals = get_sfr_mstar_z_groupcat(
            mass_bin,
            Mrcut=Mrcut
            ) 
    enough_gal = np.where(np.array(avg_sfrs) > -998)

    plt.errorbar(
            mass_bin[enough_gal], 
            np.array(avg_sfrs)[enough_gal], 
            yerr = np.array(sig_sfrs)[enough_gal], 
            lw = 4, 
            c = pretty_colors[1], 
            label='Average SFR'
            )

    if sfq_test: 

        plt.plot(mass_bin, sfr_cut(mass_bin, 0.05), c='k', lw=4, ls='--')
    
    plt.legend(loc='lower right')
    
    fig_name = ''.join(['figure/', 'qaplot_sfms_fitting_groupcat_', str(Mrcut), '.png'])
    plt.savefig(fig_name, bbox_inches='tight')
    plt.close()
Exemplo n.º 15
0
    def cenque(self, cq_obj, scatter=False, bovyplot=True, **mkwargs): 
        '''
        Plot SF-MS (M* vs SFR) for CenQue object
        '''

        if self.kwargs == {}: 
            self.kwargs = mkwargs.copy() 
        else: 
            self.kwargs = (self.kwargs).copy()
            self.kwargs.update(mkwargs)
    
        if 'label' in self.kwargs: 
            label = self.kwargs['label']
        else: 
            label = 'z = '+str(cq_obj.zsnap) 
        
        if 'color' in self.kwargs: 
            color = self.kwargs['color']
        else: 
            try: 
                color = self.pretty_colors[cq_obj.nsnap]
                self.cenque_nsnap = cq_obj.nsnap
            except TypeError: 
                color = 'black'

        if 'justsf' in self.kwargs: 
            if self.kwargs['justsf']: 
                justsf = np.where(cq_obj.gal_type == 'star-forming')

                cq_mass = cq_obj.mass[justsf]
                cq_sfr = cq_obj.sfr[justsf]
            else: 
                cq_mass = cq_obj.mass
                cq_sfr = cq_obj.sfr
        else: 
            cq_mass = cq_obj.mass
            cq_sfr = cq_obj.sfr
        
        if scatter: 
            self.sub.scatter(
                    cq_mass,
                    cq_sfr,
                    color=color, 
                    s=3
                    )
            self.sub.set_xlim([9.0, 12.0])
            self.sub.set_ylim([-5.0, 2.0])
            self.sub.set_xlabel(r'$\mathtt{M_*}$')
            self.sub.set_ylabel(r'$\mathtt{log\;SFR}$')
            self.scatter = True

        else: 
            bovy.scatterplot(
                    cq_mass, 
                    cq_sfr,
                    scatter=True, 
                    color=color, 
                    s=3, 
                    xrange=[9.0, 12.0], 
                    yrange=[-5.0, 2.0], 
                    xlabel='\mathtt{M_*}', 
                    ylabel='\mathtt{log\;SFR}'
                    )
            self.scatter = False

        return None   
Exemplo n.º 16
0
def cmass_deltaz_zspec_zphoto_test(overplot=True): 
    ''' Spherematch photometric and spectroscopic catalogs to 
    determine standard deviation redshift errors of photmetric redshifts 
    wrt spectroscopic redshifts

    Parameters 
    ----------

    Notes
    -----
    * Using pyspherematch
    * Details on CMASS redshifts in: https://trac.sdss3.org/wiki/BOSS/clustering/WGCatalogCode
    * Assuming delta_z/z distribution is gaussian
    
    '''
    prettyplot()                         # set up plot 
    pretty_colors = prettycolors()
    
    # matching spectroscopic and photometric redshifts 
    z_spec, z_photo = match_zspec_zphoto_cmass()
    
    delta_z = (z_spec - z_photo) / (1.0 + z_spec)
    
    if overplot: 
        bovy.scatterplot(
                z_spec, 
                delta_z, 
                scatter=True, 
                levels=[0.68, 0.95, 0.997],
                color=pretty_colors[1], 
                s=3,
                xrange=[0.43, 0.7], 
                yrange=[-0.3, 0.3], 
                xlabel='\mathtt{z_{spec}}', 
                ylabel=r'\mathtt{\frac{|z_{spec} - z_{photo}|}{1\;+\;z_{spec}}}'
                )

    # summary statistics (mu and sigma) of delta z / (1+z)
    z_mid, z_low, z_high, mu_deltaz, sigma_deltaz = cmass_deltaz_zspec_zphoto()

    plt.errorbar(
            z_mid, 
            mu_deltaz, 
            yerr=sigma_deltaz, 
            c=pretty_colors[3]
            ) 
    plt.scatter(
            z_mid, 
            mu_deltaz, 
            c=pretty_colors[3]
            )

    fig_dir = '/home/users/hahn/powercode/FiberCollisions/figure/'
    fig_file = ''.join([
        fig_dir, 
        'cmass_deltaz_zspec_zphoto.png'
        ]) 
    plt.savefig(
            fig_file, 
            bbox_inches='tight'
            ) 
    plt.close()
Exemplo n.º 17
0
def cmass_zspec_zphoto(): 
    """ Compare matching spectroscopic redshifts and photometric redshifts
    of the CMASS catalog. 
    """ 
    prettyplot()
    pretty_colors = prettycolors()

    # matching spectroscopic and photometric redshifts 
    z_spec, z_photo = match_zspec_zphoto_cmass()
    
    # scatter plot of z_spec versus z_photo
    bovy.scatterplot(
            z_spec, 
            z_photo, 
            scatter=True, 
            color=pretty_colors[1], 
            s=3,
            xrange=[0.0, 1.0], 
            yrange=[0.0, 1.0], 
            xlabel='\mathtt{z_{spec}}', 
            ylabel='\mathtt{z_{photo}}'
            )
    plt.plot(np.arange(0.0, 2.0, 0.1), np.arange(0.0, 2.0, 0.1), c='k', lw=4)   # y = x 
    
    fig_dir = '/home/users/hahn/powercode/FiberCollisions/figure/'
    fig_file = ''.join([
        fig_dir, 
        'cmass_zspec_zphoto.png'
        ]) 
    plt.savefig( 
            fig_file, 
            bbox_inches='tight' 
            ) 
    plt.clf() 

    # scatter plot of delta z/(1+z) vs z 

    delta_z = (z_spec - z_photo) / (1.0 + z_spec)
    
    bovy.scatterplot(
            z_spec, 
            delta_z, 
            scatter=True, 
            levels=[0.68, 0.95, 0.997],
            color=pretty_colors[1], 
            s=3,
            xrange=[0.43, 0.7], 
            yrange=[-0.3, 0.3], 
            xlabel='\mathtt{z_{spec}}', 
            ylabel=r'\mathtt{\frac{|z_{spec} - z_{photo}|}{1\;+\;z_{spec}}}'
            )
    
    fig_file = ''.join([
        fig_dir, 
        'cmass_delta_zphoto_zspec.png'
        ]) 
    plt.savefig(
            fig_file, 
            bbox_inches='tight'
            ) 
    return None 
Exemplo n.º 18
0
    def plot(self, mass=None, sfr=None, sfr_class=None, 
            gal_class='star-forming', bovyplot=True, sigSFR=True, **mkwargs): 
        ''' Plot SFR as a function of stellar mass for star-forming 
        galaxies 
        '''
        if mass is None or sfr is None:
            raise ValueError

        if sfr_class is None and gal_class != 'all': 
            raise ValueError
        
        if self.kwargs == {}: 
            self.kwargs = mkwargs.copy() 
        else: 
            self.kwargs = (self.kwargs).copy()
            self.kwargs.update(mkwargs)
        # label 
        if 'label' in self.kwargs: 
            label = self.kwargs['label']
        else: 
            label = None
        # color 
        if 'color' in self.kwargs: 
            if isinstance(self.kwargs['color'], str): 
                color = self.kwargs['color']
            elif isinstance(self.kwargs['color'], int): 
                color = self.pretty_colors[self.kwargs['color']]
        else: 
            color = 'black'
        
        if gal_class != 'all': 
            just_gal_class = np.where(sfr_class == gal_class)
            mass = mass[just_gal_class]
            sfr = sfr[just_gal_class] 
        
        if not bovyplot: 
            self.sub.scatter(mass, sfr, color=color, s=3, label=label)
            
            if sigSFR: 
                mbin = np.arange(7.0, 12.25, 0.25)
                mlow = mbin[:-1]
                mhigh = mbin[1:]
                muSFR, sigSFR = [], [] 
                for im in range(len(mlow)): 
                    mbin = np.where((mass > mlow[im]) & (mass <= mhigh[im]))
                    muSFR.append(np.mean(sfr[mbin]))
                    sigSFR.append(np.std(sfr[mbin]))
                self.sub.plot(0.5*(mlow+mhigh), muSFR, color='k', ls='--', lw=4)
                self.sub.errorbar(0.5*(mlow+mhigh), muSFR, yerr=sigSFR, color='k')

            self.sub.set_xlim([9.0, 12.0])
            self.sub.set_ylim([-5.0, 2.0])
            self.sub.set_xlabel(r'$\mathtt{log\;M_*}$', fontsize=25)
            self.sub.set_ylabel(r'$\mathtt{log\;SFR}$', fontsize=25)
        else: 
            bovy.scatterplot(mass, sfr, scatter=True, color=color, 
                    s=3, 
                    levels=[0.68, 0.95, 0.997], #1,2,3 sigmas
                    xrange=[9.0, 12.0], 
                    yrange=[-5.0, 2.0], 
                    xlabel='\mathtt{M_*}', 
                    ylabel='\mathtt{log\;SFR}'
                    )
            #plt.plot(np.arange(9.0, 12.0, 0.1), 
            #        sfr_cut(np.arange(9.0, 12.0, 0.1), cq_obj.zsnap), 
            #        ls='--', lw=3, c='r')
        return None   
Exemplo n.º 19
0
def qaplot_sfms_envcount_fitting(Mrcut=18, sfq_test=True):
    """ Test functions of the SF-MS module that fits the group catalog SFMS
    
    If sfq_test is specified, then SFR(M*,z) cutoff for SF/Q classification
    is plotted on top of the SF-MS plots
    """
    #prettyplot()        
    pretty_colors = prettycolors() 

    # read SF galaxies from the envcount catalog  
    file_dir = 'dat/wetzel_tree/envcount/'
    sdss_envcount_file = ''.join([file_dir, 
        'envcount_cylr2.5h35_thresh75_sdss_active_z0.05_0.12_primuszerr.fits']) 
    sdss_sf_data = mrdfits(sdss_envcount_file) 
    primus_envcount_file = ''.join([file_dir, 
        'envcount_cylr2.5h35_thresh75_active_z0.2_1.0_lit.fits']) 
    primus_sf_data = mrdfits(primus_envcount_file) 
    
    for i_z, z_mid in enumerate([0.1, 0.3, 0.5, 0.7, 0.9]): 

        if z_mid < 0.2: 
            sf_data = sdss_sf_data

            # impose isolation criteria, mass completeness limit (should I ?) and edge cuts
            centrals = np.where(
                    (sf_data.envcount == 0.0) & 
                    (sf_data.mass > sf_data.masslimit) & 
                    (sf_data.edgecut == 1) 
                    )
        else: 
            sf_data = primus_sf_data
            # impose isolation criteria, mass completeness limit (should I ?) and edge cuts
            centrals = np.where(
                    (sf_data.redshift >= z_mid - 0.1) &
                    (sf_data.redshift < z_mid + 0.1) &
                    (sf_data.envcount == 0.0) & 
                    (sf_data.mass > sf_data.masslimit) & 
                    (sf_data.edgecut == 1) 
                    )

        print sf_data.weight[centrals]

        bovy.scatterplot(
                sf_data.mass[centrals],
                sf_data.sfr[centrals],
                scatter = True,
                levels = [0.68, 0.95, 0.997],
                weights = sf_data.weight[centrals], 
                s = 3,
                xrange = [9.5, 12.0],
                yrange = [-1.5, 1.5],
                xlabel = 'log \; M_{*}',
                ylabel = 'log \; SFR'
                )
                #color = pretty_colors[1],

        # SDSS group catalog best fit 
        gc_zmid, gc_slope, gc_yint = get_bestfit_sfms_groupcat(Mrcut=Mrcut, clobber=True)

        mass_bin = np.arange(9.0, 12.0, 0.25)       # mass bin 

        plt.plot(
                mass_bin, 
                gc_slope * (mass_bin-10.5) + gc_yint, 
                c='k', 
                lw=6, 
                ls='--'
                ) 

        # Envcount catalog best fit 
        ec_zmid, ec_slope, ec_yint = get_bestfit_sfms_envcount(clobber=True)

        plt.plot(
                mass_bin, 
                ec_slope[i_z] * (mass_bin-10.5) + ec_yint[i_z], 
                c = pretty_colors[i_z+3], 
                lw = 4, 
                label = str(ec_zmid[i_z])
                ) 

        avg_sfrs, sig_sfrs, ngals = get_sfr_mstar_z_envcount(
            mass_bin,
            [z_mid for i in xrange(len(mass_bin))]
            ) 
        enough_gal = np.where(np.array(avg_sfrs) > -998)

        plt.errorbar(
                mass_bin[enough_gal], 
                np.array(avg_sfrs)[enough_gal], 
                yerr = np.array(sig_sfrs)[enough_gal], 
                lw = 4, 
                c = pretty_colors[1], 
                label='Average SFR'
                )

        plt.legend(loc='lower right')

        if sfq_test: 

            plt.plot(mass_bin, sfr_cut(mass_bin, z_mid), c='k', lw=4, ls='--')
        
        fig_name = ''.join(['figure/', 'qaplot_sfms_fitting_envcount_z', str(z_mid), '.png'])
        plt.savefig(fig_name, bbox_inches='tight')
        plt.close()

    return None