本文整理汇总了Python中astropy.table.QTable.add_columns方法的典型用法代码示例。如果您正苦于以下问题:Python QTable.add_columns方法的具体用法?Python QTable.add_columns怎么用?Python QTable.add_columns使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类astropy.table.QTable
的用法示例。
在下文中一共展示了QTable.add_columns方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_coord
# 需要导入模块: from astropy.table import QTable [as 别名]
# 或者: from astropy.table.QTable import add_columns [as 别名]
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
示例2: test_add_column
# 需要导入模块: from astropy.table import QTable [as 别名]
# 或者: from astropy.table.QTable import add_columns [as 别名]
def test_add_column(mixin_cols):
"""
Test that adding a column preserves values and attributes
"""
attrs = ('name', 'unit', 'dtype', 'format', 'description', 'meta')
m = mixin_cols['m']
assert m.info.name is None
# Make sure adding column in various ways doesn't touch
t = QTable([m], names=['a'])
assert m.info.name is None
t['new'] = m
assert m.info.name is None
m.info.name = 'm'
m.info.format = '{0}'
m.info.description = 'd'
m.info.meta = {'a': 1}
t = QTable([m])
# Add columns m2, m3, m4 by two different methods and test expected equality
t['m2'] = m
m.info.name = 'm3'
t.add_columns([m], copy=True)
m.info.name = 'm4'
t.add_columns([m], copy=False)
for name in ('m2', 'm3', 'm4'):
assert_table_name_col_equal(t, name, m)
for attr in attrs:
if attr != 'name':
assert getattr(t['m'].info, attr) == getattr(t[name].info, attr)
# Also check that one can set using a scalar.
s = m[0]
if type(s) is type(m):
# We're not going to worry about testing classes for which scalars
# are a different class than the real array (and thus loose info, etc.)
t['s'] = m[0]
assert_table_name_col_equal(t, 's', m[0])
for attr in attrs:
if attr != 'name':
assert getattr(t['m'].info, attr) == getattr(t['s'].info, attr)
# While we're add it, also check a length-1 table.
t = QTable([m[1:2]], names=['m'])
if type(s) is type(m):
t['s'] = m[0]
assert_table_name_col_equal(t, 's', m[0])
for attr in attrs:
if attr != 'name':
assert getattr(t['m'].info, attr) == getattr(t['s'].info, attr)
示例3: mk_summary
# 需要导入模块: from astropy.table import QTable [as 别名]
# 或者: from astropy.table.QTable import add_columns [as 别名]
def mk_summary(dlas, prefix, outfil, specpath=None, htmlfil=None):
""" Loops through the DLA list and generates a Table
Also pushes the 1D spectra into the folder
Parameters
----------
dlas : DLASurvey
prefix : str
outfil : str
Name of the output FITS summary file
htmlfil : str, optional
Returns
-------
"""
#
if htmlfil is None:
htmlfil = 'tmp.html'
# # Constructing
# QSO, RA/DEC
cqso = Column(dlas.qso, name='QSO')
ra = dlas.coord.ra.degree[0]
dec = dlas.coord.dec.degree[0]
jname = []
for abs_sys in dlas._abs_sys:
jname.append(survey_name(prefix, abs_sys))
cjname = Column(jname, name='Name')
cra = Column(ra, name='RA', unit=u.degree)
cdec = Column(dec, name='DEC', unit=u.degree)
czem = Column(dlas.zem, name='Z_QSO')
# Begin the Table
dla_table = QTable( [cjname, cqso, cra, cdec, czem] )
# LLS properties
czabs = Column(dlas.zabs, name='ZABS')
cNHI = Column(dlas.NHI, name='logNHI')
csigNHI = Column(dlas.sig_NHI, name='sig(logNHI)')
# Add to Table
dla_table.add_columns([czabs, cNHI, csigNHI])
# Spectra files
all_sfiles = []
for jj,ills in enumerate(dlas._abs_sys):
sub_spec = mk_1dspec(ills, name=cjname[jj], outpath=specpath)
# Pad
while len(sub_spec) < 5:
sub_spec.append(str('NULL'))
# Append
all_sfiles.append(sub_spec)
cspec = Column(np.array(all_sfiles), name='SPEC_FILES')
dla_table.add_column( cspec )
# Sort
dla_table.sort('RA')
# Write
print('Writing {:s}'.format(outfil))
xxf.table_to_fits(dla_table,outfil)
print('Writing {:s}'.format(htmlfil))
Table(dla_table).write(htmlfil)
return dla_table