Skip to content

Commit

Permalink
Add test for new mean cf outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
ppinchuk committed Jun 8, 2024
1 parent 4f18fbe commit e789492
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 13 deletions.
22 changes: 9 additions & 13 deletions reV/supply_curve/sc_aggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ def _check_data_layers(

@staticmethod
def _get_res_gen_lcoe_data(
gen, res_class_dset, res_class_bins, cf_dset, lcoe_dset
gen, res_class_dset, res_class_bins, lcoe_dset
):
"""Extract the basic resource / generation / lcoe data to be used in
the aggregation process.
Expand All @@ -800,8 +800,6 @@ def _get_res_gen_lcoe_data(
res_class_bins : list | None
List of two-entry lists dictating the resource class bins.
None if no resource classes.
cf_dset : str
Dataset name from f_gen containing capacity factor mean values.
lcoe_dset : str
Dataset name from f_gen containing LCOE mean values.
Expand All @@ -811,16 +809,14 @@ def _get_res_gen_lcoe_data(
Extracted resource data from res_class_dset
res_class_bins : list
List of resouce class bin ranges.
cf_data : np.ndarray | None
Capacity factor data extracted from cf_dset in gen
lcoe_data : np.ndarray | None
LCOE data extracted from lcoe_dset in gen
"""

dset_list = (res_class_dset, cf_dset, lcoe_dset)
dset_list = (res_class_dset, lcoe_dset)
gen_dsets = [] if gen is None else gen.datasets
labels = ("res_class_dset", "cf_dset", "lcoe_dset")
temp = [None, None, None]
labels = ("res_class_dset", "lcoe_dset")
temp = [None, None]

if isinstance(gen, Resource):
source_fps = [gen.h5_file]
Expand All @@ -847,12 +843,12 @@ def _get_res_gen_lcoe_data(
logger.warning(w)
warn(w, OutputWarning)

res_data, cf_data, lcoe_data = temp
res_data, lcoe_data = temp

if res_class_dset is None or res_class_bins is None:
res_class_bins = [None]

return res_data, res_class_bins, cf_data, lcoe_data
return res_data, res_class_bins, lcoe_data

@staticmethod
def _get_extra_dsets(gen, h5_dsets):
Expand Down Expand Up @@ -1110,9 +1106,9 @@ def run_serial(
excl_fpath, gen_fpath, **file_kwargs
) as fh:
temp = cls._get_res_gen_lcoe_data(
fh.gen, res_class_dset, res_class_bins, cf_dset, lcoe_dset
fh.gen, res_class_dset, res_class_bins, lcoe_dset
)
res_data, res_class_bins, cf_data, lcoe_data = temp
res_data, res_class_bins, lcoe_data = temp
h5_dsets_data = cls._get_extra_dsets(fh.gen, h5_dsets)

n_finished = 0
Expand All @@ -1131,7 +1127,7 @@ def run_serial(
gen_index,
res_class_dset=res_data,
res_class_bin=res_bin,
cf_dset=cf_data,
cf_dset=cf_dset,
lcoe_dset=lcoe_data,
h5_dsets=h5_dsets_data,
data_layers=fh.data_layers,
Expand Down
20 changes: 20 additions & 0 deletions tests/test_supply_curve_sc_aggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,22 @@ def test_agg_summary():
def test_agg_summary_solar_ac(pd):
"""Test the aggregation summary method for solar ac outputs."""

with Outputs(GEN, "r") as out:
cf_means_dc = out["cf_mean-means"]

with tempfile.TemporaryDirectory() as td:
gen = os.path.join(td, "gen.h5")
shutil.copy(GEN, gen)
Outputs.add_dataset(
gen, "dc_ac_ratio", np.array([1.3] * 188), np.float32
)
Outputs.add_dataset(
gen, "cf_mean_ac-means", cf_means_dc * 1.3, np.float32
)

with Outputs(gen, "r") as out:
assert "dc_ac_ratio" in out.datasets
assert "cf_mean_ac-means" in out.datasets

sca = SupplyCurveAggregation(
EXCL,
Expand All @@ -173,8 +180,21 @@ def test_agg_summary_solar_ac(pd):
summary = sca.summarize(gen, max_workers=1)

assert SupplyCurveField.CAPACITY_AC_MW in summary
assert SupplyCurveField.CAPACITY_DC_MW in summary
assert SupplyCurveField.MEAN_CF_AC in summary
assert SupplyCurveField.MEAN_CF_DC in summary

assert not summary[SupplyCurveField.CAPACITY_AC_MW].isna().any()
assert not summary[SupplyCurveField.CAPACITY_DC_MW].isna().any()
assert not summary[SupplyCurveField.MEAN_CF_AC].isna().any()
assert not summary[SupplyCurveField.MEAN_CF_DC].isna().any()

assert np.allclose(summary[SupplyCurveField.CAPACITY_DC_MW] / 1.3,
summary[SupplyCurveField.CAPACITY_AC_MW])
assert np.allclose(summary[SupplyCurveField.CAPACITY_DC_MW]
* summary[SupplyCurveField.MEAN_CF_DC],
summary[SupplyCurveField.CAPACITY_AC_MW]
* summary[SupplyCurveField.MEAN_CF_AC])


def test_multi_file_excl():
Expand Down

0 comments on commit e789492

Please sign in to comment.