• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python dataset.dataset函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中msmbuilder.dataset.dataset函数的典型用法代码示例。如果您正苦于以下问题:Python dataset函数的具体用法?Python dataset怎么用?Python dataset使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: test_order_1

def test_order_1():
    with tempdir():
        with dataset('ds1.h5', 'w', 'hdf5') as ds1:
            for i in range(20):
                ds1[i] = np.random.randn(10)
            assert list(ds1.keys()) == list(range(20))

        with dataset('ds1/', 'w', 'dir-npy') as ds1:
            for i in range(20):
                ds1[i] = np.random.randn(10)
            assert list(ds1.keys()) == list(range(20))
开发者ID:dr-nate,项目名称:msmbuilder,代码行数:11,代码来源:test_dataset.py


示例2: test_mdtraj_1

def test_mdtraj_1():
    ds = dataset(get_fn('') + '*.pdb', fmt='mdtraj', verbose=True)
    print(ds.keys())
    print(ds.get(0))
    print(ds.provenance)

    ds = dataset(get_fn('') + '*.pdb', fmt='mdtraj', atom_indices=[1, 2],
                 verbose=True)
    print(ds.keys())
    print(ds.get(0))
    print(ds.provenance)
开发者ID:dr-nate,项目名称:msmbuilder,代码行数:11,代码来源:test_dataset.py


示例3: test_union_3

def test_union_3():
    with tempdir():
        # This doesn't work with py2.6
        with dataset('ds1/', 'w', 'dir-npy') as ds1, \
                dataset('ds2/', 'w', 'dir-npy') as ds2:
            ds1[0] = np.random.randn(10, 2)
            ds1[1] = np.random.randn(10)
            ds2[0] = np.random.randn(10,4)
            # Uneven length!

        with assert_raises(ValueError):
            mds = dataset(['ds1', 'ds2'])
开发者ID:schwancr,项目名称:msmbuilder,代码行数:12,代码来源:test_dataset.py


示例4: test_hdf5_3

def test_hdf5_3():
    with tempdir():
        with dataset('ds.h5', 'w', 'hdf5') as ds:
            ds[0] = np.random.randn(10)
            ds[1] = np.random.randn(10)
            ref_sum = _sum_helper(ds)

        iter_args = (dataset('ds.h5') for _ in range(5))

        sums = Parallel(n_jobs=2)(
            delayed(_sum_helper)(a) for a in iter_args)

        assert all(s == ref_sum for s in sums)
开发者ID:dr-nate,项目名称:msmbuilder,代码行数:13,代码来源:test_dataset.py


示例5: test_uneven_n

def test_uneven_n():
    with tempdir():
        # This doesn't work with py2.6
        with dataset('ds1/', 'w', 'dir-npy') as ds1, \
                dataset('ds2/', 'w', 'dir-npy') as ds2:
            ds1[0] = np.random.randn(10, 2)
            ds1[1] = np.random.randn(5, 2)
            ds2[0] = np.random.randn(10, 4)
            # Uneven number of trajs!

            fu = FeatureUnion(normalize=False)
            with assert_raises(ValueError):
                fu.fit((ds1, ds2))
开发者ID:Eigenstate,项目名称:msmbuilder,代码行数:13,代码来源:test_featureunion.py


示例6: test_union_2

def test_union_2():
    with tempdir():
        # This doesn't work with py2.6
        with dataset('ds1/', 'w', 'dir-npy') as ds1, \
                dataset('ds2/', 'w', 'dir-npy') as ds2:
            ds1[0] = np.random.randn(10, 2)
            ds1[1] = np.random.randn(10)
            ds2[0] = np.random.randn(10,4)
            ds2[1] = np.random.randn(10,4)


        mds = dataset(['ds1', 'ds2'])
        mds_out = mds.create_derived('derived', fmt='dir-npy')
        assert len(mds_out.provenance.split('\n')) > 0
开发者ID:schwancr,项目名称:msmbuilder,代码行数:14,代码来源:test_dataset.py


