pycirk package

Submodules

pycirk.cli module

pycirk.fundamental_operations module

Created on Wed Nov 2 12:05:08 2016

Description: Class to perform SUT and IOT transformations and balancing

Scope: Modelling circular economy policies in EEIOA

@author:Franco Donati @institution:Leiden University CML

class pycirk.fundamental_operations.Operations[source]

Bases: object

Contains all basic operations to transform SUTs into IOTs and verify them It contains two subclasses defining two different trasformation methods PxP ITA Market share and Technical Coefficient methods note: It should be expanded to other transformation methods in the future

class IOT[source]

Bases: object

General IOT operations subclass some methods repeat from other subclasses but it’s good to have them divided for clarity

A(inv_diag_x)[source]

Technical coefficient matrix A = Z * inv(diag(x))

B(inv_diag_x)[source]

Calculates extensions intensities

IOT(Y, W, E, R, M)[source]
L()[source]

Leontief inverse L = (I-A)^-1

R(diag_x)[source]

Calculates absolute extensions

RY(diag_yj)[source]

Caclculates absolute extensions in final demand

Z(diag_x)[source]

Total product ouput Z = A * diag_x

bY(inv_diag_yj)[source]

Calculates intensities of extensions in final demand Method for transformation matrix of bY (e.g. final demand emissions)

x(Y)[source]

total product output s the sum of Si and y

x_IAy(y)[source]

Total product ouput x = inv(I - A) * yi

class PxP_ITA_MSC[source]

Bases: object

Model with Market Share Coef. Prod x Prod Industry Technology assumption

A(D)[source]

Total requirement multipliers A = Z * D

B(D, inv_diag_g)[source]

Calculates extensions intensities

D(inv_diag_q)[source]

Market share coefficients D = V * inv(diag(q))

L()[source]

Leontief inverse L = (I-A)^-1

R(diag_q)[source]

Calculates absolute extensions

S(inv_diag_g)[source]

Intermediate coefficients Input requirements Z = U * inv(diag(g))

Z(D, diag_q)[source]

Intermediates Z = inter_coef * D * diag(q)

class PxP_ITA_TC[source]

Bases: object

Model with Transformation Coefficients ProdxProd Industry Technology assumption

B(T, inv_diag_q)[source]

Calculates extension intensity

L(T, inv_diag_q)[source]

Input coefficients intermediates A = U * T * inv[diag (q)]

Multiplier matrix L = (I-A)^-1

R(diag_q)[source]

Calculates absolute extensions

T(inv_diag_g)[source]

Transformation matrix T = inv(diag(g)) * V

Z(U)[source]

Intemediates Z = U * T

calculate_characterized()[source]
delta_Y(Yalt)[source]

method to calculate difference in Y Y = final demand baseline Yalt = final demand scenario

delta_x(Lalt, y)[source]

method to calculate difference in q L = Leontief of baseline Lalt = Leontief of scenario

inv()[source]

Returns inverse by dividing by 1 and eliminating inf and nan values

verifyIOT(Y, W)[source]

pycirk.labels module

Created on sat Jan 28 2017

Description: Labelling elements for SUTs and IOTs

Scope: Modelling the Circular Economy in EEIO

@author:Franco Donati @institution:Leiden University CML

class pycirk.labels.Labels[source]

Bases: object

apply_labels(matrix, labels, axis=0)[source]

Applies labels to a dataframe axis = 0 => Index axis = 1 => columns

calc_no_of_something(labels)[source]

A general method to calculate the number of unique entries contained in a series

get_labels(matrix)[source]

Collects labels from a dataframe

get_unique_labels(dataframe_of_labels, for_units=True)[source]

Calculates all unique entries (labels) contained in a dataframe and puts them together with their units and total count of unique entries

It returns an object… which is munched, not a pretty solution but it works ok for now. Please consider refactoring in the future

identify_labels(M_name)[source]

