From cfa53bdf9fd1b34907df3d1afb02ae0ceea36aad Mon Sep 17 00:00:00 2001 From: ppinchuk Date: Tue, 22 Oct 2024 18:19:19 -0600 Subject: [PATCH 1/2] Add test for LCOE dsets to get added to pass through --- tests/test_handlers_multiyear.py | 40 +++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/tests/test_handlers_multiyear.py b/tests/test_handlers_multiyear.py index a90c20803..a3fa1563f 100644 --- a/tests/test_handlers_multiyear.py +++ b/tests/test_handlers_multiyear.py @@ -7,6 +7,7 @@ import shutil import tempfile import traceback +from copy import deepcopy import h5py import numpy as np @@ -16,7 +17,8 @@ from reV import TESTDATADIR from reV.cli import main -from reV.handlers.multi_year import MultiYear +from reV.generation.base import LCOE_REQUIRED_OUTPUTS +from reV.handlers.multi_year import MultiYear, MultiYearGroup from reV.handlers.outputs import Outputs from reV.utilities import ModuleName @@ -371,6 +373,42 @@ def test_my_stdev(dset, group): compare_arrays(my_std, dset_std, "Saved STDEV") +def test_pass_through_dsets(): + """test that LCOE dsets correctly added to pass through. """ + test_pass_through_dsets = ["capital_cost", "reg_mult", + "fixed_operating_cost", "system_capacity", + "system_capacity_ac", "fixed_charge_rate", + "variable_operating_cost", "dc_ac_ratio"] + + existing_dsets = list(LCOE_REQUIRED_OUTPUTS) + ["dc_ac_ratio"] + + with tempfile.TemporaryDirectory() as temp: + temp_h5_files = [os.path.join(temp, os.path.basename(fp)) + for fp in H5_FILES] + for fp, fp_temp in zip(H5_FILES, temp_h5_files): + shutil.copy(fp, fp_temp) + + for fp in temp_h5_files: + for i, dset in enumerate(existing_dsets): + with h5py.File(fp, 'a') as f: + shape = f['meta'].shape + arr = np.arange(shape[0]) * (i + 1) + f.create_dataset(dset, shape, data=arr) + + group = {"dsets": ["cf_profile", "cf_profile_ac", "cf_mean", + "cf_mean_ac", "ghi_mean", "lcoe_fcr", "ac", "dc", + "clipped_power"], + "source_dir": temp, + "source_prefix": "gen_ri_pv", + "pass_through_dsets": deepcopy(test_pass_through_dsets)} + + group = MultiYearGroup("test", ".", **group) + test_ptd = group.pass_through_dsets + + assert test_pass_through_dsets != test_ptd + assert all(dset in test_ptd for dset in LCOE_REQUIRED_OUTPUTS) + + def execute_pytest(capture='all', flags='-rapP'): """Execute module as pytest with detailed summary report. From 8c443a8c2c050bfbfd33b5bca93f73af3f1b9fae Mon Sep 17 00:00:00 2001 From: ppinchuk Date: Tue, 22 Oct 2024 18:19:44 -0600 Subject: [PATCH 2/2] Fix bug in MY collection if `dsets` does not contain all possible dsets --- reV/handlers/multi_year.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/reV/handlers/multi_year.py b/reV/handlers/multi_year.py index 993100219..6941e2455 100644 --- a/reV/handlers/multi_year.py +++ b/reV/handlers/multi_year.py @@ -96,14 +96,15 @@ def _parse_pass_through_dsets(self, dsets, pass_through_dsets): pass_through_dsets : list List of pass through datasets. """ + with Resource(self.source_files[0]) as res: + all_dsets = res.datasets + if isinstance(dsets, str) and dsets == 'PIPELINE': - files = parse_previous_status(self._dirout, ModuleName.MULTI_YEAR) - with Resource(files[0]) as res: - dsets = res.datasets + dsets = all_dsets if "lcoe_fcr" in dsets: for dset in LCOE_REQUIRED_OUTPUTS: - if dset not in pass_through_dsets and dset in dsets: + if dset not in pass_through_dsets and dset in all_dsets: pass_through_dsets.append(dset) if "dc_ac_ratio" in dsets: