Skip to content

Commit 1b5072b

Browse files
committed
Get outputs for first year
1 parent 872b04b commit 1b5072b

4 files changed

Lines changed: 47 additions & 26 deletions

File tree

src/muse/mca.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,9 @@ def run(self) -> None:
306306
# Save sector outputs
307307
for sector in self.sectors:
308308
if type(sector) is Sector:
309-
sector.save_outputs()
309+
if year_idx == 0:
310+
sector.save_outputs(years[0])
311+
sector.save_outputs(years[1])
310312

311313
# If we need to account for the carbon budget, we might need to change
312314
# the budget for the future, too.
@@ -324,6 +326,10 @@ def run(self) -> None:
324326
self.market.prices.sel(dims), new_market.prices.sel(year=years[1])
325327
)
326328

329+
if year_idx == 0:
330+
# Necessary to get global outputs for the first year of the framework
331+
self.outputs(self.market, self.sectors, year=years[0])
332+
327333
# Global outputs
328334
investment_year = years[1]
329335
self.outputs(self.market, self.sectors, year=investment_year)

src/muse/outputs/mca.py

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
@register_output_quantity
99
def quantity(
1010
sectors: List[AbstractSector],
11-
market: xr.Dataset, **kwargs
11+
market: xr.Dataset,
12+
year: int,
13+
**kwargs
1214
) -> Union[pd.DataFrame, xr.DataArray]:
1315
pass
1416
@@ -76,9 +78,13 @@ def round_values(function: Callable) -> OUTPUT_QUANTITY_SIGNATURE:
7678

7779
@wraps(function)
7880
def rounded(
79-
market: xr.Dataset, sectors: list[AbstractSector], rounding: int = 4, **kwargs
81+
market: xr.Dataset,
82+
sectors: list[AbstractSector],
83+
year: int,
84+
rounding: int = 4,
85+
**kwargs,
8086
) -> xr.DataArray:
81-
result = function(market, sectors, **kwargs)
87+
result = function(market=market, sectors=sectors, year=year, **kwargs)
8288

8389
if hasattr(result, "to_dataframe"):
8490
result = result.to_dataframe()
@@ -150,15 +156,17 @@ def reformat_finite_resources(params):
150156
@register_output_quantity
151157
@round_values
152158
def consumption(
153-
market: xr.Dataset, sectors: list[AbstractSector], **kwargs
159+
market: xr.Dataset, sectors: list[AbstractSector], year: int, **kwargs
154160
) -> pd.DataFrame:
155161
"""Current consumption."""
156162
return market_quantity(market.consumption, **kwargs).to_dataframe().reset_index()
157163

158164

159165
@register_output_quantity
160166
@round_values
161-
def supply(market: xr.Dataset, sectors: list[AbstractSector], **kwargs) -> pd.DataFrame:
167+
def supply(
168+
market: xr.Dataset, sectors: list[AbstractSector], year: int, **kwargs
169+
) -> pd.DataFrame:
162170
"""Current supply."""
163171
return market_quantity(market.supply, **kwargs).to_dataframe().reset_index()
164172

