muse.sectors package

Submodules

muse.sectors.abstract module

class AbstractSector[source]

Bases: ABC

Abstract base class for sectors.

Sectors are part of type hierarchy with AbstractSector at the apex: all sectors should derive from AbstractSector directly or indirectly.

MUSE only requires two things of a sector. Sector should be instanstiable via a factory() function. And they should be callable via next().

AbstractSector declares an interface with these two functions. Sectors which derive from it will be warned if either method is not implemented.

abstract classmethod factory(name, settings)[source]

Creates class from settings named-tuple.

abstract next(mca_market)[source]

Advance sector by one time period.

muse.sectors.legacy_sector module

This module defines the LegacySector class.

This is needed to interface the new MCA with the old MUSE sectors. It can be deleted once accessing those sectors is no longer needed.

class LegacyMarket(BaseYear: int, EndYear: int, Foresight: numpy.ndarray, TimeFramework: numpy.ndarray, YearlyTimeFramework: numpy.ndarray, NYears: list, GlobalCommoditiesAttributes: numpy.ndarray, CommoditiesBudget: list, macro_drivers: pandas.core.frame.DataFrame, dfRegions: pandas.core.frame.DataFrame, Regions: numpy.ndarray, interpolation_mode: str)[source]

Bases: object

BaseYear
CommoditiesBudget
EndYear
Foresight
GlobalCommoditiesAttributes
NYears
Regions
TimeFramework
YearlyTimeFramework
dfRegions
interpolation_mode
macro_drivers
class LegacySector(name, old_sector, timeslices, commodities, commodity_price, static_trade, regions, time_framework, mode, excess, market_iterative, sectors_dir, output_dir)[source]

Bases: AbstractSector

calibrated

Flag if the sector has gone through the calibration process.

commodities

Commodities for each sector, as well as global commodities.

commodity_price

Initial price of all the commodities.

dims

Order of the input and output dimensions.

excess

Allowed excess of capacity.

classmethod factory(name, settings, **kwargs)[source]

Creates class from settings named-tuple.

property global_commodities

List of all commodities used by the MCA.

inputs(consumption, prices, supply)[source]

Converts xarray to MUSE numpy input arrays.

static load_timeslices_and_aggregation(timeslices, sectors)[source]

Loads all sector timeslices and finds the finest one.

market_iterative

—–> TODO what’s this parameter?

mode

If ‘Calibration’, the sector runs in calibration mode

name

Name of the sector

next(market)[source]

Adapter between the old and the new.

old_sector

Legacy sector method to run the calculation

output_dir

Outputs directory.

outputs(consumption, prices, supply)[source]

Converts MUSE numpy outputs to xarray.

regions

Regions taking part in the simulation.

runprocessmodule(consumption, supplycost, supply, t)[source]
property sector_commodities

List of all commodities used by the Sector.

property sector_timeslices

List of all commodities used by the MCA.

sectors_dir

Sectors directory.

static_trade

Static trade needed for the conversion and supply sectors.

time_framework

Time framework of the complete simulation.

timeslices

Timeslices for sectors and mca.

commodities_idx(sector, comm)[source]

Gets the indices of the commodities involved in the processes of the sector.

Parameters:
  • sector – The old MUSE sector of interest

  • comm – Either “OUT”, “IN” or “NotENV”

Returns:

A list with the indexes

ndarray_to_xarray(years, data, ts, qt, global_commodities, sector_commodities, data_ts, dims, regions)[source]

From ndarray to dataarray.

xarray_to_ndarray(years, xdata, ts, qt, global_commodities, dims, regions)[source]

From dataarray to ndarray.

muse.sectors.preset_sector module

Sector with preset behaviours.

class PresetSector(presets, interpolation_mode='linear', name='preset')[source]

Bases: AbstractSector

Sector with outcomes fixed from the start.

classmethod factory(name, settings)[source]

Constructs a PresetSectors from input data.

interpolation_mode

Interpolation method

name

Name by which to identify a sector

next(mca_market)[source]

Advance sector by one time period.

presets

Market across time and space.

muse.sectors.register module

SECTORS_REGISTERED = {'default': <bound method Sector.factory of <class 'muse.sectors.sector.Sector'>>, 'legacy': <bound method LegacySector.factory of <class 'muse.sectors.legacy_sector.LegacySector'>>, 'preset': <bound method PresetSector.factory of <class 'muse.sectors.preset_sector.PresetSector'>>, 'presets': <bound method PresetSector.factory of <class 'muse.sectors.preset_sector.PresetSector'>>}

Dictionary of sectors.

register_sector(sector_class=None, name=None)[source]

Registers a sector so it is available MUSE-wide.

Example

>>> from muse.sectors import AbstractSector, register_sector
>>> @register_sector(name="MyResidence")
... class ResidentialSector(AbstractSector):
...     pass

muse.sectors.sector module

class Sector(name, technologies, subsectors=[], timeslices=None, technodata_timeslices=None, interactions=None, interpolation='linear', outputs=None, supply_prod=None)[source]

Bases: AbstractSector

Base class for all sectors.

property agents

Iterator over all agents in the sector.

property capacity

Aggregates capacity across agents.

The capacities are aggregated leaving only two dimensions: asset (technology, installation date, region), year.

static convert_market_timeslice(market, timeslice, intensive='prices')[source]

Converts market from one to another timeslice.

classmethod factory(name, settings)[source]

Creates class from settings named-tuple.

property forecast

Maximum forecast horizon across agents.

If no agents with a “forecast” attribute are found, defaults to 5. It cannot be lower than 1 year.

interactions

Interactions between agents.

Called right before computing new investments, this function should manage any interactions between agents, e.g. passing assets from new agents to retro agents, and maket make-up from retro to new.

Defaults to doing nothing.

The function takes the sequence of agents as input, and returns nothing. It is expected to modify the agents in-place.

interpolation

Interpolation method and arguments when computing years.

market_variables(market, technologies)[source]

Computes resulting market: production, consumption, and costs.

name

Name of the sector.

next(mca_market, time_period=None, current_year=None)[source]

Advance sector by one time period.

Parameters:
  • mca_market – Market with demand, supply, and prices.

  • time_period – Length of the time period in the framework. Defaults to the range of mca_market.year.

  • current_year – Current year of the simulation

Returns:

A market containing the supply offered by the sector, it’s attendant consumption of fuels and materials and the associated costs.

outputs

A function for outputting data for post-mortem analysis.

subsectors

Subsectors controlled by this object.

supply_prod

Computes production as used to return the supply to the MCA.

It can be anything registered with @register_production.

technologies

Parameters describing the sector’s technologies.

timeslices

Timeslice at which this sector operates.

If None, it will operate using the timeslice of the input market.

muse.sectors.subsector module

class Subsector(agents, commodities, demand_share=None, constraints=None, investment=None, name='subsector', forecast=5, expand_market_prices=False)[source]

Bases: object

Agent group servicing a subset of the sectorial commodities.

aggregate_lp(technologies, market, time_period=5, current_year=None)[source]
assign_back_to_agents(technologies, solution, current_year, time_period)[source]
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.

classmethod factory(settings, technologies, regions=None, current_year=None, name='subsector')[source]
invest(technologies, market, time_period=5, current_year=None)[source]
aggregate_enduses(assets, technologies)[source]

Aggregate enduse commodities for input assets.

This function is meant as a helper to figure out the commodities attached to a group of agents.

Module contents

Define a sector, e.g. aggregation of agents.

There are three main kinds of sectors classes, encompassing three use cases:

  • Sector: The main workhorse sector of the model. It contains only on kind of data, namely the agents responsible for holding assets and investing in new assets.

  • PresetSector: A sector that is meant to generate demand for the sectors above using a fixed formula or schedule.

  • LegacySector: A wrapper around the original MUSE sectors.

All the sectors derive from AbstractSector. The AbstractSector defines two abstract functions which should be declared by derived sectors. Abstract here means a common programming practice where some concept in the code (e.g. a sector) is given an explicit interface, with the goal of making it easier for other programmers to use and implement the concept.

  • AbstractSector.factory(): Creates a sector from input data

  • AbstractSector.next(): A function which takes a market (demand, supply, prices) and returns a market. What happens within could be anything, though it will likely consists of dispatch and investment.

New sectors can be registered with the MUSE input files using muse.sectors.register.register_sector().

class AbstractSector[source]

Bases: ABC

Abstract base class for sectors.

Sectors are part of type hierarchy with AbstractSector at the apex: all sectors should derive from AbstractSector directly or indirectly.

MUSE only requires two things of a sector. Sector should be instanstiable via a factory() function. And they should be callable via next().

