File: split.py

package info (click to toggle)
pytables 3.10.2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 15,228 kB
  • sloc: ansic: 82,212; python: 65,296; cpp: 753; sh: 394; makefile: 100
file content (39 lines) | stat: -rw-r--r-- 993 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
"""Use the H5FD_SPLIT driver to store metadata and raw data in separate files.

In this example, we store the metadata file in the current directory and
the raw data file in a subdirectory.

"""

import errno
from pathlib import Path

import numpy as np

import tables as tb

FNAME = "split"
DRIVER = "H5FD_SPLIT"
RAW_DIR = Path(__file__).with_name("raw")
DRIVER_PROPS = {"driver_split_raw_ext": str(RAW_DIR / "%s-r.h5")}
DATA_SHAPE = (2, 10)


class FooBar(tb.IsDescription):
    tag = tb.StringCol(16)
    data = tb.Float32Col(shape=DATA_SHAPE)


try:
    RAW_DIR.mkdir()
except OSError as e:
    if e.errno == errno.EEXIST:
        pass
with tb.open_file(FNAME, mode="w", driver=DRIVER, **DRIVER_PROPS) as f:
    group = f.create_group("/", "foo", "foo desc")
    table = f.create_table(group, "bar", FooBar, "bar desc")
    for i in range(5):
        table.row["tag"] = "t%d" % i
        table.row["data"] = np.random.random_sample(DATA_SHAPE)
        table.row.append()
    table.flush()