Skip to content

Commit

Permalink
MetaKeyName class for replacing hardcoded strings in summaries and metas
Browse files Browse the repository at this point in the history
  • Loading branch information
bnb32 committed May 3, 2024
1 parent 30637a3 commit 08d091b
Show file tree
Hide file tree
Showing 71 changed files with 2,336 additions and 1,878 deletions.
5 changes: 2 additions & 3 deletions examples/aws_pcluster/make_project_points.py
Expand Up @@ -3,7 +3,6 @@
"""
from rex import Resource


if __name__ == '__main__':
fp = '/nrel/nsrdb/v3/nsrdb_2019.h5'
fp = '/nrel/wtk/conus/wtk_conus_2007.h5'
Expand All @@ -22,7 +21,7 @@

print(meta[mask])
pp = meta[mask]
pp['gid'] = pp.index.values
pp[MetaKeyName.GID] = pp.index.values
pp['config'] = 'def'
pp = pp[['gid', 'config']]
pp = pp[[MetaKeyName.GID, 'config']]
pp.to_csv('./points_front_range.csv', index=False)
28 changes: 17 additions & 11 deletions examples/bespoke_wind_plants/single_run.py
Expand Up @@ -2,24 +2,29 @@
"""
An example single run to get bespoke wind plant layout
"""
import numpy as np
import matplotlib.pyplot as plt
from reV.bespoke.bespoke import BespokeSinglePlant
from reV.bespoke.plotting_functions import plot_poly, plot_turbines,\
plot_windrose
from reV import TESTDATADIR
from reV.supply_curve.tech_mapping import TechMapping

import json
import os
import shutil
import tempfile

import matplotlib.pyplot as plt
import numpy as np

from reV import TESTDATADIR
from reV.bespoke.bespoke import BespokeSinglePlant
from reV.bespoke.plotting_functions import (
plot_poly,
plot_turbines,
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 = ('cf_mean', 'cf_profile')
AGG_DSET = (MetaKeyName.CF_MEAN, MetaKeyName.CF_PROFILE)

# note that this differs from the
EXCL_DICT = {'ri_srtm_slope': {'inclusion_range': (None, 5),
Expand All @@ -29,7 +34,7 @@
'ri_reeds_regions': {'inclusion_range': (None, 400),
'exclude_nodata': False}}

with open(SAM, 'r') as f:
with open(SAM) as f:
SAM_SYS_INPUTS = json.load(f)

SAM_SYS_INPUTS['wind_farm_wake_model'] = 2
Expand All @@ -56,7 +61,8 @@
1E5 * 0.1 + (1 - 0.1))"""
objective_function = "cost / aep"

output_request = ('system_capacity', 'cf_mean', 'cf_profile')
output_request = ('system_capacity', MetaKeyName.CF_MEAN,
MetaKeyName.CF_PROFILE)
gid = 33
with tempfile.TemporaryDirectory() as td:
excl_fp = os.path.join(td, 'ri_exclusions.h5')
Expand Down
5 changes: 3 additions & 2 deletions examples/marine_energy/plot_lcoe.py
Expand Up @@ -2,16 +2,17 @@
Simple plot script for wave LCOE
"""
import os
import pandas as pd

import matplotlib.pyplot as plt
import pandas as pd

fps = ['./atlantic_rm5/atlantic_rm5_agg.csv',
'./pacific_rm5/pacific_rm5_agg.csv',
]

for fp in fps:
df = pd.read_csv(fp)
a = plt.scatter(df.longitude, df.latitude, c=df['mean_lcoe'],
a = plt.scatter(df.longitude, df.latitude, c=df[MetaKeyName.MEAN_LCOE],
s=0.5, vmin=0, vmax=1500)
plt.colorbar(a, label='lcoe_fcr ($/MWh)')
tag = os.path.basename(fp).replace('_agg.csv', '')
Expand Down
42 changes: 27 additions & 15 deletions reV/SAM/SAM.py
Expand Up @@ -6,22 +6,34 @@
import copy
import json
import logging
import numpy as np
import os
import pandas as pd
from warnings import warn
import PySAM.GenericSystem as generic

from reV.utilities.exceptions import (SAMInputWarning, SAMInputError,
SAMExecutionError, ResourceError)

from rex.multi_file_resource import (MultiFileResource, MultiFileNSRDB,
MultiFileWTK)
from rex.renewable_resource import (WindResource, SolarResource, NSRDB,
WaveResource, GeothermalResource)
import numpy as np
import pandas as pd
import PySAM.GenericSystem as generic
from rex.multi_file_resource import (
MultiFileNSRDB,
MultiFileResource,
MultiFileWTK,
)
from rex.multi_res_resource import MultiResolutionResource
from rex.renewable_resource import (
NSRDB,
GeothermalResource,
SolarResource,
WaveResource,
WindResource,
)
from rex.utilities.utilities import check_res_file

from reV.utilities import MetaKeyName
from reV.utilities.exceptions import (
ResourceError,
SAMExecutionError,
SAMInputError,
SAMInputWarning,
)

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -169,10 +181,10 @@ def _make_res_kwargs(cls, res_handler, project_points, output_request,
elif res_handler == WindResource:
args += (project_points.h, )
kwargs['icing'] = project_points.sam_config_obj.icing
if project_points.curtailment is not None:
if project_points.curtailment.precipitation:
# make precip rate available for curtailment analysis
kwargs['precip_rate'] = True
if (project_points.curtailment is not None and
project_points.curtailment.precipitation):
# make precip rate available for curtailment analysis
kwargs['precip_rate'] = True

elif res_handler == GeothermalResource:
args += (project_points.d, )
Expand Down Expand Up @@ -567,7 +579,7 @@ def __init__(self, meta, sam_sys_inputs, output_request,
Site-agnostic SAM system model inputs arguments.
output_request : list
Requested SAM outputs (e.g., 'cf_mean', 'annual_energy',
'cf_profile', 'gen_profile', 'energy_yield', 'ppa_price',
, 'gen_profile', 'energy_yield', 'ppa_price',
'lcoe_fcr').
site_sys_inputs : dict
Optional set of site-specific SAM system inputs to complement the
Expand Down
33 changes: 19 additions & 14 deletions reV/SAM/econ.py
Expand Up @@ -4,24 +4,27 @@
Wraps the NREL-PySAM lcoefcr and singleowner modules with
additional reV features.
"""
from copy import deepcopy
import logging
import numpy as np
from copy import deepcopy
from warnings import warn

