Skip to content

Commit

Permalink
improved init docstring + let file naming to user
Browse files Browse the repository at this point in the history
  • Loading branch information
matthieu-str committed Jan 27, 2025
1 parent 3102285 commit b5d43bc
Showing 1 changed file with 28 additions and 30 deletions.
58 changes: 28 additions & 30 deletions mescal/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@ def __init__(
"""
Initialize the Plot class.
:param df_impact_scores: dataframe of LCA indicators
:param esm_results_tech: dataframe of ESM results for technologies
:param esm_results_res: dataframe of ESM results for resources
:param lifetime: dataframe of lifetime of technologies
:param df_impact_scores: dataframe of LCA indicators obtained with the compute_impact_scores method of the ESM
class.
:param esm_results_tech: dataframe of ESM results for technologies. It should have the following columns: 'Run'
(iteration number), 'Name' (technology name), 'Installed capacity' (installed capacity of the technology),
'Production' (annual production of the technology).
:param esm_results_res: dataframe of ESM results for resources. It should have the following columns: 'Run'
(iteration number), 'Name' (resource name), 'Import' (annual import of the resource).
:param lifetime: dataframe of lifetime of technologies.
"""
self.df_impact_scores = df_impact_scores
self.esm_results_tech = esm_results_tech
Expand All @@ -38,7 +42,7 @@ def plot_indicators_of_technologies_for_one_impact_category(
impact_category: tuple,
metadata: dict = None,
filename: str = None,
saving_format: str = None,
saving_format: str = 'png',
saving_path: str = None,
show_plot: bool = True,
contributions_total_score: bool = False,
Expand All @@ -51,8 +55,8 @@ def plot_indicators_of_technologies_for_one_impact_category(
:param impact_category: impact category to plot (brightway format)
:param metadata: dictionary with metadata to include in the plot. It can include 'technologies_type',
'operation_unit', 'construction_unit'.
:param filename: name of the file to save the plot. If None, the plot is named with the impact category.
:param saving_format: format to save the plot, can be 'png', 'jpeg', 'pdf', 'html', etc.
:param filename: name of the file to save the plot. If None, the plot is not saved.
:param saving_format: format to save the plot, can be 'png', 'jpeg', 'pdf', 'html', etc. Default is 'png'.
:param saving_path: path to save the plot under the form 'path/to/folder/'. If None, the plot is saved in the
current directory.
:param show_plot: if True, the plot is shown in the notebook.
Expand All @@ -74,9 +78,6 @@ def plot_indicators_of_technologies_for_one_impact_category(
unit = bd.Method(impact_category).metadata['unit']
impact_category_name = impact_category[-1]

if filename is None:
filename = impact_category_name

if 'technologies_type' in metadata:
graph_title = f"LCA Indicators of {metadata['technologies_type']} technologies for {impact_category[-1]}"
else:
Expand Down Expand Up @@ -197,7 +198,7 @@ def plot_indicators_of_technologies_for_one_impact_category(
if show_plot:
fig.show()

if saving_format is None:
if filename is None:
pass
elif saving_format == 'html':
Path(saving_path).mkdir(parents=True, exist_ok=True) # Create the folder if it does not exist
Expand All @@ -212,7 +213,7 @@ def plot_indicators_of_resources_for_one_impact_category(
impact_category: tuple,
metadata: dict = None,
filename: str = None,
saving_format: str = None,
saving_format: str = 'png',
saving_path: str = None,
show_plot: bool = True,
contributions_total_score: bool = False,
Expand All @@ -224,8 +225,8 @@ def plot_indicators_of_resources_for_one_impact_category(
to have a meaningful comparison
:param impact_category: impact category to plot (brightway format)
:param metadata: dictionary with metadata to include in the plot. It can include 'resources_type', 'unit'.
:param filename: name of the file to save the plot. If None, the plot is named with the impact category.
:param saving_format: format to save the plot, can be 'png', 'jpeg', 'pdf', 'html', etc.
:param filename: name of the file to save the plot. If None, the plot is not saved.
:param saving_format: format to save the plot, can be 'png', 'jpeg', 'pdf', 'html', etc. Default is 'png'.
:param saving_path: path to save the plot under the form 'path/to/folder/'. If None, the plot is saved in the
current directory.
:param show_plot: if True, the plot is shown in the notebook.
Expand All @@ -247,9 +248,6 @@ def plot_indicators_of_resources_for_one_impact_category(
unit = bd.Method(impact_category).metadata['unit']
impact_category_name = impact_category[-1]

if filename is None:
filename = impact_category_name

if 'resources_type' in metadata:
graph_title = f"LCA Indicators of {metadata['resources_type']} resources for {impact_category[-1]})"
else:
Expand Down Expand Up @@ -316,7 +314,7 @@ def plot_indicators_of_resources_for_one_impact_category(
if show_plot:
fig.show()

if saving_format is None:
if filename is None:
pass
elif saving_format == 'html':
Path(saving_path).mkdir(parents=True, exist_ok=True) # Create the folder if it does not exist
Expand All @@ -330,7 +328,7 @@ def plot_indicators_of_technologies_for_several_impact_categories(
technologies_list: list[str],
impact_categories_list: list[tuple],
filename: str = None,
saving_format: str = None,
saving_format: str = 'png',
saving_path: str = None,
show_plot: bool = True,
):
Expand All @@ -340,8 +338,8 @@ def plot_indicators_of_technologies_for_several_impact_categories(
:param technologies_list: list of technologies to plot. They should have the same operation/infrastructure units
to have a meaningful comparison
:param impact_categories_list: list of impact category to plot (brightway format)
:param filename: name of the file to save the plot. If None, the plot is named with the impact category.
:param saving_format: format to save the plot, can be 'png', 'jpeg', 'pdf', 'html', etc.
:param filename: name of the file to save the plot. If None, the plot is not saved.
:param saving_format: format to save the plot, can be 'png', 'jpeg', 'pdf', 'html', etc. Default is 'png'.
:param saving_path: path to save the plot under the form 'path/to/folder/'. If None, the plot is saved in the
current directory.
:param show_plot: if True, the plot is shown in the notebook.
Expand Down Expand Up @@ -438,7 +436,7 @@ def plot_indicators_of_technologies_for_several_impact_categories(
if show_plot:
fig.show()

if saving_format is None or filename is None:
if filename is None:
pass
elif saving_format == 'html':
Path(saving_path).mkdir(parents=True, exist_ok=True) # Create the folder if it does not exist
Expand All @@ -452,7 +450,7 @@ def plot_indicators_of_resources_for_several_impact_categories(
resources_list: list[str],
impact_categories_list: list[tuple],
filename: str = None,
saving_format: str = None,
saving_format: str = 'png',
saving_path: str = None,
show_plot: bool = True,
):
Expand All @@ -462,8 +460,8 @@ def plot_indicators_of_resources_for_several_impact_categories(
:param resources_list: list of technologies to plot. They should have the same operation/infrastructure units
to have a meaningful comparison
:param impact_categories_list: list of impact category to plot (brightway format)
:param filename: name of the file to save the plot. If None, the plot is named with the impact category.
:param saving_format: format to save the plot, can be 'png', 'jpeg', 'pdf', 'html', etc.
:param filename: name of the file to save the plot. If None, the plot is not saved.
:param saving_format: format to save the plot, can be 'png', 'jpeg', 'pdf', 'html', etc. Default is 'png'.
:param saving_path: path to save the plot under the form 'path/to/folder/'. If None, the plot is saved in the
current directory.
:param show_plot: if True, the plot is shown in the notebook.
Expand Down Expand Up @@ -518,7 +516,7 @@ def plot_indicators_of_resources_for_several_impact_categories(
if show_plot:
fig.show()

if saving_format is None or filename is None:
if filename is None:
pass
elif saving_format == 'html':
Path(saving_path).mkdir(parents=True, exist_ok=True) # Create the folder if it does not exist
Expand All @@ -535,7 +533,7 @@ def plot_results(
normalized: bool = False,
n_run: int = 0,
filename: str = None,
saving_format: str = None,
saving_format: str = 'png',
saving_path: str = None,
show_plot: bool = True,
):
Expand All @@ -547,8 +545,8 @@ def plot_results(
:param N_highest_contributors: if split_by is 'Name', the number of highest contributors to show
:param normalized: if True, the impacts are normalized by the total impact of the category
:param n_run: number of the run to plot
:param filename: name of the file to save the plot. If None, the plot is named with the impact category.
:param saving_format: format to save the plot, can be 'png', 'jpeg', 'pdf', 'html', etc.
:param filename: name of the file to save the plot. If None, the plot is not saved.
:param saving_format: format to save the plot, can be 'png', 'jpeg', 'pdf', 'html', etc. Default is 'png'.
:param saving_path: path to save the plot under the form 'path/to/folder/'. If None, the plot is saved in the
current directory.
:param show_plot: if True, the plot is shown in the notebook.
Expand Down Expand Up @@ -675,7 +673,7 @@ def plot_results(
if show_plot:
fig.show()

if saving_format is None or filename is None:
if filename is None:
pass
elif saving_format == 'html':
Path(saving_path).mkdir(parents=True, exist_ok=True) # Create the folder if it does not exist
Expand Down

0 comments on commit b5d43bc

Please sign in to comment.