Skip to content

Commit

Permalink
fixed CI tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kbrunik committed Aug 7, 2024
1 parent 22ebb5f commit 7cddc6a
Show file tree
Hide file tree
Showing 2 changed files with 169 additions and 75 deletions.
74 changes: 48 additions & 26 deletions tests/hopp/test_detailed_pv_plant.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
import pytest
from pytest import fixture

from hopp.simulation.technologies.pv.detailed_pv_plant import DetailedPVConfig, DetailedPVPlant
from hopp.simulation.technologies.financial.custom_financial_model import CustomFinancialModel
from hopp.simulation.technologies.pv.detailed_pv_plant import (
DetailedPVConfig,
DetailedPVPlant,
)
from hopp.simulation.technologies.financial.custom_financial_model import (
CustomFinancialModel,
)
from hopp.simulation.technologies.layout.pv_layout import PVGridParameters
from tests.hopp.utils import create_default_site_info, DEFAULT_FIN_CONFIG

config_data = {
'system_capacity_kw': 100,
'tech_config': {
'subarray2_enable': 0
}
}
config_data = {"system_capacity_kw": 100, "tech_config": {"subarray2_enable": 0}}


@fixture
Expand All @@ -26,7 +26,25 @@ def test_detailed_pv_plant_initialization(site, subtests):
"""Test simple instantiation (no layout params)."""
config = DetailedPVConfig.from_dict(config_data)
pv_plant = DetailedPVPlant(site=site, config=config)
assert pv_plant.site == site
with subtests.test("Site: lat and lon"):
assert pv_plant.site.lat == site.lat
assert pv_plant.site.lon == site.lon
with subtests.test("Site: elev"):
assert pv_plant.site.data["elev"] == site.data["elev"]
with subtests.test("Site: year"):
assert pv_plant.site.data["year"] == site.data["year"]
with subtests.test("Site: tz"):
assert pv_plant.site.data["tz"] == site.data["tz"]
with subtests.test("Site: site boundaries"):
assert (
pv_plant.site.data["site_boundaries"]["verts"]
== site.data["site_boundaries"]["verts"]
)
with subtests.test("Site: site boundaries simple"):
assert (
pv_plant.site.data["site_boundaries"]["verts_simple"]
== site.data["site_boundaries"]["verts_simple"]
)
assert pv_plant._financial_model is not None
assert pv_plant.layout is not None
assert pv_plant.layout.parameters is None
Expand All @@ -36,20 +54,22 @@ def test_detailed_pv_plant_initialization(site, subtests):
def test_single_subarray_limitation(site):
"""Ensure only one subarray is allowed."""
config_with_multiple_subarrays = {
'system_capacity_kw': 100,
'tech_config': {
'subarray2_enable': 1
}
"system_capacity_kw": 100,
"tech_config": {"subarray2_enable": 1},
}
config = DetailedPVConfig.from_dict(config_with_multiple_subarrays)
with pytest.raises(Exception, match=r"Detailed PV plant currently only supports one subarray."):
with pytest.raises(
Exception, match=r"Detailed PV plant currently only supports one subarray."
):
DetailedPVPlant(site=site, config=config)


def test_processed_assign(site, subtests):
"""Test more detailed instantiation with `tech_config`."""
pvsamv1_defaults_file = Path(__file__).absolute().parent / "pvsamv1_basic_params.json"
with open(pvsamv1_defaults_file, 'r') as f:
pvsamv1_defaults_file = (
Path(__file__).absolute().parent / "pvsamv1_basic_params.json"
)
with open(pvsamv1_defaults_file, "r") as f:
tech_config = json.load(f)

with subtests.test("With Pvsamv1 configuration file"):
Expand All @@ -61,27 +81,29 @@ def test_processed_assign(site, subtests):
def test_layout_parameters(site):
"""Ensure layout parameters are set properly if provided."""
config_with_layout_params = {
'system_capacity_kw': 100,
'layout_params': PVGridParameters(
"system_capacity_kw": 100,
"layout_params": PVGridParameters(
x_position=0.5,
y_position=0.5,
aspect_power=0,
gcr=0.5,
s_buffer=2,
x_buffer=2
)
x_buffer=2,
),
}
config = DetailedPVConfig.from_dict(config_with_layout_params)
pv_plant = DetailedPVPlant(site=site, config=config)
assert pv_plant.layout.parameters == config_with_layout_params['layout_params']
assert pv_plant.layout.parameters == config_with_layout_params["layout_params"]


def test_custom_financial(site):
"""Test with a non-default financial model."""
config = DetailedPVConfig.from_dict({
'system_capacity_kw': 100,
'fin_model': CustomFinancialModel(DEFAULT_FIN_CONFIG),
})
config = DetailedPVConfig.from_dict(
{
"system_capacity_kw": 100,
"fin_model": CustomFinancialModel(DEFAULT_FIN_CONFIG),
}
)
pv_plant = DetailedPVPlant(site=site, config=config)
assert pv_plant._financial_model is not None
assert isinstance(pv_plant._financial_model, CustomFinancialModel)
assert isinstance(pv_plant._financial_model, CustomFinancialModel)
170 changes: 121 additions & 49 deletions tests/hopp/test_hybrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def hybrid_config():

return hybrid_config


@fixture
def site():
return create_default_site_info()
Expand Down Expand Up @@ -226,9 +227,25 @@ def test_hybrid_wave_only(hybrid_config, wavesite, subtests):
assert hybrid_plant.wave._financial_model.FinancialParameters == approx(
hybrid_plant.grid._financial_model.FinancialParameters
)
with subtests.test("Revenue"):
assert hybrid_plant.wave._financial_model.Revenue == approx(
hybrid_plant.grid._financial_model.Revenue
with subtests.test("Revenue: ppa price input"):
assert hybrid_plant.wave._financial_model.Revenue.ppa_price_input == approx(
hybrid_plant.grid._financial_model.Revenue.ppa_price_input
)
with subtests.test("Revenue: ppa escalation"):
assert hybrid_plant.wave._financial_model.Revenue.ppa_escalation == approx(
hybrid_plant.grid._financial_model.Revenue.ppa_escalation
)
with subtests.test("Revenue: ppa multiplier model"):
assert (
hybrid_plant.wave._financial_model.Revenue.ppa_multiplier_model
== approx(hybrid_plant.grid._financial_model.Revenue.ppa_multiplier_model)
)
with subtests.test("Revenue: ppa price input"):
assert (
hybrid_plant.wave._financial_model.Revenue.dispatch_factors_ts.all()
== approx(
hybrid_plant.grid._financial_model.Revenue.dispatch_factors_ts.all()
)
)
with subtests.test("SystemCosts"):
assert hybrid_plant.wave._financial_model.SystemCosts == approx(
Expand Down Expand Up @@ -411,30 +428,57 @@ def test_hybrid_pv_only(hybrid_config):
assert npvs.pv == approx(-5121293, 1e3)
assert npvs.hybrid == approx(-5121293, 1e3)


def test_hybrid_pv_only_custom_fin(hybrid_config, subtests):
solar_only = {
'pv': {
'system_capacity_kw': 5000,
'layout_params': {
'x_position': 0.5,
'y_position': 0.5,
'aspect_power': 0,
'gcr': 0.5,
's_buffer': 2,
'x_buffer': 2,
},
'dc_degradation': [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
'fin_model': DEFAULT_FIN_CONFIG
"pv": {
"system_capacity_kw": 5000,
"layout_params": {
"x_position": 0.5,
"y_position": 0.5,
"aspect_power": 0,
"gcr": 0.5,
"s_buffer": 2,
"x_buffer": 2,
},
"dc_degradation": [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
],
"fin_model": DEFAULT_FIN_CONFIG,
},
"grid": {
"interconnect_kw": interconnection_size_kw,
"fin_model": DEFAULT_FIN_CONFIG,
},
'grid':{
'interconnect_kw': interconnection_size_kw,
'fin_model': DEFAULT_FIN_CONFIG,
}
}
hybrid_config["technologies"] = solar_only
hybrid_config["config"] = {
"cost_info": {
'solar_installed_cost_mw': 400 * 1000,
"solar_installed_cost_mw": 400 * 1000,
}
}
hi = HoppInterface(hybrid_config)
Expand All @@ -449,57 +493,84 @@ def test_hybrid_pv_only_custom_fin(hybrid_config, subtests):
cf = hybrid_plant.capacity_factors

with subtests.test("total installed cost"):
assert hybrid_plant.pv.total_installed_cost == approx(2000000,1e-3)
assert hybrid_plant.pv.total_installed_cost == approx(2000000, 1e-3)

with subtests.test("om cost"):
assert hybrid_plant.pv.om_capacity == (20,)

with subtests.test("capacity factor"):
assert cf.hybrid == approx(cf.pv)

with subtests.test("aep"):
assert aeps.pv == approx(9884106.55, 1e-3)
assert aeps.hybrid == aeps.pv


def test_hybrid_pv_battery_custom_fin(hybrid_config, subtests):
tech = {
'pv': {
'system_capacity_kw': 5000,
'layout_params': {
'x_position': 0.5,
'y_position': 0.5,
'aspect_power': 0,
'gcr': 0.5,
's_buffer': 2,
'x_buffer': 2,
},
'dc_degradation': [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
'fin_model': DEFAULT_FIN_CONFIG
"pv": {
"system_capacity_kw": 5000,
"layout_params": {
"x_position": 0.5,
"y_position": 0.5,
"aspect_power": 0,
"gcr": 0.5,
"s_buffer": 2,
"x_buffer": 2,
},
"dc_degradation": [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
],
"fin_model": DEFAULT_FIN_CONFIG,
},
"battery": {
"system_capacity_kw": 5000,
"system_capacity_kwh": 20000,
"fin_model": DEFAULT_FIN_CONFIG,
},
"grid": {
"interconnect_kw": interconnection_size_kw,
"fin_model": DEFAULT_FIN_CONFIG,
},
'battery': {
'system_capacity_kw': 5000,
'system_capacity_kwh': 20000,
'fin_model': DEFAULT_FIN_CONFIG
},
'grid':{
'interconnect_kw': interconnection_size_kw,
'fin_model': DEFAULT_FIN_CONFIG,
}
}
hybrid_config["technologies"] = tech
hybrid_config["config"] = {
"cost_info": {
'solar_installed_cost_mw': 400 * 1000,
'storage_installed_cost_mw': 200 * 1000,
'storage_installed_cost_mwh': 300 * 1000
"solar_installed_cost_mw": 400 * 1000,
"storage_installed_cost_mw": 200 * 1000,
"storage_installed_cost_mwh": 300 * 1000,
}
}
hi = HoppInterface(hybrid_config)

hybrid_plant = hi.system
# hybrid_plant.pv.set_overnight_capital_cost(400)
# hybrid_plant.battery.set_overnight_capital_cost(300,200)
hybrid_plant.set_om_costs_per_kw(pv_om_per_kw=20,battery_om_per_kw=30)
hybrid_plant.set_om_costs_per_kw(pv_om_per_kw=20, battery_om_per_kw=30)

hi.simulate()

Expand All @@ -508,17 +579,18 @@ def test_hybrid_pv_battery_custom_fin(hybrid_config, subtests):
cf = hybrid_plant.capacity_factors

with subtests.test("pv total installed cost"):
assert hybrid_plant.pv.total_installed_cost == approx(2000000,1e-3)
assert hybrid_plant.pv.total_installed_cost == approx(2000000, 1e-3)

with subtests.test("pv om cost"):
assert hybrid_plant.pv.om_capacity == (20,)

with subtests.test("battery total installed cost"):
assert hybrid_plant.battery.total_installed_cost == approx(7000000,1e-3)
assert hybrid_plant.battery.total_installed_cost == approx(7000000, 1e-3)

with subtests.test("battery om cost"):
assert hybrid_plant.battery.om_capacity == (30,)


def test_detailed_pv_system_capacity(hybrid_config, subtests):
with subtests.test(
"Detailed PV model (pvsamv1) using defaults except the top level system_capacity_kw parameter"
Expand Down

0 comments on commit 7cddc6a

Please sign in to comment.