aiphoria 0.0.1__py3-none-any.whl → 0.8.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.
Files changed (42) hide show
  1. aiphoria/__init__.py +59 -0
  2. aiphoria/core/__init__.py +55 -0
  3. aiphoria/core/builder.py +305 -0
  4. aiphoria/core/datachecker.py +1808 -0
  5. aiphoria/core/dataprovider.py +806 -0
  6. aiphoria/core/datastructures.py +1686 -0
  7. aiphoria/core/datavisualizer.py +431 -0
  8. aiphoria/core/datavisualizer_data/LICENSE +21 -0
  9. aiphoria/core/datavisualizer_data/datavisualizer_plotly.html +5561 -0
  10. aiphoria/core/datavisualizer_data/pako.min.js +2 -0
  11. aiphoria/core/datavisualizer_data/plotly-3.0.0.min.js +3879 -0
  12. aiphoria/core/flowmodifiersolver.py +1754 -0
  13. aiphoria/core/flowsolver.py +1472 -0
  14. aiphoria/core/logger.py +113 -0
  15. aiphoria/core/network_graph.py +136 -0
  16. aiphoria/core/network_graph_data/ECHARTS_LICENSE +202 -0
  17. aiphoria/core/network_graph_data/echarts_min.js +45 -0
  18. aiphoria/core/network_graph_data/network_graph.html +76 -0
  19. aiphoria/core/network_graph_data/network_graph.js +1391 -0
  20. aiphoria/core/parameters.py +269 -0
  21. aiphoria/core/types.py +20 -0
  22. aiphoria/core/utils.py +362 -0
  23. aiphoria/core/visualizer_parameters.py +7 -0
  24. aiphoria/data/example_scenario.xlsx +0 -0
  25. aiphoria/example.py +66 -0
  26. aiphoria/lib/docs/dynamic_stock.py +124 -0
  27. aiphoria/lib/odym/modules/ODYM_Classes.py +362 -0
  28. aiphoria/lib/odym/modules/ODYM_Functions.py +1299 -0
  29. aiphoria/lib/odym/modules/__init__.py +1 -0
  30. aiphoria/lib/odym/modules/dynamic_stock_model.py +808 -0
  31. aiphoria/lib/odym/modules/test/DSM_test_known_results.py +762 -0
  32. aiphoria/lib/odym/modules/test/ODYM_Classes_test_known_results.py +107 -0
  33. aiphoria/lib/odym/modules/test/ODYM_Functions_test_known_results.py +136 -0
  34. aiphoria/lib/odym/modules/test/__init__.py +2 -0
  35. aiphoria/runner.py +678 -0
  36. aiphoria-0.8.0.dist-info/METADATA +119 -0
  37. aiphoria-0.8.0.dist-info/RECORD +40 -0
  38. {aiphoria-0.0.1.dist-info → aiphoria-0.8.0.dist-info}/WHEEL +1 -1
  39. aiphoria-0.8.0.dist-info/licenses/LICENSE +21 -0
  40. aiphoria-0.0.1.dist-info/METADATA +0 -5
  41. aiphoria-0.0.1.dist-info/RECORD +0 -5
  42. {aiphoria-0.0.1.dist-info → aiphoria-0.8.0.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,107 @@
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ Created on Mon Aug 11 16:19:39 2014
4
+
5
+ @authors: Stefan Pauliuk, Uni Freiburg, Germany
6
+ """
7
+ import os
8
+ import sys
9
+ # Put location of
10
+ sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..\\..')) + '\\modules') # add ODYM module directory to system path
11
+ #NOTE: Hidden variable __file__ must be know to script for the directory structure to work.
12
+ # Therefore: When first using the model, run the entire script with F5 so that the __file__ variable can be created.
13
+
14
+ import ODYM_Classes as msc # import the ODYM class file
15
+ import ODYM_Functions as msf # import the ODYM function file
16
+ import numpy as np
17
+ import unittest
18
+ import pandas as pd
19
+
20
+
21
+ ###############################################################################
22
+ # Test 1) A simple MFA system with 5 years and 1 chemical element
23
+ ###############################################################################
24
+ # Define results
25
+ MyMFA_Test1_Flowshape1 = (5,2) # shape of a flow in system defined below.
26
+ F_0_1_Values1 = np.array([[1,1],[0,0],[2,2],[1,1],[4,4]]) # Define some arbitrary inflow data for each year and element
27
+ F_1_2_Values1 = np.array([[1,1],[1,1],[32,32],[1,1],[4,4]]) #
28
+ F_2_1_Values1 = np.array([[0,0],[1,1],[30,30],[0,0],[0,0]]) # Define flow back to process 1, make sure mass balance holds.
29
+ F_2_0_Values1 = F_0_1_Values1.copy() # outflow equals inflow as no stocks are present
30
+ Bal_Test1 = np.zeros((5,3,2))
31
+
32
+ # Define dynamic MFA model and fill in values
33
+ """Create Dynamic MFA Models and hand over the pre-defined values."""
34
+ # Define a basic classification with 5 years, 1 element, and unity. 'Time' and 'Element' must be present!
35
+ ModelClassification_Test1 = {}
36
+ ModelClassification_Test1['Unity'] = msc.Classification(Name = 'Unity', Dimension = 'Unity', Items = [1])
37
+ ModelClassification_Test1['Time'] = msc.Classification(Name = 'Time', Dimension = 'Time', Items = [2010,2011,2012,2013,2014])
38
+ ModelClassification_Test1['Element'] = msc.Classification(Name = 'Chem_Elements', Dimension = 'Element', Items = ['All','Fe'])
39
+
40
+ #extract start and end year
41
+ Model_Time_Start = min(ModelClassification_Test1['Time'].Items)
42
+ Model_Time_End = max(ModelClassification_Test1['Time'].Items)
43
+
44
+ #Define model aspects in right order
45
+ Model_Aspects = ['Time','Element','Unity'] # aspects of the model to be considered. Must be the same as the items of the ModelClassification_Test1 dictionary
46
+ # Define a simple index table with the three aspects time, element, and unity, using the modelclassification above.
47
+ IndexTable = pd.DataFrame({'Aspect' : Model_Aspects, # 'Time' and 'Element' must be present!
48
+ 'Description' : ['Time','Element','Unity'],
49
+ 'Dimension' : ['Time','Element','Unity'], # must be the same as 'Dimenstion' in the classification above
50
+ 'Classification': [ModelClassification_Test1[Aspect] for Aspect in Model_Aspects],
51
+ 'IndexLetter' : ['t','e','i']}) # Unique one letter (upper or lower case) indices to be used later for calculations. t for time, e for element
52
+
53
+ IndexTable.set_index('Aspect', inplace = True) # Default indexing of IndexTable, other indices are produced on the fly
54
+
55
+ # Initialize MFA system
56
+ MyMFA_Test1 = msc.MFAsystem(Name = 'TestSystem',
57
+ Geogr_Scope = 'World',
58
+ Unit = 'Mt',
59
+ ProcessList = [],
60
+ FlowDict = {},
61
+ StockDict = {},
62
+ ParameterDict = None,
63
+ Time_Start = Model_Time_Start,
64
+ Time_End = Model_Time_End,
65
+ IndexTable = IndexTable,
66
+ Elements = IndexTable.ix['Element'].Classification.Items)
67
+
68
+ # Add 2 processes to system
69
+ PrL_Name = ['Environment','Process_1','Process_2']
70
+ PrL_Number = [0,1,2]
71
+ for m in range(0, len(PrL_Name)):
72
+ MyMFA_Test1.ProcessList.append(msc.Process(Name = PrL_Name[m], ID = PrL_Number[m]))
73
+
74
+ # Define 4 flows by symbol and names
75
+ MyMFA_Test1.FlowDict['F_0_1'] = msc.Flow(Name = 'Input' , P_Start = 0, P_End = 1, Indices = 't,e', Values=None, Uncert=None)
76
+ MyMFA_Test1.FlowDict['F_1_2'] = msc.Flow(Name = 'Processed input' , P_Start = 1, P_End = 2, Indices = 't,e', Values=None, Uncert=None)
77
+ MyMFA_Test1.FlowDict['F_2_1'] = msc.Flow(Name = 'Sent back to 1' , P_Start = 2, P_End = 1, Indices = 't,e', Values=None, Uncert=None)
78
+ MyMFA_Test1.FlowDict['F_2_0'] = msc.Flow(Name = 'Output' , P_Start = 2, P_End = 0, Indices = 't,e', Values=None, Uncert=None)
79
+
80
+ MyMFA_Test1.Initialize_FlowValues() # Assign empty arrays to flows according to dimensions specified above
81
+
82
+ # Assign values to flows, manually: This prodecure mimicks the calculation of results by solving the model equations
83
+ MyMFA_Test1.FlowDict['F_0_1'].Values = F_0_1_Values1
84
+ MyMFA_Test1.FlowDict['F_1_2'].Values = F_1_2_Values1
85
+ MyMFA_Test1.FlowDict['F_2_1'].Values = F_2_1_Values1
86
+ MyMFA_Test1.FlowDict['F_2_0'].Values = F_2_0_Values1
87
+
88
+ Bal = MyMFA_Test1.MassBalance() # Determine Mass Balance
89
+
90
+ ###############################################################################
91
+ # Tests
92
+ ###############################################################################
93
+
94
+ class KnownResultsTestCase(unittest.TestCase):
95
+
96
+ # For MyMFA_Test1:
97
+ def test_Dimensions_MyMFA_Test1(self):
98
+ """Test Inflow Driven Model with Fixed product lifetime."""
99
+ np.testing.assert_array_equal(MyMFA_Test1.FlowDict['F_1_2'].Values.shape[0],MyMFA_Test1_Flowshape1[0])
100
+ np.testing.assert_array_equal(MyMFA_Test1.FlowDict['F_1_2'].Values.shape[1],MyMFA_Test1_Flowshape1[1])
101
+ np.testing.assert_array_equal(MyMFA_Test1.MassBalance(),Bal_Test1)
102
+
103
+
104
+
105
+
106
+ if __name__ == '__main__':
107
+ unittest.main()
@@ -0,0 +1,136 @@
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ Created on Mon Aug 11 16:19:39 2014
4
+
5
+ @authors: Stefan Pauliuk, Uni Freiburg, Germany
6
+ """
7
+ import os
8
+ import sys
9
+ # Put location of
10
+ sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..\\..')) + '\\modules') # add ODYM module directory to system path
11
+ #NOTE: Hidden variable __file__ must be know to script for the directory structure to work.
12
+ # Therefore: When first using the model, run the entire script with F5 so that the __file__ variable can be created.
13
+
14
+ import ODYM_Classes as msc # import the ODYMM class file
15
+ import ODYM_Functions as msf # import the ODYM function file
16
+ import numpy as np
17
+ import unittest
18
+ import pandas as pd
19
+
20
+
21
+ ###############################################################################
22
+ # Test 1) A simple MFA system with 5 years and 1 chemical element
23
+ ###############################################################################
24
+ # Define results
25
+
26
+ # For TableWithFlowsToShares(Table,axis):
27
+
28
+ TSA = np.array([[1, 2, 1, 2, 4, 1],
29
+ [1, 3, 0, 2, 4, 3],
30
+ [0, 3, 4, 3, 1, 0],
31
+ [1, 4, 3, 2, 1, 0]])
32
+
33
+ TSB = np.array([[0.333333,0.166667,0.125,0.222222,0.4,0.25],
34
+ [0.333333,0.25,0,0.222222,0.4,0.75],
35
+ [0,0.25,0.5,0.333333,0.1,0],
36
+ [0.333333,0.333333,0.375,0.222222,0.1,0]])
37
+
38
+ TSC = np.array([[0.0909091,0.181818,0.0909091,0.181818,0.363636,0.0909091],
39
+ [0.0769231,0.230769,0,0.153846,0.307692,0.230769],
40
+ [0,0.272727,0.363636,0.272727,0.0909091,0],
41
+ [0.0909091,0.363636,0.272727,0.181818,0.0909091,0]])
42
+
43
+ B = msf.TableWithFlowsToShares(TSA,axis=0)
44
+ C = msf.TableWithFlowsToShares(TSA,axis=1)
45
+
46
+ TSAx = np.array([[1, 2, 1, 0, 4, 1],
47
+ [1, 3, 0, 0, 4, 3],
48
+ [0, 3, 4, 0, 1, 0],
49
+ [1, 4, 3, 0, 1, 0]])
50
+
51
+ Bx = msf.TableWithFlowsToShares(TSAx,axis=0)
52
+ Cx = msf.TableWithFlowsToShares(TSAx,axis=1)
53
+
54
+ TSBx = np.array([[0.3333333333333333,0.1666666666666667,0.125,0,0.4,0.25],
55
+ [0.3333333333333333,0.25,0,0,0.4,0.75],
56
+ [0,0.25,0.5,0,0.1,0],
57
+ [0.3333333333333333,0.3333333333333333,0.375,0,0.1,0]])
58
+
59
+ TSCx = np.array([[0.1111111111111111,0.2222222222222222,0.1111111111111111,0,0.4444444444444444,0.1111111111111111],
60
+ [0.09090909090909091,0.2727272727272727,0,0,0.3636363636363636,0.2727272727272727],
61
+ [0,0.375,0.5,0,0.125,0],
62
+ [0.1111111111111111,0.4444444444444444,0.3333333333333333,0,0.1111111111111111,0]])
63
+
64
+ TSAy = np.array([[1, 2, 1, 2, 4, 1],
65
+ [1, 3, 0, 2, 4, 3],
66
+ [0, 3, 4, 3, 1, 0],
67
+ [0, 0, 0, 0, 0, 0]])
68
+
69
+ By = msf.TableWithFlowsToShares(TSAy,axis=0)
70
+ Cy = msf.TableWithFlowsToShares(TSAy,axis=1)
71
+
72
+ TSAzref = np.array([[0.5,0.25,0.2,0.2857142857142857,0.4444444444444444,0.25],
73
+ [0.5,0.375,0,0.2857142857142857,0.4444444444444444,0.75],
74
+ [0,0.375,0.8,0.4285714285714285,0.1111111111111111,0],
75
+ [0,0,0,0,0,0]])
76
+
77
+ TSBzref = np.array([[0.090909090909090911614143238,0.18181818181818182322828648,0.090909090909090911614143238,0.18181818181818182322828648,0.36363636363636364645657295,0.090909090909090911614143238],
78
+ [0.076923076923076927347011633,0.2307692307692307820410349,0,0.15384615384615385469402327,0.30769230769230770938804653,0.2307692307692307820410349],
79
+ [0,0.2727272727272727070868541,0.36363636363636364645657295,0.2727272727272727070868541,0.090909090909090911614143238,0],
80
+ [0,0,0,0,0,0]])
81
+
82
+ TSAz = np.zeros((4,6))
83
+ Bz = msf.TableWithFlowsToShares(TSAz,axis=0)
84
+ Cz = msf.TableWithFlowsToShares(TSAz,axis=1)
85
+
86
+
87
+ ELCTest1 = np.array([[3.59212,0,0,0.00922665,3.58289,0,0,0],
88
+ [0,0,0,0,0,0,0,0],
89
+ [0,0,0,0,0,0,0,0],
90
+ [0.173689,0,0.1719,0,0,0.00178926,0,0],
91
+ [0.0574175,0,0,0,0,0.0574175,0,0],
92
+ [0,0,0,0,0,0,0,0]])
93
+
94
+ ELCTest1res = np.array([[1,0,0,0.002568583066476976,0.9974314169335231,0,0,0],
95
+ [1,0,0,0,0,0,0,1],
96
+ [1,0,0,0,0,0,0,1],
97
+ [1,0,0.9896984994927148,0,0,0.01030150050728525,0,0],
98
+ [1,0,0,0,0,1,0,0],
99
+ [1,0,0,0,0,0,0,1]])
100
+
101
+ #A= msf.DetermineElementComposition_All_Oth(ELCTest1)
102
+
103
+
104
+ ###############################################################################
105
+ # Tests
106
+ ###############################################################################
107
+
108
+ class KnownResultsTestCase(unittest.TestCase):
109
+
110
+ # For MyMFA_Test1:
111
+ def test_ListStringToListNumbers(self):
112
+ """Test the list string to list of numbers function."""
113
+ np.testing.assert_array_equal(msf.ListStringToListNumbers('[1,2,3]'),[1,2,3])
114
+
115
+ def test_MI_Tuple(self):
116
+ """Test the MI_Tuple function."""
117
+ np.testing.assert_array_equal(msf.MI_Tuple(10, [3,4,2,6]),[0,0,1,4])
118
+
119
+ def test_TableWithFlowsToShares(self):
120
+ """Test the TableWithFlowsToShares function."""
121
+ np.testing.assert_array_almost_equal(msf.TableWithFlowsToShares(TSA,axis=0),TSB,6)
122
+ np.testing.assert_array_almost_equal(msf.TableWithFlowsToShares(TSA,axis=1),TSC,6)
123
+ np.testing.assert_array_almost_equal(msf.TableWithFlowsToShares(TSAx,axis=0),TSBx,16)
124
+ np.testing.assert_array_almost_equal(msf.TableWithFlowsToShares(TSAx,axis=1),TSCx,16)
125
+ np.testing.assert_array_almost_equal(msf.TableWithFlowsToShares(TSAy,axis=0),TSAzref,16)
126
+ np.testing.assert_array_almost_equal(msf.TableWithFlowsToShares(TSAy,axis=1),TSBzref,26)
127
+ np.testing.assert_array_equal(msf.TableWithFlowsToShares(TSAz,axis=0),np.zeros((4,6)))
128
+ np.testing.assert_array_equal(msf.TableWithFlowsToShares(TSAz,axis=1),np.zeros((4,6)))
129
+
130
+ def test_DetermineElementComposition_All_Oth(self):
131
+ """Test the DetermineElementComposition_All_Oth function."""
132
+ np.testing.assert_array_almost_equal(msf.DetermineElementComposition_All_Oth(ELCTest1),ELCTest1res,16)
133
+
134
+
135
+ if __name__ == '__main__':
136
+ unittest.main()
@@ -0,0 +1,2 @@
1
+ # -*- coding: utf-8 -*-
2
+