示例7: test_assign

    def test_assign(self):
        with open(os.devnull) as dn:
            subprocess.call(
                [
                    'msmb', 'SolventShellsAssigner', '--trjs', self.traj_fn,
                    '--solute_indices', self.ute_fn, '--solvent_indices',
                    self.vent_fn, '--n_shells', '3', '--shell_width', '1',
                    '--out', self.outfn, '--chunk', '2'
                ], stdout=dn, stderr=dn
            )

        data = dataset(self.outfn)[0]

        should_be = np.array([
            [0, 0, 0, 0],
            [0, 1, 0, 0],
            [1, 0, 0, 1],
            [1, 1, 0, 1],
            [2, 0, 0, 2],
            [2, 1, 0, 2],
            # 3
            # 4
            [5, 1, 0, 0],
            [6, 1, 0, 1],
            [7, 1, 0, 2],
            # 8
        ])

        np.testing.assert_array_equal(data, should_be)
开发者ID:mpharrigan,项目名称:wetmsm,代码行数:29,代码来源:test_shells.py


示例8: test_partial_transform

    def test_partial_transform(self):
        with open(os.devnull) as dn:
            subprocess.call(
                [
                    'msmb', 'SolventShellsFeaturizer', '--trjs', self.traj_fn,
                    '--solute_indices', self.ute_fn, '--solvent_indices',
                    self.vent_fn, '--n_shells', '3', '--shell_width', '1',
                    '--out', self.outfn
                ], stdout=dn, stderr=dn
            )
        data = dataset(self.outfn)[0]

        norm = np.asarray([4 * np.pi * r ** 2 for r in [0.5, 1.5, 2.5]])
        should_be = np.array([
            [2, 0, 0],
            [0, 2, 0],
            [0, 0, 2],
            [0, 0, 0],
            [0, 0, 0],
            [1, 0, 0],
            [0, 1, 0],
            [0, 0, 1],
            [0, 0, 0]
        ]) / norm

        np.testing.assert_array_equal(data, should_be)
开发者ID:mpharrigan,项目名称:wetmsm,代码行数:26,代码来源:test_shells.py


示例9: test_1

def test_1():
    path = tempfile.mkdtemp()
    shutil.rmtree(path)
    try:
        X = np.random.randn(10, 2)
        ds = dataset(path, 'w', 'dir-npy')
        ds[0] = X
        assert set(os.listdir(path)) == set(('PROVENANCE.txt', '00000000.npy'))
        np.testing.assert_array_equal(ds[0], X)

        assert_raises(IndexError, lambda: ds[1])
        assert len(ds) == 1

        Y = np.zeros((10, 1))
        Z = np.ones((2, 2))
        ds[1] = Y
        ds[2] = Z
        np.testing.assert_array_equal(ds[1], Y)
        np.testing.assert_array_equal(ds[2], Z)
        assert len(ds) == 3

        for i, item in enumerate(ds):
            np.testing.assert_array_equal(item, [X, Y, Z][i])
    except:
        raise
    finally:
        shutil.rmtree(path)
开发者ID:dr-nate,项目名称:msmbuilder,代码行数:27,代码来源:test_dataset.py


示例10: test_2

def test_2():
    path1 = tempfile.mkdtemp()
    path2 = tempfile.mkdtemp()
    shutil.rmtree(path1)
    shutil.rmtree(path2)
    try:

        X = np.random.randn(10, 2)
        Y = np.random.randn(10, 2)
        ds1 = dataset(path1, 'w', 'dir-npy')
        ds1[0] = X

        ds2 = ds1.create_derived(path2)
        ds2[0] = Y

        np.testing.assert_array_equal(ds1[0], X)
        np.testing.assert_array_equal(ds2[0], Y)
        assert len(ds1) == 1
        assert len(ds2) == 1

        prov2 = ds2.provenance
        print(prov2)
        assert 2 == sum([s.startswith('  Command') for s in prov2.splitlines()])

    except:
        raise
    finally:
        shutil.rmtree(path1)
        shutil.rmtree(path2)
开发者ID:dr-nate,项目名称:msmbuilder,代码行数:29,代码来源:test_dataset.py


示例11: start

    def start(self):
        if os.path.exists(self.out):
            self.error('File exists: %s' % self.out)

        print(self.instance)
        if os.path.exists(os.path.expanduser(self.top)):
            top = os.path.expanduser(self.top)
        else:
            top = None

        traj_dataset = MDTrajDataset(self.trjs, topology=top,
                                     stride=self.instance.stride, verbose=False)

        with dataset(self.assignments, mode='r') as assn_dataset:
            out_dataset = assn_dataset.create_derived(self.out, fmt='dir-npy')
            pbar = ProgressBar(widgets=[Percentage(), Bar(), ETA()],
                               maxval=len(assn_dataset)).start()
            for tr_key, as_key in pbar(
                    zip(traj_dataset.keys(), assn_dataset.keys())
            ):
                out_dataset[as_key] = self.instance.partial_transform(
                    (traj_dataset[tr_key], assn_dataset[as_key])
                )
            out_dataset.close()

        print("\nSaving transformed dataset to '%s'" % self.out)
        print("To load this dataset interactive inside an IPython")
        print("shell or notebook, run\n")
        print("  $ ipython")
        print("  >>> from msmbuilder.dataset import dataset")
        print("  >>> ds = dataset('%s')\n" % self.out)
