当前位置: 首页>>代码示例>>Python>>正文


Python table.QTable类代码示例

本文整理汇总了Python中astropy.table.QTable的典型用法代码示例。如果您正苦于以下问题:Python QTable类的具体用法?Python QTable怎么用?Python QTable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了QTable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: load_HST_WFC3

    def load_HST_WFC3(cls):
        """ Load the LLS survey using HST/WFC3

        by O'Meara et al. 2013, ApJ, 765, 137

        Parameters
        ----------

        Returns
        -------
        lls_survey : IGMSurvey
        """
        # LLS File
        lls_fil = pyigm_path+'/data/LLS/HST/lls_wfc3_stat_LLS.fits.gz'
        lls = QTable.read(lls_fil)

        # Rename some columns?
        lls.rename_column('QSO_RA', 'RA')
        lls.rename_column('QSO_DEC', 'DEC')

        # Read
        lls_survey = cls.from_sfits(lls)
        lls_survey.ref = 'HST-WFC3'

        # QSOs file
        qsos_fil = pyigm_path+'/data/LLS/HST/lls_wfc3_qsos_sn1020.fits.gz'
        qsos = QTable.read(qsos_fil)
        lls_survey.sightlines = qsos

        # Return
        print('HST-WFC3: Loaded')
        return lls_survey
开发者ID:mneeleman,项目名称:pyigm,代码行数:32,代码来源:llssurvey.py

示例2: test_ecsv_mixins_qtable_to_table

def test_ecsv_mixins_qtable_to_table():
    """Test writing as QTable and reading as Table.  Ensure correct classes
    come out.
    """
    names = sorted(mixin_cols)

    t = QTable([mixin_cols[name] for name in names], names=names)
    out = StringIO()
    t.write(out, format="ascii.ecsv")
    t2 = Table.read(out.getvalue(), format='ascii.ecsv')

    assert t.colnames == t2.colnames

    for name, col in t.columns.items():
        col2 = t2[name]
        attrs = compare_attrs[name]
        compare_class = True

        if isinstance(col.info, QuantityInfo):
            # Downgrade Quantity to Column + unit
            assert type(col2) is Column
            # Class-specific attributes like `value` or `wrap_angle` are lost.
            attrs = ['unit']
            compare_class = False
            # Compare data values here (assert_objects_equal doesn't know how in this case)
            assert np.allclose(col.value, col2, rtol=1e-10)

        assert_objects_equal(col, col2, attrs, compare_class)
开发者ID:MaxNoe,项目名称:astropy,代码行数:28,代码来源:test_ecsv.py

示例3: test_possible_string_format_functions

def test_possible_string_format_functions():
    """
    The QuantityInfo info class for Quantity implements a
    possible_string_format_functions() method that overrides the
    standard pprint._possible_string_format_functions() function.
    Test this.
    """
    t = QTable([[1, 2] * u.m])
    t['col0'].info.format = '%.3f'
    assert t.pformat() == [' col0',
                           '  m  ',
                           '-----',
                           '1.000',
                           '2.000']

    t['col0'].info.format = 'hi {:.3f}'
    assert t.pformat() == ['  col0  ',
                           '   m    ',
                           '--------',
                           'hi 1.000',
                           'hi 2.000']

    t['col0'].info.format = '.4f'
    assert t.pformat() == [' col0 ',
                           '  m   ',
                           '------',
                           '1.0000',
                           '2.0000']
开发者ID:Cadair,项目名称:astropy,代码行数:28,代码来源:test_mixin.py

示例4: test_fits_mixins_qtable_to_table

def test_fits_mixins_qtable_to_table(tmpdir):
    """Test writing as QTable and reading as Table.  Ensure correct classes
    come out.
    """
    filename = str(tmpdir.join('test_simple.fits'))

    names = sorted(mixin_cols)

    t = QTable([mixin_cols[name] for name in names], names=names)
    t.write(filename, format='fits')
    t2 = Table.read(filename, format='fits', astropy_native=True)

    assert t.colnames == t2.colnames

    for name, col in t.columns.items():
        col2 = t2[name]

        # Special-case Time, which does not yet support round-tripping
        # the format.
        if isinstance(col2, Time):
            col2.format = col.format

        attrs = compare_attrs[name]
        compare_class = True

        if isinstance(col.info, QuantityInfo):
            # Downgrade Quantity to Column + unit
            assert type(col2) is Column
            # Class-specific attributes like `value` or `wrap_angle` are lost.
            attrs = ['unit']
            compare_class = False
            # Compare data values here (assert_objects_equal doesn't know how in this case)
            assert np.all(col.value == col2)

        assert_objects_equal(col, col2, attrs, compare_class)
