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


Python QTable.write方法代码示例

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


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

示例1: test_fits_mixins_qtable_to_table

# 需要导入模块: from astropy.table import QTable [as 别名]
# 或者: from astropy.table.QTable import write [as 别名]
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,代码行数:37,代码来源:test_connect.py

示例2: generic_export

# 需要导入模块: from astropy.table import QTable [as 别名]
# 或者: from astropy.table.QTable import write [as 别名]
        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,代码行数:27,代码来源:workspace.py

示例3: test_ecsv_mixins_qtable_to_table

# 需要导入模块: from astropy.table import QTable [as 别名]
# 或者: from astropy.table.QTable import write [as 别名]
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,代码行数:30,代码来源:test_ecsv.py

示例4: test_io_ascii_write

# 需要导入模块: from astropy.table import QTable [as 别名]
# 或者: from astropy.table.QTable import write [as 别名]
def test_io_ascii_write():
    """
    Test that table with mixin column can be written by io.ascii for
    every pure Python writer.  No validation of the output is done,
    this just confirms no exceptions.
    """
    from astropy.io.ascii.connect import _get_connectors_table
    t = QTable(MIXIN_COLS)
    for fmt in _get_connectors_table():
        if fmt['Format'] == 'ascii.ecsv' and not HAS_YAML:
            continue
        if fmt['Write'] and '.fast_' not in fmt['Format']:
            out = StringIO()
            t.write(out, format=fmt['Format'])
开发者ID:Cadair,项目名称:astropy,代码行数:16,代码来源:test_mixin.py

示例5: write_to_ascii

# 需要导入模块: from astropy.table import QTable [as 别名]
# 或者: from astropy.table.QTable import write [as 别名]
    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,代码行数:16,代码来源:xspectrum1d.py

示例6: test_votable_quantity_write

# 需要导入模块: from astropy.table import QTable [as 别名]
# 或者: from astropy.table.QTable import write [as 别名]
def test_votable_quantity_write(tmpdir):
    """
    Test that table with Quantity mixin column can be round-tripped by
    io.votable.  Note that FITS and HDF5 mixin support are tested (much more
    thoroughly) in their respective subpackage tests
    (io/fits/tests/test_connect.py and io/misc/tests/test_hdf5.py).
    """
    t = QTable()
    t['a'] = u.Quantity([1, 2, 4], unit='Angstrom')

    filename = str(tmpdir.join('table-tmp'))
    t.write(filename, format='votable', overwrite=True)
    qt = QTable.read(filename, format='votable')
    assert isinstance(qt['a'], u.Quantity)
    assert qt['a'].unit == 'Angstrom'
开发者ID:Cadair,项目名称:astropy,代码行数:17,代码来源:test_mixin.py

示例7: test_votable_mixin_write_fail

# 需要导入模块: from astropy.table import QTable [as 别名]
# 或者: from astropy.table.QTable import write [as 别名]
def test_votable_mixin_write_fail(mixin_cols):
    """
    Test that table with mixin columns (excluding Quantity) cannot be written by
    io.votable.
    """
    t = QTable(mixin_cols)
    # Only do this test if there are unsupported column types (i.e. anything besides
    # BaseColumn and Quantity class instances).
    unsupported_cols = t.columns.not_isinstance((BaseColumn, u.Quantity))

    if not unsupported_cols:
        pytest.skip("no unsupported column types")

    out = StringIO()
    with pytest.raises(ValueError) as err:
        t.write(out, format='votable')
    assert 'cannot write table with mixin column(s)' in str(err.value)
开发者ID:Cadair,项目名称:astropy,代码行数:19,代码来源:test_mixin.py

示例8: write_to_ascii

# 需要导入模块: from astropy.table import QTable [as 别名]
# 或者: from astropy.table.QTable import write [as 别名]
    def write_to_ascii(self, outfil, format='ascii.ecsv'):
        ''' Write spectrum to an ASCII file

        Parameters
        ----------
        outfil: str
          Name of the FITS file

        Returns:
        --------
        Outputs an ASCII file
        '''
        # Convert to astropy Table
        table = QTable([self.dispersion, self.flux, self.sig],
            names=('WAVE','FLUX','ERROR'))

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

示例9: test_ecsv_mixins_ascii_read_class

# 需要导入模块: from astropy.table import QTable [as 别名]
# 或者: from astropy.table.QTable import write [as 别名]
def test_ecsv_mixins_ascii_read_class():
    """Ensure that ascii.read(ecsv_file) returns the correct class
    (QTable if any Quantity subclasses, Table otherwise).
    """
    # Make a table with every mixin type except Quantities
    t = QTable({name: col for name, col in mixin_cols.items()
                if not isinstance(col.info, QuantityInfo)})
    out = StringIO()
    t.write(out, format="ascii.ecsv")
    t2 = ascii.read(out.getvalue(), format='ecsv')
    assert type(t2) is Table

    # Add a single quantity column
    t['lon'] = mixin_cols['lon']

    out = StringIO()
    t.write(out, format="ascii.ecsv")
    t2 = ascii.read(out.getvalue(), format='ecsv')
    assert type(t2) is QTable
开发者ID:MaxNoe,项目名称:astropy,代码行数:21,代码来源:test_ecsv.py

示例10: write_to_ascii

# 需要导入模块: from astropy.table import QTable [as 别名]
# 或者: from astropy.table.QTable import write [as 别名]
    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],
                       names=('WAVE', 'FLUX'))
        if self.sig_is_set:
            sigclm = Column(self.sig, name='ERROR')
            table.add_column(sigclm)
        if self.co_is_set:
            coclm = Column(self.co, name='CO')
            table.add_column(coclm)

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

示例11: test_write_with_mixins

# 需要导入模块: from astropy.table import QTable [as 别名]
# 或者: from astropy.table.QTable import write [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=' ')
    exp_t = ascii.read(exp)
    assert qt2.colnames == exp_t.colnames
    assert np.all(qt2 == exp_t)
开发者ID:mcara,项目名称:astropy,代码行数:24,代码来源:test_pandas.py

示例12: test_write_with_mixins

# 需要导入模块: from astropy.table import QTable [as 别名]
# 或者: from astropy.table.QTable import write [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:Cadair,项目名称:astropy,代码行数:26,代码来源:test_pandas.py


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