mrio-toolbox 1.1.1__py3-none-any.whl → 1.1.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of mrio-toolbox might be problematic. Click here for more details.
- {mrio_toolbox-1.1.1.dist-info → mrio_toolbox-1.1.3.dist-info}/METADATA +2 -2
- mrio_toolbox-1.1.3.dist-info/RECORD +5 -0
- mrio_toolbox-1.1.3.dist-info/top_level.txt +1 -0
- mrio_toolbox/__init__.py +0 -21
- mrio_toolbox/_parts/_Axe.py +0 -539
- mrio_toolbox/_parts/_Part.py +0 -1698
- mrio_toolbox/_parts/__init__.py +0 -7
- mrio_toolbox/_parts/part_operations.py +0 -57
- mrio_toolbox/extractors/__init__.py +0 -20
- mrio_toolbox/extractors/downloaders.py +0 -36
- mrio_toolbox/extractors/emerging/__init__.py +0 -3
- mrio_toolbox/extractors/emerging/emerging_extractor.py +0 -117
- mrio_toolbox/extractors/eora/__init__.py +0 -3
- mrio_toolbox/extractors/eora/eora_extractor.py +0 -132
- mrio_toolbox/extractors/exiobase/__init__.py +0 -3
- mrio_toolbox/extractors/exiobase/exiobase_extractor.py +0 -270
- mrio_toolbox/extractors/extractors.py +0 -79
- mrio_toolbox/extractors/figaro/__init__.py +0 -3
- mrio_toolbox/extractors/figaro/figaro_downloader.py +0 -280
- mrio_toolbox/extractors/figaro/figaro_extractor.py +0 -187
- mrio_toolbox/extractors/gloria/__init__.py +0 -3
- mrio_toolbox/extractors/gloria/gloria_extractor.py +0 -202
- mrio_toolbox/extractors/gtap11/__init__.py +0 -7
- mrio_toolbox/extractors/gtap11/extraction/__init__.py +0 -3
- mrio_toolbox/extractors/gtap11/extraction/extractor.py +0 -129
- mrio_toolbox/extractors/gtap11/extraction/harpy_files/__init__.py +0 -6
- mrio_toolbox/extractors/gtap11/extraction/harpy_files/_header_sets.py +0 -279
- mrio_toolbox/extractors/gtap11/extraction/harpy_files/har_file.py +0 -262
- mrio_toolbox/extractors/gtap11/extraction/harpy_files/har_file_io.py +0 -974
- mrio_toolbox/extractors/gtap11/extraction/harpy_files/header_array.py +0 -300
- mrio_toolbox/extractors/gtap11/extraction/harpy_files/sl4.py +0 -229
- mrio_toolbox/extractors/gtap11/gtap_mrio/__init__.py +0 -6
- mrio_toolbox/extractors/gtap11/gtap_mrio/mrio_builder.py +0 -158
- mrio_toolbox/extractors/icio/__init__.py +0 -3
- mrio_toolbox/extractors/icio/icio_extractor.py +0 -121
- mrio_toolbox/extractors/wiod/__init__.py +0 -3
- mrio_toolbox/extractors/wiod/wiod_extractor.py +0 -143
- mrio_toolbox/mrio.py +0 -899
- mrio_toolbox/msm/__init__.py +0 -6
- mrio_toolbox/msm/multi_scale_mapping.py +0 -863
- mrio_toolbox/utils/__init__.py +0 -3
- mrio_toolbox/utils/converters/__init__.py +0 -5
- mrio_toolbox/utils/converters/pandas.py +0 -247
- mrio_toolbox/utils/converters/xarray.py +0 -130
- mrio_toolbox/utils/formatting/__init__.py +0 -0
- mrio_toolbox/utils/formatting/formatter.py +0 -528
- mrio_toolbox/utils/loaders/__init__.py +0 -7
- mrio_toolbox/utils/loaders/_loader.py +0 -312
- mrio_toolbox/utils/loaders/_loader_factory.py +0 -96
- mrio_toolbox/utils/loaders/_nc_loader.py +0 -184
- mrio_toolbox/utils/loaders/_np_loader.py +0 -112
- mrio_toolbox/utils/loaders/_pandas_loader.py +0 -128
- mrio_toolbox/utils/loaders/_parameter_loader.py +0 -386
- mrio_toolbox/utils/savers/__init__.py +0 -11
- mrio_toolbox/utils/savers/_path_checker.py +0 -37
- mrio_toolbox/utils/savers/_to_folder.py +0 -165
- mrio_toolbox/utils/savers/_to_nc.py +0 -60
- mrio_toolbox-1.1.1.dist-info/RECORD +0 -59
- mrio_toolbox-1.1.1.dist-info/top_level.txt +0 -1
- {mrio_toolbox-1.1.1.dist-info → mrio_toolbox-1.1.3.dist-info}/WHEEL +0 -0
- {mrio_toolbox-1.1.1.dist-info → mrio_toolbox-1.1.3.dist-info}/licenses/LICENSE +0 -0
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
"""
|
|
3
|
-
Created on Wed May 11 16:15:09 2022
|
|
4
|
-
Major modifications on 04.02.2025 by wirth
|
|
5
|
-
|
|
6
|
-
Load and convert ICIO MRIO files.
|
|
7
|
-
Please put the Readme excel file in the same folder as the data and adjust the filename in the code.
|
|
8
|
-
|
|
9
|
-
Supports ICIO 2021 in csv format
|
|
10
|
-
https://www.oecd.org/sti/ind/inter-country-input-output-tables.htm
|
|
11
|
-
|
|
12
|
-
@author: beaufils and wirth
|
|
13
|
-
"""
|
|
14
|
-
|
|
15
|
-
import os
|
|
16
|
-
import logging
|
|
17
|
-
import pandas as pd
|
|
18
|
-
|
|
19
|
-
from mrio_toolbox import MRIO, Part
|
|
20
|
-
from mrio_toolbox.utils.savers._to_nc import save_to_nc
|
|
21
|
-
|
|
22
|
-
log = logging.getLogger(__name__)
|
|
23
|
-
|
|
24
|
-
def extract_icio(year, source, destination, extended=False):
|
|
25
|
-
"""
|
|
26
|
-
Extract and convert ICIO MRIO data to NetCDF format for use with mrio_toolbox.
|
|
27
|
-
|
|
28
|
-
This function loads ICIO tables and associated labels from raw OECD files,
|
|
29
|
-
processes them, and stores the result as a NetCDF file. It supports both
|
|
30
|
-
standard and extended ICIO formats (where China and Mexico are split).
|
|
31
|
-
|
|
32
|
-
Parameters
|
|
33
|
-
----------
|
|
34
|
-
year : str
|
|
35
|
-
Year of the ICIO data to load (e.g., "2021").
|
|
36
|
-
source : path-like
|
|
37
|
-
Path to the folder containing the raw ICIO data and ReadMe Excel file.
|
|
38
|
-
extended : bool, optional
|
|
39
|
-
If True, loads the extended version of the ICIO tables (China and Mexico split).
|
|
40
|
-
If False (default), loads the standard version.
|
|
41
|
-
|
|
42
|
-
Notes
|
|
43
|
-
-----
|
|
44
|
-
- The ReadMe Excel file must be present in the same source folder as the xlsx data file.
|
|
45
|
-
- Output filenames are automatically generated based on the year and format.
|
|
46
|
-
"""
|
|
47
|
-
|
|
48
|
-
#Check source path
|
|
49
|
-
if not os.path.exists(source):
|
|
50
|
-
log.error(f"{os.path.abspath(source)} does not exist.")
|
|
51
|
-
raise NotADirectoryError(f"{os.path.abspath(source)} does not exist.")
|
|
52
|
-
|
|
53
|
-
#Check destination path
|
|
54
|
-
if not os.path.exists(destination):
|
|
55
|
-
log.info(f"{os.path.abspath(
|
|
56
|
-
destination)} does not exist. Creating directory.")
|
|
57
|
-
os.makedirs(destination)
|
|
58
|
-
|
|
59
|
-
# Adapt the filenames based on the extended parameter
|
|
60
|
-
if extended:
|
|
61
|
-
readme_filename = os.path.join(source, "ReadMe_ICIO_extended.xlsx")
|
|
62
|
-
data_filename = os.path.join(source, f"{year}.csv")
|
|
63
|
-
else:
|
|
64
|
-
readme_filename = os.path.join(source,"ReadMe_ICIO_small.xlsx")
|
|
65
|
-
data_filename = os.path.join(source, f"{year}_SML.csv")
|
|
66
|
-
|
|
67
|
-
# Load the labels
|
|
68
|
-
countries = pd.read_excel(readme_filename, sheet_name='Area_Activities', header=2)['countries'].dropna().to_list()
|
|
69
|
-
# Filter out everything in parenthesis, such as the additional references (1) and (2) for Israel and Cyprus
|
|
70
|
-
# as well as (People's Republic of China) for China and (People's Democratic Republic) for Lao
|
|
71
|
-
countries = [country.split('(')[0].strip() for country in countries]
|
|
72
|
-
sectors = pd.read_excel(readme_filename, sheet_name='Area_Activities', header=2)['Industry'].dropna().to_list()
|
|
73
|
-
df = pd.read_excel(readme_filename, sheet_name='ColItems',header=3)
|
|
74
|
-
index = df[df["Sector code"] == "Final demand items"].index[0]
|
|
75
|
-
y_labs = df.iloc[index:,4].to_list()
|
|
76
|
-
va_labs = ["Taxes less subsidies on intermediate and final products", "Value added at basic prices"]
|
|
77
|
-
labels = {
|
|
78
|
-
"countries": countries,
|
|
79
|
-
"sectors": sectors,
|
|
80
|
-
"y_labs": y_labs,
|
|
81
|
-
"va_labs": va_labs
|
|
82
|
-
}
|
|
83
|
-
if extended:
|
|
84
|
-
countries_y = countries[:-4] # remove MX1, MX2, CN1, CN2
|
|
85
|
-
labels["countries_y"] = countries_y
|
|
86
|
-
|
|
87
|
-
# Extract the raw data
|
|
88
|
-
s,c = len(sectors),len(countries)
|
|
89
|
-
raw = pd.read_csv(data_filename, header=0,index_col=0).to_numpy()
|
|
90
|
-
tables = {}
|
|
91
|
-
tables["t"] = raw[:c*s,:c*s]
|
|
92
|
-
tables["y"] = raw[:c*s,c*s:-1] # last column is cumulative output
|
|
93
|
-
tables["va"] = raw[c*s:-1,:c*s]
|
|
94
|
-
tables["vay"] = raw[c*s:-1,c*s:-1]
|
|
95
|
-
|
|
96
|
-
# Build MRIO object
|
|
97
|
-
m = MRIO()
|
|
98
|
-
m.add_dimensions(labels)
|
|
99
|
-
m.parts["t"] = m.new_part(name="t", data= tables["t"],
|
|
100
|
-
dimensions = [["countries","sectors"],["countries", "sectors"]])
|
|
101
|
-
m.parts["va"] = m.new_part(name="va", data= tables["va"],
|
|
102
|
-
dimensions = ["va_labs",["countries", "sectors"]])
|
|
103
|
-
if extended:
|
|
104
|
-
m.parts["y"] = m.new_part(name="y", data= tables["y"],
|
|
105
|
-
dimensions = [["countries","sectors"],["countries_y", "y_labs"]])
|
|
106
|
-
m.parts["vay"] = m.new_part(name="vay", data= tables["vay"],
|
|
107
|
-
dimensions = ["va_labs",["countries_y", "y_labs"]])
|
|
108
|
-
else:
|
|
109
|
-
m.parts["y"] = m.new_part(name="y",data= tables["y"],
|
|
110
|
-
dimensions = [["countries","sectors"],["countries", "y_labs"]])
|
|
111
|
-
m.parts["vay"] = m.new_part(name="vay", data= tables["vay"],
|
|
112
|
-
dimensions = ["va_labs",["countries", "y_labs"]])
|
|
113
|
-
|
|
114
|
-
# Save the mrio object to a NetCDF file
|
|
115
|
-
if extended:
|
|
116
|
-
destination = os.path.join(destination, f"icio_year{year}_extended.nc")
|
|
117
|
-
else:
|
|
118
|
-
destination = os.path.join(destination, f"icio_year{year}.nc")
|
|
119
|
-
save_to_nc(m, destination, overwrite=False)
|
|
120
|
-
|
|
121
|
-
|
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Extractor for WIOD 2016 files.
|
|
3
|
-
|
|
4
|
-
This script extracts data from WIOD xlsb files and converts them to NetCDF files
|
|
5
|
-
for further use with the MRIO toolbox.
|
|
6
|
-
|
|
7
|
-
Supports WIOD 2016 in Excel format
|
|
8
|
-
https://www.rug.nl/ggdc/valuechain/wiod/wiod-2016-release
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
Created on 08.01, 2024
|
|
12
|
-
@author: wirth, based on code of beaufils
|
|
13
|
-
"""
|
|
14
|
-
|
|
15
|
-
import os
|
|
16
|
-
import logging
|
|
17
|
-
import pandas as pd
|
|
18
|
-
from mrio_toolbox import MRIO
|
|
19
|
-
from mrio_toolbox.utils.savers._to_nc import save_to_nc
|
|
20
|
-
|
|
21
|
-
log = logging.getLogger(__name__)
|
|
22
|
-
|
|
23
|
-
def extract_wiod(
|
|
24
|
-
year,
|
|
25
|
-
source):
|
|
26
|
-
"""
|
|
27
|
-
Extract WIOD data.
|
|
28
|
-
|
|
29
|
-
Loads WIOD tables and labels and store them as NetCDF for further use with
|
|
30
|
-
the mrio_toolbox library.
|
|
31
|
-
|
|
32
|
-
Parameters
|
|
33
|
-
----------
|
|
34
|
-
year : str
|
|
35
|
-
Data year to load.
|
|
36
|
-
parts : str
|
|
37
|
-
Data blocks to load:
|
|
38
|
-
basic : T, Y
|
|
39
|
-
all : T, Y, VA, QT, QY
|
|
40
|
-
source : path-like
|
|
41
|
-
Path to folder where raw data is stored
|
|
42
|
-
"""
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
#Check source path
|
|
46
|
-
if not os.path.exists(source):
|
|
47
|
-
log.error(f"{os.path.abspath(source)} does not exist.")
|
|
48
|
-
raise NotADirectoryError(f"{os.path.abspath(source)} does not exist.")
|
|
49
|
-
|
|
50
|
-
# WIOD 2016 comes with:
|
|
51
|
-
# - 43 countries + ROW
|
|
52
|
-
# - 56 sectors
|
|
53
|
-
# - 5 final demand categories
|
|
54
|
-
# - 6 value added category, including 5 tax categories
|
|
55
|
-
c,s,y,va = 44,56,5,6
|
|
56
|
-
|
|
57
|
-
log.info("Start loading")
|
|
58
|
-
|
|
59
|
-
tables = {}
|
|
60
|
-
raw = load_raw_WIOD(source, year)
|
|
61
|
-
countries, sectors, y_labs, va_labs, = [],[],[],[]
|
|
62
|
-
labels = raw.columns
|
|
63
|
-
for i in range(c):
|
|
64
|
-
countries.append(labels[i*s][2].strip())
|
|
65
|
-
for i in range(s):
|
|
66
|
-
sectors.append(labels[i][1].strip())
|
|
67
|
-
for i in range(y):
|
|
68
|
-
y_labs.append(labels[s*c + i][1].strip())
|
|
69
|
-
for i in range(va):
|
|
70
|
-
va_labs.append(raw.index[s*c + 1 + i][1].strip())
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
raw = raw.to_numpy()
|
|
74
|
-
parts = ["t","y","va","vay"]
|
|
75
|
-
|
|
76
|
-
for part in parts:
|
|
77
|
-
if part == "t":
|
|
78
|
-
tables[part] = raw[:c*s,:c*s]
|
|
79
|
-
elif part == "y":
|
|
80
|
-
tables[part] = raw[:c*s,c*s:-1]
|
|
81
|
-
elif part == "va":
|
|
82
|
-
tables[part] = raw[c*s+1:-1,:c*s]
|
|
83
|
-
elif part == "vay":
|
|
84
|
-
tables[part] = raw[c*s+1:-1,c*s:-1]
|
|
85
|
-
|
|
86
|
-
# build an MRIO object from labels and tables
|
|
87
|
-
m = MRIO()
|
|
88
|
-
labels = {
|
|
89
|
-
"countries" : countries,
|
|
90
|
-
"sectors" : sectors,
|
|
91
|
-
"y_labs" : y_labs,
|
|
92
|
-
"va_labs" : va_labs, # including 5 tax categories
|
|
93
|
-
}
|
|
94
|
-
m.add_dimensions(labels)
|
|
95
|
-
|
|
96
|
-
m.parts["t"] = m.new_part(name="t",
|
|
97
|
-
data= tables["t"],
|
|
98
|
-
dimensions = [["countries","sectors"],["countries", "sectors"]])
|
|
99
|
-
m.parts["y"] = m.new_part(name="y",
|
|
100
|
-
data= tables["y"],
|
|
101
|
-
dimensions = [["countries","sectors"],["countries", "y_labs"]])
|
|
102
|
-
m.parts["va"] = m.new_part(name="va",
|
|
103
|
-
data= tables["va"],
|
|
104
|
-
dimensions = ["va_labs",["countries", "sectors"]])
|
|
105
|
-
m.parts["vay"] = m.new_part(name="vay",
|
|
106
|
-
data= tables["vay"],
|
|
107
|
-
dimensions = ["va_labs",["countries", "y_labs"]])
|
|
108
|
-
|
|
109
|
-
m.name = f"wiod16_{year}"
|
|
110
|
-
return m
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
def load_raw_WIOD(path, year,release=16):
|
|
114
|
-
"""
|
|
115
|
-
Load the raw WIOD matrix
|
|
116
|
-
|
|
117
|
-
Parameters
|
|
118
|
-
----------
|
|
119
|
-
year : int-like
|
|
120
|
-
release : int-like, optional
|
|
121
|
-
Version of the WIOD database. The default is 2016.
|
|
122
|
-
|
|
123
|
-
Returns
|
|
124
|
-
-------
|
|
125
|
-
Pandas DataFrame
|
|
126
|
-
Full WIOD table as pandas DataFrame.
|
|
127
|
-
|
|
128
|
-
"""
|
|
129
|
-
#Check source path
|
|
130
|
-
|
|
131
|
-
path = os.path.join(path, f'WIOT{year}_Nov{release}_ROW.xlsb')
|
|
132
|
-
if not os.path.exists(path):
|
|
133
|
-
log.error(f"{os.path.abspath(path)} does not exist.")
|
|
134
|
-
raise NotADirectoryError(f"{os.path.abspath(path)} does not exist.")
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
return pd.read_excel(path, header=[2,3,4,5],index_col=[0,1,2,3])
|
|
138
|
-
|
|
139
|
-
if __name__ == "__main__":
|
|
140
|
-
extract_wiod(year=2014,
|
|
141
|
-
release=16,
|
|
142
|
-
source='/home/florian/job_merkator_institut/MRIO Projects/MRIOs/WIOD 2016 release',
|
|
143
|
-
destination="/home/florian/job_merkator_institut/MRIO Projects/MRIOs/netCDF objects")
|