示例#1
0
文件: hi.py 项目: troyraen/marvin
def plot_mass_fraction(vacdata_object):
    ''' Plot the HI mass fraction
    
    Computes and plots the HI mass fraction using
    the NSA elliptical Petrosian stellar mass from the
    MaNGA DRPall file.  Only plots data for subset of
    targets in both the HI VAC and the DRPall file.

    Parameters:
        vacdata_object (object):
            The `~.VACDataClass` instance of the HI VAC 

    Example:
        >>> from marvin.tools.vacs import VACs
        >>> v = VACs()
        >>> hi = v.HI
        >>> hi.plot_mass_fraction()
    '''
    drpall = get_drpall_table()
    drpall.add_index('plateifu')
    data = vacdata_object.data[1].data
    subset = drpall.loc[data['plateifu']]
    log_stmass = np.log10(subset['nsa_elpetro_mass'])
    diff = data['logMHI'] - log_stmass
    fig, axes = scatplot(
        log_stmass,
        diff,
        with_hist=False,
        ylim=[-5, 5],
        xlabel=r'log $M_*$',
        ylabel=r'log $M_{HI}/M_*$',
    )
    return axes[0]
示例#2
0
    def plot_massfraction(self):
        ''' Plot the HI mass fraction '''

        drpall = get_drpall_table()
        drpall.add_index('plateifu')
        subset = drpall.loc[self._hi_data['plateifu']]
        log_stmass = np.log10(subset['nsa_elpetro_mass'])
        diff = self._hi_data['logMHI'] - log_stmass
        fig, axes = scatplot(log_stmass, diff, with_hist=False, ylim=[-5, 5],
                             xlabel=r'log $M_*$', ylabel=r'log $M_{HI}/M_*$')
        return axes[0]
示例#3
0
# Takes all of the primary, secondary, color_enhanced sample galaxies from DR15 (public) and puts them in a table
# so that I can then go and grab their images from the main SDSS database

from marvin import config
from marvin.utils.general.general import get_drpall_table
config.access = 'public'#diff from collab
config.setRelease('DR15')
data = get_drpall_table()

import numpy as np
primary        = data['mngtarg1'] & 2**10
secondary      = data['mngtarg1'] & 2**11
color_enhanced = data['mngtarg1'] & 2**12

main_sample = np.logical_or.reduce((primary, secondary, color_enhanced))

plateifus = data['plateifu'][main_sample]
print(data.columns)
cols = data['nsa_camcol'][main_sample]
print(data['nsa_iauname'][main_sample])


# Make a new table with a lot of this info
file=open('/Users/beckynevin/CfA_Code/Kinematics_and_Imaging_Merger_Identification/Identify_MaNGA_SDSS_mergers_imaging/table_manga_gals.txt','w')
# Some of the galaxies fail and I have not had to time to look into why
# error is -
# ['failed to retrieve data using input parameters.']
# ['get_nsa_data: cannot find a valid DB connection.']


for j in range(len(plateifus)):
示例#4
0
    def __init__(self,
                 filename_drp=None,
                 filename_dap=None,
                 no_analog=False,
                 drpver=None,
                 dapver=None,
                 latest=True,
                 filename_targets=None,
                 filename_gz=None,
                 sersic=False,
                 **kwargs):
        # Get or set filenames for DRP all file
        if filename_drp is None:
            if drpver is None:
                self.drpver, _ = config.lookUpVersions()
                logging.warning("Using DRP Version: {}".format(self.drpver))
            else:
                self.drpver = drpver
            self.filename_drp = os.path.join(
                os.environ['SAS_BASE_DIR'], 'mangawork', 'manga', 'spectro',
                'redux', self.drpver, 'drpall-{}.fits'.format(self.drpver))
        else:
            self.filename_drp = filename_drp

        # Get or set filenames for DAP all file
        if filename_dap is None:
            if dapver is None:
                _, self.dapver = config.lookUpVersions()
                logging.warning("Using DAP Version: {}".format(self.dapver))
            else:
                self.dapver = dapver
            self.filename_dap = os.path.join(
                os.environ['SAS_BASE_DIR'], 'mangawork', 'manga', 'spectro',
                'analysis', self.drpver, self.dapver,
                'dapall-{0}-{1}.fits'.format(self.drpver, self.dapver))
        else:
            self.filename_dap = filename_dap

        # Get or set filename for Target File List
        if filename_targets is None:
            self.filename_targets = os.path.join(
                os.environ['SAS_BASE_DIR'], 'mangawork', 'manga', 'target',
                'v1_2_27', 'MaNGA_targets_extNSA_tiled_ancillary.fits')
        else:
            self.filename_targets = filename_targets

        # Get or set filename for Galaxy Zoo VAC
        if filename_gz is None:
            self.filename_gz = os.path.join(os.environ['SAS_BASE_DIR'], 'dr15',
                                            'manga', 'morphology', 'galaxyzoo',
                                            'MaNGA_gz-v1_0_1.fits')
        else:
            self.filename_gz = filename_gz

        # Load Data
        try:
            self.drp = Table.read(self.filename_drp)
        except FileNotFoundError:
            logging.warning("DRP File not found, trying to download")
            self.drp = get_drpall_table()
        try:
            self.dap = Table.read(self.filename_dap)
        except FileNotFoundError:
            logging.warning("DAP File not found, trying to download")
            self.filename = get_dapall_file(self.drpver, self.dapver)
            try:
                self.dap = Table.read(self.filename_dap)
            except FileNotFoundError:
                if (self.drpver == "v2_4_e") & (self.dapver == "2.2.1"):
                    self.dap = Table.read(
                        "https://data.sdss.org/sas/dr15/manga/spectro/analysis/v2_4_3/2.2.1/dapall-v2_4_3-2.2.1.fits"
                    )

        try:
            self.targets = Table.read(self.filename_targets)
        except FileNotFoundError:
            logging.warning("Target Data File not found")
            self.targets = Table()

        try:
            self.gz = Table.read(self.filename_gz)
        except FileNotFoundError:
            logging.warning("Galaxy Zoo Morphology Data File not found")
            self.gz = Table()

        if not no_analog:

            self.sersic = sersic

            # Set Ind Dictionary of Targets by MangaID
            self.ind_dict_target = dict(
                (k.rstrip(), i) for i, k in enumerate(self.targets['MANGAID']))

            # Set some Milky Way Stellar Mass Estimates
            self.mw_stellar_mass = 6.43 * 10**10 * u.solMass
            self.mw_stellar_mass_err = 0.63 * 10**10 * u.solMass

            self.mw_stellar_mass_jbh = 5.0 * 10**10 * u.solMass
            self.mw_stellar_mass_jbh_err = 1.0 * 10**10 * u.solMass

            self.targets_gz = self.targets_in_gz()

            if latest:
                self.barred_targets_mask = self.get_barred_galaxies_mask()
                self.nonbarred_targets_mask = self.get_nonbarred_galaxies_mask(
                )

                # At least Green Valley Selection
                # Set Color Keys:
                color_keys = ["F", "N", "u", "g", "r", "i", "z"]

                # Cosmology Correction
                h = 1 * u.mag * u.littleh
                cor = 5. * np.log10(h.to(u.mag, u.with_H0(
                    WMAP9.H0)).value) * u.mag

                barred_targets_phot = Table(self.targets_gz[
                    self.barred_targets_mask]['NSA_ELPETRO_ABSMAG'] * u.mag +
                                            cor,
                                            names=color_keys)

                nonbarred_targets_phot = Table(
                    self.targets_gz[self.nonbarred_targets_mask]
                    ['NSA_ELPETRO_ABSMAG'] * u.mag + cor,
                    names=color_keys)

                # Remove Red Galaxies with NUV - r > 5
                self.barred_targets_full = self.targets_gz[
                    self.barred_targets_mask][(barred_targets_phot["N"] -
                                               barred_targets_phot["r"]) <= 5]
                self.nonbarred_targets_full = self.targets_gz[
                    self.nonbarred_targets_mask][(
                        nonbarred_targets_phot["N"] -
                        nonbarred_targets_phot["r"]) <= 5]

                # Stellar Masses
                self.barred_targets_stellar_mass = (10**(self.barred_targets_full["NSA_ELPETRO_MASS"]) *\
                                            u.solMass* u.littleh**-2).to(u.solMass, u.with_H0(WMAP9.H0))

                self.nonbarred_targets_stellar_mass = (10**(self.nonbarred_targets_full["NSA_ELPETRO_MASS"]) *\
                                            u.solMass* u.littleh**-2).to(u.solMass, u.with_H0(WMAP9.H0))

                #Get closest nonbarred galaxy by mass for each barred galaxy
                all_gals_drawn = []
                for gal_mass in self.barred_targets_stellar_mass:
                    dif = (np.log10(gal_mass.value) -
                           np.log10(self.nonbarred_targets_stellar_mass.value))
                    ind = np.argsort(np.abs(dif))
                    added = False
                    ell = 0
                    while not added:
                        if ind[ell] not in all_gals_drawn:
                            all_gals_drawn.append(ind[ell])
                            added = True
                        else:
                            ell += 1

                self.nonbarred_targets_selected = self.nonbarred_targets_full[
                    all_gals_drawn]
                self.nonbarred_targets_selected_stellar_mass = self.nonbarred_targets_stellar_mass[
                    all_gals_drawn]

                barred_IDs = [
                    mangaid.decode("utf-8").rstrip()
                    for mangaid in self.barred_targets_full["MANGAID"].data
                ]
                nonbarred_IDs = [
                    mangaid.decode("utf-8").rstrip() for mangaid in
                    self.nonbarred_targets_selected["MANGAID"].data
                ]
                ind_dict_drp = dict(
                    (k, i) for i, k in enumerate(self.drp['mangaid']))
                barred_in_drp = set(ind_dict_drp).intersection(barred_IDs)
                bar_in_drp_ind = [ind_dict_drp[x] for x in barred_in_drp]
                nonbarred_in_drp = set(ind_dict_drp).intersection(
                    nonbarred_IDs)
                nonbar_in_drp_ind = [ind_dict_drp[x] for x in nonbarred_in_drp]
                barred_plateifus = [
                    plateifu.decode("utf").rstrip()
                    for plateifu in self.drp[bar_in_drp_ind]["plateifu"].data
                ]
                nonbarred_plateifus = [
                    plateifu.decode("utf").rstrip() for plateifu in
                    self.drp[nonbar_in_drp_ind]["plateifu"].data
                ]
                ind_dict_dap = dict(
                    (k, i) for i, k in enumerate(self.dap['PLATEIFU']))

                barred_sample_dap_ind = np.array(
                    [ind_dict_dap[plateifu] for plateifu in barred_plateifus])
                nonbarred_sample_dap_ind = np.array([
                    ind_dict_dap[plateifu] for plateifu in nonbarred_plateifus
                ])
                if config.release == "MPL-8":
                    bad_barred_ind = ind_dict_dap["10507-12705"]
                    good_barred_mask = np.array([
                        ind != bad_barred_ind for ind in barred_sample_dap_ind
                    ])
                    barred_sample_dap_ind = barred_sample_dap_ind[
                        good_barred_mask]

                    bad_nonbarred_inds = [
                        ind_dict_dap[bad]
                        for bad in ["8332-12704", "8616-3704", "10498-12704"]
                    ]
                    good_nonbarred_mask = np.array([
                        ind not in bad_nonbarred_inds
                        for ind in nonbarred_sample_dap_ind
                    ])
                    nonbarred_sample_dap_ind = nonbarred_sample_dap_ind[
                        good_nonbarred_mask]

                self.barred_sample = self.dap[barred_sample_dap_ind]
                self.nonbarred_sample = self.dap[nonbarred_sample_dap_ind]

                argsort = np.argsort(self.barred_sample["NSA_Z"])
                self.barred_sample = self.barred_sample[argsort]
                argsort = np.argsort(self.nonbarred_sample["NSA_Z"])
                self.nonbarred_sample = self.nonbarred_sample[argsort]



                self.barred_stellar_mass = (self.drp[self.barred_sample["DRPALLINDX"]]["nsa_elpetro_mass"] *\
                                            u.solMass* u.littleh**-2).to(u.solMass, u.with_H0(WMAP9.H0))
                self.nonbarred_stellar_mass = (self.drp[self.nonbarred_sample["DRPALLINDX"]]["nsa_elpetro_mass"] *\
                                            u.solMass* u.littleh**-2).to(u.solMass, u.with_H0(WMAP9.H0))

                self.in_mass_range_barred = self.barred_stellar_mass <= (
                    self.mw_stellar_mass + self.mw_stellar_mass_err * 2.5)
                self.in_mass_range_barred &= self.barred_stellar_mass > self.mw_stellar_mass - self.mw_stellar_mass_err * 2.5

                self.in_mass_range_nonbarred = self.nonbarred_stellar_mass <= self.mw_stellar_mass + self.mw_stellar_mass_err * 2.5
                self.in_mass_range_nonbarred &= self.nonbarred_stellar_mass > self.mw_stellar_mass - self.mw_stellar_mass_err * 2.5

                self.dk_sample = self.barred_sample[self.in_mass_range_barred]
                self.dk_sample_nobar = self.nonbarred_sample[
                    self.in_mass_range_nonbarred]

                self.barred_sfr = (self.barred_sample["SFR_TOT"] * u.solMass /
                                   u.yr * u.littleh**-2).to(
                                       u.solMass / u.yr, u.with_H0(WMAP9.H0))
                self.nonbarred_sfr = (self.nonbarred_sample["SFR_TOT"] *
                                      u.solMass / u.yr * u.littleh**-2).to(
                                          u.solMass / u.yr,
                                          u.with_H0(WMAP9.H0))

                self.dk_sample_sfr = self.barred_sfr[self.in_mass_range_barred]
                self.dk_sample_nobar_sfr = self.nonbarred_sfr[
                    self.in_mass_range_nonbarred]

                self.barred_sfr_1re = (self.barred_sample["SFR_1RE"] *
                                       u.solMass / u.yr * u.littleh**-2).to(
                                           u.solMass / u.yr,
                                           u.with_H0(WMAP9.H0))
                self.nonbarred_sfr_1re = (self.nonbarred_sample["SFR_1RE"] *
                                          u.solMass / u.yr * u.littleh**-2).to(
                                              u.solMass / u.yr,
                                              u.with_H0(WMAP9.H0))

                self.dk_sample_sfr_1re = self.barred_sfr_1re[
                    self.in_mass_range_barred]
                self.dk_sample_nobar_sfr_1re = self.nonbarred_sfr_1re[
                    self.in_mass_range_nonbarred]

            else:

                # Set Full Barred and Unbarred Sample
                self.barred_sample = self.get_barred_galaxies_dap()
                argsort = np.argsort(self.barred_sample["NSA_Z"])
                self.barred_sample = self.barred_sample[argsort]
                self.nonbarred_sample = self.get_barred_galaxies_dap(
                    nonbarred=True)
                argsort = np.argsort(self.nonbarred_sample["NSA_Z"])
                self.nonbarred_sample = self.nonbarred_sample[argsort]

                # At least Green Valley Selection
                # Set Color Keys:
                color_keys = ["F", "N", "u", "g", "r", "i", "z"]

                # Cosmology Correction
                h = 1 * u.mag * u.littleh
                cor = 5. * np.log10(h.to(u.mag, u.with_H0(
                    WMAP9.H0)).value) * u.mag

                barred_sample_phot = Table(
                    self.drp[self.barred_sample["DRPALLINDX"]]
                    ['nsa_elpetro_absmag'] * u.mag + cor,
                    names=color_keys)

                nonbarred_sample_phot = Table(
                    self.drp[self.nonbarred_sample["DRPALLINDX"]]
                    ['nsa_elpetro_absmag'] * u.mag + cor,
                    names=color_keys)

                # Remove Red Galaxies with NUV - r > 5
                self.barred_sample = self.barred_sample[(
                    barred_sample_phot["N"] - barred_sample_phot["r"]) <= 5]
                self.nonbarred_sample = self.nonbarred_sample[(
                    nonbarred_sample_phot["N"] -
                    nonbarred_sample_phot["r"]) <= 5]

                # Stellar Masses
                self.barred_stellar_mass = (self.drp[self.barred_sample["DRPALLINDX"]]["nsa_elpetro_mass"] * \
                      u.solMass* u.littleh**-2).to(u.solMass, u.with_H0(WMAP9.H0))
                self.nonbarred_stellar_mass = (self.drp[self.nonbarred_sample["DRPALLINDX"]]["nsa_elpetro_mass"] * \
                      u.solMass* u.littleh**-2).to(u.solMass, u.with_H0(WMAP9.H0))

                # Mass Selections
                self.in_mass_range_barred = self.barred_stellar_mass <= self.mw_stellar_mass + self.mw_stellar_mass_err
                self.in_mass_range_barred &= self.barred_stellar_mass > self.mw_stellar_mass - self.mw_stellar_mass_err

                self.in_mass_range_nonbarred = self.nonbarred_stellar_mass <= self.mw_stellar_mass + self.mw_stellar_mass_err
                self.in_mass_range_nonbarred &= self.nonbarred_stellar_mass > self.mw_stellar_mass - self.mw_stellar_mass_err

                #JBH
                self.in_mass_range_barred_jbh = self.barred_stellar_mass <= self.mw_stellar_mass_jbh + self.mw_stellar_mass_jbh_err
                self.in_mass_range_barred_jbh &= self.barred_stellar_mass > self.mw_stellar_mass_jbh - self.mw_stellar_mass_jbh_err

                self.in_mass_range_nonbarred_jbh = self.nonbarred_stellar_mass <= self.mw_stellar_mass_jbh + self.mw_stellar_mass_jbh_err
                self.in_mass_range_nonbarred_jbh &= self.nonbarred_stellar_mass > self.mw_stellar_mass_jbh - self.mw_stellar_mass_jbh_err

                self.dk_sample = self.barred_sample[self.in_mass_range_barred]
                self.dk_sample_nobar = self.nonbarred_sample[
                    self.in_mass_range_nonbarred]

                #JBH
                self.dk_sample_jbh = self.barred_sample[
                    self.in_mass_range_barred_jbh]
                self.dk_sample_jbh_nobar = self.nonbarred_sample[
                    self.in_mass_range_nonbarred_jbh]

                #SFR
                self.barred_sfr = (self.barred_sample["SFR_TOT"] * u.solMass /
                                   u.yr * u.littleh**-2).to(
                                       u.solMass / u.yr, u.with_H0(WMAP9.H0))
                self.nonbarred_sfr = (self.nonbarred_sample["SFR_TOT"] *
                                      u.solMass / u.yr * u.littleh**-2).to(
                                          u.solMass / u.yr,
                                          u.with_H0(WMAP9.H0))

                self.dk_sample_sfr = self.barred_sfr[self.in_mass_range_barred]
                self.dk_sample_nobar_sfr = self.nonbarred_sfr[
                    self.in_mass_range_nonbarred]

                self.dk_sample_jbh_sfr = self.barred_sfr[
                    self.in_mass_range_barred_jbh]
                self.dk_sample_jbh_nobar_sfr = self.nonbarred_sfr[
                    self.in_mass_range_nonbarred_jbh]