-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update activities_classifications.yaml
- Loading branch information
1 parent
348c1fe
commit dd08170
Showing
9 changed files
with
15,971 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,333 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"id": "d3775ce4-b1a2-4d49-a91c-827581efc52b", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Invalid datapackage: Descriptor validation error: {'path': 'mapping/mapping.yaml', 'profile': 'data-resource', 'name': 'mapping', 'format': 'yaml', 'mediatype': 'text/yaml', 'encoding': 'utf-8'} is not valid under any of the given schemas at \"resources/29\" in descriptor and at \"properties/resources/items/oneOf\" in profile\n", | ||
"Invalid datapackage: Descriptor validation error: 'data-resource' is not one of ['tabular-data-resource'] at \"resources/29/profile\" in descriptor and at \"properties/resources/items/properties/profile/enum\" in profile\n", | ||
"Log file: /Users/romain/Library/Logs/pathways/pathways.log\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"from pathways import Pathways\n", | ||
"import bw2calc as bc\n", | ||
"import pandas as pd\n", | ||
"from bw2calc.graph_traversal import AssumedDiagonalGraphTraversal\n", | ||
"from d3blocks import D3Blocks\n", | ||
"\n", | ||
"fp = \"/Users/romain/Github/sweet_sure-2050-switzerland/dev/remind-SSP2-NPi-stem-SPS1.zip\"\n", | ||
"p = Pathways(datapackage=fp, debug=True)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 5, | ||
"id": "74f81bf8-27aa-40c7-b950-77885d0cfcc4", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"{37285: 740396690.1804485, 37284: 64767290.8777829, 37286: 991128.6127231001, 37282: 64143285485.75293, 37283: 75612915014.40279}\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"sankey = p.sankey(\n", | ||
" #method='EF v3.0 EN15804 - climate change - global warming potential (GWP100)',\n", | ||
" method='ReCiPe 2016 v1.03, midpoint (H) - particulate matter formation - particulate matter formation potential (PMFP)',\n", | ||
" model=\"remind\",\n", | ||
" scenario=\"SSP2-NPi-SPS1\",\n", | ||
" region=\"CH\",\n", | ||
" year=2020,\n", | ||
" #variable='FE_industry_process_heat_pump',\n", | ||
" variable=[v for v in p.scenarios.coords[\"variables\"].values if \"FE_cars\" in v],\n", | ||
" cutoff=1e-3,\n", | ||
")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 6, | ||
"id": "a901d8ad-0195-42c2-bf0c-d07e3b58c7dd", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"{37285: 740396690.1804485,\n", | ||
" 37284: 64767290.8777829,\n", | ||
" 37286: 991128.6127231001,\n", | ||
" 37282: 64143285485.75293,\n", | ||
" 37283: 75612915014.40279}" | ||
] | ||
}, | ||
"execution_count": 6, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"sankey.lca.demand" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 10, | ||
"id": "874fff78-9728-4a76-ade2-ab18b50b87b0", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"True" | ||
] | ||
}, | ||
"execution_count": 10, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"sum(sankey.lca.demand_array) == sum(sankey.lca.demand.values())" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 7, | ||
"id": "fb490a29-97e9-4b5b-ba13-5259f0379c1c", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stderr", | ||
"output_type": "stream", | ||
"text": [ | ||
"/opt/homebrew/Caskroom/miniforge/base/envs/pathways/lib/python3.11/site-packages/scikits/umfpack/umfpack.py:736: UmfpackWarning: (almost) singular matrix! (estimated cond. number: 1.21e+13)\n", | ||
" warnings.warn(msg, UmfpackWarning)\n" | ||
] | ||
}, | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"100\n", | ||
"0\n", | ||
"2\n", | ||
"4\n", | ||
"5\n", | ||
"39\n", | ||
"52\n", | ||
"62\n", | ||
"67\n", | ||
"71\n", | ||
"94\n", | ||
"108\n" | ||
] | ||
}, | ||
{ | ||
"name": "stderr", | ||
"output_type": "stream", | ||
"text": [ | ||
"/opt/homebrew/Caskroom/miniforge/base/envs/pathways/lib/python3.11/site-packages/bw2calc/graph_traversal.py:171: UserWarning: Stopping traversal due to calculation count.\n", | ||
" warnings.warn(\"Stopping traversal due to calculation count.\")\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"gt = AssumedDiagonalGraphTraversal().calculate(sankey.lca, max_calc=100)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 11, | ||
"id": "6e8e1763-f67e-4881-9b01-5e33125c4482", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"df = pd.DataFrame(gt[\"edges\"])" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 12, | ||
"id": "c9fd1e63-c95d-480b-922d-3ef8dffbb8dd", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"df.columns = [\"target\", \"source\", \"amount\", \"exc_amount\", \"weight\"]\n", | ||
"df[\"unit\"] = sankey.lcia_unit" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 13, | ||
"id": "bcc7a52d-ef56-45a8-8c9f-cf8f45d4e621", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"df[\"target\"] = df[\"target\"].map({v: f\"{k[0]} [{k[-1]}]\" for k, v in sankey.activity_dict.items()})\n", | ||
"df[\"source\"] = df[\"source\"].map({v: f\"{k[0]} [{k[-1]}]\" for k, v in sankey.activity_dict.items()})" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 14, | ||
"id": "4c34c812-63b3-4d88-97c3-8f45497db062", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"df[\"target\"] = df[\"target\"].str.replace(\"market for\", \"m. for\")\n", | ||
"df[\"source\"] = df[\"source\"].str.replace(\"market for\", \"m. for\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 15, | ||
"id": "0e0c8d7d-5267-4ef5-91b2-e18e990bb6aa", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"33" | ||
] | ||
}, | ||
"execution_count": 15, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"len(df)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 16, | ||
"id": "7ed01183-6e0d-4a82-b9b6-9b87601e51c7", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"d3_graph = D3Blocks()\n", | ||
"d3_graph.sankey(\n", | ||
" df=df[1:],\n", | ||
" link={\"color\": \"source-target\"},\n", | ||
" filepath=\"/Users/romain/Github/pathways/dev/test.html\",\n", | ||
")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"id": "afd24f80-5ce7-4540-b604-9e09cccf9fbb", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"id": "35574391-e3a1-4f91-bdc6-4c0a0bb41259", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import bw2data\n", | ||
"from polyviz import sankey\n", | ||
"bw2data.projects.set_current(\"ei310\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"id": "467d506b-0f78-4937-b97c-762825439165", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"'hydrogen burned, in hydrogen boiler_FE_residential_space_heating_hydrogen' (megajoule, CH, None)" | ||
] | ||
}, | ||
"execution_count": 2, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"act = [a for a in bw2data.Database(\"2050 2\") if \"FE_\" in a [\"name\"]][0]\n", | ||
"act" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"id": "7ccafbac-055e-4159-8c73-f5b3d79345fe", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Calculating supply chain score...\n" | ||
] | ||
}, | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"'/Users/romain/Github/sweet_sure-2050-switzerland/dev/hydrogen burned in hydrogen boilerFEresidentialspaceheatinghydrogen megajoule CH IPCC 2021climate change fossilglobal warming potential GWP100 sankey.html'" | ||
] | ||
}, | ||
"execution_count": 3, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"sankey(\n", | ||
" activity=act,\n", | ||
" method=('IPCC 2021', 'climate change: fossil', 'global warming potential (GWP100)'),\n", | ||
" #level=3,\n", | ||
" cutoff=0.1,\n", | ||
")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "bcf8e530-1238-451f-ac9e-db9bc8dcc818", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"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.11.8" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"cells": [], | ||
"metadata": {}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
Binary file not shown.
Binary file not shown.
Oops, something went wrong.