Exemple #1
0
    def build_sys_from_dict(self, sys_name, llist=None, **kwargs):
        """ Build CGMAbsSys from the internal dict

        Parameters
        ----------
        sys_name : str
          Name of the system
        llist : LineList, optional
        kwargs : passed to CGMAbsSys.from_dict

        Returns
        -------
        CGMAbsSys

        """
        tdict = self._dict[sys_name]
        cgmsys = CGMAbsSys.from_dict(tdict,
                                     chk_vel=False,
                                     chk_sep=False,
                                     chk_data=False,
                                     use_coord=True,
                                     use_angrho=True,
                                     linelist=llist,
                                     **kwargs)
        # Return
        return cgmsys
Exemple #2
0
def cgm_from_galaxy_igmsystems(galaxy,
                               igmsystems,
                               R_max=300 * u.kpc,
                               dv_max=400 * u.km / u.s,
                               cosmo=None,
                               **kwargs):
    """ Generate a list of CGMAbsSys objects given an input galaxy and a list of IGMSystems

    Parameters
    ----------
    galaxy : Galaxy
    igmsystems : list
      list of IGMSystems
    R_max : Quantity
      Maximum projected separation from sightline to galaxy
    dv_max
      Maximum velocity offset between system and galaxy

    Returns
    -------
    cgm_list : list
      list of CGM objects generated

    """
    from pyigm.cgm.cgm import CGMAbsSys
    # Cosmology
    if cosmo is None:
        cosmo = cosmology.Planck15

    # R
    rho, angles = calc_rho(galaxy, igmsystems, cosmo)

    # dv
    igm_z = np.array([igmsystem.zabs for igmsystem in igmsystems])
    dv = ltu.dv_from_z(igm_z, galaxy.z)

    # Rules
    match = np.where((rho < R_max) & (np.abs(dv) < dv_max))[0]
    if len(match) == 0:
        print("No CGM objects match your rules")
        return []
    else:
        # Loop to generate
        cgm_list = []
        for imatch in match:
            cgm = CGMAbsSys(galaxy, igmsystems[imatch], cosmo=cosmo, **kwargs)
            cgm_list.append(cgm)

    # Return
    return cgm_list
Exemple #3
0
    def from_tarball(cls, tfile, debug=False, **kwargs):
        """ Load the COS-Halos survey from a tarball of JSON files
        Parameters
        ----------
        tfile : str

        Returns
        -------

        """
        import tarfile
        import json
        from linetools.lists.linelist import LineList
        llist = LineList('ISM')

        slf = cls(**kwargs)
        # Load
        tar = tarfile.open(tfile)
        for kk, member in enumerate(tar.getmembers()):
            if '.' not in member.name:
                print('Skipping a likely folder: {:s}'.format(member.name))
                continue
            # Debug
            if debug and (kk == 5):
                break
            # Extract
            f = tar.extractfile(member)
            tdict = json.load(f)
            # Generate
            cgmsys = CGMAbsSys.from_dict(tdict,
                                         chk_vel=False,
                                         chk_sep=False,
                                         chk_data=False,
                                         use_coord=True,
                                         use_angrho=True,
                                         linelist=llist,
                                         **kwargs)
            slf.cgm_abs.append(cgmsys)
        tar.close()
        # Return
        return slf
Exemple #4
0
    def from_tarball(cls, tfile, debug=False, **kwargs):
        """ Load the COS-Halos survey from a tarball of JSON files
        Parameters
        ----------
        tfile : str

        Returns
        -------

        """
        import tarfile
        import json
        from linetools.lists.linelist import LineList
        llist = LineList('ISM')

        slf = cls(**kwargs)
        # Load
        tar = tarfile.open(tfile)
        for kk, member in enumerate(tar.getmembers()):
            if '.' not in member.name:
                print('Skipping a likely folder: {:s}'.format(member.name))
                continue
            # Debug
            if debug and (kk == 5):
                break
            # Extract
            f = tar.extractfile(member)
            tdict = json.load(f)
            # Generate
            cgmsys = CGMAbsSys.from_dict(tdict, chk_vel=False, chk_sep=False, chk_data=False,
                                         use_coord=True, use_angrho=True,
                                         linelist=llist, **kwargs)
            slf.cgm_abs.append(cgmsys)
        tar.close()
        # Return
        return slf
