Skip to content

Commit a90e6bc

Browse files
authored
Merge branch 'develop' into rc2
2 parents 4246210 + 7476604 commit a90e6bc

4 files changed

Lines changed: 16 additions & 25 deletions

File tree

docs/advanced-guide/extending-muse.ipynb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@
9999
"def consumption_zero(\n",
100100
" market: Dataset,\n",
101101
" capacity: DataArray,\n",
102-
" technologies: Dataset,\n",
103102
"):\n",
104103
" \"\"\"Current consumption.\"\"\"\n",
105104
" result = (\n",
@@ -451,7 +450,6 @@
451450
"def consumption_zero( # noqa: F811\n",
452451
" market: Dataset,\n",
453452
" capacity: DataArray,\n",
454-
" technologies: Dataset,\n",
455453
" sum_over: Optional[list[str]] = None,\n",
456454
" drop: Optional[list[str]] = None,\n",
457455
" rounding: int = 4,\n",

src/muse/mca.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
from muse.outputs.cache import OutputCache
1515
from muse.readers import read_initial_market
16-
from muse.sectors import SECTORS_REGISTERED, AbstractSector
16+
from muse.sectors import SECTORS_REGISTERED, AbstractSector, Sector
1717
from muse.timeslices import drop_timeslice
1818
from muse.utilities import future_propagation
1919

@@ -342,6 +342,11 @@ def run(self) -> None:
342342

343343
_, new_market, self.sectors = self.find_equilibrium(new_market)
344344

345+
# Save sector outputs
346+
for sector in self.sectors:
347+
if type(sector) is Sector:
348+
sector.save_outputs()
349+
345350
# If we need to account for the carbon budget, we might need to change
346351
# the budget for the future, too.
347352
if check_carbon_budget and shoots and year_idx < nyear - 2:

src/muse/outputs/sector.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
def quantity(
1010
capacity: xr.DataArray,
1111
market: xr.Dataset,
12-
technologies: xr.Dataset
1312
) -> Union[xr.DataArray, DataFrame]:
1413
pass
1514
@@ -142,7 +141,6 @@ def factory(
142141
def capacity(
143142
market: xr.Dataset,
144143
capacity: xr.DataArray,
145-
technologies: xr.Dataset,
146144
rounding: int = 4,
147145
) -> pd.DataFrame:
148146
"""Current capacity."""
@@ -179,7 +177,6 @@ def market_quantity(
179177
def consumption(
180178
market: xr.Dataset,
181179
capacity: xr.DataArray,
182-
technologies: xr.Dataset,
183180
sum_over: Optional[list[str]] = None,
184181
drop: Optional[list[str]] = None,
185182
rounding: int = 4,
@@ -200,7 +197,6 @@ def consumption(
200197
def supply(
201198
market: xr.Dataset,
202199
capacity: xr.DataArray,
203-
technologies: xr.Dataset,
204200
sum_over: Optional[list[str]] = None,
205201
drop: Optional[list[str]] = None,
206202
rounding: int = 4,
@@ -221,7 +217,6 @@ def supply(
221217
def costs(
222218
market: xr.Dataset,
223219
capacity: xr.DataArray,
224-
technologies: xr.Dataset,
225220
sum_over: Optional[list[str]] = None,
226221
drop: Optional[list[str]] = None,
227222
rounding: int = 4,

src/muse/sectors/sector.py

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ def __init__(
151151
It can be anything registered with
152152
:py:func:`@register_production<muse.production.register_production>`.
153153
"""
154+
self.output_data: xr.Dataset
155+
"""Full supply, consumption and costs data for the most recent year."""
154156

155157
@property
156158
def forecast(self):
@@ -232,29 +234,19 @@ def group_assets(x: xr.DataArray) -> xr.DataArray:
232234
technologies, market, time_period=time_period, current_year=current_year
233235
)
234236

235-
# > output to mca
237+
# Full output data
236238
supply, consume, costs = self.market_variables(market, technologies)
237-
238-
output_data = xr.Dataset(
239+
self.output_data = xr.Dataset(
239240
dict(
240241
supply=supply,
241242
consumption=consume,
242243
costs=costs,
243244
)
244245
)
245246

246-
# < output to mca
247-
self.outputs(output_data, self.capacity, technologies)
248-
247+
# Output data for MCA (aggregated over assets)
249248
if len(supply.region.dims) == 0:
250-
output_data = xr.Dataset(
251-
dict(
252-
supply=supply,
253-
consumption=consume,
254-
costs=costs,
255-
)
256-
)
257-
output_data = output_data.sum("asset")
249+
output_data = self.output_data.sum("asset")
258250
output_data = output_data.expand_dims(region=[output_data.region.values])
259251
else:
260252
output_data = xr.Dataset(
@@ -265,9 +257,7 @@ def group_assets(x: xr.DataArray) -> xr.DataArray:
265257
)
266258
)
267259

268-
# > to mca timeslices
269260
result = output_data.copy(deep=True)
270-
271261
if "dst_region" in result:
272262
exclude = ["dst_region", "commodity", "year", "timeslice"]
273263
prices = market.prices.expand_dims(dst_region=market.prices.region.values)
@@ -299,9 +289,12 @@ def group_assets(x: xr.DataArray) -> xr.DataArray:
299289
result = self.convert_market_timeslice(result, mca_market.timeslice)
300290
result["comm_usage"] = technologies.comm_usage.sel(commodity=result.commodity)
301291
result.set_coords("comm_usage")
302-
# < to mca timeslices
303292
return result
304293

294+
def save_outputs(self) -> None:
295+
"""Calls the outputs function with the current output data."""
296+
self.outputs(self.output_data, self.capacity)
297+
305298
def market_variables(self, market: xr.Dataset, technologies: xr.Dataset) -> Any:
306299
"""Computes resulting market: production, consumption, and costs."""
307300
from muse.commodities import is_pollutant

0 commit comments

Comments
 (0)