Skip to content

Commit 0e3ca6d

Browse files
committed
Tidy outputs module
1 parent 9e80ec1 commit 0e3ca6d

File tree

1 file changed

+24
-31
lines changed

1 file changed

+24
-31
lines changed

src/muse/outputs/mca.py

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -257,15 +257,14 @@ def sector_fuel_costs(
257257
agent_market = market.copy()
258258
if len(technologies) > 0:
259259
for a in agents:
260-
output_year = a.year
261260
agent_market["consumption"] = (market.consumption * a.quantity).sel(
262-
year=output_year
261+
year=a.year
263262
)
264263
commodity = is_fuel(technologies.comm_usage)
265264

266265
capacity = a.filter_input(
267266
a.assets.capacity,
268-
year=output_year,
267+
year=a.year,
269268
).fillna(0.0)
270269

271270
production = supply(
@@ -274,7 +273,7 @@ def sector_fuel_costs(
274273
technologies,
275274
)
276275

277-
prices = a.filter_input(market.prices, year=output_year)
276+
prices = a.filter_input(market.prices, year=a.year)
278277
fcons = consumption(
279278
technologies=technologies, production=production, prices=prices
280279
)
@@ -283,7 +282,7 @@ def sector_fuel_costs(
283282
data_agent["agent"] = a.name
284283
data_agent["category"] = a.category
285284
data_agent["sector"] = getattr(sector, "name", "unnamed")
286-
data_agent["year"] = output_year
285+
data_agent["year"] = a.year
287286
data_agent = multiindex_to_coords(data_agent, "timeslice").to_dataframe(
288287
"fuel_consumption_costs"
289288
)
@@ -315,18 +314,17 @@ def sector_capital_costs(
315314

316315
if len(technologies) > 0:
317316
for a in agents:
318-
output_year = a.year
319-
capacity = a.filter_input(a.assets.capacity, year=output_year).fillna(0.0)
317+
capacity = a.filter_input(a.assets.capacity, year=a.year).fillna(0.0)
320318
data = a.filter_input(
321319
technologies[["cap_par", "cap_exp"]],
322-
year=output_year,
320+
year=a.year,
323321
technology=capacity.technology,
324322
)
325323
data_agent = distribute_timeslice(data.cap_par * (capacity**data.cap_exp))
326324
data_agent["agent"] = a.name
327325
data_agent["category"] = a.category
328326
data_agent["sector"] = getattr(sector, "name", "unnamed")
329-
data_agent["year"] = output_year
327+
data_agent["year"] = a.year
330328
data_agent = multiindex_to_coords(data_agent, "timeslice").to_dataframe(
331329
"capital_costs"
332330
)
@@ -362,23 +360,22 @@ def sector_emission_costs(
362360
agent_market = market.copy()
363361
if len(technologies) > 0:
364362
for a in agents:
365-
output_year = a.year
366363
agent_market["consumption"] = (market.consumption * a.quantity).sel(
367-
year=output_year
364+
year=a.year
368365
)
369366

370-
capacity = a.filter_input(a.assets.capacity, year=output_year).fillna(0.0)
367+
capacity = a.filter_input(a.assets.capacity, year=a.year).fillna(0.0)
371368
allemissions = a.filter_input(
372369
technologies.fixed_outputs,
373370
commodity=is_pollutant(technologies.comm_usage),
374371
technology=capacity.technology,
375-
year=output_year,
372+
year=a.year,
376373
)
377374
envs = is_pollutant(technologies.comm_usage)
378375
enduses = is_enduse(technologies.comm_usage)
379376
i = (np.where(envs))[0][0]
380377
red_envs = envs[i].commodity.values
381-
prices = a.filter_input(market.prices, year=output_year, commodity=red_envs)
378+
prices = a.filter_input(market.prices, year=a.year, commodity=red_envs)
382379
production = supply(
383380
agent_market,
384381
capacity,
@@ -390,7 +387,7 @@ def sector_emission_costs(
390387
data_agent["agent"] = a.name
391388
data_agent["category"] = a.category
392389
data_agent["sector"] = getattr(sector, "name", "unnamed")
393-
data_agent["year"] = output_year
390+
data_agent["year"] = a.year
394391
data_agent = multiindex_to_coords(data_agent, "timeslice").to_dataframe(
395392
"emission_costs"
396393
)
@@ -427,8 +424,7 @@ def sector_lcoe(sector: AbstractSector, market: xr.Dataset, **kwargs) -> pd.Data
427424
agents = retro if len(retro) > 0 else new
428425
if len(technologies) > 0:
429426
for agent in agents:
430-
output_year = agent.year
431-
agent_market = market.sel(year=output_year).copy()
427+
agent_market = market.sel(year=agent.year).copy()
432428
agent_market["consumption"] = agent_market.consumption * agent.quantity
433429
included = [
434430
i
@@ -439,16 +435,15 @@ def sector_lcoe(sector: AbstractSector, market: xr.Dataset, **kwargs) -> pd.Data
439435
i for i in agent_market["commodity"].values if i not in included
440436
]
441437
agent_market.loc[dict(commodity=excluded)] = 0
442-
years = [output_year, agent.year]
443-
agent_market["prices"] = agent.filter_input(market["prices"], year=years)
438+
agent_market["prices"] = agent.filter_input(
439+
market["prices"], year=agent.year
440+
)
444441

445442
techs = agent.filter_input(
446443
technologies,
447444
year=agent.year,
448445
)
449-
prices = agent_market["prices"].sel(
450-
commodity=techs.commodity, year=agent.year
451-
)
446+
prices = agent_market["prices"].sel(commodity=techs.commodity)
452447
demand = agent_market.consumption.sel(commodity=included)
453448
capacity = agent.filter_input(capacity_to_service_demand(demand, techs))
454449
production = (
@@ -473,7 +468,7 @@ def sector_lcoe(sector: AbstractSector, market: xr.Dataset, **kwargs) -> pd.Data
473468
data_agent["agent"] = agent.name
474469
data_agent["category"] = agent.category
475470
data_agent["sector"] = getattr(sector, "name", "unnamed")
476-
data_agent["year"] = output_year
471+
data_agent["year"] = agent.year
477472
data_agent = data_agent.fillna(0)
478473
data_agent = multiindex_to_coords(data_agent, "timeslice").to_dataframe(
479474
"LCOE"
@@ -510,8 +505,7 @@ def sector_eac(sector: AbstractSector, market: xr.Dataset, **kwargs) -> pd.DataF
510505
agents = retro if len(retro) > 0 else new
511506
if len(technologies) > 0:
512507
for agent in agents:
513-
output_year = agent.year
514-
agent_market = market.sel(year=output_year).copy()
508+
agent_market = market.sel(year=agent.year).copy()
515509
agent_market["consumption"] = agent_market.consumption * agent.quantity
516510
included = [
517511
i
@@ -522,16 +516,15 @@ def sector_eac(sector: AbstractSector, market: xr.Dataset, **kwargs) -> pd.DataF
522516
i for i in agent_market["commodity"].values if i not in included
523517
]
524518
agent_market.loc[dict(commodity=excluded)] = 0
525-
years = [output_year, agent.year]
526-
agent_market["prices"] = agent.filter_input(market["prices"], year=years)
519+
agent_market["prices"] = agent.filter_input(
520+
market["prices"], year=agent.year
521+
)
527522

528523
techs = agent.filter_input(
529524
technologies,
530525
year=agent.year,
531526
)
532-
prices = agent_market["prices"].sel(
533-
commodity=techs.commodity, year=agent.year
534-
)
527+
prices = agent_market["prices"].sel(commodity=techs.commodity)
535528
demand = agent_market.consumption.sel(commodity=included)
536529
capacity = agent.filter_input(capacity_to_service_demand(demand, techs))
537530
production = (
@@ -555,7 +548,7 @@ def sector_eac(sector: AbstractSector, market: xr.Dataset, **kwargs) -> pd.DataF
555548
data_agent["agent"] = agent.name
556549
data_agent["category"] = agent.category
557550
data_agent["sector"] = getattr(sector, "name", "unnamed")
558-
data_agent["year"] = output_year
551+
data_agent["year"] = agent.year
559552
data_agent = multiindex_to_coords(data_agent, "timeslice").to_dataframe(
560553
"capital_costs"
561554
)

0 commit comments

Comments
 (0)