mrio-toolbox 1.0.0__py3-none-any.whl → 1.1.1__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.

Files changed (59) hide show
  1. mrio_toolbox/__init__.py +18 -2
  2. mrio_toolbox/_parts/_Axe.py +95 -37
  3. mrio_toolbox/_parts/_Part.py +264 -70
  4. mrio_toolbox/_parts/__init__.py +4 -0
  5. mrio_toolbox/_parts/part_operations.py +24 -17
  6. mrio_toolbox/extractors/__init__.py +20 -0
  7. mrio_toolbox/extractors/downloaders.py +36 -0
  8. mrio_toolbox/extractors/emerging/__init__.py +3 -0
  9. mrio_toolbox/extractors/emerging/emerging_extractor.py +117 -0
  10. mrio_toolbox/extractors/eora/__init__.py +3 -0
  11. mrio_toolbox/extractors/eora/eora_extractor.py +132 -0
  12. mrio_toolbox/extractors/exiobase/__init__.py +3 -0
  13. mrio_toolbox/extractors/exiobase/exiobase_extractor.py +270 -0
  14. mrio_toolbox/extractors/extractors.py +79 -0
  15. mrio_toolbox/extractors/figaro/__init__.py +3 -0
  16. mrio_toolbox/extractors/figaro/figaro_downloader.py +280 -0
  17. mrio_toolbox/extractors/figaro/figaro_extractor.py +187 -0
  18. mrio_toolbox/extractors/gloria/__init__.py +3 -0
  19. mrio_toolbox/extractors/gloria/gloria_extractor.py +202 -0
  20. mrio_toolbox/extractors/gtap11/__init__.py +7 -0
  21. mrio_toolbox/extractors/gtap11/extraction/__init__.py +3 -0
  22. mrio_toolbox/extractors/gtap11/extraction/extractor.py +129 -0
  23. mrio_toolbox/extractors/gtap11/extraction/harpy_files/__init__.py +6 -0
  24. mrio_toolbox/extractors/gtap11/extraction/harpy_files/_header_sets.py +279 -0
  25. mrio_toolbox/extractors/gtap11/extraction/harpy_files/har_file.py +262 -0
  26. mrio_toolbox/extractors/gtap11/extraction/harpy_files/har_file_io.py +974 -0
  27. mrio_toolbox/extractors/gtap11/extraction/harpy_files/header_array.py +300 -0
  28. mrio_toolbox/extractors/gtap11/extraction/harpy_files/sl4.py +229 -0
  29. mrio_toolbox/extractors/gtap11/gtap_mrio/__init__.py +6 -0
  30. mrio_toolbox/extractors/gtap11/gtap_mrio/mrio_builder.py +158 -0
  31. mrio_toolbox/extractors/icio/__init__.py +3 -0
  32. mrio_toolbox/extractors/icio/icio_extractor.py +121 -0
  33. mrio_toolbox/extractors/wiod/__init__.py +3 -0
  34. mrio_toolbox/extractors/wiod/wiod_extractor.py +143 -0
  35. mrio_toolbox/mrio.py +254 -94
  36. mrio_toolbox/msm/__init__.py +6 -0
  37. mrio_toolbox/msm/multi_scale_mapping.py +863 -0
  38. mrio_toolbox/utils/__init__.py +3 -0
  39. mrio_toolbox/utils/converters/__init__.py +3 -0
  40. mrio_toolbox/utils/converters/pandas.py +8 -6
  41. mrio_toolbox/utils/converters/xarray.py +2 -13
  42. mrio_toolbox/utils/formatting/__init__.py +0 -0
  43. mrio_toolbox/utils/formatting/formatter.py +528 -0
  44. mrio_toolbox/utils/loaders/__init__.py +4 -0
  45. mrio_toolbox/utils/loaders/_loader.py +60 -4
  46. mrio_toolbox/utils/loaders/_loader_factory.py +22 -1
  47. mrio_toolbox/utils/loaders/_nc_loader.py +37 -1
  48. mrio_toolbox/utils/loaders/_pandas_loader.py +29 -3
  49. mrio_toolbox/utils/loaders/_parameter_loader.py +61 -16
  50. mrio_toolbox/utils/savers/__init__.py +3 -0
  51. mrio_toolbox/utils/savers/_path_checker.py +25 -7
  52. mrio_toolbox/utils/savers/_to_folder.py +6 -1
  53. mrio_toolbox/utils/savers/_to_nc.py +26 -18
  54. {mrio_toolbox-1.0.0.dist-info → mrio_toolbox-1.1.1.dist-info}/METADATA +10 -6
  55. mrio_toolbox-1.1.1.dist-info/RECORD +59 -0
  56. {mrio_toolbox-1.0.0.dist-info → mrio_toolbox-1.1.1.dist-info}/WHEEL +1 -1
  57. mrio_toolbox-1.0.0.dist-info/RECORD +0 -26
  58. {mrio_toolbox-1.0.0.dist-info → mrio_toolbox-1.1.1.dist-info/licenses}/LICENSE +0 -0
  59. {mrio_toolbox-1.0.0.dist-info → mrio_toolbox-1.1.1.dist-info}/top_level.txt +0 -0
mrio_toolbox/__init__.py CHANGED
@@ -1,5 +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
+
1
12
  from mrio_toolbox.mrio import MRIO
2
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
3
16
 
4
- __all__ = ["MRIO","load_part",
5
- "Part"]
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
- """Define an Axe that holds the labels and dimensions for an MRIO part
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
- Dict of labels for each level of the Axe.
24
- The levels are interpreted in the order of the keys.
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
- Dict of groupings for each level of the Axe.
28
- Grouping of labels into larger categories (e.g countries into zones).
29
- If groupings contain references not in the labels, these are removed.
30
- name : str
31
- Name of the axis
32
- If left empty, a name is generated automatically
33
-
34
- Attributes
35
- ----------
36
- labels : dict
37
- Dict of labels for each level of the Axe.
38
- levels : int
39
- Number of levels in the Axe.
40
- dims : list of int
41
- Number of labels for each level.
42
- dimensions : list of str
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
- for key in self.dimensions:
305
- labels.append(self.labels[key])
306
- return labels
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[new] = self.labels.pop(old)
437
- self.mappings[new] = self.mappings.pop(old)
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 replace_label(self,name,labels):
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)