def load_lowz(cls, grab_spectra=False, isys_path=None):
        """ LLS from Wotta+16 (includes Lehner+13)
        Updated to include systems excluded by Wotta+16 (high NHI)

        Parameters
        ----------
        grab_spectra : bool, optional
          Not implemented

        Return
        ------
        lls_survey
        """

        # System files
        l13_files = pyigm_path + '/data/LLS/Literature/lehner13.tar.gz'
        w16_files = pyigm_path + '/data/LLS/Literature/wotta16.tar.gz'

        # Load systems via the sys tarball.  Includes transitions
        L13_survey = pyisu.load_sys_files(l13_files, 'LLS', ref='Lehner+13')
        W16_survey = pyisu.load_sys_files(w16_files, 'LLS', ref='Wotta+16')
        lowz_LLS = L13_survey + W16_survey

        # Spectra?
        if grab_spectra:
            raise NotImplementedError("NOPE")
            specfils = glob.glob(spath + 'HD-LLS_J*.fits')
            if len(specfils) < 100:
                import tarfile
                print('HD-LLS: Downloading a 155Mb file.  Be patient..')
                url = 'http://www.ucolick.org/~xavier/HD-LLS/DR1/HD-LLS_spectra.tar.gz'
                spectra_fil = pyigm_path + '/data/LLS/HD-LLS/HD-LLS_spectra.tar.gz'
                f = urllib2.urlopen(url)
                with open(spectra_fil, "wb") as code:
                    code.write(f.read())
                # Unpack
                print('HD-LLS: Unpacking..')
                outdir = pyigm_path + "/data/LLS/HD-LLS"
                t = tarfile.open(spectra_fil, 'r:gz')
                t.extractall(outdir)
                # Done
                print('HD-LLS: All done')
            else:
                print('HD-LLS: Using files in {:s}'.format(spath))

        return lowz_LLS
