2.4 KiB
2.4 KiB
jupytext
jupytext | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
Quickstart
Installation
pip install qubed
Usage
Make an uncompressed qube:
from qubed import Qube
q = Qube.from_dict({
"class=od" : {
"expver=0001": {"param=1":{}, "param=2":{}},
"expver=0002": {"param=1":{}, "param=2":{}},
},
"class=rd" : {
"expver=0001": {"param=1":{}, "param=2":{}, "param=3":{}},
"expver=0002": {"param=1":{}, "param=2":{}},
},
})
print(f"{q.n_leaves = }, {q.n_nodes = }")
q
Compress it:
cq = q.compress()
assert cq.n_leaves == q.n_leaves
print(f"{cq.n_leaves = }, {cq.n_nodes = }")
cq
Load a larger example qube (requires source checkout):
import requests
qube_json = requests.get("https://github.com/ecmwf/qubed/raw/refs/heads/main/tests/example_qubes/climate_dt.json").json()
climate_dt = Qube.from_json(qube_json)
# Using the html or print methods is optional but lets you specify things like the depth of the tree to display.
print(f"{climate_dt.n_leaves = }, {climate_dt.n_nodes = }")
climate_dt.html(depth=1) # Limit how much is open initially, click leave to see more.
Select a subset of the tree:
climate_dt.select({
"activity": "scenariomip"
}).html(depth=1)
Use .span("key")
to get the set of possibles values for a key, note this includes anywhere this key appears in the tree.
climate_dt.span("activity")
Use .axes()
to get the span of every key in one go.
axes = climate_dt.axes()
for key, values in axes.items():
print(f"{key} : {list(values)[:10]}")