本文整理汇总了Python中pypet.Trajectory.f_add_result方法的典型用法代码示例。如果您正苦于以下问题:Python Trajectory.f_add_result方法的具体用法?Python Trajectory.f_add_result怎么用?Python Trajectory.f_add_result使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pypet.Trajectory
的用法示例。
在下文中一共展示了Trajectory.f_add_result方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_store_items_and_groups
# 需要导入模块: from pypet import Trajectory [as 别名]
# 或者: from pypet.Trajectory import f_add_result [as 别名]
def test_store_items_and_groups(self):
traj = Trajectory(name='testtraj', filename=make_temp_dir('teststoreitems.hdf5'))
traj.f_store()
traj.f_add_parameter('group1.test',42, comment= 'TooLong' * pypetconstants.HDF5_STRCOL_MAX_COMMENT_LENGTH)
traj.f_add_result('testres', 42)
traj.group1.f_set_annotations(Test=44)
traj.f_store_items(['test','testres','group1'])
traj2 = Trajectory(name=traj.v_name, add_time=False,
filename=make_temp_dir('teststoreitems.hdf5'))
traj2.f_load(load_parameters=2, load_results=2)
traj.f_add_result('Im.stored.along.a.path', 43)
traj.Im.stored.along.v_annotations['wtf'] =4444
traj.res.f_store_child('Im.stored.along.a.path')
traj2.res.f_load_child('Im.stored.along.a.path', load_data=2)
self.compare_trajectories(traj,traj2)
示例2: test_version_mismatch
# 需要导入模块: from pypet import Trajectory [as 别名]
# 或者: from pypet.Trajectory import f_add_result [as 别名]
def test_version_mismatch(self):
traj = Trajectory(name='TestVERSION', filename=make_temp_dir('testversionmismatch.hdf5'),
add_time=True)
traj.f_add_parameter('group1.test',42)
traj.f_add_result('testres', 42)
traj.group1.f_set_annotations(Test=44)
traj._version='0.1a.1'
traj.f_store()
traj2 = Trajectory(name=traj.v_name, add_time=False,
filename=make_temp_dir('testversionmismatch.hdf5'))
with self.assertRaises(pex.VersionMismatchError):
traj2.f_load(load_parameters=2, load_results=2)
traj2.f_load(load_parameters=2, load_results=2, force=True)
self.compare_trajectories(traj,traj2)
get_root_logger().info('Mismatch testing done!')
示例3: test_removal_of_error_parameter
# 需要导入模块: from pypet import Trajectory [as 别名]
# 或者: from pypet.Trajectory import f_add_result [as 别名]
def test_removal_of_error_parameter(self):
filename = make_temp_dir('remove_errored.hdf5')
traj = Trajectory(name='traj', add_time=True, filename=filename)
traj.f_add_result('iii', 42)
traj.f_add_result(FakeResult, 'j.j.josie', 43)
file = traj.v_storage_service.filename
traj.f_store(only_init=True)
with self.assertRaises(RuntimeError):
traj.f_store()
with ptcompat.open_file(file, mode='r') as fh:
jj = ptcompat.get_node(fh, where='/%s/results/j/j' % traj.v_name)
self.assertTrue('josie' not in jj)
traj.j.j.f_remove_child('josie')
traj.j.j.f_add_result(FakeResult2, 'josie2', 444)
traj.f_store()
with self.assertRaises(pex.NoSuchServiceError):
traj.f_store_child('results', recursive=True)
with ptcompat.open_file(file, mode='r') as fh:
jj = ptcompat.get_node(fh, where='/%s/results/j/j' % traj.v_name)
self.assertTrue('josie2' in jj)
josie2 = ptcompat.get_child(jj, 'josie2')
self.assertTrue('hey' in josie2)
self.assertTrue('fail' not in josie2)
示例4: test_auto_load
# 需要导入模块: from pypet import Trajectory [as 别名]
# 或者: from pypet.Trajectory import f_add_result [as 别名]
def test_auto_load(self):
traj = Trajectory(name='Testautoload', filename=make_temp_dir('autoload.hdf5'))
traj.v_auto_load = True
traj.f_add_result('I.am.$.a.mean.resu', 42, comment='Test')
traj.f_add_derived_parameter('ffa', 42)
traj.f_store()
ffa=traj.f_get('ffa')
ffa.f_unlock()
ffa.f_empty()
self.assertTrue(ffa.f_is_empty())
traj.f_remove_child('results', recursive=True)
# check auto load
val = traj.res.I.am.crun.a.mean.resu
self.assertTrue(val==42)
val = traj.ffa
self.assertTrue(val==42)
with self.assertRaises(pex.DataNotInStorageError):
traj.kdsfdsf
示例5: test_get_default
# 需要导入模块: from pypet import Trajectory [as 别名]
# 或者: from pypet.Trajectory import f_add_result [as 别名]
def test_get_default(self):
traj = Trajectory(name='Testgetdefault', filename=make_temp_dir('autoload.hdf5'))
traj.v_auto_load = True
traj.f_add_result('I.am.$.a.mean.resu', 42, comment='Test')
val = traj.f_get_default('jjjjjjjjjj', 555)
self.assertTrue(val==555)
traj.f_store()
traj.f_remove_child('results', recursive=True)
val = traj.f_get_default('res.I.am.crun.a.mean.answ', 444, auto_load=True)
self.assertTrue(val==444)
val = traj.f_get_default('res.I.am.crun.a.mean.resu', auto_load=True, fast_access=True)
self.assertTrue(val==42)
with self.assertRaises(Exception):
traj.kdsfdsf
示例6: test_errors
# 需要导入模块: from pypet import Trajectory [as 别名]
# 或者: from pypet.Trajectory import f_add_result [as 别名]
def test_errors(self):
filename = make_temp_dir("hdf5errors.hdf5")
traj = Trajectory(name=make_trajectory_name(self), filename=filename)
trajname = traj.v_name
npearray = np.ones((2, 10, 3), dtype=np.float)
thevlarray = np.array([compat.tobytes("j"), 22.2, compat.tobytes("gutter")])
with self.assertRaises(TypeError):
traj.f_add_result(SharedResult, "arrays.vlarray", SharedVLArray()).create_shared_data(obj=thevlarray)
traj.f_store()
traj.arrays.vlarray.create_shared_data(obj=thevlarray)
traj.f_add_result(SharedResult, "arrays.array", SharedArray()).create_shared_data(data=npearray)
traj.arrays.f_add_result(SharedResult, "super.carray", SharedCArray(), comment="carray").create_shared_data(
shape=(10, 10), atom=pt.atom.FloatAtom()
)
traj.arrays.f_add_result(SharedResult, "earray", SharedEArray()).create_shared_data("earray", obj=npearray)
traj.f_store()
with self.assertRaises(TypeError):
traj.arrays.array.iter_rows()
with StorageContextManager(traj) as cm:
with self.assertRaises(RuntimeError):
with StorageContextManager(traj) as cm2:
pass
self.assertTrue(traj.v_storage_service.is_open)
with self.assertRaises(RuntimeError):
StorageContextManager(traj).f_open_store()
self.assertFalse(traj.v_storage_service.is_open)
示例7: main
# 需要导入模块: from pypet import Trajectory [as 别名]
# 或者: from pypet.Trajectory import f_add_result [as 别名]
def main():
# We don't use an environment so we enable logging manually
logging.basicConfig(level=logging.INFO)
filename = os.path.join('hdf5','example_16.hdf5')
traj = Trajectory(filename=filename, overwrite_file=True)
# The result that will be manipulated
traj.f_add_result('last_process_name', 'N/A',
comment='Name of the last process that manipulated the trajectory')
with MultiprocContext(trajectory=traj, wrap_mode='LOCK') as mc:
# The multiprocessing context manager wraps the storage service of the trajectory
# and passes the wrapped service to the trajectory.
# Also restores the original storage service in the end.
# Moreover, wee need to use the `MANAGER_LOCK` wrapping because the locks
# are pickled and send to the pool for all function executions
# Start a pool of processes manipulating the trajectory
iterable = (traj for x in range(20))
pool = mp.Pool(processes=4)
# Pass the trajectory and the function to the pool and execute it 20 times
pool.map_async(manipulate_multiproc_safe, iterable)
pool.close()
# Wait for all processes to join
pool.join()
# Reload the data from disk and overwrite the existing result in RAM
traj.results.f_load(load_data=3)
# Print the name of the last process the trajectory was manipulated by
print('The last process to manipulate the trajectory was: `%s`' % traj.last_process_name)
示例8: test_store_and_load_large_dictionary
# 需要导入模块: from pypet import Trajectory [as 别名]
# 或者: from pypet.Trajectory import f_add_result [as 别名]
def test_store_and_load_large_dictionary(self):
traj = Trajectory(name='Testlargedict', filename=make_temp_dir('large_dict.hdf5'))
large_dict = {}
for irun in range(1025):
large_dict['item_%d' % irun] = irun
large_dict2 = {}
for irun in range(33):
large_dict2['item_%d' % irun] = irun
traj.f_add_result('large_dict', large_dict, comment='Huge_dict!')
traj.f_add_result('large_dict2', large_dict2, comment='Not so large dict!')
traj.f_store()
traj_name = traj.v_name
traj2 = Trajectory(filename=make_temp_dir('large_dict.hdf5'))
traj2.f_load(name=traj_name, load_data=2)
self.compare_trajectories(traj, traj2)
示例9: test_loading_and_storing_empty_containers
# 需要导入模块: from pypet import Trajectory [as 别名]
# 或者: from pypet.Trajectory import f_add_result [as 别名]
def test_loading_and_storing_empty_containers(self):
filename = make_temp_dir('empty_containers.hdf5')
traj = Trajectory(filename=filename)
# traj.f_add_parameter('empty.dict', {})
# traj.f_add_parameter('empty.list', [])
traj.f_add_parameter(ArrayParameter, 'empty.tuple', ())
traj.f_add_parameter(ArrayParameter, 'empty.array', np.array([], dtype=float))
spsparse_csc = spsp.csc_matrix((2,10))
spsparse_csr = spsp.csr_matrix((6660,660))
spsparse_bsr = spsp.bsr_matrix((3330,2220))
spsparse_dia = spsp.dia_matrix((1230,1230))
traj.f_add_parameter(SparseParameter, 'empty.csc', spsparse_csc)
traj.f_add_parameter(SparseParameter, 'empty.csr', spsparse_csr)
traj.f_add_parameter(SparseParameter, 'empty.bsr', spsparse_bsr)
traj.f_add_parameter(SparseParameter, 'empty.dia', spsparse_dia)
traj.f_add_result(SparseResult, 'empty.all', dict={}, list=[],
series = pd.Series(),
frame = pd.DataFrame(),
panel = pd.Panel(),
**traj.par.f_to_dict(short_names=True, fast_access=True))
traj.f_store()
newtraj = load_trajectory(index=-1, filename=filename)
newtraj.f_load(load_data=2)
epg = newtraj.par.empty
self.assertTrue(type(epg.tuple) is tuple)
self.assertTrue(len(epg.tuple) == 0)
self.assertTrue(type(epg.array) is np.ndarray)
self.assertTrue(epg.array.size == 0)
self.assertTrue(spsp.isspmatrix_csr(epg.csr))
self.assertTrue(epg.csr.size == 0)
self.assertTrue(spsp.isspmatrix_csc(epg.csc))
self.assertTrue(epg.csc.size == 0)
self.assertTrue(spsp.isspmatrix_bsr(epg.bsr))
self.assertTrue(epg.bsr.size == 0)
self.assertTrue(spsp.isspmatrix_dia(epg.dia))
self.assertTrue(epg.dia.size == 0)
self.compare_trajectories(traj, newtraj)
示例10: test_compacting
# 需要导入模块: from pypet import Trajectory [as 别名]
# 或者: from pypet.Trajectory import f_add_result [as 别名]
def test_compacting(self):
filename = make_temp_dir("hdf5compacting.hdf5")
traj = Trajectory(name=make_trajectory_name(self), filename=filename)
trajname = traj.v_name
traj.v_storage_service.complevel = 7
first_row = {"ha": compat.tobytes("hi"), "haha": np.zeros((3, 3))}
traj.f_store(only_init=True)
res1 = traj.f_add_result("My.Tree.Will.Be.Deleted", 42)
res2 = traj.f_add_result("Mine.Too.HomeBoy", 42, comment="Don`t cry for me!")
res = traj.f_add_result(SharedResult, "myres")
res["myres"] = SharedTable()
res["myres"].create_shared_data(first_row=first_row)
with StorageContextManager(traj):
tab = traj.myres
for irun in range(10000):
row = traj.myres.row
for key in first_row:
row[key] = first_row[key]
row.append()
traj.f_store()
del traj
traj = load_trajectory(name=trajname, filename=filename, load_all=2)
with StorageContextManager(traj) as cm:
tb = traj.myres.get_data_node()
ptcompat.remove_rows(tb, 1000, 10000)
cm.f_flush_store()
self.assertTrue(traj.myres.nrows == 1001)
traj.f_delete_item(traj.My, recursive=True)
traj.f_delete_item(traj.Mine, recursive=True)
size = os.path.getsize(filename)
get_root_logger().info("Filesize is %s" % str(size))
name_wo_ext, ext = os.path.splitext(filename)
backup_file_name = name_wo_ext + "_backup" + ext
code = compact_hdf5_file(filename, keep_backup=True)
if code != 0:
raise RuntimeError("ptrepack fail")
backup_size = os.path.getsize(backup_file_name)
self.assertTrue(backup_size == size)
new_size = os.path.getsize(filename)
get_root_logger().info("New filesize is %s" % str(new_size))
self.assertTrue(new_size < size, "%s > %s" % (str(new_size), str(size)))
示例11: test_delete_links
# 需要导入模块: from pypet import Trajectory [as 别名]
# 或者: from pypet.Trajectory import f_add_result [as 别名]
def test_delete_links(self):
traj = Trajectory(name='TestDelete',
filename=make_temp_dir('testpartiallydel.hdf5'),
add_time=True)
res = traj.f_add_result('mytest.test', a='b', c='d')
traj.f_add_link('x.y', res)
traj.f_add_link('x.g.h', res)
traj.f_store()
traj.f_remove_child('x', recursive=True)
traj.f_load()
self.assertEqual(traj.x.y.a, traj.test.a)
self.assertEqual(traj.x.g.h.a, traj.test.a)
traj.f_delete_link('x.y', remove_from_trajectory=True)
traj.f_delete_link((traj.x.g, 'h'), remove_from_trajectory=True)
traj.f_load()
with self.assertRaises(AttributeError):
traj.x.g.h
示例12: test_partial_loading
# 需要导入模块: from pypet import Trajectory [as 别名]
# 或者: from pypet.Trajectory import f_add_result [as 别名]
def test_partial_loading(self):
traj = Trajectory(name='TestPartial', filename=make_temp_dir('testpartially.hdf5'))
res = traj.f_add_result('mytest.test', a='b', c='d')
traj.f_store()
traj.f_remove_child('results', recursive=True)
traj.f_load_skeleton()
traj.f_load_item(traj.test, load_only=['a', 'x'])
self.assertTrue('a' in traj.test)
self.assertTrue('c' not in traj.test)
traj.f_remove_child('results', recursive=True)
traj.f_load_skeleton()
load_except= ['c', 'd']
traj.f_load_item(traj.test, load_except=load_except)
self.assertTrue(len(load_except)==2)
self.assertTrue('a' in traj.test)
self.assertTrue('c' not in traj.test)
with self.assertRaises(ValueError):
traj.f_load_item(traj.test, load_except=['x'], load_only=['y'])
示例13: test_partially_delete_stuff
# 需要导入模块: from pypet import Trajectory [as 别名]
# 或者: from pypet.Trajectory import f_add_result [as 别名]
def test_partially_delete_stuff(self):
traj = Trajectory(name='TestDelete',
filename=make_temp_dir('testpartiallydel.hdf5'))
res = traj.f_add_result('mytest.test', a='b', c='d')
traj.f_store()
self.assertTrue('a' in res)
traj.f_delete_item(res, delete_only=['a'], remove_from_item=True)
self.assertTrue('c' in res)
self.assertTrue('a' not in res)
res['a'] = 'offf'
self.assertTrue('a' in res)
traj.f_load(load_results=3)
self.assertTrue('a' not in res)
self.assertTrue('c' in res)
traj.f_delete_item(res, remove_from_trajectory=True)
self.assertTrue('results' in traj)
self.assertTrue(res not in traj)
示例14: test_overwrite_stuff
# 需要导入模块: from pypet import Trajectory [as 别名]
# 或者: from pypet.Trajectory import f_add_result [as 别名]
def test_overwrite_stuff(self):
traj = Trajectory(name='TestOverwrite', filename=make_temp_dir('testowrite.hdf5'))
res = traj.f_add_result('mytest.test', a='b', c='d')
traj.f_store()
res['a'] = np.array([1,2,3])
res['c'] = 123445
traj.f_store_item(res, overwrite='a', complevel=4)
# Should emit a warning
traj.f_store_item(res, overwrite=['a', 'b'])
traj.f_load(load_results=3)
res = traj.test
self.assertTrue((res['a']==np.array([1,2,3])).all())
self.assertTrue(res['c']=='d')
res['c'] = 123445
traj.f_store_item(res, store_data=3)
res.f_empty()
traj.f_load(load_results=3)
self.assertTrue(traj.test['c']==123445)
示例15: test_storing_and_loading_groups
# 需要导入模块: from pypet import Trajectory [as 别名]
# 或者: from pypet.Trajectory import f_add_result [as 别名]
def test_storing_and_loading_groups(self):
filename = make_temp_dir('grpgrp.hdf5')
traj = Trajectory(name='traj', add_time=True, filename=filename)
res=traj.f_add_result('aaa.bbb.ccc.iii', 42, 43, comment=7777 * '6')
traj.ccc.v_annotations['gg']=4
res=traj.f_add_result('aaa.ddd.eee.jjj', 42, 43, comment=777 * '6')
traj.ccc.v_annotations['j'] = 'osajdsojds'
traj.f_store(only_init=True)
traj.f_store_item('aaa', recursive=True)
newtraj = load_trajectory(traj.v_name, filename=filename, load_all=2)
self.compare_trajectories(traj, newtraj)
traj.iii.f_set(55)
self.assertFalse(results_equal(traj.iii, newtraj.iii))
traj.aaa.f_store(recursive=True, store_data=3)
newtraj.bbb.f_load(recursive=True, load_data=3)
self.compare_trajectories(traj, newtraj)
traj.ccc.v_annotations['gg'] = 5
traj.f_load(load_data=3)
self.assertTrue(traj.ccc.v_annotations['gg'] == 4)
traj.ccc.v_annotations['gg'] = 5
traj.f_store(store_data=3)
newtraj.f_load(load_data=2)
self.assertTrue(newtraj.ccc.v_annotations['gg'] == 4)
newtraj.f_load(load_data=3)
self.assertTrue(newtraj.ccc.v_annotations['gg'] == 5)
traj.ccc.f_add_link('link', res)
traj.f_store_item(traj.ccc, store_data=3, with_links=False)
newtraj.f_load(load_data=3)
self.assertTrue('link' not in newtraj.ccc)
traj.f_store_item(traj.ccc, store_data=3, with_links=True, recursive=True)
newtraj.f_load_item(newtraj.ccc, with_links=False, recursive=True)
self.assertTrue('link' not in newtraj.ccc)
newtraj.f_load_item(newtraj.ccc, recursive=True)
self.assertTrue('link' in newtraj.ccc)