Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
ACS
Public
VILLASframework
VILLASdataprocessing
Commits
65789370
Commit
65789370
authored
Dec 07, 2017
by
Jan Dinkelbach
Browse files
extended modelica read in (use of regex, all vars), added read in examples
parent
b3a0cf1c
Changes
3
Show whitespace changes
Inline
Side-by-side
dataprocessing/readtools.py
View file @
65789370
import
numpy
as
np
import
pandas
as
pd
from
.timeseries
import
*
import
re
def
read_timeseries_Modelica
(
filename
,
timeseries_names
=
None
):
def
read_timeseries_Modelica
(
filename
,
timeseries_names
=
None
,
is_regex
=
False
):
from
modelicares
import
SimRes
sim
=
SimRes
(
filename
)
if
timeseries_names
is
None
:
# No trajectory names specified, thus read in all
print
(
'TBD'
)
if
timeseries_names
is
None
and
is_regex
is
False
:
# No trajectory names or regex specified, thus read in all
timeseries
=
[]
for
name
in
sim
.
names
():
timeseries
.
append
(
TimeSeries
(
name
,
sim
(
name
).
times
(),
sim
(
name
).
values
()))
elif
is_regex
is
True
:
# Read in variables which match with regex
timeseries
=
[]
p
=
re
.
compile
(
timeseries_names
)
timeseries_names
=
[
name
for
name
in
sim
.
names
()
if
p
.
search
(
name
)]
timeseries_names
.
sort
()
for
name
in
timeseries_names
:
timeseries
.
append
(
TimeSeries
(
name
,
sim
(
name
).
times
(),
sim
(
name
).
values
()))
else
:
# Read in specified time series
if
not
isinstance
(
timeseries_names
,
list
):
...
...
dataprocessing/timeseries.py
View file @
65789370
...
...
@@ -14,9 +14,14 @@ class TimeSeries:
@
staticmethod
def
diff
(
name
,
ts1
,
ts2
):
"""Returns difference between values of two Timeseries objects.
Assumes the same time steps for both timeseries.
"""
if
ts1
.
time
==
ts2
.
time
:
ts_diff
=
TimeSeries
(
name
,
ts1
.
time
,
(
ts1
.
values
-
ts2
.
values
))
else
:
# different timestamps, common time vector and interpolation required before substraction
time
=
sorted
(
set
(
list
(
ts1
.
time
)
+
list
(
ts2
.
time
)))
interp_vals_ts1
=
np
.
interp
(
time
,
ts1
.
time
,
ts1
.
values
)
interp_vals_ts2
=
np
.
interp
(
time
,
ts2
.
time
,
ts2
.
values
)
ts_diff
=
TimeSeries
(
name
,
time
,
(
interp_vals_ts2
-
interp_vals_ts1
))
return
ts_diff
...
...
examples/ExamplesReadModelica.py
0 → 100644
View file @
65789370
from
dataprocessing.readtools
import
*
from
dataprocessing.plottools
import
*
import
matplotlib.pyplot
as
plt
# Example 1: read in single variable included in the Modelica results file
voltage_node126
=
read_timeseries_Modelica
(
r
"\\tsclient\N\Research\German Public\ACS0049_SINERGIEN_bsc\Data\WorkData\SimulationResults\IEEE European\Single_scenario_fixed_PV\IEEEEuropean_60.mat"
,
timeseries_names
=
"N126.Vrel"
)
plt
.
figure
(
1
,
figsize
=
(
12
,
8
))
set_timeseries_labels
(
voltage_node126
,
"voltage N126"
)
plt
.
plot
(
voltage_node126
.
time
/
3600
,
voltage_node126
.
values
,
label
=
voltage_node126
.
label
)
plt
.
legend
()
plt
.
show
(
block
=
True
)
# Example 2: read in multiple variables defined in a list
voltage_two_nodes
=
read_timeseries_Modelica
(
r
"\\tsclient\N\Research\German Public\ACS0049_SINERGIEN_bsc\Data\WorkData\SimulationResults\IEEE European\Single_scenario_fixed_PV\IEEEEuropean_60.mat"
,
timeseries_names
=
[
"N127.Vrel"
,
"N128.Vrel"
])
plt
.
figure
(
2
,
figsize
=
(
12
,
8
))
plt
.
plot
(
voltage_two_nodes
[
0
].
time
/
3600
,
voltage_two_nodes
[
0
].
values
,
label
=
voltage_two_nodes
[
0
].
label
)
plt
.
plot
(
voltage_two_nodes
[
1
].
time
/
3600
,
voltage_two_nodes
[
1
].
values
,
label
=
voltage_two_nodes
[
1
].
label
)
plt
.
legend
()
plt
.
show
(
block
=
True
)
# Example 3: read in all voltages using regular expressions
voltages_all_nodes
=
read_timeseries_Modelica
(
r
"\\tsclient\N\Research\German Public\ACS0049_SINERGIEN_bsc\Data\WorkData\SimulationResults\IEEE European\Single_scenario_fixed_PV\IEEEEuropean_60.mat"
,
timeseries_names
=
'^[^.]*.Vrel$'
,
is_regex
=
True
)
plt
.
figure
(
3
,
figsize
=
(
12
,
8
))
for
i
in
range
(
len
(
voltages_all_nodes
)):
plt
.
plot
(
voltages_all_nodes
[
i
].
time
/
3600
,
voltages_all_nodes
[
i
].
values
,
label
=
voltages_all_nodes
[
i
].
label
)
plt
.
legend
()
plt
.
show
(
block
=
True
)
# Example 4: read in all variables
variables_all
=
read_timeseries_Modelica
(
r
"\\tsclient\N\Research\German Public\ACS0049_SINERGIEN_bsc\Data\WorkData\SimulationResults\IEEE European\Single_scenario_fixed_PV\IEEEEuropean_60.mat"
)
dict_variables_all
=
{}
for
ts
in
variables_all
:
dict_variables_all
[
ts
.
name
]
=
ts
plt
.
figure
(
4
,
figsize
=
(
12
,
8
))
plt
.
plot
(
dict_variables_all
[
"L12.Irel"
].
time
/
3600
,
dict_variables_all
[
"L12.Irel"
].
values
,
label
=
dict_variables_all
[
"L12.Irel"
].
label
)
plt
.
legend
()
plt
.
show
(
block
=
True
)
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment