From e03988d2aff7ed11d0ff9d73ed849829061dc072 Mon Sep 17 00:00:00 2001 From: Tom Bland Date: Wed, 30 Oct 2024 17:16:31 +0000 Subject: [PATCH 1/7] Remove trade feature --- src/muse/agents/agent.py | 2 - src/muse/agents/factories.py | 4 -- src/muse/constraints.py | 20 -------- src/muse/demand_share.py | 4 +- src/muse/examples.py | 8 +-- src/muse/outputs/cache.py | 4 -- src/muse/outputs/mca.py | 3 -- src/muse/quantities.py | 26 ++-------- src/muse/readers/csv.py | 67 +------------------------ src/muse/readers/toml.py | 11 +---- src/muse/sectors/sector.py | 92 +++++------------------------------ src/muse/sectors/subsector.py | 33 +------------ tests/test_readers.py | 42 ---------------- 13 files changed, 20 insertions(+), 296 deletions(-) diff --git a/src/muse/agents/agent.py b/src/muse/agents/agent.py index 8d7b503ae..95afdc58e 100644 --- a/src/muse/agents/agent.py +++ b/src/muse/agents/agent.py @@ -443,8 +443,6 @@ def retirement_profile( lifetime, investment_year=current_year + time_period, ) - if "dst_region" in investments.coords: - investments = investments.reindex_like(profile, method="ffill") # Apply the retirement profile to the investments new_assets = (investments * profile).rename(replacement="asset") diff --git a/src/muse/agents/factories.py b/src/muse/agents/factories.py index f912ecd1e..ea1454745 100644 --- a/src/muse/agents/factories.py +++ b/src/muse/agents/factories.py @@ -198,10 +198,6 @@ def agents_factory( if regions and "region" in capacity.dims: capacity = capacity.sel(region=regions) - if regions and "dst_region" in capacity.dims: - capacity = capacity.sel(dst_region=regions) - if capacity.dst_region.size == 1: - capacity = capacity.squeeze("dst_region", drop=True) result = [] retrofit_present = False diff --git a/src/muse/constraints.py b/src/muse/constraints.py index 51640942a..f77ca44a5 100644 --- a/src/muse/constraints.py +++ b/src/muse/constraints.py @@ -380,9 +380,6 @@ def max_capacity_expansion( if b.region.dims == (): capa = 1 - elif "dst_region" in b.dims: - b = b.rename(region="src_region") - capa = search_space.agent.region == b.src_region return xr.Dataset( dict(b=b, capacity=capa), @@ -406,8 +403,6 @@ def demand( enduse = technologies.commodity.sel(commodity=is_enduse(technologies.comm_usage)) b = demand.sel(commodity=demand.commodity.isin(enduse)) - if "region" in b.dims and "dst_region" in assets.dims: - b = b.rename(region="dst_region") assert "year" not in b.dims return xr.Dataset( dict(b=b, production=1), attrs=dict(kind=ConstraintKind.LOWER_BOUND) @@ -477,21 +472,6 @@ def max_production( capacity = capacity.expand_dims(asset=search_space.asset) production = ones_like(capacity) b = zeros_like(production) - # Include maxaddition constraint in max production to match region-dst_region - if "dst_region" in assets.dims: - b = b.expand_dims(dst_region=assets.dst_region) - capacity = capacity.rename(region="src_region") - production = production.rename(region="src_region") - maxadd = technologies.max_capacity_addition.rename(region="src_region") - if "year" in maxadd.dims: - maxadd = maxadd.sel(year=year) - - maxadd = maxadd.rename(technology="replacement") - maxadd = maxadd.where(maxadd == 0, 0.0) - maxadd = maxadd.where(maxadd > 0, -1.0) - capacity = capacity * broadcast_timeslice(maxadd) - production = production * broadcast_timeslice(maxadd) - b = b.rename(region="src_region") return xr.Dataset( dict(capacity=-cast(np.ndarray, capacity), production=production, b=b), attrs=dict(kind=ConstraintKind.UPPER_BOUND), diff --git a/src/muse/demand_share.py b/src/muse/demand_share.py index f32aab808..2f6acdf8d 100644 --- a/src/muse/demand_share.py +++ b/src/muse/demand_share.py @@ -522,9 +522,7 @@ def unmet_demand( produced = maximum_production(capacity=capacity, technologies=technologies) # Total commodity production by summing over assets - if "dst_region" in produced.dims: - produced = produced.sum("asset").rename(dst_region="region") - elif "region" in produced.coords and produced.region.dims: + if "region" in produced.coords and produced.region.dims: produced = produced.groupby("region").sum("asset") else: produced = produced.sum("asset") diff --git a/src/muse/examples.py b/src/muse/examples.py index df6293d6f..8de881123 100644 --- a/src/muse/examples.py +++ b/src/muse/examples.py @@ -265,20 +265,16 @@ def matching_market(sector: str, model: str = "default") -> xr.Dataset: maximum_production(loaded_sector.technologies, assets.capacity), ) market["supply"] = production.sum("asset") - if "dst_region" in market.dims: - market = market.rename(dst_region="region") if market.region.dims: consump = consumption(loaded_sector.technologies, production) market["consumption"] = drop_timeslice( - consump.groupby("region").sum( - {"asset", "dst_region"}.intersection(consump.dims) - ) + consump.groupby("region").sum({"asset"}.intersection(consump.dims)) + market.supply ) else: market["consumption"] = ( consumption(loaded_sector.technologies, production).sum( - {"asset", "dst_region"}.intersection(market.dims) + {"asset"}.intersection(market.dims) ) + market.supply ) diff --git a/src/muse/outputs/cache.py b/src/muse/outputs/cache.py index 71712cd95..f0de968c8 100644 --- a/src/muse/outputs/cache.py +++ b/src/muse/outputs/cache.py @@ -353,7 +353,6 @@ def extract_agents_internal( info[aid]["agent"] = agent.name info[aid]["category"] = agent.category info[aid]["sector"] = sector_name - info[aid]["dst_region"] = agent.region info[aid]["year"] = agent.forecast_year info[aid]["installed"] = agent.year @@ -412,12 +411,9 @@ def consolidate_quantity( """ data = _aggregate_cache(quantity, cached) - ignore_dst_region = "dst_region" in data.columns for agent in tuple(agents): filter = data.agent == agent for key, value in agents[agent].items(): - if key == "dst_region" and ignore_dst_region: - continue data.loc[filter, key] = value data = data.rename(columns={"replacement": "technology"}) diff --git a/src/muse/outputs/mca.py b/src/muse/outputs/mca.py index 7d9284daf..26fec4b99 100644 --- a/src/muse/outputs/mca.py +++ b/src/muse/outputs/mca.py @@ -193,14 +193,11 @@ def sector_capacity(sector: AbstractSector) -> pd.DataFrame: capa_agent["sector"] = getattr(sector, "name", "unnamed") if len(capa_agent) > 0 and len(capa_agent.technology.values) > 0: - if "dst_region" not in capa_agent.coords: - capa_agent["dst_region"] = agent.region a = capa_agent.to_dataframe() b = ( a.groupby( [ "technology", - "dst_region", "region", "agent", "sector", diff --git a/src/muse/quantities.py b/src/muse/quantities.py index fa4cec2cc..7ac7bd09c 100644 --- a/src/muse/quantities.py +++ b/src/muse/quantities.py @@ -45,38 +45,18 @@ def supply( maxprod = maximum_production(technologies, capacity) minprod = minimum_production(technologies, capacity) size = np.array(maxprod.region).size - # in presence of trade demand needs to map maxprod dst_region - if ( - "region" in demand.dims - and "region" in maxprod.coords - and "dst_region" not in maxprod.dims - and size == 1 - ): + + if "region" in demand.dims and "region" in maxprod.coords and size == 1: demand = demand.sel(region=maxprod.region) prodsum = set(demand.dims).difference(maxprod.dims) demsum = set(maxprod.dims).difference(demand.dims) expanded_demand = (demand * maxprod / maxprod.sum(demsum)).fillna(0) - elif ( - "region" in demand.dims - and "region" in maxprod.coords - and "dst_region" not in maxprod.dims - and size > 1 - ): + elif "region" in demand.dims and "region" in maxprod.coords and size > 1: prodsum = set(demand.dims).difference(maxprod.dims) demsum = set(maxprod.dims).difference(demand.dims) expanded_demand = (demand * maxprod / maxprod.sum(demsum)).fillna(0) - elif ( - "region" in demand.dims - and "region" in maxprod.coords - and "dst_region" in maxprod.dims - ): - demand = demand.rename(region="dst_region") - prodsum = {"timeslice"} - demsum = {"asset"} - expanded_demand = (demand * maxprod / maxprod.sum(demsum)).fillna(0) - else: prodsum = set(demand.dims).difference(maxprod.dims) demsum = set(maxprod.dims).difference(demand.dims) diff --git a/src/muse/readers/csv.py b/src/muse/readers/csv.py index 4eea66108..e00726c08 100644 --- a/src/muse/readers/csv.py +++ b/src/muse/readers/csv.py @@ -237,12 +237,7 @@ def read_io_technodata(filename: Union[str, Path]) -> xr.Dataset: def read_initial_assets(filename: Union[str, Path]) -> xr.DataArray: """Reads and formats data about initial capacity into a dataframe.""" data = pd.read_csv(filename, float_precision="high", low_memory=False) - if "Time" in data.columns: - result = cast( - xr.DataArray, read_trade(filename, skiprows=[1], columns_are_source=True) - ) - else: - result = read_initial_capacity(data) + result = read_initial_capacity(data) technology = result.technology result = result.drop_vars("technology").rename(technology="asset") result["technology"] = "asset", technology.values @@ -815,66 +810,6 @@ def expand_paths(path): return result -def read_trade( - data: Union[pd.DataFrame, str, Path], - columns_are_source: bool = True, - parameters: Optional[str] = None, - skiprows: Optional[Sequence[int]] = None, - name: Optional[str] = None, - drop: Optional[Union[str, Sequence[str]]] = None, -) -> Union[xr.DataArray, xr.Dataset]: - """Read CSV table with source and destination regions.""" - from muse.readers import camel_to_snake - - if not isinstance(data, pd.DataFrame): - data = pd.read_csv(data, skiprows=skiprows) - - if parameters is None and "Parameter" in data.columns: - parameters = "Parameter" - if columns_are_source: - col_region = "src_region" - row_region = "dst_region" - else: - row_region = "src_region" - col_region = "dst_region" - data = data.apply(to_numeric, axis=0) - if isinstance(drop, str): - drop = [drop] - if drop: - drop = list(set(drop).intersection(data.columns)) - if drop: - data = data.drop(columns=drop) - data = data.rename( - columns=dict( - Time="year", - ProcessName="technology", - RegionName=row_region, - Commodity="commodity", - ) - ) - indices = list( - {"commodity", "year", "src_region", "dst_region", "technology"}.intersection( - data.columns - ) - ) - data = data.melt( - id_vars={parameters}.union(indices).intersection(data.columns), - var_name=col_region, - ) - if parameters is None: - result: Union[xr.DataArray, xr.Dataset] = xr.DataArray.from_series( - data.set_index([*indices, col_region])["value"] - ).rename(name) - else: - result = xr.Dataset.from_dataframe( - data.pivot_table( - values="value", columns=parameters, index=[*indices, col_region] - ).rename(columns=camel_to_snake) - ) - - return result.rename(src_region="region") - - def read_finite_resources(path: Union[str, Path]) -> xr.DataArray: """Reads finite resources from csv file. diff --git a/src/muse/readers/toml.py b/src/muse/readers/toml.py index 55e97692c..0e465f752 100644 --- a/src/muse/readers/toml.py +++ b/src/muse/readers/toml.py @@ -667,7 +667,7 @@ def read_technodata( **kwargs, ) -> xr.Dataset: """Helper function to create technodata for a given sector.""" - from muse.readers.csv import read_technologies, read_trade + from muse.readers.csv import read_technologies if time_framework is None: time_framework = getattr(settings, "time_framework", [2010, 2050]) @@ -727,15 +727,6 @@ def read_technodata( technologies = technologies.sel(commodity=techcomms) for name, value in technosettings.items(): if isinstance(name, (str, Path)): - data = read_trade(value, drop="Unit") - if "region" in data.dims: - data = data.sel(region=regions) - if "dst_region" in data.dims: - data = data.sel(dst_region=regions) - if data.dst_region.size == 1: - data = data.squeeze("dst_region", drop=True) - - else: data = value if isinstance(data, xr.Dataset): technologies = technologies.merge(data) diff --git a/src/muse/sectors/sector.py b/src/muse/sectors/sector.py index 7037eeca4..95a810a95 100644 --- a/src/muse/sectors/sector.py +++ b/src/muse/sectors/sector.py @@ -226,34 +226,7 @@ def group_assets(x: xr.DataArray) -> xr.DataArray: ) result = output_data.copy(deep=True) - if "dst_region" in result: - exclude = ["dst_region", "commodity", "year", "timeslice"] - prices = market.prices.expand_dims(dst_region=market.prices.region.values) - sup, prices = xr.broadcast(result.supply, prices) - sup = sup.fillna(0.0) - con, prices = xr.broadcast(result.consumption, prices) - con = con.fillna(0.0) - supply = result.supply.sum("region").rename(dst_region="region") - consumption = con.sum("dst_region") - assert len(supply.region) == len(consumption.region) - - # Need to reindex costs to avoid nans for non-producing regions - costs0, prices = xr.broadcast(result.costs, prices, exclude=exclude) - # Fulfil nans with price values - costs0 = costs0.reindex_like(prices).fillna(prices) - costs0 = costs0.where(costs0 > 0, prices) - # Find where sup >0 (exporter) - # Importers have nans and average over exporting price - costs = ((costs0 * sup) / sup.sum("dst_region")).fillna( - costs0.mean("region") - ) - - # Take average over dst regions - costs = costs.where(costs > 0, prices).mean("dst_region") - - result = xr.Dataset( - dict(supply=supply, consumption=consumption, costs=costs) - ) + result = self.convert_market_timeslice(result, mca_market.timeslice) result["comm_usage"] = self.technologies.comm_usage.sel( commodity=result.commodity ) @@ -304,60 +277,17 @@ def capacity(self) -> xr.DataArray: """ from muse.utilities import filter_input, reduce_assets - traded = [ - u.assets.capacity - for u in self.agents - if "dst_region" in u.assets.capacity.dims - ] - nontraded = [ - u.assets.capacity - for u in self.agents - if "dst_region" not in u.assets.capacity.dims - ] + nontraded = [u.assets.capacity for u in self.agents] - # Only nontraded assets - if not traded: - full_list = [ - list(nontraded[i].year.values) - for i in range(len(nontraded)) - if "year" in nontraded[i].dims - ] - flat_list = [item for sublist in full_list for item in sublist] - years = sorted(list(set(flat_list))) - nontraded = [ - filter_input(u.assets.capacity, year=years) - for u in self.agents - if "dst_region" not in u.assets.capacity.dims - ] - return reduce_assets(nontraded) - - # Only traded assets - elif not nontraded: - full_list = [ - list(traded[i].year.values) - for i in range(len(traded)) - if "year" in traded[i].dims - ] - flat_list = [item for sublist in full_list for item in sublist] - years = sorted(list(set(flat_list))) - traded = [ - filter_input(u.assets.capacity, year=years) - for u in self.agents - if "dst_region" in u.assets.capacity.dims - ] - return reduce_assets(traded) - - # Both traded and nontraded assets - else: - traded_results = reduce_assets(traded) - nontraded_results = reduce_assets(nontraded) - return reduce_assets( - [ - traded_results, - nontraded_results - * (nontraded_results.region == traded_results.dst_region), - ] - ) + full_list = [ + list(nontraded[i].year.values) + for i in range(len(nontraded)) + if "year" in nontraded[i].dims + ] + flat_list = [item for sublist in full_list for item in sublist] + years = sorted(list(set(flat_list))) + nontraded = [filter_input(u.assets.capacity, year=years) for u in self.agents] + return reduce_assets(nontraded) @property def agents(self) -> Iterator[AbstractAgent]: diff --git a/src/muse/sectors/subsector.py b/src/muse/sectors/subsector.py index 03798af0f..3493c81a5 100644 --- a/src/muse/sectors/subsector.py +++ b/src/muse/sectors/subsector.py @@ -10,7 +10,6 @@ import xarray as xr from muse.agents import Agent -from muse.timeslices import drop_timeslice class Subsector: @@ -25,7 +24,6 @@ def __init__( investment: Callable | None = None, name: str = "subsector", forecast: int = 5, - expand_market_prices: bool = False, ): from muse import constraints as cs from muse import demand_share as ds @@ -38,13 +36,6 @@ def __init__( self.investment = investment or iv.factory() self.forecast = forecast self.name = name - self.expand_market_prices = expand_market_prices - """Whether to expand prices to include destination region. - - If ``True``, the input market prices are expanded of the missing "dst_region" - dimension by setting them to the maximum between the source and destination - region. - """ def invest( self, @@ -53,13 +44,6 @@ def invest( time_period: int, current_year: int, ) -> None: - # Expand prices to include destination region (for trade models) - if self.expand_market_prices: - market = market.copy() - market["prices"] = drop_timeslice( - np.maximum(market.prices, market.prices.rename(region="dst_region")) - ) - # Agent housekeeping for agent in self.agents: agent.asset_housekeeping() @@ -85,14 +69,6 @@ def aggregate_lp( forecast=self.forecast, ) - if "dst_region" in demands.dims: - msg = """ - dst_region found in demand dimensions. This is unexpected. Demands - should only have a region dimension rather both a source and destination - dimension. - """ - raise ValueError(msg) - # Concatenate assets assets = agent_concatenation( {agent.uuid: agent.assets for agent in self.agents} @@ -126,7 +102,7 @@ def factory( from muse import constraints as cs from muse import demand_share as ds from muse import investments as iv - from muse.agents import InvestingAgent, agents_factory + from muse.agents import agents_factory from muse.commodities import is_enduse from muse.readers.toml import undo_damage @@ -184,12 +160,6 @@ def factory( investment = iv.factory(getattr(settings, "lpsolver", "scipy")) forecast = getattr(settings, "forecast", 5) - expand_market_prices = getattr(settings, "expand_market_prices", None) - if expand_market_prices is None: - expand_market_prices = "dst_region" in technologies.dims and not any( - isinstance(u, InvestingAgent) for u in agents - ) - return cls( agents=agents, commodities=commodities, @@ -198,7 +168,6 @@ def factory( investment=investment, forecast=forecast, name=name, - expand_market_prices=expand_market_prices, ) diff --git a/tests/test_readers.py b/tests/test_readers.py index 87589d1dc..7f0b1fdaa 100644 --- a/tests/test_readers.py +++ b/tests/test_readers.py @@ -380,48 +380,6 @@ def test_suffix_path_formatting(suffix, tmpdir): ) -def test_read_existing_trade(tmp_path): - from muse.examples import copy_model - from muse.readers.csv import read_trade - - copy_model("trade", tmp_path) - path = tmp_path / "model" / "technodata" / "gas" / "ExistingTrade.csv" - data = read_trade(path, skiprows=[1]) - - assert isinstance(data, xr.DataArray) - assert set(data.dims) == {"year", "technology", "dst_region", "region"} - assert list(data.coords["year"].values) == [2010, 2020, 2030, 2040, 2050] - assert list(data.coords["technology"].values) == ["gassupply1"] - assert list(data.coords["dst_region"].values) == ["R1", "R2"] - assert list(data.coords["region"].values) == ["R1", "R2"] - - -def test_read_trade_technodata(tmp_path): - from muse.examples import copy_model - from muse.readers.csv import read_trade - - copy_model("trade", tmp_path) - path = tmp_path / "model" / "technodata" / "gas" / "TradeTechnodata.csv" - data = read_trade(path, drop="Unit") - - assert isinstance(data, xr.Dataset) - assert set(data.dims) == {"technology", "dst_region", "region"} - assert set(data.data_vars) == { - "cap_par", - "cap_exp", - "fix_par", - "fix_exp", - "max_capacity_addition", - "max_capacity_growth", - "total_capacity_limit", - } - assert all(val == np.float64 for val in data.dtypes.values()) - assert list(data.coords["dst_region"].values) == ["R1", "R2"] - assert list(data.coords["technology"].values) == ["gassupply1"] - assert list(data.coords["region"].values) == ["R1", "R2", "R3"] - assert all(var.coords.equals(data.coords) for var in data.data_vars.values()) - - @fixture def default_model(tmp_path): from muse.examples import copy_model From c690a53bad699dcf86eed49c8862919d5ab62e36 Mon Sep 17 00:00:00 2001 From: Tom Bland Date: Wed, 30 Oct 2024 17:20:24 +0000 Subject: [PATCH 2/7] Fix tiny error --- src/muse/readers/toml.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/muse/readers/toml.py b/src/muse/readers/toml.py index 0e465f752..ccd9985fc 100644 --- a/src/muse/readers/toml.py +++ b/src/muse/readers/toml.py @@ -726,8 +726,7 @@ def read_technodata( techcomms = technologies.commodity[ins | outs] technologies = technologies.sel(commodity=techcomms) for name, value in technosettings.items(): - if isinstance(name, (str, Path)): - data = value + data = value if isinstance(data, xr.Dataset): technologies = technologies.merge(data) else: From 07e26c6473cf4072a60f2c1db3225e9f47925a95 Mon Sep 17 00:00:00 2001 From: Tom Bland Date: Wed, 30 Oct 2024 17:22:01 +0000 Subject: [PATCH 3/7] Delete tests --- tests/test_trade.py | 152 -------------------------------------------- 1 file changed, 152 deletions(-) delete mode 100644 tests/test_trade.py diff --git a/tests/test_trade.py b/tests/test_trade.py deleted file mode 100644 index 2398b47d9..000000000 --- a/tests/test_trade.py +++ /dev/null @@ -1,152 +0,0 @@ -from collections.abc import Mapping -from typing import Any - -import numpy as np -import xarray as xr -from pytest import approx, fixture - - -@fixture -def constraints_args(sector="power", model="trade") -> Mapping[str, Any]: - from muse import examples - from muse.utilities import agent_concatenation, reduce_assets - - power = examples.sector(model=model, sector=sector) - search_space = examples.search_space("power", model="trade") - market = examples.matching_market("power", "trade") - assets = reduce_assets( - agent_concatenation({u.uuid: u.assets for u in list(power.agents)}), - coords=["agent", "technology", "region"], - ).set_coords(["agent", "technology", "region"]) - return dict( - demand=market.consumption.sel(year=market.year.min(), drop=True), - assets=assets, - search_space=search_space, - market=market, - technologies=power.technologies, - ) - - -def test_demand_constraint(constraints_args): - from muse import constraints as cs - - constraint = cs.demand(**constraints_args) - assert set(constraint.b.dims) == {"timeslice", "dst_region", "commodity"} - - -def test_max_capacity_constraints(constraints_args): - from muse import constraints as cs - - constraint = cs.max_capacity_expansion(**constraints_args) - assert constraint.production == 0 - assert set(constraint.capacity.dims) == {"agent", "src_region"} - assert ((constraint.region == constraint.src_region) == constraint.capacity).all() - assert set(constraint.b.dims) == {"replacement", "dst_region", "src_region"} - assert set(constraint.agent.coords) == {"region", "agent"} - - -def test_max_production(constraints_args): - from muse import constraints as cs - - constraint = cs.max_production(**constraints_args) - dims = { - "timeslice", - "commodity", - "replacement", - "agent", - "timeslice", - "dst_region", - "src_region", - } - assert set(constraint.capacity.dims) == dims - assert set(constraint.production.dims) == dims - assert constraint.year.dims == () - assert set(constraint.agent.coords) == {"region", "agent", "year"} - - -def test_minimum_service(constraints_args): - from muse import constraints as cs - - assert cs.minimum_service(**constraints_args) is None - - constraints_args["technologies"]["minimum_service_factor"] = 0.5 - constraint = cs.minimum_service(**constraints_args) - dims = {"replacement", "asset", "commodity", "timeslice"} - assert set(constraint.capacity.dims) == dims - assert set(constraint.production.dims) == dims - assert set(constraint.b.dims) == dims - assert (constraint.capacity <= 0).all() - assert constraint.year.dims == () - assert set(constraint.asset.coords) == {"region", "agent", "year"} - - -def test_search_space(constraints_args): - from muse import constraints as cs - - search_space = constraints_args["search_space"] - search_space[:] = 1 - assert cs.search_space(**constraints_args) is None - - search_space[:] = search_space * (search_space.region == "R1") - constraint = cs.search_space(**constraints_args) - assert constraint.b.values == approx(0) - assert constraint.production == 0 - assert set(constraint.b.dims) == {"replacement", "agent"} - assert set(constraint.capacity.dims) == {"replacement", "agent"} - assert set(constraint.agent.coords) == {"region", "agent"} - - -def test_lp_costs(): - from muse import examples - from muse.constraints import lp_costs - - technologies = examples.technodata("power", model="trade") - search_space = examples.search_space("power", model="trade") - costs = ( - search_space - * np.arange(np.prod(search_space.shape)).reshape(search_space.shape) - * xr.ones_like(technologies.dst_region) - ) - - lpcosts = lp_costs(technologies.sel(year=2020, drop=True), costs) - assert "capacity" in lpcosts.data_vars - assert "production" in lpcosts.data_vars - assert set(lpcosts.capacity.dims) == {"agent", "replacement", "dst_region"} - assert set(lpcosts.production.dims) == { - "agent", - "replacement", - "dst_region", - "timeslice", - "commodity", - } - assert set(lpcosts.agent.coords) == {"region", "agent"} - - -def test_power_sector_no_investment(): - from muse import examples - from muse.utilities import agent_concatenation - - power = examples.sector("power", "trade") - market = examples.matching_market("power", "trade").sel(year=[2020, 2025, 2030]) - - initial = agent_concatenation({u.uuid: u.assets.capacity for u in power.agents}) - power.next(market) - final = agent_concatenation({u.uuid: u.assets.capacity for u in power.agents}) - - assert (initial == final).all() - - -def test_power_sector_some_investment(): - from muse import examples - from muse.utilities import agent_concatenation - - power = examples.sector("power", "trade") - market = examples.matching_market("power", "trade").sel(year=[2020, 2025, 2030]) - market.consumption[:] *= 1.5 - - initial = agent_concatenation({u.uuid: u.assets.capacity for u in power.agents}) - result = power.next(market) - final = agent_concatenation({u.uuid: u.assets.capacity for u in power.agents}) - assert "windturbine" not in initial.technology - assert final.sel(asset=final.technology == "windturbine", year=2030).sum() < 1 - assert "dst_region" not in result.dims From 4142463172b7c7b6c94e8b4f41d16dd765eeb7f7 Mon Sep 17 00:00:00 2001 From: Tom Bland Date: Thu, 31 Oct 2024 09:06:42 +0000 Subject: [PATCH 4/7] Remove more references to trade --- src/muse/examples.py | 48 +++++++---------------------------------- src/muse/objectives.py | 3 +-- tests/test_agents.py | 4 ---- tests/test_outputs.py | 2 -- tests/test_subsector.py | 1 - 5 files changed, 9 insertions(+), 49 deletions(-) diff --git a/src/muse/examples.py b/src/muse/examples.py index 8de881123..1d6d1d774 100644 --- a/src/muse/examples.py +++ b/src/muse/examples.py @@ -150,9 +150,14 @@ def search_space(sector: str, model: str = "default") -> xr.DataArray: Used in constraints or during investment. """ - if model == "trade" and sector != "residential": - return _trade_search_space(sector, model) - return _nontrade_search_space(sector, model) + from numpy import ones + + technology = technodata(sector, model).technology + return xr.DataArray( + ones((len(technology), len(technology)), dtype=bool), + coords=dict(asset=technology.values, replacement=technology.values), + dims=("asset", "replacement"), + ) def sector(sector: str, model: str = "default") -> AbstractSector: @@ -376,40 +381,3 @@ def _copy_trade(path: Path): copytree(example_data_dir() / "trade" / "input", path / "input") copytree(example_data_dir() / "trade" / "technodata", path / "technodata") copyfile(example_data_dir() / "trade" / "settings.toml", path / "settings.toml") - - -def _trade_search_space(sector: str, model: str = "default") -> xr.DataArray: - from muse.agents import Agent - from muse.examples import sector as load_sector - from muse.sectors import Sector - from muse.utilities import agent_concatenation - - loaded_sector = cast(Sector, load_sector(sector, model)) - - market = matching_market(sector, model) - return cast( - xr.DataArray, - agent_concatenation( - { - a.uuid: cast(Agent, a).search_rules( - agent=a, - demand=market.consumption.isel(year=0, drop=True), - technologies=loaded_sector.technologies, - market=market, - ) - for a in loaded_sector.agents - }, - dim="agent", - ), - ) - - -def _nontrade_search_space(sector: str, model: str = "default") -> xr.DataArray: - from numpy import ones - - technology = technodata(sector, model).technology - return xr.DataArray( - ones((len(technology), len(technology)), dtype=bool), - coords=dict(asset=technology.values, replacement=technology.values), - dims=("asset", "replacement"), - ) diff --git a/src/muse/objectives.py b/src/muse/objectives.py index 5e51d7ef0..33d3e90f6 100644 --- a/src/muse/objectives.py +++ b/src/muse/objectives.py @@ -362,8 +362,7 @@ def annual_levelized_cost_of_energy( ): """Annual cost of energy (LCOE) of technologies - not dependent on production. - It needs to be used for trade agents where the actual service is unknown. It follows - the `simplified LCOE` given by NREL. + It follows the `simplified LCOE` given by NREL. See :py:func:`muse.costs.annual_levelized_cost_of_energy` for more details. diff --git a/tests/test_agents.py b/tests/test_agents.py index ea351d9b0..5279ce6a5 100644 --- a/tests/test_agents.py +++ b/tests/test_agents.py @@ -199,7 +199,6 @@ def test_initial_assets(tmp_path): from muse.readers.csv import read_initial_assets copy_model("default", tmp_path / "default") - copy_model("trade", tmp_path / "trade") def path(x, y): return ( @@ -208,6 +207,3 @@ def path(x, y): assets = read_initial_assets(path("default", "capacity")) assert set(assets.dims) == {"year", "region", "asset"} - - assets = read_initial_assets(path("trade", "trade")) - assert set(assets.dims) == {"year", "region", "asset", "dst_region"} diff --git a/tests/test_outputs.py b/tests/test_outputs.py index dd4fa5d51..1a7fed89d 100644 --- a/tests/test_outputs.py +++ b/tests/test_outputs.py @@ -504,14 +504,12 @@ def test_extract_agents_internal(newcapa_agent, retro_agent): "agent", "category", "sector", - "dst_region", "year", "installed", ) assert actual[agent.uuid]["agent"] == agent.name assert actual[agent.uuid]["category"] == agent.category assert actual[agent.uuid]["sector"] == "IT" - assert actual[agent.uuid]["dst_region"] == agent.region def test_aggregate_cache(): diff --git a/tests/test_subsector.py b/tests/test_subsector.py index 3994ece31..fbb036669 100644 --- a/tests/test_subsector.py +++ b/tests/test_subsector.py @@ -84,7 +84,6 @@ def test_subsector_noninvesting_aggregation(market, model, technologies, tmp_pat del param["share"] param["agent_type"] = "default" - param["category"] = "trade" param["year"] = 2020 param["search_rules"] = "from_assets -> compress -> reduce_assets" param["objectives"] = "ALCOE" From b77d84909f175a819bfb7f80026aa8cc9ea285e9 Mon Sep 17 00:00:00 2001 From: Tom Bland Date: Thu, 31 Oct 2024 11:24:45 +0000 Subject: [PATCH 5/7] Delete trade model --- .../example/trade/input/GlobalCommodities.csv | 6 - .../data/example/trade/input/Projections.csv | 40 ------ src/muse/data/example/trade/settings.toml | 132 ------------------ .../data/example/trade/technodata/Agents.csv | 3 - .../example/trade/technodata/gas/CommIn.csv | 5 - .../example/trade/technodata/gas/CommOut.csv | 4 - .../trade/technodata/gas/ExistingTrade.csv | 12 -- .../trade/technodata/gas/Technodata.csv | 4 - .../trade/technodata/gas/TradeTechnodata.csv | 15 -- .../example/trade/technodata/power/CommIn.csv | 6 - .../trade/technodata/power/CommOut.csv | 6 - .../trade/technodata/power/ExistingTrade.csv | 32 ----- .../trade/technodata/power/Technodata.csv | 6 - .../technodata/power/TradeTechnodata.csv | 21 --- .../preset/Residential2020Consumption.csv | 13 -- .../preset/Residential2030Consumption.csv | 13 -- .../preset/Residential2050Consumption.csv | 13 -- .../trade/technodata/residential/Agents.csv | 5 - .../trade/technodata/residential/CommIn.csv | 6 - .../trade/technodata/residential/CommOut.csv | 6 - .../residential/ExistingCapacity.csv | 5 - .../technodata/residential/Technodata.csv | 6 - src/muse/examples.py | 10 -- 23 files changed, 369 deletions(-) delete mode 100644 src/muse/data/example/trade/input/GlobalCommodities.csv delete mode 100644 src/muse/data/example/trade/input/Projections.csv delete mode 100644 src/muse/data/example/trade/settings.toml delete mode 100644 src/muse/data/example/trade/technodata/Agents.csv delete mode 100644 src/muse/data/example/trade/technodata/gas/CommIn.csv delete mode 100644 src/muse/data/example/trade/technodata/gas/CommOut.csv delete mode 100644 src/muse/data/example/trade/technodata/gas/ExistingTrade.csv delete mode 100644 src/muse/data/example/trade/technodata/gas/Technodata.csv delete mode 100644 src/muse/data/example/trade/technodata/gas/TradeTechnodata.csv delete mode 100644 src/muse/data/example/trade/technodata/power/CommIn.csv delete mode 100644 src/muse/data/example/trade/technodata/power/CommOut.csv delete mode 100644 src/muse/data/example/trade/technodata/power/ExistingTrade.csv delete mode 100644 src/muse/data/example/trade/technodata/power/Technodata.csv delete mode 100644 src/muse/data/example/trade/technodata/power/TradeTechnodata.csv delete mode 100644 src/muse/data/example/trade/technodata/preset/Residential2020Consumption.csv delete mode 100644 src/muse/data/example/trade/technodata/preset/Residential2030Consumption.csv delete mode 100644 src/muse/data/example/trade/technodata/preset/Residential2050Consumption.csv delete mode 100644 src/muse/data/example/trade/technodata/residential/Agents.csv delete mode 100644 src/muse/data/example/trade/technodata/residential/CommIn.csv delete mode 100644 src/muse/data/example/trade/technodata/residential/CommOut.csv delete mode 100644 src/muse/data/example/trade/technodata/residential/ExistingCapacity.csv delete mode 100644 src/muse/data/example/trade/technodata/residential/Technodata.csv diff --git a/src/muse/data/example/trade/input/GlobalCommodities.csv b/src/muse/data/example/trade/input/GlobalCommodities.csv deleted file mode 100644 index 0d4c58da7..000000000 --- a/src/muse/data/example/trade/input/GlobalCommodities.csv +++ /dev/null @@ -1,6 +0,0 @@ -Commodity,CommodityType,CommodityName,CommodityEmissionFactor_CO2,HeatRate,Unit -Electricity,Energy,electricity,0,1,PJ -Gas,Energy,gas,56.1,1,PJ -Heat,Energy,heat,0,1,PJ -Wind,Energy,wind,0,1,PJ -CO2fuelcomsbustion,Environmental,CO2f,0,1,kt diff --git a/src/muse/data/example/trade/input/Projections.csv b/src/muse/data/example/trade/input/Projections.csv deleted file mode 100644 index 72a3c8165..000000000 --- a/src/muse/data/example/trade/input/Projections.csv +++ /dev/null @@ -1,40 +0,0 @@ -RegionName,Attribute,Time,electricity,gas,heat,CO2f,wind -Unit,-,Year,MUS$2010/PJ,MUS$2010/PJ,MUS$2010/PJ,MUS$2010/kt,MUS$2010/PJ -R1,CommodityPrice,2010,12.61111111,3.8972,0,0,0 -R1,CommodityPrice,2015,13.14814806,4.307,0,0,0 -R1,CommodityPrice,2020,13.98148139,4.7168,0,0,0 -R1,CommodityPrice,2025,16.27777778,5.1266,0,0,0 -R1,CommodityPrice,2030,17.1574075,5.5364,0,0,0 -R1,CommodityPrice,2035,17.50925917,5.9462,0,0,0 -R1,CommodityPrice,2040,18.05555556,6.3559,0,0,0 -R1,CommodityPrice,2045,20.37962972,6.7657,0,0,0 -R1,CommodityPrice,2050,21.5,7.1755,0,0,0 -R1,CommodityPrice,2055,22.12037028,7.1755,0,0,0 -R1,CommodityPrice,2060,22.00925917,7.1755,0,0,0 -R1,CommodityPrice,2065,22.14814806,7.1755,0,0,0 -R1,CommodityPrice,2070,22,7.1755,0,0,0 -R1,CommodityPrice,2075,22.11111111,7.1755,0,0,0 -R1,CommodityPrice,2080,21.92592583,7.1755,0,0,0 -R1,CommodityPrice,2085,21.51851861,7.1755,0,0,0 -R1,CommodityPrice,2090,21.31481472,7.1755,0,0,0 -R1,CommodityPrice,2095,21.03703694,7.1755,0,0,0 -R1,CommodityPrice,2100,20.46296306,7.1755,0,0,0 -R2,CommodityPrice,2010,17.33333333,3.8972,0,0,0 -R2,CommodityPrice,2015,15.66666667,4.307,0,0,0 -R2,CommodityPrice,2020,19.13888889,4.7168,0,0,0 -R2,CommodityPrice,2025,22.86111111,5.1266,0,0,0 -R2,CommodityPrice,2030,24.08333333,5.5364,0,0,0 -R2,CommodityPrice,2035,20.63888889,5.9462,0,0,0 -R2,CommodityPrice,2040,21.32407417,6.3559,0,0,0 -R2,CommodityPrice,2045,20.38888889,6.7657,0,0,0 -R2,CommodityPrice,2050,19.37037028,7.1755,0,0,0 -R2,CommodityPrice,2055,19.13888889,7.1755,0,0,0 -R2,CommodityPrice,2060,21.0925925,7.1755,0,0,0 -R2,CommodityPrice,2065,22.89814806,7.1755,0,0,0 -R2,CommodityPrice,2070,22.94444444,7.1755,0,0,0 -R2,CommodityPrice,2075,21.60185194,7.1755,0,0,0 -R2,CommodityPrice,2080,21.93518528,7.1755,0,0,0 -R2,CommodityPrice,2085,21.87962972,7.1755,0,0,0 -R2,CommodityPrice,2090,22.06481472,7.1755,0,0,0 -R2,CommodityPrice,2095,23.08333333,7.1755,0,0,0 -R2,CommodityPrice,2100,23.82407417,7.1755,0,0,0 diff --git a/src/muse/data/example/trade/settings.toml b/src/muse/data/example/trade/settings.toml deleted file mode 100644 index a851e6a96..000000000 --- a/src/muse/data/example/trade/settings.toml +++ /dev/null @@ -1,132 +0,0 @@ -# Global settings - most REQUIRED - -time_framework = [2020, 2025, 2030, 2035] -foresight = 5 # Has to be a multiple of the minimum separation between the years in time framework -regions = ["R1", "R2"] -interest_rate = 0.1 -interpolation_mode = 'Active' -log_level = 'info' -excluded_commodities = ["wind"] -# Convergence parameters -equilibrium_variable = 'demand' -maximum_iterations = 100 -tolerance = 0.1 -tolerance_unmet_demand = -0.1 - -[[outputs]] -quantity = "capacity" -sink = "aggregate" -filename = "{cwd}/{default_output_dir}/MCA{Quantity}.csv" - -[[outputs]] -quantity = "prices" -sink = "aggregate" -filename = "{cwd}/{default_output_dir}/MCA{Quantity}.csv" - -[carbon_budget_control] -budget = [] - -[global_input_files] -projections = '{path}/input/Projections.csv' -global_commodities = '{path}/input/GlobalCommodities.csv' - -[sectors.presets] -type = 'presets' -priority = 0 -consumption_path = "{path}/technodata/preset/*Consumption.csv" - -[sectors.residential] -type = 'default' -priority = 1 -dispatch_production = 'share' - -[sectors.residential.technodata] -technodata = '{path}/technodata/residential/Technodata.csv' -commodities_in = '{path}/technodata/residential/CommIn.csv' -commodities_out = '{path}/technodata/residential/CommOut.csv' - -[sectors.residential.subsectors.retro_and_new] -agents = '{path}/technodata/residential/Agents.csv' -existing_capacity = '{path}/technodata/residential/ExistingCapacity.csv' -lpsolver = "scipy" -constraints = [ - # Optional, defaults to the constraints below - "max_production", - "max_capacity_expansion", - "demand", - "search_space", - "minimum_service", - "demand_limiting_capacity" -] -demand_share = "new_and_retro" -forecast = 5 -asset_threshold = 1e-4 - -[[sectors.residential.interactions]] -net = 'new_to_retro' -interaction = 'transfer' - -[sectors.power] -type = 'default' -priority = 2 -dispatch_production = 'share' - -[sectors.power.technodata] -technodata = '{path}/technodata/power/Technodata.csv' -trade = '{path}/technodata/power/TradeTechnodata.csv' -commodities_in = '{path}/technodata/power/CommIn.csv' -commodities_out = '{path}/technodata/power/CommOut.csv' - -[sectors.power.subsectors.trade] -agents = '{path}/technodata/Agents.csv' -existing_capacity = '{path}/technodata/power/ExistingTrade.csv' -lpsolver = "scipy" -constraints = [ - # Optional, defaults to the constraints below - "max_production", - "max_capacity_expansion", - "demand", - "search_space", - "minimum_service", - "demand_limiting_capacity" -] -demand_share = "unmet_forecasted_demand" -forecast = 5 -asset_threshold = 1e-4 - -[sectors.gas] -type = 'default' -priority = 3 -dispatch_production = 'share' - -[sectors.gas.technodata] -technodata = '{path}/technodata/gas/Technodata.csv' -trade = '{path}/technodata/gas/TradeTechnodata.csv' -commodities_in = '{path}/technodata/gas/CommIn.csv' -commodities_out = '{path}/technodata/gas/CommOut.csv' - -[sectors.gas.subsectors.trade] -agents = '{path}/technodata/Agents.csv' -existing_capacity = '{path}/technodata/gas/ExistingTrade.csv' -lpsolver = "scipy" -constraints = [ - # Optional, defaults to the constraints below - "max_production", - "max_capacity_expansion", - "demand", - "search_space", - "minimum_service", - "demand_limiting_capacity" -] -demand_share = "unmet_forecasted_demand" -forecast = 5 -asset_threshold = 1e-4 - -[timeslices] -level_names = ["month", "day", "hour"] -all-year.all-week.night = 1460 -all-year.all-week.morning = 1460 -all-year.all-week.afternoon = 1460 -all-year.all-week.early-peak = 1460 -all-year.all-week.late-peak = 1460 -all-year.all-week.evening = 1460 diff --git a/src/muse/data/example/trade/technodata/Agents.csv b/src/muse/data/example/trade/technodata/Agents.csv deleted file mode 100644 index 42fd21d17..000000000 --- a/src/muse/data/example/trade/technodata/Agents.csv +++ /dev/null @@ -1,3 +0,0 @@ -AgentShare,Name,RegionName,Objective,ObjData,Objsort,SearchRule,DecisionMethod,MaturityThreshold,SpendLimit,Type -agent_share,A1,R1,ALCOE,1,TRUE,from_assets->compress->reduce_assets,singleObj,-1,inf,default -agent_share,A1,R2,ALCOE,1,TRUE,from_assets->compress->reduce_assets,singleObj,-1,inf,default diff --git a/src/muse/data/example/trade/technodata/gas/CommIn.csv b/src/muse/data/example/trade/technodata/gas/CommIn.csv deleted file mode 100644 index 6550aed24..000000000 --- a/src/muse/data/example/trade/technodata/gas/CommIn.csv +++ /dev/null @@ -1,5 +0,0 @@ -ProcessName,RegionName,Time,Level,electricity,gas,heat,CO2f,wind -Unit,-,Year,-,PJ/PJ,PJ/PJ,PJ/PJ,kt/PJ,PJ/PJ -gassupply1,R1,2010,fixed,0,1,0,0,0 -gassupply1,R2,2010,fixed,0,1,0,0,0 -gassupply1,R3,2010,fixed,0,1,0,0,0 diff --git a/src/muse/data/example/trade/technodata/gas/CommOut.csv b/src/muse/data/example/trade/technodata/gas/CommOut.csv deleted file mode 100644 index 2458e775d..000000000 --- a/src/muse/data/example/trade/technodata/gas/CommOut.csv +++ /dev/null @@ -1,4 +0,0 @@ -ProcessName,RegionName,Time,electricity,gas,heat,CO2f,wind -Unit,-,Year,PJ/PJ,PJ/PJ,PJ/PJ,kt/PJ,PJ/PJ -gassupply1,R1,2010,0,1,0,0,0 -gassupply1,R2,2010,0,1,0,0,0 diff --git a/src/muse/data/example/trade/technodata/gas/ExistingTrade.csv b/src/muse/data/example/trade/technodata/gas/ExistingTrade.csv deleted file mode 100644 index fb3ffb9e7..000000000 --- a/src/muse/data/example/trade/technodata/gas/ExistingTrade.csv +++ /dev/null @@ -1,12 +0,0 @@ -ProcessName,RegionName,Time,R1,R2 -Unit,-,Year,PJ/y,PJ/y -gassupply1,R1,2010,3000,0 -gassupply1,R1,2020,3000,0 -gassupply1,R1,2030,2100,0 -gassupply1,R1,2040,1470,0 -gassupply1,R1,2050,1029,0 -gassupply1,R2,2010,0,1200 -gassupply1,R2,2020,0,1200 -gassupply1,R2,2030,0,700 -gassupply1,R2,2040,0,490 -gassupply1,R2,2050,0,343 diff --git a/src/muse/data/example/trade/technodata/gas/Technodata.csv b/src/muse/data/example/trade/technodata/gas/Technodata.csv deleted file mode 100644 index b418fd53e..000000000 --- a/src/muse/data/example/trade/technodata/gas/Technodata.csv +++ /dev/null @@ -1,4 +0,0 @@ -ProcessName,RegionName,Time,var_par,var_exp,TechnicalLife,UtilizationFactor,ScalingSize,efficiency,InterestRate,Type,Fuel,EndUse,AgentShare -Unit,-,Year,MUS$2010/PJ,-,Years,-,PJ,%,-,-,-,-,- -gassupply1,R1,2010,3,1,10,0.9,0.00000189,86,0.1,energy,gas,gas,1 -gassupply1,R2,2010,3,1,10,0.9,0.00000189,86,0.1,energy,gas,gas,1 diff --git a/src/muse/data/example/trade/technodata/gas/TradeTechnodata.csv b/src/muse/data/example/trade/technodata/gas/TradeTechnodata.csv deleted file mode 100644 index 9a940ae5c..000000000 --- a/src/muse/data/example/trade/technodata/gas/TradeTechnodata.csv +++ /dev/null @@ -1,15 +0,0 @@ -ProcessName,RegionName,Parameter,Unit,R1,R2,R3 -gassupply1,R1,cap_par,MUSD/PJ,3,98.013,25 -gassupply1,R2,cap_par,MUSD/PJ,7.8406,5,7.8406 -gassupply1,R1,cap_exp,MUSD/PJ,1,1,1 -gassupply1,R2,cap_exp,MUSD/PJ,1,1,1 -gassupply1,R1,fix_par,MUSD/PJ,0.3,0.98013,0.90612 -gassupply1,R2,fix_par,MUSD/PJ,0.78406,0.5,0.17434 -gassupply1,R1,fix_exp,MUSD/PJ,1,1,1 -gassupply1,R2,fix_exp,MUSD/PJ,1,1,1 -gassupply1,R1,MaxCapacityAddition,PJ/y,200,0,0.1 -gassupply1,R2,MaxCapacityAddition,PJ/y,0,200,0 -gassupply1,R1,MaxCapacityGrowth,PJ/y,1,0,0.002 -gassupply1,R2,MaxCapacityGrowth,PJ/y,0,1,0 -gassupply1,R1,TotalCapacityLimit,PJ/y,3937.219,0,1 -gassupply1,R2,TotalCapacityLimit,PJ/y,0,3937.219,0 diff --git a/src/muse/data/example/trade/technodata/power/CommIn.csv b/src/muse/data/example/trade/technodata/power/CommIn.csv deleted file mode 100644 index e4095d85b..000000000 --- a/src/muse/data/example/trade/technodata/power/CommIn.csv +++ /dev/null @@ -1,6 +0,0 @@ -ProcessName,RegionName,Time,Level,electricity,gas,heat,CO2f,wind -Unit,-,Year,-,PJ/PJ,PJ/PJ,PJ/PJ,kt/PJ,PJ/PJ -gasCCGT,R1,2010,fixed,0,1.67,0,0,0 -windturbine,R1,2010,fixed,0,0,0,0,1 -gasCCGT,R2,2010,fixed,0,2,0,0,0 -windturbine,R2,2010,fixed,0,0,0,0,1 diff --git a/src/muse/data/example/trade/technodata/power/CommOut.csv b/src/muse/data/example/trade/technodata/power/CommOut.csv deleted file mode 100644 index cfebcd832..000000000 --- a/src/muse/data/example/trade/technodata/power/CommOut.csv +++ /dev/null @@ -1,6 +0,0 @@ -ProcessName,RegionName,Time,electricity,gas,heat,CO2f,wind -Unit,-,Year,PJ/PJ,PJ/PJ,PJ/PJ,kt/PJ,PJ/PJ -gasCCGT,R1,2010,1,0,0,91.66666667,0 -windturbine,R1,2010,1,0,0,0,0 -gasCCGT,R2,2010,1,0,0,91.66666667,0 -windturbine,R2,2010,1,0,0,0,0 diff --git a/src/muse/data/example/trade/technodata/power/ExistingTrade.csv b/src/muse/data/example/trade/technodata/power/ExistingTrade.csv deleted file mode 100644 index c699d5928..000000000 --- a/src/muse/data/example/trade/technodata/power/ExistingTrade.csv +++ /dev/null @@ -1,32 +0,0 @@ -ProcessName,RegionName,Time,R1,R2 -Unit,-,Year,PJ/y,PJ/y -gasCCGT,R1,2010,300,0 -gasCCGT,R1,2020,240,0 -gasCCGT,R2,2010,0,200 -gasCCGT,R2,2020,0,200 -gasCCGT,R1,2025,192,0 -gasCCGT,R2,2025,0,140 -gasCCGT,R1,2030,153.6,0 -gasCCGT,R2,2030,0,98 -gasCCGT,R1,2035,122.88,0 -gasCCGT,R2,2035,0,68.6 -gasCCGT,R1,2040,98.304,0 -gasCCGT,R2,2040,0,48.02 -gasCCGT,R1,2045,78.6432,0 -gasCCGT,R2,2045,0,33.614 -gasCCGT,R1,2050,62.91456,0 -gasCCGT,R2,2050,0,23.5298 -windturbine,R1,2020,0,0 -windturbine,R2,2020,0,0 -windturbine,R1,2025,0,0 -windturbine,R2,2025,0,0 -windturbine,R1,2030,0,0 -windturbine,R2,2030,0,0 -windturbine,R1,2035,0,0 -windturbine,R2,2035,0,0 -windturbine,R1,2040,0,0 -windturbine,R2,2040,0,0 -windturbine,R1,2045,0,0 -windturbine,R2,2045,0,0 -windturbine,R1,2050,0,0 -windturbine,R2,2050,0,0 diff --git a/src/muse/data/example/trade/technodata/power/Technodata.csv b/src/muse/data/example/trade/technodata/power/Technodata.csv deleted file mode 100644 index 61e971df9..000000000 --- a/src/muse/data/example/trade/technodata/power/Technodata.csv +++ /dev/null @@ -1,6 +0,0 @@ -ProcessName,RegionName,Time,cap_exp,fix_exp,var_par,var_exp,TechnicalLife,UtilizationFactor,ScalingSize,efficiency,InterestRate,Type,Fuel,EndUse,AgentShare -Unit,-,Year,-,-,MUS$2010/PJ,-,Years,-,PJ,%,-,-,-,-, -gasCCGT,R1,2010,1,1,0,1,35,0.9,0.00000189,86,0.1,energy,gas,electricity,1 -windturbine,R1,2010,1,1,0,1,25,0.4,0.00000189,86,0.1,energy,wind,electricity,1 -gasCCGT,R2,2010,1,1,0,1,35,0.9,0.00000189,86,0.1,energy,gas,electricity,1 -windturbine,R2,2010,1,1,0,1,25,0.4,0.00000189,86,0.1,energy,wind,electricity,1 diff --git a/src/muse/data/example/trade/technodata/power/TradeTechnodata.csv b/src/muse/data/example/trade/technodata/power/TradeTechnodata.csv deleted file mode 100644 index f5af71ccd..000000000 --- a/src/muse/data/example/trade/technodata/power/TradeTechnodata.csv +++ /dev/null @@ -1,21 +0,0 @@ -ProcessName,RegionName,Parameter,Unit,R1,R2 -gasCCGT,R1,cap_par,MUSD/PJ,28.29,56.58 -windturbine,R1,cap_par,MUSD/PJ,43.2,0 -gasCCGT,R2,cap_par,MUSD/PJ,57.08,28.54 -windturbine,R2,cap_par,MUSD/PJ,0,43.57 -gasCCGT,R1,fix_par,MUSD/PJ,2.829,5.658 -windturbine,R1,fix_par,MUSD/PJ,0,0 -gasCCGT,R2,fix_par,MUSD/PJ,5.708,2.854 -windturbine,R2,fix_par,MUSD/PJ,0,0 -gasCCGT,R1,MaxCapacityAddition,PJ/y,393.72188,0 -windturbine,R1,MaxCapacityAddition,PJ/y,393.72188,0 -gasCCGT,R2,MaxCapacityAddition,PJ/y,0,393.72188 -windturbine,R2,MaxCapacityAddition,PJ/y,0,393.72188 -gasCCGT,R1,MaxCapacityGrowth,PJ/y,0.05,0.05 -windturbine,R1,MaxCapacityGrowth,PJ/y,0.05,0 -gasCCGT,R2,MaxCapacityGrowth,PJ/y,0.05,0.05 -windturbine,R2,MaxCapacityGrowth,PJ/y,0,0.05 -gasCCGT,R1,TotalCapacityLimit,PJ/y,3937.2188,0 -windturbine,R1,TotalCapacityLimit,PJ/y,3937.2188,0 -gasCCGT,R2,TotalCapacityLimit,PJ/y,0,3937.2188 -windturbine,R2,TotalCapacityLimit,PJ/y,0,3937.2188 diff --git a/src/muse/data/example/trade/technodata/preset/Residential2020Consumption.csv b/src/muse/data/example/trade/technodata/preset/Residential2020Consumption.csv deleted file mode 100644 index cab86f138..000000000 --- a/src/muse/data/example/trade/technodata/preset/Residential2020Consumption.csv +++ /dev/null @@ -1,13 +0,0 @@ -RegionName,Timeslice,electricity,gas,CO2f,wind,heat -R1,1,0,0,0,0,73 -R1,2,0,0,0,0,103.2 -R1,3,0,0,0,0,77.4 -R1,4,0,0,0,0,77.4 -R1,5,0,0,0,0,111.8 -R1,6,0,0,0,0,77.2 -R2,1,0,0,0,0,2 -R2,2,0,0,0,0,2.2 -R2,3,0,0,0,0,1.8 -R2,4,0,0,0,0,1.8 -R2,5,0,0,0,0,2.3 -R2,6,0,0,0,0,1.8 diff --git a/src/muse/data/example/trade/technodata/preset/Residential2030Consumption.csv b/src/muse/data/example/trade/technodata/preset/Residential2030Consumption.csv deleted file mode 100644 index b77f0f46b..000000000 --- a/src/muse/data/example/trade/technodata/preset/Residential2030Consumption.csv +++ /dev/null @@ -1,13 +0,0 @@ -RegionName,Timeslice,electricity,gas,CO2f,wind,heat -R1,1,0,0,0,0,87.6 -R1,2,0,0,0,0,123.84 -R1,3,0,0,0,0,92.88 -R1,4,0,0,0,0,92.88 -R1,5,0,0,0,0,134.16 -R1,6,0,0,0,0,92.64 -R2,1,0,0,0,0,2.4 -R2,2,0,0,0,0,2.64 -R2,3,0,0,0,0,2.16 -R2,4,0,0,0,0,2.16 -R2,5,0,0,0,0,2.76 -R2,6,0,0,0,0,2.16 diff --git a/src/muse/data/example/trade/technodata/preset/Residential2050Consumption.csv b/src/muse/data/example/trade/technodata/preset/Residential2050Consumption.csv deleted file mode 100644 index 9341b4292..000000000 --- a/src/muse/data/example/trade/technodata/preset/Residential2050Consumption.csv +++ /dev/null @@ -1,13 +0,0 @@ -RegionName,Timeslice,electricity,gas,CO2f,wind,heat -R1,1,0,0,0,0,94.9 -R1,2,0,0,0,0,134.16 -R1,3,0,0,0,0,100.62 -R1,4,0,0,0,0,100.62 -R1,5,0,0,0,0,145.34 -R1,6,0,0,0,0,100.36 -R2,1,0,0,0,0,2.6 -R2,2,0,0,0,0,2.86 -R2,3,0,0,0,0,2.34 -R2,4,0,0,0,0,2.34 -R2,5,0,0,0,0,2.99 -R2,6,0,0,0,0,2.34 diff --git a/src/muse/data/example/trade/technodata/residential/Agents.csv b/src/muse/data/example/trade/technodata/residential/Agents.csv deleted file mode 100644 index 520b667ae..000000000 --- a/src/muse/data/example/trade/technodata/residential/Agents.csv +++ /dev/null @@ -1,5 +0,0 @@ -AgentShare,Name,RegionName,Objective1,Objective2,Objective3,ObjData1,ObjData2,ObjData3,Objsort1,Objsort2,Objsort3,SearchRule,DecisionMethod,Quantity,MaturityThreshold,Budget,Type -agent_share_1,A1,R1,LCOE,,,1,,,TRUE,,,all,singleObj,1,-1,inf,New -agent_share_2,A1,R1,LCOE,,,1,,,TRUE,,,all,singleObj,1,-1,inf,Retrofit -agent_share_1,A1,R2,LCOE,,,1,,,TRUE,,,all,singleObj,1,-1,inf,New -agent_share_2,A1,R2,LCOE,,,1,,,TRUE,,,all,singleObj,1,-1,inf,Retrofit diff --git a/src/muse/data/example/trade/technodata/residential/CommIn.csv b/src/muse/data/example/trade/technodata/residential/CommIn.csv deleted file mode 100644 index 67f0e4fde..000000000 --- a/src/muse/data/example/trade/technodata/residential/CommIn.csv +++ /dev/null @@ -1,6 +0,0 @@ -ProcessName,RegionName,Time,Level,electricity,gas,heat,CO2f,wind -Unit,-,Year,-,PJ/PJ,PJ/PJ,PJ/PJ,kt/PJ,PJ/PJ -gasboiler,R1,2010,fixed,0,1.162790698,0,0,0 -heatpump,R1,2010,fixed,0.4,0,0,0,0 -gasboiler,R2,2010,fixed,0,1.395348838,0,0,0 -heatpump,R2,2010,fixed,0.48,0,0,0,0 diff --git a/src/muse/data/example/trade/technodata/residential/CommOut.csv b/src/muse/data/example/trade/technodata/residential/CommOut.csv deleted file mode 100644 index 93c208776..000000000 --- a/src/muse/data/example/trade/technodata/residential/CommOut.csv +++ /dev/null @@ -1,6 +0,0 @@ -ProcessName,RegionName,Time,electricity,gas,heat,CO2f,wind -Unit,-,Year,PJ/PJ,PJ/PJ,PJ/PJ,kt/PJ,PJ/PJ -gasboiler,R1,2010,0,0,1,64.70588235,0 -heatpump,R1,2010,0,0,1,0,0 -gasboiler,R2,2010,0,0,1,77.64705882,0 -heatpump,R2,2010,0,0,1,0,0 diff --git a/src/muse/data/example/trade/technodata/residential/ExistingCapacity.csv b/src/muse/data/example/trade/technodata/residential/ExistingCapacity.csv deleted file mode 100644 index 8fc854a9c..000000000 --- a/src/muse/data/example/trade/technodata/residential/ExistingCapacity.csv +++ /dev/null @@ -1,5 +0,0 @@ -ProcessName,RegionName,Unit,2010,2020,2030,2040,2050 -gasboiler,R1,PJ/y,946.8,662.76,463.932,324.7524,227.32668 -heatpump,R1,PJ/y,0,0,0,0,0 -gasboiler,R2,PJ/y,50,35,24.5,17.15,12.005 -heatpump,R2,PJ/y,0,0,0,0,0 diff --git a/src/muse/data/example/trade/technodata/residential/Technodata.csv b/src/muse/data/example/trade/technodata/residential/Technodata.csv deleted file mode 100644 index 9dc35cdc7..000000000 --- a/src/muse/data/example/trade/technodata/residential/Technodata.csv +++ /dev/null @@ -1,6 +0,0 @@ -ProcessName,RegionName,Time,cap_par,cap_exp,fix_par,fix_exp,var_par,var_exp,MaxCapacityAddition,MaxCapacityGrowth,TotalCapacityLimit,TechnicalLife,UtilizationFactor,ScalingSize,efficiency,InterestRate,Type,Fuel,EndUse,Agent2 -Unit,-,Year,MUS$2010/PJ_a,-,MUS$2010/PJ,-,MUS$2010/PJ,-,PJ,-,PJ,Years,-,PJ,%,-,-,-,-,Retrofit -gasboiler,R1,2010,4.52,1,0,1,0,1,600,0.2,2000,10,0.9,0.00000189,86,0.1,energy,gas,heat,1 -heatpump,R1,2010,10.55,1,0,1,0,1,600,0.2,2000,10,0.9,0.00000189,86,0.1,energy,electricity,heat,1 -gasboiler,R2,2010,4.94,1,0,1,0,1,600,0.2,2000,10,0.9,0.00000189,86,0.1,energy,gas,heat,1 -heatpump,R2,2010,11.53,1,0,1,0,1,600,0.2,2000,10,0.9,0.00000189,86,0.1,energy,electricity,heat,1 diff --git a/src/muse/examples.py b/src/muse/examples.py index 1d6d1d774..cbfbe67ac 100644 --- a/src/muse/examples.py +++ b/src/muse/examples.py @@ -122,8 +122,6 @@ def copy_model( _copy_multiple_agents(path) elif name.lower() == "minimum_service": _copy_minimum_service(path) - elif name.lower() == "trade": - _copy_trade(path) return path @@ -373,11 +371,3 @@ def _copy_minimum_service(path: Path): copyfile( example_data_dir() / "minimum_service" / "settings.toml", path / "settings.toml" ) - - -def _copy_trade(path: Path): - from shutil import copyfile, copytree - - copytree(example_data_dir() / "trade" / "input", path / "input") - copytree(example_data_dir() / "trade" / "technodata", path / "technodata") - copyfile(example_data_dir() / "trade" / "settings.toml", path / "settings.toml") From dd83f1fac3b1d49e305fcc34f7604db1d57fc3b1 Mon Sep 17 00:00:00 2001 From: Tom Bland Date: Mon, 4 Nov 2024 15:38:46 +0000 Subject: [PATCH 6/7] Simplify capacity property --- src/muse/sectors/sector.py | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/src/muse/sectors/sector.py b/src/muse/sectors/sector.py index 95a810a95..43bf371e5 100644 --- a/src/muse/sectors/sector.py +++ b/src/muse/sectors/sector.py @@ -277,17 +277,10 @@ def capacity(self) -> xr.DataArray: """ from muse.utilities import filter_input, reduce_assets - nontraded = [u.assets.capacity for u in self.agents] - - full_list = [ - list(nontraded[i].year.values) - for i in range(len(nontraded)) - if "year" in nontraded[i].dims - ] - flat_list = [item for sublist in full_list for item in sublist] - years = sorted(list(set(flat_list))) - nontraded = [filter_input(u.assets.capacity, year=years) for u in self.agents] - return reduce_assets(nontraded) + capacities = [u.assets.capacity for u in self.agents] + all_years = sorted({year for capa in capacities for year in capa.year.values}) + capacities = [filter_input(capa, year=all_years) for capa in capacities] + return reduce_assets(capacities) @property def agents(self) -> Iterator[AbstractAgent]: From d66eadaea88fffb4a81d7f2081f6fcbc132afab7 Mon Sep 17 00:00:00 2001 From: Tom Bland Date: Mon, 27 Jan 2025 13:06:36 +0000 Subject: [PATCH 7/7] Fix merge mistake --- src/muse/sectors/sector.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/muse/sectors/sector.py b/src/muse/sectors/sector.py index 1ad04e52d..cb277bbcb 100644 --- a/src/muse/sectors/sector.py +++ b/src/muse/sectors/sector.py @@ -246,7 +246,6 @@ def group_assets(x: xr.DataArray) -> xr.DataArray: ) result = output_data.copy(deep=True) - result = self.convert_market_timeslice(result, mca_market.timeslice) result["comm_usage"] = self.technologies.comm_usage.sel( commodity=result.commodity )