{
"cells": [
{
"cell_type": "code",
"execution_count": 36,
"metadata": {},
"outputs": [],
"source": [
"import bw2data as bd\n",
"\n",
"bd.projects.set_current(\"multi-level-tds\")"
]
},
{
"cell_type": "code",
"execution_count": 37,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"100%|██████████| 1/1 [00:00<00:00, 7244.05it/s]"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Vacuuming database \n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"\n"
]
}
],
"source": [
"biosphere = bd.Database(\"biosphere\")\n",
"biosphere.write(\n",
" {\n",
" (\"biosphere\", \"CO2\"): {\n",
" \"type\": \"emission\",\n",
" \"name\": \"carbon dioxide\",\n",
" },\n",
" }\n",
")\n",
"\n",
"if \"foreground\" in bd.databases:\n",
" del bd.databases[\"foreground\"] # to make sure we create the foreground from scratch\n",
"foreground = bd.Database(\"foreground\")\n",
"foreground.register()\n",
"\n",
"if \"background_2020\" in bd.databases:\n",
" del bd.databases[\"background_2020\"] # to make sure we create the foreground from scratch\n",
"background_2020 = bd.Database(\"background_2020\")\n",
"background_2020.register()\n",
"\n",
"if \"background_2030\" in bd.databases:\n",
" del bd.databases[\"background_2030\"] # to make sure we create the foreground from scratch\n",
"background_2030 = bd.Database(\"background_2030\")\n",
"background_2030.register()"
]
},
{
"cell_type": "code",
"execution_count": 38,
"metadata": {},
"outputs": [],
"source": [
"node_co2 = biosphere.get(\"CO2\")\n",
"\n",
"fu = foreground.new_node(\"fu\", name=\"fu\", unit=\"unit\")\n",
"fu['reference product'] = \"fu\"\n",
"fu.save()\n",
"\n",
"first_level_input = foreground.new_node(\"first_level_input\", name=\"first_level_input\", unit=\"unit\")\n",
"first_level_input['reference product'] = \"first_level_input\"\n",
"first_level_input.save()\n",
"\n",
"background_process_2020 = background_2020.new_node(\"background_process\", name=\"background_process\", unit=\"background_process\")\n",
"background_process_2020['reference product'] = \"background_process\"\n",
"background_process_2020.save()\n",
"\n",
"background_process_2030 = background_2030.new_node(\"background_process\", name=\"background_process\", unit=\"background_process\")\n",
"background_process_2030['reference product'] = \"background_process\"\n",
"background_process_2030.save()\n"
]
},
{
"cell_type": "code",
"execution_count": 39,
"metadata": {},
"outputs": [],
"source": [
"fu.new_edge(input=fu, amount=1, type=\"production\").save()\n",
"first_level_input_to_fu = fu.new_edge(input=first_level_input, amount=1, type=\"technosphere\")\n",
"\n",
"first_level_input.new_edge(input=first_level_input, amount=1, type=\"production\").save()\n",
"background_process_2020_to_first_level_input = first_level_input.new_edge(input=background_process_2020, amount=840, type=\"technosphere\")\n",
"\n",
"background_process_2020.new_edge(input=background_process_2020, amount=1, type=\"production\").save()\n",
"background_process_2020.new_edge(input=node_co2, amount=1, type=\"biosphere\").save()\n",
"\n",
"background_process_2030.new_edge(input=background_process_2030, amount=1, type=\"production\").save()\n",
"background_process_2030.new_edge(input=node_co2, amount=1, type=\"biosphere\").save()\n"
]
},
{
"cell_type": "code",
"execution_count": 40,
"metadata": {},
"outputs": [],
"source": [
"from bw_temporalis import TemporalDistribution\n",
"import numpy as np\n",
"\n",
"td_first_level_input_to_fu = TemporalDistribution(\n",
" date=np.array([-2, -1], dtype=\"timedelta64[M]\"), amount=np.array([0.2, 0.8])\n",
")\n",
"\n",
"td_background_process_2020_to_first_level_input = TemporalDistribution(\n",
" date=np.array([-3, -2], dtype=\"timedelta64[Y]\"), amount=np.array([0.4, 0.6])\n",
")\n",
"\n",
"# td_first_level_input_to_fu = TemporalDistribution(\n",
"# date=np.array([-2, -1], dtype=\"timedelta64[Y]\"), amount=np.array([0.2, 0.8])\n",
"# )\n",
"\n",
"# td_background_process_2020_to_first_level_input = TemporalDistribution(\n",
"# date=np.array([-3, -2], dtype=\"timedelta64[Y]\"), amount=np.array([0.4, 0.6])\n",
"# )"
]
},
{
"cell_type": "code",
"execution_count": 41,
"metadata": {},
"outputs": [],
"source": [
"first_level_input_to_fu[\"temporal_distribution\"] = td_first_level_input_to_fu\n",
"first_level_input_to_fu.save()\n",
"\n",
"background_process_2020_to_first_level_input[\"temporal_distribution\"] = td_background_process_2020_to_first_level_input\n",
"background_process_2020_to_first_level_input.save()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## LCA using `bw_timex`\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"As usual, we need to select a method:"
]
},
{
"cell_type": "code",
"execution_count": 42,
"metadata": {},
"outputs": [],
"source": [
"method = (\"GWP\", \"example\")\n",
"bd.Method(method).write(\n",
" [\n",
" ((\"biosphere\", \"CO2\"), 1),\n",
" ]\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 43,
"metadata": {},
"outputs": [],
"source": [
"from datetime import datetime\n",
"\n",
"database_date_dict = {\n",
" \"background_2020\": datetime.strptime(\"2020\", \"%Y\"),\n",
" \"background_2030\": datetime.strptime(\"2030\", \"%Y\"),\n",
" \"foreground\": \"dynamic\", # flag databases that should be temporally distributed with \"dynamic\"\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": 44,
"metadata": {},
"outputs": [],
"source": [
"from bw_timex import TimexLCA\n",
"\n",
"tlca = TimexLCA({fu: 1}, method, database_date_dict)"
]
},
{
"cell_type": "code",
"execution_count": 45,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"336.0"
]
},
"execution_count": 45,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"1008/3"
]
},
{
"cell_type": "code",
"execution_count": 46,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"168"
]
},
"execution_count": 46,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"1008-840"
]
},
{
"cell_type": "code",
"execution_count": 50,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Starting graph traversal\n",
"Calculation count: 2\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/timodiepers/Documents/Coding/bw_timex/bw_timex/timex_lca.py:194: UserWarning: No edge filter function provided. Skipping all edges within background databases.\n",
" warnings.warn(\n"
]
},
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" date_producer | \n",
" producer_name | \n",
" date_consumer | \n",
" consumer_name | \n",
" amount | \n",
" interpolation_weights | \n",
"
\n",
" \n",
" \n",
" \n",
" | 0 | \n",
" 2021-01-01 | \n",
" background_process | \n",
" 2024-01-01 | \n",
" first_level_input | \n",
" 672.0 | \n",
" {'background_2020': 0.8998083766767041, 'backg... | \n",
"
\n",
" \n",
" | 1 | \n",
" 2022-01-01 | \n",
" background_process | \n",
" 2024-01-01 | \n",
" first_level_input | \n",
" 1008.0 | \n",
" {'background_2020': 0.7998905009581166, 'backg... | \n",
"
\n",
" \n",
" | 2 | \n",
" 2024-01-01 | \n",
" fu | \n",
" 2024-01-01 | \n",
" -1 | \n",
" 1.0 | \n",
" None | \n",
"
\n",
" \n",
" | 3 | \n",
" 2024-01-01 | \n",
" first_level_input | \n",
" 2024-01-01 | \n",
" fu | \n",
" 1.0 | \n",
" None | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" date_producer producer_name date_consumer consumer_name amount \\\n",
"0 2021-01-01 background_process 2024-01-01 first_level_input 672.0 \n",
"1 2022-01-01 background_process 2024-01-01 first_level_input 1008.0 \n",
"2 2024-01-01 fu 2024-01-01 -1 1.0 \n",
"3 2024-01-01 first_level_input 2024-01-01 fu 1.0 \n",
"\n",
" interpolation_weights \n",
"0 {'background_2020': 0.8998083766767041, 'backg... \n",
"1 {'background_2020': 0.7998905009581166, 'backg... \n",
"2 None \n",
"3 None "
]
},
"execution_count": 50,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"tlca.build_timeline(temporal_grouping=\"year\")"
]
},
{
"cell_type": "code",
"execution_count": 33,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/timodiepers/anaconda3/envs/timex/lib/python3.10/site-packages/bw2calc/lca_base.py:127: SparseEfficiencyWarning: splu converted its input to CSC format\n",
" self.solver = factorized(self.technosphere_matrix)\n"
]
}
],
"source": [
"tlca.lci()"
]
},
{
"cell_type": "code",
"execution_count": 75,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/timodiepers/anaconda3/envs/timex/lib/python3.10/site-packages/bw2calc/lca_base.py:127: SparseEfficiencyWarning: splu converted its input to CSC format\n",
" self.solver = factorized(self.technosphere_matrix)\n"
]
}
],
"source": [
"tlca.lci()"
]
},
{
"cell_type": "code",
"execution_count": 78,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1680.0000000000002"
]
},
"execution_count": 78,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"tlca.static_lcia()\n",
"tlca.static_score"
]
},
{
"cell_type": "code",
"execution_count": 79,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"840.0000000000001"
]
},
"execution_count": 79,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"tlca.base_lca.score"
]
},
{
"cell_type": "code",
"execution_count": 76,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{(('foreground', 'fu'), 'dynamic'): 187,\n",
" (('foreground', 'first_level_input'), 'dynamic'): 188,\n",
" (('background_2020', 'background_process'), 2020): 189,\n",
" (('background_2030', 'background_process'), 2030): 190,\n",
" (('temporalized', 'background_process'), 2021): 191,\n",
" (('temporalized', 'background_process'), 2022): 192,\n",
" (('temporalized', 'fu'), 2024): 193,\n",
" (('temporalized', 'first_level_input'), 2024): 194}"
]
},
"execution_count": 76,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"tlca.activity_time_mapping_dict"
]
},
{
"cell_type": "code",
"execution_count": 77,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" date | \n",
" amount | \n",
" flow | \n",
" activity | \n",
"
\n",
" \n",
" \n",
" \n",
" | 0 | \n",
" 2019-01-01 | \n",
" 67.2 | \n",
" 41 | \n",
" 46 | \n",
"
\n",
" \n",
" | 1 | \n",
" 2020-01-01 | \n",
" 369.6 | \n",
" 41 | \n",
" 44 | \n",
"
\n",
" \n",
" | 2 | \n",
" 2021-01-01 | \n",
" 403.2 | \n",
" 41 | \n",
" 47 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" date amount flow activity\n",
"0 2019-01-01 67.2 41 46\n",
"1 2020-01-01 369.6 41 44\n",
"2 2021-01-01 403.2 41 47"
]
},
"execution_count": 77,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import pandas as pd\n",
"\n",
"expected_inventory = pd.DataFrame(\n",
" data={\n",
" \"date\": pd.Series(\n",
" data=[\n",
" \"01-01-2019\",\n",
" \"01-01-2020\",\n",
" \"01-01-2021\",\n",
" ],\n",
" dtype=\"datetime64[s]\",\n",
" ),\n",
" \"amount\": pd.Series(\n",
" data=[0.2*336, 0.8*336+0.2*504, 0.8*504], dtype=\"float64\"\n",
" ),\n",
" \"flow\": pd.Series(data=[41, 41, 41], dtype=\"int\"),\n",
" \"activity\": pd.Series(data=[46, 44, 47], dtype=\"int\"),\n",
" }\n",
")\n",
"expected_inventory"
]
},
{
"cell_type": "code",
"execution_count": 49,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" ((foreground, fu), dynamic) | \n",
" ((foreground, first_level_input), dynamic) | \n",
" ((background_2020, background_process), 2020) | \n",
" ((background_2030, background_process), 2030) | \n",
" ((temporalized, background_process), 2019) | \n",
" ((temporalized, background_process), 2020) | \n",
" ((temporalized, background_process), 2021) | \n",
" ((temporalized, first_level_input), 2022) | \n",
" ((temporalized, first_level_input), 2023) | \n",
" ((temporalized, fu), 2024) | \n",
"
\n",
" \n",
" \n",
" \n",
" | ((foreground, fu), dynamic) | \n",
" 1.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.000000 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
"
\n",
" \n",
" | ((foreground, first_level_input), dynamic) | \n",
" -1.0 | \n",
" 1.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.000000 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
"
\n",
" \n",
" | ((background_2020, background_process), 2020) | \n",
" 0.0 | \n",
" -840.0 | \n",
" 1.0 | \n",
" 0.0 | \n",
" -1.0 | \n",
" -1.0 | \n",
" -0.899808 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
"
\n",
" \n",
" | ((background_2030, background_process), 2030) | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 1.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" -0.100192 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
"
\n",
" \n",
" | ((temporalized, background_process), 2019) | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 1.0 | \n",
" 0.0 | \n",
" 0.000000 | \n",
" -336.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
"
\n",
" \n",
" | ((temporalized, background_process), 2020) | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 1.0 | \n",
" 0.000000 | \n",
" -504.0 | \n",
" -336.0 | \n",
" 0.0 | \n",
"
\n",
" \n",
" | ((temporalized, background_process), 2021) | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 1.000000 | \n",
" 0.0 | \n",
" -504.0 | \n",
" 0.0 | \n",
"
\n",
" \n",
" | ((temporalized, first_level_input), 2022) | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.000000 | \n",
" 1.0 | \n",
" 0.0 | \n",
" -0.2 | \n",
"
\n",
" \n",
" | ((temporalized, first_level_input), 2023) | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.000000 | \n",
" 0.0 | \n",
" 1.0 | \n",
" -0.8 | \n",
"
\n",
" \n",
" | ((temporalized, fu), 2024) | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.000000 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 1.0 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" ((foreground, fu), dynamic) \\\n",
"((foreground, fu), dynamic) 1.0 \n",
"((foreground, first_level_input), dynamic) -1.0 \n",
"((background_2020, background_process), 2020) 0.0 \n",
"((background_2030, background_process), 2030) 0.0 \n",
"((temporalized, background_process), 2019) 0.0 \n",
"((temporalized, background_process), 2020) 0.0 \n",
"((temporalized, background_process), 2021) 0.0 \n",
"((temporalized, first_level_input), 2022) 0.0 \n",
"((temporalized, first_level_input), 2023) 0.0 \n",
"((temporalized, fu), 2024) 0.0 \n",
"\n",
" ((foreground, first_level_input), dynamic) \\\n",
"((foreground, fu), dynamic) 0.0 \n",
"((foreground, first_level_input), dynamic) 1.0 \n",
"((background_2020, background_process), 2020) -840.0 \n",
"((background_2030, background_process), 2030) 0.0 \n",
"((temporalized, background_process), 2019) 0.0 \n",
"((temporalized, background_process), 2020) 0.0 \n",
"((temporalized, background_process), 2021) 0.0 \n",
"((temporalized, first_level_input), 2022) 0.0 \n",
"((temporalized, first_level_input), 2023) 0.0 \n",
"((temporalized, fu), 2024) 0.0 \n",
"\n",
" ((background_2020, background_process), 2020) \\\n",
"((foreground, fu), dynamic) 0.0 \n",
"((foreground, first_level_input), dynamic) 0.0 \n",
"((background_2020, background_process), 2020) 1.0 \n",
"((background_2030, background_process), 2030) 0.0 \n",
"((temporalized, background_process), 2019) 0.0 \n",
"((temporalized, background_process), 2020) 0.0 \n",
"((temporalized, background_process), 2021) 0.0 \n",
"((temporalized, first_level_input), 2022) 0.0 \n",
"((temporalized, first_level_input), 2023) 0.0 \n",
"((temporalized, fu), 2024) 0.0 \n",
"\n",
" ((background_2030, background_process), 2030) \\\n",
"((foreground, fu), dynamic) 0.0 \n",
"((foreground, first_level_input), dynamic) 0.0 \n",
"((background_2020, background_process), 2020) 0.0 \n",
"((background_2030, background_process), 2030) 1.0 \n",
"((temporalized, background_process), 2019) 0.0 \n",
"((temporalized, background_process), 2020) 0.0 \n",
"((temporalized, background_process), 2021) 0.0 \n",
"((temporalized, first_level_input), 2022) 0.0 \n",
"((temporalized, first_level_input), 2023) 0.0 \n",
"((temporalized, fu), 2024) 0.0 \n",
"\n",
" ((temporalized, background_process), 2019) \\\n",
"((foreground, fu), dynamic) 0.0 \n",
"((foreground, first_level_input), dynamic) 0.0 \n",
"((background_2020, background_process), 2020) -1.0 \n",
"((background_2030, background_process), 2030) 0.0 \n",
"((temporalized, background_process), 2019) 1.0 \n",
"((temporalized, background_process), 2020) 0.0 \n",
"((temporalized, background_process), 2021) 0.0 \n",
"((temporalized, first_level_input), 2022) 0.0 \n",
"((temporalized, first_level_input), 2023) 0.0 \n",
"((temporalized, fu), 2024) 0.0 \n",
"\n",
" ((temporalized, background_process), 2020) \\\n",
"((foreground, fu), dynamic) 0.0 \n",
"((foreground, first_level_input), dynamic) 0.0 \n",
"((background_2020, background_process), 2020) -1.0 \n",
"((background_2030, background_process), 2030) 0.0 \n",
"((temporalized, background_process), 2019) 0.0 \n",
"((temporalized, background_process), 2020) 1.0 \n",
"((temporalized, background_process), 2021) 0.0 \n",
"((temporalized, first_level_input), 2022) 0.0 \n",
"((temporalized, first_level_input), 2023) 0.0 \n",
"((temporalized, fu), 2024) 0.0 \n",
"\n",
" ((temporalized, background_process), 2021) \\\n",
"((foreground, fu), dynamic) 0.000000 \n",
"((foreground, first_level_input), dynamic) 0.000000 \n",
"((background_2020, background_process), 2020) -0.899808 \n",
"((background_2030, background_process), 2030) -0.100192 \n",
"((temporalized, background_process), 2019) 0.000000 \n",
"((temporalized, background_process), 2020) 0.000000 \n",
"((temporalized, background_process), 2021) 1.000000 \n",
"((temporalized, first_level_input), 2022) 0.000000 \n",
"((temporalized, first_level_input), 2023) 0.000000 \n",
"((temporalized, fu), 2024) 0.000000 \n",
"\n",
" ((temporalized, first_level_input), 2022) \\\n",
"((foreground, fu), dynamic) 0.0 \n",
"((foreground, first_level_input), dynamic) 0.0 \n",
"((background_2020, background_process), 2020) 0.0 \n",
"((background_2030, background_process), 2030) 0.0 \n",
"((temporalized, background_process), 2019) -336.0 \n",
"((temporalized, background_process), 2020) -504.0 \n",
"((temporalized, background_process), 2021) 0.0 \n",
"((temporalized, first_level_input), 2022) 1.0 \n",
"((temporalized, first_level_input), 2023) 0.0 \n",
"((temporalized, fu), 2024) 0.0 \n",
"\n",
" ((temporalized, first_level_input), 2023) \\\n",
"((foreground, fu), dynamic) 0.0 \n",
"((foreground, first_level_input), dynamic) 0.0 \n",
"((background_2020, background_process), 2020) 0.0 \n",
"((background_2030, background_process), 2030) 0.0 \n",
"((temporalized, background_process), 2019) 0.0 \n",
"((temporalized, background_process), 2020) -336.0 \n",
"((temporalized, background_process), 2021) -504.0 \n",
"((temporalized, first_level_input), 2022) 0.0 \n",
"((temporalized, first_level_input), 2023) 1.0 \n",
"((temporalized, fu), 2024) 0.0 \n",
"\n",
" ((temporalized, fu), 2024) \n",
"((foreground, fu), dynamic) 0.0 \n",
"((foreground, first_level_input), dynamic) 0.0 \n",
"((background_2020, background_process), 2020) 0.0 \n",
"((background_2030, background_process), 2030) 0.0 \n",
"((temporalized, background_process), 2019) 0.0 \n",
"((temporalized, background_process), 2020) 0.0 \n",
"((temporalized, background_process), 2021) 0.0 \n",
"((temporalized, first_level_input), 2022) -0.2 \n",
"((temporalized, first_level_input), 2023) -0.8 \n",
"((temporalized, fu), 2024) 1.0 "
]
},
"execution_count": 49,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"tlca.create_labelled_technosphere_dataframe()"
]
},
{
"cell_type": "code",
"execution_count": 50,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" ((foreground, fu), dynamic) | \n",
" ((foreground, first_level_input), dynamic) | \n",
" ((background_2020, background_process), 2020) | \n",
" ((background_2030, background_process), 2030) | \n",
" ((temporalized, background_process), 2019) | \n",
" ((temporalized, background_process), 2020) | \n",
" ((temporalized, background_process), 2021) | \n",
" ((temporalized, first_level_input), 2022) | \n",
" ((temporalized, first_level_input), 2023) | \n",
" ((temporalized, fu), 2024) | \n",
"
\n",
" \n",
" \n",
" \n",
" | (181, 2019-01-01T00:00:00) | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 1.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
"
\n",
" \n",
" | (181, 2020-01-01T00:00:00) | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 1.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
"
\n",
" \n",
" | (181, 2021-01-01T00:00:00) | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 1.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" ((foreground, fu), dynamic) \\\n",
"(181, 2019-01-01T00:00:00) 0.0 \n",
"(181, 2020-01-01T00:00:00) 0.0 \n",
"(181, 2021-01-01T00:00:00) 0.0 \n",
"\n",
" ((foreground, first_level_input), dynamic) \\\n",
"(181, 2019-01-01T00:00:00) 0.0 \n",
"(181, 2020-01-01T00:00:00) 0.0 \n",
"(181, 2021-01-01T00:00:00) 0.0 \n",
"\n",
" ((background_2020, background_process), 2020) \\\n",
"(181, 2019-01-01T00:00:00) 0.0 \n",
"(181, 2020-01-01T00:00:00) 0.0 \n",
"(181, 2021-01-01T00:00:00) 0.0 \n",
"\n",
" ((background_2030, background_process), 2030) \\\n",
"(181, 2019-01-01T00:00:00) 0.0 \n",
"(181, 2020-01-01T00:00:00) 0.0 \n",
"(181, 2021-01-01T00:00:00) 0.0 \n",
"\n",
" ((temporalized, background_process), 2019) \\\n",
"(181, 2019-01-01T00:00:00) 1.0 \n",
"(181, 2020-01-01T00:00:00) 0.0 \n",
"(181, 2021-01-01T00:00:00) 0.0 \n",
"\n",
" ((temporalized, background_process), 2020) \\\n",
"(181, 2019-01-01T00:00:00) 0.0 \n",
"(181, 2020-01-01T00:00:00) 1.0 \n",
"(181, 2021-01-01T00:00:00) 0.0 \n",
"\n",
" ((temporalized, background_process), 2021) \\\n",
"(181, 2019-01-01T00:00:00) 0.0 \n",
"(181, 2020-01-01T00:00:00) 0.0 \n",
"(181, 2021-01-01T00:00:00) 1.0 \n",
"\n",
" ((temporalized, first_level_input), 2022) \\\n",
"(181, 2019-01-01T00:00:00) 0.0 \n",
"(181, 2020-01-01T00:00:00) 0.0 \n",
"(181, 2021-01-01T00:00:00) 0.0 \n",
"\n",
" ((temporalized, first_level_input), 2023) \\\n",
"(181, 2019-01-01T00:00:00) 0.0 \n",
"(181, 2020-01-01T00:00:00) 0.0 \n",
"(181, 2021-01-01T00:00:00) 0.0 \n",
"\n",
" ((temporalized, fu), 2024) \n",
"(181, 2019-01-01T00:00:00) 0.0 \n",
"(181, 2020-01-01T00:00:00) 0.0 \n",
"(181, 2021-01-01T00:00:00) 0.0 "
]
},
"execution_count": 50,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"tlca.create_labelled_dynamic_biosphere_dataframe()"
]
},