Skip to content

Commit 1f6d7b9

Browse files
committed
Updated blog example
1 parent 7079e7a commit 1f6d7b9

File tree

1 file changed

+14
-17
lines changed

1 file changed

+14
-17
lines changed

examples/tree-store-blog.py

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,36 +14,33 @@
1414

1515
# --- 1. Creating and populating a TreeStore ---
1616
print("--- 1. Creating and populating a TreeStore ---")
17-
# Create a new TreeStore in write mode ('w')
17+
# Create a new TreeStore
1818
with blosc2.TreeStore("my_experiment.b2z", mode="w") as ts:
1919
# You can store numpy arrays, which are converted to blosc2.NDArray
20-
ts["/group1/dataset1"] = np.arange(100)
20+
ts["/dataset0"] = np.arange(100)
2121

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,))
2424

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
3229
print("Created 'my_experiment.b2z' with initial data.\n")
3330

3431

3532
# --- 2. Reading from a TreeStore ---
3633
print("--- 2. Reading from a TreeStore ---")
37-
# Open the TreeStore in read mode ('r')
34+
# Open the TreeStore in read-only mode ('r')
3835
with blosc2.TreeStore("my_experiment.b2z", mode="r") as ts:
3936
# Access a dataset
4037
dataset1 = ts["/group1/dataset1"]
4138
print("Dataset 1:", dataset1[:]) # Use [:] to decompress and get a NumPy array
4239

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[:])
4744

4845
# List all paths in the store
4946
print("Paths in TreeStore:", list(ts))
@@ -55,7 +52,7 @@
5552
with blosc2.TreeStore("my_experiment.b2z", mode="a") as ts: # 'a' for append/modify
5653
# Add metadata to the root
5754
ts.vlmeta["author"] = "The Blosc Team"
58-
ts.vlmeta["date"] = "2025-07-10"
55+
ts.vlmeta["date"] = "2025-08-17"
5956

6057
# Add metadata to a group
6158
ts["/group1"].vlmeta["description"] = "Data from the first run"

0 commit comments

Comments
 (0)