Exemple #2
0
    def load_lowz(cls, grab_spectra=False, isys_path=None):
        """ LLS from Wotta+16 (includes Lehner+13)

        Parameters
        ----------
        grab_spectra : bool, optional
          Not implemented

        Return
        ------
        lls_survey
        """

        # System files
        l13_files = pyigm_path+'/data/LLS/Literature/lehner13.tar.gz'
        w16_files = pyigm_path+'/data/LLS/Literature/wotta16.tar.gz'


        # Load systems via the sys tarball.  Includes transitions
        L13_survey = pyisu.load_sys_files(l13_files, 'LLS', ref='Lehner+13')
        W16_survey = pyisu.load_sys_files(w16_files, 'LLS', ref='Wotta+16')
        lowz_LLS = L13_survey+W16_survey

        # Spectra?
        if grab_spectra:
            raise NotImplementedError("NOPE")
            specfils = glob.glob(spath+'HD-LLS_J*.fits')
            if len(specfils) < 100:
                import tarfile
                print('HD-LLS: Downloading a 155Mb file.  Be patient..')
                url = 'http://www.ucolick.org/~xavier/HD-LLS/DR1/HD-LLS_spectra.tar.gz'
                spectra_fil = pyigm_path+'/data/LLS/HD-LLS/HD-LLS_spectra.tar.gz'
                f = urllib2.urlopen(url)
                with open(spectra_fil, "wb") as code:
                    code.write(f.read())
                # Unpack
                print('HD-LLS: Unpacking..')
                outdir = pyigm_path+"/data/LLS/HD-LLS"
                t = tarfile.open(spectra_fil, 'r:gz')
                t.extractall(outdir)
                # Done
                print('HD-LLS: All done')
            else:
                print('HD-LLS: Using files in {:s}'.format(spath))

        return lowz_LLS
    def load_HDLLS(cls, load_sys=True, grab_spectra=False, isys_path=None):
        """ Default sample of LLS (HD-LLS, DR1)

        Parameters
        ----------
        grab_spectra : bool, optional
          Grab 1D spectra?  (155Mb)
        load_sys : bool, optional
          Load systems using the sys tarball
        isys_path : str, optional
          Read system files from this path

        Return
        ------
        lls_survey
        """

        # Pull from Internet (as necessary)
        summ_fil = pyigm_path + "/data/LLS/HD-LLS/HD-LLS_DR1.fits"
        print('HD-LLS: Loading summary file {:s}'.format(summ_fil))

        # Ions
        ions_fil = pyigm_path + "/data/LLS/HD-LLS/HD-LLS_ions.json"
        print('HD-LLS: Loading ions file {:s}'.format(ions_fil))

        # System files
        sys_files = pyigm_path + "/data/LLS/HD-LLS/HD-LLS_sys.tar.gz"

        # Transitions
        #clm_files = pyigm_path+"/data/LLS/HD-LLS/HD-LLS_clms.tar.gz"

        # Metallicity
        ZH_fil = pyigm_path + "/data/LLS/HD-LLS/HD-LLS_DR1_dustnhi.hdf5"
        print('HD-LLS: Loading metallicity file {:s}'.format(ZH_fil))

        # Load systems via the sys tarball.  Includes transitions
        if load_sys:  # This approach takes ~120s
            if isys_path is not None:
                lls_survey = pyisu.load_sys_files(isys_path,
                                                  'LLS',
                                                  sys_path=True,
                                                  ref='HD-LLS')
            else:
                lls_survey = pyisu.load_sys_files(sys_files,
                                                  'LLS',
                                                  ref='HD-LLS')
            lls_survey.fill_ions(use_components=True)
        else:
            # Read
            lls_survey = cls.from_sfits(summ_fil)
            # Load ions
            lls_survey.fill_ions(jfile=ions_fil)
        lls_survey.ref = 'HD-LLS'
        """
        # Load transitions
        if not skip_trans:
            print('HD-LLS: Loading transitions from {:s}'.format(clm_files))
            tar = tarfile.open(clm_files)
            for member in tar.getmembers():
                if '.' not in member.name:
                    print('Skipping a likely folder: {:s}'.format(member.name))
                    continue
                # Extract
                f = tar.extractfile(member)
                tdict = json.load(f)
                # Find system
                i0 = member.name.rfind('/')
                i1 = member.name.rfind('_clm')
                try:
                    idx = names.index(member.name[i0+1:i1])
                except ValueError:
                    print('Skipping {:s}, not statistical in DR1'.format(member.name[i0+1:i1]))
                    continue
                # Fill up
                lls_survey._abs_sys[idx].load_components(tdict)
                lls_survey._abs_sys[idx]._components = lls_survey._abs_sys[idx].subsys['A']._components
        """

        # Load metallicity
        fh5 = h5py.File(ZH_fil, 'r')
        ras = []
        decs = []
        zval = []
        mkeys = fh5['met'].keys()
        mkeys.remove('left_edge_bins')
        for key in mkeys:
            radec, z = key.split('z')
            coord = ltu.radec_to_coord(radec)
            # Save
            zval.append(float(z))
            ras.append(coord.ra.value)
            decs.append(coord.dec.value)
        mcoords = SkyCoord(ras, decs, unit='deg')
        zval = np.array(zval)

        # Set data path and metallicity
        spath = pyigm_path + "/data/LLS/HD-LLS/Spectra/"
        for lls in lls_survey._abs_sys:
            lls.spec_path = spath
            # Match
            sep = lls.coord.separation(mcoords)
            mt = np.where((sep < 15 * u.arcsec)
                          & (np.abs(zval - lls.zabs) < 2e-3))[0]
            if len(mt) == 0:
                pdb.set_trace()
                raise ValueError("Bad match")
            elif len(mt) > 1:  # Take closest
                mt = np.argmin(sep)
            else:
                mt = mt[0]
            # Save
            lls.metallicity = MetallicityPDF(
                fh5['met']['left_edge_bins'] +
                fh5['met']['left_edge_bins'].attrs['BINSIZE'] / 2.,
                fh5['met'][mkeys[mt]])

        # Spectra?
        if grab_spectra:
            specfils = glob.glob(spath + 'HD-LLS_J*.fits')
            if len(specfils) < 100:
                import tarfile
                print('HD-LLS: Downloading a 155Mb file.  Be patient..')
                url = 'http://www.ucolick.org/~xavier/HD-LLS/DR1/HD-LLS_spectra.tar.gz'
                spectra_fil = pyigm_path + '/data/LLS/HD-LLS/HD-LLS_spectra.tar.gz'
                f = urllib2.urlopen(url)
                with open(spectra_fil, "wb") as code:
                    code.write(f.read())
                # Unpack
                print('HD-LLS: Unpacking..')
                outdir = pyigm_path + "/data/LLS/HD-LLS"
                t = tarfile.open(spectra_fil, 'r:gz')
                t.extractall(outdir)
                # Done
                print('HD-LLS: All done')
            else:
                print('HD-LLS: Using files in {:s}'.format(spath))

        return lls_survey
