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
8c538bc7
Commit
8c538bc7
authored
5 years ago
by
Junjie Zhang
Browse files
Options
Downloads
Patches
Plain Diff
add methods to get real part of ts, calculation of relative abs error
parent
d4fe7c88
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
villas/dataprocessing/timeseries.py
+37
-0
37 additions, 0 deletions
villas/dataprocessing/timeseries.py
with
37 additions
and
0 deletions
villas/dataprocessing/timeseries.py
+
37
−
0
View file @
8c538bc7
...
...
@@ -35,6 +35,15 @@ class TimeSeries:
ts_phase
=
TimeSeries
(
self
.
name
+
'
_phase
'
,
self
.
time
,
phase_values
)
return
ts_phase
def
real
(
self
):
"""
get the real part of complex time series.
"""
_real
=
[]
for
value
in
self
.
values
:
_real
.
append
(
np
.
real
(
value
))
ts_real
=
TimeSeries
(
self
.
name
+
'
_real
'
,
self
.
time
,
_real
)
return
ts_real
def
phasor
(
self
):
"""
Calculate phasors of complex time series
and return dict with absolute value and phase.
...
...
@@ -141,6 +150,24 @@ class TimeSeries:
"""
return
np
.
sqrt
((
TimeSeries
.
diff
(
'
diff
'
,
ts1
,
ts2
).
values
**
2
).
mean
())
@staticmethod
def
max_abs_err
(
ts1
,
ts2
):
"""
Calculate max absolute error between two time series
"""
return
np
.
absolute
((
TimeSeries
.
diff
(
'
diff
'
,
ts1
,
ts2
).
values
)).
max
()
@staticmethod
def
max_rel_abs_err
(
ts1
,
ts2
):
"""
Calculate max relative absolute error between two time series objects to the first
"""
return
np
.
absolute
(
TimeSeries
.
rel_diff
(
'
rel_diff
'
,
ts1
,
ts2
).
values
).
max
()
@staticmethod
def
mean_rel_abs_err
(
ts1
,
ts2
):
"""
Calculate mean relative absolute error between two time series objects to the first
"""
return
np
.
absolute
(
TimeSeries
.
rel_diff
(
'
rel_diff
'
,
ts1
,
ts2
).
values
).
mean
()
@staticmethod
def
norm_rmse
(
ts1
,
ts2
):
"""
Calculate root mean square error between two time series,
...
...
@@ -167,6 +194,16 @@ class TimeSeries:
ts_diff
=
TimeSeries
(
name
,
time
,
(
interp_vals_ts2
-
interp_vals_ts1
))
return
ts_diff
@staticmethod
def
rel_diff
(
name
,
ts1
,
ts2
):
"""
Returns relative difference between two time series objects to the first.
"""
diff_val
=
TimeSeries
.
diff
(
'
diff
'
,
ts1
,
ts2
).
values
# in case an element in ts1 is zero and the corresponding diff is non-zero
rel_diff_to_ts1
=
np
.
divide
(
diff_val
,
ts1
.
values
,
out
=
np
.
zeros_like
(
diff_val
),
where
=
ts1
.
values
!=
0
)
ts_rel_diff_to_ts1
=
TimeSeries
(
name
,
ts1
.
time
,
rel_diff_to_ts1
)
return
ts_rel_diff_to_ts1
@staticmethod
def
complex_abs
(
name
,
ts_real
,
ts_imag
):
"""
Calculate absolute value of complex variable.
...
...
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