Work with your custom database#
This notebook shows the smallest end-to-end workflow to create a MARIO-readable Excel template and parse it back into a database object. The examples use compact IOT and SUT structures whose labels mirror the packaged MARIO test tables, so the focus stays on the template format rather than on the data values.
[ ]:
import mario
Write an IOT template#
The first example generates a minimal IOT workbook with regions, sectors, final demand, factors, and satellite accounts already declared.
[ ]:
mario.write_parse_template(
"/path/to/custom_iot_template.xlsx",
table="IOT",
sets={
"regions": ["Reg1", "Reg2"],
"sectors": ["Agriculture", "Services"],
"final demand": ["Final demand"],
"factors": ["Taxes", "Wages"],
"satellites": ["CO2"],
},
units={
"sectors": "M EUR",
"factors": "M EUR",
"satellites": "kg",
},
)
INFO Metadata: initialized by dataframes.
INFO Resolver: resolving z for baseline.
INFO Resolver: trying z via formula build_iot_z_from_Z_X.
INFO Resolver: resolved z via formula build_iot_z_from_Z_X.
INFO Resolver: resolving v for baseline.
INFO Resolver: trying v via formula build_iot_v_from_V_X.
INFO Resolver: resolved v via formula build_iot_v_from_V_X.
INFO Resolver: resolving e for baseline.
INFO Resolver: trying e via formula build_iot_e_from_E_X.
INFO Resolver: resolved e via formula build_iot_e_from_E_X.
'/Users/lorenzorinaldi/Documents/GitHub/MARIO/mario/test/supporting_files/custom_iot_template.xlsx'
The figure below shows the structure of the Excel template that MARIO writes for you.

Parse the template back#
After the workbook is filled, parse_from_excel() reads it back and builds a database object with the sets and matrices implied by the template. In this example the numeric cells are empty, so MARIO reads them as zeros. That is still enough to validate the structure before filling real data.
Download the packaged example workbooks#
The exact workbooks used in this notebook are available here:
[ ]:
db = mario.parse_from_excel(
path="/path/to/custom_iot_filled.xlsx",
table="IOT",
mode="flows",
)
db.get_index("all")
INFO Parser: excel reading IOT flows from /Users/lorenzorinaldi/Documents/GitHub/MARIO/mario/test/supporting_files/custom_iot_filled.xlsx.
INFO Parser: state payload ready with 6 canonical blocks.
INFO Parser: excel state ready for IOT.
INFO Metadata: initialized.
{'Factor of production': ['Taxes', 'Wages'],
'Satellite account': ['CO2'],
'Consumption category': ['Final demand'],
'Region': ['Reg1', 'Reg2'],
'Sector': ['Agriculture', 'Services']}
[4]:
db.Z
[4]:
| Region | Reg1 | Reg2 | |||
|---|---|---|---|---|---|
| Sector | Agriculture | Services | Agriculture | Services | |
| Region | Sector | ||||
| Reg1 | Agriculture | 1.0 | 1.0 | 1.0 | 1.0 |
| Services | 1.0 | 1.0 | 1.0 | 1.0 | |
| Reg2 | Agriculture | 1.0 | 1.0 | 1.0 | 1.0 |
| Services | 1.0 | 1.0 | 1.0 | 1.0 | |
[5]:
db.Y
[5]:
| Region | Reg1 | Reg2 | |
|---|---|---|---|
| Consumption category | Final demand | Final demand | |
| Region | Sector | ||
| Reg1 | Agriculture | 4.0 | 4.0 |
| Services | 4.0 | 4.0 | |
| Reg2 | Agriculture | 4.0 | 4.0 |
| Services | 4.0 | 4.0 |
Write a SUT template#
The same pattern works for SUT tables: here the template is defined with activities and commodities instead of a single sector set, and then parsed back in the same way.
[ ]:
mario.write_parse_template(
path="/path/to/custom_sut_template.xlsx",
table="SUT",
sets={
"regions": ["Region 1"],
"activities": ["Manufacturing", "Services"],
"commodities": ["Goods", "Services"],
"final demand": ["Final demand"],
"factors": ["Taxes"],
"satellites": ["CO2"],
},
units={
"activities": "M EUR",
"commodities": "M EUR",
"factors": "M EUR",
"satellites": "kg",
},
)
sut = mario.parse_from_excel(
path="/path/to/custom_sut_filled.xlsx",
table="SUT",
mode="flows",
)
sut.get_index("all")
INFO Metadata: initialized by dataframes.
INFO Resolver: resolving z for baseline.
INFO Resolver: trying z via concat.
INFO Resolver: resolved z via concat.
INFO Resolver: resolving v for baseline.
INFO Resolver: trying v via concat.
INFO Resolver: resolved v via concat.
INFO Resolver: resolving e for baseline.
INFO Resolver: trying e via concat.
INFO Resolver: resolved e via concat.
INFO Parser: excel reading SUT flows from /Users/lorenzorinaldi/Documents/GitHub/MARIO/mario/test/supporting_files/custom_sut_filled.xlsx.
INFO Parser: state payload ready with 10 canonical blocks.
INFO Parser: excel state ready for SUT.
INFO Metadata: initialized.
{'Activity': ['Manufacturing', 'Services'],
'Commodity': ['Goods', 'Services'],
'Factor of production': ['Taxes'],
'Satellite account': ['CO2'],
'Consumption category': ['Final demand'],
'Region': ['Region 1']}