当前位置: 首页>>代码示例>>Python>>正文


Python Trajectory.f_load_item方法代码示例

本文整理汇总了Python中pypet.trajectory.Trajectory.f_load_item方法的典型用法代码示例。如果您正苦于以下问题:Python Trajectory.f_load_item方法的具体用法?Python Trajectory.f_load_item怎么用?Python Trajectory.f_load_item使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pypet.trajectory.Trajectory的用法示例。


在下文中一共展示了Trajectory.f_load_item方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_partial_loading

# 需要导入模块: from pypet.trajectory import Trajectory [as 别名]
# 或者: from pypet.trajectory.Trajectory import f_load_item [as 别名]
    def test_partial_loading(self):
        traj = Trajectory(name='TestPartial', filename=make_temp_file('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_update_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_update_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'])
开发者ID:ilonajulczuk,项目名称:pypet,代码行数:32,代码来源:hdf5_storage_test.py

示例2: creation

# 需要导入模块: from pypet.trajectory import Trajectory [as 别名]
# 或者: from pypet.trajectory.Trajectory import f_load_item [as 别名]
# trajectory name on creation (if you do not want this, just say `add_time=False`).
# Thus, the name is not `example_09_huge_data`, but `example_09_huge_data_XXXX_XX_XX_XXhXXmXXs`:
old_traj_name = traj.v_name
del traj
traj = Trajectory(filename=filename)

# We only want to load the skeleton but not the data:
traj.f_load(name=old_traj_name, load_results=pypetconstants.LOAD_SKELETON)

# Check if we only loaded the skeleton, that means the `huge_matrices` result must be empty:
if traj.huge_matrices.f_is_empty():
    print('Told you!')
else:
    print('Unbelievable, this sucks!')

# Now let's only load `monty` and `mat1`.
# We can do this by passing the keyword argument `load_only` to the load item function:
traj.f_load_item('huge_matrices', load_only=['monty','mat1'])

# Check if this worked:
if ('monty' in traj.huge_matrices and
     'mat1' in traj.huge_matrices and
      not 'mat2' in traj.huge_matrices ):

    val_mat1 = traj.huge_matrices.mat1[10,10,10]
    print('mat1 contains %f at position [10,10,10]' % val_mat1)
    print('And do not forget: %s' % traj.huge_matrices.monty)
else:
    print('That\'s it, I quit! I cannot work like this!')

# Thanks for your attention!
开发者ID:henribunting,项目名称:pypet,代码行数:33,代码来源:example_09_large_results.py

示例3: main

