From ffc5f20754a4fd67dc8005c49c1a1aca71731ee9 Mon Sep 17 00:00:00 2001 From: Markus Mirz <mmirz@eonerc.rwth-aachen.de> Date: Wed, 3 Oct 2018 00:42:56 +0200 Subject: [PATCH] add freq shifting func to time series --- dataprocessing/dpsim.py | 3 ++- dataprocessing/timeseries.py | 27 ++++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/dataprocessing/dpsim.py b/dataprocessing/dpsim.py index e56cb5f..67d0f82 100644 --- a/dataprocessing/dpsim.py +++ b/dataprocessing/dpsim.py @@ -1,5 +1,6 @@ from dataprocessing.readtools import * from dataprocessing.timeseries import * +from dataprocessing.plottools import * def get_node_voltage_phasors(dpsim_timeseries_list): """Calculate voltage phasors of all nodes @@ -24,7 +25,7 @@ def get_node_emt_voltages(timeseries_list, freq): """ voltages_list = {} for name, ts in timeseries_list.items(): - ts_emt = ts.dynphasor_shift_to_emt(ts.name, freq) + ts_emt = ts.frequency_shift(ts.name, freq) voltages_list[ts.name] = ts_emt return voltages_list diff --git a/dataprocessing/timeseries.py b/dataprocessing/timeseries.py index 300c0b5..d94ca41 100644 --- a/dataprocessing/timeseries.py +++ b/dataprocessing/timeseries.py @@ -37,6 +37,31 @@ class TimeSeries: ts_phase = TimeSeries(name, self.time, phase_values) return ts_phase + def phasor(self, name): + """Calculate phasor of complex time series and return dict with abs and phase. + """ + ts_abs = ts.abs(ts.name + '_abs') + ts_phase = ts.phase(ts.name + '_phase') + ts_phasor = {} + ts_phasor['abs'] = ts_abs + ts_phasor['phase'] = ts_phase + + return ts_phasor + + @staticmethod + def frequency_shift_list(timeseries_list, freq): + """Calculate shifted frequency results of all time series + :param timeseries_list: timeseries list retrieved from dpsim results + :param freq: frequency by which the timeseries should be shifted + :return: list of shifted time series + """ + result_list = {} + for name, ts in timeseries_list.items(): + ts_emt = ts.frequency_shift(ts.name, freq) + result_list[ts.name] = ts_emt + + return result_list + @staticmethod def rmse(ts1, ts2): """ Calculate root mean square error between two time series @@ -69,7 +94,7 @@ class TimeSeries: ts_diff = TimeSeries(name, time, (interp_vals_ts2 - interp_vals_ts1)) return ts_diff - def dynphasor_shift_to_emt(self, name, freq): + def frequency_shift(self, name, freq): """ Shift dynamic phasor values to EMT by frequency freq. Assumes the same time steps for both timeseries. :param name: name of returned time series -- GitLab