Skip to content

Commit

Permalink
Merge pull request #448 from NREL/pp/year_in_run_dir_fix
Browse files Browse the repository at this point in the history
Fix gen output file name if year in directory
  • Loading branch information
ppinchuk authored Apr 2, 2024
2 parents 4ccfbc8 + 57e9908 commit 9cf454c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
6 changes: 4 additions & 2 deletions reV/generation/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -881,9 +881,10 @@ def _init_fpath(self, out_fpath, module):
out_fn = out_fn.replace(".h5", extension_with_module)

# ensure year is in out_fpath
if self.year is not None and str(self.year) not in out_fn:
if self.year is not None:
extension_with_year = "_{}.h5".format(self.year)
out_fn = out_fn.replace(".h5", extension_with_year)
if extension_with_year not in out_fn:
out_fn = out_fn.replace(".h5", extension_with_year)

# create and use optional output dir
if project_dir and not os.path.exists(project_dir):
Expand Down Expand Up @@ -1134,6 +1135,7 @@ def _pre_split_pc(self, pool_size=None):
.format(len(pc_chunks), [len(x) for x in pc_chunks]))
return N, pc_chunks

# pylint: disable=unused-argument
def _reduce_kwargs(self, pc, **kwargs):
"""Placeholder for functions that need to reduce the global kwargs that
they send to workers to reduce memory footprint
Expand Down
37 changes: 37 additions & 0 deletions tests/test_gen_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,43 @@ def test_gen_mw_config_input(runner, clear_loggers, expected_log_message):
clear_loggers()


def test_year_in_dir_name(runner, clear_loggers):
"""Test generation run with year in project dir"""
with tempfile.TemporaryDirectory() as td:

run_dir = os.path.join(td, 'generation_2012_2013')
os.mkdir(run_dir)
project_points = os.path.join(TESTDATADIR, 'config', '..',
'config', "wtk_pp_2012_10.csv")
resource_file = os.path.join(TESTDATADIR, 'wtk/ri_100_wtk_{}.h5')
sam_files = {"wind0":
os.path.join(TESTDATADIR,
"SAM/wind_gen_standard_losses_0.json")}

config = os.path.join(TESTDATADIR, 'config', 'local_wind.json')
config = safe_json_load(config)

config['project_points'] = project_points
config['resource_file'] = resource_file
config['sam_files'] = sam_files
config['log_directory'] = run_dir
config["analysis_years"] = [2012, 2013]

config_path = os.path.join(run_dir, 'config.json')
with open(config_path, 'w') as f:
json.dump(config, f)

result = runner.invoke(main, ['generation', '-c', config_path])
msg = ('Failed with error {}'
.format(traceback.print_exception(*result.exc_info)))
assert result.exit_code == 0, msg

h5_files = [fn for fn in os.listdir(run_dir)
if "generation_2012_2013" in fn and ".h5" in fn]
assert len(h5_files) == 2
clear_loggers()


def execute_pytest(capture='all', flags='-rapP'):
"""Execute module as pytest with detailed summary report.
Expand Down

0 comments on commit 9cf454c

Please sign in to comment.