Skip to content

Commit

Permalink
Update tests for BOS
Browse files Browse the repository at this point in the history
  • Loading branch information
ppinchuk committed May 30, 2024
1 parent 09a736b commit 7d70257
Showing 1 changed file with 40 additions and 23 deletions.
63 changes: 40 additions & 23 deletions tests/test_bespoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from reV import TESTDATADIR
from reV.cli import main
from reV.bespoke.bespoke import BespokeSinglePlant, BespokeWindPlants
from reV.bespoke.place_turbines import PlaceTurbines
from reV.bespoke.place_turbines import PlaceTurbines, _compute_nn_conn_dist
from reV.handlers.outputs import Outputs
from reV.supply_curve.tech_mapping import TechMapping
from reV.supply_curve.supply_curve import SupplyCurve
Expand Down Expand Up @@ -69,6 +69,7 @@
FOC_FUN = ('60 * system_capacity '
'* np.exp(-system_capacity / 1E5 * 0.1 + (1 - 0.1))')
VOC_FUN = '3'
BOS_FUN = '0'
OBJECTIVE_FUNCTION = ('(0.0975 * capital_cost + fixed_operating_cost) '
'/ aep + variable_operating_cost')

Expand All @@ -95,6 +96,7 @@ def test_turbine_placement(gid=33):
CAP_COST_FUN,
FOC_FUN,
VOC_FUN,
'10 * nn_conn_dist_m',
excl_dict=EXCL_DICT,
output_request=output_request,
)
Expand All @@ -109,6 +111,7 @@ def test_turbine_placement(gid=33):
assert place_optimizer.capital_cost is None
assert place_optimizer.fixed_operating_cost is None
assert place_optimizer.variable_operating_cost is None
assert place_optimizer.balance_of_system_cost is None
assert place_optimizer.objective is None
place_optimizer.place_turbines(max_time=5)

Expand Down Expand Up @@ -139,13 +142,17 @@ def test_turbine_placement(gid=33):
capital_cost = eval(CAP_COST_FUN, globals(), locals())
fixed_operating_cost = eval(FOC_FUN, globals(), locals()) * 2
variable_operating_cost = eval(VOC_FUN, globals(), locals()) * 5
balance_of_system_cost = 10 * _compute_nn_conn_dist(
place_optimizer.turbine_x, place_optimizer.turbine_y
)
# pylint: disable=W0123
assert place_optimizer.objective ==\
eval(OBJECTIVE_FUNCTION, globals(), locals())
assert place_optimizer.capital_cost == capital_cost
assert place_optimizer.fixed_operating_cost == fixed_operating_cost
assert (place_optimizer.variable_operating_cost
== variable_operating_cost)
assert place_optimizer.balance_of_system_cost == balance_of_system_cost

bsp.close()

Expand All @@ -170,7 +177,7 @@ def test_zero_area(gid=33):
bsp = BespokeSinglePlant(gid, excl_fp, res_fp, TM_DSET,
SAM_SYS_INPUTS,
objective_function, CAP_COST_FUN,
FOC_FUN, VOC_FUN,
FOC_FUN, VOC_FUN, BOS_FUN,
excl_dict=EXCL_DICT,
output_request=output_request,
)
Expand Down Expand Up @@ -213,7 +220,7 @@ def test_correct_turb_location(gid=33):
bsp = BespokeSinglePlant(gid, excl_fp, res_fp, TM_DSET,
SAM_SYS_INPUTS,
objective_function, CAP_COST_FUN,
FOC_FUN, VOC_FUN,
FOC_FUN, VOC_FUN, BOS_FUN,
excl_dict=EXCL_DICT,
output_request=output_request,
)
Expand All @@ -224,6 +231,7 @@ def test_correct_turb_location(gid=33):
bsp.capital_cost_function,
bsp.fixed_operating_cost_function,
bsp.variable_operating_cost_function,
bsp.balance_of_system_cost_function,
include_mask, pixel_side_length=90,
min_spacing=45)