开发者ID:mpharrigan,项目名称:wetmsm,代码行数:31,代码来源:vmd_write.py


示例12: test_transform_command_1

def test_transform_command_1():
    with tempdir():
        shell("msmb KCenters -i {data_home}/alanine_dipeptide/*.dcd "
              "-o model.pkl --top {data_home}/alanine_dipeptide/ala2.pdb "
              "--metric rmsd".format(data_home=get_data_home()))
        shell("msmb TransformDataset -i {data_home}/alanine_dipeptide/*.dcd "
              "-m model.pkl -t transformed.h5 --top "
              "{data_home}/alanine_dipeptide/ala2.pdb".format(data_home=get_data_home()))

        eq(dataset('transformed.h5')[0], load('model.pkl').labels_[0])
开发者ID:synapticarbors,项目名称:msmbuilder-1,代码行数:10,代码来源:test_commands.py


示例13: test_hdf5_1

def test_hdf5_1():
    with tempdir():
        ds = dataset('ds.h5', 'w', 'hdf5')
        print(ds.provenance)
        ds[0] = np.zeros(10)
        np.testing.assert_array_equal(ds.get(0), np.zeros(10))
        assert list(ds.keys()) == [0]
        assert len(ds) == 1

        ds[0] = np.random.randn(10, 1)
        ds[1] = np.random.randn(10, 2)
        ds[2] = np.random.randn(10, 3)

        np.testing.assert_array_equal(ds[:][0], ds[0])
        np.testing.assert_array_equal(ds[:][1], ds[1])
        np.testing.assert_array_equal(ds[:][2], ds[2])

        ds.close()
        with dataset('ds.h5') as ds:
            assert ds[0].shape == (10, 1)
开发者ID:dr-nate,项目名称:msmbuilder,代码行数:20,代码来源:test_dataset.py


示例14: test_atom_pairs_featurizer

def test_atom_pairs_featurizer():
    with tempdir():
        shell('msmb AtomIndices -o all.txt --all -d -p %s/alanine_dipeptide/ala2.pdb' % get_data_home()),
        shell("msmb AtomPairsFeaturizer --trjs '{data_home}/alanine_dipeptide/*.dcd'"
              " --out pairs --pair_indices all.txt"
              " --top {data_home}/alanine_dipeptide/ala2.pdb".format(
                  data_home=get_data_home()))
        ds = dataset('pairs')
        assert len(ds) == 10
        assert ds[0].shape[1] == len(np.loadtxt('all.txt')**2)
        print(ds.provenance)
开发者ID:schwancr,项目名称:msmbuilder,代码行数:11,代码来源:test_commands.py


示例15: test_union

def test_union():
    with tempdir():
        # This doesn't work with py2.6
        with dataset('ds1.h5', 'w', 'hdf5') as ds1, \
             dataset('ds2.h5', 'w', 'hdf5') as ds2:
            ds1[0] = np.random.randn(10, 2)
            ds1[1] = np.random.randn(10)
            ds2[0] = np.random.randn(10,4)
            ds2[1] = np.random.randn(10,4)

            # Compare row sums
            rs1 = np.sum(ds1[0], axis=1) + np.sum(ds2[0], axis=1)
            rs2 = ds1[1] + np.sum(ds2[1], axis=1)

        mds = dataset(['ds1.h5', 'ds2.h5'])

        assert len(mds) == 2
        assert mds[0].shape == (10, 6)
        assert mds[1].shape == (10, 5)
        np.testing.assert_array_almost_equal(np.sum(mds[0], axis=1), rs1)
        np.testing.assert_array_almost_equal(np.sum(mds[1], axis=1), rs2)
开发者ID:schwancr,项目名称:msmbuilder,代码行数:21,代码来源:test_dataset.py


示例16: test_superpose_featurizer

