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


Python Table.read方法代码示例

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


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

示例1: __init__

# 需要导入模块: from astropy.table import Table [as 别名]
# 或者: from astropy.table.Table import read [as 别名]
def __init__(self, conf_file='WFC3.IR.G141.V2.5.conf'):
        """Read an aXe-compatible configuration file

        Parameters
        ----------
        conf_file: str
            Filename of the configuration file to read

        """
        if conf_file is not None:
            self.conf = self.read_conf_file(conf_file)
            self.conf_file = conf_file
            self.count_beam_orders()

            # Global XOFF/YOFF offsets
            if 'XOFF' in self.conf.keys():
                self.xoff = np.float(conf['XOFF'])
            else:
                self.xoff = 0.

            if 'YOFF' in self.conf.keys():
                self.yoff = np.float(conf['YOFF'])
            else:
                self.yoff = 0. 
开发者ID:gbrammer,项目名称:grizli,代码行数:26,代码来源:grismconf.py

示例2: load_grism_config

# 需要导入模块: from astropy.table import Table [as 别名]
# 或者: from astropy.table.Table import read [as 别名]
def load_grism_config(conf_file):
    """Load parameters from an aXe configuration file

    Parameters
    ----------
    conf_file : str
        Filename of the configuration file

    Returns
    -------
    conf : `~grizli.grismconf.aXeConf`
        Configuration file object.  Runs `conf.get_beams()` to read the
        sensitivity curves.
    """
    conf = aXeConf(conf_file)
    conf.get_beams()
    return conf 
开发者ID:gbrammer,项目名称:grizli,代码行数:19,代码来源:grismconf.py

示例3: get_table

# 需要导入模块: from astropy.table import Table [as 别名]
# 或者: from astropy.table.Table import read [as 别名]
def get_table(self, ext=None):
        ''' Create an Astropy table for a data extension
        
        Parameters:
            ext (int|str):
                The HDU extension name or number
        
        Returns:
            An Astropy table for the given extension
        '''
        if not ext:
            log.info('No HDU extension specified.  Defaulting to ext=1')
            ext = 1

        # check if extension is an image
        if self.data[ext].is_image:
            log.info('Ext={0} is not a table extension.  Cannot read.'.format(ext))
            return
            
        return Table.read(self._path, ext, format='fits') 
开发者ID:sdss,项目名称:marvin,代码行数:22,代码来源:vacs.py

示例4: check_pointing

# 需要导入模块: from astropy.table import Table [as 别名]
# 或者: from astropy.table.Table import read [as 别名]
def check_pointing(sector, camera, chip, path=None):
    """ Checks to see if a pointing model exists locally already.
    """
    # Tries to create a pointing model directory
    if path == None:
        pm_dir = '.'
    else:
        pm_dir = path

    searches = [
        's{0:04d}-{1}-{2}_tess_v2_pm.txt'.format(sector, camera, chip),
        'pointingModel_{0:04d}_{1}-{2}.txt'.format(sector, camera, chip),
    ]

    # Checks a directory of pointing models, if it exists
    # Returns the pointing model if it's in the pointing model directory
    for search in searches:
        if not os.path.isdir(pm_dir):
            continue
        pm_downloaded = os.listdir(pm_dir)
        pm = [i for i in pm_downloaded if search in i]
        if len(pm) > 0:
            return Table.read(os.path.join(pm_dir, pm[0]), format="ascii.basic")
    warnings.warn("couldn't find pointing model") 
开发者ID:afeinstein20,项目名称:eleanor,代码行数:26,代码来源:ffi.py

示例5: __init__

# 需要导入模块: from astropy.table import Table [as 别名]
# 或者: from astropy.table.Table import read [as 别名]
def __init__(self, **kwargs):

        # get the tabulated information
        data_path = pkg_resources.resource_filename("dust_extinction", "data/")

        a = Table.read(
            data_path + "CT06_pixiedust.dat", format="ascii.commented_header"
        )

        self.obsdata_x = 1.0 / a["wave"].data
        # ext is A(lambda)/A(K)
        # A(K)/A(V) = 0.112 (F19, R(V) = 3.1)
        self.obsdata_axav = 0.112 * a["galcen"].data

        # accuracy of the observed data based on published table
        self.obsdata_tolerance = 1e-6

        super().__init__(**kwargs) 
开发者ID:karllark,项目名称:dust_extinction,代码行数:20,代码来源:averages.py

示例6: test_serialize_ecsv_masked

