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.

@@ -0,0 +1,3 @@
1
+ from ._Part import Part,load_part
2
+
3
+ __all__ = ['Part','load_part']
@@ -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
+