Event#
- class Event(*, impact, name='Unnamed', occurrence=1, duration=1)[source]#
Bases:
ABC
An Event object stores all information about a unique shock during simulation such as time of occurrence, duration, type of shock, amount of damages. Computation of recovery or initially requested rebuilding demand is also done in this class.
Warning
The Event class is abstract and cannot be instantiated directly. Only its non-abstract subclasses can be instantiated.
Note
Events should be constructed using
from_series()
,from_dataframe()
,from_scalar_industries()
or fromfrom_scalar_regions_sectors()
. Depending on the type of event chosen, these constructors require additional keyword arguments, that are documented for each instantiable Event subclass. For instance,EventKapitalRebuild
additionally requires rebuild_tau and rebuilding_sectors.See also
Tutorial How to define Events
Methods
__init__
(*, impact[, name, occurrence, duration])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.
Attributes
Normalized final consumption matrix
Normalized intermediate consumption matrix
The industries affected by the event.
The array of regions affected by the event
The array of lexicographically ordered affected region indexes
The array of affected sectors by the event
The array of lexicographically ordered affected sectors indexes
The duration of the event.
GVA per (region,sector)
A pandas Series with all possible industries as index, holding the impact vector of the event.
The series specifying how damages are distributed among affected industries (regions,sectors)
The series specifying how damages are distributed among affected regions
Amount of unitary currency used in the MRIOT (e.g. 1000000 if in € millions).
MRIOT identification
The temporal unit of occurrence of the event.
List of final demand categories present in the MRIOT used by the model
List of regions present in the MRIOT used by the model
List of sectors present in the MRIOT used by the model
lexicographic region indexes
Fraction of total (regional) GVA for each sectors
lexicographic sector indexes
Maximum temporal unit simulated
Shape of the x (production) vector in the model
Shape of the Y (final demand) matrix in the model
Shape of the Z (intermediate consumption) matrix in the model
An identifying name for the event (for convenience mostly)
States if the event happened
States if the event is over
Store relevant information about the event
- possible_sectors = Index([], dtype='object')#
List of sectors 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_final_demand_cat = Index([], dtype='object')#
List of final demand categories present in the MRIOT used by the model
- temporal_unit_range = 0#
Maximum temporal unit simulated
- z_shape = (0, 0)#
Shape of the Z (intermediate consumption) matrix in the model
- y_shape = (0, 0)#
Shape of the Y (final demand) matrix in the model
- x_shape = (0, 0)#
Shape of the x (production) vector in the model
- regions_idx = array([], dtype=float64)#
lexicographic region indexes
- sectors_idx = array([], dtype=float64)#
lexicographic sector indexes
- model_monetary_factor = 1#
Amount of unitary currency used in the MRIOT (e.g. 1000000 if in € millions)
- gva_df = Series([], dtype: float64)#
GVA per (region,sector)
Fraction of total (regional) GVA for each sectors
- Z_distrib = array([], dtype=float64)#
Normalized intermediate consumption matrix
- Y_distrib = array([], dtype=float64)#
Normalized final consumption matrix
- mrio_name = ''#
MRIOT identification
- 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
- classmethod from_series(impact, *, occurrence=1, duration=1, name=None, **kwargs)[source]#
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)
- classmethod from_dataframe(impact, *, occurrence=1, duration=1, name=None, **kwargs)[source]#
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 distribute_impact_by_gva(impact_vec)[source]#
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)[source]#
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.
- classmethod from_scalar_industries(impact, *, industries, impact_industries_distrib=None, gva_distrib=False, occurrence=1, duration=1, name=None, **kwargs)[source]#
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)[source]#
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,
- 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 aff_industries#
The industries affected by the event.
- property occurrence#
The temporal unit of occurrence of the event.
- property duration#
The duration of the event.
- property aff_regions_idx#
The array of lexicographically ordered affected region indexes
- property aff_regions#
The array of regions affected by the event
- property aff_sectors_idx#
The array of lexicographically ordered affected sectors indexes
- property aff_sectors#
The array of affected sectors by the event
- property impact_regional_distrib#
The series specifying how damages are distributed among affected regions
- property impact_industries_distrib#
The series specifying how damages are distributed among affected industries (regions,sectors)