Skip to content

Commit

Permalink
init commit
Browse files Browse the repository at this point in the history
  • Loading branch information
bnb32 committed May 2, 2024
1 parent e350725 commit 30637a3
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 36 deletions.
69 changes: 33 additions & 36 deletions reV/bespoke/bespoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,40 @@
reV bespoke wind plant analysis tools
"""
# pylint: disable=anomalous-backslash-in-string
from inspect import signature
import time
import logging
import copy
import pandas as pd
import numpy as np
import os
import json
import psutil
import logging
import os
import time
from concurrent.futures import as_completed
from importlib import import_module
from inspect import signature
from numbers import Number
from concurrent.futures import as_completed
from warnings import warn

import numpy as np
import pandas as pd
import psutil
from rex.joint_pd.joint_pd import JointPD
from rex.multi_year_resource import MultiYearWindResource
from rex.renewable_resource import WindResource
from rex.utilities.bc_parse_table import parse_bc_table
from rex.utilities.execution import SpawnProcessPool
from rex.utilities.loggers import create_dirs, log_mem
from rex.utilities.utilities import parse_year

from reV.config.output_request import SAMOutputRequest
from reV.generation.generation import Gen
from reV.SAM.generation import WindPower, WindPowerPD
from reV.econ.utilities import lcoe_fcr
from reV.handlers.outputs import Outputs
from reV.generation.generation import Gen
from reV.handlers.exclusions import ExclusionLayers
from reV.handlers.outputs import Outputs
from reV.SAM.generation import WindPower, WindPowerPD
from reV.supply_curve.aggregation import AggFileHandler, BaseAggregation
from reV.supply_curve.extent import SupplyCurveExtent
from reV.supply_curve.points import AggregationSupplyCurvePoint as AggSCPoint
from reV.supply_curve.points import SupplyCurvePoint
from reV.supply_curve.aggregation import BaseAggregation, AggFileHandler
from reV.utilities.exceptions import (EmptySupplyCurvePointError,
FileInputError)
from reV.utilities import log_versions, ModuleName

from rex.utilities.bc_parse_table import parse_bc_table
from rex.joint_pd.joint_pd import JointPD
from rex.renewable_resource import WindResource
from rex.multi_year_resource import MultiYearWindResource
from rex.utilities.loggers import log_mem, create_dirs
from rex.utilities.utilities import parse_year
from rex.utilities.execution import SpawnProcessPool
from reV.utilities import ModuleName, log_versions
from reV.utilities.exceptions import EmptySupplyCurvePointError, FileInputError

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -79,7 +78,7 @@ def __init__(self, res_fpath, sc_gid_to_hh, sc_gid_to_res_gid):
self._pre_load_data()

def _pre_load_data(self):
"""Pre-load the resource data. """
"""Pre-load the resource data."""

for sc_gid, gids in self.sc_gid_to_res_gid.items():
hh = self.sc_gid_to_hh[sc_gid]
Expand Down Expand Up @@ -186,7 +185,7 @@ def __getitem__(self, key):


class BespokeSinglePlant:
"""Framework for analyzing and optimized a wind plant layout specific to
"""Framework for analyzing and optimizing a wind plant layout specific to
the local wind resource and exclusions for a single reV supply curve point.
"""

Expand Down Expand Up @@ -530,7 +529,7 @@ def _parse_gid_map(gid_map):
for i in gid_map['gid'].keys()}

elif gid_map.endswith('.json'):
with open(gid_map, 'r') as f:
with open(gid_map) as f:
gid_map = json.load(f)

return gid_map
Expand Down Expand Up @@ -892,7 +891,7 @@ def initialize_wind_plant_ts(self):

@property
def wind_plant_pd(self):
"""reV WindPowerPD compute object for plant layout optimization based
"""ReV WindPowerPD compute object for plant layout optimization based
on wind joint probability distribution
Returns
Expand All @@ -909,7 +908,7 @@ def wind_plant_pd(self):

@property
def wind_plant_ts(self):
"""reV WindPower compute object(s) based on wind resource timeseries
"""ReV WindPower compute object(s) based on wind resource timeseries
data keyed by year
Returns
Expand Down Expand Up @@ -1066,9 +1065,7 @@ def _check_sys_inputs(plant1, plant2,
"""
bad = []
for k, v in plant1.sam_sys_inputs.items():
if k not in plant2.sam_sys_inputs:
bad.append(k)
elif str(v) != str(plant2.sam_sys_inputs[k]):
if k not in plant2.sam_sys_inputs or str(v) != str(plant2.sam_sys_inputs[k]):
bad.append(k)
bad = [b for b in bad if b not in ignore]
if any(bad):
Expand Down Expand Up @@ -1277,7 +1274,7 @@ def __init__(self, excl_fpath, res_fpath, tm_dset, objective_function,
resolution=64, excl_area=None, data_layers=None,
pre_extract_inclusions=False, prior_run=None, gid_map=None,
bias_correct=None, pre_load_data=False):
"""reV bespoke analysis class.
r"""ReV bespoke analysis class.
Much like generation, ``reV`` bespoke analysis runs SAM
simulations by piping in renewable energy resource data (usually
Expand Down Expand Up @@ -1861,7 +1858,7 @@ def _check_files(self):
assert any(f.dsets)

def _pre_load_data(self, pre_load_data):
"""Pre-load resource data, if requested. """
"""Pre-load resource data, if requested."""
if not pre_load_data:
return

Expand Down Expand Up @@ -1898,7 +1895,7 @@ def _hh_for_sc_gid(self, sc_gid):
return int(config["wind_turbine_hub_ht"])

def _pre_loaded_data_for_sc_gid(self, sc_gid):
"""Pre-load data for a given SC GID, if requested. """
"""Pre-load data for a given SC GID, if requested."""
if self._pre_loaded_data is None:
return None

Expand Down Expand Up @@ -1981,7 +1978,7 @@ def meta(self):

@property
def slice_lookup(self):
"""dict | None: Lookup mapping sc_point_gid to exclusion slice. """
"""Dict | None: Lookup mapping sc_point_gid to exclusion slice."""
if self._slice_lookup is None and self._inclusion_mask is not None:
with SupplyCurveExtent(self._excl_fpath,
resolution=self._resolution) as sc:
Expand Down Expand Up @@ -2146,7 +2143,7 @@ def save_outputs(self, out_fpath):
except Exception as e:
msg = 'Failed to write "{}" to disk.'.format(dset)
logger.exception(msg)
raise IOError(msg) from e
raise OSError(msg) from e

logger.info('Saved output data to: {}'.format(out_fpath))
return out_fpath
Expand Down
38 changes: 38 additions & 0 deletions reV/utilities/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,49 @@
reV utilities.
"""
from enum import Enum

import PySAM
from rex.utilities.loggers import log_versions as rex_log_versions

from reV.version import __version__


class SupplyCurvePointSummaryKey(str, Enum):
"""An enumerated map to Supply Curve Point summary keys.
Each output name should match the name of a key in
meth:`AggregationSupplyCurvePoint.summary` or
meth:`GenerationSupplyCurvePoint.point_summary`
"""

SC_POINT_GID = 'sc_point_gid'
SOURCE_GIDS = 'source_gids'
GID_COUNTS = 'gid_counts'
GID = 'gid'
N_GIDS = 'n_gids'
RES_GIDS = 'res_gids'
GEN_GIDS = 'gen_gids'
AREA_SQ_KM = 'area_sq_km'
LATITUDE = 'latitude'
LONGITUDE = 'longitude'
COUNTRY = 'country'
STATE = 'state'
COUNTY = 'county'
COUNTRY = 'country',
ELEVATION = 'elevation'
TIMEZONE = 'timezone'
MEAN_CF = 'mean_cf'
MEAN_LCOE = 'mean_lcoe'
MEAN_RES = 'mean_res'
CAPACITY = 'capacity'

def __str__(self):
return self.value

def __format__(self, format_spec):
return str.__format__(self.value, format_spec)


class ModuleName(str, Enum):
"""A collection of the module names available in reV.
Expand Down

0 comments on commit 30637a3

Please sign in to comment.