MISO2 Model
Core logic of calculating a MISO2 model.
Created on Wed Feb 16 20:57:53 2022
@author: jstreeck & bgrammer
- class model.core.MISO2_model.MISO2Model(miso_config, miso_survival_functions, nr_start=0, nr_stop=1, balance_error_tolerance=1e-05)
Contains the logic for calculating a MISO2 Model.
- Parameters:
miso_config (MISO2Config) – Model configuration. Should not be written to from the model object.
miso_survival_functions (MISO2SurvivalFunctions) – Precomputed survival functions.
nr_start (int) – Region start index. This needs only be set when the MISO2Config data contains more than one region and the data needs to be subset for computation. Defaults to 0.
nr_stop (int) – Region stop index. Defaults to 1.
balance_error_tolerance (float) – Error tolerance for mass balancing. Defaults to 1e-5.
- miso_config
Model configuration. Should not be written to from the model object.
- Type:
- sf_array
Precomputed survival functions.
- Type:
- balance_error_tolerance
Error tolerance for mass balancing.
- Type:
float
- miso_model_data
Holds arrays for ongoing calculations.
- Type:
- MFA_system_control
Used for error checking. Holds control values of system, such as information about expected zero and non-zero values of MFA system after model run.
- Type:
dict
- Raises:
AttributeError – If UUID of MISO2Config and MISO2SurvivalFunctions do not match up.
- P10_Dynamic_Stock_Model(r, dimensions)
Dynamic Stock Model calculation of stock by cohort and EoL outflows
Modifies F_10_11 / S_10 inplace.
TO DO: See if the stock computation can be simplified. Currently running over all years every year. odym function .compute_s_c_inflow_driven() needs dimensions t,tc; if running per year these are not given anymore. tbd
- Parameters:
r (int) – Region index
dimensions (dict) – Model dimensions
- P11_waste_collection(r, t)
Waste collection, calculate collected potentially recoverable new scrap and old scrap and total
- Parameters:
r (int) – Region index.
t (int) – Time index.
- P12_trade_recoverable_waste(r, t)
Trade of potentially recoverable waste
- Parameters:
r (int) – Region index.
t (int) – Time index.
- P13_recycling_downcycling(r, t, selector_downc_mats, new_scrap_cycle)
P13 recycling and downcycling
start with flow F_12_13 = apparent supply of recoverable waste cycling data can differ in two dimensions: it can be in absolute flows (ABSOLUTE) or flows can be calculated by multiplying waste flows by cycling rates (RATE); and it can either refer to end-of-life cycling only (EoL), or to total cycling (TOTAL), which includes EoL and new scrap cycling for recycling, these four categories are exclusive per material and year (and thus additive), meaning that a material can either have absolute or rate recycling input data for either EoL or Total recycling for downcycling, only the exclusive (additive) categories absolute or rate recycling input data apply, as we assume that no new scrap is downcycled (and thus both cases always refer to EoL not Total cycling.
- Parameters:
r (int) – Region index.
t (int) – Time index.
selector_downc_mats (list) – Indices of downcycle materials
new_scrap_cycle()
- P14_final_waste_disposal(r, t)
Final waste disposal
Calculate final waste flows to outside system boundaries; calculate for previous year, as F_13_14 could only be determined after Calculating actual use of recycled and downcycled aggregate in current year from supply of previous year
- Parameters:
r (int) – Region index.
t (int) – Time index.
- P20_buffer_transfer(r, t, buffer_stocks_flows)
Buffer transferring cycled materials (20a/b) and potential supply of aggregates, virgin & downcycled from year t to t+1
- Parameters:
r (int) – Region index.
t (int) – Time index.
buffer_stocks_flows (dict) – Dictionary mapping buffer flows and stocks
- P4_add_raw_product_trade(r, mats, t)
Add raw product trade, calculate apparent consumption and balance P4.
- Parameters:
r (int) – Region index.
mats (int) – Material selector index.
t (int) – Time index.
- P4_generate_production_raw_products(r, selector_NoAggr, t)
Assign primary production and total production from input data and adjust to flow definitions.
Primary production F_3_4a or total production total2primary from input data. The latter adjusted to F_3_4b via re/downcycling flows 20_4a/b, F_3_4a and F_3_4b are exclusive per material, meaning that either total or primary production is reported per material
- Parameters:
r (int) – Region index.
selector_NoAggr (list) – List of non-aggregate indices.
t (int) – Time index.
- P5_fabricate_semi_finished_products(r, mats, t)
Fabricate semi-finished products #recoverable (a) & unrecoverable (b) waste during fabrication
- Parameters:
r (int) – Region index.
mats (int) – Material selector index.
t (int) – Time index.
- P6_trade_semi_finished_products(r, mats, t)
Add trade of semi-finished products, calculate apparent consumption and balance P6.
- Parameters:
r (int) – Region index.
mats (int) – Material selector index.
t (int) – Time index.
- P7_manufacture_final_products(r, mats, t)
Manufacture final products via subtracting recoverable (a) & unrecoverable (b) waste during manufacturing.
- Parameters:
r (int) – Region index.
mats (int) – Material selector index.
t (int) – Time index.
- P8_trade_final_products(r, mats, t)
Add trade of final products, calculate apparent consumption and balance P8
- Parameters:
r (int) – Region index.
mats (int) – Material selector index.
t (int) – Time index.
P9.1 Introduce end-use shares gross additions to stock (GAS) per end-use = (AC final products - waste) end-use shares (new dimensions r,e,m,g,t)
- Parameters:
r (int) – Region index.
mats (int) – Material selector index.
t (int) – Time index.
enduse_shares (np.Array) – Array of enduse shares
- P9_2_change_material_categories(r, t, cementBitumen_2_concreteAsphalt, appar_consump_end_use, multiplier_cementBitumen, waste_cascade_dict)
P9.2 change of material categories: cement & bitumen + sand & gravel –> concrete & asphalt
- Parameters:
r (int) – Region index.
t (int) – Time index.
cementBitumen_2_concreteAsphalt()
appar_consump_end_use (np.Array) – remgt array
multiplier_cementBitumen()
waste_cascade_dict (dict)
- P9_2_recov_unrecov_waste_flows(r, mats, t, cementBitumen_2_concreteAsphalt, selector_Aggr, trade_larger_req_g)
Set P9 standard flows F9_11, recoverable (a) & unrecoverable (b) waste during fabrication.
Conditionally for aggregates, recov. waste = input per end-use * waste rate per end-use + excess aggregate imports (can be used in next year)
- Parameters:
r (int) – Region index.
t (int) – Time index.
mats (list) – Material selector index.
cementBitumen_2_concreteAsphalt (np.Array) – apparent consumption of materials with bitumen/cement partially transformed to asphalt, concrete (see P9_2_change_material_categories)
selector_Aggr (list) – List of aggregate selectors
trade_larger_req_g (np.Array) – array with non-zero values, if net imports of virgin aggregates larger than aggregate requirement (aggregate requirement & trade_larger_req_g estimated in first loop of ‘mats’ selector, considering only non-aggregate materials; and compared to virgin aggregate net imports in second loop of ‘mats’ selector; trade_larger_req_g is overflowing into recoverable waste flows, to be recycled next year; this is a contingency for the rare case that imports of virgin aggregates larger than aggregate requirement ) )
- P9_3_aggregate_gap(r, t, enduse_shares, endUse_aggregates, selector_downc_mats, selector_multiplier_materials, aggr_req_mg, waste_cascade_dict, net_trade_aggr_p9)
Aggregate Gap: estimate demand of aggregates, appraise supply from recycled and downcycled aggregates and calc. additional required virgin
Aggregate input (time steps inherent) Estimate demand per end-use relevant for aggregate use as specified in variable endUse_aggregates (e.g. buildings, roads, other construction) Conditional: only run aggregate gap once (when prior flows for all materials except aggregates have been calculated) enable or disable estimation of aggregate gap
- Parameters:
r (int) – Region index.
t (int) – Time index.
enduse_shares (np.Array) – something else
endUse_aggregates (dict) – Maps enduses (?) to aggregate multiplier values
selector_downc_mats (list) – List of aggregate selectors
selector_multiplier_materials (list) – List of materials with foundation aggregate multipliers
aggr_req_mg()
net_trade_aggr_p9()
waste_cascade_dict (dict)
- balance_process(process_output, r, t)
Balance process of all materials.
set negative consumption values to value of previous year :param process_output: Output of a process. :type process_output: np.Array :param r: Region index. :type r: int :param t: Time index. :type t: int
- Returns:
balance_item(np.Array): Difference between original and modified array
- Return type:
cons_balanced(np.Array)
- balance_process_indexed(process_output, material_selector, r, t)
Balance process of selected material.
Set negative consumption values to value of previous year
- Parameters:
process_output (np.Array) – Output of a process.
material_selector (int) – Index of selected material.
r (int) – Region index.
t (int) – Time index.
- Returns:
balance_item(np.Array): Difference between original and modified array
- Return type:
cons_balanced(np.Array)
- calc_net_trade_aggr_p9(r, t, waste_cascade_dict)
Calculate net trade of aggregates at process p9 (which requires subtraction of waste losses depending on at which part of supply chain trade occurs)
- Parameters:
r (int) – Region index.
t (int) – Time index.
waste_cascade_dict (dict) – Waste cascade dictionary
- calc_waste_cascades(r, t)
Calculate waste cascade factors throughout processes 5-7-9 to adjust backward calculations for aggregates in P9.2, P9.3. (i.e. add the losses waste occurring throughout processes 5-7-9 to calculate original flows)
- Parameters:
r (int) – Region index.
t (int) – Time index.
- define_mfa_system(mfa_system_initializer)
Load MFA system into the MISO2 model.
Since the model core logic relies on access to the correct parameter names to model a system, the model logic is at the moment customized towards the most recent MFA system definition. In future versions, this should be replaced with a mapping of MFA systems to appropriate model logic and output functions. The MFA System initializer sets the control variables of the system (MFA_system_control) for later error checking and metadata creation.
- Parameters:
mfa_system_initializer (func) – A MISO2_system_definitions function.
- derive_cycled_mat_from_last_year(r, t, buffer_flows_stocks)
Start year-loop with deriving recycled/downcycled material from last year from buffer S20
S_20a = recycled material use (except for aggregates, these are listed in S_20c) S_20c = maximal supply of recycled virgin aggregates and downcycled aggregates from asphalt, concrete, bricks (use determined from supply in p9) S_20 should be zero afterward.
- Parameters:
r (int) – Region index.
t (int) – Time index.
buffer_flows_stocks (dict) – Dictionary mapping flows to stocks,
- run_model(estimate_aggregates=True, save_stock_cohorts=True, save_last_year=False)
Run the MISO2 model.
The parameters for the model run are taken from the models nr_start and nr_stop values. A start and stop region index can be specified, but the user needs to make sure that this index is covered by the MISO2Configs data and the MISO2SurvivalFunctions SF_Array.
- Parameters:
estimate_aggregates (bool) – If True, foundation aggregates will be estimated. Defaults to True.
save_stock_cohorts (bool) – If True, stock cohorts will be added to output. They considerably increase the output size. Defaults to False.
save_last_year (bool) – If True, the last year of the model run will be included in the output. Values of the last year may contain nonsensical or NaN values and are usually not desired in the output, but may be useful for debugging.
- Returns:
Results of the model run.
- Return type:
miso_output(MISO2Output)
- Raises:
WasteRateError – If waste ratios exceed 1.
InputLimitError – If any data point violates parameter hard limits.
- write_debug_to_xls(filepath)
Writes the model debug dataframes as sheets to an XLS file at specified location. Use this after a finished model run to get diagnostic information on the model that is not usually saved to outputs, e.g. mass balances.
- Parameters:
filepath (str) – Path and name of debug file.