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
eaca9430
Commit
eaca9430
authored
5 years ago
by
Junjie Zhang
Browse files
Options
Downloads
Patches
Plain Diff
update plottools and timeseries
parent
349f33b4
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
villas/dataprocessing/plottools.py
+13
-8
13 additions, 8 deletions
villas/dataprocessing/plottools.py
villas/dataprocessing/timeseries.py
+29
-5
29 additions, 5 deletions
villas/dataprocessing/timeseries.py
with
42 additions
and
13 deletions
villas/dataprocessing/plottools.py
+
13
−
8
View file @
eaca9430
import
matplotlib.pyplot
as
plt
import
numpy
as
np
from
.timeseries
import
*
import
scipy.signal
as
signal
def
plot_timeseries
(
figure_id
,
timeseries
,
plt_linestyle
=
'
-
'
,
plt_linewidth
=
2
,
plt_color
=
None
,
plt_legend_loc
=
'
lower right
'
):
def
plot_timeseries
(
figure_id
,
timeseries
,
marker
=
'
None
'
,
plt_linestyle
=
'
-
'
,
plt_linewidth
=
2
,
plt_color
=
None
,
plt_legend_loc
=
'
lower right
'
,
plt_legend
=
True
,
inlineLabel
=
False
):
"""
This function plots either a single timeseries or several timeseries in the figure defined by figure_id.
Several timeseries (handed over in a list) are plotted in several subplots.
...
...
@@ -12,20 +13,24 @@ def plot_timeseries(figure_id, timeseries, plt_linestyle='-', plt_linewidth=2, p
plt
.
figure
(
figure_id
)
if
not
isinstance
(
timeseries
,
list
):
if
plt_color
:
plt
.
plot
(
timeseries
.
time
,
timeseries
.
values
,
linestyle
=
plt_linestyle
,
label
=
timeseries
.
label
,
linewidth
=
plt_linewidth
,
color
=
plt_color
)
plt
.
plot
(
timeseries
.
time
,
timeseries
.
values
,
marker
=
marker
,
linestyle
=
plt_linestyle
,
label
=
timeseries
.
label
,
linewidth
=
plt_linewidth
,
color
=
plt_color
)
else
:
plt
.
plot
(
timeseries
.
time
,
timeseries
.
values
,
linestyle
=
plt_linestyle
,
label
=
timeseries
.
label
,
linewidth
=
plt_linewidth
)
plt
.
plot
(
timeseries
.
time
,
timeseries
.
values
,
marker
=
marker
,
linestyle
=
plt_linestyle
,
label
=
timeseries
.
label
,
linewidth
=
plt_linewidth
)
plt
.
gca
().
autoscale
(
axis
=
'
x
'
,
tight
=
True
)
plt
.
legend
(
loc
=
plt_legend_loc
)
if
(
plt_legend
):
plt
.
legend
(
loc
=
plt_legend_loc
)
else
:
for
ts
in
timeseries
:
plt
.
subplot
(
len
(
timeseries
),
1
,
timeseries
.
index
(
ts
)
+
1
)
if
plt_color
:
plt
.
plot
(
ts
.
time
,
ts
.
values
,
linestyle
=
plt_linestyle
,
label
=
ts
.
label
,
linewidth
=
plt_linewidth
,
color
=
plt_color
)
plt
.
plot
(
ts
.
time
,
ts
.
values
,
marker
=
marker
,
linestyle
=
plt_linestyle
,
label
=
ts
.
label
,
linewidth
=
plt_linewidth
,
color
=
plt_color
)
else
:
plt
.
plot
(
ts
.
time
,
ts
.
values
,
linestyle
=
plt_linestyle
,
label
=
ts
.
label
,
linewidth
=
plt_linewidth
)
plt
.
plot
(
ts
.
time
,
ts
.
values
,
marker
=
marker
,
linestyle
=
plt_linestyle
,
label
=
ts
.
label
,
linewidth
=
plt_linewidth
)
plt
.
gca
().
autoscale
(
axis
=
'
x
'
,
tight
=
True
)
plt
.
legend
()
if
(
plt_legend
):
plt
.
legend
()
if
(
inlineLabel
):
plt
.
text
(
timeseries
.
time
[
-
1
],
timeseries
.
values
[
-
1
],
timeseries
.
label
)
def
set_timeseries_labels
(
timeseries
,
timeseries_labels
):
...
...
@@ -37,4 +42,4 @@ def set_timeseries_labels(timeseries, timeseries_labels):
timeseries
.
label
=
timeseries_labels
else
:
for
ts
in
timeseries
:
ts
.
label
=
timeseries_labels
[
timeseries
.
index
(
ts
)]
ts
.
label
=
timeseries_labels
[
timeseries
.
index
(
ts
)]
\ No newline at end of file
This diff is collapsed.
Click to expand it.
villas/dataprocessing/timeseries.py
+
29
−
5
View file @
eaca9430
import
numpy
as
np
import
cmath
from
scipy.signal
import
hilbert
,
chirp
from
scipy.signal
import
hilbert
,
find_peaks
class
TimeSeries
:
"""
Stores data from different simulation sources.
...
...
@@ -10,7 +10,10 @@ class TimeSeries:
self
.
time
=
np
.
array
(
time
)
self
.
values
=
np
.
array
(
values
)
self
.
name
=
name
self
.
label
=
name
if
not
label
:
self
.
label
=
name
else
:
self
.
label
=
label
def
scale
(
self
,
factor
):
"""
Returns scaled timeseries.
...
...
@@ -18,13 +21,22 @@ class TimeSeries:
ts_scaled
=
TimeSeries
(
self
.
name
+
'
_scl
'
,
self
.
time
,
self
.
values
*
factor
)
return
ts_scaled
def
slice_ts
(
self
,
start_time
,
end_time
):
time_step
=
self
.
time
[
1
]
-
self
.
time
[
0
]
start_index
=
int
(
start_time
/
time_step
)
end_index
=
int
(
end_time
/
time_step
)
slice_time
=
self
.
time
[
start_index
:
end_index
]
slice_values
=
self
.
values
[
start_index
:
end_index
]
ts_slice
=
TimeSeries
(
self
.
name
+
'
_slice
'
,
slice_time
,
slice_values
)
return
ts_slice
def
abs
(
self
):
"""
Calculate absolute value of complex time series.
"""
abs_values
=
[]
for
value
in
self
.
values
:
abs_values
.
append
(
np
.
abs
(
value
))
ts_abs
=
TimeSeries
(
self
.
name
+
'
_abs
'
,
self
.
time
,
abs_values
)
ts_abs
=
TimeSeries
(
self
.
name
+
'
_abs
'
,
self
.
time
,
abs_values
,
self
.
label
+
'
_abs
'
)
return
ts_abs
def
phase
(
self
):
...
...
@@ -33,7 +45,7 @@ class TimeSeries:
phase_values
=
[]
for
value
in
self
.
values
:
phase_values
.
append
(
np
.
angle
(
value
,
deg
=
True
))
ts_phase
=
TimeSeries
(
self
.
name
+
'
_phase
'
,
self
.
time
,
phase_values
)
ts_phase
=
TimeSeries
(
self
.
name
+
'
_phase
'
,
self
.
time
,
phase_values
,
self
.
label
+
'
_phase
'
)
return
ts_phase
def
real
(
self
):
...
...
@@ -239,8 +251,20 @@ class TimeSeries:
duration
=
ts
.
time
.
max
()
samples
=
ts
.
time
.
size
sampling_freq
=
samples
/
duration
analytic_signal
=
hilbert
(
ts
.
abs
().
values
)
analytic_signal
=
hilbert
(
ts
.
values
)
instaneous_phase
=
np
.
unwrap
(
np
.
angle
(
analytic_signal
))
instantaneous_frequency
=
(
np
.
diff
(
instaneous_phase
)
/
(
2.0
*
np
.
pi
)
*
sampling_freq
)
ts_instFreq
=
TimeSeries
(
str
(
ts
.
name
+
"
instFreq
"
),
ts
.
time
[:
-
1
],
instantaneous_frequency
)
return
ts_instFreq
@staticmethod
def
getPeaks
(
ts
,
nom
,
tolerance
):
peaks_
,
properties_
=
find_peaks
(
ts
.
values
,
height
=
nom
+
tolerance
)
ts_peaks
=
TimeSeries
(
str
(
ts
.
name
+
"
.peaks
"
),
ts
.
time
[
peaks_
],
ts
.
values
[
peaks_
])
return
ts_peaks
@staticmethod
def
getDeviation
(
ts
,
nom
,
tolerance
):
dev_
=
np
.
where
(
np
.
abs
(
ts
.
abs
().
values
-
nom
)
>
tolerance
)
ts_dev
=
TimeSeries
(
str
(
ts
.
name
+
"
.peaks
"
),
ts
.
time
[
dev_
],
ts
.
values
[
dev_
])
return
ts_dev
\ 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