Exemple #5
0
def p11():
    """ Ingest Prochaska et al. 2011 CGM survey
    """
    # Low z OVI summary
    ovi_file = pyigm.__path__[0] + '/data/CGM/P11/lowovidat.fits'
    ovidat = Table.read(ovi_file)
    qso_radec = SkyCoord(ra=ovidat['QSO_RA'],
                         dec=ovidat['QSO_DEC'],
                         unit=(u.hourangle, u.deg))
    qso_nms = np.array([row['QSO'].strip() for row in ovidat])

    # CGM Survey
    p11 = CGMAbsSurvey(survey='P11', ref='Prochaska+11')

    # Dwarfs
    cgm_dwarf_file = pyigm.__path__[0] + '/data/CGM/P11/dwarf_galabs_strct.fits'
    cgm_dwarfs = Table.read(cgm_dwarf_file)
    # sub L*
    cgm_subls_file = pyigm.__path__[0] + '/data/CGM/P11/subls_galabs_strct.fits'
    cgm_subls = Table.read(cgm_subls_file)
    # L*
    cgm_lstar_file = pyigm.__path__[0] + '/data/CGM/P11/lstar_galabs_strct.fits'
    cgm_lstar = Table.read(cgm_lstar_file)

    # Loop on subsets
    for subset in [cgm_dwarfs, cgm_subls, cgm_lstar]:
        for row in subset:
            # RA, DEC
            # Galaxy
            gal = Galaxy((row['RA'], row['DEC']), z=row['Z'])
            gal.Lstar = row['DDEC']
            gal.type = row['GAL_TYPE']
            # IGMSys
            mtqso = np.where(qso_nms == row['FIELD'].strip())[0]
            if len(mtqso) != 1:
                pdb.set_trace()
                raise ValueError("No Field match")
            igmsys = IGMSystem(qso_radec[mtqso[0]], row['Z'],
                               (-400., 400.) * u.km / u.s)
            # HI
            if row['MAG'][2] > 0.:
                # Lya
                lya = AbsLine(1215.67 * u.AA, z=float(row['MAG'][3]))
                lya.attrib['EW'] = row['MAG'][4] / 1e3 * u.AA
                if row['MAG'][5] >= 99.:
                    lya.attrib['flag_EW'] = 3
                else:
                    lya.attrib['flag_EW'] = 1
                lya.attrib['sig_EW'] = row['MAG'][5] / 1e3 * u.AA
                # Ref
                lya.attrib['Ref'] = int(row['MAG'][2])
                # HI component
                if row['MAG'][9] <= 0.:
                    flagN = 3
                elif row['MAG'][9] > 9.:
                    flagN = 2
                else:
                    flagN = 1
                HIcomp = AbsComponent(qso_radec[mtqso[0]], (1, 1),
                                      float(row['MAG'][3]),
                                      (-400, 400) * u.km / u.s,
                                      Ntup=(flagN, row['MAG'][8],
                                            row['MAG'][9]))
                HIcomp._abslines.append(lya)
                igmsys._components.append(HIcomp)
                # NHI
                igmsys.NHI = HIcomp.logN
                igmsys.flag_NHI = HIcomp.flag_N
                igmsys.sig_NHI = HIcomp.sig_N
            # OVI
            if row['MAGERR'][2] > 0.:
                # OVI 1031
                ovi1031 = None
                if row['MAGERR'][4] > 0.:
                    ovi1031 = AbsLine(1031.9261 * u.AA,
                                      z=float(row['MAGERR'][3]))
                    if row['MAGERR'][5] >= 99.:
                        ovi1031.attrib['flag_EW'] = 3
                    else:
                        ovi1031.attrib['flag_EW'] = 1
                    ovi1031.attrib['EW'] = row['MAGERR'][4] / 1e3 * u.AA
                    ovi1031.attrib['sig_EW'] = row['MAGERR'][5] / 1e3 * u.AA
                # OVI component
                if row['MAGERR'][9] <= 0.:
                    flagN = 3
                elif row['MAGERR'][9] > 9.:
                    flagN = 2
                else:
                    flagN = 1
                OVIcomp = AbsComponent(qso_radec[mtqso[0]], (8, 6),
                                       float(row['MAGERR'][3]),
                                       (-400, 400) * u.km / u.s,
                                       Ntup=(flagN, row['MAGERR'][8],
                                             row['MAGERR'][9]))
                if ovi1031 is not None:
                    OVIcomp._abslines.append(ovi1031)
                # Ref
                OVIcomp.Ref = int(row['MAG'][2])
                igmsys._components.append(OVIcomp)
            # CGM
            cgmabs = CGMAbsSys(gal, igmsys, chk_lowz=False)
            p11.cgm_abs.append(cgmabs)
    # Write tarball
    out_file = pyigm.__path__[0] + '/data/CGM/P11/P11_sys.tar'
    p11.to_json_tarball(out_file)
Exemple #6
0
def ingest_johnson15():
    """ Ingest Johnson+15
    """
    # Dict for QSO coords
    qsos = {}
    qsos['1ES1028+511'] = ltu.radec_to_coord('J103118.52517+505335.8193')
    qsos['FBQS1010+3003'] = ltu.radec_to_coord((152.5029167, 30.056111))
    qsos['HE0226-4110'] = ltu.radec_to_coord('J022815.252-405714.62')
    qsos['HS1102+3441'] = ltu.radec_to_coord('J110539.8189+342534.672')
    qsos['LBQS1435-0134'] = ltu.radec_to_coord((219.451183, -1.786328))
    qsos['PG0832+251'] = ltu.radec_to_coord('J083535.8048+245940.146')
    qsos['PG1522+101'] = ltu.radec_to_coord((231.1023075, 9.9749372))
    qsos['PKS0405-123'] = ltu.radec_to_coord('J040748.4376-121136.662')
    qsos['SBS1108+560'] = ltu.radec_to_coord((167.8841667, 55.790556))
    qsos['SBS1122+594'] = ltu.radec_to_coord((171.4741250, 59.172667))
    qsos['Ton236'] = ltu.radec_to_coord((232.1691746, 28.424928))

    # Virial matching
    j15_file = resource_filename('pyigm',
                                 'data/CGM/z0/johnson2015_table1.fits')
    j15_tbl = Table.read(j15_file)

    # Clip COS-Halos
    keep = j15_tbl['Survey'] != 'COS-Halos'
    j15_tbl = j15_tbl[keep]

    # CGM Survey
    j15 = CGMAbsSurvey(survey='J15', ref='Johnson+15')

    # Linelist
    llist = LineList('ISM')

    for row in j15_tbl:
        # RA, DEC
        # Galaxy
        gal = Galaxy((row['RAJ2000'], row['DEJ2000']), z=float(row['zgal']))
        gal.Class = row['Class']
        gal.Mstar = row['logM_']
        gal.field = row['Name']
        gal.Env = row['Env']
        gal.d_Rh = row['d_Rh']
        #
        igmsys = IGMSystem(qsos[row['Name']], float(row['zgal']),
                           (-400., 400.) * u.km / u.s)
        # HI
        if np.isnan(row['logNHI']):
            pass
        else:
            # HI component
            if row['l_logNHI'] == '<':
                flagN = 3
                sigNHI = 99.
            elif np.isnan(row['e_logNHI']):
                flagN = 2
                sigNHI = 99.
            else:
                flagN = 1
                sigNHI = row['e_logNHI']
            HIcomp = AbsComponent(qsos[row['Name']], (1, 1),
                                  float(row['zgal']), (-400, 400) * u.km / u.s,
                                  Ntup=(flagN, row['logNHI'], sigNHI))
            igmsys._components.append(HIcomp)
            # NHI
            igmsys.NHI = HIcomp.logN
            igmsys.flag_NHI = HIcomp.flag_N
            igmsys.sig_NHI = HIcomp.sig_N
        # OVI
        if np.isnan(row['logNHOVI']):
            pass
        else:
            # OVI component
            if row['l_logNHOVI'] == '<':
                flagN = 3
                sigNHOVI = 99.
            elif np.isnan(row['e_logNHOVI']):
                flagN = 2
                sigNHOVI = 99.
            else:
                flagN = 1
                sigNHOVI = row['e_logNHOVI']
            OVIcomp = AbsComponent(qsos[row['Name']], (8, 6),
                                   float(row['zgal']),
                                   (-400, 400) * u.km / u.s,
                                   Ntup=(flagN, row['logNHOVI'], sigNHOVI))
            igmsys._components.append(OVIcomp)
        # CGM
        cgmabs = CGMAbsSys(gal, igmsys, chk_lowz=False)
        j15.cgm_abs.append(cgmabs)
    # Write tarball
    out_file = resource_filename('pyigm', '/data/CGM/z0/J15_sys.tar')
    j15.to_json_tarball(out_file)
Exemple #7
0
def ingest_burchett16(smthd='vir'):
    """ Ingest Burchett+16
    """
    # Virial matching
    if smthd == 'vir':
        b16_file = resource_filename(
            'pyigm', 'data/CGM/z0/Burchett2016_CIV_HI_virselect.fits')
    else:
        b16_file = resource_filename(
            'pyigm', 'data/CGM/z0/Burchett2016_CIV_HI_kpcselect.fits')
    b16_tbl = Table.read(b16_file)

    # CGM Survey
    b16 = CGMAbsSurvey(survey='B16', ref='Burchett+16')

    # Linelist
    llist = LineList('ISM')

    for row in b16_tbl:
        # RA, DEC
        # Galaxy
        gal = Galaxy((row['ra_gal'], row['dec_gal']), z=row['zgal'])
        gal.SFR = row['SFR']
        gal.sig_SFR = row['SFR_err']
        gal.Mstar = row['mstars']
        gal.field = row['field']
        gal.RRvir = row['rrvir']
        gal.NSAidx = row['NSAidx']
        #
        igmsys = IGMSystem((row['ra_qso'], row['dec_qso']), row['zgal'],
                           (-400., 400.) * u.km / u.s)
        # HI
        if row['flag_h1'] > 0:
            # Lya
            lya = AbsLine(1215.67 * u.AA, z=row['zgal'], linelist=llist)
            lya.attrib['EW'] = row['EW_h1'] * u.AA
            lya.attrib['logN'] = row['col_h1']
            lya.attrib['N'] = 10**row['col_h1'] * u.cm**-2
            if row['flag_h1'] == 3:
                lya.attrib['flag_EW'] = 3
                lya.attrib['flag_N'] = 3
                lya.attrib['sig_N'] = (10**(row['col_h1'])) / 3. * u.cm**-2
            elif row['flag_h1'] == 2:
                lya.attrib['flag_EW'] = 1
                lya.attrib['flag_N'] = 2
            else:
                lya.attrib['flag_EW'] = 1
                lya.attrib['flag_N'] = 1
                lya.attrib['sig_N'] = (10**(row['col_h1'] + row['colsig_h1']) -
                                       10**row['col_h1']) * u.cm**-2
            lya.attrib['sig_EW'] = row['EWsig_h1'] * u.AA
            # Ref
            lya.attrib['Ref'] = 'Burchett+16'
            # HI component
            if row['colsig_h1'] >= 99.:
                flagN = 2
            elif row['colsig_h1'] <= 0.:
                flagN = 3
            else:
                flagN = 1
            HIcomp = AbsComponent(
                (row['ra_qso'], row['dec_qso']), (1, 1),
                row['zgal'], (-400, 400) * u.km / u.s,
                Ntup=(flagN, row['col_h1'], row['colsig_h1']))
            HIcomp._abslines.append(lya)
            igmsys._components.append(HIcomp)
            # NHI
            igmsys.NHI = HIcomp.logN
            igmsys.flag_NHI = HIcomp.flag_N
            igmsys.sig_NHI = HIcomp.sig_N
        # CIV
        if row['flag_c4'] > 0:
            # CIV 1548
            civ1548 = AbsLine(1548.195 * u.AA, z=row['zgal'], linelist=llist)
            civ1548.attrib['EW'] = row['EW_c4'] * u.AA
            civ1548.attrib['logN'] = row['col_c4']
            civ1548.attrib['N'] = 10**row['col_c4'] * u.cm**-2
            if row['flag_c4'] == 3:
                civ1548.attrib['flag_EW'] = 3
                civ1548.attrib['flag_N'] = 3
                civ1548.attrib['sig_N'] = (10**(row['col_c4'])) / 3. * u.cm**-2
            elif row['flag_c4'] == 2:
                civ1548.attrib['flag_EW'] = 1
                civ1548.attrib['flag_N'] = 2
            else:
                civ1548.attrib['flag_EW'] = 1
                civ1548.attrib['flag_N'] = 1
                civ1548.attrib['sig_N'] = (10**
                                           (row['col_c4'] + row['colsig_c4']) -
                                           10**row['col_c4']) * u.cm**-2
            civ1548.attrib['sig_EW'] = row['EWsig_c4'] * u.AA
            # Ref
            civ1548.attrib['Ref'] = 'Burchett+16'
            # CIV component
            if row['colsig_c4'] >= 99.:
                flagN = 2
            elif row['colsig_c4'] <= 0.:
                flagN = 3
            else:
                flagN = 1
            CIVcomp = AbsComponent(
                (row['ra_qso'], row['dec_qso']), (6, 4),
                row['zgal'], (-400, 400) * u.km / u.s,
                Ntup=(flagN, row['col_c4'], row['colsig_c4']))
            CIVcomp._abslines.append(civ1548)
            igmsys._components.append(CIVcomp)
        # CGM
        cgmabs = CGMAbsSys(gal, igmsys, correct_lowz=False)
        b16.cgm_abs.append(cgmabs)
    # Write tarball
    if smthd == 'vir':
        out_file = resource_filename('pyigm', '/data/CGM/z0/B16_vir_sys.tar')
    else:
        out_file = resource_filename('pyigm', '/data/CGM/z0/B16_kpc_sys.tar')
    b16.to_json_tarball(out_file)
