Skip to content

Commit

Permalink
Tests for new cost outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
ppinchuk committed Jun 1, 2024
1 parent b41ba7c commit 437a768
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 0 deletions.
49 changes: 49 additions & 0 deletions tests/test_econ_lcoe.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from reV import TESTDATADIR
from reV.cli import main
from reV.econ.econ import Econ
from reV.generation.base import LCOE_REQUIRED_OUTPUTS
from reV.handlers.outputs import Outputs
from reV.utilities import ModuleName

Expand Down Expand Up @@ -60,6 +61,9 @@ def test_lcoe(year, max_workers, spw):

assert result

for output in LCOE_REQUIRED_OUTPUTS:
assert output in obj.out


@pytest.mark.parametrize('year', ('2012', '2013'))
def test_fout(year):
Expand All @@ -80,6 +84,8 @@ def test_fout(year):
econ.run(max_workers=1, out_fpath=fpath)
with Outputs(fpath) as f:
lcoe = f['lcoe_fcr']
for output in LCOE_REQUIRED_OUTPUTS:
assert output in f.datasets

with h5py.File(r1f, mode='r') as f:
year_rows = {'2012': 0, '2013': 1}
Expand Down Expand Up @@ -116,6 +122,8 @@ def test_append_data(year):
lcoe = f['lcoe_fcr']
meta = f.meta
ti = f.time_index
for output in LCOE_REQUIRED_OUTPUTS:
assert output in f.datasets

with Outputs(original_file) as f:
og_dsets = f.dsets
Expand Down Expand Up @@ -163,6 +171,8 @@ def test_append_multi_node(node):
meta = out.meta
data_test = out['lcoe_fcr']
test_cap_cost = out['capital_cost']
for output in LCOE_REQUIRED_OUTPUTS:
assert output in out.datasets

assert np.allclose(data_baseline, data_test)

Expand Down Expand Up @@ -218,6 +228,8 @@ def test_econ_from_config(runner, clear_loggers):
out_fpath = os.path.join(td, fn_out)
with Outputs(out_fpath, 'r') as f:
lcoe = f['lcoe_fcr']
for output in LCOE_REQUIRED_OUTPUTS:
assert output in f.datasets

with h5py.File(r1f, mode='r') as f:
r1_lcoe = f['pv']['lcoefcr'][0, 0:10] * 1000
Expand All @@ -229,6 +241,43 @@ def test_econ_from_config(runner, clear_loggers):
clear_loggers()


def test_multiplier_regional(clear_loggers):
"""Gen PV CF profiles with write to disk and compare against rev1."""
with tempfile.TemporaryDirectory() as dirout:
cf_file = os.path.join(TESTDATADIR,
'gen_out/gen_ri_pv_2012_x000.h5')
sam_files = os.path.join(TESTDATADIR, 'SAM',
'i_lcoe_naris_pv_1axis_inv13.json')
fpath = os.path.join(dirout, 'lcoe_out_econ_2012.h5')
mults = np.arange(0, 100) / 100
points = pd.DataFrame({"gid": np.arange(0, 100),
"multiplier_regional": mults})
econ = Econ(points, sam_files, cf_file,
output_request='lcoe_fcr',
sites_per_worker=25)
econ.run(max_workers=1, out_fpath=fpath)

with Outputs(cf_file) as f:
cf = f['cf_mean']

with Outputs(fpath) as f:
lcoe = f['lcoe_fcr']
for output in LCOE_REQUIRED_OUTPUTS:
assert output in f.datasets

with open(sam_files, "r") as fh:
sam_config = json.load(fh)

cc = sam_config["capital_cost"] * mults
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"]

assert np.allclose(lcoe, lcoe_truth, rtol=RTOL, atol=ATOL)
clear_loggers()