Expand Down Expand Up @@ -306,7 +314,7 @@ def test_single(gid=33):
bsp = BespokeSinglePlant(gid, excl_fp, res_fp, TM_DSET,
SAM_SYS_INPUTS,
OBJECTIVE_FUNCTION, CAP_COST_FUN,
FOC_FUN, VOC_FUN,
FOC_FUN, VOC_FUN, BOS_FUN,
ga_kwargs={'max_time': 5},
excl_dict=EXCL_DICT,
output_request=output_request,
Expand Down Expand Up @@ -389,7 +397,7 @@ def test_extra_outputs(gid=33):
bsp = BespokeSinglePlant(gid, excl_fp, res_fp, TM_DSET,
SAM_SYS_INPUTS,
objective_function, CAP_COST_FUN,
FOC_FUN, VOC_FUN,
FOC_FUN, VOC_FUN, BOS_FUN,
ga_kwargs={'max_time': 5},
excl_dict=EXCL_DICT,
output_request=output_request,
Expand All @@ -401,7 +409,7 @@ def test_extra_outputs(gid=33):
bsp = BespokeSinglePlant(gid, excl_fp, res_fp, TM_DSET,
sam_sys_inputs,
objective_function, CAP_COST_FUN,
FOC_FUN, VOC_FUN,
FOC_FUN, VOC_FUN, BOS_FUN,
ga_kwargs={'max_time': 5},
excl_dict=EXCL_DICT,
output_request=output_request,
Expand Down Expand Up @@ -436,7 +444,7 @@ def test_extra_outputs(gid=33):
bsp = BespokeSinglePlant(gid, excl_fp, res_fp, TM_DSET,
sam_sys_inputs,
objective_function, CAP_COST_FUN,
FOC_FUN, VOC_FUN,
FOC_FUN, VOC_FUN, BOS_FUN,
ga_kwargs={'max_time': 5},
excl_dict=EXCL_DICT,
output_request=output_request,
Expand Down Expand Up @@ -505,7 +513,8 @@ def test_bespoke():
assert not os.path.exists(out_fpath_truth)
bsp = BespokeWindPlants(excl_fp, res_fp, TM_DSET,
OBJECTIVE_FUNCTION, CAP_COST_FUN,
FOC_FUN, VOC_FUN, fully_excluded_points,
FOC_FUN, VOC_FUN, BOS_FUN,
fully_excluded_points,
SAM_CONFIGS, ga_kwargs={'max_time': 5},
excl_dict=EXCL_DICT,
output_request=output_request)
Expand All @@ -515,8 +524,8 @@ def test_bespoke():

assert not os.path.exists(out_fpath_truth)
bsp = BespokeWindPlants(excl_fp, res_fp, TM_DSET, OBJECTIVE_FUNCTION,
CAP_COST_FUN, FOC_FUN, VOC_FUN, points,
SAM_CONFIGS, ga_kwargs={'max_time': 5},
CAP_COST_FUN, FOC_FUN, VOC_FUN, BOS_FUN,
points, SAM_CONFIGS, ga_kwargs={'max_time': 5},
excl_dict=EXCL_DICT,
output_request=output_request)
test_fpath = bsp.run(max_workers=2, out_fpath=out_fpath_request)
Expand Down Expand Up @@ -554,8 +563,8 @@ def test_bespoke():

out_fpath_pre = os.path.join(td, 'bespoke_out_pre.h5')
bsp = BespokeWindPlants(excl_fp, res_fp, TM_DSET, OBJECTIVE_FUNCTION,
CAP_COST_FUN, FOC_FUN, VOC_FUN, points,
SAM_CONFIGS, ga_kwargs={'max_time': 1},
CAP_COST_FUN, FOC_FUN, VOC_FUN, BOS_FUN,
points, SAM_CONFIGS, ga_kwargs={'max_time': 1},
excl_dict=EXCL_DICT,
output_request=output_request,
pre_load_data=True)
Expand Down Expand Up @@ -695,6 +704,7 @@ def test_wake_loss_multiplier(wlm):
CAP_COST_FUN,
FOC_FUN,
VOC_FUN,
BOS_FUN,
excl_dict=EXCL_DICT,
output_request=output_request,
)
Expand All @@ -721,6 +731,7 @@ def test_wake_loss_multiplier(wlm):
CAP_COST_FUN,
FOC_FUN,
VOC_FUN,
BOS_FUN,
excl_dict=EXCL_DICT,
output_request=output_request,
wake_loss_multiplier=wlm)
Expand Down Expand Up @@ -760,6 +771,7 @@ def test_bespoke_wind_plant_with_power_curve_losses():
CAP_COST_FUN,
FOC_FUN,
VOC_FUN,
BOS_FUN,
excl_dict=EXCL_DICT,
output_request=output_request,
)
Expand All @@ -786,6 +798,7 @@ def test_bespoke_wind_plant_with_power_curve_losses():
CAP_COST_FUN,
FOC_FUN,
VOC_FUN,
BOS_FUN,
excl_dict=EXCL_DICT,
output_request=output_request)