Exemple #8
0
def cgm_from_galaxy_igmsystems(galaxy,
                               igmsystems,
                               rho_max=300 * u.kpc,
                               dv_max=400 * u.km / u.s,
                               cosmo=None,
                               dummysys=False,
                               dummyspec=None,
                               verbose=True,
                               **kwargs):
    """ Generate a list of CGMAbsSys objects given an input galaxy and a list of IGMSystems

    Parameters
    ----------
    galaxy : Galaxy
    igmsystems : list
      list of IGMSystems
    rho_max : Quantity
      Maximum projected separation from sightline to galaxy
    dv_max
      Maximum velocity offset between system and galaxy
    dummysys: bool, optional
        If True, instantiate CGMAbsSys even if no match is found in igmsystems
    dummyspec : XSpectrum1D, optional
        Spectrum object to attach to dummy AbsLine/AbsComponent objects when
        adding IGMSystems if dummysys is True.

    Returns
    -------
    cgm_list : list
      list of CGM objects generated

    """
    from pyigm.cgm.cgm import CGMAbsSys
    # Cosmology
    if cosmo is None:
        cosmo = cosmology.Planck15

    if dummysys is True:
        if dummyspec is None:
            dummyspec = igmsystems[0]._components[0]._abslines[0].analy['spec']
        dummycoords = igmsystems[0].coord

    # R -- speed things up
    rho, angles = calc_cgm_rho(galaxy, igmsystems, cosmo, **kwargs)
    if len(igmsystems) == 1:  # Kludge
        rho = u.Quantity([rho])
        angles = u.Quantity([angles])

    # dv
    igm_z = np.array([igmsystem.zabs for igmsystem in igmsystems])
    dv = ltu.dv_from_z(igm_z, galaxy.z)

    # Rules
    match = np.where((rho < rho_max) & (np.abs(dv) < dv_max))[0]

    ### If none, see if some system has a component that's actually within dv_max
    if (len(match) == 0) & (rho[0] < rho_max):
        zcomps = []
        sysidxs = []
        for i, csys in enumerate(igmsystems):
            thesezs = [comp.zcomp for comp in csys._components]
            sysidxs.extend([i] * len(thesezs))
            zcomps.extend(thesezs)
        zcomps = np.array(zcomps)
        sysidxs = np.array(sysidxs)
        dv_comps = ltu.dv_from_z(zcomps, galaxy.z)
        match = np.unique(sysidxs[np.where(np.abs(dv_comps) < dv_max)[0]])

    if len(match) == 0:
        if dummysys is False:
            print(
                "No IGMSystem paired to this galaxy. CGM object not created.")
            return []
        else:
            if verbose:
                print("No IGMSystem match found. Attaching dummy IGMSystem.")
            dummysystem = IGMSystem(dummycoords, galaxy.z, vlim=None)
            dummycomp = AbsComponent(dummycoords, (1, 1), galaxy.z,
                                     [-100., 100.] * u.km / u.s)
            dummycomp.flag_N = 3
            dummyline = AbsLine(
                'HI 1215',
                **kwargs)  # Need an actual transition for comp check
            dummyline.analy['spec'] = dummyspec
            dummyline.attrib['coord'] = dummycoords
            dummycomp.add_absline(dummyline, chk_vel=False, chk_sep=False)
            dummysystem.add_component(dummycomp, chk_vel=False, chk_sep=False)
            cgm = CGMAbsSys(galaxy, dummysystem, cosmo=cosmo, **kwargs)
            cgm_list = [cgm]
    else:
        # Loop to generate
        cgm_list = []
        for imatch in match:
            # Instantiate new IGMSystem
            # Otherwise, updates to the IGMSystem cross-pollinate other CGMs
            sysmatch = igmsystems[imatch]
            newisys = sysmatch.copy()
            # Handle z limits
            zlim = ltu.z_from_dv((-dv_max.value, dv_max.value) * u.km / u.s,
                                 galaxy.z)
            newlims = zLimits(galaxy.z, zlim.tolist())
            newisys.limits = newlims
            # Allow for components extending beyond dv_max
            newisys.update_vlim()
            newisys.update_component_vel()
            # Finish
            cgm = CGMAbsSys(galaxy,
                            newisys,
                            cosmo=cosmo,
                            rho=rho[imatch],
                            ang_sep=angles[imatch],
                            **kwargs)
            cgm_list.append(cgm)

    # Return
    return cgm_list
