From 73588da54c6aee37cbd58be3ef1bab48a91cbaa6 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 13 Jan 2025 15:10:56 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- examples/example5.ipynb | 4 ++-- flodym/_df_to_flodym_array.py | 4 +++- flodym/flodym_arrays.py | 8 +++++--- flodym/stock_helper.py | 4 +--- howtos/04_arrays.ipynb | 2 +- 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/examples/example5.ipynb b/examples/example5.ipynb index a7f5721..0583f91 100644 --- a/examples/example5.ipynb +++ b/examples/example5.ipynb @@ -692,7 +692,7 @@ " * vehicle_mfa_2.parameters[\"vehicle material content\"]\n", " * 1e-9\n", ")\n", - "global_stock_by_material_type = stock_by_material_type.sum_nda_over(sum_over_dims=(\"r\"))\n", + "global_stock_by_material_type = stock_by_material_type.sum_over(sum_over_dims=(\"r\"))\n", "global_stock_by_material_type_in_2017 = global_stock_by_material_type[{\"t\": 2017}]\n", "\n", "stock_df = global_stock_by_material_type_in_2017.to_df(index=False)\n", @@ -833,7 +833,7 @@ ], "source": [ "np.nan_to_num(vehicle_mfa_2.flows[\"scrap => sysenv\"].values, copy=False)\n", - "scrap_outflow = vehicle_mfa_2.flows[\"scrap => sysenv\"].sum_nda_over(sum_over_dims=(\"m\"))\n", + "scrap_outflow = vehicle_mfa_2.flows[\"scrap => sysenv\"].sum_over(sum_over_dims=(\"m\"))\n", "outflow_df = scrap_outflow.to_df(dim_to_columns=\"waste\")\n", "outflow_df = outflow_df[outflow_df.index > 2017]\n", "fig = px.line(outflow_df, title=\"Scrap outflow\")\n", diff --git a/flodym/_df_to_flodym_array.py b/flodym/_df_to_flodym_array.py index 938b7aa..7885b3a 100644 --- a/flodym/_df_to_flodym_array.py +++ b/flodym/_df_to_flodym_array.py @@ -198,7 +198,9 @@ def _check_data_complete(self): if self.flodym_array.dims.ndim == 0: expected_index_tuples = set() else: - expected_index_tuples = set(itertools.product(*(dim.items for dim in self.flodym_array.dims))) + expected_index_tuples = set( + itertools.product(*(dim.items for dim in self.flodym_array.dims)) + ) # Generate actual index tuples from DataFrame columns actual_index_tuples = set( diff --git a/flodym/flodym_arrays.py b/flodym/flodym_arrays.py index 77816a7..687f4a5 100644 --- a/flodym/flodym_arrays.py +++ b/flodym/flodym_arrays.py @@ -212,7 +212,7 @@ def sum_values_to(self, result_dims: tuple[str] = ()): result_dims = self._tuple_to_letters(result_dims) return np.einsum(f"{self.dims.string}->{''.join(result_dims)}", self.values) - def sum_to(self, result_dims: tuple = ()) -> 'FlodymArray': + def sum_to(self, result_dims: tuple = ()) -> "FlodymArray": """Return the FlodymArray summed, such that only the dimensions given in the result_dims tuple are left. Args: @@ -228,7 +228,7 @@ def sum_to(self, result_dims: tuple = ()) -> 'FlodymArray': name=self.name, ) - def sum_over(self, sum_over_dims: tuple = ()) -> 'FlodymArray': + def sum_over(self, sum_over_dims: tuple = ()) -> "FlodymArray": """Return the FlodymArray summed over a given tuple of dimensions. Args: @@ -565,7 +565,9 @@ def to_flodym_array(self) -> "FlodymArray": "Use a new dimension object with the subset as values instead" ) - return FlodymArray(dims=self.dims_out, values=self.values_pointer, name=self.flodym_array.name) + return FlodymArray( + dims=self.dims_out, values=self.values_pointer, name=self.flodym_array.name + ) def _init_ids(self): """ diff --git a/flodym/stock_helper.py b/flodym/stock_helper.py index 5d7476a..6912221 100644 --- a/flodym/stock_helper.py +++ b/flodym/stock_helper.py @@ -29,9 +29,7 @@ def stock_stack(stocks: list[Stock], dimension: Dimension) -> FlowDrivenStock: """ stacked_stock = flodym_array_stack([stock.stock for stock in stocks], dimension=dimension) stacked_inflow = flodym_array_stack([stock.inflow for stock in stocks], dimension=dimension) - stacked_outflow = flodym_array_stack( - [stock.outflow for stock in stocks], dimension=dimension - ) + stacked_outflow = flodym_array_stack([stock.outflow for stock in stocks], dimension=dimension) return FlowDrivenStock( stock=stacked_stock, inflow=stacked_inflow, diff --git a/howtos/04_arrays.ipynb b/howtos/04_arrays.ipynb index 901271b..f09b0f2 100644 --- a/howtos/04_arrays.ipynb +++ b/howtos/04_arrays.ipynb @@ -262,7 +262,7 @@ } ], "source": [ - "reduced = multiplied.sum_nda_to(result_dims=(\"t\", \"r\"))\n", + "reduced = multiplied.sum_to(result_dims=(\"t\", \"r\"))\n", "print(\"reduced:\")\n", "show_array(reduced)" ]