Changing mario settings¶
mario has the capability of being flexible in the definition of some definitions in an instance. This feature, allows the users to customize mario, to their specfici nomenclature or naming convensions and preferences.
For example, the dimenssion of regions in a table, by default, is called “Region” in mario, but you might prefer to call it “Country”. Or, the technical coefficient matrix in mario is called “z”, but as in the literature, “A” is mainly used for the technical coefficient, you might change this in mario, without impacting the performance of the code.
This can be done thorugh mario settings module functionalities as described below:
from mario import upload_settings,download_settings,reset_settings
To change the default settings, you need to follow a specific structure, that is represented as a nested python dict or a can be represented as a yaml file. To access the default settings, you can use the ‘download_settings’ function:
settings = download_settings()
settings
{'index': {'a': 'Activity',
'c': 'Commodity',
'f': 'Factor of production',
'k': 'Satellite account',
'n': 'Consumption category',
'r': 'Region',
's': 'Sector'},
'nomenclature': {'E': 'E',
'EY': 'EY',
'F': 'F',
'M': 'M',
'S': 'S',
'U': 'U',
'V': 'V',
'X': 'X',
'Y': 'Y',
'Z': 'Z',
'b': 'b',
'e': 'e',
'f': 'f',
'g': 'g',
'm': 'm',
'p': 'p',
's': 's',
'u': 'u',
'v': 'v',
'w': 'w',
'y': 'y',
'z': 'z'}}
If you wish to download the yaml file and modify the yaml file, you can path the directory where you want to download the yaml file like:
settings = download_settings("path to download")
Now lets assume we want to implement two changes on the settings:
Changing “Region” to “Country” for indexing
Using “A” for the technical coefficient matrix instead of “z”
Chaning the index¶
# current setting
settings["index"]["r"]
'Region'
# Changing setting
settings["index"]["r"] = "Country"
# new setting
settings["index"]["r"]
'Country'
Changing the matrix nomenclature¶
for this, you need to change the var of the specific key in nomenclature. Please refer to mario’s terminology (https://mario-suite.readthedocs.io/en/latest/terminology.html)
# current settings
settings["nomenclature"]["z"]
'z'
# Changing settings
settings["nomenclature"]["z"] = "A"
# New settings
settings["nomenclature"]["z"]
'A'
Once your changes are ready, you can upload them to mario settings using the “upload_settings” function. You can pass the python dictionary or the path to the yaml file:
upload_settings(settings)
Now your changes are implemented into the settings. To make sure, you can download the settings again and check the status:
download_settings()
{'index': {'a': 'Activity',
'c': 'Commodity',
'f': 'Factor of production',
'k': 'Satellite account',
'n': 'Consumption category',
'r': 'Country',
's': 'Sector'},
'nomenclature': {'E': 'E',
'EY': 'EY',
'F': 'F',
'M': 'M',
'S': 'S',
'U': 'U',
'V': 'V',
'X': 'X',
'Y': 'Y',
'Z': 'Z',
'b': 'b',
'e': 'e',
'f': 'f',
'g': 'g',
'm': 'm',
'p': 'p',
's': 's',
'u': 'u',
'v': 'v',
'w': 'w',
'y': 'y',
'z': 'A'}}
Warning:
mario needs to reload some of its modules to force the software to use the new settings everywhere. in some cases, the changes might not be syncronized everywhere. To secure the full syncronization, it is advised to close your interactive session and reload mario after you implemented your changes.
Now we can check how things are changed. Let’s import a mario example:
from mario import load_test
example = load_test("IOT")
example
name = IOT test
table = IOT
scenarios = ['baseline']
Factor of production = 3
Satellite account = 4
Consumption category = 1
Country = 2
Sector = 6
At first, you can notice that, the regions are now represent with “Country” keyword in the database. that can be also seen when using the get_index funciton:
example.get_index("Country")
['RoW', 'Italy']
Now if you need to take the technical coefficient matrix, you need to request “A” instead of “z”:
example.A
Country | Italy | RoW | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Level | Sector | Sector | ||||||||||||
Item | Agriculture | Construction | Manufacturing | Mining | Services | Transport | Agriculture | Construction | Manufacturing | Mining | Services | Transport | ||
Country | Level | Item | ||||||||||||
Italy | Sector | Agriculture | 0.035106 | 0.000653 | 0.021014 | 0.000083 | 0.001676 | 0.000288 | 5.048324e-05 | 0.000002 | 0.000024 | 0.000001 | 0.000005 | 0.000002 |
Construction | 0.012325 | 0.194778 | 0.004384 | 0.005575 | 0.008825 | 0.002324 | 7.457826e-07 | 0.000019 | 0.000001 | 0.000002 | 0.000004 | 0.000002 | ||
Manufacturing | 0.132174 | 0.237906 | 0.240282 | 0.072057 | 0.049447 | 0.055996 | 5.809324e-04 | 0.001911 | 0.002514 | 0.000878 | 0.000415 | 0.000788 | ||
Mining | 0.000580 | 0.007814 | 0.004607 | 0.043918 | 0.001428 | 0.000343 | 2.853587e-06 | 0.000019 | 0.000025 | 0.000021 | 0.000002 | 0.000001 | ||
Services | 0.137336 | 0.133450 | 0.206065 | 0.248969 | 0.231043 | 0.183065 | 1.207210e-04 | 0.000200 | 0.000249 | 0.000153 | 0.000322 | 0.000281 | ||
Transport | 0.027626 | 0.016173 | 0.050787 | 0.108437 | 0.034471 | 0.248808 | 2.007685e-05 | 0.000028 | 0.000043 | 0.000034 | 0.000035 | 0.000319 | ||
RoW | Sector | Agriculture | 0.029250 | 0.001083 | 0.004822 | 0.000277 | 0.000723 | 0.000153 | 1.081939e-01 | 0.006410 | 0.053775 | 0.003453 | 0.005811 | 0.008671 |
Construction | 0.000110 | 0.003467 | 0.000326 | 0.000257 | 0.000102 | 0.000055 | 3.635630e-03 | 0.068389 | 0.002878 | 0.012448 | 0.011287 | 0.004867 | ||
Manufacturing | 0.018519 | 0.025394 | 0.112831 | 0.013736 | 0.011612 | 0.009333 | 1.190623e-01 | 0.312903 | 0.431001 | 0.101473 | 0.068652 | 0.112907 | ||
Mining | 0.000631 | 0.000609 | 0.037504 | 0.027916 | 0.004308 | 0.000780 | 2.203056e-03 | 0.011217 | 0.047095 | 0.060872 | 0.003256 | 0.002639 | ||
Services | 0.011629 | 0.010859 | 0.019097 | 0.023009 | 0.019389 | 0.012611 | 1.565488e-01 | 0.151628 | 0.154824 | 0.156603 | 0.258929 | 0.162667 | ||
Transport | 0.001366 | 0.000667 | 0.003838 | 0.008621 | 0.003904 | 0.024286 | 2.019775e-02 | 0.042909 | 0.025625 | 0.037014 | 0.023152 | 0.163810 |
It’s Awesome! Isn’t it?
Reseting to default settings¶
If you wish to comeback to the original mario settings, you need to use the reset_settings funciton:
reset_settings()
⚠️ warning:
if you make a mistake in your custom settings, mario will switch to the default settings. Let’s take an example by removing one of the essential index elements in the custom setting:
del settings["index"]["a"]
settings
{'index': {'c': 'Commodity',
'f': 'Factor of production',
'k': 'Satellite account',
'n': 'Consumption category',
'r': 'Country',
's': 'Sector'},
'nomenclature': {'E': 'E',
'EY': 'EY',
'F': 'F',
'M': 'M',
'S': 'S',
'U': 'U',
'V': 'V',
'X': 'X',
'Y': 'Y',
'Z': 'Z',
'b': 'b',
'e': 'e',
'f': 'f',
'g': 'g',
'm': 'm',
'p': 'p',
's': 's',
'u': 'u',
'v': 'v',
'w': 'w',
'y': 'y',
'z': 'A'}}
upload_settings(settings)
The user settings is not correctly build for index, so the original mario settings are used.
# Lets get back to the original settings to continue with the tests
reset_settings()
Advanced use cases of settings¶
If you wish to go through mario code and make some changes in the software, you need to properly use the enums created for these naming convensions. Everytime that mario is loaded, it is reading the configuration file, and create two specific classes for naming conventions using Index and Nomenclature:
from mario import Index,Nomenclature
idx = Index()
nom = Nomenclature()
These two objects will carry on the naming convensions, so it can be used when coding in mario, to encapsulate the coding and naming convensions. Let’s take a look to these objects:
idx.r
'Region'
idx.a
'Activity'
nom.z
'z'
nom.Z
'Z'
As you can see, instead of using direct variables in mario, we rely on these two clases to get the user the opprotunity to change the settings wihtout any troubles. Inside mario, these two classes are extensively used for these purpose. If you check the core code, in constants modlues of mario, you will find two variabls called **”_MASTER_INDEX”* and *”_ENUM”* which are instances of the *“Index”** and “Nomenclautre” respectively:
from mario.tools.constants import _MASTER_INDEX,_ENUM
_MASTER_INDEX["r"] # This is equal to _MASTER_INDEX.r
'Region'
Using these two instances, all over the software, we encapsulated the code 👩💻 and the naming convensions.