本文整理汇总了Python中astropy.table.QTable.add_column方法的典型用法代码示例。如果您正苦于以下问题:Python QTable.add_column方法的具体用法?Python QTable.add_column怎么用?Python QTable.add_column使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类astropy.table.QTable
的用法示例。
在下文中一共展示了QTable.add_column方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load_mage_z3
# 需要导入模块: from astropy.table import QTable [as 别名]
# 或者: from astropy.table.QTable import add_column [as 别名]
def load_mage_z3(cls, sample='all'):
""" Load the LLS table from the z~3 MagE survey
(Fumagalli et al. 2013, ApJ, 775, 78)
Parameters
----------
sample : str
Survey sample
* all -- All
* non-color -- Restricts to quasars that were *not* color-selected
* color -- Restricts to quasars that were color-selected
Returns
-------
lls_survey : IGMSurvey
Includes all quasars observed in the survey
And all the LLS
"""
# LLS File
survey_fil = pyigm_path+'/data/LLS/HD-LLS/fumagalli13_apj775_78_tab1+2.fits'
tab = Table.read(survey_fil)
# Rename some columns
tab.rename_column('RAJ2000', 'RA')
tab['RA'].unit = u.deg
tab.rename_column('DEJ2000', 'DEC')
tab['DEC'].unit = u.deg
tab.rename_column('zqso', 'Z_QSO')
tab.rename_column('zlls', 'Z_LLS')
tab.rename_column('zend', 'Z_START') # F13 was opposite of POW10
tab.rename_column('zstart', 'Z_END') # F13 was opposite of POW10
# Cut table
if sample == 'all':
pass
elif sample == 'non-color':
NC = np.array([True if row['n_Name'][0] == 'N' else False for row in tab])
tab = tab[NC]
elif sample == 'color':
Clr = [True if row['n_Name'][0] == 'C' else False for row in tab]
tab = tab[Clr]
# Good LLS
lls = tab['Z_LLS'] >= tab['Z_START']
lls_tab = QTable(tab[lls])
nlls = np.sum(lls)
# Set NHI to 17.8 (tau>=2)
lls_tab.add_column(Column([17.8]*nlls, name='NHI'))
lls_tab.add_column(Column([99.9]*nlls, name='SIGNHI'))
# Generate survey
lls_survey = cls.from_sfits(lls_tab)
lls_survey.ref = 'z3_MagE'
lls_survey.sightlines = tab
return lls_survey
示例2: build_table
# 需要导入模块: from astropy.table import QTable [as 别名]
# 或者: from astropy.table.QTable import add_column [as 别名]
def build_table(self):
"""Generate an astropy QTable out of the component.
Returns
-------
comp_tbl : QTable
"""
if len(self._abslines) == 0:
return
comp_tbl = QTable()
comp_tbl.add_column(Column([iline.wrest.to(u.AA).value for iline in self._abslines]*u.AA, name='wrest'))
for attrib in ['z', 'flag_N', 'logN', 'sig_logN']:
comp_tbl.add_column(Column([iline.attrib[attrib] for iline in self._abslines], name=attrib))
# Return
return comp_tbl
示例3: write_to_ascii
# 需要导入模块: from astropy.table import QTable [as 别名]
# 或者: from astropy.table.QTable import add_column [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)
示例4: mk_summary
# 需要导入模块: from astropy.table import QTable [as 别名]
# 或者: from astropy.table.QTable import add_column [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
示例5: group_table
# 需要导入模块: from astropy.table import QTable [as 别名]
# 或者: from astropy.table.QTable import add_column [as 别名]
def group_table(self, edges):
"""Compute bin groups table for the map axis, given coarser bin edges.
Parameters
----------
edges : `~astropy.units.Quantity`
Group bin edges.
Returns
-------
groups : `~astropy.table.Table`
Map axis group table.
"""
# TODO: try to simplify this code
if not self.node_type == "edges":
raise ValueError("Only edge based map axis can be grouped")
edges_pix = self.coord_to_pix(edges)
edges_pix = np.clip(edges_pix, -0.5, self.nbin - 0.5)
edges_idx = np.round(edges_pix + 0.5) - 0.5
edges_idx = np.unique(edges_idx)
edges_ref = self.pix_to_coord(edges_idx) * self.unit
groups = QTable()
groups["{}_min".format(self.name)] = edges_ref[:-1]
groups["{}_max".format(self.name)] = edges_ref[1:]
groups["idx_min"] = (edges_idx[:-1] + 0.5).astype(int)
groups["idx_max"] = (edges_idx[1:] - 0.5).astype(int)
if len(groups) == 0:
raise ValueError("No overlap between reference and target edges.")
groups["bin_type"] = "normal "
edge_idx_start, edge_ref_start = edges_idx[0], edges_ref[0]
if edge_idx_start > 0:
underflow = {
"bin_type": "underflow",
"idx_min": 0,
"idx_max": edge_idx_start,
"{}_min".format(self.name): self.pix_to_coord(-0.5) * self.unit,
"{}_max".format(self.name): edge_ref_start,
}
groups.insert_row(0, vals=underflow)
edge_idx_end, edge_ref_end = edges_idx[-1], edges_ref[-1]
if edge_idx_end < (self.nbin - 0.5):
overflow = {
"bin_type": "overflow",
"idx_min": edge_idx_end + 1,
"idx_max": self.nbin - 1,
"{}_min".format(self.name): edge_ref_end,
"{}_max".format(self.name): self.pix_to_coord(self.nbin - 0.5)
* self.unit,
}
groups.add_row(vals=overflow)
group_idx = Column(np.arange(len(groups)))
groups.add_column(group_idx, name="group_idx", index=0)
return groups