# 需要导入模块: from astropy.table import Table [as 别名]
# 或者: from astropy.table.Table import read [as 别名]
def test_serialize_ecsv_masked(tmpdir):
    tm = Time([1, 2, 3], format='cxcsec')
    tm[1] = np.ma.masked

    # Serializing in the default way for ECSV fails to round-trip
    # because it writes out a "nan" instead of "".  But for jd1/jd2
    # this works OK.
    tm.info.serialize_method['ecsv'] = 'jd1_jd2'

    fn = str(tmpdir.join('tempfile.ecsv'))
    t = Table([tm])
    t.write(fn)
    t2 = Table.read(fn)

    assert t2['col0'].masked
    assert np.all(t2['col0'].mask == [False, True, False])
    # Serializing floats to ASCII loses some precision so use allclose
    # and 1e-7 seconds tolerance.
    assert np.allclose(t2['col0'].value, t['col0'].value, rtol=0, atol=1e-7) 
开发者ID:holzschu,项目名称:Carnets,代码行数:21,代码来源:test_mask.py

示例7: T1

# 需要导入模块: from astropy.table import Table [as 别名]
# 或者: from astropy.table.Table import read [as 别名]
def T1(request):
    T = Table.read([' a b c d',
                 ' 2 c 7.0 0',
                 ' 2 b 5.0 1',
                 ' 2 b 6.0 2',
                 ' 2 a 4.0 3',
                 ' 0 a 0.0 4',
                 ' 1 b 3.0 5',
                 ' 1 a 2.0 6',
                 ' 1 a 1.0 7',
                 ], format='ascii')
    T.meta.update({'ta': 1})
    T['c'].meta.update({'a': 1})
    T['c'].description = 'column c'
    if request.param:
        T.add_index('a')
    return T 
开发者ID:holzschu,项目名称:Carnets,代码行数:19,代码来源:conftest.py

示例8: test_read_through_table_interface

# 需要导入模块: from astropy.table import Table [as 别名]
# 或者: from astropy.table.Table import read [as 别名]
def test_read_through_table_interface(tmpdir):
    from astropy.table import Table

    with get_pkg_data_fileobj('data/regression.xml', encoding='binary') as fd:
        t = Table.read(fd, format='votable', table_id='main_table')

    assert len(t) == 5

    # Issue 8354
    assert t['float'].format is None

    fn = os.path.join(str(tmpdir), "table_interface.xml")

    # W39: Bit values can not be masked
    with pytest.warns(W39):
        t.write(fn, table_id='FOO', format='votable')

    with open(fn, 'rb') as fd:
        t2 = Table.read(fd, format='votable', table_id='FOO')

    assert len(t2) == 5 
开发者ID:holzschu,项目名称:Carnets,代码行数:23,代码来源:table_test.py

示例9: test_table_io

# 需要导入模块: from astropy.table import Table [as 别名]
# 或者: from astropy.table.Table import read [as 别名]
def test_table_io(tmpdir):

    tmpfile = str(tmpdir.join('table.asdf'))

    table = make_table()

    table.write(tmpfile)

    # Simple sanity check using ASDF directly
    with asdf.open(tmpfile) as af:
        assert 'data' in af.keys()
        assert isinstance(af['data'], Table)
        assert all(af['data'] == table)

    # Now test using the table reader
    new_t = Table.read(tmpfile)
    assert all(new_t == table) 
开发者ID:holzschu,项目名称:Carnets,代码行数:19,代码来源:test_io.py

示例10: test_read_write_format

# 需要导入模块: from astropy.table import Table [as 别名]
# 或者: from astropy.table.Table import read [as 别名]
def test_read_write_format(fmt):
    """
    Test round-trip through pandas write/read for supported formats.

    :param fmt: format name, e.g. csv, html, json
    :return:
    """
    # Skip the reading tests
    if fmt == 'html' and not HAS_HTML_DEPS:
        pytest.skip('Missing lxml or bs4 + html5lib for HTML read/write test')

    pandas_fmt = 'pandas.' + fmt
    # Explicitly provide dtype to avoid casting 'a' to int32.
    # See https://github.com/astropy/astropy/issues/8682
    t = Table([[1, 2, 3], [1.0, 2.5, 5.0], ['a', 'b', 'c']],
              dtype=(np.int64, np.float64, np.str))
    buf = StringIO()
    t.write(buf, format=pandas_fmt)

    buf.seek(0)
    t2 = Table.read(buf, format=pandas_fmt)

    assert t.colnames == t2.colnames
    assert np.all(t == t2) 
开发者ID:holzschu,项目名称:Carnets,代码行数:26,代码来源:test_pandas.py

示例11: test_read_fixed_width_format