开发者ID:astrofrog,项目名称:astropy,代码行数:35,代码来源:test_connect.py

示例5: generic_export

        def generic_export(spectrum, path):
            """
            Creates a temporary export format for use in writing out data.
            """
            from astropy.table import QTable
            import astropy.units as u

            data = {
                'spectral_axis': spectrum.spectral_axis,
                'flux': spectrum.flux,
                'mask': spectrum.mask if spectrum.mask is not None
                        else u.Quantity(np.ones(spectrum.spectral_axis.shape))
            }

            if spectrum.uncertainty is not None:
                data['uncertainty'] = spectrum.uncertainty.array * spectrum.uncertainty.unit

            meta = {}

            if spectrum.meta is not None and 'header' in spectrum.meta:
                meta.update({'header': {k: v for k, v in
                                        spectrum.meta['header'].items()}})

            tab = QTable(data, meta=meta)
            tab.write(path, format='ascii.ecsv')
开发者ID:nmearl,项目名称:specviz,代码行数:25,代码来源:workspace.py

示例6: test_insert_row_bad_unit

def test_insert_row_bad_unit():
    """
    Insert a row into a QTable with the wrong unit
    """
    t = QTable([[1] * u.m])
    with pytest.raises(ValueError) as exc:
        t.insert_row(0, (2 * u.m / u.s,))
    assert "'m / s' (speed) and 'm' (length) are not convertible" in str(exc.value)
开发者ID:Cadair,项目名称:astropy,代码行数:8,代码来源:test_mixin.py

示例7: test_auto_format_func

def test_auto_format_func():
    """Test for #5802 (fix for #5800 where format_func key is not unique)"""
    t = Table([[1, 2] * u.m])
    t['col0'].format = '%f'
    t.pformat()  # Force caching of format function

    qt = QTable(t)
    qt.pformat()  # Generates exception prior to #5802
开发者ID:MaxNoe,项目名称:astropy,代码行数:8,代码来源:test_pprint.py

示例8: load_mage_z3

    def load_mage_z3(cls, sample='all'):
        """ Load the LLS table from the z~3 MagE survey

        (Fumagalli et al. 2013, ApJ, 775, 78)

        Parameters
        ----------
        sample : str
          Survey sample
            * all -- All
            * non-color -- Restricts to quasars that were *not* color-selected
            * color -- Restricts to quasars that were color-selected

        Returns
        -------
        lls_survey : IGMSurvey
          Includes all quasars observed in the survey
          And all the LLS

        """
        # LLS File
        survey_fil = pyigm_path+'/data/LLS/HD-LLS/fumagalli13_apj775_78_tab1+2.fits'
        tab = Table.read(survey_fil)

        # Rename some columns
        tab.rename_column('RAJ2000', 'RA')
        tab['RA'].unit = u.deg
        tab.rename_column('DEJ2000', 'DEC')
        tab['DEC'].unit = u.deg
        tab.rename_column('zqso', 'Z_QSO')
        tab.rename_column('zlls', 'Z_LLS')
        tab.rename_column('zend', 'Z_START')  # F13 was opposite of POW10
        tab.rename_column('zstart', 'Z_END')  # F13 was opposite of POW10

        # Cut table
        if sample == 'all':
            pass
        elif sample == 'non-color':
            NC = np.array([True if row['n_Name'][0] == 'N' else False for row in tab])
            tab = tab[NC]
        elif sample == 'color':
            Clr = [True if row['n_Name'][0] == 'C' else False for row in tab]
            tab = tab[Clr]

        # Good LLS
        lls = tab['Z_LLS'] >= tab['Z_START']
        lls_tab = QTable(tab[lls])
        nlls = np.sum(lls)
        # Set NHI to 17.8 (tau>=2)
        lls_tab.add_column(Column([17.8]*nlls, name='NHI'))
        lls_tab.add_column(Column([99.9]*nlls, name='SIGNHI'))

        # Generate survey
        lls_survey = cls.from_sfits(lls_tab)
        lls_survey.ref = 'z3_MagE'
        lls_survey.sightlines = tab

        return lls_survey
开发者ID:mneeleman,项目名称:pyigm,代码行数:58,代码来源:llssurvey.py