Expand Down Expand Up @@ -821,7 +834,7 @@ def test_bespoke_run_with_power_curve_losses():
bsp = BespokeSinglePlant(33, excl_fp, res_fp, TM_DSET,
SAM_SYS_INPUTS,
OBJECTIVE_FUNCTION, CAP_COST_FUN,
FOC_FUN, VOC_FUN,
FOC_FUN, VOC_FUN, BOS_FUN,
ga_kwargs={'max_time': 5},
excl_dict=EXCL_DICT,
output_request=output_request)
Expand All @@ -841,6 +854,7 @@ def test_bespoke_run_with_power_curve_losses():
CAP_COST_FUN,
FOC_FUN,
VOC_FUN,
BOS_FUN,
ga_kwargs={'max_time': 5},
excl_dict=EXCL_DICT,
output_request=output_request)
Expand Down Expand Up @@ -872,7 +886,7 @@ def test_bespoke_run_with_scheduled_losses():
bsp = BespokeSinglePlant(33, excl_fp, res_fp, TM_DSET,
SAM_SYS_INPUTS,
OBJECTIVE_FUNCTION, CAP_COST_FUN,
FOC_FUN, VOC_FUN,
FOC_FUN, VOC_FUN, BOS_FUN,
ga_kwargs={'max_time': 5},
excl_dict=EXCL_DICT,
output_request=output_request)
Expand All @@ -898,6 +912,7 @@ def test_bespoke_run_with_scheduled_losses():
CAP_COST_FUN,
FOC_FUN,
VOC_FUN,
BOS_FUN,
ga_kwargs={'max_time': 5},
excl_dict=EXCL_DICT,
output_request=output_request)
Expand Down Expand Up @@ -938,6 +953,7 @@ def test_bespoke_aep_is_zero_if_no_turbines_placed():
CAP_COST_FUN,
FOC_FUN,
VOC_FUN,
BOS_FUN,
excl_dict=EXCL_DICT,
output_request=output_request,
)
Expand Down Expand Up @@ -997,7 +1013,7 @@ def test_bespoke_prior_run():

bsp = BespokeWindPlants(excl_fp, res_fp_all, TM_DSET,
OBJECTIVE_FUNCTION, CAP_COST_FUN,
FOC_FUN, VOC_FUN, points, sam_configs,
FOC_FUN, VOC_FUN, BOS_FUN, points, sam_configs,
ga_kwargs={'max_time': 1}, excl_dict=EXCL_DICT,
output_request=output_request)
bsp.run(max_workers=1, out_fpath=out_fpath1)
Expand All @@ -1007,7 +1023,7 @@ def test_bespoke_prior_run():

bsp = BespokeWindPlants(excl_fp, res_fp_2013, TM_DSET,
OBJECTIVE_FUNCTION, CAP_COST_FUN,
FOC_FUN, VOC_FUN, points, sam_configs,
FOC_FUN, VOC_FUN, BOS_FUN, points, sam_configs,
ga_kwargs={'max_time': 1}, excl_dict=EXCL_DICT,
output_request=output_request,
prior_run=out_fpath1)
Expand Down Expand Up @@ -1071,7 +1087,7 @@ def test_gid_map():

