Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New feature region grouping v2 #156

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 32 additions & 4 deletions examples/CAISO-ERCOT-IC/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ regions:
- id: US-TX
long_name: Texas
description: "The US state of Texas"

- id: ATLANTIC-MARKET
long_name: atlantic market
description: a node representing atlantic import markets
Expand All @@ -41,6 +41,33 @@ regions:
long_name: pacific market
description: a node representing pacific import markets

regionsgroup:
- id: CA-TX
long_name: California-Texas group
description: combined CAL-TX region group
include_in_region_group:
"US-TX":
"*": True
"US-CA":
"*": True
"PACIFIC-MARKET":
"*": False
"ATLANTIC-MARKET":
"*": False

- id: PA-AT
long_name: Texas-Atlantic group
description: Texas-Atlantic group
include_in_region_group:
"PACIFIC-MARKET":
"*": True
"ATLANTIC-MARKET":
"*": True
"US-TX":
"*": False
"US-CA":
"*": False

# TRADE ROUTES
trade:
- id: "ELEC trade"
Expand Down Expand Up @@ -98,9 +125,10 @@ impacts:
long_name: equivalent carbon dioxide emissions
description: equivalent carbon dioxide emissions
penalty: # mn$/mntonne
US-CA: 20.
US-TX: 10.
constraint_annual: "{y:225*((2041-y)/(2041-2022)) for y in ${time_definition.years}}"
US-CA: 0.
US-TX: 0.
constraint_annual_region_group:
CA-TX: "{y:225*((2041-y)/(2041-2022)) for y in ${time_definition.years}}"

# RENEWABLE TARGETS
renewable_production_target:
Expand Down
52 changes: 52 additions & 0 deletions examples/CAISO-ERCOT-IC/technologies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,58 @@ technologies:
# additional_capacity_min_growth_rate: 0.


# constraints - activity
activity_annual_max: null
activity_annual_min: null
activity_total_max: null
activity_total_min: null

- id: coal
long_name: coal gen
description: coal gen
capacity_activity_unit_ratio: 31.536
capacity_one_tech_unit: null
availability_factor: 1.
capacity_factor: 1.
operating_life: 25
include_in_joint_reserve_margin: true
include_in_joint_renewable_target: true
# Not Implemented
# include_regions: null
# exclude_regions:
# - ATLANTIC-MARKET
# - PACIFIC-MARKET
capex:
"*": "{y:100 - 100*(max(${time_definition.years})-y)/(max(${time_definition.years}) - min(${time_definition.years})) for y in ${time_definition.years}}"
opex_fixed: 5
operating_modes:
- id: GEN
long_name: generation mode
description: default generation mode
emission_activity_ratio: {"CO2": 0.1}
input_activity_ratio: null
output_activity_ratio:
"*": # all regions
ELEC:
"*": # all years
1.
to_storage: null
from_storage: null
opex_variable: 0.
residual_capacity: 166.3

# CAPACITY
capacity_gross_max: 500.
capacity_gross_min: 0.
capacity_additional_min: 0.

# To be implemented
# additional_capacity_max_ceil: null
# additional_capacity_max_floor: 5
# additional_capacity_max_growth_rate: 0.1
# additional_capacity_min_growth_rate: 0.


# constraints - activity
activity_annual_max: null
activity_annual_min: null
Expand Down
3 changes: 3 additions & 0 deletions tests/test_solve/test_solve.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ def test_model_construction_from_yaml():

model._m.solve(solver_name="highs")

breakpoint()
assert model._m.termination_condition == "optimal"
assert np.round(model._m.objective.value) == 29044.0

test_model_construction_from_yaml()