示例9: load_SDSS_DR7

    def load_SDSS_DR7(cls, sample='stat'):
        """ Load the LLS from the SDSS-DR7 survey (Prochaska+10, ApJ, 718, 391)

        Parameters
        ----------
        sample : str, optional
          LLS sample
            stat : Statistical sample
            all : All LLS
            nonstat : Non-statistical sample


        Returns
        -------
        lls_survey : IGMSurvey

        """
        # LLS File
        lls_fil = pyigm_path+'/data/LLS/SDSS/lls_dr7_stat_LLS.fits.gz'
        print('SDSS-DR7: Loading LLS file {:s}'.format(lls_fil))
        lls = QTable.read(lls_fil)

        # Rename some columns?
        lls.rename_column('QSO_RA', 'RA')
        lls.rename_column('QSO_DEC', 'DEC')

        # Read
        lls_survey = cls.from_sfits(lls)
        lls_survey.ref = 'SDSS-DR7'

        # QSOs file
        qsos_fil = pyigm_path+'/data/LLS/SDSS/lls_dr7_qsos_sn2050.fits.gz'
        print('SDSS-DR7: Loading QSOs file {:s}'.format(qsos_fil))
        qsos = QTable.read(qsos_fil)
        lls_survey.sightlines = qsos

        # All?
        if sample == 'all':
            return lls_survey


        # Stat
        # z_em cut
        zem_min = 3.6
        lowz_q = qsos['ZEM'] < zem_min
        qsos['ZT2'][lowz_q] = 99.99

        # Generate mask
        print('SDSS-DR7: Performing stats (~60s)')
        mask = lls_stat(lls_survey, qsos)
        if sample == 'stat':
            lls_survey.mask = mask
        else:
            lls_survey.mask = ~mask
        # Return
        print('SDSS-DR7: Loaded')
        return lls_survey
开发者ID:mneeleman,项目名称:pyigm,代码行数:57,代码来源:llssurvey.py

示例10: __getitem__

 def __getitem__(self, item):
     if self._is_list_or_tuple_of_str(item):
         if 'time_bin_start' not in item or 'time_bin_size' not in item:
             out = QTable([self[x] for x in item],
                          meta=deepcopy(self.meta),
                          copy_indices=self._copy_indices)
             out._groups = groups.TableGroups(out, indices=self.groups._indices,
                                              keys=self.groups._keys)
             return out
     return super().__getitem__(item)
开发者ID:Cadair,项目名称:astropy,代码行数:10,代码来源:binned.py

示例11: test_quantity_representation

def test_quantity_representation():
    """
    Test that table representation of quantities does not have unit
    """
    t = QTable([[1, 2] * u.m])
    assert t.pformat() == ['col0',
                           ' m  ',
                           '----',
                           ' 1.0',
                           ' 2.0']
开发者ID:Cadair,项目名称:astropy,代码行数:10,代码来源:test_mixin.py

示例12: test_convert_np_array

def test_convert_np_array(mixin_cols):
    """
    Test that converting to numpy array creates an object dtype and that
    each instance in the array has the expected type.
    """
    t = QTable(mixin_cols)
    ta = t.as_array()
    m = mixin_cols['m']
    dtype_kind = m.dtype.kind if hasattr(m, 'dtype') else 'O'
    assert ta['m'].dtype.kind == dtype_kind
开发者ID:Cadair,项目名称:astropy,代码行数:10,代码来源:test_mixin.py

示例13: read_observation_table