bsp = BespokeWindPlants(excl_fp, res_fp_2013, TM_DSET,
OBJECTIVE_FUNCTION, CAP_COST_FUN,
FOC_FUN, VOC_FUN, points, SAM_CONFIGS,
FOC_FUN, VOC_FUN, BOS_FUN, points, SAM_CONFIGS,
ga_kwargs={'max_time': 1}, excl_dict=EXCL_DICT,
output_request=output_request)
bsp.run(max_workers=1, out_fpath=out_fpath1)
Expand All @@ -1081,7 +1097,7 @@ def test_gid_map():

bsp = BespokeWindPlants(excl_fp, res_fp_2013, TM_DSET,
OBJECTIVE_FUNCTION, CAP_COST_FUN,
FOC_FUN, VOC_FUN, points, SAM_CONFIGS,
FOC_FUN, VOC_FUN, BOS_FUN, points, SAM_CONFIGS,
ga_kwargs={'max_time': 1}, excl_dict=EXCL_DICT,
output_request=output_request,
gid_map=fp_gid_map)
Expand Down Expand Up @@ -1110,7 +1126,7 @@ def test_gid_map():
out_fpath_pre = os.path.join(td, 'bespoke_out_pre.h5')
bsp = BespokeWindPlants(excl_fp, res_fp_2013, TM_DSET,
OBJECTIVE_FUNCTION, CAP_COST_FUN,
FOC_FUN, VOC_FUN, points, SAM_CONFIGS,
FOC_FUN, VOC_FUN, BOS_FUN, points, SAM_CONFIGS,
ga_kwargs={'max_time': 1}, excl_dict=EXCL_DICT,
output_request=output_request,
gid_map=fp_gid_map, pre_load_data=True)
Expand Down Expand Up @@ -1155,7 +1171,7 @@ def test_bespoke_bias_correct():

bsp = BespokeWindPlants(excl_fp, res_fp_2013, TM_DSET,
OBJECTIVE_FUNCTION, CAP_COST_FUN,
FOC_FUN, VOC_FUN, points, SAM_CONFIGS,
FOC_FUN, VOC_FUN, BOS_FUN, points, SAM_CONFIGS,
ga_kwargs={'max_time': 1}, excl_dict=EXCL_DICT,
output_request=output_request)
bsp.run(max_workers=1, out_fpath=out_fpath1)
Expand All @@ -1165,7 +1181,7 @@ def test_bespoke_bias_correct():

bsp = BespokeWindPlants(excl_fp, res_fp_2013, TM_DSET,
OBJECTIVE_FUNCTION, CAP_COST_FUN,
FOC_FUN, VOC_FUN, points, SAM_CONFIGS,
FOC_FUN, VOC_FUN, BOS_FUN, points, SAM_CONFIGS,
ga_kwargs={'max_time': 1}, excl_dict=EXCL_DICT,
output_request=output_request,
bias_correct=fp_bc)
Expand Down Expand Up @@ -1220,6 +1236,7 @@ def test_cli(runner, clear_loggers):
"capital_cost_function": CAP_COST_FUN,
"fixed_operating_cost_function": FOC_FUN,
"variable_operating_cost_function": VOC_FUN,
"balance_of_system_cost_function": "0",
"project_points": [33, 35],
"sam_files": SAM_CONFIGS,
"min_spacing": '5x',
Expand Down Expand Up @@ -1310,8 +1327,8 @@ def test_bespoke_5min_sample():
excl_file.create_dataset(name=tm_dset, data=arr)

bsp = BespokeWindPlants(excl_fp, res_fp, tm_dset, OBJECTIVE_FUNCTION,
CAP_COST_FUN, FOC_FUN, VOC_FUN, points,
sam_configs, ga_kwargs={'max_time': 5},
CAP_COST_FUN, FOC_FUN, VOC_FUN, BOS_FUN,
points, sam_configs, ga_kwargs={'max_time': 5},
excl_dict=EXCL_DICT,
output_request=output_request)
_ = bsp.run(max_workers=1, out_fpath=out_fpath)
Expand Down

0 comments on commit 7d70257

Please sign in to comment.