|
14 | 14 |
|
15 | 15 | # --- 1. Creating and populating a TreeStore --- |
16 | 16 | print("--- 1. Creating and populating a TreeStore ---") |
17 | | -# Create a new TreeStore in write mode ('w') |
| 17 | +# Create a new TreeStore |
18 | 18 | with blosc2.TreeStore("my_experiment.b2z", mode="w") as ts: |
19 | 19 | # You can store numpy arrays, which are converted to blosc2.NDArray |
20 | | - ts["/group1/dataset1"] = np.arange(100) |
| 20 | + ts["/dataset0"] = np.arange(100) |
21 | 21 |
|
22 | | - # You can also store blosc2 arrays directly |
23 | | - ts["/group1/dataset2"] = blosc2.full((5, 5), fill_value=3.14) |
| 22 | + # Create a group with a dataset that can be a blosc2 NDArray |
| 23 | + ts["/group1/dataset1"] = blosc2.zeros((10,)) |
24 | 24 |
|
25 | | - # And external arrays with vlmeta attached (these are included internally too) |
26 | | - ext = blosc2.zeros((10,), urlpath="external_array.b2nd", mode="w") |
27 | | - ext.vlmeta["desc"] = "included array metadata" |
28 | | - ts["/group1/included_array"] = ext |
29 | | - |
30 | | - # Create another group with a dataset |
31 | | - ts["/group2/another_dataset"] = blosc2.zeros((10,)) |
| 25 | + # You can also store blosc2 arrays directly (vlmeta included) |
| 26 | + ext = blosc2.linspace(0, 1, 10_000, dtype=np.float32) |
| 27 | + ext.vlmeta["desc"] = "dataset2 metadata" |
| 28 | + ts["/group1/dataset2"] = ext |
32 | 29 | print("Created 'my_experiment.b2z' with initial data.\n") |
33 | 30 |
|
34 | 31 |
|
35 | 32 | # --- 2. Reading from a TreeStore --- |
36 | 33 | print("--- 2. Reading from a TreeStore ---") |
37 | | -# Open the TreeStore in read mode ('r') |
| 34 | +# Open the TreeStore in read-only mode ('r') |
38 | 35 | with blosc2.TreeStore("my_experiment.b2z", mode="r") as ts: |
39 | 36 | # Access a dataset |
40 | 37 | dataset1 = ts["/group1/dataset1"] |
41 | 38 | print("Dataset 1:", dataset1[:]) # Use [:] to decompress and get a NumPy array |
42 | 39 |
|
43 | | - # Access the external array that has been included internally |
44 | | - ext_array = ts["/group1/included_array"] |
45 | | - print("Included array:", ext_array[:]) |
46 | | - print("Included array metadata:", ext_array.vlmeta[:]) |
| 40 | + # Access the external array that has been stored internally |
| 41 | + dataset2 = ts["/group1/dataset2"] |
| 42 | + print("Dataset 2", dataset2[:]) |
| 43 | + print("Dataset 2 metadata:", dataset2.vlmeta[:]) |
47 | 44 |
|
48 | 45 | # List all paths in the store |
49 | 46 | print("Paths in TreeStore:", list(ts)) |
|
55 | 52 | with blosc2.TreeStore("my_experiment.b2z", mode="a") as ts: # 'a' for append/modify |
56 | 53 | # Add metadata to the root |
57 | 54 | ts.vlmeta["author"] = "The Blosc Team" |
58 | | - ts.vlmeta["date"] = "2025-07-10" |
| 55 | + ts.vlmeta["date"] = "2025-08-17" |
59 | 56 |
|
60 | 57 | # Add metadata to a group |
61 | 58 | ts["/group1"].vlmeta["description"] = "Data from the first run" |
|
0 commit comments