def test_model_solve_from_otoole_csv():
"""
Expand Down Expand Up @@ -61,6 +63,7 @@ def test_most_simple():

model._m.solve(solver_name="highs")

breakpoint()
assert model._m.termination_condition == "optimal"
assert np.round(model._m.objective.value) == 45736.0

Expand Down
2 changes: 1 addition & 1 deletion tests/test_solve/test_to_xr_ds.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from tz.osemosys.io.load_model import load_model

EXAMPLE_YAML = "examples/utopia/main.yaml"
EXAMPLE_YAML = "/home/dwelsby/repos/tz-osemosys/examples/utopia"


def test_to_xr_ds():
Expand Down
3 changes: 2 additions & 1 deletion tz/osemosys/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from tz.osemosys.model.model import Model
from tz.osemosys.schemas.commodity import Commodity
from tz.osemosys.schemas.impact import Impact
from tz.osemosys.schemas.region import Region
from tz.osemosys.schemas.region import Region, RegionGroup
from tz.osemosys.schemas.storage import Storage
from tz.osemosys.schemas.technology import OperatingMode, Technology
from tz.osemosys.schemas.time_definition import TimeDefinition
Expand All @@ -22,6 +22,7 @@
"Storage",
"Impact",
"Region",
"RegionGroup",
"TimeDefinition",
"OperatingMode",
"load_model",
Expand Down
2 changes: 2 additions & 0 deletions tz/osemosys/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class Defaults(BaseSettings):
trade_capex: float = Field(0.00001)
trade_operating_life: int = Field(1)
trade_capacity_activity_unit_ratio: float = Field(1.0)
include_in_region_group: bool = Field(False)


class DefaultsLinopy(BaseSettings):
Expand All @@ -44,6 +45,7 @@ class DefaultsLinopy(BaseSettings):
"ResidualCapacity": 0,
"SpecifiedAnnualDemand": 0,
"TradeRoute": False,
"RegionGroupTagRegion": False,
}
)

Expand Down
7 changes: 7 additions & 0 deletions tz/osemosys/model/constraints/emissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,11 @@ def add_emissions_constraints(ds: xr.Dataset, m: Model, lex: Dict[str, LinearExp
mask = (ds["ModelPeriodEmissionLimit"] != -1) & (ds["ModelPeriodEmissionLimit"].notnull())
m.add_constraints(con, name="E9_ModelPeriodEmissionsLimit", mask=mask)

con = lex["AnnualEmissionsRegionGroup"].fillna(0) <= ds["AnnualEmissionLimitRegionGroup"] - ds[
"AnnualExogenousEmissionRegionGroup"
].fillna(0)
mask = (ds["AnnualEmissionLimitRegionGroup"] != -1) & (ds["AnnualEmissionLimitRegionGroup"].notnull())

m.add_constraints(con, name="E10_AnnualEmmissionsLimitRegionGroup", mask=mask)

return m
20 changes: 20 additions & 0 deletions tz/osemosys/model/linear_expressions/emissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,24 @@ def add_lex_emissions(ds: xr.Dataset, m: Model, lex: Dict[str, LinearExpression]
.where(ds["EmissionActivityRatio"].notnull(), drop=False)
)

AnnualTechnologyEmissionByModeRegionGroup = (
(ds["EmissionActivityRatio"] * ds["YearSplit"] * m["RateOfActivity"])
.sum("TIMESLICE")
).where(
ds["EmissionActivityRatio"].notnull()
& (ds["RegionGroupTagRegion"] == 1),
drop=False,
)

AnnualTechnologyEmission = AnnualTechnologyEmissionByMode.sum(dims="MODE_OF_OPERATION").where(
ds["EmissionActivityRatio"].sum("MODE_OF_OPERATION") != 0, drop=False
)

AnnualTechnologyEmissionRegionGroup = AnnualTechnologyEmissionByModeRegionGroup.sum(
dims="MODE_OF_OPERATION").where(
ds["EmissionActivityRatio"].sum("MODE_OF_OPERATION") != 0, drop=False
)

AnnualTechnologyEmissionPenaltyByEmission = (
AnnualTechnologyEmission * ds["EmissionsPenalty"]
).where(
Expand All @@ -28,6 +42,8 @@ def add_lex_emissions(ds: xr.Dataset, m: Model, lex: Dict[str, LinearExpression]
)

AnnualEmissions = AnnualTechnologyEmission.sum(dims="TECHNOLOGY")
AnnualEmissionsRegionGroupTag = AnnualTechnologyEmissionRegionGroup.sum(dims="TECHNOLOGY")
AnnualEmissionsRegionGroup = AnnualEmissionsRegionGroupTag.sum(dims="REGION")

ModelPeriodEmissions = AnnualEmissions.sum(dims="YEAR") + ds[
"ModelPeriodExogenousEmission"
Expand All @@ -36,10 +52,14 @@ def add_lex_emissions(ds: xr.Dataset, m: Model, lex: Dict[str, LinearExpression]
lex.update(
{
"AnnualTechnologyEmissionByMode": AnnualTechnologyEmissionByMode,
"AnnualTechnologyEmissionByModeRegionGroup": AnnualTechnologyEmissionByModeRegionGroup,
"AnnualTechnologyEmission": AnnualTechnologyEmission,
"AnnualTechnologyEmissionRegionGroup": AnnualTechnologyEmissionRegionGroup,
"AnnualTechnologyEmissionPenaltyByEmission": AnnualTechnologyEmissionPenaltyByEmission,
"AnnualTechnologyEmissionsPenalty": AnnualTechnologyEmissionsPenalty,
"AnnualEmissions": AnnualEmissions,
"AnnualEmissionsRegionGroupTag": AnnualEmissionsRegionGroupTag,
"AnnualEmissionsRegionGroup": AnnualEmissionsRegionGroup,
"ModelPeriodEmissions": ModelPeriodEmissions,
}
)
5 changes: 5 additions & 0 deletions tz/osemosys/model/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ class Model(RunSpec):
`regions` `(List[Region])` - List of Region instances to contain region names.
Required parameter.

`regionsgroup` `(List[RegionGroup])` - List of Region Group instances to contain region group
names.
Optional parameter, defaults to `None`.

`commodities` `(List[Commodity])` - List of Commodity instances to contain all data related to
commodities (OSeMOSYS FUEL).
Required parameter.
Expand Down Expand Up @@ -96,6 +100,7 @@ class Model(RunSpec):
TimeDefinition,
Commodity,
Region,
RegionGroup,
Impact,
OperatingMode,
)
Expand Down
Loading
Loading