diff --git a/src/muse/agents/agent.py b/src/muse/agents/agent.py index eddc6600e..caf65a172 100644 --- a/src/muse/agents/agent.py +++ b/src/muse/agents/agent.py @@ -475,8 +475,6 @@ def retirement_profile( lifetime, investment_year=investment_year, ) - 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 7fcde0a9b..15b2c4249 100644 --- a/src/muse/agents/factories.py +++ b/src/muse/agents/factories.py @@ -193,10 +193,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 ff297175f..c01fff309 100644 --- a/src/muse/constraints.py +++ b/src/muse/constraints.py @@ -362,9 +362,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), @@ -385,8 +382,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 technologies.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) @@ -451,18 +446,6 @@ def max_production( capa = capa.expand_dims(asset=search_space.asset) production = ones_like(capa) b = zeros_like(production) - # Include maxaddition constraint in max production to match region-dst_region - if "dst_region" in technologies.dims: - b = b.expand_dims(dst_region=technologies.dst_region) - capa = capa.rename(region="src_region") - production = production.rename(region="src_region") - maxadd = technologies.max_capacity_addition.rename(region="src_region") - maxadd = maxadd.rename(technology="replacement") - maxadd = maxadd.where(maxadd == 0, 0.0) - maxadd = maxadd.where(maxadd > 0, -1.0) - capa = capa * broadcast_timeslice(maxadd, level=timeslice_level) - production = production * broadcast_timeslice(maxadd, level=timeslice_level) - b = b.rename(region="src_region") return xr.Dataset( dict(capacity=-cast(np.ndarray, capa), production=production, b=b), attrs=dict(kind=ConstraintKind.UPPER_BOUND), 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 a812ea926..000000000 --- a/src/muse/data/example/trade/settings.toml +++ /dev/null @@ -1,128 +0,0 @@ -# Global settings - most REQUIRED - -time_framework = [2020, 2025, 2030, 2035] -regions = ["R1", "R2"] -interest_rate = 0.1 -interpolation_mode = 'linear' -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" -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" -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" -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 99ceb6088..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 -Agent1,A1,R1,ALCOE,1,TRUE,from_assets->compress->reduce_assets,singleObj,-1,inf,default -Agent1,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 4f5d9a0f6..000000000 --- a/src/muse/data/example/trade/technodata/gas/CommIn.csv +++ /dev/null @@ -1,4 +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 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 fb71f05e2..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,Agent1 -Unit,-,Year,MUS$2010/PJ,-,Years,-,PJ,%,-,-,-,-,New -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 e587dc93d..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,Agent1 -Unit,-,Year,-,-,MUS$2010/PJ,-,Years,-,PJ,%,-,-,-,-,New -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 7bfc25298..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 -Agent1,A1,R1,LCOE,,,1,,,TRUE,,,all,singleObj,1,-1,inf,New -Agent2,A1,R1,LCOE,,,1,,,TRUE,,,all,singleObj,1,-1,inf,Retrofit -Agent1,A1,R2,LCOE,,,1,,,TRUE,,,all,singleObj,1,-1,inf,New -Agent2,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/demand_share.py b/src/muse/demand_share.py index 28bca4c7a..38e9f364e 100644 --- a/src/muse/demand_share.py +++ b/src/muse/demand_share.py @@ -614,9 +614,7 @@ def unmet_demand( ) # 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 3aa3e2878..25dc2588c 100644 --- a/src/muse/examples.py +++ b/src/muse/examples.py @@ -132,8 +132,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 @@ -160,9 +158,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: @@ -273,21 +276,15 @@ def matching_market(sector: str, model: str = "default") -> xr.Dataset: techs = broadcast_over_assets(loaded_sector.technologies, assets.capacity) production = maximum_production(techs, 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(techs, 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(techs, production).sum( - {"asset", "dst_region"}.intersection(market.dims) - ) + consumption(techs, production).sum({"asset"}.intersection(market.dims)) + market.supply ) market["prices"] = market.supply.dims, np.random.random(market.supply.shape) @@ -394,48 +391,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") - - -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 1d521c1ce..290d5b7b6 100644 --- a/src/muse/objectives.py +++ b/src/muse/objectives.py @@ -408,8 +408,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/src/muse/outputs/cache.py b/src/muse/outputs/cache.py index 5f77aa706..f43db82c8 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.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 fa38b2d3c..da97ce62f 100644 --- a/src/muse/outputs/mca.py +++ b/src/muse/outputs/mca.py @@ -203,14 +203,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/readers/csv.py b/src/muse/readers/csv.py index 9e6818638..7892c0b5c 100644 --- a/src/muse/readers/csv.py +++ b/src/muse/readers/csv.py @@ -227,12 +227,7 @@ def read_io_technodata(filename: str | Path) -> xr.Dataset: def read_initial_assets(filename: 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 @@ -808,66 +803,6 @@ def expand_paths(path): return result -def read_trade( - data: pd.DataFrame | str | Path, - columns_are_source: bool = True, - parameters: str | None = None, - skiprows: Sequence[int] | None = None, - name: str | None = None, - drop: str | Sequence[str] | None = None, -) -> 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: 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 check_utilization_and_minimum_service_factors( data: pd.DataFrame, filename: str | list[str] ) -> None: diff --git a/src/muse/readers/toml.py b/src/muse/readers/toml.py index 2f88e892f..6643687b0 100644 --- a/src/muse/readers/toml.py +++ b/src/muse/readers/toml.py @@ -661,7 +661,7 @@ def read_technodata( interpolation_mode: str = "linear", ) -> 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]) @@ -720,17 +720,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 = 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 + data = value if isinstance(data, xr.Dataset): technologies = technologies.merge(data) else: diff --git a/src/muse/sectors/sector.py b/src/muse/sectors/sector.py index 00d2532a1..bde5920be 100644 --- a/src/muse/sectors/sector.py +++ b/src/muse/sectors/sector.py @@ -236,34 +236,6 @@ 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["comm_usage"] = self.technologies.comm_usage.sel( commodity=result.commodity ) @@ -358,65 +330,10 @@ def capacity(self) -> xr.DataArray: """ from muse.utilities import interpolate_capacity, 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 - ] - - # 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))) - capacity = reduce_assets( - [ - u.assets.capacity - for u in self.agents - if "dst_region" not in u.assets.capacity.dims - ] - ) - return interpolate_capacity(capacity, year=years) - - # 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))) - capacity = reduce_assets( - [ - u.assets.capacity - for u in self.agents - if "dst_region" in u.assets.capacity.dims - ] - ) - return interpolate_capacity(capacity, year=years) - - # Both traded and nontraded assets - else: - traded_results = reduce_assets(traded) - nontraded_results = reduce_assets(nontraded) - capacity = reduce_assets( - [ - traded_results, - nontraded_results - * (nontraded_results.region == traded_results.dst_region), - ] - ) - return interpolate_capacity(capacity, year=years) + capacities = [u.assets.capacity for u in self.agents] + all_years = sorted({year for capa in capacities for year in capa.year.values}) + capacity = reduce_assets(capacities) + return interpolate_capacity(capacity, year=all_years) @property def agents(self) -> Iterator[AbstractAgent]: diff --git a/src/muse/sectors/subsector.py b/src/muse/sectors/subsector.py index 266e54a77..45bda1b37 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: @@ -24,7 +23,6 @@ def __init__( constraints: Callable | None = None, investment: Callable | None = None, name: str = "subsector", - expand_market_prices: bool = False, timeslice_level: str | None = None, ): from muse import constraints as cs @@ -37,14 +35,7 @@ def __init__( self.constraints = constraints or cs.factory() self.investment = investment or iv.factory() self.name = name - self.expand_market_prices = expand_market_prices self.timeslice_level = timeslice_level - """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, @@ -54,13 +45,6 @@ def invest( assert "year" not in technologies.dims assert len(market.year) == 2 - # 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() @@ -84,14 +68,6 @@ def aggregate_lp( timeslice_level=self.timeslice_level, ) - 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) - # Increment each agent (perform investments) for agent in self.agents: if "agent" in demands.coords: @@ -115,7 +91,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 @@ -187,12 +163,6 @@ def factory( # only used by non-self-investing agents investment = iv.factory(getattr(settings, "lpsolver", "scipy")) - 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, @@ -200,7 +170,6 @@ def factory( constraints=constraints, investment=investment, name=name, - expand_market_prices=expand_market_prices, timeslice_level=timeslice_level, ) diff --git a/tests/test_agents.py b/tests/test_agents.py index 6c6b96896..be97e7996 100644 --- a/tests/test_agents.py +++ b/tests/test_agents.py @@ -200,7 +200,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 ( @@ -209,6 +208,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 9a8105786..337f517bf 100644 --- a/tests/test_outputs.py +++ b/tests/test_outputs.py @@ -479,14 +479,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_readers.py b/tests/test_readers.py index ec00d1726..e5ed1c7fe 100644 --- a/tests/test_readers.py +++ b/tests/test_readers.py @@ -343,48 +343,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 diff --git a/tests/test_subsector.py b/tests/test_subsector.py index f0162b8ad..fd11ac060 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" diff --git a/tests/test_trade.py b/tests/test_trade.py deleted file mode 100644 index 3db85642f..000000000 --- a/tests/test_trade.py +++ /dev/null @@ -1,148 +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 = agent_concatenation({u.uuid: u.assets for u in list(power.agents)}) - capacity = reduce_assets(assets.capacity, coords=("region", "technology")) - return dict( - demand=market.consumption.sel(year=2025, drop=True), - capacity=capacity.sel(year=[2020, 2025]), - search_space=search_space, - market=market, - technologies=power.technologies.sel(year=2025, drop=True), - ) - - -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 set(constraint.agent.coords) == {"region", "agent"} - - -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", "agent", "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 set(constraint.agent.coords) == {"region", "agent"} - - -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]) - - 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]) - 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=2025).sum() < 1 - assert "dst_region" not in result.dims