本文整理汇总了Python中pypet.trajectory.Trajectory.f_iter_nodes方法的典型用法代码示例。如果您正苦于以下问题:Python Trajectory.f_iter_nodes方法的具体用法?Python Trajectory.f_iter_nodes怎么用?Python Trajectory.f_iter_nodes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pypet.trajectory.Trajectory
的用法示例。
在下文中一共展示了Trajectory.f_iter_nodes方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_loading
# 需要导入模块: from pypet.trajectory import Trajectory [as 别名]
# 或者: from pypet.trajectory.Trajectory import f_iter_nodes [as 别名]
def test_loading(filenames, traj_names):
loading_times = np.zeros(len(traj_names))
loading_times_wd = np.zeros(len(traj_names))
n_groups= np.zeros(len(traj_names), dtype='int')
for idx, traj_name in enumerate(traj_names):
filename = filenames[idx]
traj = Trajectory(name=traj_name, filename=filename, add_time=False)
start = time.time()
traj.f_load(load_parameters=2, load_results=1, load_derived_parameters=1)
elapsed = (time.time() - start)
loading_times[idx]=elapsed
n_groups[idx] = len([x for x in traj.f_iter_nodes(recursive=True)])
del traj
traj = Trajectory(name=traj_name, filename=filename, add_time=False)
start = time.time()
traj.f_load(load_all=2)
elapsed = (time.time() - start)
loading_times_wd[idx]=elapsed
for idx, loading_time in enumerate(loading_times):
loading_time_wd = loading_times_wd[idx]
groups = n_groups[idx]
print('Groups: %d, Loading: %.3fs, with Data: %.3fs' % (groups, loading_time, loading_time_wd))
示例2: test_file_translation
# 需要导入模块: from pypet.trajectory import Trajectory [as 别名]
# 或者: from pypet.trajectory.Trajectory import f_iter_nodes [as 别名]
def test_file_translation(self):
filename = make_temp_dir('to_new_tree.hdf5')
mytraj = Trajectory('SCRATCH', filename=filename)
mytraj.f_add_parameter('Test.Group.Test', 42)
mytraj.f_add_derived_parameter('trajectory.saaaa',33)
mytraj.f_add_derived_parameter('trajectory.intraj.dpar1',33)
mytraj.f_add_derived_parameter('run_00000008.inrun.dpar2',33)
mytraj.f_add_derived_parameter('run_00000001.inrun.dpar3',35)
mytraj.f_add_result('trajectory.intraj.res1',33)
mytraj.f_add_result('run_00000008.inrun.res1',33)
mytraj.f_store()
mytraj.f_migrate(new_name=mytraj.v_name + 'PETER', in_store=True)
mytraj.f_store()
fu=FileUpdater(filename=filename, backup=True)
fu.update_file()
mytraj = Trajectory(name=mytraj.v_name, add_time=False, filename=filename)
mytraj.f_load(load_parameters=2, load_derived_parameters=2, load_results=2)
for node in mytraj.f_iter_nodes():
self.assertTrue(node.v_name != 'trajectory')
if 'run_' in node.v_full_name:
self.assertTrue('.runs.' in node.v_full_name)
remove_data()
示例3: TrajectoryTest
# 需要导入模块: from pypet.trajectory import Trajectory [as 别名]
# 或者: from pypet.trajectory.Trajectory import f_iter_nodes [as 别名]
#.........这里部分代码省略.........
bfs_queue=[traj]
depth_dict={}
while len(bfs_queue)>0:
item = bfs_queue.pop(0)
depth = item.v_depth
if not depth in depth_dict:
depth_dict[depth]=[]
depth_dict[depth].append(item)
if not item.v_is_leaf:
if as_run in item._children:
bfs_queue.append(item._children[as_run])
for child in item._children.values():
if not (child.v_name.startswith(pypetconstants.RUN_NAME) and
child.v_name != pypetconstants.RUN_NAME_DUMMY):
bfs_queue.append(child)
else:
for child in item._children.values():
bfs_queue.append(child)
return depth_dict
def test_iter_bfs(self):
depth_dict = self.get_depth_dict(self.traj)
depth_dict[0] =[]
prev_depth = 0
for node in self.traj.f_iter_nodes(recursive=True):
if prev_depth != node.v_depth:
self.assertEqual(len(depth_dict[prev_depth]),0)
prev_depth = node.v_depth
depth_dict[node.v_depth].remove(node)
depth_dict = self.get_depth_dict(self.traj)
depth_dict[0] =[]
prev_depth = 0
self.traj.v_iter_recursive = True
for node in self.traj:
if prev_depth != node.v_depth:
self.assertEqual(len(depth_dict[prev_depth]),0)
prev_depth = node.v_depth
depth_dict[node.v_depth].remove(node)
#
#
# def test_iter_dfs(self):
#
# prev_node = None
#
# x= [x for x in self.traj.f_iter_nodes(recursive=True, search_strategy='DFS')]
#
# for node in self.traj.f_iter_nodes(recursive=True, search_strategy='DFS'):
示例4: AnnotationsTest
# 需要导入模块: from pypet.trajectory import Trajectory [as 别名]
# 或者: from pypet.trajectory.Trajectory import f_iter_nodes [as 别名]
class AnnotationsTest(unittest.TestCase):
def setUp(self):
self.filename = make_temp_file('experiments/tests/HDF5/annotations.hdf5')
self.traj = Trajectory(name='Annotations', filename = self.filename)
self.traj.f_add_result('testres', 42)
self.traj.f_add_parameter('testgroup.testparam', 42)
self.make_annotations()
self.add_annotations(self.traj)
self.assertTrue(len([node for node in self.traj.f_iter_nodes(recursive=True)]) == 5)
def make_annotations(self):
self.annotations={}
self.annotations['dict']={'33':12,'kkk':[1,2,'h'], 3:{'a':42.0}}
self.annotations['list']= [self.annotations['dict'],33]
self.annotations['string'] = 'string'
self.annotations['integer'] = 42
self.annotations['tuple']=(3,4,5)
self.annotations['Numpy_Data'] = np.array(['fff','ddd'])
self.annotations[0] = 7777
def add_annotations(self, traj):
funcs = 5
for idx,node in enumerate(traj.f_iter_nodes(recursive=True)):
for name in self.annotations:
anno = self.annotations[name]
if name == 0:
node.f_set_annotations(anno)
node.v_annotations.f_set(anno)
elif idx % funcs == 0:
node.f_set_annotations(**{name:anno})
elif idx % funcs == 1:
node.v_annotations.f_set(**{name:anno})
elif idx % funcs == 2:
node.v_annotations.f_set_single(name,anno)
elif idx % funcs == 3:
setattr(node.v_annotations,name, anno)
elif idx % funcs == 4:
node.v_annotations[name]=anno
def test_annotations_insert(self):
for node in self.traj.f_iter_nodes(recursive=True):
for name in self.annotations:
anno = self.annotations[name]
node_anno = node.v_annotations[name]
self.assertTrue(comp.nested_equal(anno, node_anno),
'%s != %s' % (str(anno), str(node_anno)))
def test_pickling(self):
dump = pickle.dumps(self.traj)
del self.traj
self.traj = pickle.loads(dump)
self.test_annotations_insert()
def test_storage_and_loading(self):
self.traj.f_store()
traj_name = self.traj.v_name
del self.traj
self.traj = Trajectory(filename=self.filename)
self.traj.f_load(name=traj_name, load_results=2, load_parameters=2, load_derived_parameters=2,
load_other_data=2)
self.test_annotations_insert()
def test_attribute_deletion(self):
for node in self.traj.f_iter_nodes(recursive=True):
name_list=[name for name in node.v_annotations]
for name in name_list:
delattr(node.v_annotations, name)
self.assertTrue(node.v_annotations.f_is_empty())
def test_get_item(self):
for node in self.traj.f_iter_nodes(recursive=True):
for key, val1 in node.v_annotations.f_to_dict().items():
val2 = node.v_annotations[key]
self.assertTrue(comp.nested_equal(val1,val2))
#.........这里部分代码省略.........