AbstractSector declares an interface with these two functions. Sectors which derive from it will be warned if either method is not implemented.

abstract classmethod factory(name, settings)[source]

Creates class from settings named-tuple.

abstract next(mca_market)[source]

Advance sector by one time period.

class LegacySector(name, old_sector, timeslices, commodities, commodity_price, static_trade, regions, time_framework, mode, excess, market_iterative, sectors_dir, output_dir)[source]

Bases: AbstractSector

calibrated

Flag if the sector has gone through the calibration process.

commodities

Commodities for each sector, as well as global commodities.

commodity_price

Initial price of all the commodities.

dims

Order of the input and output dimensions.

excess

Allowed excess of capacity.

classmethod factory(name, settings, **kwargs)[source]

Creates class from settings named-tuple.

property global_commodities

List of all commodities used by the MCA.

inputs(consumption, prices, supply)[source]

Converts xarray to MUSE numpy input arrays.

static load_timeslices_and_aggregation(timeslices, sectors)[source]

Loads all sector timeslices and finds the finest one.

market_iterative

—–> TODO what’s this parameter?

mode

If ‘Calibration’, the sector runs in calibration mode

name

Name of the sector

next(market)[source]

Adapter between the old and the new.

old_sector

Legacy sector method to run the calculation

output_dir

Outputs directory.

outputs(consumption, prices, supply)[source]

Converts MUSE numpy outputs to xarray.

regions

Regions taking part in the simulation.

runprocessmodule(consumption, supplycost, supply, t)[source]
property sector_commodities

List of all commodities used by the Sector.

property sector_timeslices

List of all commodities used by the MCA.

sectors_dir

Sectors directory.

static_trade

Static trade needed for the conversion and supply sectors.

time_framework

Time framework of the complete simulation.

timeslices

Timeslices for sectors and mca.

class PresetSector(presets, interpolation_mode='linear', name='preset')[source]

Bases: AbstractSector

Sector with outcomes fixed from the start.

classmethod factory(name, settings)[source]

Constructs a PresetSectors from input data.

interpolation_mode

Interpolation method

name

Name by which to identify a sector

next(mca_market)[source]

Advance sector by one time period.

presets

Market across time and space.

class Sector(name, technologies, subsectors=[], timeslices=None, technodata_timeslices=None, interactions=None, interpolation='linear', outputs=None, supply_prod=None)[source]

Bases: AbstractSector

Base class for all sectors.

property agents

Iterator over all agents in the sector.

property capacity

Aggregates capacity across agents.

The capacities are aggregated leaving only two dimensions: asset (technology, installation date, region), year.

static convert_market_timeslice(market, timeslice, intensive='prices')[source]

Converts market from one to another timeslice.

classmethod factory(name, settings)[source]

Creates class from settings named-tuple.

property forecast

Maximum forecast horizon across agents.

If no agents with a “forecast” attribute are found, defaults to 5. It cannot be lower than 1 year.

interactions

Interactions between agents.

Called right before computing new investments, this function should manage any interactions between agents, e.g. passing assets from new agents to retro agents, and maket make-up from retro to new.

Defaults to doing nothing.

The function takes the sequence of agents as input, and returns nothing. It is expected to modify the agents in-place.

interpolation

Interpolation method and arguments when computing years.

market_variables(market, technologies)[source]

Computes resulting market: production, consumption, and costs.

name

Name of the sector.

next(mca_market, time_period=None, current_year=None)[source]

Advance sector by one time period.

Parameters:
  • mca_market – Market with demand, supply, and prices.

  • time_period – Length of the time period in the framework. Defaults to the range of mca_market.year.

  • current_year – Current year of the simulation

Returns:

A market containing the supply offered by the sector, it’s attendant consumption of fuels and materials and the associated costs.

outputs

A function for outputting data for post-mortem analysis.

subsectors

Subsectors controlled by this object.

supply_prod

Computes production as used to return the supply to the MCA.

It can be anything registered with @register_production.

technologies

Parameters describing the sector’s technologies.

timeslices

Timeslice at which this sector operates.

If None, it will operate using the timeslice of the input market.

register_sector(sector_class=None, name=None)[source]

Registers a sector so it is available MUSE-wide.

Example

>>> from muse.sectors import AbstractSector, register_sector
>>> @register_sector(name="MyResidence")
... class ResidentialSector(AbstractSector):
...     pass