Exemple #9
0
    def load_tarball(self,
                     tfile,
                     build_data=True,
                     build_sys=False,
                     llist=None,
                     verbose=True,
                     **kwargs):
        """
        Parameters
        ----------
        tfile
        build_data
        build_sys
        llist
        kwargs

        Returns
        -------

        """
        import tarfile
        # Load
        tar = tarfile.open(tfile)
        for kk, member in enumerate(tar.getmembers()):
            if '.json' not in member.name:
                print('Skipping a likely folder: {:s}'.format(member.name))
                continue
            # Extract
            f = tar.extractfile(member)
            try:
                tdict = json.load(f)
            except:
                if verbose:
                    print('Unable to load {}'.format(member))
                continue
            # Build dict
            self._dict[tdict['Name']] = tdict
            # Generate
            if build_sys:
                cgmsys = CGMAbsSys.from_dict(tdict,
                                             chk_vel=False,
                                             chk_sep=False,
                                             chk_data=False,
                                             use_coord=True,
                                             use_angrho=True,
                                             linelist=llist,
                                             **kwargs)
                self.cgm_abs.append(cgmsys)
        tar.close()

        # Galaxy coords
        ras = [self._dict[key]['RA'] for key in self._dict.keys()]
        decs = [self._dict[key]['DEC'] for key in self._dict.keys()]
        self.coords = SkyCoord(ra=ras, dec=decs, unit='deg')

        # Sightline coords
        ras = [self._dict[key]['igm_sys']['RA'] for key in self._dict.keys()]
        decs = [self._dict[key]['igm_sys']['DEC'] for key in self._dict.keys()]
        self.scoords = SkyCoord(ra=ras, dec=decs, unit='deg')

        # Data table
        if build_data:
            self.build_data_from_dict()
        # Return
        return