# 需要导入模块: from pypet.trajectory import Trajectory [as 别名]
# 或者: from pypet.trajectory.Trajectory import f_load_item [as 别名]
def main():

    env = Environment(trajectory='Example_05_Euler_Integration',
                      filename='experiments/example_05/HDF5/example_05.hdf5',
                      file_title='Example_05_Euler_Integration',
                      log_folder='experiments/example_05/LOGS/',
                      comment = 'Go for Euler!')


    traj = env.v_trajectory
    trajectory_name = traj.v_name

    # 1st a) phase parameter addition
    add_parameters(traj)

    # 1st b) phase preparation
    # We will add the differential equation (well, its source code only) as a derived parameter
    traj.f_add_derived_parameter(FunctionParameter,'diff_eq', diff_lorenz,
                                 comment='Source code of our equation!')

    # We want to explore some initial conditions
    traj.f_explore({'initial_conditions' : [
        np.array([0.01,0.01,0.01]),
        np.array([2.02,0.02,0.02]),
        np.array([42.0,4.2,0.42])
    ]})
    # 3 different conditions are enough for an illustrative example

    # 2nd phase let's run the experiment
    # We pass `euler_scheme` as our top-level simulation function and
    # the Lorenz equation 'diff_lorenz' as an additional argument
    env.f_run(euler_scheme, diff_lorenz)

    # We don't have a 3rd phase of post-processing here

    # 4th phase analysis.
    # I would recommend to do post-processing completely independent from the simulation,
    # but for simplicity let's do it here.

    # Let's assume that we start all over again and load the entire trajectory new.
    # Yet, there is an error within this approach, do you spot it?
    del traj
    traj = Trajectory(filename='experiments/example_05/HDF5/example_05.hdf5')

    # We will only fully load parameters and derived parameters.
    # Results will be loaded manually later on.
    try:
        # However, this will fail because our trajectory does not know how to
        # build the FunctionParameter. You have seen this coming, right?
        traj.f_load(name=trajectory_name,load_parameters=2,
                    load_derived_parameters=2,load_results=1)
    except ImportError as e:

        print 'That did\'nt work, I am sorry. %s ' % e.message

        # Ok, let's try again but this time with adding our parameter to the imports
        traj = Trajectory(filename='experiments/example_05/HDF5/example_05.hdf5',
                           dynamically_imported_classes=FunctionParameter)

        # Now it works:
        traj.f_load(name=trajectory_name,load_parameters=2,
                    load_derived_parameters=2,load_results=1)


    #For the fun of it, let's print the source code
    print '\n ---------- The source code of your function ---------- \n %s' % traj.diff_eq

    # Let's get the exploration array:
    initial_conditions_exploration_array = traj.f_get('initial_conditions').f_get_range()
    # Now let's plot our simulated equations for the different initial conditions:
    # We will iterate through the run names
    for idx, run_name in enumerate(traj.f_get_run_names()):

        #Get the result of run idx from the trajectory
        euler_result = traj.results.f_get(run_name).euler_evolution
        # Now we manually need to load the result. Actually the results are not so large and we
        # could load them all at once. But for demonstration we do as if they were huge:
        traj.f_load_item(euler_result)
        euler_data = euler_result.data

        #Plot fancy 3d plot
        fig = plt.figure(idx)
        ax = fig.gca(projection='3d')
        x = euler_data[:,0]
        y = euler_data[:,1]
        z = euler_data[:,2]
        ax.plot(x, y, z, label='Initial Conditions: %s' % str(initial_conditions_exploration_array[idx]))
        plt.legend()
        plt.show()

        # Now we free the data again (because we assume its huuuuuuge):
        del euler_data
        euler_result.f_empty()
开发者ID:ilonajulczuk,项目名称:pypet,代码行数:95,代码来源:example_05_custom_parameter.py

示例4: Trajectory

# 需要导入模块: from pypet.trajectory import Trajectory [as 别名]
# 或者: from pypet.trajectory.Trajectory import f_load_item [as 别名]
traj.f_add_result('starwars.gross_income_of_film', amount=10.1 ** 11, currency='$$$',
                  comment='George Lucas is rich, dude!')
# This is a large number, we better store it and than free the memory:
traj.f_store_item('gross_income_of_film')
traj.gross_income_of_film.f_empty()


# Now lets reload the trajectory
del traj
traj = Trajectory(filename='experiments/example_02/HDF5/example_02.hdf5')
# We want to load the last trajectory in the file, therefore index = -1
# We want to load the parameters, therefore load_parameters=2
# We only want to load the skeleton of the results, so load_results=1
traj.f_load(index=-1,load_parameters=2,load_results=1)

# Let's check if our result is really empty
if traj.gross_income_of_film.f_is_empty():
    print 'Nothing there!'
else:
    print 'I found something!'

# Ok, let's manually reload the result
traj.f_load_item('gross_income_of_film')
if traj.gross_income_of_film.f_is_empty():
    print 'Still empty :-('
else:
    print 'George Lucas earned %s%s!' %(str(traj.gross_income_of_film.amount),
                                         traj.gross_income_of_film.currency)

# And that's how it works! If you wish, you can inspect the
# experiments/example_02/HDF5/example_02.hdf5 file to take a look at the tree structure
开发者ID:ilonajulczuk,项目名称:pypet,代码行数:33,代码来源:example_02_trajectory_access_and_storage.py


注:本文中的pypet.trajectory.Trajectory.f_load_item方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。