{ "cells": [ { "cell_type": "markdown", "id": "ce9349ae", "metadata": {}, "source": [ "# Use of `shrecc`\n", "\n", "This notebook guides you through the various steps needed to create spatially- and regionally-specific consumption electricity mixes. These mixes are written directly in a dedicated `brightway` database, ready to be used in your own LCA project." ] }, { "cell_type": "code", "execution_count": null, "id": "ddd00229-e983-4012-9e79-6288efe9f5b2", "metadata": {}, "outputs": [], "source": [ "import bw2data as bd\n", "import bw2io as bi\n", "import pandas as pd\n", "from shrecc.database import create_database, filt_cutoff\n", "from shrecc.download import get_data\n", "from shrecc.treatment import data_processing" ] }, { "cell_type": "markdown", "id": "55583e0f-db5c-4ee6-a451-3de520757d88", "metadata": {}, "source": [ "## Prepare your data" ] }, { "cell_type": "markdown", "id": "ba5b169a-6736-4a68-a2a0-521c35a2dedd", "metadata": {}, "source": [ "Do this in case you want to download data for any other year than the default year in the `shrecc_data` [repository](https://git.list.lu/shrecc_project/shrecc_data), or if you simply want to recalculate it on your own." ] }, { "cell_type": "markdown", "id": "52637e07-d6f1-478e-96a2-82c1bf2b3f87", "metadata": {}, "source": [ "First, run function get_data(). This will download all the electricity data for all countries for a selected year." ] }, { "cell_type": "markdown", "id": "2a6384fe-e258-43db-b61d-9f376995d90f", "metadata": {}, "source": [ "You have the option to download the data to \n", "+ a specific location you want, by specifying it at the `path_to_data` variable.\n", " **If** you use the data download directly from the [shrecc_data](https://git.list.lu/shrecc_project/shrecc_data) repository, please make sure you save it under a directory called `data`. shreec will take this as the root to look for the `2022`, `2023`, etc. directories.\n", "+ provide no location, and shrecc will download it to the package location" ] }, { "cell_type": "code", "execution_count": null, "id": "9eac15e4-3893-4418-bc76-ca0476066340", "metadata": {}, "outputs": [], "source": [ "# Define here the path to data, and re-use it as necessary if you want to store the data in a specific location\n", "PATH_TO_DATA = \"data\"" ] }, { "cell_type": "code", "execution_count": null, "id": "9a0e6b01-405e-4cba-9a83-961ed525dc20", "metadata": { "scrolled": true }, "outputs": [], "source": [ "data = get_data(year=2024, path_to_data=PATH_TO_DATA)\n", "# if no path given, shrecc will create a folder inside of shrecc/data and save the data there" ] }, { "cell_type": "markdown", "id": "94892f16-d0d8-4e71-8608-0b51d361e528", "metadata": {}, "source": [ "Next, it's time to treat the data. This part is very heavy due to matrix inversion, and is recommended to run on a server." ] }, { "cell_type": "code", "execution_count": null, "id": "3fb0a74b-e7d7-4f9e-ae65-81839f859b75", "metadata": { "scrolled": true }, "outputs": [], "source": [ "data_processing(data_df=data, year=2024, path_to_data=PATH_TO_DATA)\n", "# if no path given, shrecc will create a folder inside of shrecc/data and save the data there" ] }, { "cell_type": "markdown", "id": "c4a0cb39-ee35-4786-b333-0d00fda42328", "metadata": {}, "source": [ "And that's literally it! Now it's time to select which countries and times you are interested in and create your database." ] }, { "cell_type": "markdown", "id": "512022d8-6f6e-403e-a1f5-da1622f7a8d0", "metadata": {}, "source": [ "## Get your project ready\n", "In order to run following functions, you need to have a `brightway` (2 or 2.5) project with biosphere and ecoinvent installed. Matching of electricity sources is valid for ecoinvent 3.9.1, but should be compatible with 3.10 and 3.11. You also need to have a `pandas` dataframe with all the electricity data. Either you created it on your own with the above steps, or you downloaded it from [our git](https://git.list.lu/shrecc_project/shrecc_data)." ] }, { "cell_type": "code", "execution_count": null, "id": "bbca7c61-6b39-4ab1-9bdf-fe6779db6d89", "metadata": {}, "outputs": [], "source": [ "PROJECT_NAME = \"SHRECCei311\"" ] }, { "cell_type": "code", "execution_count": null, "id": "4bfe1c52-0664-4add-ba66-834a44f94505", "metadata": {}, "outputs": [], "source": [ "bd.projects.set_current(PROJECT_NAME)" ] }, { "cell_type": "code", "execution_count": null, "id": "8f9f340c", "metadata": {}, "outputs": [], "source": [ "bd.databases" ] }, { "cell_type": "code", "execution_count": null, "id": "0f52435a-47ce-4d8b-9c22-cec81905ee73", "metadata": {}, "outputs": [], "source": [ "if \"ecoinvent-3.11-cutoff\" not in bd.databases:\n", " bi.import_ecoinvent_release(\n", " version=\"3.11\",\n", " system_model=\"cutoff\",\n", " username=\"XX\",\n", " password=\"YY\",\n", " )" ] }, { "cell_type": "markdown", "id": "0389c349-7890-4c7f-9a0f-6a7b0ceb17ec", "metadata": {}, "source": [ "To download already-calculated data, you can visit the SHRECC data git repository: https://git.list.lu/shrecc_project/shrecc_data" ] }, { "cell_type": "markdown", "id": "3bcc2ad5-9fdf-49a1-92fd-b6a73cd43810", "metadata": {}, "source": [ "### Example 1: all days in June around noon\n", "In this example, we model the consumption mix of five countries, around noon on all days in June.\n" ] }, { "cell_type": "code", "execution_count": null, "id": "c7031b1d", "metadata": {}, "outputs": [], "source": [ "countries = [\"FI\", \"SE\", \"LU\", \"AT\", \"FR\"]" ] }, { "cell_type": "code", "execution_count": null, "id": "47c75160-977d-4d61-9492-8aa175075ca4", "metadata": {}, "outputs": [], "source": [ "example = filt_cutoff(\n", " countries=countries,\n", " general_range=[\"2024-06-01 01:00:00\", \"2024-06-30 23:00:00\"],\n", " refined_range=[10, 14],\n", " freq=\"h\",\n", " cutoff=1e-3,\n", " include_cutoff=True,\n", " path_to_data=PATH_TO_DATA,\n", ")\n", "# if no path given, shrecc will look for the data inside of shrecc/data" ] }, { "cell_type": "markdown", "id": "29c916de-e7f5-4e93-843c-12ce93daaa54", "metadata": {}, "source": [ "#### To create a database based on our filtered and cut off dataframe with selected days/times" ] }, { "cell_type": "code", "execution_count": null, "id": "5a7daa44", "metadata": {}, "outputs": [], "source": [ "example.head()" ] }, { "cell_type": "code", "execution_count": null, "id": "7563d9f9-55b4-4c61-b4eb-5afc3aa31430", "metadata": {}, "outputs": [], "source": [ "create_database(\n", " dataframe_filt=example,\n", " project_name=PROJECT_NAME,\n", " db_name=\"elec_june_2024_noon\",\n", " eidb_name=\"ecoinvent-3.11-cutoff\",\n", ")" ] }, { "cell_type": "markdown", "id": "71303dfb-1de3-4eb1-b1bc-891f0980008c", "metadata": {}, "source": [ "### Example 2: all days on February evenings\n", "Another example of dataframe, this time on February evenings" ] }, { "cell_type": "code", "execution_count": null, "id": "0f28e163-3c7b-4fd5-b66a-053929af7ae0", "metadata": {}, "outputs": [], "source": [ "example2 = filt_cutoff(\n", " countries=countries,\n", " general_range=[\"2024-02-01 01:00:00\", \"2024-02-28 23:00:00\"],\n", " refined_range=[19, 23],\n", " freq=\"h\",\n", " cutoff=1e-3,\n", " include_cutoff=True,\n", " path_to_data=PATH_TO_DATA,\n", ")\n", "# if no path given, shrecc will look for the data in shrecc/data" ] }, { "cell_type": "code", "execution_count": null, "id": "cd635013-6ddc-4140-a57d-6be63ea4c7a3", "metadata": {}, "outputs": [], "source": [ "create_database(\n", " dataframe_filt=example2,\n", " project_name=PROJECT_NAME,\n", " db_name=\"elec_february_2024_evening\",\n", " eidb_name=\"ecoinvent-3.11-cutoff\",\n", ")" ] }, { "cell_type": "markdown", "id": "5c36ce32-4d7e-4eb5-ae7a-44a9bb5c4083", "metadata": {}, "source": [ "## To show that shrecc results are similar enough to ecoinvent" ] }, { "cell_type": "markdown", "id": "b9c98318-8d0f-4cff-b9d5-eb238dc71ac9", "metadata": {}, "source": [ "We compare 2021 Energy-Charts data with ecoinvent 3.11 cutoff, which uses 2021 data for most European countries (except of Switzerland).\n", "You can download our data from shrecc_project/shrecc_data/2021. Supply the path to were you saved the data." ] }, { "cell_type": "code", "execution_count": null, "id": "333d480c-95c9-4305-a8f9-2639f0167974", "metadata": {}, "outputs": [], "source": [ "data = get_data(year=2021, path_to_data=PATH_TO_DATA)\n", "# if no path given, shrecc will create a folder inside of shrecc/data, download the data and save it there" ] }, { "cell_type": "code", "execution_count": null, "id": "69401466-1668-4491-ae86-6f4441c0622a", "metadata": {}, "outputs": [], "source": [ "data_processing(data_df=data, year=2021, path_to_data=PATH_TO_DATA)\n", "# if no path given, shrecc will create a folder inside of shrecc/data, download the data and save it there" ] }, { "cell_type": "markdown", "id": "55c96190-4992-40b0-8d16-c9f8405a7f3d", "metadata": {}, "source": [ "Selecting all the countries that do not contain missing data:" ] }, { "cell_type": "code", "execution_count": null, "id": "90b63a71-a92c-428e-9417-8e03b5dd2336", "metadata": {}, "outputs": [], "source": [ "countries = [\n", " \"AT\",\n", " \"BE\",\n", " \"CZ\",\n", " \"DE\",\n", " \"DK\",\n", " \"ES\",\n", " \"FI\",\n", " \"FR\",\n", " \"GR\",\n", " \"HU\",\n", " \"IE\",\n", " \"IT\",\n", " \"LU\",\n", " \"NL\",\n", " \"NO\",\n", " \"PL\",\n", " \"PT\",\n", " \"RO\",\n", " \"SE\",\n", " \"SK\",\n", " \"SI\",\n", "]" ] }, { "cell_type": "code", "execution_count": null, "id": "d406614b-49c0-4b96-9cd6-93f17bb53034", "metadata": {}, "outputs": [], "source": [ "year2021 = filt_cutoff(\n", " countries=countries,\n", " general_range=[\"2021-01-01 00:00:00\", \"2021-12-31 23:00:00\"],\n", " freq=\"h\",\n", " cutoff=1e-8,\n", " include_cutoff=True,\n", " path_to_data=PATH_TO_DATA,\n", ")" ] }, { "cell_type": "code", "execution_count": null, "id": "32291e9d-8021-4c7e-bede-8e185267742d", "metadata": {}, "outputs": [], "source": [ "create_database(\n", " dataframe_filt=year2021,\n", " project_name=PROJECT_NAME,\n", " db_name=\"full year 2021\",\n", " eidb_name=\"ecoinvent-3.11-cutoff\",\n", ")" ] }, { "cell_type": "code", "execution_count": null, "id": "d7d62ef8", "metadata": {}, "outputs": [], "source": [ "import bw2calc as bc" ] }, { "cell_type": "code", "execution_count": null, "id": "c2650043", "metadata": {}, "outputs": [], "source": [ "ef_methods = [m for m in bd.methods if m[1] == \"EF v3.0\"]\n", "config = {\"impact_categories\": ef_methods}" ] }, { "cell_type": "code", "execution_count": null, "id": "4aa935dc-2e28-4ea3-a695-1d7ad7a2c47f", "metadata": {}, "outputs": [], "source": [ "demands_year = {\n", " f\"{a['name']}, full year\": {a[\"id\"]: 1} for a in bd.Database(\"full year 2021\")\n", "}" ] }, { "cell_type": "code", "execution_count": null, "id": "548d0c5f-642c-4fbe-9052-87dd3be6ee5b", "metadata": {}, "outputs": [], "source": [ "acts_ei = [\n", " bd.get_node(\n", " database=\"ecoinvent-3.11-cutoff\",\n", " location=country,\n", " name=\"market for electricity, low voltage\",\n", " )\n", " for country in sorted(countries)\n", "]" ] }, { "cell_type": "code", "execution_count": null, "id": "816a75e9-3bb9-4f1b-9eb7-e8678f4ec753", "metadata": {}, "outputs": [], "source": [ "demands_year.update({f\"{a['name']}, {a['location']}\": {a[\"id\"]: 1} for a in acts_ei})" ] }, { "cell_type": "code", "execution_count": null, "id": "01acf631-141a-42fd-897a-f92885d84f57", "metadata": {}, "outputs": [], "source": [ "data_objs = bd.get_multilca_data_objs(\n", " functional_units=demands_year, method_config=config\n", ")" ] }, { "cell_type": "code", "execution_count": null, "id": "2965b3be-1f8f-45e3-a563-de2f492f1dc4", "metadata": {}, "outputs": [], "source": [ "m_lca = bc.MultiLCA(demands=demands_year, method_config=config, data_objs=data_objs)" ] }, { "cell_type": "code", "execution_count": null, "id": "a293598c-8541-4001-96ac-9fbc4ea02625", "metadata": {}, "outputs": [], "source": [ "m_lca.lci()" ] }, { "cell_type": "code", "execution_count": null, "id": "8a14453f-df9b-4c02-85e4-38ebf0dfeaba", "metadata": {}, "outputs": [], "source": [ "m_lca.lcia()" ] }, { "cell_type": "code", "execution_count": null, "id": "38643b9b-6a30-4590-ae8d-fe741904f3c7", "metadata": {}, "outputs": [], "source": [ "results = []\n", "for (method, fu), score in m_lca.scores.items():\n", " demand = m_lca.demands[fu]\n", " a_id = list(demand).pop()\n", " a = bd.get_activity(a_id)\n", " results.append(\n", " {\n", " \"activity\": a[\"name\"],\n", " \"database\": a[\"database\"],\n", " \"location\": a[\"location\"],\n", " \"production amount\": demand[a_id],\n", " \"activity unit\": a[\"unit\"],\n", " \"reference product\": a[\"reference product\"],\n", " \"methodology\": method[1],\n", " \"category\": method[2],\n", " \"indicator\": method[3],\n", " \"score\": score,\n", " \"unit\": bd.Method(method).metadata[\"unit\"],\n", " },\n", " )\n", "res_df = pd.DataFrame(results)\n", "res_df = res_df.set_index([c for c in res_df.columns if c != \"score\"]).unstack(\n", " [\"category\", \"indicator\", \"unit\"]\n", ")" ] }, { "cell_type": "code", "execution_count": null, "id": "50292ad0-b99b-4c12-9908-8caff0f7fa64", "metadata": {}, "outputs": [], "source": [ "res_df.sort_index(level=\"location\", inplace=True)" ] }, { "cell_type": "code", "execution_count": null, "id": "4107c5d9-2977-4b2d-a441-bf8b0f526b63", "metadata": {}, "outputs": [], "source": [ "data = res_df[\n", " (\"score\", \"climate change\", \"global warming potential (GWP100)\", \"kg CO2-Eq\")\n", "]\n", "data = data.droplevel(\"activity\")\n", "data = data.loc[data.index.get_level_values(\"location\").isin(countries)]\n", "data = data.unstack(\"location\").T\n", "\n", "ax = data.plot.bar(figsize=(10, 6))\n", "ax.set_ylabel(\"kg CO₂ eq./kWh\")\n", "\n", "import matplotlib.pyplot as plt\n", "\n", "plt.tight_layout()\n", "plt.show()" ] }, { "cell_type": "markdown", "id": "2b2e4b30-acb2-42de-9ac2-f0f036119426", "metadata": {}, "source": [ "There are differences in some countries, namely Norway and The Netherlands.In Norway, we recommend setting the cut off to 0, as small imports are summed together and European mix is used as the source. For most countries, that is fine, but in this specific case, Norwegian electricity is very low impact, so using the European average skews it a lot. In case of The Netherlands, there are some issues in solar power reporting, and this will be fixed in the future versions of shrecc." ] }, { "cell_type": "markdown", "id": "17344161", "metadata": {}, "source": [ "# Test\n", "We run an LCA for the 4 mix samples, as well as their ecoinvent 3.11 equivalents. It is fair to say that here, we are using 2024 data (shrecc) and ecoinvent 3.11 (2021 data), so the results also differ due to changes in the grid." ] }, { "cell_type": "code", "execution_count": null, "id": "deaa956a-03b8-4c49-8678-022ba7571194", "metadata": {}, "outputs": [], "source": [ "countries = [\"AT\", \"FR\", \"LU\", \"SE\", \"FI\"]" ] }, { "cell_type": "code", "execution_count": null, "id": "6bea58a2", "metadata": {}, "outputs": [], "source": [ "demands_summer_noon = {\n", " f\"{a['name']}, summer, noon\": {a[\"id\"]: 1}\n", " for a in bd.Database(\"elec_june_2024_noon\")\n", "}\n", "demands_winter_evening = {\n", " f\"{a['name']}, winter, evening\": {a[\"id\"]: 1}\n", " for a in bd.Database(\"elec_february_2024_evening\")\n", "}\n", "demands = {**demands_summer_noon, **demands_winter_evening}" ] }, { "cell_type": "code", "execution_count": null, "id": "d390a0a1", "metadata": {}, "outputs": [], "source": [ "acts_ei = [\n", " bd.get_node(\n", " database=\"ecoinvent-3.11-cutoff\",\n", " location=country,\n", " name=\"market for electricity, low voltage\",\n", " )\n", " for country in sorted(countries)\n", "]\n", "acts_ei" ] }, { "cell_type": "code", "execution_count": null, "id": "d5871b94", "metadata": {}, "outputs": [], "source": [ "demands.update({f\"{a['name']}, {a['location']}\": {a[\"id\"]: 1} for a in acts_ei})\n", "demands" ] }, { "cell_type": "code", "execution_count": null, "id": "2d0017e9", "metadata": {}, "outputs": [], "source": [ "data_objs = bd.get_multilca_data_objs(functional_units=demands, method_config=config)" ] }, { "cell_type": "code", "execution_count": null, "id": "214c8aa9", "metadata": {}, "outputs": [], "source": [ "m_lca = bc.MultiLCA(demands=demands, method_config=config, data_objs=data_objs)" ] }, { "cell_type": "code", "execution_count": null, "id": "1a1100a5", "metadata": {}, "outputs": [], "source": [ "m_lca.lci()" ] }, { "cell_type": "code", "execution_count": null, "id": "70244608", "metadata": {}, "outputs": [], "source": [ "m_lca.lcia()" ] }, { "cell_type": "code", "execution_count": null, "id": "961b8cad", "metadata": {}, "outputs": [], "source": [ "results = []\n", "for (method, fu), score in m_lca.scores.items():\n", " demand = m_lca.demands[fu]\n", " a_id = list(demand).pop()\n", " a = bd.get_activity(a_id)\n", " # prod_e = list(a.production()).pop()\n", " results.append(\n", " {\n", " \"activity\": a[\"name\"],\n", " \"database\": a[\"database\"],\n", " \"location\": a[\"location\"],\n", " \"production amount\": demand[a_id],\n", " \"activity unit\": a[\"unit\"],\n", " \"reference product\": a[\"reference product\"],\n", " \"methodology\": method[0],\n", " \"category\": method[1],\n", " \"indicator\": method[2],\n", " \"score\": score,\n", " \"unit\": bd.Method(method).metadata[\"unit\"],\n", " },\n", " )\n", "res_df = pd.DataFrame(results)\n", "res_df = res_df.set_index([c for c in res_df.columns if c != \"score\"]).unstack(\n", " [\"category\", \"indicator\", \"unit\"]\n", ")" ] }, { "cell_type": "code", "execution_count": null, "id": "232cfb5b", "metadata": {}, "outputs": [], "source": [ "res_df.sort_index(level=\"location\", inplace=True)" ] }, { "cell_type": "code", "execution_count": null, "id": "92fdd24e", "metadata": {}, "outputs": [], "source": [ "ax = (\n", " res_df[(\"score\", \"EF v3.0\", \"climate change\", \"kg CO2-Eq\")]\n", " .droplevel([\"activity\"])\n", " .unstack([\"location\"])\n", " .T.plot.bar(figsize=(10, 6))\n", ")\n", "ax.set_ylabel(\"kg CO2 eq./kWh\")" ] }, { "cell_type": "markdown", "id": "ccd05b99", "metadata": {}, "source": [ "# Further analysis and comparisons" ] }, { "cell_type": "markdown", "id": "e7c86096-ebc8-4e4c-9edd-e3bf576c3a0b", "metadata": {}, "source": [ "The following code uses the `invert_technosphere_matrix` method of the base bw2calc LCA class.\n", "For this method to work correctly, the version of **bw2calc must be**: `>= 2.1`" ] }, { "cell_type": "code", "execution_count": null, "id": "3c81a81f", "metadata": {}, "outputs": [], "source": [ "m_lca.lci()" ] }, { "cell_type": "code", "execution_count": null, "id": "5d54b78f", "metadata": {}, "outputs": [], "source": [ "m_lca.invert_technosphere_matrix()" ] }, { "cell_type": "code", "execution_count": null, "id": "bf0eb968", "metadata": {}, "outputs": [], "source": [ "m_lca.demands" ] }, { "cell_type": "code", "execution_count": null, "id": "cd28247b", "metadata": {}, "outputs": [], "source": [ "matrix_indices = [\n", " {k: m_lca.activity_dict[vk] for vk in v.keys()} for k, v in m_lca.demands.items()\n", "]\n", "matrix_indices" ] }, { "cell_type": "code", "execution_count": null, "id": "11b772c1", "metadata": {}, "outputs": [], "source": [ "m_lca.inverted_technosphere_matrix.shape" ] }, { "cell_type": "code", "execution_count": null, "id": "0db32fdb", "metadata": {}, "outputs": [], "source": [ "demands_inverted = {\n", " k: m_lca.inverted_technosphere_matrix[:, v]\n", " for d in matrix_indices\n", " for k, v in d.items()\n", "}" ] }, { "cell_type": "code", "execution_count": null, "id": "a6ffc3c0", "metadata": {}, "outputs": [], "source": [ "reversed_activity_dict = {v: k for k, v in m_lca.activity_dict.items()}" ] }, { "cell_type": "code", "execution_count": null, "id": "25e91958", "metadata": {}, "outputs": [], "source": [ "matrix_index = [\n", " bd.get_activity(reversed_activity_dict[i])\n", " for i in range(m_lca.inverted_technosphere_matrix.shape[0])\n", "]" ] }, { "cell_type": "code", "execution_count": null, "id": "dc84d376", "metadata": {}, "outputs": [], "source": [ "properties = [\n", " \"name\",\n", " \"unit\",\n", " \"code\",\n", " \"location\",\n", " \"reference product\",\n", " \"type\",\n", " \"database\",\n", " \"id\",\n", "]\n", "df_index = pd.MultiIndex.from_tuples(\n", " [[m[prop] for prop in properties] for m in matrix_index], names=properties\n", ")" ] }, { "cell_type": "code", "execution_count": null, "id": "936533a6", "metadata": {}, "outputs": [], "source": [ "demands_inverted_df = pd.DataFrame(demands_inverted, index=df_index)" ] }, { "cell_type": "code", "execution_count": null, "id": "7f769be2", "metadata": {}, "outputs": [], "source": [ "process_contribution = demands_inverted_df.sort_values(\n", " by=demands_inverted_df.columns[0], ascending=False\n", ")" ] }, { "cell_type": "code", "execution_count": null, "id": "24699522", "metadata": {}, "outputs": [], "source": [ "idx_elec = process_contribution.index.get_level_values(\"name\").str.startswith(\n", " \"electricity production\"\n", ")" ] }, { "cell_type": "code", "execution_count": null, "id": "dff3309c", "metadata": {}, "outputs": [], "source": [ "process_contribution_elec = (\n", " process_contribution.loc[idx_elec]\n", " .sort_index(axis=1)\n", " .droplevel([\"unit\", \"code\", \"reference product\", \"type\", \"database\", \"id\"])\n", ")\n", "process_contribution_elec" ] }, { "cell_type": "code", "execution_count": null, "id": "6e0cb423-2245-4b27-ac81-63b11488213b", "metadata": {}, "outputs": [], "source": [ "country = \"lu\"\n", "threshold = 0.05" ] }, { "cell_type": "code", "execution_count": null, "id": "64c0c714", "metadata": {}, "outputs": [], "source": [ "for country in countries:\n", " process_contribution_elec_c = process_contribution_elec[\n", " [c for c in process_contribution_elec if country in c]\n", " ]\n", "\n", " idx_filt = (process_contribution_elec_c >= threshold).any(axis=1)\n", " mix_to_plot = pd.concat(\n", " [\n", " process_contribution_elec_c.loc[idx_filt],\n", " pd.DataFrame(\n", " process_contribution_elec_c[~idx_filt].sum(), columns=[(\"REST\", \"REST\")]\n", " ).T,\n", " ],\n", " axis=0,\n", " ).T # .droplevel(['code','unit'], axis=0)\n", "\n", " ax = mix_to_plot.plot.bar(stacked=True)\n", " h, l = ax.get_legend_handles_labels()\n", " ax.legend(\n", " loc=\"center left\", bbox_to_anchor=(1.05, 0.5), handles=h[::-1], labels=l[::-1]\n", " )\n", " ax.set_title(\n", " f\"Comparison of background process contribution for electricity-producing activities\\nbetween shrecc and ecoinvent, for location {country}\"\n", " )" ] }, { "cell_type": "markdown", "id": "457256a2", "metadata": {}, "source": [ "Some remarks about the mix analysis.\n", "\n", "1. From the comparison of background processes in Sweden, you can see that the electricity mix done by shrecc contains some aggregated data for hydro electricity. On the Energy Chart API, there is no distinction between the types, and so all hydro (run-off-river, reservoir, hydro pumped storage) is together in one category. Ecoinvent has the different types in the mix.\n", "2. Not all background processes sum to one; we performed our search based on \"electricity production\", and there might be some activities with a different name, still contributing to the electricity mix." ] } ], "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.12.8" } }, "nbformat": 4, "nbformat_minor": 5 }