EventArbitraryProd#

class EventArbitraryProd(*, impact, recovery_time=1, recovery_function='linear', name='Unnamed', occurrence=1, duration=1)[source]#

Bases: Event

An EventArbitraryProd object holds an event with arbitrary impact on production capacity.

Such events can be used to represent temporary loss of production capacity in a completely exogenous way (e.g., loss of working hours from a heatwave).

Warning

This type of event suffers from a problem with the recovery and does not function properly at the moment.

Note

For this type of event, the impact value represent the share of production capacity lost of an industry.

Note

In addition to the base arguments of an Event, EventArbitraryProd requires a recovery_time (1 step by default) and a recovery_function (linear by default).

See also

Tutorial How to define Events

Methods

__init__(*, impact[, recovery_time, ...])

distribute_impact_by_gva(impact_vec)

Distribute a vector of impact by the GVA of affected industries.

distribute_impact_equally(impact_vec)

Distribute an impact equally between all affected regions.

from_dataframe(impact, *[, occurrence, ...])

Convenience function for DataFrames.

from_scalar_industries(impact, *, industries)

Creates an Event from a scalar and a list of industries affected.

from_scalar_regions_sectors(impact, *, ...)

Creates an Event from a scalar, a list of regions and a list of sectors affected.

from_series(impact, *[, occurrence, ...])

Create an event for an impact given as a pd.Series.

recovery(current_temporal_unit)

Apply the recovery function to the capital destroyed for the current temporal unit.

Attributes

Y_distrib

Normalized final consumption matrix

Z_distrib

Normalized intermediate consumption matrix

aff_industries

The industries affected by the event.

aff_regions

The array of regions affected by the event

aff_regions_idx

The array of lexicographically ordered affected region indexes

aff_sectors

The array of affected sectors by the event

aff_sectors_idx

The array of lexicographically ordered affected sectors indexes

duration

The duration of the event.

gva_df

GVA per (region,sector)

impact_df

A pandas Series with all possible industries as index, holding the impact vector of the event.

impact_industries_distrib

The series specifying how damages are distributed among affected industries (regions,sectors)

impact_regional_distrib

The series specifying how damages are distributed among affected regions

model_monetary_factor

Amount of unitary currency used in the MRIOT (e.g. 1000000 if in € millions).

mrio_name

MRIOT identification

occurrence

The temporal unit of occurrence of the event.

possible_final_demand_cat

List of final demand categories present in the MRIOT used by the model

possible_regions

List of regions present in the MRIOT used by the model

possible_sectors

List of sectors present in the MRIOT used by the model

prod_cap_delta_arbitrary

The optional array storing arbitrary (as in not related to productive_capital destroyed) production capacity loss

recoverable

A boolean stating if an event can start recover

recovery_function

The recovery function used for recovery (Callable)

regions_idx

lexicographic region indexes

sectors_gva_shares

Fraction of total (regional) GVA for each sectors

sectors_idx

lexicographic sector indexes

temporal_unit_range

Maximum temporal unit simulated

x_shape

Shape of the x (production) vector in the model

y_shape

Shape of the Y (final demand) matrix in the model

z_shape

Shape of the Z (intermediate consumption) matrix in the model

recovery_time

The characteristic recovery duration after the event is over

name

An identifying name for the event (for convenience mostly)

happened

States if the event happened

over

States if the event is over

event_dict

Store relevant information about the event

recovery_time#

The characteristic recovery duration after the event is over

Y_distrib = array([], dtype=float64)#

Normalized final consumption matrix

Z_distrib = array([], dtype=float64)#

Normalized intermediate consumption matrix

property aff_industries#

The industries affected by the event.

property aff_regions#

The array of regions affected by the event

property aff_regions_idx#

The array of lexicographically ordered affected region indexes

property aff_sectors#

The array of affected sectors by the event

property aff_sectors_idx#

The array of lexicographically ordered affected sectors indexes

classmethod distribute_impact_by_gva(impact_vec)#

Distribute a vector of impact by the GVA of affected industries.

Each values of the given impact are mutliplied by the share of the GVA the industry has over the GVA of all affected industries.

Parameters:
impact_vecpd.Series

The impact values to be reweigthed. Current use-case assumes all values are the total impact.

Returns:
pd.Series

The impact where each value was multiplied by the share of GVA of each affected industry (over total GVA affected).

classmethod distribute_impact_equally(impact_vec)#

Distribute an impact equally between all affected regions.

Assume impact is given as a vector with all value being the total impact to distribute.

Parameters:
impact_vecpd.Series

The impact to distribute.

Returns:
pd.Series

The impact vector equally distributed among affected industries.

property duration#

The duration of the event.

classmethod from_dataframe(impact, *, occurrence=1, duration=1, name=None, **kwargs)#

Convenience function for DataFrames. See from_series(). This constructor only apply .squeeze() to the given DataFrame.

Parameters:
impactpd.DataFrame

A pd.DataFrame defining the impact per (region, sector)

occurrenceint

The ordinal of occurrence of the event (requires to be > 0). Defaults to 1.

durationint

The duration of the event (entire impact applied during this number of steps). Defaults to 1.

nameOptional[str]

A possible name for the event, for convenience. Defaults to None.

**kwargs

Keyword arguments Other keyword arguments to pass to the instantiate method (depends on the type of event)

Returns:
Event

An Event object (or one of its subclass).

Raises:
ValueError

If impact cannot be squeezed to a Series

classmethod from_scalar_industries(impact, *, industries, impact_industries_distrib=None, gva_distrib=False, occurrence=1, duration=1, name=None, **kwargs)#

Creates an Event from a scalar and a list of industries affected.

The scalar impact is distributed evenly by default. Otherwise it can be distributed proportionnaly to the GVA of affected industries, or to a custom distribution.

Parameters:
impactScalarImpact

The scalar impact.

industriesIndustriesList

The list of industries affected by the impact.

impact_industries_distribOptional[npt.ArrayLike]

A vector of equal size to the list of industries, stating the share of the impact each industry should receive. Defaults to None.

gva_distribOptional[bool]

A boolean stating if the impact should be distributed proportionnaly to GVA. Defaults to False.

occurrenceOptional[int]

The ordinal of occurrence of the event (requires to be > 0). Defaults to 1.

durationOptional[int]

The duration of the event (entire impact applied during this number of steps). Defaults to 1.

nameOptional[str]

A possible name for the event, for convenience. Defaults to None.

**kwargs

Keyword arguments Other keyword arguments to pass to the instantiate method (depends on the type of event)

Returns:
Event

An Event object or one of its subclass.

Raises:
ValueError

Raised if Impact is null, if len(industries) < 1 or if the sum of impact_industries_distrib differs from 1.0.

classmethod from_scalar_regions_sectors(impact, *, regions, sectors, impact_regional_distrib=None, impact_sectoral_distrib=None, occurrence=1, duration=1, name=None, **kwargs)#

Creates an Event from a scalar, a list of regions and a list of sectors affected.

Parameters:
impactScalarImpact

The scalar impact.

regionsRegionsList

The list of regions affected.

sectorsSectorsList

The list of sectors affected in each region.

impact_regional_distribOptional[npt.ArrayLike], optional

A vector of equal size to the list of regions affected, stating the share of the impact each industry should receive. Defaults to None.

impact_sectoral_distribOptional[Union[str, npt.ArrayLike]], optional

Either:

  • "gdp", the impact is then distributed using the gross value added of each sector as a weight.

  • A vector of equal size to the list of sectors affected, stating the share of the impact each industry should receive. Defaults to None.

occurrenceint, optional

The ordinal of occurrence of the event (requires to be > 0). Defaults to 1.

durationint, optional

The duration of the event (entire impact applied during this number of steps). Defaults to 1.

nameOptional[str], optional

A possible name for the event, for convenience. Defaults to None.

**kwargs

Keyword arguments Other keyword arguments to pass to the instantiate method (depends on the type of event)

Returns:
Event

An Event object or one of its subclass.

Raises:
ValueError

Raise if Impact is null, if len(regions) or len(sectors) < 1,

classmethod from_series(impact, *, occurrence=1, duration=1, name=None, **kwargs)#

Create an event for an impact given as a pd.Series.

Parameters:
impactpd.Series

A pd.Series defining the impact per (region, sector)

occurrenceint

The ordinal of occurrence of the event (requires to be > 0). Defaults to 1.

durationint

The duration of the event (entire impact applied during this number of steps). Defaults to 1.

nameOptional[str]

A possible name for the event, for convenience. Defaults to None.

**kwargs

Keyword arguments keyword arguments to pass to the instantiating method

(depends on the type of event).
Returns:
Event

An Event object or one of its subclass

Raises:
ValueError

Raised if impact is empty of contains negative values.

Examples

>>> import pandas as pd
>>> import pymrio as pym
>>> from boario.simulation import Simulation
>>> from boario.extended_model import ARIOPsiModel
>>> from boario.event import EventKapitalRecover
>>>
>>> mriot = pym.load_test()
>>> mriot.calc_all()
>>>
>>> impact_series = pd.Series({('reg1', 'electricity'): 100000.0, ('reg1', 'mining'): 50000.0})
>>> model = ARIOPsiModel(mriot)
>>> sim = Simulation(model)
>>> event = EventKapitalRecover.from_series(impact_series, occurrence=5, duration=10, recovery_time=30, name="Event 1")
>>> sim.add_event(event)
gva_df = Series([], dtype: float64)#

GVA per (region,sector)

property impact_df#

A pandas Series with all possible industries as index, holding the impact vector of the event. The impact is defined for each sectors in each region.

property impact_industries_distrib#

The series specifying how damages are distributed among affected industries (regions,sectors)

property impact_regional_distrib#

The series specifying how damages are distributed among affected regions

model_monetary_factor = 1#

Amount of unitary currency used in the MRIOT (e.g. 1000000 if in € millions)

mrio_name = ''#

MRIOT identification

property occurrence#

The temporal unit of occurrence of the event.

possible_final_demand_cat = Index([], dtype='object')#

List of final demand categories present in the MRIOT used by the model

possible_regions = Index([], dtype='object')#

List of regions present in the MRIOT used by the model

possible_sectors = Index([], dtype='object')#

List of sectors present in the MRIOT used by the model

property prod_cap_delta_arbitrary#

The optional array storing arbitrary (as in not related to productive_capital destroyed) production capacity loss

regions_idx = array([], dtype=float64)#

lexicographic region indexes

sectors_gva_shares = array([], dtype=float64)#

Fraction of total (regional) GVA for each sectors

sectors_idx = array([], dtype=float64)#

lexicographic sector indexes

temporal_unit_range = 0#

Maximum temporal unit simulated

x_shape = (0, 0)#

Shape of the x (production) vector in the model

y_shape = (0, 0)#

Shape of the Y (final demand) matrix in the model

z_shape = (0, 0)#

Shape of the Z (intermediate consumption) matrix in the model

name#

An identifying name for the event (for convenience mostly)

happened#

States if the event happened

over#

States if the event is over

event_dict#

Store relevant information about the event

property recoverable#

A boolean stating if an event can start recover

property recovery_function#

The recovery function used for recovery (Callable)

recovery(current_temporal_unit)[source]#

Apply the recovery function to the capital destroyed for the current temporal unit.

Parameters:
current_temporal_unitint

The current temporal unit

Raises:
RuntimeError

Raised if no recovery function has been set.