本文整理汇总了Python中astropy.table.QTable.insert_row方法的典型用法代码示例。如果您正苦于以下问题:Python QTable.insert_row方法的具体用法?Python QTable.insert_row怎么用?Python QTable.insert_row使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类astropy.table.QTable
的用法示例。
在下文中一共展示了QTable.insert_row方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_insert_row_bad_unit
# 需要导入模块: from astropy.table import QTable [as 别名]
# 或者: from astropy.table.QTable import insert_row [as 别名]
def test_insert_row_bad_unit():
"""
Insert a row into a QTable with the wrong unit
"""
t = QTable([[1] * u.m])
with pytest.raises(ValueError) as exc:
t.insert_row(0, (2 * u.m / u.s,))
assert "'m / s' (speed) and 'm' (length) are not convertible" in str(exc.value)
示例2: test_insert_row
# 需要导入模块: from astropy.table import QTable [as 别名]
# 或者: from astropy.table.QTable import insert_row [as 别名]
def test_insert_row(mixin_cols):
"""
Test inserting a row, which only works for BaseColumn and Quantity
"""
t = QTable(mixin_cols)
t['m'].info.description = 'd'
if isinstance(t['m'], (u.Quantity, Column, time.Time)):
t.insert_row(1, t[-1])
assert t[1] == t[-1]
assert t['m'].info.description == 'd'
else:
with pytest.raises(ValueError) as exc:
t.insert_row(1, t[-1])
assert "Unable to insert row" in str(exc.value)
示例3: group_table
# 需要导入模块: from astropy.table import QTable [as 别名]
# 或者: from astropy.table.QTable import insert_row [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