# API Reference¶

API references for all modules

## Data input and output¶

### Test system¶

 load_test() Returns a small test MRIO

 download_exiobase3(storage_folder[, years, …]) Downloads EXIOBASE 3 files from Zenodo download_wiod2013(storage_folder[, years, …]) Downloads the 2013 wiod release download_oecd(storage_folder[, version, …]) Downloads the OECD ICIO tables

### Raw data¶

 parse_exiobase1(path) Parse the exiobase1 raw data files. parse_exiobase2(path[, charact, popvector]) Parse the exiobase 2.2.2 source files for the IOSystem parse_exiobase3(path) Parses the public EXIOBASE 3 system generic_exiobase12_parser(exio_files[, system]) Generic EXIOBASE version 1 and 2 parser parse_wiod(path[, year, names, popvector]) Parse the wiod source files for the IOSystem parse_eora26(path[, year, price, country_names]) Parse the Eora26 database parse_oecd(path[, year]) Parse the OECD ICIO tables

### Save data¶

Currently, the full MRIO system can be saved in txt or the python specific binary format (‘pickle’). Both formats work with the same API interface:

 IOSystem.save(path[, table_format, sep, …]) Saving the system to path IOSystem.save_all(path[, table_format, sep, …]) Saves the system and all extensions

Already saved MRIO databases can be archived with

 archive(source, archive[, path_in_arc, …]) Archives a MRIO database as zip file

This functions load IOSystems or individual extensions which have been saved with pymrio before.

 load(path[, include_core, path_in_arc]) Loads a IOSystem or Extension previously saved with pymrio load_all(path[, include_core, subfolders, …]) Loads a full IO system with all extension in path

### Accessing¶

pymrio stores all tables as pandas DataFrames. This data can be accessed with the usual pandas methods. On top of that, the following functions return (in fact yield) several tables at once:

 IOSystem.get_DataFrame([data, with_unit, …]) Yields all panda.DataFrames or there names IOSystem.get_extensions([data]) Yields the extensions or their names

For the extensions, it is also possible to receive all data (F, S, M, D_cba, …) for one specified row.

 Extension.get_row_data(row[, name]) Returns a dict with all available data for a row in the extension

## Exploring the IO System¶

The following functions provide informations about the structure of the IO System and the extensions. The methods work on the IOSystem as well as directly on the Extensions.

 IOSystem.get_regions([entries]) Returns the names of regions in the IOSystem as unique names in order IOSystem.get_sectors([entries]) Names of sectors in the IOSystem as unique names in order IOSystem.get_Y_categories([entries]) Returns names of y cat. IOSystem.get_index([as_dict, grouping_pattern]) Returns the index of the DataFrames in the system IOSystem.set_index(index) Sets the pd dataframe index of all dataframes in the system to index IOSystem.get_gross_trade() Returns the gross bilateral trade flows and totals Extension.get_rows() Returns the name of the rows of the extension

## Calculations¶

### Top level methods¶

The top level level function calc_all checks the IO System and its extensions for missing parts and calculate these. This function calls the specific calculation method for the core system and for the extensions.

 IOSystem.calc_all() Calculates missing parts of the IOSystem and all extensions. IOSystem.calc_system() Calculates the missing part of the core IOSystem Extension.calc_system(x, Y[, Y_agg, L, …]) Calculates the missing part of the extension plus accounts

### Low level matrix calculations¶

The top level functions work by calling the following low level functions. These can also be used independently from the IO System for pandas DataFrames and numpy array.

 calc_x(Z, Y) Calculate the industry output x from the Z and Y matrix calc_Z(A, x) calculate the Z matrix (flows) from A and x calc_A(Z, x) Calculate the A matrix (coefficients) from Z and x calc_L(A) Calculate the Leontief L from A calc_S(F, x) Calculate extensions/factor inputs coefficients calc_F(S, x) Calculate total direct impacts from the impact coefficients calc_M(S, L) Calculate multipliers of the extensions calc_e(M, Y) Calculate total impacts (footprints of consumption Y) calc_accounts(S, L, Y) Calculate sector specific cba and pba based accounts, imp and exp accounts calc_trade_flows

Each pymrio core system object contains a field ‘meta’ which stores meta data as well as changes to the MRIO system. This data is stored as json file in the root of a saved MRIO data and accessible through the attribute ‘.meta’.

 MRIOMetaData([location, description, name, …]) MRIOMetaData.note(entry) Add the passed string as note to the history MRIOMetaData.history All recorded history MRIOMetaData.modification_history All modification history entries MRIOMetaData.note_history All note history entries MRIOMetaData.file_io_history All fileio history entries MRIOMetaData.save([location]) Saves the current status of the metadata

## Modifiying the IO System and its Extensions¶

### Aggregation¶

The IO System method ‘aggregate’ accepts concordance matrices and/or aggregation vectors. The latter can be generated automatically for various aggregation levels for the test system and EXIOBASE 2.

 IOSystem.aggregate([region_agg, sector_agg, …]) Aggregates the IO system. build_agg_vec(agg_vec, **source) Builds an combined aggregation vector based on various classifications

### Characterizing stressors¶

 Extension.characterize(factors[, …]) Characterize stressors

### Analysing the source of impacts¶

 Extension.diag_stressor(stressor[, name, _meta]) Diagonalize one row of the stressor matrix for a flow analysis.

### Changing extensions¶

 IOSystem.remove_extension([ext]) Remove extension from IOSystem concate_extension(*extensions, name) Concatenate extensions parse_exio12_ext(ext_file, index_col, name) Parse an EXIOBASE version 1 or 2 like extension file into pymrio.Extension

### Renaming¶

 IOSystem.rename_regions(regions) Sets new names for the regions IOSystem.rename_sectors(sectors) Sets new names for the sectors IOSystem.rename_Y_categories(Y_categories) Sets new names for the Y_categories

## Report¶

The following method works on the IO System (generating reports for every extension available) or at individual extensions.

 IOSystem.report_accounts(path[, per_region, …]) Generates a report to the given path for all extension

## Visualization¶

 Extension.plot_account(row[, per_capita, …]) Plots D_pba, D_cba, D_imp and D_exp for the specified row (account)

## Miscellaneous¶

 IOSystem.reset_to_flows([force]) Keeps only the absolute values. IOSystem.reset_to_coefficients() Keeps only the coefficient. IOSystem.copy([new_name]) Returns a deep copy of the system