Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 3.8 #6

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/doc/data/
61 changes: 61 additions & 0 deletions doc/0 - download exiobase.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"outputs": [],
"source": [
"import os"
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "code",
"execution_count": null,
"outputs": [],
"source": [
"import pymrio"
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "code",
"execution_count": null,
"outputs": [],
"source": [
"pymrio.download_exiobase3(\n",
" storage_folder=os.path.join(os.getcwd(), 'data/pymrio_downloads'),\n",
" years=['2022']\n",
")"
],
"metadata": {
"collapsed": false
}
}
],
"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.9.16"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
130 changes: 130 additions & 0 deletions doc/1 - run ecospold2matrix.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 5,
"outputs": [],
"source": [
"import os"
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "code",
"execution_count": 6,
"outputs": [],
"source": [
"import ecospold2matrix as e2m"
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"2023-01-24 14:39:28,778 - ecoinvent38 - INFO - Ecospold2Matrix Processing\n",
"2023-01-24 14:39:29,071 - ecoinvent38 - INFO - Current git commit: bcc307fdc19f968b06a7e5b6536ea5e9bcb2e914\n",
"2023-01-24 14:39:29,072 - ecoinvent38 - INFO - Project name: ecoinvent38\n",
"2023-01-24 14:39:29,073 - ecoinvent38 - INFO - Unit process and Master data directory: /home/lele/git/pylcaio_raw_raw/doc/data/ecoinvent 3.8_cutoff_ecoSpold02\n",
"2023-01-24 14:39:29,073 - ecoinvent38 - INFO - Data saved in: /home/lele/git/pylcaio_raw_raw/doc/data/ecospold2matrix_matrices/ecoinvent38\n",
"2023-01-24 14:39:29,074 - ecoinvent38 - INFO - Official rolled-up life cycle inventories in: /home/lele/git/pylcaio_raw_raw/doc/data/ecoinvent 3.8_cutoff_ecoSpold02/datasets\n",
"2023-01-24 14:39:29,075 - ecoinvent38 - INFO - Sign conventions changed to make waste flows positive\n",
"2023-01-24 14:39:29,075 - ecoinvent38 - INFO - Replace Not-a-Number instances with 0.0 in all matrices\n",
"2023-01-24 14:39:29,076 - ecoinvent38 - INFO - Pickle intermediate results to files\n",
"2023-01-24 14:39:29,076 - ecoinvent38 - INFO - Order processes based on: ISIC, activityName\n",
"2023-01-24 14:39:29,077 - ecoinvent38 - INFO - Order elementary exchanges based on: comp, name, subcomp\n",
"rm: cannot remove 'ecoinvent38_characterisation.db': No such file or directory\n",
"2023-01-24 14:39:29,138 - ecoinvent38 - WARNING - obs2char_subcomps constraints temporarily relaxed because not full recipe parsed\n"
]
}
],
"source": [
"parser = e2m.Ecospold2Matrix(\n",
" sys_dir=os.path.join(os.getcwd(), 'data/ecoinvent 3.8_cutoff_ecoSpold02'),\n",
" project_name='ecoinvent38',\n",
" out_dir=os.path.join(os.getcwd(), 'data/ecospold2matrix_matrices/ecoinvent38'),\n",
" lci_dir=os.path.join(os.getcwd(), 'data/ecoinvent 3.8_cutoff_ecoSpold02/datasets'),\n",
" positive_waste=True,\n",
" nan2null=True,\n",
" version_name='3.8',\n",
" characterisation_file=os.path.join(os.getcwd(), 'data/ecoinvent 3.8_LCIA_implementation/LCIA Implementation v3.8.xlsx')\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"2023-01-24 14:39:29,536 - ecoinvent38 - INFO - Products extracted from IntermediateExchanges.xml with SHA-1 of 1da23bc8fd24d97422a2a21ba3626d2cdfa6a428\n",
"2023-01-24 14:40:24,671 - ecoinvent38 - WARNING - Removed 162 duplicate rows from activity_list, see duplicate_activity_list.csv.\n",
"2023-01-24 14:40:24,797 - ecoinvent38 - INFO - Activities extracted from ActivityIndex.xml with SHA-1 of 03403c01ac6f74a5d6cc5ca8820593f7e516b709\n",
"2023-01-24 14:40:24,833 - ecoinvent38 - INFO - Processing 19565 files in /home/lele/git/pylcaio_raw_raw/doc/data/ecoinvent 3.8_cutoff_ecoSpold02/datasets\n",
"2023-01-24 14:42:43,655 - ecoinvent38 - INFO - Flows saved in /home/lele/git/pylcaio_raw_raw/doc/data/ecoinvent 3.8_cutoff_ecoSpold02/flows.pickle with SHA-1 of 3d04666305776667caaac5221fd6dd2c4c07499b\n",
"2023-01-24 14:42:43,750 - ecoinvent38 - INFO - Processing 19565 files - this may take a while ...\n",
"2023-01-24 14:45:51,807 - ecoinvent38 - INFO - Elementary flows extracted from ElementaryExchanges.xml with SHA-1 of f65edb9180cc5fb6df99289157b5aab92d30c0d1\n",
"2023-01-24 14:45:51,918 - ecoinvent38 - INFO - Labels saved in /home/lele/git/pylcaio_raw_raw/doc/data/ecoinvent 3.8_cutoff_ecoSpold02/rawlabels.pickle with SHA-1 of 3b8391230c405f267b9649ae62739834caaf9eb4\n",
"2023-01-24 14:45:51,940 - ecoinvent38 - INFO - OK. No untraceable flows.\n",
"2023-01-24 14:45:52,616 - ecoinvent38 - INFO - OK. Source activities seem in order. Each product traceable to an activity that actually does produce or distribute this product.\n",
"2023-01-24 14:45:53,147 - ecoinvent38 - INFO - Starting to assemble the matrices\n",
"2023-01-24 14:46:00,678 - ecoinvent38 - INFO - fillna\n",
"2023-01-24 14:46:12,500 - ecoinvent38 - INFO - Starting normalizing matrices\n",
"2023-01-24 14:47:20,633 - ecoinvent38 - INFO - Characterisation file seems to be ecoinvent LCIA implementation. Will apply simple name matching\n",
"2023-01-24 14:47:39,928 - ecoinvent38 - INFO - Starting characterisation matching\n",
"2023-01-24 14:47:42,444 - ecoinvent38 - INFO - Characterisation matching done. C matrix created\n",
"2023-01-24 14:47:42,458 - ecoinvent38 - INFO - Starting to export to file\n",
"2023-01-24 14:47:42,459 - ecoinvent38 - INFO - about to write to file\n",
"2023-01-24 14:48:49,496 - ecoinvent38 - INFO - Final, symmetric, normalized matrices saved in /home/lele/git/pylcaio_raw_raw/doc/data/ecospold2matrix_matrices/ecoinvent38/ecoinvent38Pandas_symmNorm.gz.pickle with SHA-1 of cd2bc679856e0a95df7eed0220f414843ccea2fe\n",
"2023-01-24 14:48:49,497 - ecoinvent38 - INFO - Done running ecospold2matrix.ecospold_to_Leontief\n"
]
}
],
"source": [
"parser.ecospold_to_Leontief(fileformats='Pandas', with_absolute_flows=False)"
]
},
{
"cell_type": "code",
"execution_count": null,
"outputs": [],
"source": [],
"metadata": {
"collapsed": false
}
}
],
"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.9.16"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
141 changes: 141 additions & 0 deletions doc/2 - run pylcaio.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"outputs": [],
"source": [
"import os\n",
"os.environ['BRIGHTWAY2_DIR'] = os.path.join(os.getcwd(), 'data/brightway')"
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "code",
"execution_count": null,
"outputs": [],
"source": [
"import sys\n",
"sys.path.append(os.path.join(os.path.dirname(os.getcwd()), 'src'))"
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "code",
"execution_count": null,
"outputs": [],
"source": [
"import gzip\n",
"import pandas as pd\n",
"import pymrio\n",
"import pylcaio"
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "code",
"execution_count": null,
"outputs": [],
"source": [
"with gzip.open(\n",
" os.path.join(os.getcwd(), 'data/ecospold2matrix_matrices/ecoinvent38/ecoinvent38Pandas_symmNorm.gz.pickle'),\n",
" 'rb') as f:\n",
" ecoinvent = pd.read_pickle(f)"
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "code",
"execution_count": null,
"outputs": [],
"source": [
"io = pymrio.parse_exiobase3(path=os.path.join(os.getcwd(), 'data/pymrio_downloads/IOT_2022_pxp.zip')).calc_all()"
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "code",
"execution_count": null,
"outputs": [],
"source": [
"database_loader = pylcaio.DatabaseLoader(\n",
" lca_database_processed=ecoinvent,\n",
" io_database_processed=io,\n",
" lca_database_name_and_version='ecoinvent3.8',\n",
" io_database_name_and_version='exiobase3'\n",
")"
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "code",
"execution_count": null,
"outputs": [],
"source": [
"lcaio_object = database_loader.combine_ecoinvent_exiobase(\n",
" complete_extensions=False,\n",
" impact_world=True,\n",
" regionalized=False\n",
")"
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "code",
"execution_count": null,
"outputs": [],
"source": [
"lcaio_object.hybridize('STAM')"
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "code",
"execution_count": null,
"outputs": [],
"source": [
"lcaio_object.save_system('pickle')"
],
"metadata": {
"collapsed": false
}
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Loading