From 28894a872af076602f0359bbe46a0b8d8ffed83d Mon Sep 17 00:00:00 2001 From: romainsacchi Date: Tue, 3 Oct 2023 16:53:11 +0200 Subject: [PATCH] Update bw2io versioning to 0.8.10 --- dev/Ti-IAM test.ipynb | 1767 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 1767 insertions(+) create mode 100644 dev/Ti-IAM test.ipynb diff --git a/dev/Ti-IAM test.ipynb b/dev/Ti-IAM test.ipynb new file mode 100644 index 00000000..5843c3ca --- /dev/null +++ b/dev/Ti-IAM test.ipynb @@ -0,0 +1,1767 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "id": "6d93e33a-b89e-4e56-bfb7-5a8a0a232053", + "metadata": {}, + "outputs": [], + "source": [ + "from premise import *\n", + "import bw2data\n", + "bw2data.projects.set_current(\"ei39\")" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "10b37313-f780-4102-a6d4-7a813dad9d3f", + "metadata": {}, + "outputs": [], + "source": [ + "scenarios = [\n", + " {\"model\":\"tiam\", \"pathway\":\"SSP2-RCP19\", \"year\":2020, \"filepath\": \"/Users/romain/Downloads/Scenario Files/Production volumes & efficiencies\"}, # optimistic renewable scenario, 2.3-2.8 °C\n", + "]" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "bc61f1aa-81d4-4a83-b7c5-0b10ad1a5b65", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "premise v.(1, 7, 1)\n", + "+------------------------------------------------------------------+\n", + "| Warning |\n", + "+------------------------------------------------------------------+\n", + "| Because some of the scenarios can yield LCI databases |\n", + "| containing net negative emission technologies (NET), |\n", + "| it is advised to account for biogenic CO2 flows when calculating |\n", + "| Global Warming potential indicators. |\n", + "| `premise_gwp` provides characterization factors for such flows. |\n", + "| It also provides factors for hydrogen emissions to air. |\n", + "| |\n", + "| Within your bw2 project: |\n", + "| from premise_gwp import add_premise_gwp |\n", + "| add_premise_gwp() |\n", + "+------------------------------------------------------------------+\n", + "+--------------------------------+----------------------------------+\n", + "| Utils functions | Description |\n", + "+--------------------------------+----------------------------------+\n", + "| clear_cache() | Clears the cache folder. Useful |\n", + "| | when updating `premise`or |\n", + "| | encountering issues with |\n", + "| | inventories. |\n", + "+--------------------------------+----------------------------------+\n", + "| get_regions_definition(model) | Retrieves the list of countries |\n", + "| | for each region of the model. |\n", + "+--------------------------------+----------------------------------+\n", + "| ndb.NewDatabase(...) | Generates a summary of the most |\n", + "| ndb.generate_scenario_report() | important scenarios' variables. |\n", + "+--------------------------------+----------------------------------+\n", + "Keep uncertainty data?\n", + "NewDatabase(..., keep_uncertainty_data=True)\n", + "\n", + "Disable multiprocessing?\n", + "NewDatabase(..., use_multiprocessing=False)\n", + "\n", + "Hide these messages?\n", + "NewDatabase(..., quiet=True)\n", + "\n", + "//////////////////// EXTRACTING SOURCE DATABASE ////////////////////\n", + "Done!\n", + "\n", + "////////////////// IMPORTING DEFAULT INVENTORIES ///////////////////\n", + "Done!\n", + "\n", + "/////////////////////// EXTRACTING IAM DATA ////////////////////////\n", + "Reading /Users/romain/Downloads/Scenario Files/Production volumes & efficiencies/tiam_SSP2-RCP19.xlsx as excel file\n", + "Done!\n" + ] + } + ], + "source": [ + "ndb = NewDatabase(\n", + " scenarios=scenarios,\n", + " source_db=\"ecoinvent 3.9.1 cutoff\",\n", + " source_version=\"3.9.1\",\n", + " use_absolute_efficiency=True,\n", + " #source_type=\"ecospold\",\n", + " #source_file_path=f\"/Users/romain/Documents/ecoinvent 3.9.1_cutoff_ecoSpold02/datasets\", # <-- this is NEW\n", + " #key='tUePmX_S5B8ieZkkM7WUU2CnO8SmShwmAeWK9x2rTFo=',\n", + " #system_model=\"cutoff\",\n", + " #system_args=combinations[0]\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "c7996c75-e3e7-42ba-9ecb-c016b6462109", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "/////////////////////////// ELECTRICITY ////////////////////////////\n", + "Warning: No activities found for Biomass CHP (existing) -- revise mapping.\n", + "Warning: No activities found for Coal USC -- revise mapping.\n", + "Warning: No activities found for Coal USC CCS -- revise mapping.\n", + "Warning: No activities found for Gas GT -- revise mapping.\n", + "{'Biogas CHP': {'heat and power co-generation, biogas, gas engine',\n", + " 'heat and power co-generation, biogas, gas engine, renewable '\n", + " 'energy products'},\n", + " 'Biomass CHP': {'heat and power co-generation, wood chips, 2000 kW',\n", + " 'heat and power co-generation, wood chips, 2000 kW, '\n", + " 'state-of-the-art 2014',\n", + " 'heat and power co-generation, wood chips, 6667 kW',\n", + " 'heat and power co-generation, wood chips, 6667 kW, '\n", + " 'state-of-the-art 2014'},\n", + " 'Biomass CHP (existing)': {'heat and power co-generation, existing, wood '\n", + " 'chips'},\n", + " 'Biomass IGCC': {'electricity production, at biomass-fired IGCC power plant'},\n", + " 'Biomass IGCC CCS': {'electricity production, at biomass-fired IGCC power '\n", + " 'plant, pre, pipeline 200km, storage 1000m'},\n", + " 'Biomass MSW': {'treatment of municipal solid waste, incineration'},\n", + " 'Biomass ST': {'electricity production, at wood burning power plant'},\n", + " 'Biomass ST CCS': {'electricity production, at wood burning power plant, '\n", + " 'post, pipeline 200km, storage 1000m'},\n", + " 'Coal CF 50-50': {'electricity production, at co-firing wood and coal power '\n", + " 'plant, 50-50'},\n", + " 'Coal CF 80-20': {'electricity production, at co-firing wood and coal power '\n", + " 'plant, 80-20'},\n", + " 'Coal CHP': {'heat and power co-generation, hard coal',\n", + " 'heat and power co-generation, lignite'},\n", + " 'Coal IGCC': {'electricity production, at hard coal-fired IGCC power plant',\n", + " 'electricity production, at lignite-fired IGCC power plant'},\n", + " 'Coal IGCC CCS': {'electricity production, at hard coal-fired IGCC power '\n", + " 'plant, pre, pipeline 200km, storage 1000m',\n", + " 'electricity production, at lignite-fired IGCC power plant, '\n", + " 'pre, pipeline 200km, storage 1000m'},\n", + " 'Coal PC': {'electricity production, hard coal',\n", + " 'electricity production, hard coal, conventional',\n", + " 'electricity production, hard coal, subcritical',\n", + " 'electricity production, lignite'},\n", + " 'Coal SC': {'electricity production, hard coal, supercritical'},\n", + " 'Coal USC': {'electricity production, hard coal, ultra-supercritical'},\n", + " 'Coal USC CCS': {'electricity production, at hard coal-fired power plant, '\n", + " 'ultra-super critical, oxy, pipeline 200km, storage 1000m'},\n", + " 'Gas CC': {'electricity production, natural gas, combined cycle power plant'},\n", + " 'Gas CC CCS': {'electricity production, at natural gas-fired combined cycle '\n", + " 'power plant, post, pipeline 200km, storage 1000m'},\n", + " 'Gas CHP': {'heat and power co-generation, natural gas, combined cycle power '\n", + " 'plant, 400MW electrical',\n", + " 'heat and power co-generation, natural gas, conventional power '\n", + " 'plant, 100MW electrical'},\n", + " 'Gas GT': {'electricity production, natural gas, gas turbine, conventional '\n", + " 'power plant'},\n", + " 'Gas OC': {'electricity production, natural gas, conventional power plant'},\n", + " 'Geothermal': {'electricity production, deep geothermal'},\n", + " 'Hydro': {'electricity production, hydro, reservoir, alpine region',\n", + " 'electricity production, hydro, reservoir, non-alpine region',\n", + " 'electricity production, hydro, reservoir, tropical region',\n", + " 'electricity production, hydro, run-of-river'},\n", + " 'Hydro, run-of-river': {'electricity production, hydro, run-of-river'},\n", + " 'Nuclear': {'electricity production, nuclear, boiling water reactor',\n", + " 'electricity production, nuclear, pressure water reactor',\n", + " 'electricity production, nuclear, pressure water reactor, heavy '\n", + " 'water moderated'},\n", + " 'Oil CC': {'electricity production, oil'},\n", + " 'Oil CHP': {'heat and power co-generation, oil'},\n", + " 'Oil ST': {'electricity production, oil'},\n", + " 'Solar CSP': {'electricity production, solar thermal parabolic trough, 50 MW',\n", + " 'electricity production, solar tower power plant, 20 MW'},\n", + " 'Solar PV Centralized': {'electricity production, photovoltaic, commercial'},\n", + " 'Solar PV Residential': {'electricity production, photovoltaic, residential'},\n", + " 'Wave': {'electricity production, wave energy converter'},\n", + " 'Wind Offshore': {'electricity production, wind, 1-3MW turbine, offshore'},\n", + " 'Wind Onshore': {'electricity production, wind, 1-3MW turbine, onshore',\n", + " 'electricity production, wind, <1MW turbine, onshore',\n", + " 'electricity production, wind, >3MW turbine, onshore'}}\n", + "None\n", + "Gas CHP\n", + "Coal USC\n", + "Coal PC\n", + "Biomass CHP (existing)\n", + "Biomass ST\n", + "Biogas CHP\n", + "Biomass MSW\n", + "Biomass IGCC\n", + "Biomass IGCC CCS\n", + "Coal CF 80-20\n", + "Gas GT\n", + "Biomass CHP\n", + "Coal SC\n", + "Gas OC\n", + "Oil CC\n", + "Coal IGCC\n", + "Coal CF 50-50\n", + "Coal IGCC CCS\n", + "Gas CC CCS\n", + "Coal USC CCS\n", + "Oil CHP\n", + "Coal CHP\n", + "Biomass ST CCS\n", + "Gas CC\n", + "Oil ST\n", + "Done!\n", + "\n" + ] + } + ], + "source": [ + "ndb.update_electricity()" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "9cabccc2-a9c3-4056-bfe3-b3093850199b", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Generate change report.\n", + "Report saved under /Users/romain/GitHub/premise/dev.\n" + ] + } + ], + "source": [ + "ndb.generate_change_report()" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "da6f4bbc-8e8f-4cb3-ab73-176ee6d30d10", + "metadata": {}, + "outputs": [], + "source": [ + "import wurst.searching as ws\n", + "name = \"heat and power co-generation, wood chips\"\n", + "ref_prod = \"electricity, high voltage\"\n", + "for d in ws.get_many(\n", + " ndb.database,\n", + " ws.equals(\"name\", name),\n", + " ws.contains(\"reference product\", ref_prod),\n", + "):\n", + " print(d[\"location\"])\n" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "1916650c-fc34-4fde-a918-a34fc3f6111b", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array(['AFR', 'AUS', 'CAN', 'CHI', 'CSA', 'EEU', 'FSU', 'IND', 'JPN',\n", + " 'MEA', 'MEX', 'ODA', 'SKO', 'UK', 'USA', 'WEU', 'World'],\n", + " dtype=object)" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "ndb.scenarios[0][\"iam data\"].production_volumes.region.values" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a85ca090-8d49-42c2-8b21-ffc69fabc12d", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Write new database(s) to Brightway2.\n", + "Database ecoinvent_cutoff_3.9_remind_SSP1-PkBudg500_2030 already exists: it will be overwritten.\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "Writing activities to SQLite3 database:\n", + "0% [##############################] 100% | ETA: 00:00:00\n", + "Total time elapsed: 00:00:56\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Title: Writing activities to SQLite3 database:\n", + " Started: 08/08/2023 13:46:33\n", + " Finished: 08/08/2023 13:47:30\n", + " Total time elapsed: 00:00:56\n", + " CPU %: 99.20\n", + " Memory %: 23.54\n", + "Created database: ecoinvent_cutoff_3.9_remind_SSP1-PkBudg500_2030\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "Writing activities to SQLite3 database:\n", + "0% [########### ] 100% | ETA: 00:00:35" + ] + } + ], + "source": [ + "ndb.write_db_to_brightway()" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "1d863e7b-11ab-417b-96f7-3342529422ad", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "methane, from electrochemical methanation, with carbon from atmospheric carbon dioxide capture RER\n", + "methane, from biological methanation, with carbon from atmospheric carbon dioxide capture RER\n" + ] + } + ], + "source": [ + "for ds in ndb.scenarios[0][\"database\"]:\n", + " for e in ds[\"exchanges\"]:\n", + " if e[\"name\"] == \"carbon dioxide, captured from atmosphere, with a sorbent-based direct air capture system, 100ktCO2\":\n", + " print(ds[\"name\"], ds[\"location\"])" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "407ea861-e723-4fda-9e23-d2c21f01d42a", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Generate change report.\n", + "Report saved under /Users/romain/Github/premise/dev.\n" + ] + } + ], + "source": [ + "ndb.generate_change_report()" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "4247493c-67c4-492c-a124-e3b5590a3c76", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "
<xarray.DataArray 'value' (variables: 2, year: 19)>\n",
+       "array([[9.91877907e-01, 9.90871332e-01, 9.91196756e-01, 9.91188649e-01,\n",
+       "        9.90118025e-01, 9.83021566e-01, 9.75568480e-01, 9.63609588e-01,\n",
+       "        9.43883991e-01, 9.28584201e-01, 9.42510199e-01, 9.59305111e-01,\n",
+       "        9.82257021e-01, 9.97215137e-01, 9.99995102e-01, 9.99995157e-01,\n",
+       "        9.99995735e-01, 9.99999014e-01, 9.99972882e-01],\n",
+       "       [8.12209329e-03, 9.12866826e-03, 8.80324396e-03, 8.81135120e-03,\n",
+       "        9.88197487e-03, 1.69784344e-02, 2.44315195e-02, 3.63904117e-02,\n",
+       "        5.61160093e-02, 7.14157994e-02, 5.74898011e-02, 4.06948892e-02,\n",
+       "        1.77429794e-02, 2.78486319e-03, 4.89775356e-06, 4.84292554e-06,\n",
+       "        4.26532184e-06, 9.86388757e-07, 2.71178968e-05]])\n",
+       "Coordinates:\n",
+       "    region     <U5 'World'\n",
+       "  * variables  (variables) <U11 'natural gas' 'biomethane'\n",
+       "  * year       (year) int64 2005 2010 2015 2020 2025 ... 2100 2110 2130 2150
" + ], + "text/plain": [ + "\n", + "array([[9.91877907e-01, 9.90871332e-01, 9.91196756e-01, 9.91188649e-01,\n", + " 9.90118025e-01, 9.83021566e-01, 9.75568480e-01, 9.63609588e-01,\n", + " 9.43883991e-01, 9.28584201e-01, 9.42510199e-01, 9.59305111e-01,\n", + " 9.82257021e-01, 9.97215137e-01, 9.99995102e-01, 9.99995157e-01,\n", + " 9.99995735e-01, 9.99999014e-01, 9.99972882e-01],\n", + " [8.12209329e-03, 9.12866826e-03, 8.80324396e-03, 8.81135120e-03,\n", + " 9.88197487e-03, 1.69784344e-02, 2.44315195e-02, 3.63904117e-02,\n", + " 5.61160093e-02, 7.14157994e-02, 5.74898011e-02, 4.06948892e-02,\n", + " 1.77429794e-02, 2.78486319e-03, 4.89775356e-06, 4.84292554e-06,\n", + " 4.26532184e-06, 9.86388757e-07, 2.71178968e-05]])\n", + "Coordinates:\n", + " region \u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mndb\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcache\u001b[49m\n", + "\u001b[0;31mAttributeError\u001b[0m: 'NewDatabase' object has no attribute 'cache'" + ] + } + ], + "source": [ + "ndb.scenarios[0]." + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "64ed127c-8fe5-4c6a-853d-b889b91cbc07", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "petrol production, unleaded, petroleum refinery operation IN market for platinum GLO\n", + "pitch production, petroleum refinery operation RoW market for platinum World\n", + "reformate production, petroleum refinery operation RoW market for platinum World\n", + "sulfur production, petroleum refinery operation PE market for platinum GLO\n", + "petroleum coke production, petroleum refinery operation RoW market for platinum World\n", + "heavy fuel oil production, petroleum refinery operation Europe without Switzerland market for platinum GLO\n", + "electricity production, medium voltage, petroleum refinery operation IN market for platinum GLO\n", + "base oil production, petroleum refinery operation BR market for platinum GLO\n", + "electricity production, medium voltage, petroleum refinery operation CO market for platinum GLO\n", + "white spirit production, petroleum refinery operation RoW market for platinum World\n", + "white spirit production, petroleum refinery operation Europe without Switzerland market for platinum GLO\n", + "internal combustion engine production, passenger car GLO market for platinum World\n", + "light fuel oil production, petroleum refinery operation IN market for platinum GLO\n", + "diesel production, low-sulfur, petroleum refinery operation PE market for platinum GLO\n", + "hydrogen production, gaseous, petroleum refinery operation RoW market for platinum World\n", + "reformate production, petroleum refinery operation ZA market for platinum GLO\n", + "catalytic converter production, oxidation, 20 litre RoW market for platinum World\n", + "sulfur production, petroleum refinery operation IN market for platinum GLO\n", + "electric parts production, heat and power co-generation unit, 160kW electrical RER market for platinum GLO\n", + "hydrogen production, gaseous, petroleum refinery operation PE market for platinum GLO\n", + "petroleum slack wax production, petroleum refinery operation BR market for platinum GLO\n", + "fuel cell production, polymer electrolyte membrane, 2kW electrical, future CH market for platinum GLO\n", + "hydrogen production, gaseous, petroleum refinery operation BR market for platinum GLO\n", + "motor scooter production RoW market for platinum World\n", + "naphtha production, petroleum refinery operation CO market for platinum GLO\n", + "fuel cell production, polymer electrolyte membrane, 2kW electrical, future RoW market for platinum World\n", + "refinery gas production, petroleum refinery operation IN market for platinum GLO\n", + "petroleum slack wax production, petroleum refinery operation IN market for platinum GLO\n", + "diesel production, low-sulfur, petroleum refinery operation CO market for platinum GLO\n", + "kerosene production, petroleum refinery operation CO market for platinum GLO\n", + "pitch production, petroleum refinery operation IN market for platinum GLO\n", + "hydrogen production, gaseous, petroleum refinery operation IN market for platinum GLO\n", + "reformate production, petroleum refinery operation Europe without Switzerland market for platinum GLO\n", + "motor scooter production RER market for platinum GLO\n", + "light fuel oil production, petroleum refinery operation PE market for platinum GLO\n", + "heavy fuel oil production, petroleum refinery operation RoW market for platinum World\n", + "white spirit production, petroleum refinery operation ZA market for platinum GLO\n", + "petroleum refinery operation CH market for platinum GLO\n", + "reformate production, petroleum refinery operation PE market for platinum GLO\n", + "petroleum refinery operation CH market for platinum GLO\n", + "light fuel oil production, petroleum refinery operation RoW market for platinum World\n", + "C3 hydrocarbon production, mixture, petroleum refinery operation BR market for platinum GLO\n", + "petroleum refinery operation CH market for platinum GLO\n", + "nuclear power plant construction, pressure water reactor 650MW CA-QC market for platinum GLO\n", + "heavy fuel oil production, petroleum refinery operation PE market for platinum GLO\n", + "petroleum refinery operation CH market for platinum GLO\n", + "petrol production, unleaded, petroleum refinery operation BR market for platinum GLO\n", + "nuclear power plant construction, pressure water reactor 650MW RoW market for platinum World\n", + "ascorbic acid production RoW market for platinum World\n", + "kerosene production, petroleum refinery operation IN market for platinum GLO\n", + "ascorbic acid production RER market for platinum GLO\n", + "reformate production, petroleum refinery operation CO market for platinum GLO\n", + "kerosene production, petroleum refinery operation RoW market for platinum World\n", + "catalytic converter production, oxidation, 20 litre RER market for platinum GLO\n", + "naphtha production, petroleum refinery operation Europe without Switzerland market for platinum GLO\n", + "C3 hydrocarbon production, mixture, petroleum refinery operation IN market for platinum GLO\n", + "white spirit production, petroleum refinery operation IN market for platinum GLO\n", + "diesel production, petroleum refinery operation BR market for platinum GLO\n", + "base oil production, petroleum refinery operation CO market for platinum GLO\n", + "petroleum coke production, petroleum refinery operation Europe without Switzerland market for platinum GLO\n", + "electricity production, medium voltage, petroleum refinery operation RoW market for platinum World\n", + "sulfur production, petroleum refinery operation BR market for platinum GLO\n", + "electric parts production, heat and power co-generation unit, 160kW electrical RoW market for platinum World\n", + "sodium perchlorate production GLO market for platinum World\n", + "hydrogen production, gaseous, petroleum refinery operation ZA market for platinum GLO\n", + "diesel production, low-sulfur, petroleum refinery operation BR market for platinum GLO\n", + "refinery gas production, petroleum refinery operation ZA market for platinum GLO\n", + "pitch production, petroleum refinery operation CO market for platinum GLO\n", + "refinery gas production, petroleum refinery operation Europe without Switzerland market for platinum GLO\n", + "catalytic converter production, three-way, 19.1l RoW market for platinum World\n", + "maintenance, polymer electrolyte membrane fuel cell 2kW electrical CH market for platinum GLO\n", + "electric parts production, mini CHP plant CH market for platinum GLO\n", + "fuel cell production, stack polymer electrolyte membrane, 2kW electrical, future RoW market for platinum World\n", + "petrol production, unleaded, petroleum refinery operation PE market for platinum GLO\n", + "petroleum slack wax production, petroleum refinery operation ZA market for platinum GLO\n", + "diesel production, low-sulfur, petroleum refinery operation ZA market for platinum GLO\n", + "white spirit production, petroleum refinery operation BR market for platinum GLO\n", + "light fuel oil production, petroleum refinery operation ZA market for platinum GLO\n", + "white spirit production, petroleum refinery operation PE market for platinum GLO\n", + "hydrogen production, gaseous, petroleum refinery operation CO market for platinum GLO\n", + "light fuel oil production, petroleum refinery operation BR market for platinum GLO\n", + "heavy fuel oil production, petroleum refinery operation IN market for platinum GLO\n", + "fuel cell production, stack polymer electrolyte membrane, 2kW electrical, future CH market for platinum GLO\n", + "sulfur production, petroleum refinery operation ZA market for platinum GLO\n", + "white spirit production, petroleum refinery operation CO market for platinum GLO\n", + "refinery gas production, petroleum refinery operation CO market for platinum GLO\n", + "petroleum coke production, petroleum refinery operation ZA market for platinum GLO\n", + "base oil production, petroleum refinery operation PE market for platinum GLO\n", + "diesel production, petroleum refinery operation PE market for platinum GLO\n", + "naphtha production, petroleum refinery operation IN market for platinum GLO\n", + "heavy fuel oil production, petroleum refinery operation BR market for platinum GLO\n", + "petroleum slack wax production, petroleum refinery operation CO market for platinum GLO\n", + "maintenance, polymer electrolyte membrane fuel cell 2kW electrical RoW market for platinum World\n", + "refinery gas production, petroleum refinery operation RoW market for platinum World\n", + "pitch production, petroleum refinery operation ZA market for platinum GLO\n", + "diesel production, low-sulfur, petroleum refinery operation IN market for platinum GLO\n", + "pitch production, petroleum refinery operation Europe without Switzerland market for platinum GLO\n", + "pitch production, petroleum refinery operation PE market for platinum GLO\n", + "power saw production, with catalytic converter GLO market for platinum World\n", + "kerosene production, petroleum refinery operation ZA market for platinum GLO\n", + "pitch production, petroleum refinery operation BR market for platinum GLO\n", + "naphtha production, petroleum refinery operation ZA market for platinum GLO\n", + "petroleum slack wax production, petroleum refinery operation RoW market for platinum World\n", + "base oil production, petroleum refinery operation RoW market for platinum World\n", + "liquefied petroleum gas production, petroleum refinery operation CO market for platinum GLO\n", + "diesel production, petroleum refinery operation RoW market for platinum World\n", + "C3 hydrocarbon production, mixture, petroleum refinery operation Europe without Switzerland market for platinum GLO\n", + "liquefied petroleum gas production, petroleum refinery operation Europe without Switzerland market for platinum GLO\n", + "petroleum refinery operation CH market for platinum GLO\n", + "light fuel oil production, petroleum refinery operation CO market for platinum GLO\n", + "base oil production, petroleum refinery operation Europe without Switzerland market for platinum GLO\n", + "base oil production, petroleum refinery operation IN market for platinum GLO\n", + "liquefied petroleum gas production, petroleum refinery operation RoW market for platinum World\n", + "petroleum slack wax production, petroleum refinery operation PE market for platinum GLO\n", + "liquefied petroleum gas production, petroleum refinery operation PE market for platinum GLO\n", + "light fuel oil production, petroleum refinery operation Europe without Switzerland market for platinum GLO\n", + "C3 hydrocarbon production, mixture, petroleum refinery operation CO market for platinum GLO\n", + "liquefied petroleum gas production, petroleum refinery operation BR market for platinum GLO\n", + "heavy fuel oil production, petroleum refinery operation CO market for platinum GLO\n", + "reformate production, petroleum refinery operation BR market for platinum GLO\n", + "reformate production, petroleum refinery operation IN market for platinum GLO\n", + "liquefied petroleum gas production, petroleum refinery operation IN market for platinum GLO\n", + "control cabinet production, heat and power co-generation unit, 160kW electrical RER market for platinum GLO\n", + "petroleum slack wax production, petroleum refinery operation Europe without Switzerland market for platinum GLO\n", + "control cabinet production, heat and power co-generation unit, 160kW electrical RoW market for platinum World\n", + "C3 hydrocarbon production, mixture, petroleum refinery operation PE market for platinum GLO\n", + "petroleum refinery operation CH market for platinum GLO\n", + "sulfur production, petroleum refinery operation RoW market for platinum World\n", + "diesel production, petroleum refinery operation ZA market for platinum GLO\n", + "diesel production, petroleum refinery operation CO market for platinum GLO\n", + "C3 hydrocarbon production, mixture, petroleum refinery operation ZA market for platinum GLO\n", + "kerosene production, petroleum refinery operation BR market for platinum GLO\n", + "refinery gas production, petroleum refinery operation PE market for platinum GLO\n", + "platinum to generic market for metal catalyst for catalytic converter GLO market for platinum World\n", + "petrol production, unleaded, petroleum refinery operation ZA market for platinum GLO\n", + "naphtha production, petroleum refinery operation BR market for platinum GLO\n", + "C3 hydrocarbon production, mixture, petroleum refinery operation RoW market for platinum World\n", + "base oil production, petroleum refinery operation ZA market for platinum GLO\n", + "hydrogen production, gaseous, petroleum refinery operation Europe without Switzerland market for platinum GLO\n", + "diesel production, petroleum refinery operation IN market for platinum GLO\n", + "electricity production, medium voltage, petroleum refinery operation Europe without Switzerland market for platinum GLO\n", + "naphtha production, petroleum refinery operation PE market for platinum GLO\n", + "catalytic converter production, three-way, 19.1l RER market for platinum GLO\n", + "liquefied petroleum gas production, petroleum refinery operation ZA market for platinum GLO\n", + "electric parts production, mini CHP plant RoW market for platinum World\n", + "refinery gas production, petroleum refinery operation BR market for platinum GLO\n", + "heavy fuel oil production, petroleum refinery operation ZA market for platinum GLO\n", + "diesel production, petroleum refinery operation Europe without Switzerland market for platinum GLO\n", + "sulfur production, petroleum refinery operation CO market for platinum GLO\n", + "diesel production, low-sulfur, petroleum refinery operation Europe without Switzerland market for platinum GLO\n", + "naphtha production, petroleum refinery operation RoW market for platinum World\n", + "kerosene production, petroleum refinery operation PE market for platinum GLO\n", + "kerosene production, petroleum refinery operation Europe without Switzerland market for platinum GLO\n", + "petrol production, unleaded, petroleum refinery operation Europe without Switzerland market for platinum GLO\n", + "petrol production, unleaded, petroleum refinery operation RoW market for platinum World\n", + "diesel production, low-sulfur, petroleum refinery operation RoW market for platinum World\n", + "petrol production, unleaded, petroleum refinery operation CO market for platinum GLO\n", + "sulfur production, petroleum refinery operation Europe without Switzerland market for platinum GLO\n", + "electrolyzer production, 1MWe, PEM, Stack RER market for platinum GLO\n", + "hydrogenation of hydrogen RER market for platinum GLO\n", + "dehydrogenation of hydrogen RER market for platinum GLO\n", + "fuel cell stack production, 1 kWe, proton exchange membrane (PEM) GLO market for platinum World\n", + "market for platinum World market for platinum World\n" + ] + } + ], + "source": [ + "for ds in ndb.scenarios[0][\"database\"]:\n", + " for e in ds[\"exchanges\"]:\n", + " if e[\"name\"] == \"market for platinum\" and e[\"product\"] == \"platinum\":\n", + " print(ds[\"name\"], ds[\"location\"], e[\"name\"], e[\"location\"])" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "d751e8eb-0534-445c-b034-f3f338d62c36", + "metadata": {}, + "outputs": [], + "source": [ + "import pprint\n", + "for ds in ndb.scenarios[0][\"database\"]:\n", + " if ds[\"name\"].lower() == \"lithium carbonate, precipitated\":\n", + " print(ds[\"name\"], ds[\"location\"])" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "c7b54985-0f01-4bea-b19a-cbb655a88084", + "metadata": {}, + "outputs": [], + "source": [ + "from premise.activity_maps import InventorySet\n", + "inv = InventorySet(ndb.database, \"3.9\")" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "a54f1930-02ac-4de9-aaab-4eb14efa978f", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'Dysprosium': {'Dysprosium'},\n", + " 'Neodymium': {'Neodymium, 4% in bastnasite, 0.4% in crude ore'},\n", + " 'Nickel': {'Nickel',\n", + " 'Nickel, 1.13% in sulfide, Ni 0.76% and Cu 0.76% in crude ore',\n", + " 'Nickel, 1.98% in silicates, 1.04% in crude ore',\n", + " 'Nickel, Ni 2.5E+0%, in mixed ore'},\n", + " 'Manganese': {'Manganese',\n", + " 'Manganese, 35.7% in sedimentary deposit, 14.2% in crude ore'},\n", + " 'Yttrium': {'Yttrium'},\n", + " 'Vanadium': {'Vanadium'},\n", + " 'Cobalt': {'Cobalt', 'Cobalt, Co 5.0E-2%, in mixed ore'},\n", + " 'Lithium': {'Lithium', 'Lithium, 0.15% in brine'},\n", + " 'Sulfur': {'Sulfur'},\n", + " 'Platinum': {'Platinum', 'Platinum, Pt 4.7E-7%, in mixed ore'},\n", + " 'Cerium': {'Cerium', 'Cerium, 24% in bastnasite, 2.4% in crude ore'},\n", + " 'Lanthanum': {'Lanthanum',\n", + " 'Lanthanum, 7.2% in bastnasite, 0.72% in crude ore'},\n", + " 'Zirconium': {'Zirconium', 'Zirconium, 50% in zircon, 0.39% in crude ore'},\n", + " 'Gadolinium': {'Gadolinium',\n", + " 'Gadolinium, 0.15% in bastnasite, 0.015% in crude ore'},\n", + " 'Scandium': {'Scandium'},\n", + " 'Strontium': {'Strontium'},\n", + " 'Potassium': {'Potassium'},\n", + " 'Iridium': {'Iridium'},\n", + " 'Silver': {'Silver',\n", + " 'Silver, 0.007% in sulfide, Ag 0.004%, Pb, Zn, Cd, In',\n", + " 'Silver, 0.01% in crude ore',\n", + " 'Silver, 3.2ppm in sulfide, Ag 1.2ppm, Cu and Te, in crude ore',\n", + " 'Silver, Ag 1.5E-4%, Au 6.8E-4%, in ore',\n", + " 'Silver, Ag 1.5E-5%, Au 5.4E-4%, in ore',\n", + " 'Silver, Ag 1.8E-6%, in mixed ore',\n", + " 'Silver, Ag 2.1E-4%, Au 2.1E-4%, in ore',\n", + " 'Silver, Ag 4.2E-3%, Au 1.1E-4%, in ore',\n", + " 'Silver, Ag 4.6E-5%, Au 1.3E-4%, in ore',\n", + " 'Silver, Ag 5.4E-3%, in mixed ore',\n", + " 'Silver, Ag 7.6E-5%, Au 9.7E-5%, in ore',\n", + " 'Silver, Ag 9.7E-4%, in mixed ore'},\n", + " 'Germanium': {'Germanium'},\n", + " 'Indium': {'Indium', 'Indium, 0.005% in sulfide, In 0.003%, Pb, Zn, Ag, Cd'},\n", + " 'Gallium': {'Gallium', 'Gallium, 0.014% in bauxite'},\n", + " 'Selenium': {'Selenium'},\n", + " 'Cadmium': {'Cadmium', 'Cadmium, 0.30% in sulfide, Cd 0.18%, Pb, Zn, Ag, In'},\n", + " 'Tellurium': {'Tellurium',\n", + " 'Tellurium, 0.5ppm in sulfide, Te 0.2ppm, Cu and Ag, in crude ore'}}" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "inv.generate_metals_map()" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "daa5d530-fbfc-470c-a06b-0e9103860aa3", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'Biomass CHP': {'heat and power co-generation, wood chips, 2000 kW',\n", + " 'heat and power co-generation, wood chips, 2000 kW, state-of-the-art 2014',\n", + " 'heat and power co-generation, wood chips, 6667 kW',\n", + " 'heat and power co-generation, wood chips, 6667 kW, state-of-the-art 2014',\n", + " 'heat and power co-generation, wood chips, 6667 kW, state-of-the-art 2014, renewable energy products'},\n", + " 'Biomass CHP CCS': {'electricity production, at co-generation power plant/wood, post, pipeline 200km, storage 1000m',\n", + " 'electricity production, at co-generation power plant/wood, post, pipeline 400km, storage 3000m'},\n", + " 'Biomass ST': {'electricity production, at wood burning power plant 20 MW, truck 25km, no CCS'},\n", + " 'Biomass IGCC CCS': {'electricity production, at BIGCC power plant, pre, pipeline 200km, storage 1000m',\n", + " 'electricity production, at wood burning power plant 20 MW, truck 25km, post, pipeline 200km, storage 1000m'},\n", + " 'Biomass IGCC': {'electricity production, at BIGCC power plant, no CCS'},\n", + " 'Coal PC': {'electricity production, hard coal',\n", + " 'electricity production, hard coal, at coal mine power plant',\n", + " 'electricity production, hard coal, conventional',\n", + " 'electricity production, hard coal, supercritical',\n", + " 'electricity production, lignite'},\n", + " 'Coal IGCC': {'electricity production, at power plant/hard coal, IGCC, no CCS',\n", + " 'electricity production, at power plant/lignite, IGCC, no CCS'},\n", + " 'Coal PC CCS': {'electricity production, at power plant/hard coal, post, pipeline 200km, storage 1000m',\n", + " 'electricity production, at power plant/lignite, post, pipeline 200km, storage 1000m'},\n", + " 'Coal IGCC CCS': {'electricity production, at power plant/hard coal, pre, pipeline 200km, storage 1000m',\n", + " 'electricity production, at power plant/lignite, pre, pipeline 200km, storage 1000m'},\n", + " 'Coal CHP': {'heat and power co-generation, hard coal',\n", + " 'heat and power co-generation, lignite'},\n", + " 'Coal CHP CCS': {'electricity production, at co-generation power plant/hard coal, oxy, pipeline 200km, storage 1000m',\n", + " 'electricity production, at co-generation power plant/hard coal, oxy, pipeline 400km, storage 3000m',\n", + " 'electricity production, at co-generation power plant/hard coal, post, pipeline 200km, storage 1000m',\n", + " 'electricity production, at co-generation power plant/hard coal, post, pipeline 400km, storage 1000m',\n", + " 'electricity production, at co-generation power plant/hard coal, post, pipeline 400km, storage 3000m'},\n", + " 'Gas OC': {'electricity production, natural gas, conventional power plant'},\n", + " 'Gas CC': {'electricity production, natural gas, combined cycle power plant'},\n", + " 'Gas CHP': {'heat and power co-generation, natural gas, combined cycle power plant, 400MW electrical',\n", + " 'heat and power co-generation, natural gas, conventional power plant, 100MW electrical'},\n", + " 'Gas CHP CCS': {'electricity production, at co-generation power plant/natural gas, post, pipeline 200km, storage 1000m',\n", + " 'electricity production, at co-generation power plant/natural gas, pre, pipeline 200km, storage 1000m'},\n", + " 'Gas CC CCS': {'electricity production, at power plant/natural gas, post, pipeline 200km, storage 1000m',\n", + " 'electricity production, at power plant/natural gas, post, pipeline 400km, storage 1000m',\n", + " 'electricity production, at power plant/natural gas, post, pipeline 400km, storage 3000m',\n", + " 'electricity production, at power plant/natural gas, pre, pipeline 200km, storage 1000m',\n", + " 'electricity production, at power plant/natural gas, pre, pipeline 400km, storage 3000m'},\n", + " 'Geothermal': {'electricity production, deep geothermal'},\n", + " 'Hydro': {'electricity production, hydro, reservoir, alpine region',\n", + " 'electricity production, hydro, reservoir, alpine region, renewable energy products',\n", + " 'electricity production, hydro, reservoir, non-alpine region',\n", + " 'electricity production, hydro, reservoir, tropical region',\n", + " 'electricity production, hydro, run-of-river',\n", + " 'electricity production, hydro, run-of-river, renewable energy products'},\n", + " 'Nuclear': {'electricity production, nuclear, boiling water reactor',\n", + " 'electricity production, nuclear, pressure water reactor',\n", + " 'electricity production, nuclear, pressure water reactor, heavy water moderated'},\n", + " 'Nuclear_EPR': {'electricity production, Evolutionary Power Reactor (EPR)'},\n", + " 'Nuclear_SMR': {'electricity production, Small Modular Reactor (SMR)'},\n", + " 'Oil ST': {'electricity production, oil'},\n", + " 'Oil CC': {'electricity production, oil'},\n", + " 'Oil CC CCS': {'electricity production, at co-generation power plant/oil, post, pipeline 200km, storage 1000m',\n", + " 'electricity production, at co-generation power plant/oil, pre, pipeline 200km, storage 1000m'},\n", + " 'Oil CHP': {'heat and power co-generation, oil'},\n", + " 'Oil CHP CCS': {'electricity production, at co-generation power plant/oil, post, pipeline 200km, storage 1000m',\n", + " 'electricity production, at co-generation power plant/oil, pre, pipeline 200km, storage 1000m'},\n", + " 'Solar CSP': {'electricity production, solar thermal parabolic trough, 50 MW',\n", + " 'electricity production, solar tower power plant, 20 MW'},\n", + " 'Solar PV Centralized': {'electricity production, photovoltaic, commercial'},\n", + " 'Solar PV Residential': {'electricity production, photovoltaic, residential'},\n", + " 'Wind Onshore': {'electricity production, wind, 1-3MW turbine, onshore',\n", + " 'electricity production, wind, 1-3MW turbine, onshore, renewable energy products',\n", + " 'electricity production, wind, <1MW turbine, onshore',\n", + " 'electricity production, wind, <1MW turbine, onshore, renewable energy products',\n", + " 'electricity production, wind, >3MW turbine, onshore',\n", + " 'electricity production, wind, >3MW turbine, onshore, renewable energy products'},\n", + " 'Wind Offshore': {'electricity production, wind, 1-3MW turbine, offshore'},\n", + " 'Wave': {'electricity production, wave energy converter'}}" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "inv.generate_powerplant_map()" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "2c8f798d-7404-4c6d-8764-ada72f72e42d", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'dac_solvent': {'carbon dioxide, captured from atmosphere, with a solvent-based direct air capture system, 1MtCO2'},\n", + " 'dac_sorbent': {'carbon dioxide, captured from atmosphere, with a sorbent-based direct air capture system, 100ktCO2'},\n", + " 'daccs_solvent': {'carbon dioxide, captured from atmosphere and stored, with a solvent-based direct air capture system, 1MtCO2'},\n", + " 'daccs_sorbent': {'carbon dioxide, captured from atmosphere and stored, with a sorbent-based direct air capture system, 100ktCO2'}}" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "inv.generate_daccs_map()" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "5da69f1b-31f9-4687-b8e7-b48207dfae56", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Write new database(s) to Brightway2.\n", + "Prepare database 1.\n", + "- check for duplicates...\n", + "One or multiple duplicates detected. Removing them...\n", + "- check for values format...\n", + "- relinking exchanges...\n", + "Done!\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "Writing activities to SQLite3 database:\n", + "0% [##############################] 100% | ETA: 00:00:00\n", + "Total time elapsed: 00:00:31\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Title: Writing activities to SQLite3 database:\n", + " Started: 06/19/2023 12:11:07\n", + " Finished: 06/19/2023 12:11:38\n", + " Total time elapsed: 00:00:31\n", + " CPU %: 86.50\n", + " Memory %: 11.62\n", + "Created database: test_metals\n", + "Generate scenario report.\n", + "Report saved under /Users/romain/GitHub/premise/dev/export/scenario_report.\n", + "Generate change report.\n", + "Report saved under /Users/romain/GitHub/premise/dev.\n" + ] + } + ], + "source": [ + "ndb.write_db_to_brightway(\"test_metals\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "fb809bb4-77c3-4e57-98a0-bbc15e3b7115", + "metadata": {}, + "outputs": [], + "source": [ + "products = [\n", + " 'lightweighting, glider',\n", + " 'auxilliary battery inputs, for road vehicle',\n", + " 'battery cell, Li-ion, NMC622',\n", + " 'auxilliary electronics inputs, for fuel cell electric vehicle',\n", + " 'auxilliary material inputs, for fuel cell electric vehicle',\n", + " 'fuel cell stack, for fuel cell electric vehicle',\n", + " 'carbon fiber, weaved',\n", + " 'tank liner, polyethylene, high density',\n", + " 'transformer and rectifier unit, for electrolyser',\n", + " 'fuel tank, for diesel road vehicle',\n", + " 'fuel tank, for compressed hydrogen gas, 700bar',\n", + " 'fuel tank, for compressed hydrogen gas, 700bar',\n", + " 'fuel tank, for compressed hydrogen gas, 700bar',\n", + " 'fuel tank, for compressed natural gas, 200 bar',\n", + " 'charger, level 3, plugin, 200 kW, for electric vehicle',\n", + " 'gearbox, for lorry',\n", + " 'transmission, for lorry',\n", + " 'suspension, for lorry',\n", + " 'power electronics, for lorry',\n", + " 'auxilliary material inputs, for electric lorry',\n", + " 'retarder, for lorry',\n", + " 'cabin, for lorry',\n", + " 'frame, blanks and saddle, for lorry',\n", + " 'tires and wheels, for lorry',\n", + " 'auxilliary material inputs, for hydrid electric lorry',\n", + " 'exhaust system, for lorry',\n", + " 'internal combustion engine, for lorry',\n", + " 'lead acid battery, for lorry',\n", + " 'charger, level 3, with pantograph, 450 kW, for electric vehicle',\n", + " 'overhead lines, for electric vehicle',\n", + " 'battery cell, Li-ion, LTO',\n", + " 'charging station, 3kW',\n", + " 'battery cell,  Li-ion, LFP',\n", + " 'battery cell, Li-ion, NCA',\n", + " 'assembly operation, for lorry'\n", + "]\n", + "\n", + "print(len(products))\n", + "\n", + "acts = [a for a in bw.Database(\"brian\") if a[\"reference product\"] in products]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "2fe0b434-3bf6-4966-8b32-4a8edc4fa4a9", + "metadata": {}, + "outputs": [], + "source": [ + "len(acts)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "bbb39e2b-407c-4322-bcdb-d1052d752269", + "metadata": {}, + "outputs": [], + "source": [ + "[a[\"reference product\"] for a in acts]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "da6140c8-de76-4652-adc2-71eb503db0ad", + "metadata": {}, + "outputs": [], + "source": [ + "import bw2data\n", + "bw2io.BW2Package.export_obj(obj=bw.Database(\"brian\"), filename=\"db_for_brian.bw2package\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "064e659a-3099-4873-95f7-58cfd38b182a", + "metadata": {}, + "outputs": [], + "source": [ + "import bw2data\n", + "bw2io.BW2Package.import_file(\"db_for_brian.bw2package\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "72c77405-f7ce-4bb5-ba51-25da01464e38", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "99d0e38d-2076-43bf-89b5-0f1eb0b2c517", + "metadata": {}, + "outputs": [], + "source": [ + "fp = \"/Users/romain/Library/Application Support/Brightway3/ei39.f1469ad5eb0a071dc60323f6e0fce980/output/lci-brian.xlsx\"\n", + "import bw2io\n", + "\n", + "i = bw2io.ExcelImporter(fp)\n", + "i.apply_strategies()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6e1c7c26-2f03-4f08-a51f-e49dd9a24654", + "metadata": {}, + "outputs": [], + "source": [ + "ei_acts = list(set([(a[\"name\"], a[\"reference product\"]) for a in bw.Database(\"ecoinvent 3.9.1 cutoff\")]))\n", + "print(len(ei_acts))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c7e00458-5c8f-4020-b572-217edbcd99b0", + "metadata": {}, + "outputs": [], + "source": [ + "for ds in i.data:\n", + " if (ds[\"name\"], ds[\"reference product\"]) in ei_acts:\n", + " i.data.remove(ds)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3b401e2d-00ac-436c-9790-4d2993b34d5c", + "metadata": {}, + "outputs": [], + "source": [ + "for ds in i.data:\n", + " if (ds[\"name\"], ds[\"reference product\"]) not in ei_acts:\n", + " print(ds[\"name\"])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "14c845d0-bec2-422a-b45f-65449cfee617", + "metadata": {}, + "outputs": [], + "source": [ + "len(i.data)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "aae4a053-361c-467f-b2bf-8e0ec296825d", + "metadata": {}, + "outputs": [], + "source": [ + "for ds in i.data:\n", + " print(ds[\"name\"])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b925692a-0ea5-4d81-ab0d-f372ed885066", + "metadata": {}, + "outputs": [], + "source": [ + "i.match_database(fields=[\"name\", \"unit\", \"location\"])\n", + "i.match_database(\"ecoinvent 3.9.1 cutoff\", fields=[\"name\", \"reference product\", \"location\", \"unit\"])\n", + "i.match_database(\"biosphere3\", fields=[\"name\", \"categories\", \"unit\"])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c11cbab3-54d4-4b5f-95af-c884c132cf71", + "metadata": {}, + "outputs": [], + "source": [ + "i.statistics()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a9c2561c-04b2-40ff-9260-e98001d18182", + "metadata": {}, + "outputs": [], + "source": [ + "list(i.unlinked)[-1]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ce5a2786-ca13-4da6-ab1f-a1e8851d13cd", + "metadata": {}, + "outputs": [], + "source": [ + "bw.get_activity(('brian', '360c5e612a154ebb8cee2650bcc1bc75_copy1'))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "63f69aa3-ab14-4301-8ad7-5ed044bc1ec0", + "metadata": {}, + "outputs": [], + "source": [ + "for f in bw.Database(\"biosphere3\"):\n", + " if f[\"code\"] == \"e030108f-2125-4bcb-a73b-ad72130fcca3\":\n", + " print(f)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "834f3044-a3eb-4527-8c36-cbfdc92cf312", + "metadata": {}, + "outputs": [], + "source": [ + "bw.projects.set_current(\"ei39\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "bdf5d023-c454-47cb-8a7f-254ab7aa95a1", + "metadata": {}, + "outputs": [], + "source": [ + "l = []\n", + "\n", + "for f in bw.Database(\"biosphere3\"):\n", + " l.append([f[\"name\"], f[\"categories\"][0], f[\"categories\"][1] if len(f[\"categories\"])>1 else \"unspecified\", f[\"unit\"], f[\"code\"]])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "523e3465-6669-481f-a549-667c79eb75e0", + "metadata": {}, + "outputs": [], + "source": [ + "import csv\n", + "\n", + "with open(\"flows_biosphere_39.csv\", \"w\", newline=\"\", ) as f:\n", + " writer = csv.writer(f, delimiter=\";\")\n", + " writer.writerows(l)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "66dd7104-57aa-4338-945e-c005711a8e72", + "metadata": {}, + "outputs": [], + "source": [ + "ndb.scenarios[1][\"iam data\"].fuel_markets.sel(region=\"NEU\").variables.values" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "07410afa-636e-4960-b73a-09d4b472ca32", + "metadata": {}, + "outputs": [], + "source": [ + "import numpy as np\n", + "for ds in ndb.scenarios[1][\"database\"]:\n", + " if ds[\"name\"] == (\"carbon dioxide, captured from atmosphere, with a solvent-based direct air capture system, 1MtCO2, with waste heat, and grid electricity\",\n", + " \"carbon dioxide, captured from atmosphere\"):\n", + " print(ds[\"name\"], ds[\"location\"])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "38db0088-294b-4fe4-9476-5e3ad1928b1e", + "metadata": {}, + "outputs": [], + "source": [ + "for ds in ndb.scenarios[1][\"database\"]:\n", + " if \"carbon dioxide, captured\" in ds[\"name\"]:\n", + " print(ds[\"name\"], ds[\"location\"])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "225fc5ae-a809-4f4f-86aa-bfeadfd8f9a3", + "metadata": {}, + "outputs": [], + "source": [ + "ndb.scenarios[0][\"iam data\"].fuel_markets.sel(region=\"WEU\", year=2050)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c119f58f-7c7f-4ae3-9ed1-da5d66e117f4", + "metadata": {}, + "outputs": [], + "source": [ + "ndb.scenarios[0][\"iam data\"].fuel_markets.sel(region=\"WEU\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "eda800d6-71a9-44ac-96d9-5b08f3a1bdd5", + "metadata": {}, + "outputs": [], + "source": [ + "ndb.update_electricity()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3a6b893a-288b-4efd-861c-4c076ec833d5", + "metadata": {}, + "outputs": [], + "source": [ + "ndb.scenarios[0][\"iam data\"].fuel_markets" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "cf5554a4-3f00-41e8-8c7d-93fea7d7fb96", + "metadata": {}, + "outputs": [], + "source": [ + "ndb.generate_scenario_report()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "54cf2fb0-3d72-4b55-91dd-99111c1e56b5", + "metadata": {}, + "outputs": [], + "source": [ + "ndb.generate_change_report()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d6308c7c-d6b3-4f3a-bbae-51ee3ca647ac", + "metadata": {}, + "outputs": [], + "source": [ + "ndb.update_all()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "0a4df5b8-f080-4c5f-9f89-85b60f1ef901", + "metadata": {}, + "outputs": [], + "source": [ + "ndb.generate_scenario_report()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c3befdd3-1c6b-4ea3-a2e5-ac6a00bd4256", + "metadata": {}, + "outputs": [], + "source": [ + "ndb.generate_change_report()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "71a07af3-cea2-4ed1-9ce2-df129cc610ae", + "metadata": {}, + "outputs": [], + "source": [ + "ndb.scenarios[0][\"iam data\"].gains_data_IAM" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "0a65551d-3511-46d5-9d1d-bca62464349a", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b985c91f-f574-467e-91e7-06cf0914dec4", + "metadata": {}, + "outputs": [], + "source": [ + "ndb.update_all()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9bb2ac11-7da7-4c39-b87b-7aa1a66ef4b0", + "metadata": {}, + "outputs": [], + "source": [ + "ndb.write_db_to_brightway([\"test_dac\", \"test_dac2\"])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "bf88e9fc-4599-4de0-b926-5c8d3769a578", + "metadata": {}, + "outputs": [], + "source": [ + "from premise.geomap import Geomap" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a30fd37c-1a81-489b-877d-fe1073eb4106", + "metadata": {}, + "outputs": [], + "source": [ + "Geomap()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8b173e59-c5d2-444c-b287-8b5ee262fa47", + "metadata": {}, + "outputs": [], + "source": [ + "Geomap(model=\"remind\").geo.keys()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d20965c2-7b61-4488-bf78-9e268fc44471", + "metadata": {}, + "outputs": [], + "source": [ + "ndb.scenarios[0][\"iam data\"].carbon_capture_rate.sel(variables=\"steel\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "672acf43-2f1a-4154-8d0f-5366b0490acd", + "metadata": {}, + "outputs": [], + "source": [ + "for ds in ndb.scenarios[0][\"database\"]:\n", + " for e in ds[\"exchanges\"]:\n", + " if e[\"name\"].startswith(\"CO2 capture, at cement production plant\"):\n", + " print(e[\"name\"], e.get(\"location\"), e[\"amount\"])\n", + " print(ds[\"name\"])\n", + " print(\"--------------------\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "78d7a866-3371-42e5-b1d2-6b8df2a801a4", + "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.12" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}