Skip to content

Commit

Permalink
fix: bad replacements
Browse files Browse the repository at this point in the history
  • Loading branch information
bnb32 committed May 12, 2024
1 parent 08d091b commit 2b6b919
Show file tree
Hide file tree
Showing 34 changed files with 964 additions and 680 deletions.
7 changes: 3 additions & 4 deletions examples/bespoke_wind_plants/single_run.py
Expand Up @@ -18,13 +18,12 @@
plot_windrose,
)
from reV.supply_curve.tech_mapping import TechMapping
from reV.utilities import MetaKeyName

SAM = os.path.join(TESTDATADIR, 'SAM/i_windpower.json')
EXCL = os.path.join(TESTDATADIR, 'ri_exclusions/ri_exclusions.h5')
RES = os.path.join(TESTDATADIR, 'wtk/ri_100_wtk_{}.h5')
TM_DSET = 'techmap_wtk_ri_100'
AGG_DSET = (MetaKeyName.CF_MEAN, MetaKeyName.CF_PROFILE)
AGG_DSET = ('cf_mean', 'cf_profile')

# note that this differs from the
EXCL_DICT = {'ri_srtm_slope': {'inclusion_range': (None, 5),
Expand Down Expand Up @@ -61,8 +60,8 @@
1E5 * 0.1 + (1 - 0.1))"""
objective_function = "cost / aep"

output_request = ('system_capacity', MetaKeyName.CF_MEAN,
MetaKeyName.CF_PROFILE)
output_request = ('system_capacity', 'cf_mean',
'cf_profile')
gid = 33
with tempfile.TemporaryDirectory() as td:
excl_fp = os.path.join(td, 'ri_exclusions.h5')
Expand Down
44 changes: 20 additions & 24 deletions reV/SAM/SAM.py
Expand Up @@ -27,7 +27,6 @@
)
from rex.utilities.utilities import check_res_file

from reV.utilities import MetaKeyName
from reV.utilities.exceptions import (
ResourceError,
SAMExecutionError,
Expand Down Expand Up @@ -376,19 +375,18 @@ def __setitem__(self, key, value):
.format(key, self.pysam))
logger.exception(msg)
raise SAMInputError(msg)
else:
self.sam_sys_inputs[key] = value
group = self._get_group(key, outputs=False)
try:
setattr(getattr(self.pysam, group), key, value)
except Exception as e:
msg = ('Could not set input key "{}" to '
'group "{}" in "{}".\n'
'Data is: {} ({})\n'
'Received the following error: "{}"'
.format(key, group, self.pysam, value, type(value), e))
logger.exception(msg)
raise SAMInputError(msg) from e
self.sam_sys_inputs[key] = value
group = self._get_group(key, outputs=False)
try:
setattr(getattr(self.pysam, group), key, value)
except Exception as e:
msg = ('Could not set input key "{}" to '
'group "{}" in "{}".\n'
'Data is: {} ({})\n'
'Received the following error: "{}"'
.format(key, group, self.pysam, value, type(value), e))
logger.exception(msg)
raise SAMInputError(msg) from e

@property
def pysam(self):
Expand Down Expand Up @@ -739,7 +737,7 @@ def get_time_interval(cls, time_index):
if t == 1.0:
time_interval += 1
break
elif t == 0.0:
if t == 0.0:
time_interval += 1

return int(time_interval)
Expand Down Expand Up @@ -797,22 +795,20 @@ def _is_arr_like(val):
"""Returns true if SAM data is array-like. False if scalar."""
if isinstance(val, (int, float, str)):
return False
try:
len(val)
except TypeError:
return False
else:
try:
len(val)
except TypeError:
return False
else:
return True
return True

@classmethod
def _is_hourly(cls, val):
"""Returns true if SAM data is hourly or sub-hourly. False otherise."""
if not cls._is_arr_like(val):
return False
else:
L = len(val)
return L >= 8760
L = len(val)
return L >= 8760

def outputs_to_utc_arr(self):
"""Convert array-like SAM outputs to UTC np.ndarrays"""
Expand Down
16 changes: 8 additions & 8 deletions reV/generation/generation.py
Expand Up @@ -82,7 +82,7 @@ class Gen(BaseGen):

def __init__(self, technology, project_points, sam_files, resource_file,
low_res_resource_file=None,
output_request=(MetaKeyName.CF_MEAN,),
output_request=('cf_mean',),
site_data=None, curtailment=None, gid_map=None,
drop_leap=False, sites_per_worker=None,
memory_utilization_limit=0.4, scale_outputs=True,
Expand Down Expand Up @@ -123,10 +123,10 @@ def __init__(self, technology, project_points, sam_files, resource_file,
>>> gen.run()
>>>
>>> gen.out
{MetaKeyName.CF_MEAN: array([0.16966143], dtype=float32)}
{'cf_mean': array([0.16966143], dtype=float32)}
>>>
>>> sites = [3, 4, 7, 9]
>>> req = (MetaKeyName.CF_MEAN, , MetaKeyName.LCOE_FCR)
>>> req = ('cf_mean', , MetaKeyName.LCOE_FCR)
>>> gen = Gen(sam_tech, sites, fp_sam, fp_res, output_request=req)
>>> gen.run()
>>>
Expand Down Expand Up @@ -283,7 +283,7 @@ def __init__(self, technology, project_points, sam_files, resource_file,
aggregation/supply curve step if the ``"dc_ac_ratio"``
dataset is detected in the generation file.
By default, ``(MetaKeyName.CF_MEAN,)``.
By default, ``('cf_mean',)``.
site_data : str | pd.DataFrame, optional
Site-specific input data for SAM calculation. If this input
is a string, it should be a path that points to a CSV file.
Expand Down Expand Up @@ -547,7 +547,7 @@ def handle_lifetime_index(self, ti):
var for var, attrs in GEN_ATTRS.items()
if attrs['type'] == 'array'
]
valid_vars = [MetaKeyName.GEN_PROFILE, MetaKeyName.CF_PROFILE,
valid_vars = [MetaKeyName.GEN_PROFILE, 'cf_profile',
'cf_profile_ac']
invalid_vars = set(array_vars) - set(valid_vars)
invalid_requests = [var for var in self.output_request
Expand Down Expand Up @@ -836,7 +836,7 @@ def _parse_bc(bias_correct):
if isinstance(bias_correct, type(None)):
return bias_correct

elif isinstance(bias_correct, str):
if isinstance(bias_correct, str):
bias_correct = pd.read_csv(bias_correct)

msg = ('Bias correction data must be a filepath to csv or a dataframe '
Expand Down Expand Up @@ -874,8 +874,8 @@ def _parse_output_request(self, req):
output_request = self._output_request_type_check(req)

# ensure that cf_mean is requested from output
if MetaKeyName.CF_MEAN not in output_request:
output_request.append(MetaKeyName.CF_MEAN)
if 'cf_mean' not in output_request:
output_request.append('cf_mean')

for request in output_request:
if request not in self.OUT_ATTRS:
Expand Down
4 changes: 2 additions & 2 deletions reV/handlers/multi_year.py
Expand Up @@ -34,7 +34,7 @@ class MultiYearGroup:
def __init__(self, name, out_dir, source_files=None,
source_dir=None, source_prefix=None,
source_pattern=None,
dsets=(MetaKeyName.CF_MEAN,), pass_through_dsets=None):
dsets=('cf_mean',), pass_through_dsets=None):
"""
Parameters
----------
Expand All @@ -61,7 +61,7 @@ def __init__(self, name, out_dir, source_files=None,
`source_prefix` but is not used if `source_files` are
specified explicitly. By default, ``None``.
dsets : list | tuple, optional
List of datasets to collect. By default, ``(MetaKeyName.CF_MEAN,)``.
List of datasets to collect. By default, ``('cf_mean',)``.
pass_through_dsets : list | tuple, optional
Optional list of datasets that are identical in the
multi-year files (e.g. input datasets that don't vary from
Expand Down
40 changes: 20 additions & 20 deletions reV/rep_profiles/rep_profiles.py
Expand Up @@ -302,7 +302,7 @@ class RegionRepProfile:
RES_GID_COL = MetaKeyName.RES_GIDS
GEN_GID_COL = MetaKeyName.GEN_GIDS

def __init__(self, gen_fpath, rev_summary, cf_dset=MetaKeyName.CF_PROFILE,
def __init__(self, gen_fpath, rev_summary, cf_dset='cf_profile',
rep_method='meanoid', err_method='rmse',
weight=MetaKeyName.GID_COUNTS,
n_profiles=1):
Expand Down Expand Up @@ -442,7 +442,7 @@ def _get_region_attr(rev_summary, attr_name):
if any(data):
if isinstance(data[0], str):
# pylint: disable=simplifiable-condition
if ('[' and ']' in data[0]) or ('(' and ')' in data[0
if ('[' and ']' in data[0]) or ('(' and ')' in data[0]):
data = [json.loads(s) for s in data]

if isinstance(data[0], (list, tuple)):
Expand Down Expand Up @@ -474,23 +474,23 @@ def _run_rep_methods(self):
rep_method=self._rep_method, err_method=self._err_method,
n_profiles=self._n_profiles)

@property
@ property
def rep_profiles(self):
"""Get the representative profiles of this region."""
if self._profiles is None:
self._run_rep_methods()

return self._profiles

@property
@ property
def i_reps(self):
"""Get the representative profile index(es) of this region."""
if self._i_reps is None:
self._run_rep_methods()

return self._i_reps

@property
@ property
def rep_gen_gids(self):
"""Get the representative profile gen gids of this region."""
gids = self._gen_gids
Expand All @@ -501,7 +501,7 @@ def rep_gen_gids(self):

return rep_gids

@property
@ property
def rep_res_gids(self):
"""Get the representative profile resource gids of this region."""
gids = self._res_gids
Expand All @@ -512,9 +512,9 @@ def rep_res_gids(self):

return rep_gids

@classmethod
@ classmethod
def get_region_rep_profile(cls, gen_fpath, rev_summary,
cf_dset=MetaKeyName.CF_PROFILE,
cf_dset='cf_profile',
rep_method='meanoid',
err_method='rmse',
weight=MetaKeyName.GID_COUNTS,
Expand Down Expand Up @@ -568,7 +568,7 @@ class RepProfilesBase(ABC):
"""Abstract utility framework for representative profile run classes."""

def __init__(self, gen_fpath, rev_summary, reg_cols=None,
cf_dset=MetaKeyName.CF_PROFILE, rep_method='meanoid',
cf_dset='cf_profile', rep_method='meanoid',
err_method='rmse', weight=MetaKeyName.GID_COUNTS,
n_profiles=1):
"""
Expand Down Expand Up @@ -634,7 +634,7 @@ def __init__(self, gen_fpath, rev_summary, reg_cols=None,
self._rep_method = rep_method
self._err_method = err_method

@staticmethod
@ staticmethod
def _parse_rev_summary(rev_summary):
"""Extract, parse, and check the rev summary table.
Expand Down Expand Up @@ -670,7 +670,7 @@ def _parse_rev_summary(rev_summary):

return rev_summary

@staticmethod
@ staticmethod
def _check_req_cols(df, cols):
"""Check a dataframe for required columns.
Expand All @@ -693,7 +693,7 @@ def _check_req_cols(df, cols):
logger.error(e)
raise KeyError(e)

@staticmethod
@ staticmethod
def _check_rev_gen(gen_fpath, cf_dset, rev_summary):
"""Check rev gen file for requisite datasets.
Expand Down Expand Up @@ -736,7 +736,7 @@ def _init_profiles(self):
dtype=np.float32)
for k in range(self._n_profiles)}

@property
@ property
def time_index(self):
"""Get the time index for the rep profiles.
Expand All @@ -756,7 +756,7 @@ def time_index(self):

return self._time_index

@property
@ property
def meta(self):
"""Meta data for the representative profiles.
Expand All @@ -768,7 +768,7 @@ def meta(self):
"""
return self._meta

@property
@ property
def profiles(self):
"""Get the arrays of representative CF profiles corresponding to meta.
Expand Down Expand Up @@ -866,15 +866,15 @@ def save_profiles(self, fout, save_rev_summary=True,
scaled_precision=scaled_precision)
self._write_h5_out(fout, save_rev_summary=save_rev_summary)

@abstractmethod
@ abstractmethod
def _run_serial(self):
"""Abstract method for serial run method."""

@abstractmethod
@ abstractmethod
def _run_parallel(self):
"""Abstract method for parallel run method."""

@abstractmethod
@ abstractmethod
def run(self):
"""Abstract method for generic run method."""

Expand All @@ -883,7 +883,7 @@ class RepProfiles(RepProfilesBase):
"""RepProfiles"""

def __init__(self, gen_fpath, rev_summary, reg_cols,
cf_dset=MetaKeyName.CF_PROFILE,
cf_dset='cf_profile',
rep_method='meanoid', err_method='rmse',
weight=MetaKeyName.GID_COUNTS,
n_profiles=1, aggregate_profiles=False):
Expand Down Expand Up @@ -1001,7 +1001,7 @@ def __init__(self, gen_fpath, rev_summary, reg_cols,
'key such as "sc_gid".')
logger.error(e)
raise ValueError(e)
elif isinstance(reg_cols, str):
if isinstance(reg_cols, str):
reg_cols = [reg_cols]
elif not isinstance(reg_cols, list):
reg_cols = list(reg_cols)
Expand Down

0 comments on commit 2b6b919

Please sign in to comment.