From 3b8deff95823bffa984d5ac59e0dd8346e96fe3a Mon Sep 17 00:00:00 2001 From: "Brandon N. Benton" Date: Wed, 29 May 2024 11:42:55 -0600 Subject: [PATCH] using `.name.lower` to match fixed sc point attributes --- reV/econ/economies_of_scale.py | 81 ++++++++++++++++++++++----------- reV/supply_curve/aggregation.py | 14 ++++-- reV/supply_curve/points.py | 2 +- reV/utilities/__init__.py | 1 + 4 files changed, 67 insertions(+), 31 deletions(-) diff --git a/reV/econ/economies_of_scale.py b/reV/econ/economies_of_scale.py index 022b262eb..38f0e75ed 100644 --- a/reV/econ/economies_of_scale.py +++ b/reV/econ/economies_of_scale.py @@ -3,16 +3,20 @@ reV module for calculating economies of scale where larger power plants will have reduced capital cost. """ + import copy import logging import re # pylint: disable=unused-import -import numpy as np import pandas as pd from rex.utilities.utilities import check_eval_str from reV.econ.utilities import lcoe_fcr +from reV.utilities import ( + OldSupplyCurveField, + SupplyCurveField, +) logger = logging.getLogger(__name__) @@ -59,23 +63,32 @@ def _preflight(self): check_eval_str(str(self._eqn)) if isinstance(self._data, pd.DataFrame): - self._data = {k: self._data[k].values.flatten() - for k in self._data.columns} + self._data = { + k: self._data[k].values.flatten() for k in self._data.columns + } if not isinstance(self._data, dict): - e = ('Cannot evaluate EconomiesOfScale with data input of type: {}' - .format(type(self._data))) + e = ( + "Cannot evaluate EconomiesOfScale with data input of type: " + "{}".format(type(self._data)) + ) + logger.error(e) raise TypeError(e) missing = [name for name in self.vars if name not in self._data] if any(missing): - e = ('Cannot evaluate EconomiesOfScale, missing data for variables' - ': {} for equation: {}'.format(missing, self._eqn)) + e = ( + "Cannot evaluate EconomiesOfScale, missing data for variables" + ": {} for equation: {}".format(missing, self._eqn) + ) logger.error(e) raise KeyError(e) + rename_map = SupplyCurveField.map_from(OldSupplyCurveField) + self._data = {rename_map.get(k, k): v for k, v in self._data.items()} + @staticmethod def is_num(s): """Check if a string is a number""" @@ -89,7 +102,7 @@ def is_num(s): @staticmethod def is_method(s): """Check if a string is a numpy/pandas or python builtin method""" - return bool(s.startswith(('np.', 'pd.')) or s in dir(__builtins__)) + return bool(s.startswith(("np.", "pd.")) or s in dir(__builtins__)) @property def vars(self): @@ -105,8 +118,8 @@ def vars(self): """ var_names = [] if self._eqn is not None: - delimiters = ('*', '/', '+', '-', ' ', '(', ')', '[', ']', ',') - regex_pattern = '|'.join(map(re.escape, delimiters)) + delimiters = ("*", "/", "+", "-", " ", "(", ")", "[", "]", ",") + regex_pattern = "|".join(map(re.escape, delimiters)) var_names = [] for sub in re.split(regex_pattern, str(self._eqn)): if sub and not self.is_num(sub) and not self.is_method(sub): @@ -160,9 +173,10 @@ def _get_prioritized_keys(input_dict, key_list): break if out is None: - e = ('Could not find requested key list ({}) in the input ' - 'dictionary keys: {}' - .format(key_list, list(input_dict.keys()))) + e = ( + "Could not find requested key list ({}) in the input " + "dictionary keys: {}".format(key_list, list(input_dict.keys())) + ) logger.error(e) raise KeyError(e) @@ -190,7 +204,10 @@ def raw_capital_cost(self): out : float | np.ndarray Unscaled (raw) capital_cost found in the data input arg. """ - key_list = ['capital_cost', 'mean_capital_cost'] + key_list = [ + SupplyCurveField.CAPITAL_COST, + "mean_capital_cost", + ] return self._get_prioritized_keys(self._data, key_list) @property @@ -217,7 +234,7 @@ def system_capacity(self): ------- out : float | np.ndarray """ - key_list = ['system_capacity', 'mean_system_capacity'] + key_list = ["system_capacity", "mean_system_capacity"] return self._get_prioritized_keys(self._data, key_list) @property @@ -229,9 +246,12 @@ def fcr(self): out : float | np.ndarray Fixed charge rate from input data arg """ - key_list = ['fixed_charge_rate', - 'mean_fixed_charge_rate', - 'fcr', 'mean_fcr'] + key_list = [ + SupplyCurveField.FIXED_CHARGE_RATE, + "mean_fixed_charge_rate", + "fcr", + "mean_fcr", + ] return self._get_prioritized_keys(self._data, key_list) @property @@ -243,9 +263,12 @@ def foc(self): out : float | np.ndarray Fixed operating cost from input data arg """ - key_list = ['fixed_operating_cost', - 'mean_fixed_operating_cost', - 'foc', 'mean_foc'] + key_list = [ + SupplyCurveField.FIXED_OPERATING_COST, + "mean_fixed_operating_cost", + "foc", + "mean_foc", + ] return self._get_prioritized_keys(self._data, key_list) @property @@ -257,9 +280,12 @@ def voc(self): out : float | np.ndarray Variable operating cost from input data arg """ - key_list = ['variable_operating_cost', - 'mean_variable_operating_cost', - 'voc', 'mean_voc'] + key_list = [ + SupplyCurveField.VARIABLE_OPERATING_COST, + "mean_variable_operating_cost", + "voc", + "mean_voc", + ] return self._get_prioritized_keys(self._data, key_list) @property @@ -285,7 +311,7 @@ def raw_lcoe(self): ------- lcoe : float | np.ndarray """ - key_list = ["raw_lcoe", "mean_lcoe"] + key_list = [SupplyCurveField.RAW_LCOE, SupplyCurveField.MEAN_LCOE] return copy.deepcopy(self._get_prioritized_keys(self._data, key_list)) @property @@ -301,5 +327,6 @@ def scaled_lcoe(self): LCOE calculated with the scaled capital cost based on the EconomiesOfScale input equation. """ - return lcoe_fcr(self.fcr, self.scaled_capital_cost, self.foc, - self.aep, self.voc) + return lcoe_fcr( + self.fcr, self.scaled_capital_cost, self.foc, self.aep, self.voc + ) diff --git a/reV/supply_curve/aggregation.py b/reV/supply_curve/aggregation.py index 629c80d0b..0d7850bef 100644 --- a/reV/supply_curve/aggregation.py +++ b/reV/supply_curve/aggregation.py @@ -18,7 +18,7 @@ from reV.supply_curve.extent import SupplyCurveExtent from reV.supply_curve.points import AggregationSupplyCurvePoint from reV.supply_curve.tech_mapping import TechMapping -from reV.utilities import SupplyCurveField, log_versions +from reV.utilities import ResourceMetaField, SupplyCurveField, log_versions from reV.utilities.exceptions import ( EmptySupplyCurvePointError, FileInputError, @@ -472,12 +472,17 @@ def _parse_gen_index(gen_fpath): logger.error(msg) raise FileInputError(msg) + gen_index = gen_index.rename( + ResourceMetaField.map_to(SupplyCurveField), axis=1 + ) if SupplyCurveField.GID in gen_index: gen_index = gen_index.rename( columns={SupplyCurveField.GID: SupplyCurveField.RES_GIDS} ) gen_index[SupplyCurveField.GEN_GIDS] = gen_index.index - gen_index = gen_index[[SupplyCurveField.RES_GIDS, SupplyCurveField.GEN_GIDS]] + gen_index = gen_index[ + [SupplyCurveField.RES_GIDS, SupplyCurveField.GEN_GIDS] + ] gen_index = gen_index.set_index(keys=SupplyCurveField.RES_GIDS) gen_index = gen_index.reindex( range(int(gen_index.index.max() + 1)) @@ -696,7 +701,10 @@ def run_serial( "area_filter_kernel": area_filter_kernel, "min_area": min_area, } - dsets = (*agg_dset, "meta",) + dsets = ( + *agg_dset, + "meta", + ) agg_out = {ds: [] for ds in dsets} with AggFileHandler(excl_fpath, h5_fpath, **file_kwargs) as fh: n_finished = 0 diff --git a/reV/supply_curve/points.py b/reV/supply_curve/points.py index d9620d9d4..093f31b9b 100644 --- a/reV/supply_curve/points.py +++ b/reV/supply_curve/points.py @@ -2219,7 +2219,7 @@ def point_summary(self, args=None): SupplyCurveField.SC_POINT_ANNUAL_ENERGY_AC, ] for attr in extra_atts: - value = getattr(self, attr) + value = getattr(self, attr.name.lower()) if value is not None: ARGS[attr] = value diff --git a/reV/utilities/__init__.py b/reV/utilities/__init__.py index 3ce30d6b2..deeea147c 100644 --- a/reV/utilities/__init__.py +++ b/reV/utilities/__init__.py @@ -86,6 +86,7 @@ class ResourceMetaField(FieldEnum): "sc_row_ind": "SC_ROW_IND", "sc_col_ind": "SC_COL_IND", "mean_cf": "MEAN_CF", + "capital_cost": "CAPITAL_COST", }