Exemple #4
0
    def load_H100(cls, grab_spectra=False, load_sys=True, isys_path=None):  #skip_trans=True):
        """ Sample of unbiased HIRES DLAs compiled and analyzed by Neeleman+13

        Neeleman, M. et al. 2013, ApJ, 769, 54

        Parameters
        ----------
        grab_spectra : bool, optional
          Grab 1D spectra?  (141Mb)
        load_sys : bool, optional
          Load systems? (takes ~60s for 100 systems)
        skip_trans : bool, optional
          Skip loading transitions (takes ~60s)?
        isys_path : str, optional
          Read system files from this path

        Return
        ------
        dla_survey
        """
        # Pull from Internet (as necessary)
        summ_fil = pyigm_path+"/data/DLA/H100/H100_DLA.fits"
        print('H100: Loading summary file {:s}'.format(summ_fil))

        # Ions
        ions_fil = pyigm_path+"/data/DLA/H100/H100_DLA_ions.json"
        print('H100: Loading ions file {:s}'.format(ions_fil))

        # Transitions
        trans_fil = pyigm_path+"/data/DLA/H100/H100_DLA_clms.tar.gz"

        # System files
        sys_files = pyigm_path+"/data/DLA/H100/H100_DLA_sys.tar.gz"

        if load_sys:  # This approach takes ~120s
            print('H100: Loading systems.  This takes ~120s')
            if isys_path is not None:
                dla_survey = pyisu.load_sys_files(isys_path, 'DLA', sys_path=True)
            else:
                dla_survey = pyisu.load_sys_files(sys_files, 'DLA')
            dla_survey.fill_ions(use_components=True)
        else:
            # Read
            dla_survey = cls.from_sfits(summ_fil)
            # Load ions
            dla_survey.fill_ions(jfile=ions_fil)

        dla_survey.ref = 'Neeleman+13'

        """
        # Load transitions
        names = list(dla_survey.name)
        if not skip_trans:
            print('H100: Loading transitions file {:s}'.format(trans_fil))
            tar = tarfile.open(trans_fil)
            for member in tar.getmembers():
                if '.' not in member.name:
                    print('Skipping a likely folder: {:s}'.format(member.name))
                    continue
                # Extract
                f = tar.extractfile(member)
                # Need to fix for 3.4
                tdict = json.load(f)
                # Find system
                i0 = member.name.rfind('/')
                i1 = member.name.rfind('_clm')
                try:
                    idx = names.index(member.name[i0+1:i1])
                except ValueError:
                    pdb.set_trace()
                # Fill up
                dla_survey._abs_sys[idx].load_components(tdict)
        """


        spath = pyigm_path+"/data/DLA/H100/Spectra/"
        for dla in dla_survey._abs_sys:
            dla.spec_path = spath

        # Spectra?
        if grab_spectra:
            pdb.set_trace()  # USE IGMSPEC!!
            specfils = glob.glob(spath+'H100_J*.fits')
            if len(specfils) < 100:
                import tarfile
                print('H100: Downloading a 141Mb file.  Be patient..')
                url = 'https://dl.dropboxusercontent.com/u/6285549/DLA/H100/H100_DLA_spectra.tar.gz'
                spectra_fil = pyigm_path+'/data/DLA/H100/H100_spectra.tar.gz'
                f = urllib2.urlopen(url)
                with open(spectra_fil, "wb") as code:
                    code.write(f.read())
                # Unpack
                print('H100: Unpacking..')
                outdir = pyigm_path+"/data/DLA/H100"
                t = tarfile.open(spectra_fil, 'r:gz')
                t.extractall(outdir)
                # Remove
                print('H100: Removing tar file')
                os.remove(spectra_fil)
                # Done
                print('H100: All done')
            else:
                print('H100: Using files in {:s}'.format(spath))

        return dla_survey