Exemple #10
0
    def load_coolgas(self):
        """ Load data on cool gas (CII, CIV, SiII, SiIII)
        Richter+17
        """
        llist = LineList('ISM')
        # Ricther+17
        print('Loading Richter+17 for CII, CIV, SiII, SiIII')
        r17_a1_file = resource_filename('pyigm',
                                        '/data/CGM/Galaxy/richter17_A1.fits')
        r17_a1 = Table.read(r17_a1_file)
        r17_a2_file = resource_filename('pyigm',
                                        '/data/CGM/Galaxy/richter17_A2.fits')
        r17_a2 = Table.read(r17_a2_file)
        # Coords
        coords = SkyCoord(ra=r17_a1['_RAJ2000'],
                          dec=r17_a1['_DEJ2000'],
                          unit='deg')
        gc = coords.transform_to('galactic')
        ra = np.zeros((len(r17_a2)))
        dec = np.zeros((len(r17_a2)))

        # Loop on Sightlines
        for kk, row in enumerate(r17_a1):
            if self.debug and (kk == 5):
                break
            a2_idx = np.where(r17_a2['Name'] == row['Name'])[0]
            if len(a2_idx) == 0:
                continue
            ra[a2_idx] = row['_RAJ2000']
            dec[a2_idx] = row['_DEJ2000']
            # Generate the components
            icoord = gc[kk]
            alines = []
            for jj, idx in enumerate(a2_idx):
                # Transition
                trans = '{:s} {:d}'.format(r17_a2['Ion'][idx].strip(),
                                           int(r17_a2['lambda0'][idx]))
                try:
                    aline = AbsLine(trans, linelist=llist)
                except ValueError:
                    pdb.set_trace()
                aline.attrib['coord'] = icoord

                # Skip EW=0 lines
                if r17_a2['e_W'][idx] == 0:
                    continue
                # Velocity
                z = 0.
                aline.setz(z)
                vlim = np.array([r17_a2['vmin'][idx], r17_a2['vmax'][idx]
                                 ]) * u.km / u.s

                aline.limits.set(vlim)  # These are v_LSR
                # EW
                aline.attrib['flag_EW'] = 1
                aline.attrib['EW'] = r17_a2['W'][idx] / 1e3 * u.AA
                aline.attrib['sig_EW'] = r17_a2['e_W'][idx] / 1e3 * u.AA
                # Column

                if np.isnan(
                        r17_a2['logN']
                    [idx]):  # Odd that some lines had an error but no value
                    aline.attrib['flag_N'] = 0
                elif r17_a2['l_logN'][idx] == '>':
                    aline.attrib['flag_N'] = 2
                    aline.attrib['sig_logN'] = 99.99
                else:
                    aline.attrib['flag_N'] = 1
                    aline.attrib['sig_logN'] = r17_a2['e_logN'][idx]
                aline.attrib['logN'] = r17_a2['logN'][idx]
                # Fill linear
                _, _ = linear_clm(aline.attrib)
                alines.append(aline)
            # Generate components from abslines
            comps = ltiu.build_components_from_abslines(alines,
                                                        chk_sep=False,
                                                        chk_vel=False)
            # Limits
            vmin = np.min([icomp.limits.vmin.value for icomp in comps])
            vmax = np.max([icomp.limits.vmax.value for icomp in comps])
            # Instantiate
            s_kwargs = dict(name=row['Name'] + '_z0')
            c_kwargs = dict(chk_sep=False, chk_z=False)
            abssys = IGMSystem.from_components(comps,
                                               vlim=[vmin, vmax] * u.km / u.s,
                                               s_kwargs=s_kwargs,
                                               c_kwargs=c_kwargs)
            # CGM Abs
            rho, ang_sep = calc_Galactic_rho(abssys.coord)
            cgmabs = CGMAbsSys(self.galaxy,
                               abssys,
                               rho=rho,
                               ang_sep=ang_sep,
                               cosmo=self.cosmo)
            # Add to cgm_abs
            self.abs.cgm_abs.append(cgmabs)
        # Finish
        r17_a2['RA'] = ra
        r17_a2['DEC'] = dec
        self.richter17 = r17_a2
        # Reference
        if len(self.refs) > 0:
            self.refs += ','
        self.refs += 'Richter+17'
