File tree 2 files changed +24
-4
lines changed
2 files changed +24
-4
lines changed Original file line number Diff line number Diff line change @@ -674,10 +674,15 @@ def _score_integer() -> xr.DataArray:
674
674
675
675
def _score_relative_deployment () -> xr .DataArray :
676
676
"""Relative deployment scoring algorithm."""
677
- previous_cap = latest_results ["flow_cap" ].where (spores_techs )
678
- relative_cap = previous_cap / self .inputs ["flow_cap_max" ].where (
679
- spores_techs
680
- )
677
+ previous_cap = latest_results ["flow_cap" ]
678
+ if (
679
+ "flow_cap_max" not in self .inputs
680
+ or (self .inputs ["flow_cap_max" ].where (spores_techs ) == np .inf ).any ()
681
+ ):
682
+ raise exceptions .BackendError (
683
+ "Cannot score SPORES with `relative_deployment` when `flow_cap_max` is undefined for some or all tracked technologies."
684
+ )
685
+ relative_cap = previous_cap / self .inputs ["flow_cap_max" ]
681
686
682
687
new_score = (
683
688
# Make sure that penalties are applied only to non-negligible relative capacities
Original file line number Diff line number Diff line change 1
1
import logging
2
2
from contextlib import contextmanager
3
3
4
+ import numpy as np
4
5
import numpy .testing
5
6
import pandas as pd
6
7
import pytest
@@ -376,6 +377,20 @@ def test_save_per_spore_skip_cost_op(
376
377
model_baseline_solved_separately ._model_data .flow_cap
377
378
)
378
379
380
+ def test_spores_relative_deployment_needs_max_param (self ):
381
+ """Can only run the `relative_deployment` algorithm if all techs have flow_cap_max."""
382
+ model = build_model (
383
+ {"techs.test_supply_elec.flow_cap_max" : np .inf },
384
+ "spores,spores_tech_tracking,investment_costs" ,
385
+ )
386
+ model .build (mode = "spores" )
387
+
388
+ with pytest .raises (
389
+ calliope .exceptions .BackendError ,
390
+ match = "Cannot score SPORES with `relative_deployment`" ,
391
+ ):
392
+ model .solve (** {"spores.scoring_algorithm" : "relative_deployment" })
393
+
379
394
380
395
class TestBuild :
381
396
@pytest .fixture
You can’t perform that action at this time.
0 commit comments