Commit e1f08571 authored by Markus Mirz's avatar Markus Mirz

improve frequency shift functions

parent 3b7427a1
...@@ -97,35 +97,43 @@ class TimeSeries: ...@@ -97,35 +97,43 @@ class TimeSeries:
return result_list return result_list
@staticmethod @staticmethod
def create_emt_from_dp(timeseries_list, freqs_list): def frequency_shift_list(timeseries_list, freqs_list):
"""Calculate shifted frequency results of all time series """ Calculate shifted frequency results of all time series in list by using
the frequency with the same index in the frequency list
or the same frequency if there is only one frequency defined.
:param timeseries_list: timeseries list retrieved from dpsim results :param timeseries_list: timeseries list retrieved from dpsim results
:param freq: frequency by which the timeseries should be shifted :param freqs_list: frequency or list of frequencies by which the timeseries should be shifted
:return: list of shifted time series :return: list of shifted time series
""" """
result = np.zeros_like(timeseries_list[0].values) if not isinstance(freqs_list, list):
result_list = {}
for name, ts in timeseries_list.items():
ts_shift = ts.frequency_shift(freqs_list)
result_list[ts_shift.name] = ts_shift
return result_list
else:
result_list = {}
for ts, freq in zip(timeseries_list, freqs_list): for ts, freq in zip(timeseries_list, freqs_list):
ts_shift = ts.frequency_shift(freq) ts_shift = ts.frequency_shift(freq)
result = result + ts_shift.values result_list[ts.name] = ts_shift
return result_list
ts_result = TimeSeries('emt_signal', timeseries_list[0].time, result.real)
return ts_result
@staticmethod @staticmethod
def frequency_shift_list(timeseries_list, freq): def create_emt_from_dp(timeseries_list, freqs_list, new_name = 'emt_signal'):
"""Calculate shifted frequency results of all time series """ Calculate shifted frequency results of all time series in list
and synthesize emt signal by summing them.
:param timeseries_list: timeseries list retrieved from dpsim results :param timeseries_list: timeseries list retrieved from dpsim results
:param freq: frequency by which the timeseries should be shifted :param freqs_list: frequency or list of frequencies by which the timeseries should be shifted
:return: list of shifted time series :return: emt equivalent time series
""" """
result_list = {} result = np.zeros_like(timeseries_list[0].values)
for name, ts in timeseries_list.items():
ts_emt = ts.frequency_shift(freq)
result_list[ts.name] = ts_emt
return result_list for ts, freq in zip(timeseries_list, freqs_list):
ts_shift = ts.frequency_shift(freq)
result = result + ts_shift.values
ts_result = TimeSeries(new_name, timeseries_list[0].time, result.real)
return ts_result
@staticmethod @staticmethod
def rmse(ts1, ts2): def rmse(ts1, ts2):
...@@ -176,6 +184,6 @@ class TimeSeries: ...@@ -176,6 +184,6 @@ class TimeSeries:
""" """
phasor_list = {} phasor_list = {}
for name, ts in timeseries_list.items(): for name, ts in timeseries_list.items():
phasor_list[name] = ts.phasor(name) phasor_list[name] = ts.phasor()
return phasor_list return phasor_list
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment