OpenSimula 0.5.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.
Files changed (44) hide show
  1. opensimula/Child.py +19 -0
  2. opensimula/Component.py +214 -0
  3. opensimula/Iterative_process.py +47 -0
  4. opensimula/Message.py +19 -0
  5. opensimula/Parameter_container.py +80 -0
  6. opensimula/Parameters.py +755 -0
  7. opensimula/Project.py +674 -0
  8. opensimula/Simulation.py +212 -0
  9. opensimula/Variable.py +37 -0
  10. opensimula/__init__.py +8 -0
  11. opensimula/components/Building.py +511 -0
  12. opensimula/components/Building_surface.py +318 -0
  13. opensimula/components/Calculator.py +51 -0
  14. opensimula/components/Construction.py +309 -0
  15. opensimula/components/Day_schedule.py +64 -0
  16. opensimula/components/File_data.py +117 -0
  17. opensimula/components/File_met.py +1035 -0
  18. opensimula/components/Frame.py +35 -0
  19. opensimula/components/Glazing.py +122 -0
  20. opensimula/components/HVAC_DX_equipment.py +210 -0
  21. opensimula/components/HVAC_DX_system.py +254 -0
  22. opensimula/components/HVAC_MZW_system.py +554 -0
  23. opensimula/components/HVAC_SZW_system.py +338 -0
  24. opensimula/components/HVAC_coil_equipment.py +206 -0
  25. opensimula/components/HVAC_fan_equipment.py +44 -0
  26. opensimula/components/HVAC_perfect_system.py +137 -0
  27. opensimula/components/Material.py +14 -0
  28. opensimula/components/Opening.py +409 -0
  29. opensimula/components/Opening_type.py +90 -0
  30. opensimula/components/Solar_surface.py +114 -0
  31. opensimula/components/Space.py +388 -0
  32. opensimula/components/Space_type.py +81 -0
  33. opensimula/components/Surface.py +129 -0
  34. opensimula/components/Test_component.py +76 -0
  35. opensimula/components/Week_schedule.py +30 -0
  36. opensimula/components/Year_schedule.py +65 -0
  37. opensimula/components/__init__.py +40 -0
  38. opensimula/visual_3D/Environment_3D.py +257 -0
  39. opensimula/visual_3D/Polygon_3D.py +262 -0
  40. opensimula-0.5.1.dist-info/METADATA +49 -0
  41. opensimula-0.5.1.dist-info/RECORD +44 -0
  42. opensimula-0.5.1.dist-info/WHEEL +5 -0
  43. opensimula-0.5.1.dist-info/licenses/LICENSE +21 -0
  44. opensimula-0.5.1.dist-info/top_level.txt +1 -0
