Tdat#
- class astropy.io.ascii.Tdat[源代码]#
基类:
BaseReader
TDAT格式
请参阅:https://heasarc.gsfc.nasa.gov/docs/software/dbdocs/tdat.html
例子::
<HEADER> # # and // are comments table_name = example_table table_description = "Example table" # # Table Parameters # field[id] = integer [meta.id] (key) // Unique ID field[ra] = float:.4f_degree [pos.eq.ra] (index) // Right Ascension field[name] = char12 [meta.id] // Name # # Virtual Parameters # table_author = Example et al. # # Data Format Specification # line[1] = id name ra <DATA> 1|TargetOne|1.0| 2|TargetTwo|2.0| <END>
在标题中定义的注释和关键字(除了常见的标题部分标题和空白注释)可通过输出表获得
meta
属性::>>> from astropy.io import ascii >>> lines = ascii.tdat.make_example_data() >>> data = ascii.read(lines, format='tdat') >>> print(data.meta['comments']) ['# and // are comments'] >>> for name, keyword in data.meta['keywords'].items(): ... print(name, keyword) table_name example_table table_description Example table table_author Example et al.
写入TDAT格式时,标头将由表中的信息自动填充,并对Table.Meta中给出的信息进行优先级排序:
- comments列表或字符串,(可选)
提供上下文的表格信息。此信息包含在所有其他行之前的标题中,并用#注释掉
- keywordsdict,(可选,推荐)
标题关键字将在文件中显示为“名称=值”行。特别重要的是table_list、table_title和table_doctor_url。
如果没有Table.Meta,则此编写器将尝试根据表和列属性以及HEASARC对TDAT格式的建议自动生成适当的头信息。柱
units
使用CDS格式编写。例子::
>>> from astropy.table import Table >>> import sys >>> t = Table(names=('reference_id', 'RA', 'Name'), ... data=[[1, 2, 3], [1.0, 2.0, 3.0], ['c', 'd', 'e']]) >>> t.meta['table_name'] = "astropy_table" >>> t.write(sys.stdout, format="ascii.tdat") <HEADER> table_name = astropy_table # # Table Parameters # field[reference_id] = int4 field[RA] = float8 field[Name] = char1 # # Data Format Specification # line[1] = reference_id RA Name # <DATA> 1|1.0|c| 2|2.0|d| 3|3.0|e| <END>
通过属性分配和元数据添加的混合,可以分别包含表和列的相关元数据::
>>> from astropy.table import Table >>> from io import StringIO >>> t = Table(names=('reference_id', 'RA', 'Name'), ... data=[[1, 2, 3], [1.0, 2.0, 3.0], ['c', 'd', 'e']]) >>> t.meta["table_name"] = "example_table" >>> t.meta["table_description"] = "An example table for the tdat writer." >>> t.add_index('reference_id') >>> t.columns['reference_id'].meta['comment'] = "For internal reference only" >>> t.add_index('RA') >>> t.columns['RA'].unit = "degree" >>> t.columns['RA'].format = ".4f" >>> t.columns['RA'].meta['ucd'] = "pos.eq.ra" >>> t.columns['Name'].description = "The name of the source (if available)" >>> t.write(sys.stdout, format="ascii.tdat") <HEADER> table_name = example_table table_description = An example table for the tdat writer. # # Table Parameters # field[reference_id] = int4 (key) // // For internal reference only field[RA] = float8:.4f_deg [pos.eq.ra] (index) field[Name] = char1 // The name of the source (if available) # # Data Format Specification # line[1] = reference_id RA Name # <DATA> 1|1.0000|c| 2|2.0000|d| 3|3.0000|e| <END>