Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix regional cost bug #477

Merged
merged 4 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions reV/SAM/SAM.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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. """
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.4"
__version__ = "0.9.5"
2 changes: 1 addition & 1 deletion tests/test_econ_lcoe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
51 changes: 51 additions & 0 deletions tests/test_gen_pv.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"""

import os
import json
import shutil
import tempfile

Expand Down Expand Up @@ -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",
[
Expand Down
Loading