Exemple #5
0
    def load_HDLLS(cls, load_sys=True, grab_spectra=False, isys_path=None):
        """ Default sample of LLS (HD-LLS, DR1)

        Parameters
        ----------
        grab_spectra : bool, optional
          Grab 1D spectra?  (155Mb)
        load_sys : bool, optional
          Load systems using the sys tarball
        isys_path : str, optional
          Read system files from this path

        Return
        ------
        lls_survey
        """

        # Pull from Internet (as necessary)
        summ_fil = pyigm_path+"/data/LLS/HD-LLS/HD-LLS_DR1.fits"
        print('HD-LLS: Loading summary file {:s}'.format(summ_fil))

        # Ions
        ions_fil = pyigm_path+"/data/LLS/HD-LLS/HD-LLS_ions.json"
        print('HD-LLS: Loading ions file {:s}'.format(ions_fil))

        # System files
        sys_files = pyigm_path+"/data/LLS/HD-LLS/HD-LLS_sys.tar.gz"

        # Transitions
        #clm_files = pyigm_path+"/data/LLS/HD-LLS/HD-LLS_clms.tar.gz"

        # Metallicity
        ZH_fil = pyigm_path+"/data/LLS/HD-LLS/HD-LLS_DR1_dustnhi.hdf5"
        print('HD-LLS: Loading metallicity file {:s}'.format(ZH_fil))

        # Load systems via the sys tarball.  Includes transitions
        if load_sys:  # This approach takes ~120s
            if isys_path is not None:
                lls_survey = pyisu.load_sys_files(isys_path, 'LLS',sys_path=True)
            else:
                lls_survey = pyisu.load_sys_files(sys_files, 'LLS')
            lls_survey.fill_ions(use_components=True)
        else:
            # Read
            lls_survey = cls.from_sfits(summ_fil)
            # Load ions
            lls_survey.fill_ions(jfile=ions_fil)
        lls_survey.ref = 'HD-LLS'

        """
        # Load transitions
        if not skip_trans:
            print('HD-LLS: Loading transitions from {:s}'.format(clm_files))
            tar = tarfile.open(clm_files)
            for member in tar.getmembers():
                if '.' not in member.name:
                    print('Skipping a likely folder: {:s}'.format(member.name))
                    continue
                # Extract
                f = tar.extractfile(member)
                tdict = json.load(f)
                # Find system
                i0 = member.name.rfind('/')
                i1 = member.name.rfind('_clm')
                try:
                    idx = names.index(member.name[i0+1:i1])
                except ValueError:
                    print('Skipping {:s}, not statistical in DR1'.format(member.name[i0+1:i1]))
                    continue
                # Fill up
                lls_survey._abs_sys[idx].load_components(tdict)
                lls_survey._abs_sys[idx]._components = lls_survey._abs_sys[idx].subsys['A']._components
        """


        # Load metallicity
        fh5=h5py.File(ZH_fil, 'r')
        ras = []
        decs = []
        zval = []
        mkeys = fh5['met'].keys()
        mkeys.remove('left_edge_bins')
        for key in mkeys:
            radec, z = key.split('z')
            coord = ltu.radec_to_coord(radec)
            # Save
            zval.append(float(z))
            ras.append(coord.ra.value)
            decs.append(coord.dec.value)
        mcoords = SkyCoord(ras, decs, unit='deg')
        zval = np.array(zval)

        # Set data path and metallicity
        spath = pyigm_path+"/data/LLS/HD-LLS/Spectra/"
        for lls in lls_survey._abs_sys:
            lls.spec_path = spath
            # Match
            sep = lls.coord.separation(mcoords)
            mt = np.where((sep < 15*u.arcsec) & (np.abs(zval-lls.zabs) < 2e-3))[0]
            if len(mt) == 0:
                pdb.set_trace()
                raise ValueError("Bad match")
            elif len(mt) > 1:  # Take closest
                mt = np.argmin(sep)
            # Save
            lls.metallicity = MetallicityPDF(fh5['met']['left_edge_bins']+
                                             fh5['met']['left_edge_bins'].attrs['BINSIZE']/2.,
                                             fh5['met'][mkeys[mt]])

        # Spectra?
        if grab_spectra:
            specfils = glob.glob(spath+'HD-LLS_J*.fits')
            if len(specfils) < 100:
                import tarfile
                print('HD-LLS: Downloading a 155Mb file.  Be patient..')
                url = 'http://www.ucolick.org/~xavier/HD-LLS/DR1/HD-LLS_spectra.tar.gz'
                spectra_fil = pyigm_path+'/data/LLS/HD-LLS/HD-LLS_spectra.tar.gz'
                f = urllib2.urlopen(url)
                with open(spectra_fil, "wb") as code:
                    code.write(f.read())
                # Unpack
                print('HD-LLS: Unpacking..')
                outdir = pyigm_path+"/data/LLS/HD-LLS"
                t = tarfile.open(spectra_fil, 'r:gz')
                t.extractall(outdir)
                # Done
                print('HD-LLS: All done')
            else:
                print('HD-LLS: Using files in {:s}'.format(spath))

        return lls_survey
