mrio-toolbox 1.0.0__py3-none-any.whl → 1.1.2__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.
- __init__.py +21 -0
- {mrio_toolbox/_parts → _parts}/_Axe.py +95 -37
- {mrio_toolbox/_parts → _parts}/_Part.py +346 -111
- _parts/__init__.py +7 -0
- {mrio_toolbox/_parts → _parts}/part_operations.py +24 -17
- extractors/__init__.py +20 -0
- extractors/downloaders.py +36 -0
- extractors/emerging/__init__.py +3 -0
- extractors/emerging/emerging_extractor.py +117 -0
- extractors/eora/__init__.py +3 -0
- extractors/eora/eora_extractor.py +132 -0
- extractors/exiobase/__init__.py +3 -0
- extractors/exiobase/exiobase_extractor.py +270 -0
- extractors/extractors.py +81 -0
- extractors/figaro/__init__.py +3 -0
- extractors/figaro/figaro_downloader.py +280 -0
- extractors/figaro/figaro_extractor.py +187 -0
- extractors/gloria/__init__.py +3 -0
- extractors/gloria/gloria_extractor.py +202 -0
- extractors/gtap11/__init__.py +7 -0
- extractors/gtap11/extraction/__init__.py +3 -0
- extractors/gtap11/extraction/extractor.py +129 -0
- extractors/gtap11/extraction/harpy_files/__init__.py +6 -0
- extractors/gtap11/extraction/harpy_files/_header_sets.py +279 -0
- extractors/gtap11/extraction/harpy_files/har_file.py +262 -0
- extractors/gtap11/extraction/harpy_files/har_file_io.py +974 -0
- extractors/gtap11/extraction/harpy_files/header_array.py +300 -0
- extractors/gtap11/extraction/harpy_files/sl4.py +229 -0
- extractors/gtap11/gtap_mrio/__init__.py +6 -0
- extractors/gtap11/gtap_mrio/mrio_builder.py +158 -0
- extractors/icio/__init__.py +3 -0
- extractors/icio/icio_extractor.py +121 -0
- extractors/wiod/__init__.py +3 -0
- extractors/wiod/wiod_extractor.py +143 -0
- mrio_toolbox/mrio.py → mrio.py +254 -94
- {mrio_toolbox-1.0.0.dist-info → mrio_toolbox-1.1.2.dist-info}/METADATA +11 -7
- mrio_toolbox-1.1.2.dist-info/RECORD +59 -0
- {mrio_toolbox-1.0.0.dist-info → mrio_toolbox-1.1.2.dist-info}/WHEEL +1 -1
- mrio_toolbox-1.1.2.dist-info/top_level.txt +6 -0
- msm/__init__.py +6 -0
- msm/multi_scale_mapping.py +863 -0
- utils/__init__.py +3 -0
- utils/converters/__init__.py +5 -0
- {mrio_toolbox/utils → utils}/converters/pandas.py +5 -6
- {mrio_toolbox/utils → utils}/converters/xarray.py +6 -15
- utils/formatting/formatter.py +527 -0
- utils/loaders/__init__.py +7 -0
- {mrio_toolbox/utils → utils}/loaders/_loader.py +60 -4
- {mrio_toolbox/utils → utils}/loaders/_loader_factory.py +22 -1
- {mrio_toolbox/utils → utils}/loaders/_nc_loader.py +37 -1
- {mrio_toolbox/utils → utils}/loaders/_pandas_loader.py +29 -3
- {mrio_toolbox/utils → utils}/loaders/_parameter_loader.py +61 -16
- {mrio_toolbox/utils → utils}/savers/__init__.py +3 -0
- utils/savers/_path_checker.py +37 -0
- {mrio_toolbox/utils → utils}/savers/_to_folder.py +6 -1
- utils/savers/_to_nc.py +60 -0
- mrio_toolbox/__init__.py +0 -5
- mrio_toolbox/_parts/__init__.py +0 -3
- mrio_toolbox/utils/converters/__init__.py +0 -2
- mrio_toolbox/utils/loaders/__init__.py +0 -3
- mrio_toolbox/utils/savers/_path_checker.py +0 -19
- mrio_toolbox/utils/savers/_to_nc.py +0 -52
- mrio_toolbox-1.0.0.dist-info/RECORD +0 -26
- mrio_toolbox-1.0.0.dist-info/top_level.txt +0 -1
- {mrio_toolbox-1.0.0.dist-info → mrio_toolbox-1.1.2.dist-info/licenses}/LICENSE +0 -0
- {mrio_toolbox/utils → utils/formatting}/__init__.py +0 -0
- {mrio_toolbox/utils → utils}/loaders/_np_loader.py +0 -0
__init__.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"""
|
|
2
|
+
The MRIO toolbox module provides several submodules with different functionalities:
|
|
3
|
+
|
|
4
|
+
- `mrio_toolbox.mrio`: Contains the MRIO class for handling multi-regional input-output data.
|
|
5
|
+
- `mrio_toolbox._parts`: Contains the Part and Axe classes for managing parts of MRIO data.
|
|
6
|
+
- `mrio_toolbox.extractors`: Provides functions to extract raw MRIO data.
|
|
7
|
+
- 'mrio_toolbox._msm': Contains the multi-scale mapping algorithm for mapping PRIMAP data into an MRIO
|
|
8
|
+
- `mrio_toolbox._utils`: Contains utility functions for MRIO loading, saving and converting MRIO data to different formats.
|
|
9
|
+
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from mrio_toolbox.mrio import MRIO
|
|
13
|
+
from mrio_toolbox._parts._Part import Part,load_part
|
|
14
|
+
from mrio_toolbox.extractors import extract_MRIO
|
|
15
|
+
from mrio_toolbox.extractors import download_MRIO
|
|
16
|
+
|
|
17
|
+
__all__ = ["MRIO",
|
|
18
|
+
"load_part",
|
|
19
|
+
"Part",
|
|
20
|
+
"extract_MRIO",
|
|
21
|
+
"download_MRIO"]
|
|
@@ -11,41 +11,93 @@ from copy import deepcopy
|
|
|
11
11
|
|
|
12
12
|
log = logging.getLogger(__name__)
|
|
13
13
|
class Axe:
|
|
14
|
+
"""
|
|
15
|
+
Representation of an Axe object.
|
|
16
|
+
|
|
17
|
+
An Axe holds the labels and dimensions for an MRIO Part. Axes are used
|
|
18
|
+
to slice MRIO Parts based on labels or indices and support multi-level
|
|
19
|
+
indexing and groupings.
|
|
20
|
+
|
|
21
|
+
Instance variables
|
|
22
|
+
------------------
|
|
23
|
+
labels : dict
|
|
24
|
+
Dictionary of labels for each level of the Axe.
|
|
25
|
+
levels : int
|
|
26
|
+
Number of levels in the Axe.
|
|
27
|
+
dims : list of int
|
|
28
|
+
Number of labels for each level.
|
|
29
|
+
dimensions : list of str
|
|
30
|
+
Keys of the labels dictionary, representing the dimensions of the Axe.
|
|
31
|
+
groupings : dict
|
|
32
|
+
Groupings of the labels for each level of the Axe.
|
|
33
|
+
mappings : dict
|
|
34
|
+
Mappings used to convert grouping labels into indices.
|
|
35
|
+
multipliers : dict
|
|
36
|
+
Multipliers used to convert labels into indices.
|
|
37
|
+
name : str
|
|
38
|
+
Name of the Axe.
|
|
39
|
+
|
|
40
|
+
Methods
|
|
41
|
+
-------
|
|
42
|
+
set_labels(labels):
|
|
43
|
+
Set the labels of the Axe.
|
|
44
|
+
update_multipliers():
|
|
45
|
+
Update the multipliers used to convert labels into indices.
|
|
46
|
+
squeeze():
|
|
47
|
+
Remove levels with only one label.
|
|
48
|
+
swap_levels(level1, level2):
|
|
49
|
+
Swap the positions of two levels in the Axe.
|
|
50
|
+
label(as_index=False):
|
|
51
|
+
Generate the labels for the full axis.
|
|
52
|
+
isin(arg, level):
|
|
53
|
+
Check whether an element is in the labels of a given level.
|
|
54
|
+
derive_mappings(groupings=None):
|
|
55
|
+
Update the mappings of the Axe based on the groupings.
|
|
56
|
+
update_groupings(groupings=None):
|
|
57
|
+
Update the groupings of the Axe.
|
|
58
|
+
get(args, labels=False):
|
|
59
|
+
Get the indices corresponding to a selection on the Axe.
|
|
60
|
+
rename_labels(old, new):
|
|
61
|
+
Rename labels in the Axe.
|
|
62
|
+
replace_labels(name, labels):
|
|
63
|
+
Replace a given label in the Axe.
|
|
64
|
+
has_dim(dim):
|
|
65
|
+
Check whether a given dimension is in the Axe.
|
|
66
|
+
__getitem__(*args):
|
|
67
|
+
Indexing is passed to the `get` method.
|
|
68
|
+
__eq__(other):
|
|
69
|
+
Check equality between two Axe objects.
|
|
70
|
+
__len__():
|
|
71
|
+
Get the full label length of the Axe.
|
|
72
|
+
"""
|
|
73
|
+
|
|
14
74
|
def __init__(self,labels,groupings=None,
|
|
15
75
|
name=None):
|
|
16
|
-
"""
|
|
17
|
-
|
|
18
|
-
Axes hold the methods to slice MRIO Parts based on labels or indices.
|
|
76
|
+
"""
|
|
77
|
+
Initialize an Axe object.
|
|
19
78
|
|
|
20
79
|
Parameters
|
|
21
80
|
----------
|
|
22
81
|
labels : dict or list of list of str
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
If a list of list of str is passed, levels are set to 0,1,2...
|
|
82
|
+
Dictionary of labels for each level of the Axe. If a list of lists
|
|
83
|
+
is passed, levels are set to 0, 1, 2, etc.
|
|
26
84
|
groupings : dict, optional
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
If groupings
|
|
30
|
-
name : str
|
|
31
|
-
Name of the
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
Keys of the labels dict.
|
|
44
|
-
|
|
45
|
-
Main methods
|
|
46
|
-
------------
|
|
47
|
-
label : Generate the labels for the full axis
|
|
48
|
-
get : Get the indices of a selection on the Axe
|
|
85
|
+
Dictionary of groupings for each level of the Axe. Groupings define
|
|
86
|
+
how labels are grouped into larger categories (e.g., countries into zones).
|
|
87
|
+
If not provided, groupings are set to the identity.
|
|
88
|
+
name : str, optional
|
|
89
|
+
Name of the Axe. If not provided, a name is generated automatically
|
|
90
|
+
based on the dimensions.
|
|
91
|
+
|
|
92
|
+
Raises
|
|
93
|
+
------
|
|
94
|
+
TypeError
|
|
95
|
+
If the provided labels are not a dictionary or a list of lists.
|
|
96
|
+
|
|
97
|
+
Notes
|
|
98
|
+
-----
|
|
99
|
+
The `labels` parameter defines the structure of the Axe, while the
|
|
100
|
+
`groupings` parameter allows grouping labels into higher-level categories.
|
|
49
101
|
"""
|
|
50
102
|
if isinstance(labels,dict):
|
|
51
103
|
self.labels = labels
|
|
@@ -66,6 +118,7 @@ class Axe:
|
|
|
66
118
|
str(dim) for dim in self.labels.keys()
|
|
67
119
|
] #Dimensions of the Axe
|
|
68
120
|
#Dimensions also save the order of the levels
|
|
121
|
+
self.ndim = len(self.dims)
|
|
69
122
|
self.update_multipliers()
|
|
70
123
|
if groupings is None:
|
|
71
124
|
self.groupings = {i:{} for i in self.dimensions}
|
|
@@ -102,6 +155,7 @@ class Axe:
|
|
|
102
155
|
self.levels = len(self.labels)
|
|
103
156
|
self.dims = [len(dim) for dim in self.labels.values()]
|
|
104
157
|
self.dimensions = list(self.labels.keys())
|
|
158
|
+
self.ndim = len(self.dims)
|
|
105
159
|
|
|
106
160
|
def update_multipliers(self):
|
|
107
161
|
"""
|
|
@@ -125,6 +179,7 @@ class Axe:
|
|
|
125
179
|
self.levels = len(self.labels)
|
|
126
180
|
self.dims = [len(dim) for dim in self.labels.values()]
|
|
127
181
|
self.dimensions = list(self.labels.keys())
|
|
182
|
+
self.ndim = len(self.dims)
|
|
128
183
|
|
|
129
184
|
|
|
130
185
|
def swap_levels(self,level1,level2):
|
|
@@ -299,11 +354,12 @@ class Axe:
|
|
|
299
354
|
return [sum(arg) for arg in itertools.product(*sel)]
|
|
300
355
|
|
|
301
356
|
def get_labels(self):
|
|
302
|
-
"""Get the labels of the Axe"""
|
|
303
|
-
labels
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
357
|
+
"""Get the labels of the Axe as a dict"""
|
|
358
|
+
return {key:self.labels[key] for key in self.dimensions}
|
|
359
|
+
|
|
360
|
+
def get_groupings(self):
|
|
361
|
+
"""Get the groupings of the Axe"""
|
|
362
|
+
return self.groupings
|
|
307
363
|
|
|
308
364
|
def get_labs(self,args):
|
|
309
365
|
"""Extract the labels corresponding to a given selection of multiple levels
|
|
@@ -433,12 +489,14 @@ class Axe:
|
|
|
433
489
|
"""
|
|
434
490
|
if old not in self.labels.keys():
|
|
435
491
|
raise IndexError(f"Label {old} not in the Axe")
|
|
436
|
-
self.labels
|
|
437
|
-
|
|
492
|
+
self.labels = { (new if key == old else key): val
|
|
493
|
+
for key, val in self.labels.items()}
|
|
494
|
+
self.mappints = { (new if key == old else key): val
|
|
495
|
+
for key, val in self.mappings.items()}
|
|
438
496
|
self.dimensions = list(self.labels.keys())
|
|
439
497
|
self.update_multipliers()
|
|
440
498
|
|
|
441
|
-
def
|
|
499
|
+
def replace_labels(self,name,labels):
|
|
442
500
|
"""
|
|
443
501
|
Replace a given label
|
|
444
502
|
|
|
@@ -450,7 +508,7 @@ class Axe:
|
|
|
450
508
|
New labels
|
|
451
509
|
"""
|
|
452
510
|
self.labels.update(labels)
|
|
453
|
-
if name != labels.keys()[0]:
|
|
511
|
+
if name != list(labels.keys())[0]:
|
|
454
512
|
self.labels.pop(name)
|
|
455
513
|
self.dimensions = list(self.labels.keys())
|
|
456
514
|
self.mappings[labels.keys()[0]] = self.mappings.pop(name)
|