mrio-toolbox 1.0.0__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/__init__.py +5 -0
- mrio_toolbox/_parts/_Axe.py +481 -0
- mrio_toolbox/_parts/_Part.py +1504 -0
- mrio_toolbox/_parts/__init__.py +3 -0
- mrio_toolbox/_parts/part_operations.py +50 -0
- mrio_toolbox/mrio.py +739 -0
- mrio_toolbox/utils/__init__.py +0 -0
- mrio_toolbox/utils/converters/__init__.py +2 -0
- mrio_toolbox/utils/converters/pandas.py +245 -0
- mrio_toolbox/utils/converters/xarray.py +141 -0
- mrio_toolbox/utils/loaders/__init__.py +3 -0
- mrio_toolbox/utils/loaders/_loader.py +256 -0
- mrio_toolbox/utils/loaders/_loader_factory.py +75 -0
- mrio_toolbox/utils/loaders/_nc_loader.py +148 -0
- mrio_toolbox/utils/loaders/_np_loader.py +112 -0
- mrio_toolbox/utils/loaders/_pandas_loader.py +102 -0
- mrio_toolbox/utils/loaders/_parameter_loader.py +341 -0
- mrio_toolbox/utils/savers/__init__.py +8 -0
- mrio_toolbox/utils/savers/_path_checker.py +19 -0
- mrio_toolbox/utils/savers/_to_folder.py +160 -0
- mrio_toolbox/utils/savers/_to_nc.py +52 -0
- mrio_toolbox-1.0.0.dist-info/LICENSE +674 -0
- mrio_toolbox-1.0.0.dist-info/METADATA +28 -0
- mrio_toolbox-1.0.0.dist-info/RECORD +26 -0
- mrio_toolbox-1.0.0.dist-info/WHEEL +5 -0
- mrio_toolbox-1.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"""Basic operations on Parts
|
|
2
|
+
|
|
3
|
+
Because of my inexperience in software development,
|
|
4
|
+
I only created this file lately.
|
|
5
|
+
|
|
6
|
+
I will move the relevant methods from the _Part class to this file
|
|
7
|
+
at a later point.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
def reformat(part,new_dimensions):
|
|
11
|
+
"""
|
|
12
|
+
Reshape a Part to match a new dimensions combination
|
|
13
|
+
|
|
14
|
+
Equivalent to a combination of the develop and combine_axes methods.
|
|
15
|
+
|
|
16
|
+
This only works for contiguous dimensions in the current Part,
|
|
17
|
+
without overlapping dimensions.
|
|
18
|
+
For example, if the Part has dimensions:
|
|
19
|
+
[["countries"],["sectors"],["sectors"]]
|
|
20
|
+
The following is allowed:
|
|
21
|
+
[["countries","sectors"],["sectors"]]
|
|
22
|
+
The following is not allowed:
|
|
23
|
+
[["countries"],["sectors","sectors"]]
|
|
24
|
+
[["sectors"],["countries","sectors"]]
|
|
25
|
+
[["sectors","countries"],["sectors"]]
|
|
26
|
+
|
|
27
|
+
Parameters
|
|
28
|
+
----------
|
|
29
|
+
dimensions : list of list of str
|
|
30
|
+
Original dimensions of the Part
|
|
31
|
+
|
|
32
|
+
Returns
|
|
33
|
+
-------
|
|
34
|
+
data : numpy array
|
|
35
|
+
Reshaped data
|
|
36
|
+
axes : list of Axe instances
|
|
37
|
+
Reshaped axes
|
|
38
|
+
|
|
39
|
+
"""
|
|
40
|
+
def formatting_iteration(part,new_dimensions):
|
|
41
|
+
if part.get_dimensions() == new_dimensions:
|
|
42
|
+
return part
|
|
43
|
+
for i,dim in enumerate(part.get_dimensions()):
|
|
44
|
+
if dim != new_dimensions[i]:
|
|
45
|
+
part = part.combine_axes(i,i+len(new_dimensions)-1)
|
|
46
|
+
return formatting_iteration(part,new_dimensions)
|
|
47
|
+
developed = part.develop()
|
|
48
|
+
return formatting_iteration(developed,new_dimensions)
|
|
49
|
+
|
|
50
|
+
|