@@ -168,6 +176,7 @@ def supply(market: xr.Dataset, sectors: list[AbstractSector], **kwargs) -> pd.Da
168176
def prices(
169177
market: xr.Dataset,
170178
sectors: list[AbstractSector],
179+
year: int,
171180
**kwargs,
172181
) -> pd.DataFrame:
173182
"""Current MCA market prices."""
@@ -177,7 +186,7 @@ def prices(
177186
@register_output_quantity
178187
@round_values
179188
def capacity(
180-
market: xr.Dataset, sectors: list[AbstractSector], **kwargs
189+
market: xr.Dataset, sectors: list[AbstractSector], year: int, **kwargs
181190
) -> pd.DataFrame:
182191
"""Current capacity across all sectors."""
183192
return _aggregate_sectors(sectors, op=sector_capacity)
@@ -236,14 +245,14 @@ def _aggregate_sectors(
236245

237246
@register_output_quantity(name=["fuel_costs"])
238247
def metric_fuel_costs(
239-
market: xr.Dataset, sectors: list[AbstractSector], **kwargs
248+
market: xr.Dataset, sectors: list[AbstractSector], year: int, **kwargs
240249
) -> pd.DataFrame:
241250
"""Current fuel costs across all sectors."""
242-
return _aggregate_sectors(sectors, market, op=sector_fuel_costs)
251+
return _aggregate_sectors(sectors, market, year, op=sector_fuel_costs)
243252

244253

245254
def sector_fuel_costs(
246-
sector: AbstractSector, market: xr.Dataset, **kwargs
255+
sector: AbstractSector, market: xr.Dataset, year: int, **kwargs
247256
) -> pd.DataFrame:
248257
"""Sector fuel costs with agent annotations."""
249258
from muse.commodities import is_fuel
@@ -299,14 +308,14 @@ def sector_fuel_costs(
299308

300309
@register_output_quantity(name=["capital_costs"])
301310
def metric_capital_costs(
302-
market: xr.Dataset, sectors: list[AbstractSector], **kwargs
311+
market: xr.Dataset, sectors: list[AbstractSector], year: int, **kwargs
303312
) -> pd.DataFrame:
304313
"""Current capital costs across all sectors."""
305-
return _aggregate_sectors(sectors, market, op=sector_capital_costs)
314+
return _aggregate_sectors(sectors, market, year, op=sector_capital_costs)
306315

307316

308317
def sector_capital_costs(
309-
sector: AbstractSector, market: xr.Dataset, **kwargs
318+
sector: AbstractSector, market: xr.Dataset, year: int, **kwargs
310319
) -> pd.DataFrame:
311320
"""Sector capital costs with agent annotations."""
312321
data_sector: list[xr.DataArray] = []
@@ -342,14 +351,14 @@ def sector_capital_costs(
342351

343352
@register_output_quantity(name=["emission_costs"])
344353
def metric_emission_costs(
345-
market: xr.Dataset, sectors: list[AbstractSector], **kwargs
354+
market: xr.Dataset, sectors: list[AbstractSector], year: int, **kwargs
346355
) -> pd.DataFrame:
347356
"""Current emission costs across all sectors."""
348-
return _aggregate_sectors(sectors, market, op=sector_emission_costs)
357+
return _aggregate_sectors(sectors, market, year, op=sector_emission_costs)
349358

350359

351360
def sector_emission_costs(
352-
sector: AbstractSector, market: xr.Dataset, **kwargs
361+
sector: AbstractSector, market: xr.Dataset, year: int, **kwargs
353362
) -> pd.DataFrame:
354363
"""Sector emission costs with agent annotations."""
355364
from muse.commodities import is_enduse, is_pollutant
@@ -407,13 +416,15 @@ def sector_emission_costs(
407416

408417
@register_output_quantity(name=["LCOE"])
409418
def metric_lcoe(
410-
market: xr.Dataset, sectors: list[AbstractSector], **kwargs
419+
market: xr.Dataset, sectors: list[AbstractSector], year: int, **kwargs
411420
) -> pd.DataFrame:
412421
"""Current lifetime levelised cost across all sectors."""
413-
return _aggregate_sectors(sectors, market, op=sector_lcoe)
422+
return _aggregate_sectors(sectors, market, year, op=sector_lcoe)
414423

415424

416-
def sector_lcoe(sector: AbstractSector, market: xr.Dataset, **kwargs) -> pd.DataFrame:
425+
def sector_lcoe(
426+
sector: AbstractSector, market: xr.Dataset, year: int, **kwargs
427+
) -> pd.DataFrame:
417428
"""Levelized cost of energy () of technologies over their lifetime."""
418429
from muse.costs import levelized_cost_of_energy as LCOE
419430
from muse.quantities import capacity_to_service_demand, consumption
@@ -490,13 +501,15 @@ def sector_lcoe(sector: AbstractSector, market: xr.Dataset, **kwargs) -> pd.Data
490501

491502
@register_output_quantity(name=["EAC"])
492503
def metric_eac(
493-
market: xr.Dataset, sectors: list[AbstractSector], **kwargs
504+
market: xr.Dataset, sectors: list[AbstractSector], year: int, **kwargs
494505
) -> pd.DataFrame:
495506
"""Current emission costs across all sectors."""
496-
return _aggregate_sectors(sectors, market, op=sector_eac)
507+
return _aggregate_sectors(sectors, market, year, op=sector_eac)
497508

498509

499-
def sector_eac(sector: AbstractSector, market: xr.Dataset, **kwargs) -> pd.DataFrame:
510+
def sector_eac(
511+
sector: AbstractSector, market: xr.Dataset, year: int, **kwargs
512+
) -> pd.DataFrame:
500513
"""Net Present Value of technologies over their lifetime."""
501514
from muse.costs import equivalent_annual_cost as EAC
502515
from muse.quantities import capacity_to_service_demand, consumption

src/muse/outputs/sector.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def save_multiple_outputs(market, *args, year: int | None = None) -> list[Any]:
107107
year = int(market.year.max())
108108

109109
return [
110-
sink(quantity(market, *args), year=year)
110+
sink(quantity(market, *args, year=year), year=year)
111111
for quantity, sink in zip(quantities, sinks)
112112
]
113113

@@ -182,6 +182,7 @@ def consumption(
182182
sum_over: list[str] | None = None,
183183
drop: list[str] | None = None,
184184
rounding: int = 4,
185+
**kwargs,
185186
) -> xr.DataArray:
186187
"""Current consumption."""
187188
moutput = market.copy(deep=True).reset_index("timeslice")
@@ -202,6 +203,7 @@ def supply(
202203
sum_over: list[str] | None = None,
203204
drop: list[str] | None = None,
204205
rounding: int = 4,
206+
**kwargs,
205207
) -> xr.DataArray:
206208
"""Current supply."""
207209
moutput = market.copy(deep=True).reset_index("timeslice")
@@ -222,6 +224,7 @@ def costs(
222224
sum_over: list[str] | None = None,
223225
drop: list[str] | None = None,
224226
rounding: int = 4,
227+
**kwargs,
225228
) -> xr.DataArray:
226229
"""Current costs."""
227230
from muse.commodities import is_pollutant

src/muse/sectors/sector.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,10 +281,9 @@ def group_assets(x: xr.DataArray) -> xr.DataArray:
281281
# Convert result to global timeslicing scheme
282282
return self.convert_to_global_timeslicing(result)
283283

284-
def save_outputs(self) -> None:
284+
def save_outputs(self, year: int) -> None:
285285
"""Calls the outputs function with the current output data."""
286-
investment_year = self.output_data.year.values[1]
287-
self.outputs(self.output_data, self.capacity, year=investment_year)
286+
self.outputs(self.output_data, self.capacity, year=year)
288287

289288
def market_variables(self, market: xr.Dataset, technologies: xr.Dataset) -> Any:
290289
"""Computes resulting market: production, consumption, and costs."""

0 commit comments

Comments
 (0)