本文整理汇总了Python中astropy.table.QTable.keys方法的典型用法代码示例。如果您正苦于以下问题:Python QTable.keys方法的具体用法?Python QTable.keys怎么用?Python QTable.keys使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类astropy.table.QTable
的用法示例。
在下文中一共展示了QTable.keys方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: read_observation_table
# 需要导入模块: from astropy.table import QTable [as 别名]
# 或者: from astropy.table.QTable import keys [as 别名]
def read_observation_table(pathin):
if pathin[-4:]=='.csv':
table = ascii.read(pathin)
qtable = QTable(table)
for key in qtable.keys():
if key[-3:]=='[s]' or key[-5:]=='[sec]':
qtable[key] = qtable[key] * u.s
if key[-5:]=='[min]':
qtable[key] = qtable[key] * u.min
if key[-3:]=='[h]' or key[-4:]=='[hr]' or key[-6:]=='[hour]':
qtable[key] = qtable[key] * u.s
if key[-3:]=='[d]' or key[-5:]=='[day]':
qtable[key] = qtable[key] * u.d
if key[-5:]=='[mag]':
qtable[key] = qtable[key] * u.Magnitude
if key[-4:]=='[Jy]':
qtable[key] = qtable[key] * u.Jy
if key[-5:]=='[mJy]':
qtable[key] = qtable[key] * u.mJy
if key[-12:]=='[erg/cm^2/s]':
qtable[key] = qtable[key] * u.erg / u.cm / u.cm / u.s
elif pathin[-7:]=='.pickle':
pdata = pickle_utilities.load(pathin)['results']
time = []
time_err_lo = []
time_err_hi = []
eflux = []
eflux_err_lo = []
eflux_err_hi = []
for period in pdata:
time.append(np.sqrt(period['time']['min']*period['time']['max']))
time_err_lo.append(time[-1] - period['time']['min'])
time_err_hi.append(period['time']['max'] - time[-1])
dll_map = period['dloglike']['dloglike']
eflux_map = period['dloglike']['eflux']
args_bestlike = zip(np.where(dll_map==dll_map.min())[0], np.where(dll_map==dll_map.min())[1])[0]
eflux_shown = eflux_map[2.*dll_map<=2.30]
eflux_min = min(eflux_shown.flatten())
eflux_max = max(eflux_shown.flatten())
eflux.append(eflux_map[args_bestlike[0]][args_bestlike[1]])
eflux_err_hi.append(eflux_max-eflux[-1])
eflux_err_lo.append(eflux[-1]-eflux_min)
qtable = QTable()
qtable['time'] = Column(time, unit=u.s)
qtable['time_err_lo'] = Column(time_err_lo, unit=u.s)
qtable['time_err_hi'] = Column(time_err_hi, unit=u.s)
qtable['eflux'] = Column(eflux, unit=u.MeV/u.cm/u.cm/u.s)
qtable['eflux_err_lo'] = Column(eflux_err_lo, unit=u.MeV/u.cm/u.cm/u.s)
qtable['eflux_err_hi'] = Column(eflux_err_hi, unit=u.MeV/u.cm/u.cm/u.s)
return qtable
示例2: complist_from_table
# 需要导入模块: from astropy.table import QTable [as 别名]
# 或者: from astropy.table.QTable import keys [as 别名]
def complist_from_table(table):
"""
Returns a list of AbsComponents from an input astropy.Table.
Parameters
----------
table : Table
Table with component information (each row must correspond
to a component). Each column is expecting a unit when
appropriate.
Returns
-------
complist : list
List of AbsComponents defined from the input table.
Notes
-----
Mandatory column names: 'RA', 'DEC', 'ion_name', 'z_comp', 'vmin', 'vmax'
These column are required.
Special column names: 'name', 'comment', 'logN', 'sig_logN', 'flag_logN'
These columns will fill internal attributes when corresponding.
In order to fill in the Ntuple attribute all three 'logN', 'sig_logN', 'flag_logN'
must be present. For convenience 'logN' and 'sig_logN' are expected to be floats
corresponding to their values in np.log10(1/cm^2).
Other columns: 'any_column_name'
These will be added as attributes within the AbsComponent.attrib dictionary,
with their respective units if given.
"""
# Convert to QTable to handle units in individual entries more easily
table = QTable(table)
# mandatory and optional columns
min_columns = ['RA', 'DEC', 'ion_name', 'z_comp', 'vmin', 'vmax']
special_columns = ['name', 'comment', 'logN', 'sig_logN', 'flag_logN']
for colname in min_columns:
if colname not in table.keys():
raise IOError('{} is a mandatory column. Please make sure your input table has it.'.format(colname))
#loop over rows
complist = []
for row in table:
# mandatory
coord = SkyCoord(row['RA'].to('deg').value, row['DEC'].to('deg').value, unit='deg') # RA y DEC must both come with units
Zion = name_to_ion(row['ion_name'])
zcomp = row['z_comp']
vlim =[row['vmin'].to('km/s').value, row['vmax'].to('km/s').value] * u.km / u.s # units are expected here too
# special columns
try:
Ntuple = (row['flag_logN'], row['logN'], row['sig_logN']) # no units expected
except KeyError:
Ntuple = None
try:
comment = row['comment']
except KeyError:
comment = ''
try:
name = row['name']
except KeyError:
name = None
# define the component
comp = AbsComponent(coord, Zion, zcomp, vlim, Ntup=Ntuple, comment=comment, name=name)
# other columns will be filled in comp.attrib dict
for colname in table.keys():
if (colname not in special_columns) and (colname not in min_columns):
kms_cols = ['b', 'sig_b']
if colname in kms_cols: # check units for parameters expected in velocity units
try:
val_aux = row[colname].to('km/s').value * u.km / u.s
except u.UnitConversionError:
raise IOError('If `{}` column is present, it must have velocity units.'.format(colname))
comp.attrib[colname] = val_aux
# parameters we do not care about units much
else:
comp.attrib[colname] = row[colname]
# append
complist += [comp]
return complist