diff --git a/reV/SAM/SAM.py b/reV/SAM/SAM.py index 32a447ca2..7149c4669 100644 --- a/reV/SAM/SAM.py +++ b/reV/SAM/SAM.py @@ -927,6 +927,9 @@ def execute(self): def _add_cost_defaults(sam_inputs): """Add default values for required cost outputs if they are missing. """ + if sam_inputs.get("__already_added_cost_defaults"): + return + sam_inputs.setdefault("fixed_charge_rate", None) reg_mult = sam_inputs.setdefault("capital_cost_multiplier", 1) @@ -943,6 +946,8 @@ def _add_cost_defaults(sam_inputs): else: sam_inputs["capital_cost"] = None + sam_inputs["__already_added_cost_defaults"] = True + def _add_sys_capacity(sam_inputs): """Add system capacity SAM input if it is missing. """ diff --git a/reV/version.py b/reV/version.py index 45fa73838..eb66a7b3d 100644 --- a/reV/version.py +++ b/reV/version.py @@ -2,4 +2,4 @@ reV Version number """ -__version__ = "0.9.4" +__version__ = "0.9.5" diff --git a/tests/test_econ_lcoe.py b/tests/test_econ_lcoe.py index 84afdfc87..fe4a3ac45 100644 --- a/tests/test_econ_lcoe.py +++ b/tests/test_econ_lcoe.py @@ -272,7 +272,7 @@ def test_capital_cost_multiplier_regional(clear_loggers): num = (cc * sam_config["fixed_charge_rate"] + sam_config["fixed_operating_cost"]) aep = cf * sam_config["system_capacity"] / 1000 * 8760 - lcoe_truth = num / aep + sam_config["variable_operating_cost"] + lcoe_truth = num / aep + sam_config["variable_operating_cost"] * 1000 assert np.allclose(lcoe, lcoe_truth, rtol=RTOL, atol=ATOL) clear_loggers() diff --git a/tests/test_gen_pv.py b/tests/test_gen_pv.py index e4a0b216f..d989f3718 100644 --- a/tests/test_gen_pv.py +++ b/tests/test_gen_pv.py @@ -9,6 +9,7 @@ """ import os +import json import shutil import tempfile @@ -875,6 +876,56 @@ def test_ac_outputs(): assert np.isclose(gen.out["cf_profile_ac"], 1).any() +def test_pv_regional_mults(): + """Test reV pvwattsv8 regional multiplier outputs""" + + res_file = TESTDATADIR + "/nsrdb/ri_100_nsrdb_2012.h5" + points = pd.DataFrame({"gid": [0, 1, 2], + "capital_cost_multiplier": [0.6, 0.8, 1]}) + + output_request = ("cf_mean", "cf_mean_ac", "cf_profile", "cf_profile_ac", + "system_capacity", "system_capacity_ac", "ac", "dc", + "dc_ac_ratio", "lcoe_fcr") + + with open(TESTDATADIR + "/SAM/i_pvwattsv8.json") as fh: + sam_config = json.load(fh) + + costs = {"capital_cost": 39767200, "fixed_charge_rate": 0.096, + "fixed_operating_cost": 260000, "variable_operating_cost": 10, + "system_capacity": 20_000} + sam_config.update(costs) + sam_files = {"default": sam_config} + + # run reV 2.0 generation + gen = Gen("pvwattsv8", points, sam_files, res_file, sites_per_worker=1, + output_request=output_request) + gen.run(max_workers=1) + + # SAM config unchanged + assert sam_config["capital_cost"] == 39767200 + assert sam_config["fixed_operating_cost"] == 260000 + assert sam_config["variable_operating_cost"] == 10 + + assert np.allclose(gen.out["base_fixed_operating_cost"], 260000) + assert np.allclose(gen.out["fixed_operating_cost"], 260000) + assert np.allclose(gen.out["base_variable_operating_cost"], 10) + assert np.allclose(gen.out["variable_operating_cost"], 10) + + assert np.allclose(gen.out["capital_cost_multiplier"], + points["capital_cost_multiplier"]) + + assert np.allclose(gen.out["base_capital_cost"], 39767200) + cc = sam_config["capital_cost"] * points["capital_cost_multiplier"] + assert np.allclose(gen.out["capital_cost"], cc) + + cost = (cc * sam_config["fixed_charge_rate"] + + sam_config["fixed_operating_cost"]) + aep = gen.out["cf_mean"] * sam_config["system_capacity"] / 1000 * 8760 + lcoe_truth = cost / aep + sam_config["variable_operating_cost"] * 1000 + + assert np.allclose(gen.out["lcoe_fcr"], lcoe_truth) + + @pytest.mark.parametrize( "bad_input", [