generated from jupyterlite/xeus-python-demo
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
131332e
commit bae34cf
Showing
6 changed files
with
1,363 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,257 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"metadata": { | ||
"trusted": true | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"import micropip" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"We need to patch [pyfilesystem2](https://docs.pyfilesystem.org/en/latest/index.html) because pyodide currently doesn't implement all of the standard library. See [#38](https://github.com/brightway-lca/brightway-live/issues/38)." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 4, | ||
"metadata": { | ||
"trusted": true | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"await micropip.install(\n", | ||
" 'https://files.brightway.dev/fs-2.5.1-py2.py3-none-any.whl'\n", | ||
")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Manually set the directory where data is stored to avoid errors related to the browser virtual filesystem." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 5, | ||
"metadata": { | ||
"trusted": true | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"import os\n", | ||
"os.environ[\"BRIGHTWAY_DIR\"] = \"/tmp/\"" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 6, | ||
"metadata": { | ||
"trusted": true | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"await micropip.install('bw2data==4.0.dev29', keep_going = True)\n", | ||
"await micropip.install('bw2io==0.9.dev23', keep_going = True)\n", | ||
"await micropip.install('bw2calc==2.0.dev14', keep_going = True)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 7, | ||
"metadata": { | ||
"trusted": true | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"import bw2data\n", | ||
"import bw2calc\n", | ||
"import bw2io" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"We can't import larger project backups yet - see [#37](https://github.com/brightway-lca/brightway-live/issues/37). But we can create a small sample database." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 8, | ||
"metadata": { | ||
"trusted": true | ||
}, | ||
"outputs": [ | ||
{ | ||
"name": "stderr", | ||
"output_type": "stream", | ||
"text": [ | ||
"/lib/python3.11/site-packages/openpyxl/worksheet/_reader.py:329: UserWarning: Unknown extension is not supported and will be removed\n", | ||
" warn(msg)\n" | ||
] | ||
}, | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Extracted 4 worksheets in 0.02 seconds\n", | ||
"Applying strategy: csv_restore_tuples\n", | ||
"Applying strategy: csv_restore_booleans\n", | ||
"Applying strategy: csv_numerize\n", | ||
"Applying strategy: csv_drop_unknown\n", | ||
"Applying strategy: csv_add_missing_exchanges_section\n", | ||
"Applying strategy: strip_biosphere_exc_locations\n", | ||
"Applying strategy: set_code_by_activity_hash\n", | ||
"Applying strategy: assign_only_product_as_production\n", | ||
"Applying strategy: drop_falsey_uncertainty_fields_but_keep_zeros\n", | ||
"Applying strategy: convert_uncertainty_types_to_integers\n", | ||
"Applying strategy: convert_activity_parameters_to_list\n", | ||
"Applied 11 strategies in 0.00 seconds\n", | ||
"Applying strategy: link_iterable_by_fields\n", | ||
"Not able to determine geocollections for all datasets. This database is not ready for regionalization.\n" | ||
] | ||
}, | ||
{ | ||
"name": "stderr", | ||
"output_type": "stream", | ||
"text": [ | ||
"/lib/python3.11/site-packages/bw2data/backends/base.py:50: TqdmMonitorWarning: tqdm:disabling monitor support (monitor_interval = 0) due to:\n", | ||
"can't start new thread\n", | ||
" return tqdm(iterable)\n", | ||
"100%|██████████| 9/9 [00:00<?, ?it/s]\n" | ||
] | ||
}, | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Vacuuming database \n", | ||
"Created database: Mobility example\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"bw2io.add_example_database(searchable=False)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"We can now do normal Brightway operations:" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 9, | ||
"metadata": { | ||
"trusted": true | ||
}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"Databases dictionary with 1 object(s):\n", | ||
"\tMobility example" | ||
] | ||
}, | ||
"execution_count": 9, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"bw2data.databases" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 10, | ||
"metadata": { | ||
"trusted": true | ||
}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"'Driving an combustion car' (kilometer, Europe, None)\n", | ||
"'CO2' (kilogram, None, None)\n", | ||
"'Electric car battery' (unit, GLO, ('Electric car battery',))\n", | ||
"'Combustion car' (unit, GLO, ('Combustion car',))\n", | ||
"'Electric car' (unit, GLO, ('Electric car',))\n", | ||
"'Steel' (kilogram, GLO, None)\n", | ||
"'Driving an electric car' (kilometer, Europe, None)\n", | ||
"'Electricity' (kilowatt hour, GLO, None)\n", | ||
"'Lithium' (kilogram, GLO, None)\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"for obj in bw2data.Database(\"Mobility example\"):\n", | ||
" print(obj)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 11, | ||
"metadata": { | ||
"trusted": true | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"co2 = bw2data.get_node(name=\"CO2\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 12, | ||
"metadata": { | ||
"trusted": true | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"gwp = bw2data.Method((\"GWP\", \"simple\"))\n", | ||
"gwp.write([(co2.key, 1)])" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"lca = bw2calc.LCA({bw2data.get_node(name=\"Electric car\"): " | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python (Pyodide)", | ||
"language": "python", | ||
"name": "python" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "python", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.8" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 4 | ||
} |
Oops, something went wrong.