From 194c7a7be9b5856e9fb653d839e324f5e77ba239 Mon Sep 17 00:00:00 2001 From: msm_sardar Date: Sat, 2 Mar 2024 17:50:07 -0500 Subject: [PATCH 1/3] pin scipy --- HISTORY.rst | 5 +++++ requirements.txt | 4 ++-- swolfpy/__init__.py | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index 641fd4b..5ec60da 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -2,6 +2,11 @@ History ======= +1.4.0 (2024-03-02) +------------------ + +* Pin the version of scipy to 1.8.0 to avoid inexact indices changed from a deprecation to raising an error in 1.9 + 1.3.0 (2024-02-20) ------------------ diff --git a/requirements.txt b/requirements.txt index 29f1aa2..b67f4c2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -brightway2==2.4.1 +brightway2==2.4.1 # TODO: Upgrade to 2.5 bw-migrations==0.1 bw2analyzer==0.10 bw2calc==1.8.2 @@ -16,7 +16,7 @@ PySide2==5.15.2.1 pytest pytest-cov pytest-flake8 -scipy==1.9.0 +scipy==1.8.0 # To avoid https://stackoverflow.com/questions/74219727/brightway2-lca-scores-calculations/74371350#74371350 swolfpy_inputdata==1.1.* swolfpy_processmodels==1.1.* xlrd==1.2.0 diff --git a/swolfpy/__init__.py b/swolfpy/__init__.py index 2e12efc..1242554 100644 --- a/swolfpy/__init__.py +++ b/swolfpy/__init__.py @@ -29,7 +29,7 @@ "SwolfPy", ] -__version__ = "1.3.0" +__version__ = "1.4.0" class SwolfPy: From 8f27cbf3a39695b2bf3d2fe47a4909473385f805 Mon Sep 17 00:00:00 2001 From: msm_sardar Date: Sun, 3 Mar 2024 12:16:12 -0500 Subject: [PATCH 2/3] fix sphinx warning --- .pre-commit-config.yaml | 5 +++-- docs/conf.py | 4 ++-- swolfpy/LCA_matrix.py | 9 +++++++-- swolfpy/Monte_Carlo.py | 8 ++++++-- swolfpy/Optimization.py | 22 ++++++++++++++-------- swolfpy/Parameters.py | 7 +++++-- swolfpy/Project.py | 30 +++++++++++++++++++++++------- swolfpy/Technosphere.py | 6 +++++- swolfpy/UI/Table_from_pandas.py | 2 +- 9 files changed, 66 insertions(+), 27 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index df4e6a5..2866fed 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -18,17 +18,18 @@ repos: - id: isort - repo: https://github.com/pycqa/docformatter - rev: v1.5.1 + rev: v1.7.5 hooks: - id: docformatter args: [ --in-place, --make-summary-multi-line, - --close-quotes-on-newline , + --close-quotes-on-newline, --pre-summary-newline, --recursive, --wrap-summaries=90, --wrap-descriptions=90, + --blank ] - repo: https://github.com/psf/black diff --git a/docs/conf.py b/docs/conf.py index a6e2e3e..c5f461b 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -104,7 +104,7 @@ # # This is also used if you do content translation via gettext catalogs. # Usually you set "language" from the command line for these cases. -language = None +language = "en" # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. @@ -139,7 +139,7 @@ # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". -html_static_path = ["_static"] +# html_static_path = ["_static"] # -- Options for HTMLHelp output --------------------------------------- diff --git a/swolfpy/LCA_matrix.py b/swolfpy/LCA_matrix.py index 928898b..b192a0c 100644 --- a/swolfpy/LCA_matrix.py +++ b/swolfpy/LCA_matrix.py @@ -7,11 +7,11 @@ class LCA_matrix(LCA): """ This class translate the ``row`` and ``col`` of the ``tech_param`` and ``bio_param`` - to the activity `key` in the Brightway2 database. \n Both the ``tech_param`` and + to the activity `key` in the Brightway2 database. Both the ``tech_param`` and ``bio_param`` has the ``dtype=[('input', '` for more info. + """ def __init__(self, functional_unit, method): @@ -66,6 +67,7 @@ def update_techmatrix(process_name, report_dict, tech_matrix): :param tech_matrix: :type tech_matrix: ``LCA_matrix.tech_matrix`` + """ for material, value in report_dict["Technosphere"].items(): for key2, value2 in value.items(): @@ -188,6 +190,7 @@ def update_biomatrix(process_name, report_dict, bio_matrix): :param bio_matrix: :type bio_matrix: ``LCA_matrix.bio_matrix`` + """ for material, value in report_dict["Biosphere"].items(): for key2, value2 in value.items(): @@ -272,6 +275,7 @@ def get_mass_flow(LCA, process): :return: Total mass of flows to `process` :rtype: float + """ mass = 0 for i in LCA.activity_dict: @@ -300,6 +304,7 @@ def get_mass_flow_comp(LCA, process, index): :return: Pandas series with mass flows as values and index as rows. :rtype: pandas.core.series.Series + """ mass = pd.Series(np.zeros(len(index)), index=index) for i in LCA.activity_dict: diff --git a/swolfpy/Monte_Carlo.py b/swolfpy/Monte_Carlo.py index 804c007..edb4e7d 100644 --- a/swolfpy/Monte_Carlo.py +++ b/swolfpy/Monte_Carlo.py @@ -12,8 +12,8 @@ class Monte_Carlo(LCA_matrix): """ Setups the Monte Carlo simulation. This class is inherited from - ``swolfpy.LCA_matrix``. \n The Monte Carlo simulation will be only done for the - process models, common data or parameters than the class gets by arguments. + ``swolfpy.LCA_matrix``. The Monte Carlo simulation will be only done for the process + models, common data or parameters than the class gets by arguments. :param functional_unit: ``{flow:amount}`` :type functional_unit: dict @@ -38,6 +38,7 @@ class Monte_Carlo(LCA_matrix): :param seed: seed for ``stats_arrays.RandomNumberGenerator`` :type seed: int, optional + """ def __init__( @@ -72,6 +73,7 @@ def run(self, nproc, n): :type nproc: int :param n: Number of iterations in MC :type n: int + """ def pool_adapter(x): @@ -169,6 +171,7 @@ def parallel_mc( and ``bio_matrix``. Creates new ``bio_param`` and ``tech_param`` and then recalculate the LCA. + """ uncertain_inputs = [] if process_models: @@ -223,6 +226,7 @@ def result_to_DF(self): :return: Monte Carlo results :rtype: ``pandas.DataFrame`` + """ output = pd.DataFrame() # Reporting the LCIA results; Create a column for each method diff --git a/swolfpy/Optimization.py b/swolfpy/Optimization.py index b7383e1..799290c 100644 --- a/swolfpy/Optimization.py +++ b/swolfpy/Optimization.py @@ -163,7 +163,7 @@ def _objective_function(self, x): ### Mass to process def get_mass_flow_from_supply_array(self, key, KeyType, x): """ - calculate the mass to the process from the `supply_array` matrix. + Calculate the mass to the process from the `supply_array` matrix. """ self._objective_function(x) @@ -186,7 +186,7 @@ def get_mass_flow_from_supply_array(self, key, KeyType, x): ### Emission flow in LCI def get_emission_amount(self, emission, x): """ - calculate the mass of the `emission` to biosphere from the `inventory`. + Calculate the mass of the `emission` to biosphere from the `inventory`. """ self._objective_function(x) inventory = self.biosphere_matrix * self.supply_array @@ -337,9 +337,13 @@ def multi_start_optimization( initialize_guess="random", ): """ - Call the ``scipy.optimize.minimize()`` to minimize the LCA score. \n - ``constraints`` is python dictionary. \n Constraint type can be ``'<='`` or - ``'>='``. \n Three kind of constraints are defined as below: \n. + Call the ``scipy.optimize.minimize()`` to minimize the LCA score. + + Notes + ----- + - ``constraints`` is python dictionary. + - Constraint type can be ``'<='`` or ``'>='``. + - Three kind of constraints are defined as below: * **Process:** Constraint on the total mass to the process. The ``'KeyType'`` should be ``'Process'`` (e.g., The capacity of the WTE). Example: @@ -360,6 +364,7 @@ def multi_start_optimization( >>> constraints = {} >>> # Use database key as key in dict >>> constraints[('biosphere3', 'eba59fd6-f37e-41dc-9ca3-c7ea22d602c7')] = {'limit':100,'KeyType':'Emission','ConstType':"<="} + """ optObject.constraints = constraints optObject.collection = collection @@ -517,9 +522,9 @@ def set_optimized_parameters_to_project(self): def plot_sankey(self, optimized_flow=True, show=True, fileName=None, params=None): """ - Plots a sankey diagram for the waste mass flows. \n Calls the - ``plotly.graph_objs.Sankey`` to plot sankey. \n Calculates the mass flows by - calling ``self.get_mass_flow_from_supply_array()``. \n. + Plots a sankey diagram for the waste mass flows. Calls the + ``plotly.graph_objs.Sankey`` to plot sankey. Calculates the mass flows by calling + ``self.get_mass_flow_from_supply_array()``. :param optimized_flow: If ``True``, it plots the sankey based on the optimized waste fractions. If ``False``, it plots the sankey based on the current waste fractions by calling ``self.project.parameters_list``. @@ -527,6 +532,7 @@ def plot_sankey(self, optimized_flow=True, show=True, fileName=None, params=None :param show: If ``True``, it will show the figure :type show: bool + """ if optimized_flow: params = [i["amount"] for i in self.optimized_x] diff --git a/swolfpy/Parameters.py b/swolfpy/Parameters.py index b265e0a..6dc01ff 100644 --- a/swolfpy/Parameters.py +++ b/swolfpy/Parameters.py @@ -74,6 +74,7 @@ def add_parameter( :type process_model_to: str :param value: Value for the parameter :type value: float + """ param_name = ( "frac_of_" + product + "_from_" + process_model_from + "_to_" + process_model_to @@ -123,10 +124,10 @@ def add_parameter( def SWM_network(self, view=True, show_vals=True, all_flow=True, filename="SWM_network"): """ To render the generated DOT source code, you also need to install `Graphviz. - `_. ..note:: Make sure that the directory containing the dot executable is on your systems path. + """ # Initialize SWM network self.network = graphviz.Digraph( @@ -222,10 +223,11 @@ def check_sum(self): def add_uncertainty(self, param_name, **kwargs): """ - add uncertainty to parameter. + Add uncertainty to parameter. :param param_name: Name of the parameter (wastefraction) that has uncertainty :type param_name: str + """ base_dict = {} base_dict["loc"] = kwargs.get("loc", None) @@ -300,6 +302,7 @@ def MC_get_param_val(self, param_name): :type param_name: str :return: Value of the parameter :rtype: float + """ for item in self.MC_param_uncertainty_dict.values(): for list_item in item: diff --git a/swolfpy/Project.py b/swolfpy/Project.py index 111f01d..6f9c5d0 100644 --- a/swolfpy/Project.py +++ b/swolfpy/Project.py @@ -84,11 +84,14 @@ class Project: >>> demo.write_project() >>> demo.group_exchanges() >>> demo.parameters.default_parameters_list() + [{'name': 'frac_of_Bottom_Ash_from_WTE_to_LF', 'amount': 1.0}, {'name': 'frac_of_Fly_Ash_from_WTE_to_LF', 'amount': 1.0}, {'name': 'frac_of_RWC_from_SF_COl_to_LF', 'amount': 0.5}, {'name': 'frac_of_RWC_from_SF_COl_to_WTE', 'amount': 0.5}] + >>> demo.update_parameters(demo.parameters.default_parameters_list()) + """ def __init__( @@ -147,6 +150,7 @@ def _find_destination(self, product): :return: A list of the discovered processes in the ``Treatment_processes`` dictionary that can treat the `product` :rtype: list + """ destination = [] for P in self.Treatment_processes: @@ -156,10 +160,12 @@ def _find_destination(self, product): def init_project(self, signal=None): """ - Calls the Create_Technosphere_ method to initialize a project.\n This function - create an empty database for each process as a placeholder, so swolfpy can browse - these databases in the next step (writing project) and create exchanges between - them. + Calls the Create_Technosphere_ method to initialize a project. + + This function create an empty database for each process as a placeholder, so + swolfpy can browse these databases in the next step (writing project) and create + exchanges between them. + """ if signal: self._progress += 5 @@ -211,11 +217,13 @@ def _import_database(self, name): """ .. _import_database: - Instantiate the ProcessDB_ class for the process model and gets the LCI report from it; then translates - the report for Brightway2 and populates the databases by Write_DB_ method. + Instantiate the ProcessDB_ class for the process model and gets the LCI report + from it; then translates the report for Brightway2 and populates the databases by + Write_DB_ method. :return: Returns a tuple (parameters,act_in_group) :rtype: tuple + """ self.process_model[name] = ProcessDB( name, self.waste_treatment, self.CommonData, self.processTypes, self.Distance @@ -255,8 +263,10 @@ def report_parameters(self): """ Reports the `parameters` in dictionary format. - :return: dictionary include the processes as key and parameters in each process as values. + :return: dictionary include the processes as key and parameters in each process as + values. :rtype: dict + """ return self.parameters_dict @@ -266,6 +276,7 @@ def report_parameters_list(self): :return: List of `parameters` (waste fractions) in the project :rtype: list + """ return self.parameters_list @@ -276,6 +287,7 @@ def group_exchanges(self, signal=None): As a results, model know to update the values in those exchanges when the `parameter` is updated + """ for j in self.processes: print( @@ -306,6 +318,7 @@ def update_parameters(self, new_param_data, signal=None): .. note:: `parameters` are waste fractions which show what fraction of waste from one source go to different destinations, so sum of parameters from each source should be 1. (0<= `parameters` <=1) + """ progress = 0 @@ -374,6 +387,7 @@ def setup_LCA(name, functional_units, impact_methods): ``bw2calc.multi_lca`` is a wrapper class for performing LCA calculations with many functional units and LCIA methods. + """ if len(functional_units) > 0 and len(impact_methods) > 0: calculation_setups[name] = {"inv": functional_units, "ia": impact_methods} @@ -402,6 +416,7 @@ def contribution_analysis( * ``bw2analyzer.ContributionAnalysis.annotated_top_processes`` * ``bw2analyzer.ContributionAnalysis.annotated_top_emissions`` + """ lca = LCA(functional_unit, impact_method) lca.lci() @@ -488,6 +503,7 @@ def save(self, filename): :param filename: :type filename: str + """ with open(filename, "wb") as f: pickle.dump(self, f) diff --git a/swolfpy/Technosphere.py b/swolfpy/Technosphere.py index 48d75fb..6ef0f84 100644 --- a/swolfpy/Technosphere.py +++ b/swolfpy/Technosphere.py @@ -12,6 +12,7 @@ class Technosphere: """ + :param project_name: Name for the project :type project_name: str :param LCI_path: Path to the technosphere LIC csv file @@ -20,6 +21,7 @@ class Technosphere: :type LCI_Reference_path: str :param Ecospold2_Path: Path to the user defined technosphere LCI with ecospold2 format. :type Ecospold2_Path: str + """ def __init__(self, project_name, LCI_path=None, LCI_Reference_path=None, Ecospold2_Path=None): @@ -43,6 +45,7 @@ def Create_Technosphere(self): Note: If the `project` already exists, it will delete all the databases except 'biosphere3'. `Technosphere` database is written from the `SWOLF_AccountMode_LCI DATA.csv` in the `Data` folder unless user select new file with it's `path`. + """ projects.set_current(self.project_name) bw2setup() @@ -127,6 +130,7 @@ def _Write_user_technosphere(self): \n Interface with Brightway2: Calls the ``bw2io.importers.SingleOutputEcospold2Importer`` function. + """ self.user_tech = bw2io.importers.SingleOutputEcospold2Importer( dirpath=self.Ecospold2_Path, db_name=self.user_tech_name @@ -158,7 +162,7 @@ def _Write_user_technosphere(self): def _write_technosphere(self): """ - Creates the swolfpy technosphere database.\n. + Creates the swolfpy technosphere database. """ self.technosphere_data = {} # activities diff --git a/swolfpy/UI/Table_from_pandas.py b/swolfpy/UI/Table_from_pandas.py index 9f59a94..eec4992 100644 --- a/swolfpy/UI/Table_from_pandas.py +++ b/swolfpy/UI/Table_from_pandas.py @@ -5,7 +5,7 @@ def f_n(x): """ - format number function If the input is string, it returns string but if the input in + Format number function If the input is string, it returns string but if the input in number, it will return it in scientific format. """ if (isinstance(x, float) or isinstance(x, int)) and len(str(x)) > 6: From e1a43150db7f7956da11405bf7f231442557289c Mon Sep 17 00:00:00 2001 From: msm_sardar Date: Sun, 3 Mar 2024 12:16:49 -0500 Subject: [PATCH 3/3] update history --- HISTORY.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/HISTORY.rst b/HISTORY.rst index 5ec60da..4020401 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -6,6 +6,7 @@ History ------------------ * Pin the version of scipy to 1.8.0 to avoid inexact indices changed from a deprecation to raising an error in 1.9 +* Fix sphinx warnings 1.3.0 (2024-02-20) ------------------