A method to understand what type of labels are being handled depending on the name of the matrix in dataframe type that is being passed

list_of_something(labels)[source]

A general method to return a list of unique entries contained in a series

load_labels(directory)[source]
organize_unique_labels(directory)[source]
relabel(M, column_labels, index_labels)[source]

Processes apply_labels and apply _names together

relabel_to_save(data, trans_method, labels_directory)[source]

This function makes sure that everything is labeled in IOT tables

trans_method = 0 is prod x prod , 1 is ind x ind

save_labels(data, directory)[source]

saves the labels of the database in the labels directory

pycirk.make_scenarios module

Created on Fri Nov 25 12:13:29 2016

Description: Reading policy values and modifying matrices for scenarios

Scope: Modelling the Circular Economy in EEIO

@author: Franco Donati @institution: Leiden University CML

pycirk.make_scenarios.basic_add(a, at)[source]

Adds values together

a : numpy.array

at : numpy array

pycirk.make_scenarios.basic_mult(ide, a, kt, kp)[source]

Policy intervention

It may be a primary intervention or an acillary action.

a: numpy.array
a supply chain or a point in it subject to a change
kt: float
technical coefficient (max achievable technically)
kp: float
penetration coefficient (level of market penet. of the policy)
ide: int
identification number of the intervention in case of missing information

A a numpy.array of the same order/shape of a

pycirk.make_scenarios.counterfactual(scen_file, scen_no, M, M_name, labels)[source]

Separates changes by matrix subject to intervention and apply them on a specific matrix

scen_file: str
directory of the file in which the scenarios are specified
scen_no : int
specific scenario e.g “1” or “scenario_1”
M : numpy.array
matrix affected by the policies
M_name : str
matrix name as diplayed under sheet_name[“matrix”]
labels : obj
matrix labels

A numpy array modified according to the specified changes in the scenario file

pycirk.make_scenarios.counterfactual_engine(M, inter_sets, subs=False, copy=False)[source]

This function allows for the proccessing of the specified interventions onto a selected matrix. It calls various functions to modify the values in a specified matrix.

M : numpy.array
matrix of reference
inter_sets: dict
contains all specfication concerning the changes to be applied (intervention sets)
subs : bool
If True it will call the subsitution function according to specifications in scenarios.xlsx
copy : bool
if True it will copy value from one part of the matrix to another according to specifications in scenarios.xlsx

i : index coordinate

g : column coordinate

ide : intervention identification number

kt : technical change coefficient

kp : market penetration coefficient

fx_kp : market penetration coeffient applicable to substitution

expan : expansion coef. (used only for simple transaction changes)

A numpy.array of the modified matrix

pycirk.make_scenarios.make_counterfactuals(data, scen_no, scen_file, labels)[source]

Calculate all the counterfactual IO matrices

data : obj
An object containing all necessary matrices of the IO system
scen_no : int
the identification number of the scenario to reference in scen_file
scen_file : str
the directory where the scenarios.xlsx file is store
labels : obj
an object containing all labels for the IO matrices

An object contaning a mofified IO system

pycirk.make_scenarios.make_new(filtered_changes, M, M_name, labels)[source]

Organizes the data concerning the changes and calls the functions to modified matrices based on specied scenarios

filterd_changes: pandas.DataFrame
A table filtered by matrix name containing all changes to be applied
M : numpy.array
matrix on which to implement the changes
M_name : str
nomenclature referring to the matrix to be changed
labels: obj
object containing all matrix labels

g is any column in the matrix

i is any row row in the matrix

A numpy.array of the processed matrix

pycirk.make_scenarios.substitution(d, s, fx_kp)[source]

Moves the value from one or multiple cells (in the same row or column)

Substitution: Material subsitution or certain types of rebound effects

If the size of the array of the original value is different from that of the destination (substituted), we obtain the total of the value to be substituted and the substitution is implemented by dividing the tot by the number of elements on the destination array and then added to the destination array (equally distributed)

