-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added excel functions to dopo __init__
- Loading branch information
Showing
5 changed files
with
848 additions
and
4 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
Binary file not shown.
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,297 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"0. import dopo" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# from functions_v2 import*\n", | ||
"# from methods import MethodFinder\n", | ||
"import dopo\n", | ||
"\n", | ||
"import brightway2 as bw\n", | ||
"import bw2data as bd\n", | ||
"import bw2analyzer as ba" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"1. Define a bw project, bw setup, get the databases" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Biosphere database already present!!! No setup is needed\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"bd.projects.set_current(\"premise-validation-try1\")\n", | ||
"bw.bw2setup()\n", | ||
"\n", | ||
"bio3=bw.Database('biosphere3')\n", | ||
"ei39=bw.Database('ecoinvent 3.9.1 cutoff')\n", | ||
"ei39SSP2=bw.Database('ei_cutoff_3.9_image_SSP2-RCP19_2050 2024-06-27')" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"2. Define filter files" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 4, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"{'Cement': {'yaml': 'yamls\\\\cement_small.yaml', 'yaml identifier': 'Cement'},\n", | ||
" 'Electricity': {'yaml': 'yamls\\\\electricity_small.yaml',\n", | ||
" 'yaml identifier': 'Electricity'}}" | ||
] | ||
}, | ||
"execution_count": 4, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"files_dict={}\n", | ||
"files_dict['Cement']={'yaml': 'yamls\\cement_small.yaml',\n", | ||
" 'yaml identifier': 'Cement'}\n", | ||
"files_dict['Electricity']= {'yaml':'yamls\\electricity_small.yaml',\n", | ||
" 'yaml identifier': 'Electricity'} #yaml identifier is the name of the filter in the yaml file, in the first line.\n", | ||
"files_dict" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"3. Get activity lists from filters and store them in a dictionary by sector" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 5, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"sectors_dict = dopo.dopo_excel.process_yaml_files(files_dict, ei39SSP2)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"2. Initiate MethodFinder()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 6, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"finder=dopo.methods.MethodFinder()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"3. Define methods and store them in a dictionary" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 7, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"{'method_1': {'object': Brightway2 Method: IPCC 2013: climate change: global warming potential (GWP100),\n", | ||
" 'method name': ('IPCC 2013',\n", | ||
" 'climate change',\n", | ||
" 'global warming potential (GWP100)'),\n", | ||
" 'short name': 'global warming potential (GWP100)',\n", | ||
" 'unit': 'kg CO2-Eq'},\n", | ||
" 'method_2': {'object': Brightway2 Method: EN15804: inventory indicators ISO21930: Cumulative Energy Demand - non-renewable energy resources,\n", | ||
" 'method name': ('EN15804',\n", | ||
" 'inventory indicators ISO21930',\n", | ||
" 'Cumulative Energy Demand - non-renewable energy resources'),\n", | ||
" 'short name': 'Cumulative Energy Demand - non-renewable energy resources',\n", | ||
" 'unit': 'megajoule'},\n", | ||
" 'method_3': {'object': Brightway2 Method: selected LCI results: resource: land occupation,\n", | ||
" 'method name': ('selected LCI results', 'resource', 'land occupation'),\n", | ||
" 'short name': 'land occupation',\n", | ||
" 'unit': 'square meter-year'},\n", | ||
" 'method_4': {'object': Brightway2 Method: EN15804: inventory indicators ISO21930: use of net fresh water,\n", | ||
" 'method name': ('EN15804',\n", | ||
" 'inventory indicators ISO21930',\n", | ||
" 'use of net fresh water'),\n", | ||
" 'short name': 'use of net fresh water',\n", | ||
" 'unit': 'cubic meter'}}" | ||
] | ||
}, | ||
"execution_count": 7, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"finder.find_and_create_method(criteria=['IPCC', '2013', 'GWP100'], exclude=['no LT'])\n", | ||
"finder.find_and_create_method(criteria=['EN15804','Cumulative', 'non-renewable' ])\n", | ||
"finder.find_and_create_method(criteria=['land occupation','selected'])\n", | ||
"finder.find_and_create_method(criteria=['EN15804','fresh water'])\n", | ||
"method_dict=finder.get_all_methods()\n", | ||
"method_dict" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"4. get LCA score tables and store them in scores_dict" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 8, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Omitting activity name common prefix: 'cement production, '\n", | ||
"Omitting activity name common prefix: 'cement production, '\n", | ||
"Omitting activity name common prefix: 'cement production, '\n", | ||
"Omitting activity name common prefix: 'cement production, '\n", | ||
"Omitting activity name common prefix: 'electricity production, at biomass-fired IGCC power '\n", | ||
"Omitting activity name common prefix: 'electricity production, at biomass-fired IGCC power '\n", | ||
"Omitting activity name common prefix: 'electricity production, at biomass-fired IGCC power '\n", | ||
"Omitting activity name common prefix: 'electricity production, at biomass-fired IGCC power '\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"scores_dict = dopo.dopo_excel.sector_lca_scores(sectors_dict, method_dict) " | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"5. trasnfer lca tables to excel, add some statistics, get positions of columns." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 9, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"index_positions = dopo.dopo_excel.sector_lca_scores_to_excel_and_column_positions(scores_dict, 'test_charts_v1.xlsx')" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"6. group sheets by sector" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 10, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"worksheet_dict=dopo.dopo_excel.categorize_sheets_by_sector('test_charts_v1.xlsx')" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"7. generate dot plot and store row position of last chart in variable for stacked bar inital position" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 11, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"current_row_dots=dopo.dopo_excel.dot_plots('test_charts_v1.xlsx', worksheet_dict, index_positions=index_positions)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"8. get stacked bars on the same sheet as the dot plots" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 12, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"dopo.dopo_excel.stacked_bars('test_charts_v1.xlsx', worksheet_dict, index_positions, current_row_dots)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Et voila" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "premise", | ||
"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.11.9" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
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
Oops, something went wrong.