
{
"cell_type": "code",
"execution_count": 51,
"metadata": {},
"outputs": [],
"source": [
"from dynamic_characterization.timex import characterize_co2"
]
},
{
"cell_type": "code",
"execution_count": 53,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/timodiepers/anaconda3/envs/timex/lib/python3.10/site-packages/dynamic_characterization/dynamic_characterization.py:262: UserWarning: Using bw_timex's default CO2 characterization function for GWP reference.\n",
" warnings.warn(\n"
]
},
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" date | \n",
" amount | \n",
" flow | \n",
" activity | \n",
"
\n",
" \n",
" \n",
" \n",
" | 0 | \n",
" 2019-01-01 | \n",
" 67.2 | \n",
" 181 | \n",
" 186 | \n",
"
\n",
" \n",
" | 1 | \n",
" 2020-01-01 | \n",
" 369.6 | \n",
" 181 | \n",
" 187 | \n",
"
\n",
" \n",
" | 2 | \n",
" 2021-01-01 | \n",
" 403.2 | \n",
" 181 | \n",
" 188 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" date amount flow activity\n",
"0 2019-01-01 67.2 181 186\n",
"1 2020-01-01 369.6 181 187\n",
"2 2021-01-01 403.2 181 188"
]
},
"execution_count": 53,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"tlca.dynamic_lcia(metric=\"GWP\", characterization_function_dict={node_co2.id: characterize_co2})"
]
},
{
"cell_type": "code",
"execution_count": 54,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"840.0"
]
},
"execution_count": 54,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"tlca.dynamic_score"
]
},
{
"cell_type": "code",
"execution_count": 55,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"840.0000000000001"
]
},
"execution_count": 55,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"tlca.base_lca.score"
]
},
{
"cell_type": "code",
"execution_count": 56,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"840.0"
]
},
"execution_count": 56,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"tlca.static_lcia()\n",
"tlca.static_score"
]
},
{
"cell_type": "code",
"execution_count": null,
"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.10.14"
}
},
"nbformat": 4,
"nbformat_minor": 4
}