Skip to content

Commit

Permalink
update ev example in docs
Browse files Browse the repository at this point in the history
  • Loading branch information
TimoDiepers committed Aug 6, 2024
1 parent 1242d25 commit 81d6c90
Showing 1 changed file with 38 additions and 35 deletions.
73 changes: 38 additions & 35 deletions docs/content/examples/example_ev.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"This notebook shows how to use `bw_timex` with a cradle-to-grave case study of an electric vehicle. The case study is simplified, not meant to reflect the complexity of electric mobility but to demonstrate hot to use `bw_timex`.\n",
"This notebook shows how to use `bw_timex` with a cradle-to-grave case study of an electric vehicle. The case study is simplified, not meant to reflect the complexity of electric mobility but to demonstrate hot to use `bw_timex`. \n",
"\n",
"More information on the inner workings of `bw_timex` can be found [here](https://timex.readthedocs.io/en/latest/content/theory.html)."
"More information on the inner workings of `bw_timex` can be found [here](https://timex.readthedocs.io/en/latest/content/theory.html).\n",
"\n",
"\n",
"> **Note:** This is the \"premise\" version of this notebook that works with ecoinvent and premise data. If you don't have access to that, please check out the [\"standalone\" version](https://github.com/brightway-lca/bw_timex/blob/main/notebooks/example_electric_vehicle_standalone.ipynb) of this notebook."
]
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -38,7 +41,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -63,11 +66,12 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"del bd.databases[\"foreground\"] # to make sure we create the foreground from scratch\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.write({}) "
]
Expand All @@ -81,20 +85,16 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"glider_production = bd.get_activity((\"db_2020\", \"133b33cc867081af144475d62179286b\"))\n",
"powertrain_production = bd.get_activity(\n",
" (\"db_2020\", \"f6d3f0b01e4a38c055e3c5c1356a4bba\")\n",
") # eol included\n",
"battery_production = bd.get_activity((\"db_2020\", \"ba87aff6361d99be2636e8c59e55a5b2\"))\n",
"electricity_production = bd.get_activity(\n",
" (\"db_2020\", \"fec93a95a9a84d7fa0ede9c3082bb79f\")\n",
")\n",
"glider_eol = bd.get_activity((\"db_2020\", \"f8114e0ff375b3c6d72ccfa49f79e44d\"))\n",
"battery_eol = bd.get_activity((\"db_2020\", \"82ebcdf42e8512cbe00151dda6210d29\"))"
"glider_production = db_2020.get(name=\"market for glider, passenger car\")\n",
"powertrain_production = db_2020.get(name=\"market for powertrain, for electric passenger car\")\n",
"battery_production = db_2020.get(name=\"battery production, Li-ion, LiMn2O4, rechargeable, prismatic\")\n",
"electricity_production = db_2020.get(name=\"market group for electricity, low voltage\", location=\"GLO\")\n",
"glider_eol = db_2020.get(name=\"market for manual dismantling of used electric passenger car\")\n",
"battery_eol = db_2020.get(name=\"market for used Li-ion battery\")"
]
},
{
Expand All @@ -119,8 +119,8 @@
"metadata": {},
"outputs": [],
"source": [
"fg.new_node(\"EV_lifecycle\", name=\"Electric vehicle, lifecycle\", unit=\"unit\").save()\n",
"ev_lifecycle = fg.get(\"EV_lifecycle\")"
"ev_lifecycle = fg.new_node(\"EV_lifecycle\", name=\"Electric vehicle, lifecycle\", unit=\"unit\")\n",
"ev_lifecycle.save()"
]
},
{
Expand Down Expand Up @@ -359,9 +359,9 @@
"from datetime import datetime\n",
"\n",
"database_date_dict = {\n",
" \"db_2020\": datetime.strptime(\"2020\", \"%Y\"),\n",
" \"db_2030\": datetime.strptime(\"2030\", \"%Y\"),\n",
" \"db_2040\": datetime.strptime(\"2040\", \"%Y\"),\n",
" db_2020.name: datetime.strptime(\"2020\", \"%Y\"),\n",
" db_2030.name: datetime.strptime(\"2030\", \"%Y\"),\n",
" db_2040.name: datetime.strptime(\"2040\", \"%Y\"),\n",
" \"foreground\": \"dynamic\", # flag databases that should be temporally distributed with \"dynamic\"\n",
"}"
]
Expand All @@ -377,14 +377,14 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[0;31mInit signature:\u001b[0m \u001b[0mTimexLCA\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdemand\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmethod\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdatabase_date_dict\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mdict\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m->\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mInit signature:\u001b[0m \u001b[0mTimexLCA\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdemand\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mdict\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmethod\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mtuple\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdatabase_date_dict\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mdict\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m->\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mDocstring:\u001b[0m \n",
"Class to perform time-explicit LCA calculations.\n",
"\n",
Expand All @@ -403,22 +403,25 @@
"\n",
"TimexLCA calculates:\n",
" 1) a static LCA score (`TimexLCA.static_lca.score`, same as `bw2calc.lca.score`),\n",
" 2) a static time-explicit LCA score (`TimexLCA.score`), which links LCIs to the respective background databases but without additional temporal dynamics of the biosphere flows,\n",
" 2) a static time-explicit LCA score (`TimexLCA.static_score`), which links LCIs to the respective background databases but without additional temporal dynamics of the biosphere flows,\n",
" 3) a dynamic time-explicit LCA score (`TimexLCA.dynamic_score`), with dynamic inventory and dynamic charaterization factors. These are provided for radiative forcing and GWP but can also be user-defined.\n",
"\n",
"Example\n",
"-------\n",
">>> demand = {('my_foreground_database', 'my_process'): 1} #replace here with your functinal unit\n",
">>> method = (\"some_method_family\", \"some_category\", \"some_method\") #replace here with your method \n",
">>> database_date_dict = {'my_database': datetime.strptime(\"2020\", \"%Y\"),\n",
" 'my_foreground_database':'dynamic'} #replace here with your database dates\n",
">>> bw_timex = TimexLCA(demand, method, database_date_dict) \n",
">>> demand = {('my_foreground_database', 'my_process'): 1}\n",
">>> method = (\"some_method_family\", \"some_category\", \"some_method\")\n",
">>> database_date_dict = {\n",
" 'my_background_database_one': datetime.strptime(\"2020\", \"%Y\"),\n",
" 'my_background_database_two': datetime.strptime(\"2030\", \"%Y\"),\n",
" 'my_foreground_database':'dynamic'\n",
" }\n",
">>> bw_timex = TimexLCA(demand, method, database_date_dict)\n",
">>> bw_timex.build_timeline() # you can pass many optional arguments here, also for the graph traversal\n",
">>> bw_timex.lci()\n",
">>> bw_timex.static_lcia()\n",
">>> bw_timex.static_score\n",
">>> print(bw_timex.static_score)\n",
">>> bw_timex.dynamic_lcia(metric=\"radiative_forcing\") # different metrics can be used, e.g. \"GWP\", \"radiative_forcing\"\n",
">>> bw_timex.dynamic_score\n",
">>> print(bw_timex.dynamic_score)\n",
"\u001b[0;31mInit docstring:\u001b[0m\n",
"Instantiating a `TimexLCA` object calculates a static LCA, initializes time mapping dicts for activities and biosphere flows, and stores useful subsets of ids in the node_id_collection_dict.\n",
"\n",
Expand All @@ -431,7 +434,7 @@
" Tuple defining the LCIA method, such as `('foo', 'bar')` or default methods, such as `(\"EF v3.1\", \"climate change\", \"global warming potential (GWP100)\")`\n",
"database_date_dict : dict, optional\n",
" Dictionary mapping database names to dates.\n",
"\u001b[0;31mFile:\u001b[0m ~/Documents/Coding/timex/bw_timex/bw_timex.py\n",
"\u001b[0;31mFile:\u001b[0m ~/Documents/Coding/bw_timex/bw_timex/timex_lca.py\n",
"\u001b[0;31mType:\u001b[0m type\n",
"\u001b[0;31mSubclasses:\u001b[0m "
]
Expand Down Expand Up @@ -1601,7 +1604,7 @@
" continue\n",
" exc.input = bd.get_node(\n",
" **{\n",
" \"database\": \"db_2040\",\n",
" \"database\": db_2040.name,\n",
" \"name\": exc.input[\"name\"],\n",
" \"product\": exc.input[\"reference product\"],\n",
" \"location\": exc.input[\"location\"],\n",
Expand Down Expand Up @@ -1717,7 +1720,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.9"
"version": "3.10.14"
}
},
"nbformat": 4,
Expand Down

0 comments on commit 81d6c90

Please sign in to comment.