d : numpy.array
transaction with which we are substituting
s : numpy.array
original transaction that was subject to changes (the transactions from which the value is coming from)
fx_kp : float
relative size of c that is added on the transaction to expand d

A numpy.array of modified d

pycirk.make_secondary_flows module

Created on Mon Jul 16 15:10:19 2018 Description: Modifying SUT to ensure appearance of secondary material flows in IOT

Scope: Modelling the Circular Economy in EEIO

@author:Franco Donati @contributor: Arjan de Koning @institution:Leiden University CML

pycirk.make_secondary_flows.allocate_sec_mat(V, U, Y, prod_or, ind_or)[source]

This function allows to move the primary material output from the secondary material industries to the secondary material output. This allows for the presence of secondary materials in the IOT once they are transformed from SUTS.

prod_or = row position of the primary supplied material ind_or = colum pos. of the primary industry supplying primary material

pycirk.make_secondary_flows.make_secondary(data)[source]

This allows to allign secondary flow in such a way that they then appear in the IOT

Primary Products’ positions

C_WOOD: 57 C_PULP: 59 C_PLAS: 85 C_GLAS: 96 C_CMNT: 100 C_STEL: 103 C_PREM: 105 C_ALUM: 107 C_LZTP: 109 C_COPP: 111 C_ONFM: 113 C_CONS: 149

Primary Sectors’positions:

A_WOOD: 49 A_PULP: 51 A_PLAS: 58 A_GLAS: 64 A_CMNT: 68 A_STEL: 71 A_PREM: 73 A_ALUM: 75 A_LZTP: 77 A_COPP: 79 A_ONFM: 81 A_CONS: 112

pycirk.organize_io module

Created on Tue Feb 7 16:29:23 2017

Description: Organize essential tables for saving

Scope: Modelling the Circular economy in EEIO

@author: Franco Donati @institution: Leiden University CML

pycirk.organize_io.organizer(data)[source]

pycirk.positions module

Created on Wed Jan 23 10:58:46 2019

Description: Finding the position of labels

Scope: Modelling the Circular Economy in EEIO

@author:Franco Donati @institution:Leiden University CML

pycirk.positions.make_coord_array(cat_coord, reg_coord, no_countries, no_categories)[source]

It creates an an array of coordinates based on the specification of the users.

cat_coord : int, numpy.array, bool
the numerical coordinate of a specific category belonging to a matrix in the IO or SUT system. If None is passed then it will return an array of all coordinates in range no_categories.
reg_coord : int, numpy.array, bool
the numerical coordinate of a specific region in the IO or SUT system. If None is passed then it will return an array of all coordinates in range no_countries.
no_countries : int
the total number of countries or regions in the dataset
no_categories : int
the total number of categories referring one axis in the chosen matrix

A numpy.array referring to each coordinate point specified by the user

pycirk.positions.make_coord_array_for_make_sec(coordinates, no_countries, no_categories)[source]

It creates an an array of coordinates based on the total location of secondary materials and processing categories

coordinates : int, numpy.array
the numerical coordinate of secondary categories belonging to the SUT system
no_countries : int
the total number of countries or regions in the dataset
no_categories : int
the total number of categories referring one axis in the chosen matrix

A numpy.array referring to each coordinate point

pycirk.positions.single_position(item, labels)[source]

Takes a dataframe of the multiindex and identifies the position of the specified values

item : str
The label the user is looking for
labels : obj
An object cointaining a set of labels (as specified in the labels.py module)

An numpy.array containing the coordinate of a specific label or None in case of there is no specified label

pycirk.pycirk module

Created on Tue Nov 15 16:29:23 2016

Description: Outputting scenarios

Scope: Modelling the Circular Economy in EEIO

@author:Franco Donati @institution:Leiden University CML

class pycirk.pycirk.Launch(method=0, make_secondary=False, save_directory=None, aggregation=1, file=None, test=False)[source]

Bases: object

Pycirk’s main class and methods

Initialize the pycirk programme to make EEIO scenarios and analysis. From here, you can launch all the analysis specifications listed under scenarios.xlsx

method : int

SUTs to IO transformation methods

0 = Prod X Prod Ind-Tech Assumption Technical Coeff method

1 = Prod X Prod Ind-Tech Assumption Market Share Coeff method

make_secondary : bool

modifies SUT so that secondary technologies which process scrap materials into primary materials are also available in the IO tables

False = Don’t modify

True = Modify

save_directory : str
directory in which you want to work and save your results

aggregation : int, bool

0 = None (multi-regional 49 regions)

1 = bi-regional (EU- ROW)

file : bool, str
allows you to specify where the dataset is placed. None will use the default location within the installed package
test : bool
if set to true it will run the test settings under under pycirk//tests
scenario_results : int

Allows to calculate the results for a given specified scenario

0 = baseline data

all_results :
Retrieves all results for all specified scenarios and baseline
save_results : int and bool
save all specified analytical results from all scenario and baseline
analysis.xlsx : excel file
to be found under the default folder on the specified directory it allows to specify the parameters for your scenario and analysis
IO tables : pkl
IO tables of the specified scenarios, these are located in the output folder in the save directory
results : DataFrame
results gathered from the processed scenarios and baseline
all_results()[source]

Process all scenarios and collects their results together with Baseline analysis results

It outputs a pandas.DataFrame with all results

delete_previous_IO_builds()[source]

Call this method if you want to elinate all previous IO databases created by pycirk. SUTs database is not affected.

save_results(scen_no=None, output_dataset=False)[source]

Saves all results in excel format for info and results or in pickle format for the dataset

scen_no: int

0 = baseline

1-n = specified scenarios

output_datase: bool
If true it will output a dictionary containing all IOT tables in pd.DataFrames

Default values will save all results from the all_results method and they will output only scenario.xlsx and info_and_results.xlsx

Output_dataset is only possible when scen_no is specified in which case it would save also a data.pkl file

scenarios.xlsx : excel file
scenario settings excel file used for the analysis in the same output directory with the results
info_and_results.xlsx : excel file
excel file containing general info about project plus the results from the analysis
data.pkl : pickle file
new modified IO dataset in pickle format This is only possible if outputting single scenario (scen_no != None)
scenario_results(scen_no, output_dataset=False)[source]

Run to output results of a specified scenario

scen_no: int
0 = baseline 1-n = specified scenarios
output_datase: bool
If true it will output a dictionary containing all IOT tables in pd.DataFrames

specified results in DataFrame form or a dictionary containing results and a dictionary of dataframes containing IO matrices

pycirk.pycirk_settings module

Created on Wed Feb 20 16:29:23 2019

Description: Setting parameters for pycirk

Scope: Modelling the Circular Economy in EEIO

@author:Franco Donati @institution:Leiden University CML

class pycirk.pycirk_settings.Settings(method=0, make_secondary=False, save_directory='', aggregation=1, file=None, test=False)[source]

Bases: object

This class allows for to specify the settings for pycirk.

method : int

SUTs to IO transformation methods

0 = Prod X Prod Ind-Tech Assumption Technical Coeff method

1 = Prod X Prod Ind-Tech Assumption Market Share Coeff method

make_secondary : bool

modifies SUT so that secondary technologies which process scrap materials into primary materials are also available in the IO tables

False = Don’t modify

True = Modify

save_directory : str
directory in which you want to work and save your results

aggregation : int, bool

0 = None (multi-regional 49 regions)

1 = bi-regional (EU- ROW)

file : bool, str
allows you to specify where the dataset is placed. None will use the default location within the installed package
test : bool
if set to true it will run the test settings under under pycirk//tests
assign_labels_to_class()[source]

Assigns all labels to their respective attributes in the Labels class These are used througout the program to find coordinates and label results

check_dataset_location()[source]

It identifies where the baseline dataset is located and whether it is present in the directory. If an IO database was already created in the past then it will just return it’s location and type instead of transforming the SUTs into IOT anew

A dictionary containing location “loc” and type of format (SUT or IO)

check_expand_directory(directory)[source]

Checking that we are using the right directory for the right OS

create_output_folder()[source]

It creates an output folder where to save analytical results This is placed in the user’s working directory

create_scenario_file()[source]

It creates a new scenario file by copying the original from pycirk directory to the new working directory specified by the user

load_dataset(data)[source]

It loads the baseline dataset

load_results_params()[source]
number_scenarios()[source]
project_specs(test=False)[source]

General specifications for the project, they are also used to mark the output files

scenario_file()[source]

It returns where the working scenarios.xlsx file is located

set_IO_scenario(data, scen_no)[source]

Class the functions to modify the IO database according to your scenario specifications

set_SUTs()[source]
set_save_directory()[source]

It specifies where the scenario file for input is located

transform_to_io()[source]

Transforms the SUT dataset into an IO system

If the user specified to make secondary material processing apparent then it will launch the function to modify the database

If an IO from the same transformation method exists, then it will load that one instead

If a pre-existing IO is not present then it will save the transformed dataset in the directory. This is done to spead up processing time.

An object containing all the fundamental IO matrices to begin the analysis and scenarios.

pycirk.results module

Created on Mon Feb 27 09:26:43 2017

Description: module to perform results analysis

Scope: Modelling the Circular Economy in EEIO

@author:Franco Donati @institution:Leiden University CML, TU Delft TPM

pycirk.results.iter_thru_for_results(data, analysis_specs, scen_no, labels)[source]

It uses your analytical specification on scenarios.xlxl to return a dataframe of the desired results

pycirk.results.retrieve_specified_data(data, spec_row, labels)[source]

Separate, collect and rename results for base and scenarios according to specifications under th sheet “analysis” in scenarios.xls

data = any IOT table spec_row = row in the scenarios sheet specifying settings

pycirk.save_utils module

Created on Sat Mar 4 11:02:52 2017

Description: Save data to xls

Scope: Modelling circular economy policies in EEIOA

@author: Franco Donati @institution: Leiden University CML

pycirk.save_utils.add_date_to_gen_specs(specs)[source]

Adds timemark to general specifications e.g. authors, institution etc

pycirk.save_utils.save_outputs(results, directory, specs, scen_no, data=None)[source]

It saves results into a previously specified directory

results : pandas.DataFrame
a dataframe containing only selected results
directory : str
the general location specified for your scenarios.xlsx file
specs : dict
a dictionary containing general info about the project (e.g. author, institution, etc)
scen_no : int or None
an integer specifying the scenario number or enter None to save all results
data : dict of pd.DataFrames
a completely new dataset to be pickled. Default value is None otherwise pass the dataset
scenarios.xlsx : excel file
scenario settings excel file used for the analysis in the same output directory with the results
info_and_results.xlsx : excel file
excel file containing general info about project plus the results from the analysis
data.pkl : pickle file
new modified IO dataset in pickle format

pycirk.transformation_methods module

Created on Mon Feb 6 12: 29: 47 2017

Description: Uses methods within SUTops to calculate IOT and Extensions

Scope: Modelling the Circular economy in EEIO

@author: Franco Donati @institution: Leiden University CML

class pycirk.transformation_methods.Transform(SUTs)[source]

Bases: object

Transforms SUTs to IOT an calcualate extensions

IOTpxpSTA_MSCm()[source]

IOT prod x prod Single tech Industry-technology assumption Market share coef method

IOTpxpSTA_TCm()[source]

IOT prod x prod Single tech Industry-technology assumption Technical coef method

Module contents

Top-level package for pycirk.