def execute_pytest(capture='all', flags='-rapP'):
"""Execute module as pytest with detailed summary report.
Expand Down
7 changes: 7 additions & 0 deletions tests/test_gen_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from reV import TESTDATADIR
from reV.cli import main
from reV.config.project_points import ProjectPoints
from reV.generation.base import LCOE_REQUIRED_OUTPUTS
from reV.generation.generation import Gen
from reV.handlers.outputs import Outputs
from reV.utilities import SiteDataField
Expand Down Expand Up @@ -107,6 +108,12 @@ def test_gen_from_config(runner, tech, clear_loggers):
monthly = cf['monthly_energy']
assert monthly.shape == (12, 10)

for output in LCOE_REQUIRED_OUTPUTS:
if tech == 'pv':
assert output in cf.datasets
else:
assert output not in cf.datasets

break

if rev2_profiles is None:
Expand Down
27 changes: 27 additions & 0 deletions tests/test_gen_geothermal.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from rex import Outputs

from reV import TESTDATADIR
from reV.generation.base import LCOE_REQUIRED_OUTPUTS
from reV.generation.generation import Gen
from reV.SAM.generation import Geothermal
from reV.utilities import ResourceMetaField
Expand Down Expand Up @@ -115,6 +116,8 @@ def test_gen_geothermal(depth, sample_resource_data):
)
assert np.allclose(truth, test, rtol=RTOL, atol=ATOL), msg

for output in LCOE_REQUIRED_OUTPUTS:
assert output in gen.out

@pytest.mark.parametrize(
"sample_resource_data", [{"temp": 60, "potential": 200}], indirect=True
Expand Down Expand Up @@ -165,6 +168,9 @@ def test_gen_geothermal_temp_too_low(sample_resource_data):
)
assert np.allclose(truth, test, rtol=RTOL, atol=ATOL), msg

for output in LCOE_REQUIRED_OUTPUTS:
assert output in gen.out


@pytest.mark.parametrize(
"sample_resource_data", [{"temp": 150, "potential": 100}], indirect=True
Expand Down Expand Up @@ -211,6 +217,9 @@ def test_per_kw_cost_inputs(sample_resource_data):
)
assert np.allclose(truth, test, rtol=1e-6, atol=ATOL), msg

for output in LCOE_REQUIRED_OUTPUTS:
assert output in gen.out


@pytest.mark.parametrize(
"sample_resource_data", [{"temp": 150, "potential": 100}], indirect=True
Expand Down Expand Up @@ -258,6 +267,9 @@ def test_drill_cost_inputs(sample_resource_data):
)
assert np.allclose(truth, test, rtol=1e-6, atol=ATOL), msg

for output in LCOE_REQUIRED_OUTPUTS:
assert output in gen.out


@pytest.mark.parametrize(
"sample_resource_data", [{"temp": 150, "potential": 20}], indirect=True
Expand Down Expand Up @@ -315,6 +327,9 @@ def test_gen_with_nameplate_input(sample_resource_data):
)
assert np.allclose(truth, test, rtol=RTOL, atol=ATOL), msg

for output in LCOE_REQUIRED_OUTPUTS:
assert output in gen.out


@pytest.mark.parametrize(
"sample_resource_data", [{"temp": 150, "potential": 20}], indirect=True
Expand Down Expand Up @@ -359,6 +374,9 @@ def test_gen_egs_too_high_egs_plant_design_temp(sample_resource_data):
)
assert np.allclose(truth, test, rtol=RTOL, atol=ATOL), msg

for output in LCOE_REQUIRED_OUTPUTS:
assert output not in gen.out


@pytest.mark.parametrize(
"sample_resource_data",
Expand Down Expand Up @@ -406,6 +424,9 @@ def test_gen_egs_too_low_egs_plant_design_temp(sample_resource_data):
)
assert np.allclose(truth, test, rtol=RTOL, atol=ATOL), msg

for output in LCOE_REQUIRED_OUTPUTS:
assert output not in gen.out


@pytest.mark.parametrize(
"sample_resource_data",
Expand Down Expand Up @@ -454,6 +475,9 @@ def test_gen_egs_plant_design_temp_adjusted_from_user(sample_resource_data):
)
assert np.allclose(truth, test, rtol=RTOL, atol=ATOL), msg

for output in LCOE_REQUIRED_OUTPUTS:
assert output not in gen.out


@pytest.mark.parametrize(
"sample_resource_data", [{"temp": 150, "potential": 20}], indirect=True
Expand Down Expand Up @@ -491,6 +515,9 @@ def test_gen_with_time_index_step_input(sample_resource_data):

assert gen.out["cf_profile"].shape[0] == 8760 // 2

for output in LCOE_REQUIRED_OUTPUTS:
assert output in gen.out


def execute_pytest(capture="all", flags="-rapP"):
"""Execute module as pytest with detailed summary report.
Expand Down

0 comments on commit 437a768

Please sign in to comment.