光盘#
- class astropy.io.ascii.Cds(readme=None)[源代码]#
基类:
BaseReader
CDS格式表。
请参阅:https://vizier.unistra.fr/doc/catstd.htx
例子::
Table: Table name here = ============================================================================== Catalog reference paper Bibliography info here ================================================================================ ADC_Keywords: Keyword ; Another keyword ; etc Description: Catalog description here. ================================================================================ Byte-by-byte Description of file: datafile3.txt -------------------------------------------------------------------------------- Bytes Format Units Label Explanations -------------------------------------------------------------------------------- 1- 3 I3 --- Index Running identification number 5- 6 I2 h RAh Hour of Right Ascension (J2000) 8- 9 I2 min RAm Minute of Right Ascension (J2000) 11- 15 F5.2 s RAs Second of Right Ascension (J2000) -------------------------------------------------------------------------------- Note (1): A CDS file can contain sections with various metadata. Notes can be multiple lines. Note (2): Another note. -------------------------------------------------------------------------------- 1 03 28 39.09 2 04 18 24.11
关于解析CDS格式
CDS格式由表说明和表数据组成。这些文件可以作为
ReadMe
文件加上数据文件,或合并到单个文件中。描述中的不同部分用虚线或等号(“----”或“====”)分隔开。指定列信息的表前面必须有一行以“文件的逐字节描述:”开头。如果表说明与数据值组合在一起,则数据必须位于最后一个节中,并且必须在其前面加上一个节分隔符行(仅限短划线或等号)。
基本用法
使用
ascii.read()
功能正常,可选择readme
指示CDS自述文件的参数。如果未提供,则假定头信息位于给定表的顶部。示例:>>> from astropy.io import ascii >>> table = ascii.read("data/cds.dat") >>> table = ascii.read("data/vizier/table1.dat", readme="data/vizier/ReadMe") >>> table = ascii.read("data/cds/multi/lhs2065.dat", readme="data/cds/multi/ReadMe") >>> table = ascii.read("data/cds/glob/lmxbrefs.dat", readme="data/cds/glob/ReadMe")
表名和CDS自述文件可以作为url输入。这可以用于从Internet直接加载表。例如,来自CD的Vizier表:
>>> table = ascii.read("ftp://cdsarc.u-strasbg.fr/pub/cats/VII/253/snrs.dat", ... readme="ftp://cdsarc.u-strasbg.fr/pub/cats/VII/253/ReadMe")
如果头(自述文件)和数据存储在一个文件中,并且头和数据之间有内容(例如Notes),那么解析过程可能会失败。在这种情况下,您可以通过提供
data_start='guess'
在呼叫ascii.read()
功能。您应该根据输入CDS文件验证输出数据表是否符合预期。使用reader对象
什么时候?
Cds
读取器对象是用readme
参数在初始化时传递给它,那么当read
方法使用表文件名执行,指定表的头信息从readme
文件。安InconsistentTableError
如果readme
文件没有给定表的头信息。>>> readme = "data/vizier/ReadMe" >>> r = ascii.get_reader(ascii.Cds, readme=readme) >>> table = r.read("data/vizier/table1.dat") >>> # table5.dat has the same ReadMe file >>> table = r.read("data/vizier/table5.dat")
如果没有
readme
参数,则假定头信息位于给定表的顶部。>>> r = ascii.get_reader(ascii.Cds) >>> table = r.read("data/cds.dat") >>> #The following gives InconsistentTableError, since no >>> #readme file was given and table1.dat does not have a header. >>> table = r.read("data/vizier/table1.dat") Traceback (most recent call last): ... InconsistentTableError: No CDS section delimiter found
Caveats:
本栏提供了单位和说明
unit
和description
属性。此格式定义的其他元数据在输出表中不可用。
方法总结
read
\(表)阅读
table
并以由确定的格式返回结果outputter
属性。write
([table])不可用于CDS类(引发NotImplementedError)。
方法文件