Exemple #11
0
    def load_hotgas(self):
        """ Load data on hot gas (e.g. OVII, OVIII)
        Fang+15
        """

        # Init
        llist = LineList('EUV')
        ovii = AbsLine('OVII 21', linelist=llist)
        scoord = self.abs.scoord  # Sightline coordiantes

        # Fang+15  Table 1  [OVII]
        fang15_file = resource_filename('pyigm',
                                        '/data/CGM/Galaxy/fang15_table1.dat')
        self.fang15 = Table.read(fang15_file, format='cds')
        print('Loading Fang+15 for OVII')
        # Reference
        if len(self.refs) > 0:
            self.refs += ','
        self.refs += 'Fang+15'
        # Generate the systems
        # # (should check to see if low-ion ones exist already)
        for row in self.fang15:
            # Coordinates
            gc = SkyCoord(l=row['GLON'] * u.degree,
                          b=row['GLAT'] * u.degree,
                          frame='galactic')
            # Limits
            # OVII line
            aline = ovii.copy()
            aline.attrib['coord'] = gc
            z = row['Vel'] / c_kms
            try:
                aline.setz(z)
            except IOError:
                z = 0.
                vlim = np.array([-300, 300]) * u.km / u.s
                aline.attrib['flag_EW'] = 3
                aline.attrib['EW'] = row['EW1'] / 1e3 * u.AA
                aline.attrib['sig_EW'] = 99. * u.AA
                #
                aline.attrib[
                    'flag_N'] = 0  # Might be able to set an upper limit
            else:
                aline.attrib['b'] = row['b'] * u.km / u.s
                aline.attrib['flag_EW'] = 1
                aline.attrib['EW'] = row['EW1'] / 1e3 * u.AA
                aline.attrib['sig_EW'] = row['e_EW1'] / 1e3 * u.AA
                vlim = np.array(
                    [-1, 1]) * (2 * row['b'] + 2 * row['E_b']) * u.km / u.s
                # N_OVII
                aline.attrib['flag_N'] = 1
                aline.attrib['logN'] = row['logNO']
                aline.attrib['sig_logN'] = np.array(
                    [row['e_logNO'], row['E_logNO']])
                # Fill linear
                _, _ = linear_clm(aline.attrib)
            # OVII
            aline.limits.set(vlim)
            # Generate component and add
            comp = AbsComponent.from_abslines([aline])
            if aline.attrib['flag_N'] == 0:  # Hack to merge later
                comp.attrib['sig_logN'] = np.array([0., 0.])
            else:
                pass
            # Check for existing system
            minsep = np.min(comp.coord.separation(scoord).to('arcsec'))
            if minsep < 30 * u.arcsec:  # Add component to existing system
                idx = np.argmin(comp.coord.separation(scoord).to('arcsec'))
                if self.verbose:
                    print("Adding OVII system to {}".format(
                        self.abs.cgm_abs[idx].igm_sys))
                self.abs.cgm_abs[idx].igm_sys.add_component(comp,
                                                            chk_sep=False,
                                                            debug=True)
            else:  # Instantiate
                abssys = IGMSystem(gc,
                                   z,
                                   vlim,
                                   name=row['Name'] + '_z0',
                                   zem=row['z'])
                abssys.add_component(comp, chk_sep=False)
                # CGM Abs
                rho, ang_sep = calc_Galactic_rho(abssys.coord)
                cgmabs = CGMAbsSys(self.galaxy,
                                   abssys,
                                   rho=rho,
                                   ang_sep=ang_sep,
                                   cosmo=self.cosmo)
                # Add to cgm_abs
                self.abs.cgm_abs.append(cgmabs)

        scoord = self.abs.scoord  # Sightline coordiantes
        # Savage+03  Table 2  [OVI] -- Thick disk/halo only??
        print('Loading Savage+03 for OVI')
        savage03_file = resource_filename(
            'pyigm', '/data/CGM/Galaxy/savage03_table2.fits')
        self.savage03 = Table.read(savage03_file)
        # Reference
        if len(self.refs) > 0:
            self.refs += ','
        self.refs += 'Savage+03'
        # Generate the systems
        # # (should check to see if low-ion ones exist already)
        for row in self.savage03:
            # Coordinates
            coord = SkyCoord(ra=row['_RA'] * u.deg,
                             dec=row['_DE'] * u.deg,
                             frame='icrs')
            gc = coord.transform_to('galactic')
            # Build the component
            vlim = np.array([row['V-'], row['V_']]) * u.km / u.s
            comp = AbsComponent(gc, (8, 6), 0., vlim)
            # Add attributes
            if row['b'] > 0.:
                comp.attrib['vcen'] = row['__v_obs'] * u.km / u.s
                comp.attrib['sig_vcen'] = row['e__v_obs'] * u.km / u.s
                comp.attrib['b'] = row['b'] * u.km / u.s
                comp.attrib['sig_b'] = row['e_b'] * u.km / u.s
                # Column
                comp.attrib['flag_N'] = 1
                comp.attrib['logN'] = row['logN_OVI_']
                comp.attrib['sig_logN'] = np.array(
                    [np.sqrt(row['e_sc']**2 + row['e_sys']**2)] * 2)
            else:  # Upper limit
                comp.attrib['flag_N'] = 3
                comp.attrib['logN'] = row['logN_OVI_']
                comp.attrib['sig_logN'] = np.array([99.] * 2)
            # Set linear quantities
            _, _ = linear_clm(comp.attrib)
            # Check for existing system
            minsep = np.min(comp.coord.separation(scoord).to('arcsec'))
            if minsep < 30 * u.arcsec:
                idx = np.argmin(comp.coord.separation(scoord).to('arcsec'))
                self.abs.cgm_abs[idx].igm_sys.add_component(comp,
                                                            chk_sep=False,
                                                            debug=True,
                                                            update_vlim=True)
            else:  # New
                if row['RV'] > 0:
                    zem = row['RV'] / c_kms
                else:
                    zem = row['z']
                abssys = IGMSystem(gc,
                                   comp.zcomp,
                                   vlim,
                                   name=row['Name'] + '_z0',
                                   zem=zem)
                abssys.add_component(comp, chk_sep=False, debug=True)
                # CGM Abs
                rho, ang_sep = calc_Galactic_rho(abssys.coord)
                cgmabs = CGMAbsSys(self.galaxy,
                                   abssys,
                                   rho=rho,
                                   ang_sep=ang_sep,
                                   cosmo=self.cosmo)
                # Add to cgm_abs
                self.abs.cgm_abs.append(cgmabs)