Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decreasing memory footprint of Tech Mapping #504

Draft
wants to merge 9 commits into
base: mg/agg_zones
Choose a base branch
from
4 changes: 3 additions & 1 deletion examples/bespoke_wind_plants/single_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@
shutil.copy(RES.format(2013), res_fp.format(2013))
res_fp = res_fp.format('*')

TechMapping.run(excl_fp, RES.format(2012), dset=TM_DSET, max_workers=1)
TechMapping.run(
excl_fp, RES.format(2012), tm_dset=TM_DSET, max_workers=1
)
bsp = BespokeSinglePlant(gid, excl_fp, res_fp, TM_DSET,
SAM_SYS_INPUTS,
objective_function, cost_function,
Expand Down
6 changes: 4 additions & 2 deletions reV/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from reV.handlers.cli_multi_year import my_command
from reV.supply_curve.cli_sc_aggregation import sc_agg_command
from reV.supply_curve.cli_supply_curve import sc_command
from reV.supply_curve.cli_tech_mapping import tm_command
from reV.rep_profiles.cli_rep_profiles import rep_profiles_command
from reV.hybrids.cli_hybrids import hybrids_command
from reV.nrwal.cli_nrwal import nrwal_command
Expand All @@ -24,8 +25,9 @@


commands = [bespoke_command, gen_command, econ_command, collect_command,
my_command, sc_agg_command, sc_command, rep_profiles_command,
hybrids_command, nrwal_command, qa_qc_command]
my_command, tm_command, sc_agg_command, sc_command,
rep_profiles_command, hybrids_command, nrwal_command,
qa_qc_command]
main = make_cli(commands, info={"name": "reV", "version": __version__})
main.add_command(qa_qc_extra)
main.add_command(project_points)
Expand Down
2 changes: 1 addition & 1 deletion reV/supply_curve/aggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ def _validate_tech_mapping(self):
)
try:
TechMapping.run(
self._excl_fpath, self._res_fpath, dset=self._tm_dset
self._excl_fpath, self._res_fpath, tm_dset=self._tm_dset
)
except Exception as e:
msg = (
Expand Down
66 changes: 66 additions & 0 deletions reV/supply_curve/cli_tech_mapping.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# -*- coding: utf-8 -*-
"""
reV Tech Mapping CLI utility functions.
"""
import logging

from gaps.cli import as_click_command, CLICommandFromClass

from reV.supply_curve.tech_mapping import TechMapping
from reV.utilities import ModuleName
from reV.utilities.exceptions import ConfigError
from reV.supply_curve.cli_sc_aggregation import _format_res_fpath

logger = logging.getLogger(__name__)


def _preprocessor(config):
"""Preprocess tech mapping config user input.

Parameters
----------
config : dict
User configuration file input as (nested) dict.

Returns
-------
dict
Updated config file.
"""
_validate_excl_fpath(config)
config = _format_res_fpath(config)
_validate_tm_dset(config)

return config


def _validate_excl_fpath(config):
paths = config["excl_fpath"]
if isinstance(paths, list):
raise ConfigError(
"Multiple exclusion file paths passed via excl_fpath. "
"Cannot run tech mapping with arbitrary multiple exclusion. "
"Specify a single exclusion file path to write to."
)


def _validate_tm_dset(config):
if config.get("tm_dset") is None:
raise ConfigError(
"tm_dset must be specified to run tech mapping."
)


tm_command = CLICommandFromClass(TechMapping, method="run",
name=str(ModuleName.TECH_MAPPING),
add_collect=False, split_keys=None,
config_preprocessor=_preprocessor)
main = as_click_command(tm_command)


if __name__ == '__main__':
try:
main(obj={})
except Exception:
logger.exception('Error running reV Tech Mapping CLI.')
raise
Loading
Loading