本文整理汇总了Python中km3pipe.dataclasses.Table.append_columns方法的典型用法代码示例。如果您正苦于以下问题:Python Table.append_columns方法的具体用法?Python Table.append_columns怎么用?Python Table.append_columns使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类km3pipe.dataclasses.Table
的用法示例。
在下文中一共展示了Table.append_columns方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_append_columns
# 需要导入模块: from km3pipe.dataclasses import Table [as 别名]
# 或者: from km3pipe.dataclasses.Table import append_columns [as 别名]
def test_append_columns(self):
tab = Table(self.arr)
print(tab)
with pytest.raises(ValueError):
tab = tab.append_columns('new', [1, 2, 3, 4])
tab = tab.append_columns('new', [1, 2, 3])
print(tab)
assert tab.new[0] == 1
assert tab.new[-1] == 3
tab = tab.append_columns('bar', 0)
print(tab)
assert tab.bar[0] == 0
assert tab.bar[-1] == 0
tab = tab.append_columns('lala', [1])
print(tab)
assert tab.lala[0] == 1
assert tab.lala[-1] == 1
with pytest.raises(ValueError):
tab = tab.append_columns(['m', 'n'], [1, 2])
with pytest.raises(ValueError):
tab = tab.append_columns(['m', 'n'], [[1], [2]])
tab = tab.append_columns(['m', 'n'], [[1, 1, 2], [2, 4, 5]])
print(tab)
assert tab.m[0] == 1
assert tab.m[-1] == 2
assert tab.n[0] == 2
assert tab.n[-1] == 5
示例2: extract_event
# 需要导入模块: from km3pipe.dataclasses import Table [as 别名]
# 或者: from km3pipe.dataclasses.Table import append_columns [as 别名]
def extract_event(self):
blob = Blob()
r = self.event_reader
r.retrieve_next_event() # do it at the beginning!
n = r.n_fits
if n > self.buf_size:
self._resize_buffers(int(n * 3 / 2))
r.get_fits(
self._pos_xs,
self._pos_ys,
self._pos_zs,
self._dir_xs,
self._dir_ys,
self._dir_zs,
self._ndfs,
self._times,
self._qualities,
self._energies,
)
fit_collection = Table({
'pos_x': self._pos_xs[:n],
'pos_y': self._pos_ys[:n],
'pos_z': self._pos_zs[:n],
'dir_x': self._dir_xs[:n],
'dir_y': self._dir_ys[:n],
'dir_z': self._dir_zs[:n],
'ndf': self._ndfs[:n],
'time': self._times[:n],
'quality': self._qualities[:n],
'energy': self._energies[:n],
},
h5loc='/jfit')
fit_collection = fit_collection.append_columns(['event_id'],
[self.event_index])
# TODO make this into a datastructure
event_info = Table.from_template({
'det_id': 0,
'frame_index': 0,
'livetime_sec': 0,
'MC ID': 0,
'MC time': 0,
'n_events_gen': 0,
'n_files_gen': 0,
'overlays': 0,
'trigger_counter': 0,
'trigger_mask': 0,
'utc_nanoseconds': 0,
'utc_seconds': 0,
'weight_w1': np.nan,
'weight_w2': np.nan,
'weight_w3': np.nan,
'run_id': 0,
'group_id': self.event_index,
}, 'EventInfo')
self.event_index += 1
blob['EventInfo'] = event_info
blob['JFit'] = fit_collection
return blob
示例3: test_append_columns_which_is_too_long
# 需要导入模块: from km3pipe.dataclasses import Table [as 别名]
# 或者: from km3pipe.dataclasses.Table import append_columns [as 别名]
def test_append_columns_which_is_too_long(self):
tab = Table({'a': [1, 2, 3]})
with pytest.raises(ValueError):
tab.append_columns('b', values=[4, 5, 6, 7])
示例4: test_append_columns_with_mismatching_lengths_raises
# 需要导入模块: from km3pipe.dataclasses import Table [as 别名]
# 或者: from km3pipe.dataclasses.Table import append_columns [as 别名]
def test_append_columns_with_mismatching_lengths_raises(self):
tab = Table({'a': [1, 2, 3]})
with pytest.raises(ValueError):
tab.append_columns(colnames=['b', 'c'], values=[[4, 5, 6], [7, 8]])
示例5: test_append_columns_duplicate
# 需要导入模块: from km3pipe.dataclasses import Table [as 别名]
# 或者: from km3pipe.dataclasses.Table import append_columns [as 别名]
def test_append_columns_duplicate(self):
tab = Table({'a': 1})
with pytest.raises(ValueError):
tab = tab.append_columns(['a'], np.array([[2]]))
示例6: test_append_column_which_is_too_short_raises
# 需要导入模块: from km3pipe.dataclasses import Table [as 别名]
# 或者: from km3pipe.dataclasses.Table import append_columns [as 别名]
def test_append_column_which_is_too_short_raises(self):
tab = Table({'a': [1, 2, 3]})
with pytest.raises(ValueError):
tab = tab.append_columns('b', [4, 5])
示例7: test_append_columns_modifies_dtype
# 需要导入模块: from km3pipe.dataclasses import Table [as 别名]
# 或者: from km3pipe.dataclasses.Table import append_columns [as 别名]
def test_append_columns_modifies_dtype(self):
tab = Table({'a': [1, 2]})
tab = tab.append_columns('group_id', [0, 1])
assert 'group_id' in tab.dtype.names
示例8: test_append_columns_with_multiple_values
# 需要导入模块: from km3pipe.dataclasses import Table [as 别名]
# 或者: from km3pipe.dataclasses.Table import append_columns [as 别名]
def test_append_columns_with_multiple_values(self):
tab = Table({'a': [1, 2]})
tab = tab.append_columns('group_id', [0, 1])
assert 0 == tab.group_id[0]
assert 1 == tab.group_id[1]
示例9: test_append_columns_with_single_value
# 需要导入模块: from km3pipe.dataclasses import Table [as 别名]
# 或者: from km3pipe.dataclasses.Table import append_columns [as 别名]
def test_append_columns_with_single_value(self):
tab = Table({'a': 1})
tab = tab.append_columns('group_id', 0)
assert 0 == tab.group_id[0]
示例10: test_append__single_column
# 需要导入模块: from km3pipe.dataclasses import Table [as 别名]
# 或者: from km3pipe.dataclasses.Table import append_columns [as 别名]
def test_append__single_column(self):
tab = Table({'a': 1})
print(tab.dtype)
tab = tab.append_columns(['b'], np.array([[2]]))
print(tab.dtype)
print(tab.b)