Inspect and query a database
Find labels, inspect scenarios and retrieve the matrices you need.
Start with the packaged IOT; use your parsed db in the same calls.
import mario
db = mario.load_test("IOT")
sectors = db.get_index("Sector")
production = db.query("X", scenarios="baseline")
Result · sectors is a list of native labels; production is a
pandas DataFrame indexed by region and sector.
Sets, labels and scenarios#
Labels and sets
db.sets lists the sets. db.get_index("all") returns their members.
Use db.search("Agr") to find labels without knowing their exact spelling.
Scenarios and matrices
db.scenarios lists the scenarios.
db.list_matrices(scenario="baseline") shows what is stored.
db.available_matrices() lists quantities the runtime can resolve.
Read data#
Z = db.Z # Baseline transactions.
e = db.query("e") # Calculate if missing.
selected = Z.loc[("Reg1", "Sector", "Agriculture")]
Dotted access and query() can trigger a calculation. They are more than
lookups of already stored matrices. See Calculate matrices for control
over requested targets and scenarios.
SUTs: activities and commodities
sut = mario.load_test("SUT")
activities = sut.get_index("Activity")
commodities = sut.get_index("Commodity")
use = sut.query("U")
commodity_output = sut.query("Xc")
The inspection pattern stays the same; SUTs have separate activity and commodity sets and split matrix blocks. See Supply and Use Tables.
BONSAI and other regional classifications
When membership varies by region, get_index() returns
{region: [members]}. Ask for one region or the union explicitly:
local = db.get_index("Sector", region="IT")
union = db.get_index("Sector", flat=True)
These calls require a database containing IT. A label in the union need
not exist in every region. search() accepts the same selectors.
Continue with named groups, classification concordances or exporting your model.