def test_superpose_featurizer():
    with tempdir():
        shell('msmb AtomIndices -o all.txt --all -a -p %s/alanine_dipeptide/ala2.pdb' % get_data_home()),
        shell("msmb SuperposeFeaturizer --trjs '{data_home}/alanine_dipeptide/*.dcd'"
              " --out distances --atom_indices all.txt"
              " --reference_traj {data_home}/alanine_dipeptide/ala2.pdb"
              " --top {data_home}/alanine_dipeptide/ala2.pdb".format(
                  data_home=get_data_home()))
        ds = dataset('distances')
        assert len(ds) == 10
        assert ds[0].shape[1] == len(np.loadtxt('all.txt'))
        print(ds.provenance)
开发者ID:schwancr,项目名称:msmbuilder,代码行数:12,代码来源:test_commands.py


示例17: test_append_dirnpy

def test_append_dirnpy():
    path = tempfile.mkdtemp()
    shutil.rmtree(path)
    try:
        with dataset(path, 'w', 'dir-npy') as ds:
            ds[0] = np.random.randn(10, 2)
        with dataset(path, 'a', 'dir-npy') as ds:
            ds[1] = np.random.randn(10, 2)
        with dataset(path, 'a', 'dir-npy') as ds:
            ds[2] = np.random.randn(10, 2)
        with dataset(path, 'a', 'dir-npy') as ds:
            # Overwrite
            ds[2] = np.random.randn(10, 2)

        np.testing.assert_array_equal(ds[:][0], ds[0])
        np.testing.assert_array_equal(ds[:][1], ds[1])
        np.testing.assert_array_equal(ds[:][2], ds[2])


    finally:
        shutil.rmtree(path)
开发者ID:dr-nate,项目名称:msmbuilder,代码行数:21,代码来源:test_dataset.py


示例18: test_4

def test_4():
    path = tempfile.mkdtemp()
    shutil.rmtree(path)
    try:
        ds = dataset(path, 'w', 'dir-npy')
        ds[0] = np.random.randn(10, 2)
        v = ds.get(0, mmap=True)
        assert isinstance(v, np.memmap)
        np.testing.assert_array_equal(ds[0], v)
        del v  # close the underlying file
    finally:
        shutil.rmtree(path)
开发者ID:dr-nate,项目名称:msmbuilder,代码行数:12,代码来源:test_dataset.py


示例19: test_dataset

def test_dataset():
    with tempdir():
        # This doesn't work with py2.6
        with dataset('ds1.h5', 'w', 'hdf5') as ds1, \
                dataset('ds2.h5', 'w', 'hdf5') as ds2:
            ds1[0] = np.random.randn(10, 2)
            ds1[1] = np.random.randn(5, 2)
            ds2[0] = np.random.randn(10, 4)
            ds2[1] = np.random.randn(5, 4)

            # Compare row sums
            rs1 = np.sum(ds1[0], axis=1) + np.sum(ds2[0], axis=1)
            rs2 = np.sum(ds1[1], axis=1) + np.sum(ds2[1], axis=1)

            fu = FeatureUnion(normalize=False)
            mds = fu.fit_transform((ds1, ds2))

        assert len(mds) == 2
        assert mds[0].shape == (10, 6)
        assert mds[1].shape == (5, 6)
        np.testing.assert_array_almost_equal(np.sum(mds[0], axis=1), rs1)
        np.testing.assert_array_almost_equal(np.sum(mds[1], axis=1), rs2)
开发者ID:Eigenstate,项目名称:msmbuilder,代码行数:22,代码来源:test_featureunion.py


示例20: test_3

def test_3():
    path = tempfile.mkdtemp()
    shutil.rmtree(path)
    try:
        ds = dataset(path, 'w', 'dir-npy')
        ds[0] = np.random.randn(10, 2)
        ds[1] = np.random.randn(10, 2)
        ds[2] = np.random.randn(10, 2)

        np.testing.assert_array_equal(ds[:][0], ds[0])
        np.testing.assert_array_equal(ds[:][1], ds[1])
        np.testing.assert_array_equal(ds[:][2], ds[2])


    finally:
        shutil.rmtree(path)
开发者ID:dr-nate,项目名称:msmbuilder,代码行数:16,代码来源:test_dataset.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python core.fast_pdist函数代码示例发布时间:2022-05-27
下一篇:
Python cluster.NDGrid类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap