Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Stew-McD committed Mar 15, 2024
1 parent 635a5c3 commit 87ee4f0
Show file tree
Hide file tree
Showing 102 changed files with 280,781 additions and 103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

ca = bwa.ContributionAnalysis()

PROJECT = "T-reX-SSP2-cutoff"
PROJECT = "T-reX-premise-SSP2-cutoff"
KEY = "market for battery, Li-ion, rechargeable"

KEYWORDS_METHODS = [
Expand All @@ -23,8 +23,8 @@

SEARCH_ACTIVITIES = 0
SEARCH_METHODS = 0
GET_RESULTS = 1
GET_SUPPLY_CHAIN_RESULTS = 0
GET_RESULTS = 0
GET_SUPPLY_CHAIN_RESULTS = 1

CWD = Path.cwd()
DIR_DATA = CWD / "data"
Expand Down Expand Up @@ -286,8 +286,13 @@ def get_supply_chain_results():

if len(methods_waste) == 0:
print("\t\t ## No waste methods found ##")
else:
print(f"\t\t Waste methods: {len(methods_waste)}")
if len(methods_material) == 0:
print("\t\t ## No material methods found ##")
else:
print(f"\t\t Material methods: {len(methods_material)}")


dbs = activities.database.unique()

Expand Down Expand Up @@ -346,9 +351,9 @@ def get_supply_chain_results():
df_result = bwa.compare_activities_by_grouped_leaves(
df_acts.activity_object,
method,
max_level=5,
max_level=3,
output_format="pandas",
cutoff=0.025,
cutoff=0.125,
)

df_single = df_act.join(df_result)
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,17 @@ def replace_strings_in_string(string, term_replacements):
continue

fig, ax = plt.subplots()
title_raw = f"{df_methods_2['method_0'].iloc[0]}\n{method_2}"
title_raw = f"{df_methods_2['method_0'].iloc[0]}--- material/waste footprints\n{method_1} --- {method_2}"

title = replace_strings_in_string(title_raw, term_replacements)

plt.title(title, fontsize=8)
ax.set_xlabel("Year", fontsize=7)
ax.set_ylabel(f"{df_methods_2['unit'].iloc[0]} / kg (battery)", fontsize=7)

# reduce number of tick labels
years = [year for year in years if year % 10 == 0]

ax.set_xticks(years)
ax.set_xticklabels(years, fontsize=6)
ax.yaxis.set_tick_params(labelsize=6)
Expand Down Expand Up @@ -209,7 +213,7 @@ def replace_strings_in_string(string, term_replacements):
filename_safe = filename.replace("/", "|") # Replacing any forward slashes to avoid path issues
filepath = os.path.join("visualisation/individual-methods", filename_safe)
plt.savefig(filepath, format="svg", bbox_inches="tight") # Saving as SVG
plt.show()
# plt.show()
plt.close(fig)

# print progress
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
)

# Create a PDF file
c = canvas.Canvas("combined_methods.pdf", pagesize=(page_width, page_height))
c = canvas.Canvas("visualisation/scatter-combined_methods.pdf", pagesize=(page_width, page_height))

# Add the title
c.setFont("Libertine", 16) # Set Libertine font and size for the title
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
print(f"Total page size set to: {page_width}x{page_height}")

# Create a PDF file
c = canvas.Canvas("similar_methods.pdf")
c = canvas.Canvas("visualisation/scatter-similar_methods.pdf")
c.setPageSize((page_width, page_height))

# Initialize Y-coordinate for drawing
Expand Down Expand Up @@ -89,4 +89,4 @@

# Save the PDF
c.save()
print("PDF created: similar_methods.pdf")
print("PDF created: scatter-similar_methods.pdf")
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def replace_strings_in_string(string, term_replacements):

# Plotting setup (title, labels, legend, etc.)
title_raw = f"Contribution to total by sector for Li-ion battery `{activity}'"
method_text = f"LCA Method: ({method[0]}, {method[2]})"
method_text = f"LCA Method: ({method[0]}, {method[1]}, {method[2]})"
ax.text(
0.01,
1.02, # x, y coordinates in axes fraction
Expand Down
22 changes: 22 additions & 0 deletions examples/batteries/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# T-reX: Li-ion battery example study

This example study demonstrates the use of T-reX to explore the supply chain material demands and waste generation of five lithium ion batteries from ecoinvent 3.9.1. Also inclusive are two future scenario paths created by premise, forecasting the ecoinvent database until 2100.


## Step by step

### Before running this example

1. Install T-reX and its dependencies
2. Manipulate your brightway project and its databases with T-reX
3. Change the settings in the case study code to match your project and your needs (i.e. method sets, database names, etc.)

### Running the example

1. Run the `batteries.py` script to generate the results
* toggle the component functions, start with generating the `methods.csv' and `activities.csv` files
* if the methods and activities look good, then toggle the calculation functions and run the `batteries.py` script again
* note that the contribution analysis can take a very long time with many databases, methods, and activities (i.e. hours to days if there are many)
2. Run the `results.py` script to process the results
3. Run the `results_significant.py` script
4. Run the visualisation scripts to generate the plots
Loading

0 comments on commit 87ee4f0

Please sign in to comment.