import numpy as np
import PySAM.Lcoefcr as PySamLCOE
import PySAM.Singleowner as PySamSingleOwner

from reV.SAM.defaults import DefaultSingleOwner, DefaultLCOE
from reV.handlers.outputs import Outputs
from reV.SAM.windbos import WindBos
from reV.SAM.defaults import DefaultLCOE, DefaultSingleOwner
from reV.SAM.SAM import RevPySam
from reV.SAM.windbos import WindBos
from reV.utilities import MetaKeyName
from reV.utilities.exceptions import SAMExecutionError

logger = logging.getLogger(__name__)


class Economic(RevPySam):
"""Base class for SAM economic models."""

MODULE = None

def __init__(self, sam_sys_inputs, site_sys_inputs=None,
Expand Down Expand Up @@ -172,7 +175,7 @@ def _get_cf_profiles(sites, cf_file, year):
with Outputs(cf_file) as cfh:

# get the index location of the site in question
site_gids = list(cfh.get_meta_arr('gid'))
site_gids = list(cfh.get_meta_arr(MetaKeyName.GID))
isites = [site_gids.index(s) for s in sites]

# look for the cf_profile dataset
Expand Down Expand Up @@ -335,6 +338,7 @@ def reV_run(cls, site, site_df, inputs, output_request):
class LCOE(Economic):
"""SAM LCOE model.
"""

MODULE = 'lcoefcr'
PYSAM = PySamLCOE

Expand Down Expand Up @@ -375,7 +379,7 @@ def _parse_lcoe_inputs(site_df, cf_file, year):

# get the cf_file meta data gid's to use as indexing tools
with Outputs(cf_file) as cfh:
site_gids = list(cfh.meta['gid'])
site_gids = list(cfh.meta[MetaKeyName.GID])

calc_aey = False
if 'annual_energy' not in site_df:
Expand Down Expand Up @@ -463,6 +467,7 @@ def reV_run(cls, points_control, site_df, cf_file, year,
class SingleOwner(Economic):
"""SAM single owner economic model.
"""

MODULE = 'singleowner'
PYSAM = PySamSingleOwner

Expand Down Expand Up @@ -497,14 +502,14 @@ def _windbos(inputs):
"""

outputs = {}
if inputs is not None:
if 'total_installed_cost' in inputs:
if isinstance(inputs['total_installed_cost'], str):
if inputs['total_installed_cost'].lower() == 'windbos':
wb = WindBos(inputs)
inputs['total_installed_cost'] = \
wb.total_installed_cost
outputs = wb.output
if (inputs is not None and
'total_installed_cost' in inputs and
isinstance(inputs['total_installed_cost'], str) and
inputs['total_installed_cost'].lower() == 'windbos'):
wb = WindBos(inputs)
inputs['total_installed_cost'] = \
wb.total_installed_cost
outputs = wb.output
return inputs, outputs

@staticmethod
Expand Down

0 comments on commit 08d091b

Please sign in to comment.