@@ -0,0 +1,212 @@
1
+ from opensimula.Project import Project
2
+ from opensimula.Message import Message
3
+ import pandas as pd
4
+ import plotly.express as px
5
+ from plotly.subplots import make_subplots
6
+ from dash import Dash, callback, Input, Output, html, State
7
+ import dash_ag_grid as dag
8
+ import dash_bootstrap_components as dbc
9
+
10
+
11
+ class Simulation:
12
+ """Simulation environment object for handling projects and print messages"""
13
+
14
+ def __init__(self):
15
+ self._projects_ = []
16
+ self.console_print = True
17
+ self._messages_ = []
18
+
19
+ def new_project(self, project_name):
20
+ """Create new project in the Simulation
21
+
22
+ Args:
23
+ project_name (string): Name of the project to be added to the simulation environment
24
+ """
25
+ if self.project(project_name) is None:
26
+ pro = Project(project_name, self)
27
+ self._projects_.append(pro)
28
+ return pro
29
+ else:
30
+ self.message("Error: There is already a project named: "+project_name)
31
+ return None
32
+
33
+ def del_project(self, project):
34
+ """Delete project from Simulation
35
+
36
+ Args:
37
+ project (Project): Project to be removed from the simulation environment
38
+ """
39
+ self._projects_.remove(project)
40
+
41
+ def project(self, name):
42
+ """Find and return a project using its name
43
+
44
+ Args:
45
+ name (string): name of the project
46
+
47
+ Returns:
48
+ project (Project): project found, None if not found.
49
+ """
50
+ for pro in self._projects_:
51
+ if pro.parameter("name").value == name:
52
+ return pro
53
+ return None
54
+
55
+ def project_list(self):
56
+ """Projects list in the simulation environment
57
+
58
+ Returns:
59
+ projects (Project): List of projects.
60
+ """
61
+ return self._projects_
62
+
63
+ def project_dataframe(self, string_format=False):
64
+ data = pd.DataFrame()
65
+ pro_list = self.project_list()
66
+ parameters = []
67
+ if len(pro_list) > 0:
68
+ for key, par in pro_list[0]._parameters_.items():
69
+ parameters.append(key)
70
+ param_array = []
71
+ for pro in pro_list:
72
+ if string_format:
73
+ param_array.append(str(pro.parameter(key).value))
74
+ else:
75
+ param_array.append(pro.parameter(key).value)
76
+ data[key] = param_array
77
+ return data
78
+
79
+ def _repr_html_(self):
80
+ html = "<h3>Simulation projects:</h3><ul>"
81
+ html += self.project_dataframe().to_html()
82
+ return html
83
+
84
+ def message(self, message):
85
+ """Add new message
86
+
87
+ Store de message in the message_list and print if console_print = True
88
+
89
+ Args:
90
+ message (Message): message to add
91
+ """
92
+ self._messages_.append(message)
93
+ if self.console_print:
94
+ message.print()
95
+
96
+ def message_list(self):
97
+ """Return the list of messages"""
98
+ return self._messages_
99
+
100
+ def plot(self, dates, variables, names=[], axis=[], frequency=None, value="mean"):
101
+ """_summary_
102
+ Draw variables graph (using plotly)
103
+
104
+ Args:
105
+ variables: List of hourly variables
106
+ axis: list of axis y 1 or 2 to use for each variable, empty all in first axis
107
+ frequency (None or str, optional): frequency of the values: None, "H" Hour, "D" Day, "M" Month, "Y" Year . Defaults to None.
108
+ value (str, optional): "mean", "sum", "max" or "min". Defaults to "mean".
109
+
110
+ """
111
+
112
+ series = {}
113
+ series["date"] = dates
114
+ for i in range(len(variables)):
115
+ if i < len(names):
116
+ series[names[i]] = variables[i].values
117
+ else:
118
+ series[variables[i].parent.parameter(
119
+ "name").value+":"+variables[i].key] = variables[i].values
120
+ data = pd.DataFrame(series)
121
+ if frequency is not None:
122
+ if value == "mean":
123
+ data = data.resample(frequency, on='date').mean()
124
+ elif value == "sum":
125
+ data = data.resample(frequency, on='date').sum()
126
+ elif value == "max":
127
+ data = data.resample(frequency, on='date').max()
128
+ elif value == "min":
129
+ data = data.resample(frequency, on='date').min()
130
+ data["date"] = data.index
131
+
132
+ subfig = make_subplots(specs=[[{"secondary_y": True}]])
133
+
134
+ for i in range(len(variables)):
135
+ if i < len(names):
136
+ name = names[i]
137
+ else:
138
+ name = variables[i].parent.parameter(
139
+ "name").value+":"+variables[i].key
140
+ fig = px.line(data, x='date', y=name)
141
+ fig.for_each_trace(lambda t: t.update(name=name))
142
+ fig.update_traces(showlegend=True)
143
+ if i < len(axis):
144
+ if (axis[i] == 2):
145
+ fig.update_traces(yaxis="y2")
146
+ subfig.add_traces(fig.data)
147
+
148
+ subfig.for_each_trace(lambda t: t.update(
149
+ line=dict(color=t.marker.color)))
150
+ # fig.update_traces(showlegend=True)
151
+ subfig.show()
152
+
153
+ def project_editor(self):
154
+ editor = Dash(external_stylesheets=[dbc.themes.BOOTSTRAP])
155
+ df = self.project_dataframe(string_format=True)
156
+ self._n_clicks_new_project_ = 0
157
+ self._n_clicks_del_project_ = 0
158
+ column_definition = [
159
+ {"field": "name", "checkboxSelection": True, "headerCheckboxSelection": True}]
160
+ for i in df.columns:
161
+ if i != "name":
162
+ column_definition.append({"field": i})
163
+
164
+ editor.layout = html.Div([
165
+ dbc.Label("Projects editor: "),
166
+ html.Br(),
167
+ dbc.Button('New project', id='btn-new-project', n_clicks=0),
168
+ dbc.Button('Delete selected projects',
169
+ id='btn-del-project', n_clicks=0, style={"margin-left": "15px"}),
170
+ html.Br(),
171
+ html.Br(),
172
+ dag.AgGrid(
173
+ id="project-table",
174
+ rowData=df.to_dict("records"),
175
+ columnDefs=column_definition,
176
+ columnSize="sizeToFit",
177
+ defaultColDef={"filter": True, "editable": True},
178
+ style={"height": '250px'},
179
+ dashGridOptions={
180
+ "rowSelection": "multiple",
181
+ "suppressRowClickSelection": True,
182
+ "pagination": True,
183
+ })
184
+ ])
185
+
186
+ @callback(
187
+ Output('project-table', 'rowData'),
188
+ Input('project-table', 'cellValueChanged'),
189
+ Input('btn-new-project', 'n_clicks'),
190
+ Input('btn-del-project', 'n_clicks'),
191
+ State('project-table', 'selectedRows'),
192
+ prevent_initial_call=True)
193
+ def update_data(changed, n_clicks_new, n_clicks_del, selectedRows):
194
+ if (self._n_clicks_new_project_ < n_clicks_new):
195
+ self.new_project("new_project_"+str(n_clicks_new))
196
+ self._n_clicks_new_project_ = n_clicks_new
197
+ elif (self._n_clicks_del_project_ < n_clicks_del):
198
+ for row in selectedRows:
199
+ self.del_project(self.project(row["name"]))
200
+ self._n_clicks_del_project_ = n_clicks_del
201
+ else:
202
+ if changed is not None:
203
+ if changed[0]["colId"] == "name":
204
+ self.project(changed[0]['oldValue']).parameter(
205
+ "name").value = changed[0]["value"]
206
+ else:
207
+ self.project(changed[0]['data']["name"]).parameter(
208
+ changed[0]["colId"]).value = changed[0]["value"]
209
+ df_end = self.project_dataframe(string_format=True)
210
+ return df_end.to_dict("records")
211
+
212
+ editor.run(jupyter_height=350)
opensimula/Variable.py ADDED
@@ -0,0 +1,37 @@
1
+ import numpy as np
2
+ from opensimula.Child import Child
3
+
4
+ # _________________ Variable ___________________________
5
+
6
+
7
+ class Variable(Child):
8
+ def __init__(self, key, unit="", description=""):
9
+ Child.__init__(self)
10
+ self._key_ = key
11
+ self._unit_ = unit
12
+ self._description_ = description
13
+ self._values_ = None
14
+ self._sim_ = None
15
+
16
+ @property
17
+ def key(self):
18
+ return self._key_
19
+
20
+ @key.setter
21
+ def key(self, key):
22
+ self._key_ = key
23
+
24
+ @property
25
+ def values(self):
26
+ return self._values_
27
+
28
+ @property
29
+ def unit(self):
30
+ return self._unit_
31
+
32
+ @property
33
+ def description(self):
34
+ return self._description_
35
+
36
+ def initialise(self, n, default=0.0):
37
+ self._values_ = np.full(n, default)
opensimula/__init__.py ADDED
@@ -0,0 +1,8 @@
1
+ """opensimula Package
2
+
3
+ opensimula is a Python Package for perform time simulations
4
+
5
+ """
6
+ from opensimula.Simulation import Simulation
7
+ from opensimula.Iterative_process import Iterative_process
8
+ VERSION = "0.5.1"