Skip to content

Commit 7ad9fe2

Browse files
Clean up unit conversion
1 parent 0da0340 commit 7ad9fe2

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

src/geophires_x/EconomicsSam.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ def _get_single_owner_parameters(model: Model) -> dict[str, Any]:
413413
ret['ppa_price_input'] = ppa_price_schedule_per_kWh
414414

415415
if model.economics.royalty_rate.Provided:
416-
ret['om_production'] = _get_royalties_variable_om_per_MWh_schedule(model)
416+
ret['om_production'] = _get_royalties_variable_om_USD_per_MWh_schedule(model)
417417

418418
# Debt/equity ratio ('Fraction of Investment in Bonds' parameter)
419419
ret['debt_percent'] = _pct(econ.FIB)
@@ -436,22 +436,21 @@ def _get_single_owner_parameters(model: Model) -> dict[str, Any]:
436436
return ret
437437

438438

439-
def _get_royalties_variable_om_per_MWh_schedule(model: Model):
440-
"""TODO price unit in method name"""
441-
439+
def _get_royalties_variable_om_USD_per_MWh_schedule(model: Model):
442440
royalty_rate_schedule = _get_royalty_rate_schedule(model)
443441
ppa_price_schedule_per_kWh = _get_ppa_price_schedule_per_kWh(model)
444442

445443
# For each year, calculate the royalty as a $/MWh variable cost.
446444
# The royalty is a percentage of revenue (MWh * $/MWh). By setting the
447445
# variable O&M rate to (PPA Price * Royalty Rate), SAM's calculation
448446
# (Rate * MWh) will correctly yield the total royalty payment.
449-
variable_om_schedule_per_MWh = [
450-
(price_kWh * 1000) * royalty_fraction # TODO use pint unit conversion instead
447+
variable_om_schedule_USD_per_MWh = [
448+
quantity(price_kWh, model.economics.ElecStartPrice.CurrentUnits).to('USD / megawatt_hour').magnitude
449+
* royalty_fraction
451450
for price_kWh, royalty_fraction in zip(ppa_price_schedule_per_kWh, royalty_rate_schedule)
452451
]
453452

454-
return variable_om_schedule_per_MWh
453+
return variable_om_schedule_USD_per_MWh
455454

456455

457456
def _get_fed_and_state_tax_rates(geophires_ctr_tenths: float) -> tuple[list[float]]:
@@ -471,18 +470,22 @@ def _pct(econ_value: Parameter) -> float:
471470
return econ_value.quantity().to(convertible_unit('%')).magnitude
472471

473472

474-
def _get_ppa_price_schedule_per_kWh(model: Model) -> list[float]:
475-
"""TODO price unit in method name"""
473+
def _get_ppa_price_schedule_per_kWh(model: Model) -> list:
474+
"""
475+
:return: quantity list of PPA price schedule per kWh in econ.ElecStartPrice.CurrentUnits
476+
"""
476477

477478
econ = model.economics
478-
return _ppa_pricing_model(
479+
pricing_model = _ppa_pricing_model(
479480
model.surfaceplant.plant_lifetime.value,
480481
econ.ElecStartPrice.value,
481482
econ.ElecEndPrice.value,
482483
econ.ElecEscalationStart.value,
483484
econ.ElecEscalationRate.value,
484485
)
485486

487+
return [quantity(it, econ.ElecStartPrice.CurrentUnits).magnitude for it in pricing_model]
488+
486489

487490
def _ppa_pricing_model(
488491
plant_lifetime: int, start_price: float, end_price: float, escalation_start_year: int, escalation_rate: float

tests/geophires_x_tests/test_economics_sam.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -654,9 +654,7 @@ def get_row(name: str):
654654

655655
ppa_revenue_row_USD = get_row('PPA revenue ($)')
656656
expected_royalties_USD = [x * royalty_rate for x in ppa_revenue_row_USD]
657-
expected_royalties_MUSD = [x * 1e-6 for x in expected_royalties_USD]
658-
659-
self.assertListEqual(expected_royalties_MUSD, sam_econ.royalties_opex.value)
657+
self.assertListAlmostEqual(expected_royalties_USD, sam_econ.royalties_opex.value, places=0)
660658

661659
om_prod_based_expense_row = get_row('O&M production-based expense ($)')
662660
self.assertListAlmostEqual(expected_royalties_USD, om_prod_based_expense_row, places=0)

0 commit comments

Comments
 (0)