Skip to content

Commit

Permalink
using .name.lower to match fixed sc point attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
bnb32 committed May 29, 2024
1 parent 36d00ef commit 3b8deff
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 31 deletions.
81 changes: 54 additions & 27 deletions reV/econ/economies_of_scale.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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"""
Expand All @@ -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):
Expand All @@ -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):
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
)
14 changes: 11 additions & 3 deletions reV/supply_curve/aggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion reV/supply_curve/points.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions reV/utilities/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}


Expand Down

0 comments on commit 3b8deff

Please sign in to comment.