def read_observation_table(pathin):
    if pathin[-4:]=='.csv':
        table = ascii.read(pathin)
        qtable = QTable(table)
        for key in qtable.keys():
            if key[-3:]=='[s]' or key[-5:]=='[sec]':
                qtable[key] = qtable[key] * u.s
            if key[-5:]=='[min]':
                qtable[key] = qtable[key] * u.min
            if key[-3:]=='[h]' or key[-4:]=='[hr]' or key[-6:]=='[hour]':
                qtable[key] = qtable[key] * u.s
            if key[-3:]=='[d]' or key[-5:]=='[day]':
                qtable[key] = qtable[key] * u.d
            if key[-5:]=='[mag]':
                qtable[key] = qtable[key] * u.Magnitude
            if key[-4:]=='[Jy]':
                qtable[key] = qtable[key] * u.Jy
            if key[-5:]=='[mJy]':
                qtable[key] = qtable[key] * u.mJy
            if key[-12:]=='[erg/cm^2/s]':
                qtable[key] = qtable[key] * u.erg / u.cm / u.cm / u.s
    elif pathin[-7:]=='.pickle':
        pdata = pickle_utilities.load(pathin)['results']
        time = []
        time_err_lo = []
        time_err_hi = []
        eflux = []
        eflux_err_lo = []
        eflux_err_hi = []
        for period in pdata:
            time.append(np.sqrt(period['time']['min']*period['time']['max']))
            time_err_lo.append(time[-1] - period['time']['min'])
            time_err_hi.append(period['time']['max'] - time[-1])
            
            dll_map = period['dloglike']['dloglike']
            eflux_map = period['dloglike']['eflux']

            args_bestlike = zip(np.where(dll_map==dll_map.min())[0], np.where(dll_map==dll_map.min())[1])[0]

            eflux_shown = eflux_map[2.*dll_map<=2.30]
            eflux_min = min(eflux_shown.flatten())
            eflux_max = max(eflux_shown.flatten())
            eflux.append(eflux_map[args_bestlike[0]][args_bestlike[1]])
            eflux_err_hi.append(eflux_max-eflux[-1]) 
            eflux_err_lo.append(eflux[-1]-eflux_min) 
        qtable = QTable()
        qtable['time'] = Column(time, unit=u.s)
        qtable['time_err_lo'] = Column(time_err_lo, unit=u.s)
        qtable['time_err_hi'] = Column(time_err_hi, unit=u.s)
        qtable['eflux'] = Column(eflux, unit=u.MeV/u.cm/u.cm/u.s)
        qtable['eflux_err_lo'] = Column(eflux_err_lo, unit=u.MeV/u.cm/u.cm/u.s)
        qtable['eflux_err_hi'] = Column(eflux_err_hi, unit=u.MeV/u.cm/u.cm/u.s)

    return qtable
开发者ID:Mitsunari-Takahashi,项目名称:Fermi,代码行数:54,代码来源:ModelGRBAfterglow.py

示例14: get_coord

def get_coord(targ_file, radec=None):
    '''
    radec: int (None)
      None: Read from ASCII file
      1: List of [Name, RA, DEC] with RA/DEC as : separated strings
      2: List of [Name, RA, DEC] with RA/DEC as decimal degrees
    '''

    if not isinstance(targ_file,basestring):
        raise IOError('Bad input to finder.get_coord!')

    from astropy.io import ascii 
    # Import Tables
    if radec == None:
        # Read 
        ra_tab = ascii.read(targ_file) #, names=('Name','RA','DEC','Epoch'))
        # Rename the columns
        ra_tab.rename_column('col1','Name')
        if isinstance(ra_tab['col2'][0],basestring):
            ra_tab.rename_column('col2','RAS')
            ra_tab.rename_column('col3','DECS')
        else:
            ra_tab.rename_column('col2','RA')
            ra_tab.rename_column('col3','DEC')
    elif radec == 1: 
        # Error check
        if len(targ_file) != 3:
            return -1
        # Manipulate
        arr = np.array(targ_file).reshape(1,3)
        # Generate the Table
        ra_tab = QTable( arr, names=('Name','RAS','DECS') )
    elif radec == 2: 
        # Error check
        if len(targ_file) != 3:
            return -1
        # Manipulate
        ras, decs = x_radec.dtos1((targ_file[1], targ_file[2]))
        # Generate the Table
        ra_tab = QTable( [ [targ_file[0]], [ras], [decs] ], names=('Name','RA','DEC') )
    else:
        raise ValueError('get_coord: Bad flag')

    # Add dummy columns for decimal degrees and EPOCH
    nrow = len(ra_tab)
    col_RAD = Column(name='RAD', data=np.zeros(nrow), unit=u.degree)
    col_DECD = Column(name='DECD', data=np.zeros(nrow), unit=u.degree)
    col_EPOCH = Column(name='EPOCH', data=np.zeros(nrow))
    ra_tab.add_columns( [col_RAD, col_DECD, col_EPOCH] )
    # Assume 2000 for now
    ra_tab['EPOCH'] = 2000.
        
    return ra_tab
开发者ID:,项目名称:,代码行数:53,代码来源:

示例15: write_to_ascii

    def write_to_ascii(self, outfil, format='ascii.ecsv'):
        ''' Write to a text file.

        Parameters
        ----------
        outfil: str
          Filename.
        '''
        # Convert to astropy Table
        table = QTable([self.wavelength, self.flux, self.sig],
                       names=('WAVE', 'FLUX', 'ERROR'))

        # Write
        table.write(outfil, format=format)
开发者ID:MSeifert04,项目名称:linetools,代码行数:14,代码来源:xspectrum1d.py


注:本文中的astropy.table.QTable类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。