本文整理汇总了Python中km3pipe.dataclasses.Table.group_id[:]方法的典型用法代码示例。如果您正苦于以下问题:Python Table.group_id[:]方法的具体用法?Python Table.group_id[:]怎么用?Python Table.group_id[:]使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类km3pipe.dataclasses.Table
的用法示例。
在下文中一共展示了Table.group_id[:]方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_blob
# 需要导入模块: from km3pipe.dataclasses import Table [as 别名]
# 或者: from km3pipe.dataclasses.Table import group_id[:] [as 别名]
#.........这里部分代码省略.........
if 'group_id' in tab.dtype.names:
index_column = 'group_id'
elif 'event_id' in tab.dtype.names:
index_column = 'event_id'
if index_column is not None:
try:
if h5loc not in self._tab_indices:
self._read_tab_indices(h5loc)
tab_idx_start = self._tab_indices[h5loc][0][group_id]
tab_n_items = self._tab_indices[h5loc][1][group_id]
if tab_n_items == 0:
continue
arr = tab[tab_idx_start:tab_idx_start + tab_n_items]
except IndexError:
self.log.debug("No data for h5loc '%s'" % h5loc)
continue
except NotImplementedError:
# 64-bit unsigned integer columns like ``group_id``
# are not yet supported in conditions
self.log.debug(
"get_blob: found uint64 column at '{}'...".
format(h5loc)
)
arr = tab.read()
arr = arr[arr[index_column] == group_id]
except ValueError:
# "there are no columns taking part
# in condition ``group_id == 0``"
self.log.info(
"get_blob: no `%s` column found in '%s'! "
"skipping... " % (index_column, h5loc)
)
continue
else:
if h5loc not in self._singletons:
log.info(
"Caching H5 singleton: {} ({})".format(tabname, h5loc)
)
self._singletons[h5loc] = Table(
tab.read(),
h5loc=h5loc,
split_h5=False,
name=tabname,
h5singleton=True
)
blob[tabname] = self._singletons[h5loc]
continue
self.log.debug("h5loc: '{}'".format(h5loc))
tab = Table(arr, h5loc=h5loc, split_h5=False, name=tabname)
if self.shuffle and self.reset_index:
tab.group_id[:] = index
blob[tabname] = tab
# skipped locs are now column wise datasets (usually hits)
# currently hardcoded, in future using hdf5 attributes
# to get the right constructor
for loc in split_table_locs:
# if some events are missing (group_id not continuous),
# this does not work as intended
# idx, n_items = self.indices[loc][group_id]
idx = self.indices[loc].col('index')[group_id]
n_items = self.indices[loc].col('n_items')[group_id]
end = idx + n_items
node = self.h5file.get_node(loc)
columns = (c for c in node._v_children if c != '_indices')
data = {}
for col in columns:
data[col] = self.h5file.get_node(loc + '/' + col)[idx:end]
tabname = camelise(loc.split('/')[-1])
s_tab = Table(data, h5loc=loc, split_h5=True, name=tabname)
if self.shuffle and self.reset_index:
s_tab.group_id[:] = index
blob[tabname] = s_tab
if self.header is not None:
blob['Header'] = self.header
for ndarr_loc in ndarray_locs:
self.log.info("Reading %s" % ndarr_loc)
try:
idx = self.indices[ndarr_loc]['index'][group_id]
n_items = self.indices[ndarr_loc]['n_items'][group_id]
except IndexError:
continue
end = idx + n_items
ndarr = self.h5file.get_node(ndarr_loc)
ndarr_name = camelise(ndarr_loc.split('/')[-1])
_ndarr = NDArray(
ndarr[idx:end],
h5loc=ndarr_loc,
title=ndarr.title,
group_id=group_id
)
if self.shuffle and self.reset_index:
_ndarr.group_id = index
blob[ndarr_name] = _ndarr
return blob