Skip to content

Commit

Permalink
Merge pull request #459 from NREL/pp/my_fix
Browse files Browse the repository at this point in the history
Multi-year collection bug fix
  • Loading branch information
ppinchuk authored Jun 27, 2024
2 parents 77f3bb5 + 1a6865a commit a27dc0a
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 7 deletions.
8 changes: 2 additions & 6 deletions reV/handlers/multi_year.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,9 @@ def _parse_pass_through_dsets(self, dsets, pass_through_dsets):

if "lcoe_fcr" in dsets:
for dset in LCOE_REQUIRED_OUTPUTS:
if dset not in pass_through_dsets:
if dset not in pass_through_dsets and dset in dsets:
pass_through_dsets.append(dset)

if "dc_ac_ratio" in dsets:
if "dc_ac_ratio" not in pass_through_dsets:
pass_through_dsets.append("dc_ac_ratio")
Expand Down Expand Up @@ -839,11 +840,6 @@ def my_collect_groups(out_fpath, groups, clobber=True):
dset, group=group['group'])

pass_through_dsets = group.get('pass_through_dsets') or []
if "lcoe_fcr" in group['dsets']:
for dset in LCOE_REQUIRED_OUTPUTS:
if dset not in pass_through_dsets:
pass_through_dsets.append(dset)

for dset in pass_through_dsets:
MultiYear.pass_through(out_fpath, group['source_files'],
dset, group=group['group'])
Expand Down
2 changes: 1 addition & 1 deletion reV/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
reV Version number
"""

__version__ = "0.9.2"
__version__ = "0.9.3"
64 changes: 64 additions & 0 deletions tests/test_handlers_multiyear.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,70 @@ def test_cli(runner, clear_loggers):
clear_loggers()


# pylint: disable=no-member
def test_cli_single_file(runner, clear_loggers):
"""Test multi year collection cli for a single yearly file."""

with tempfile.TemporaryDirectory() as temp:
config = {"log_directory": temp,
"execution_control": {"option": "local"},
"groups": {"none": {"dsets": ["cf_mean", "lcoe_fcr"],
"pass_through_dsets": ['pass_through_1',
'pass_through_2'],
"source_dir": temp,
"source_prefix": (
"ri_wind_gen_profiles"
)}},
"log_level": "INFO"}

dirname = os.path.basename(temp)
fn = "{}_{}.h5".format(dirname, ModuleName.MULTI_YEAR)
my_out = os.path.join(temp, fn).replace("-", "_")
fp_in = os.path.join(temp, 'ri_wind_gen_profiles_2010.h5')
shutil.copy(os.path.join(TESTDATADIR, 'gen_out',
'ri_wind_gen_profiles_2010.h5'), fp_in)

pass_through_dsets = config['groups']['none']['pass_through_dsets']
for i, dset in enumerate(pass_through_dsets):
with h5py.File(fp_in, 'a') as f:
shape = f['meta'].shape
arr = np.arange(shape[0]) * (i + 1)
f.create_dataset(dset, shape, data=arr)

with h5py.File(my_out, 'a') as f:
f.create_dataset(dset, shape, data=np.zeros_like(arr))

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

result = runner.invoke(main, [str(ModuleName.MULTI_YEAR),
'-c', fp_config])
msg = ('Failed with error {}'
.format(traceback.print_exception(*result.exc_info)))
assert result.exit_code == 0, msg
assert "WARNING" in result.output
assert "Found existing multi-year file" in result.output

with Resource(my_out) as res:
assert 'cf_mean-2010' in res.dsets
assert 'cf_mean-means' in res.dsets
assert 'cf_mean-stdev' in res.dsets
assert 'lcoe_fcr-2010' in res.dsets
assert 'lcoe_fcr-means' in res.dsets
assert 'lcoe_fcr-stdev' in res.dsets
assert 'pass_through_1' in res.dsets
assert 'pass_through_2' in res.dsets
assert 'pass_through_1-means' not in res.dsets
assert 'pass_through_2-means' not in res.dsets
assert np.allclose(res['pass_through_1'],
1 * np.arange(len(res.meta)))
assert np.allclose(res['pass_through_2'],
2 * np.arange(len(res.meta)))

clear_loggers()


@pytest.mark.parametrize(('dset', 'group'), [
('cf_mean', None),
('cf_mean', 'pytest')])
Expand Down

0 comments on commit a27dc0a

Please sign in to comment.