{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Metadata and change recording" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**DEPRECATED**: this will be removed and changed to loguru soon" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "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':" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import pymrio\n", "\n", "io = pymrio.load_test()" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Description: test mrio for pymrio\n", "MRIO Name: testmrio\n", "System: pxp\n", "Version: v1\n", "File: /home/konstans/proj/pymrio/pymrio/mrio_models/test_mrio/metadata.json\n", "History:\n", "20210224 10:41:58 - FILEIO - Load test_mrio from /home/konstans/proj/pymrio/pymrio/mrio_models/test_mrio\n", "20171024 12:11:47 - FILEIO - Created metadata file ../test_mrio/metadata.json" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "io.meta" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Description: test mrio for pymrio\n", "MRIO Name: testmrio\n", "System: pxp\n", "Version: v1\n", "File: /home/konstans/proj/pymrio/pymrio/mrio_models/test_mrio/metadata.json\n", "History:\n", "20210224 10:41:58 - NOTE - Loaded the pymrio test sytem\n", "20210224 10:41:58 - FILEIO - Load test_mrio from /home/konstans/proj/pymrio/pymrio/mrio_models/test_mrio\n", "20171024 12:11:47 - FILEIO - Created metadata file ../test_mrio/metadata.json\n" ] } ], "source": [ "io.meta(\"Loaded the pymrio test sytem\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can now do several steps to modify the system, for example:" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "io.calc_all()\n", "io.aggregate(region_agg=\"global\")" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Description: test mrio for pymrio\n", "MRIO Name: testmrio\n", "System: pxp\n", "Version: v1\n", "File: /home/konstans/proj/pymrio/pymrio/mrio_models/test_mrio/metadata.json\n", "History:\n", "20210224 10:41:58 - MODIFICATION - Calculating accounts for extension emissions\n", "20210224 10:41:58 - MODIFICATION - Calculating accounts for extension factor_inputs\n", "20210224 10:41:58 - MODIFICATION - Aggregate extensions...\n", "20210224 10:41:58 - MODIFICATION - Aggregate extensions...\n", "20210224 10:41:58 - MODIFICATION - Aggregate population vector\n", "20210224 10:41:58 - MODIFICATION - Aggregate industry output x\n", "20210224 10:41:58 - MODIFICATION - Aggregate transaction matrix Z\n", "20210224 10:41:58 - MODIFICATION - Aggregate final demand y\n", "20210224 10:41:58 - MODIFICATION - Reset to absolute flows\n", "20210224 10:41:58 - MODIFICATION - Calculating accounts for extension emissions\n", " ... (more lines in history)" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "io.meta" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Notes can added at any time:" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "io.meta.note(\"First round of calculations finished\")" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Description: test mrio for pymrio\n", "MRIO Name: testmrio\n", "System: pxp\n", "Version: v1\n", "File: /home/konstans/proj/pymrio/pymrio/mrio_models/test_mrio/metadata.json\n", "History:\n", "20210224 10:41:58 - NOTE - First round of calculations finished\n", "20210224 10:41:58 - MODIFICATION - Calculating accounts for extension emissions\n", "20210224 10:41:58 - MODIFICATION - Calculating accounts for extension factor_inputs\n", "20210224 10:41:58 - MODIFICATION - Aggregate extensions...\n", "20210224 10:41:58 - MODIFICATION - Aggregate extensions...\n", "20210224 10:41:58 - MODIFICATION - Aggregate population vector\n", "20210224 10:41:58 - MODIFICATION - Aggregate industry output x\n", "20210224 10:41:58 - MODIFICATION - Aggregate transaction matrix Z\n", "20210224 10:41:58 - MODIFICATION - Aggregate final demand y\n", "20210224 10:41:58 - MODIFICATION - Reset to absolute flows\n", " ... (more lines in history)" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "io.meta" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In addition, all file io operations are recorde in the meta data:" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "io.save_all(\"/tmp/foo\")" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "io_new = pymrio.load_all(\"/tmp/foo\")" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Description: test mrio for pymrio\n", "MRIO Name: testmrio\n", "System: pxp\n", "Version: v1\n", "File: /tmp/foo/metadata.json\n", "History:\n", "20210224 10:41:58 - FILEIO - Added satellite account from /tmp/foo/factor_inputs\n", "20210224 10:41:58 - FILEIO - Added satellite account from /tmp/foo/emissions\n", "20210224 10:41:58 - FILEIO - Loaded IO system from /tmp/foo\n", "20210224 10:41:58 - FILEIO - Saved testmrio to /tmp/foo\n", "20210224 10:41:58 - NOTE - First round of calculations finished\n", "20210224 10:41:58 - MODIFICATION - Calculating accounts for extension emissions\n", "20210224 10:41:58 - MODIFICATION - Calculating accounts for extension factor_inputs\n", "20210224 10:41:58 - MODIFICATION - Aggregate extensions...\n", "20210224 10:41:58 - MODIFICATION - Aggregate extensions...\n", "20210224 10:41:58 - MODIFICATION - Aggregate population vector\n", " ... (more lines in history)" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "io_new.meta" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The top level meta data can be changed as well. These changes will also be recorded in the history:" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [], "source": [ "io_new.meta.change_meta(\"Version\", \"v2\")" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Description: test mrio for pymrio\n", "MRIO Name: testmrio\n", "System: pxp\n", "Version: v2\n", "File: /tmp/foo/metadata.json\n", "History:\n", "20210224 10:41:58 - METADATA_CHANGE - Changed parameter \"version\" from \"v1\" to \"v2\"\n", "20210224 10:41:58 - FILEIO - Added satellite account from /tmp/foo/factor_inputs\n", "20210224 10:41:58 - FILEIO - Added satellite account from /tmp/foo/emissions\n", "20210224 10:41:58 - FILEIO - Loaded IO system from /tmp/foo\n", "20210224 10:41:58 - FILEIO - Saved testmrio to /tmp/foo\n", "20210224 10:41:58 - NOTE - First round of calculations finished\n", "20210224 10:41:58 - MODIFICATION - Calculating accounts for extension emissions\n", "20210224 10:41:58 - MODIFICATION - Calculating accounts for extension factor_inputs\n", "20210224 10:41:58 - MODIFICATION - Aggregate extensions...\n", "20210224 10:41:58 - MODIFICATION - Aggregate extensions...\n", " ... (more lines in history)" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "io_new.meta" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To get the full history list, use:" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['20210224 10:41:58 - METADATA_CHANGE - Changed parameter \"version\" from \"v1\" to \"v2\"',\n", " '20210224 10:41:58 - FILEIO - Added satellite account from /tmp/foo/factor_inputs',\n", " '20210224 10:41:58 - FILEIO - Added satellite account from /tmp/foo/emissions',\n", " '20210224 10:41:58 - FILEIO - Loaded IO system from /tmp/foo',\n", " '20210224 10:41:58 - FILEIO - Saved testmrio to /tmp/foo',\n", " '20210224 10:41:58 - NOTE - First round of calculations finished',\n", " '20210224 10:41:58 - MODIFICATION - Calculating accounts for extension emissions',\n", " '20210224 10:41:58 - MODIFICATION - Calculating accounts for extension factor_inputs',\n", " '20210224 10:41:58 - MODIFICATION - Aggregate extensions...',\n", " '20210224 10:41:58 - MODIFICATION - Aggregate extensions...',\n", " '20210224 10:41:58 - MODIFICATION - Aggregate population vector',\n", " '20210224 10:41:58 - MODIFICATION - Aggregate industry output x',\n", " '20210224 10:41:58 - MODIFICATION - Aggregate transaction matrix Z',\n", " '20210224 10:41:58 - MODIFICATION - Aggregate final demand y',\n", " '20210224 10:41:58 - MODIFICATION - Reset to absolute flows',\n", " '20210224 10:41:58 - MODIFICATION - Calculating accounts for extension emissions',\n", " '20210224 10:41:58 - MODIFICATION - Calculating accounts for extension factor_inputs',\n", " '20210224 10:41:58 - MODIFICATION - Leontief matrix L calculated',\n", " '20210224 10:41:58 - MODIFICATION - Coefficient matrix A calculated',\n", " '20210224 10:41:58 - MODIFICATION - Industry output x calculated',\n", " '20210224 10:41:58 - NOTE - Loaded the pymrio test sytem',\n", " '20210224 10:41:58 - FILEIO - Load test_mrio from /home/konstans/proj/pymrio/pymrio/mrio_models/test_mrio',\n", " '20171024 12:11:47 - FILEIO - Created metadata file ../test_mrio/metadata.json']" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "io_new.meta.history" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This can be restricted to one of the history types by:" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['20210224 10:41:58 - MODIFICATION - Calculating accounts for extension emissions',\n", " '20210224 10:41:58 - MODIFICATION - Calculating accounts for extension factor_inputs',\n", " '20210224 10:41:58 - MODIFICATION - Aggregate extensions...',\n", " '20210224 10:41:58 - MODIFICATION - Aggregate extensions...',\n", " '20210224 10:41:58 - MODIFICATION - Aggregate population vector',\n", " '20210224 10:41:58 - MODIFICATION - Aggregate industry output x',\n", " '20210224 10:41:58 - MODIFICATION - Aggregate transaction matrix Z',\n", " '20210224 10:41:58 - MODIFICATION - Aggregate final demand y',\n", " '20210224 10:41:58 - MODIFICATION - Reset to absolute flows',\n", " '20210224 10:41:58 - MODIFICATION - Calculating accounts for extension emissions',\n", " '20210224 10:41:58 - MODIFICATION - Calculating accounts for extension factor_inputs',\n", " '20210224 10:41:58 - MODIFICATION - Leontief matrix L calculated',\n", " '20210224 10:41:58 - MODIFICATION - Coefficient matrix A calculated',\n", " '20210224 10:41:58 - MODIFICATION - Industry output x calculated']" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "io_new.meta.modification_history" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "or" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['20210224 10:41:58 - NOTE - First round of calculations finished',\n", " '20210224 10:41:58 - NOTE - Loaded the pymrio test sytem']" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "io_new.meta.note_history" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.12" } }, "nbformat": 4, "nbformat_minor": 4 }