# 需要导入模块: from astropy.table import Table [as 别名]
# 或者: from astropy.table.Table import read [as 别名]
def test_read_fixed_width_format():
    """Test reading with pandas read_fwf()

    """
    tbl = """\
    a   b   c
    1  2.0  a
    2  3.0  b"""
    buf = StringIO()
    buf.write(tbl)

    # Explicitly provide converters to avoid casting 'a' to int32.
    # See https://github.com/astropy/astropy/issues/8682
    t = Table.read(tbl, format='ascii', guess=False,
                   converters={'a': [ascii.convert_numpy(np.int64)]})

    buf.seek(0)
    t2 = Table.read(buf, format='pandas.fwf')

    assert t.colnames == t2.colnames
    assert np.all(t == t2) 
开发者ID:holzschu,项目名称:Carnets,代码行数:23,代码来源:test_pandas.py

示例12: test_write_with_mixins

# 需要导入模块: from astropy.table import Table [as 别名]
# 或者: from astropy.table.Table import read [as 别名]
def test_write_with_mixins():
    """Writing a table with mixins just drops them via to_pandas()

    This also tests passing a kwarg to pandas read and write.
    """
    sc = SkyCoord([1, 2], [3, 4], unit='deg')
    q = [5, 6] * u.m
    qt = QTable([[1, 2], q, sc], names=['i', 'q', 'sc'])

    buf = StringIO()
    qt.write(buf, format='pandas.csv', sep=' ')
    exp = ['i q sc.ra sc.dec',
           '1 5.0 1.0 3.0',
           '2 6.0 2.0 4.0']
    assert buf.getvalue().splitlines() == exp

    # Read it back
    buf.seek(0)
    qt2 = Table.read(buf, format='pandas.csv', sep=' ')
    # Explicitly provide converters to avoid casting 'i' to int32.
    # See https://github.com/astropy/astropy/issues/8682
    exp_t = ascii.read(exp, converters={'i': [ascii.convert_numpy(np.int64)]})
    assert qt2.colnames == exp_t.colnames
    assert np.all(qt2 == exp_t) 
开发者ID:holzschu,项目名称:Carnets,代码行数:26,代码来源:test_pandas.py

示例13: test_preserve_all_dtypes

# 需要导入模块: from astropy.table import Table [as 别名]
# 或者: from astropy.table.Table import read [as 别名]
def test_preserve_all_dtypes(tmpdir):

    test_file = str(tmpdir.join('test.hdf5'))

    t1 = Table()

    for dtype in ALL_DTYPES:
        values = _default_values(dtype)
        t1.add_column(Column(name=str(dtype), data=np.array(values, dtype=dtype)))

    t1.write(test_file, path='the_table')

    t2 = Table.read(test_file, path='the_table')

    for dtype in ALL_DTYPES:
        values = _default_values(dtype)
        assert np.all(t2[str(dtype)] == values)
        assert t2[str(dtype)].dtype == dtype 
开发者ID:holzschu,项目名称:Carnets,代码行数:20,代码来源:test_hdf5.py

示例14: test_preserve_meta

# 需要导入模块: from astropy.table import Table [as 别名]
# 或者: from astropy.table.Table import read [as 别名]
def test_preserve_meta(tmpdir):

    test_file = str(tmpdir.join('test.hdf5'))

    t1 = Table()
    t1.add_column(Column(name='a', data=[1, 2, 3]))

    t1.meta['a'] = 1
    t1.meta['b'] = 'hello'
    t1.meta['c'] = 3.14159
    t1.meta['d'] = True
    t1.meta['e'] = np.array([1, 2, 3])

    t1.write(test_file, path='the_table')

    t2 = Table.read(test_file, path='the_table')

    for key in t1.meta:
        assert np.all(t1.meta[key] == t2.meta[key]) 
开发者ID:holzschu,项目名称:Carnets,代码行数:21,代码来源:test_hdf5.py

示例15: test_preserve_serialized

# 需要导入模块: from astropy.table import Table [as 别名]
# 或者: from astropy.table.Table import read [as 别名]
def test_preserve_serialized(tmpdir):
    test_file = str(tmpdir.join('test.hdf5'))

    t1 = Table()
    t1['a'] = Column(data=[1, 2, 3], unit="s")
    t1['a'].meta['a0'] = "A0"
    t1['a'].meta['a1'] = {"a1": [0, 1]}
    t1['a'].format = '7.3f'
    t1['a'].description = 'A column'
    t1.meta['b'] = 1
    t1.meta['c'] = {"c0": [0, 1]}

    t1.write(test_file, path='the_table', serialize_meta=True, overwrite=True)

    t2 = Table.read(test_file, path='the_table')

    assert t1['a'].unit == t2['a'].unit
    assert t1['a'].format == t2['a'].format
    assert t1['a'].description == t2['a'].description
    assert t1['a'].meta == t2['a'].meta
    assert t1.meta == t2.meta 
开发者ID:holzschu,项目名称:Carnets,代码行数:23,代码来源:test_hdf5.py


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