Metadata and change recording¶
Each pymrio core system object contains a field ‘meta’ which stores meta data as well as changes to the MRIO system. This data is stored as json file in the root of a saved MRIO data and accessible through the attribute ‘.meta’:
In [1]:
import pymrio
io = pymrio.load_test()
In [2]:
io.meta
Out[2]:
Description: test mrio for pymrio
MRIO Name: testmrio
System: pxp
Version: v1
File: /home/konstans/proj/pymrio/pymrio/mrio_models/test_mrio/metadata.json
History:
20180111 11:02:58 - FILEIO - Load test_mrio from /home/konstans/proj/pymrio/pymrio/mrio_models/test_mrio
20171024 12:11:47 - FILEIO - Created metadata file ../test_mrio/metadata.json
In [3]:
io.meta('Loaded the pymrio test sytem')
Description: test mrio for pymrio
MRIO Name: testmrio
System: pxp
Version: v1
File: /home/konstans/proj/pymrio/pymrio/mrio_models/test_mrio/metadata.json
History:
20180111 11:02:58 - NOTE - Loaded the pymrio test sytem
20180111 11:02:58 - FILEIO - Load test_mrio from /home/konstans/proj/pymrio/pymrio/mrio_models/test_mrio
20171024 12:11:47 - FILEIO - Created metadata file ../test_mrio/metadata.json
We can now do several steps to modify the system, for example:
In [4]:
io.calc_all()
io.aggregate(region_agg = 'global')
Out[4]:
<pymrio.core.mriosystem.IOSystem at 0x7fc4f1a4d518>
In [5]:
io.meta
Out[5]:
Description: test mrio for pymrio
MRIO Name: testmrio
System: pxp
Version: v1
File: /home/konstans/proj/pymrio/pymrio/mrio_models/test_mrio/metadata.json
History:
20180111 11:03:02 - MODIFICATION - Calculating accounts for extension emissions
20180111 11:03:02 - MODIFICATION - Calculating accounts for extension factor_inputs
20180111 11:03:02 - MODIFICATION - Calculating aggregated final demand
20180111 11:03:02 - MODIFICATION - Aggregate extensions...
20180111 11:03:02 - MODIFICATION - Aggregate extensions...
20180111 11:03:02 - MODIFICATION - Aggregate population vector
20180111 11:03:02 - MODIFICATION - Aggregate industry output x
20180111 11:03:02 - MODIFICATION - Aggregate transaction matrix Z
20180111 11:03:02 - MODIFICATION - Aggregate final demand y
20180111 11:03:02 - MODIFICATION - Calculating accounts for extension emissions
... (more lines in history)
Notes can added at any time:
In [6]:
io.meta.note('First round of calculations finished')
In [7]:
io.meta
Out[7]:
Description: test mrio for pymrio
MRIO Name: testmrio
System: pxp
Version: v1
File: /home/konstans/proj/pymrio/pymrio/mrio_models/test_mrio/metadata.json
History:
20180111 11:03:09 - NOTE - First round of calculations finished
20180111 11:03:02 - MODIFICATION - Calculating accounts for extension emissions
20180111 11:03:02 - MODIFICATION - Calculating accounts for extension factor_inputs
20180111 11:03:02 - MODIFICATION - Calculating aggregated final demand
20180111 11:03:02 - MODIFICATION - Aggregate extensions...
20180111 11:03:02 - MODIFICATION - Aggregate extensions...
20180111 11:03:02 - MODIFICATION - Aggregate population vector
20180111 11:03:02 - MODIFICATION - Aggregate industry output x
20180111 11:03:02 - MODIFICATION - Aggregate transaction matrix Z
20180111 11:03:02 - MODIFICATION - Aggregate final demand y
... (more lines in history)
In addition, all file io operations are recorde in the meta data:
In [8]:
io.save_all('/tmp/foo')
Out[8]:
<pymrio.core.mriosystem.IOSystem at 0x7fc4f1a4d518>
In [9]:
io_new = pymrio.load_all('/tmp/foo')
In [10]:
io_new.meta
Out[10]:
Description: test mrio for pymrio
MRIO Name: testmrio
System: pxp
Version: v1
File: /tmp/foo/metadata.json
History:
20180111 11:03:12 - FILEIO - Added satellite account from /tmp/foo/factor_inputs
20180111 11:03:12 - FILEIO - Added satellite account from /tmp/foo/emissions
20180111 11:03:12 - FILEIO - Loaded IO system from /tmp/foo
20180111 11:03:12 - FILEIO - Saved testmrio to /tmp/foo
20180111 11:03:09 - NOTE - First round of calculations finished
20180111 11:03:02 - MODIFICATION - Calculating accounts for extension emissions
20180111 11:03:02 - MODIFICATION - Calculating accounts for extension factor_inputs
20180111 11:03:02 - MODIFICATION - Calculating aggregated final demand
20180111 11:03:02 - MODIFICATION - Aggregate extensions...
20180111 11:03:02 - MODIFICATION - Aggregate extensions...
... (more lines in history)
The top level meta data can be changed as well. These changes will also be recorded in the history:
In [11]:
io_new.meta.change_meta('Version', 'v2')
In [12]:
io_new.meta
Out[12]:
Description: test mrio for pymrio
MRIO Name: testmrio
System: pxp
Version: v2
File: /tmp/foo/metadata.json
History:
20180111 11:03:13 - METADATA_CHANGE - Changed parameter "version" from "v1" to "v2"
20180111 11:03:12 - FILEIO - Added satellite account from /tmp/foo/factor_inputs
20180111 11:03:12 - FILEIO - Added satellite account from /tmp/foo/emissions
20180111 11:03:12 - FILEIO - Loaded IO system from /tmp/foo
20180111 11:03:12 - FILEIO - Saved testmrio to /tmp/foo
20180111 11:03:09 - NOTE - First round of calculations finished
20180111 11:03:02 - MODIFICATION - Calculating accounts for extension emissions
20180111 11:03:02 - MODIFICATION - Calculating accounts for extension factor_inputs
20180111 11:03:02 - MODIFICATION - Calculating aggregated final demand
20180111 11:03:02 - MODIFICATION - Aggregate extensions...
... (more lines in history)
To get the full history list, use:
In [13]:
io_new.meta.history
Out[13]:
['20180111 11:03:13 - METADATA_CHANGE - Changed parameter "version" from "v1" to "v2"',
'20180111 11:03:12 - FILEIO - Added satellite account from /tmp/foo/factor_inputs',
'20180111 11:03:12 - FILEIO - Added satellite account from /tmp/foo/emissions',
'20180111 11:03:12 - FILEIO - Loaded IO system from /tmp/foo',
'20180111 11:03:12 - FILEIO - Saved testmrio to /tmp/foo',
'20180111 11:03:09 - NOTE - First round of calculations finished',
'20180111 11:03:02 - MODIFICATION - Calculating accounts for extension emissions',
'20180111 11:03:02 - MODIFICATION - Calculating accounts for extension factor_inputs',
'20180111 11:03:02 - MODIFICATION - Calculating aggregated final demand',
'20180111 11:03:02 - MODIFICATION - Aggregate extensions...',
'20180111 11:03:02 - MODIFICATION - Aggregate extensions...',
'20180111 11:03:02 - MODIFICATION - Aggregate population vector',
'20180111 11:03:02 - MODIFICATION - Aggregate industry output x',
'20180111 11:03:02 - MODIFICATION - Aggregate transaction matrix Z',
'20180111 11:03:02 - MODIFICATION - Aggregate final demand y',
'20180111 11:03:02 - MODIFICATION - Calculating accounts for extension emissions',
'20180111 11:03:02 - MODIFICATION - Calculating accounts for extension factor_inputs',
'20180111 11:03:02 - MODIFICATION - Calculating aggregated final demand',
'20180111 11:03:02 - MODIFICATION - Leontief matrix L calculated',
'20180111 11:03:02 - MODIFICATION - Coefficient matrix A calculated',
'20180111 11:03:02 - MODIFICATION - Industry output x calculated',
'20180111 11:02:58 - NOTE - Loaded the pymrio test sytem',
'20180111 11:02:58 - FILEIO - Load test_mrio from /home/konstans/proj/pymrio/pymrio/mrio_models/test_mrio',
'20171024 12:11:47 - FILEIO - Created metadata file ../test_mrio/metadata.json']
This can be restricted to one of the history types by:
In [14]:
io_new.meta.modification_history
Out[14]:
['20180111 11:03:02 - MODIFICATION - Calculating accounts for extension emissions',
'20180111 11:03:02 - MODIFICATION - Calculating accounts for extension factor_inputs',
'20180111 11:03:02 - MODIFICATION - Calculating aggregated final demand',
'20180111 11:03:02 - MODIFICATION - Aggregate extensions...',
'20180111 11:03:02 - MODIFICATION - Aggregate extensions...',
'20180111 11:03:02 - MODIFICATION - Aggregate population vector',
'20180111 11:03:02 - MODIFICATION - Aggregate industry output x',
'20180111 11:03:02 - MODIFICATION - Aggregate transaction matrix Z',
'20180111 11:03:02 - MODIFICATION - Aggregate final demand y',
'20180111 11:03:02 - MODIFICATION - Calculating accounts for extension emissions',
'20180111 11:03:02 - MODIFICATION - Calculating accounts for extension factor_inputs',
'20180111 11:03:02 - MODIFICATION - Calculating aggregated final demand',
'20180111 11:03:02 - MODIFICATION - Leontief matrix L calculated',
'20180111 11:03:02 - MODIFICATION - Coefficient matrix A calculated',
'20180111 11:03:02 - MODIFICATION - Industry output x calculated']
or
In [15]:
io_new.meta.note_history
Out[15]:
['20180111 11:03:09 - NOTE - First round of calculations finished',
'20180111 11:02:58 - NOTE - Loaded the pymrio test sytem']