Esempio n. 1
0
def test_iter_datasets():
    with h5.File('horton.scripts.test.test_hdf2csv.test_iter_datasets', driver='core', backing_store=False) as f:
        fill_hdf5(f)
        l = list(iter_datasets(f))
        assert len(l) == 5
        assert l[0][0] == 'bar/foo'
        assert l[0][1] == f['bar/foo']
        assert l[1][0] == 'test0'
        assert l[1][1] == f['test0']
        assert l[2][0] == 'test1'
        assert l[2][1] == f['test1']
        assert l[3][0] == 'test2'
        assert l[3][1] == f['test2']
        assert l[4][0] == 'zzz'
        assert l[4][1] == f['zzz']
Esempio n. 2
0
def test_iter_datasets():
    with h5.File('horton.scripts.test.test_hdf2csv.test_iter_datasets', driver='core', backing_store=False) as f:
        fill_hdf5(f)
        l = list(iter_datasets(f))
        assert len(l) == 5
        assert l[0][0] == 'bar/foo'
        assert l[0][1] == f['bar/foo']
        assert l[1][0] == 'test0'
        assert l[1][1] == f['test0']
        assert l[2][0] == 'test1'
        assert l[2][1] == f['test1']
        assert l[3][0] == 'test2'
        assert l[3][1] == f['test2']
        assert l[4][0] == 'zzz'
        assert l[4][1] == f['zzz']
Esempio n. 3
0
def test_iter_datasets():
    with h5.File("horton.scripts.test.test_hdf2csv.test_iter_datasets", driver="core", backing_store=False) as f:
        fill_hdf5(f)
        l = list(iter_datasets(f))
        assert len(l) == 5
        assert l[0][0] == "bar/foo"
        assert l[0][1] == f["bar/foo"]
        assert l[1][0] == "test0"
        assert l[1][1] == f["test0"]
        assert l[2][0] == "test1"
        assert l[2][1] == f["test1"]
        assert l[3][0] == "test2"
        assert l[3][1] == f["test2"]
        assert l[4][0] == "zzz"
        assert l[4][1] == f["zzz"]
Esempio n. 4
0
def main():
    args = parse_args()

    fn_h5, grp_name = parse_h5(args.h5, 'h5')
    with LockedH5File(fn_h5, 'r') as fin, open(args.csv, 'w') as fout:
        w = csv.writer(fout)
        w.writerow(['Converted data from %s' % args.h5])
        w.writerow([])
        for name, dset in iter_datasets(fin[grp_name]):
            if len(dset.shape) > 3:
                if log.do_warning:
                    log.warn(
                        'Skipping %s because it has more than three axes.' %
                        name)
            else:
                log('Converting %s' % name)

            w.writerow(['Dataset', name])
            w.writerow(['Shape'] + list(dset.shape))
            if len(dset.shape) == 0:
                w.writerow([dset[()]])
            elif len(dset.shape) == 1:
                for value in dset:
                    w.writerow([value])
            elif len(dset.shape) == 2:
                for row in dset:
                    w.writerow([value for value in row])
            elif len(dset.shape) == 3:
                for array in dset:
                    l = []
                    for col in array.T:
                        for value in col:
                            l.append(value)
                        l.append('')
                    del l[-1]
                    w.writerow(l)
            else:
                w.writerow(['Skipped because ndim=%i>3' % len(dset.shape)])
            w.writerow([])
Esempio n. 5
0
def main():
    args = parse_args()

    fn_h5, grp_name = parse_h5(args.h5, 'h5')
    with LockedH5File(fn_h5, 'r') as fin, open(args.csv, 'w') as fout:
        w = csv.writer(fout)
        w.writerow(['Converted data from %s' % args.h5])
        w.writerow([])
        for name, dset in iter_datasets(fin[grp_name]):
            if len(dset.shape) > 3:
                if log.do_warning:
                    log.warn('Skipping %s because it has more than three axes.' % name)
            else:
                log('Converting %s' % name)

            w.writerow(['Dataset', name])
            w.writerow(['Shape'] + list(dset.shape))
            if len(dset.shape) == 0:
                w.writerow([dset[()]])
            elif len(dset.shape) == 1:
                for value in dset:
                    w.writerow([value])
            elif len(dset.shape) == 2:
                for row in dset:
                    w.writerow([value for value in row])
            elif len(dset.shape) == 3:
                for array in dset:
                    l = []
                    for col in array.T:
                        for value in col:
                            l.append(value)
                        l.append('')
                    del l[-1]
                    w.writerow(l)
            else:
                w.writerow(['Skipped because ndim=%i>3' % len(dset.shape)])
            w.writerow([])