Exemple #6
0
    def load_H100(cls, grab_spectra=False, build_abs_sys=True, isys_path=None):
        """ Sample of unbiased HIRES DLAs compiled and analyzed by Neeleman+13

        Neeleman, M. et al. 2013, ApJ, 769, 54

        Parameters
        ----------
        build_abs_sys : bool, optional
          Build AbsSystem objects (~10s)
          Required for a fair bit of other things, e.g. kin
        isys_path : str, optional
          Read system files from this path
        grab_spectra : bool, optional
          Grab 1D spectra?  (141Mb)
          deprecated..   Use igmspec

        Return
        ------
        dla_survey : DLASurvey
        """

        # Pull from Internet (as necessary)
        summ_fil = resource_filename('pyigm', "/data/DLA/H100/H100_DLA.fits")
        print('H100: Loading summary file {:s}'.format(summ_fil))

        # Ions
        ions_fil = resource_filename('pyigm',
                                     "/data/DLA/H100/H100_DLA_ions.json")
        print('H100: Loading ions file {:s}'.format(ions_fil))

        # Transitions
        trans_fil = resource_filename('pyigm',
                                      "/data/DLA/H100/H100_DLA_clms.tar.gz")

        # System files
        sys_files = resource_filename('pyigm',
                                      "/data/DLA/H100/H100_DLA_sys.tar.gz")

        print('H100: Loading systems.  This takes ~10s')
        dla_survey = pyisu.load_sys_files(sys_files,
                                          'DLA',
                                          build_abs_sys=build_abs_sys)
        # Reset flag_NHI (which has been wrong)
        for key in dla_survey._dict.keys():
            dla_survey._dict[key]['flag_NHI'] = 1
        # Fill ion Tables
        if build_abs_sys:
            print("Filling the _ionN tables...")
            dla_survey.fill_ions(use_components=True)
        dla_survey.ref = 'Neeleman+13'

        if not build_abs_sys:
            print(
                "Not loading up all the other data.  Use build_abs_sys=True for that!"
            )
            return dla_survey

        # Metallicities
        tbl2_file = resource_filename('pyigm',
                                      "/data/DLA/H100/H100_table2.dat")
        tbl2 = Table.read(tbl2_file, format='cds')
        # Parse for matching
        names = dla_survey._data['Name']
        qsonames = []
        zabs = []
        for name in names:
            prs = name.split('_')
            qsonames.append(prs[0])
            try:
                zabs.append(float(prs[-1][1:]))
            except ValueError:
                pdb.set_trace()
        qsonames = np.array(qsonames)
        zabs = np.array(zabs)
        # Match
        for ii, iqso, izabs in zip(range(len(tbl2)), tbl2['QSO'],
                                   tbl2['zabs']):
            mt = np.where((qsonames == iqso)
                          & (np.abs(izabs - zabs) < 1e-3))[0]
            if len(mt) == 0:
                pdb.set_trace()
            elif len(mt) != 1:
                pdb.set_trace()
            # Metallicity
            dla_survey._abs_sys[mt[0]].ZH = tbl2['[M/H]'][ii]
            dla_survey._abs_sys[mt[0]].sig_ZH = tbl2['e_[M/H]'][ii]
            if tbl2['M'][ii] in ['S', 'Si', 'O']:
                dla_survey._abs_sys[mt[0]].flag_ZH = 1  # Alpha
            elif tbl2['M'][ii] in ['Zn']:
                dla_survey._abs_sys[mt[0]].flag_ZH = 2  # Zn
            elif tbl2['M'][ii] in ['Fe']:
                dla_survey._abs_sys[mt[0]].flag_ZH = 4  # Fe
            else:
                raise ValueError("Bad metal")
            dla_survey._abs_sys[mt[0]].elm_Z = tbl2['M'][ii]
            # Kin
            dla_survey._abs_sys[mt[0]].kin['dv'] = tbl2['dv'][ii]
            dla_survey._abs_sys[mt[0]].kin['trans'] = tbl2['trans'][ii]
            dla_survey._abs_sys[mt[0]].selection = tbl2['Select'][ii]

        spath = pyigm_path + "/data/DLA/H100/Spectra/"
        for dla in dla_survey._abs_sys:
            dla.spec_path = spath

        # Spectra?
        if grab_spectra:
            warnings.warn(
                "All of these spectra are in igmspec at https://github.com/specdb/specdb"
            )
            print("Grab them there!")

        print("All done!!")
        return dla_survey
Exemple #7
0
    def load_H100(cls, grab_spectra=False, load_sys=True, isys_path=None):  #skip_trans=True):
        """ Sample of unbiased HIRES DLAs compiled and analyzed by Neeleman+13

        Neeleman, M. et al. 2013, ApJ, 769, 54

        Parameters
        ----------
        grab_spectra : bool, optional
          Grab 1D spectra?  (141Mb)
        load_sys : bool, optional
          Load systems? (takes ~60s for 100 systems)
        skip_trans : bool, optional
          Skip loading transitions (takes ~60s)?
        isys_path : str, optional
          Read system files from this path

        Return
        ------
        dla_survey
        """
        # Pull from Internet (as necessary)
        summ_fil = pyigm_path+"/data/DLA/H100/H100_DLA.fits"
        print('H100: Loading summary file {:s}'.format(summ_fil))

        # Ions
        ions_fil = pyigm_path+"/data/DLA/H100/H100_DLA_ions.json"
        print('H100: Loading ions file {:s}'.format(ions_fil))

        # Transitions
        trans_fil = pyigm_path+"/data/DLA/H100/H100_DLA_clms.tar.gz"

        # System files
        sys_files = pyigm_path+"/data/DLA/H100/H100_DLA_sys.tar.gz"

        if load_sys:  # This approach takes ~120s
            print('H100: Loading systems.  This takes ~120s')
            if isys_path is not None:
                dla_survey = pyisu.load_sys_files(isys_path, 'DLA', sys_path=True)
            else:
                dla_survey = pyisu.load_sys_files(sys_files, 'DLA')
            dla_survey.fill_ions(use_components=True)
        else:
            # Read
            dla_survey = cls.from_sfits(summ_fil)
            # Load ions
            dla_survey.fill_ions(jfile=ions_fil)

        dla_survey.ref = 'Neeleman+13'

        """
        # Load transitions
        names = list(dla_survey.name)
        if not skip_trans:
            print('H100: Loading transitions file {:s}'.format(trans_fil))
            tar = tarfile.open(trans_fil)
            for member in tar.getmembers():
                if '.' not in member.name:
                    print('Skipping a likely folder: {:s}'.format(member.name))
                    continue
                # Extract
                f = tar.extractfile(member)
                # Need to fix for 3.4
                tdict = json.load(f)
                # Find system
                i0 = member.name.rfind('/')
                i1 = member.name.rfind('_clm')
                try:
                    idx = names.index(member.name[i0+1:i1])
                except ValueError:
                    pdb.set_trace()
                # Fill up
                dla_survey._abs_sys[idx].load_components(tdict)
        """


        spath = pyigm_path+"/data/DLA/H100/Spectra/"
        for dla in dla_survey._abs_sys:
            dla.spec_path = spath

        # Spectra?
        if grab_spectra:
            pdb.set_trace()  # USE IGMSPEC!!
            specfils = glob.glob(spath+'H100_J*.fits')
            if len(specfils) < 100:
                import tarfile
                print('H100: Downloading a 141Mb file.  Be patient..')
                url = 'https://dl.dropboxusercontent.com/u/6285549/DLA/H100/H100_DLA_spectra.tar.gz'
                spectra_fil = pyigm_path+'/data/DLA/H100/H100_spectra.tar.gz'
                f = urllib2.urlopen(url)
                with open(spectra_fil, "wb") as code:
                    code.write(f.read())
                # Unpack
                print('H100: Unpacking..')
                outdir = pyigm_path+"/data/DLA/H100"
                t = tarfile.open(spectra_fil, 'r:gz')
                t.extractall(outdir)
                # Remove
                print('H100: Removing tar file')
                os.remove(spectra_fil)
                # Done
                print('H100: All done')
            else:
                print('H100: Using files in {:s}'.format(spath))

        return dla_survey
Exemple #8
0
    def load_H100(cls, grab_spectra=False, load_sys=True, isys_path=None):  #skip_trans=True):
        """ Sample of unbiased HIRES DLAs compiled and analyzed by Neeleman+13

        Neeleman, M. et al. 2013, ApJ, 769, 54

        Parameters
        ----------
        grab_spectra : bool, optional
          Grab 1D spectra?  (141Mb)
        load_sys : bool, optional
          Load systems? (takes ~60s for 100 systems)
        skip_trans : bool, optional
          Skip loading transitions (takes ~60s)?
        isys_path : str, optional
          Read system files from this path

        Return
        ------
        dla_survey
        """
        # Pull from Internet (as necessary)
        summ_fil = resource_filename('pyigm', "/data/DLA/H100/H100_DLA.fits")
        print('H100: Loading summary file {:s}'.format(summ_fil))

        # Ions
        ions_fil = resource_filename('pyigm', "/data/DLA/H100/H100_DLA_ions.json")
        print('H100: Loading ions file {:s}'.format(ions_fil))

        # Transitions
        trans_fil = resource_filename('pyigm', "/data/DLA/H100/H100_DLA_clms.tar.gz")

        # System files
        sys_files = resource_filename('pyigm', "/data/DLA/H100/H100_DLA_sys.tar.gz")

        if load_sys:  # This approach takes ~120s
            print('H100: Loading systems.  This takes ~120s')
            if isys_path is not None:
                dla_survey = pyisu.load_sys_files(isys_path, 'DLA', sys_path=True, use_coord=True)
            else:
                dla_survey = pyisu.load_sys_files(sys_files, 'DLA', use_coord=True)
            dla_survey.fill_ions(use_components=True)
        else:
            # Read
            dla_survey = cls.from_sfits(summ_fil)
            # Load ions
            dla_survey.fill_ions(jfile=ions_fil)

        # Metallicities
        tbl2_file = resource_filename('pyigm', "/data/DLA/H100/H100_table2.dat")
        tbl2 = Table.read(tbl2_file, format='cds')
        names = dla_survey.name
        qsonames = []
        zabs = []
        for name in names:
            prs = name.split('_')
            qsonames.append(prs[0])
            zabs.append(float(prs[1][1:]))
        qsonames = np.array(qsonames)
        zabs = np.array(zabs)
        for ii, iqso, izabs in zip(range(len(tbl2)), tbl2['QSO'], tbl2['zabs']):
            mt = np.where((qsonames == iqso) & (np.abs(izabs-zabs) < 1e-3))[0]
            if len(mt) == 0:
                pdb.set_trace()
            elif len(mt) != 1:
                pdb.set_trace()
            # Metallicity
            dla_survey._abs_sys[mt[0]].ZH = tbl2['[M/H]'][ii]
            dla_survey._abs_sys[mt[0]].sig_ZH = tbl2['e_[M/H]'][ii]
            if tbl2['M'][ii] in ['S','Si','O']:
                dla_survey._abs_sys[mt[0]].flag_ZH = 1  # Alpha
            elif tbl2['M'][ii] in ['Zn']:
                dla_survey._abs_sys[mt[0]].flag_ZH = 2  # Zn
            elif tbl2['M'][ii] in ['Fe']:
                dla_survey._abs_sys[mt[0]].flag_ZH = 4  # Fe
            else:
                raise ValueError("Bad metal")
            dla_survey._abs_sys[mt[0]].elm_Z = tbl2['M'][ii]
            # Kin
            dla_survey._abs_sys[mt[0]].kin['dv'] = tbl2['dv'][ii]
            dla_survey._abs_sys[mt[0]].kin['trans'] = tbl2['trans'][ii]
            dla_survey._abs_sys[mt[0]].selection = tbl2['Select'][ii]

        dla_survey.ref = 'Neeleman+13'

        spath = pyigm_path+"/data/DLA/H100/Spectra/"
        for dla in dla_survey._abs_sys:
            dla.spec_path = spath

        # Spectra?
        if grab_spectra:
            warnings.warn("All of these spectra are in igmspec at https://github.com/specdb/specdb")
            specfils = glob.glob(spath+'H100_J*.fits')
            if len(specfils) < 100:
                import tarfile
                print('H100: Downloading a 141Mb file.  Be patient..')
                url = 'https://dl.dropboxusercontent.com/u/6285549/DLA/H100/H100_DLA_spectra.tar.gz'
                spectra_fil = pyigm_path+'/data/DLA/H100/H100_spectra.tar.gz'
                f = urlopen(url)
                with open(spectra_fil, "wb") as code:
                    code.write(f.read())
                # Unpack
                print('H100: Unpacking..')
                outdir = pyigm_path+"/data/DLA/H100"
                t = tarfile.open(spectra_fil, 'r:gz')
                t.extractall(outdir)
                # Remove
                print('H100: Removing tar file')
                os.remove(spectra_fil)
                # Done
                print('H100: All done')
            else:
                print('H100: Using files in {:s}'.format(spath))

        return dla_survey