Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
V
VILLASdataprocessing
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Contributor analytics
CI/CD analytics
Repository analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ACS
Public
VILLASframework
VILLASdataprocessing
Commits
65789370
Commit
65789370
authored
7 years ago
by
Jan Dinkelbach
Browse files
Options
Downloads
Patches
Plain Diff
extended modelica read in (use of regex, all vars), added read in examples
parent
b3a0cf1c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
dataprocessing/readtools.py
+15
-4
15 additions, 4 deletions
dataprocessing/readtools.py
dataprocessing/timeseries.py
+7
-2
7 additions, 2 deletions
dataprocessing/timeseries.py
examples/ExamplesReadModelica.py
+45
-0
45 additions, 0 deletions
examples/ExamplesReadModelica.py
with
67 additions
and
6 deletions
dataprocessing/readtools.py
+
15
−
4
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
):
...
...
This diff is collapsed.
Click to expand it.
dataprocessing/timeseries.py
+
7
−
2
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.
"""
ts_diff
=
TimeSeries
(
name
,
ts1
.
time
,
(
ts1
.
values
-
ts2
.
values
))
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
...
...
This diff is collapsed.
Click to expand it.
examples/ExamplesReadModelica.py
0 → 100644
+
45
−
0
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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment