Skip to content
Snippets Groups Projects
Commit a6ba5850 authored by leufen1's avatar leufen1
Browse files

fir filter can be used with daily data

parent 2e52fa71
Branches
Tags
5 merge requests!319add all changes of dev into release v1.4.0 branch,!318Resolve "release v1.4.0",!317enabled window_lead_time=1,!295Resolve "data handler FIR filter",!259Draft: Resolve "WRF-Datahandler should inherit from SingleStationDatahandler"
......@@ -117,15 +117,40 @@ class DataHandlerFirFilterSingleStation(DataHandlerFilterSingleStation):
filter_add_unfiltered=DEFAULT_ADD_UNFILTERED, **kwargs):
# self._check_sampling(**kwargs)
# self.original_data = None # ToDo: implement here something to store unfiltered data
self.filter_cutoff_period = (lambda x: [x] if isinstance(x, tuple) else to_list(x))(filter_cutoff_period)
self.fs = self._get_fs(**kwargs)
self.filter_cutoff_period, removed_index = self._prepare_filter_cutoff_period(filter_cutoff_period, self.fs)
self.filter_cutoff_freq = self._period_to_freq(self.filter_cutoff_period)
assert len(self.filter_cutoff_period) == len(filter_order)
self.filter_order = filter_order
assert len(self.filter_cutoff_period) == (len(filter_order) - len(removed_index))
self.filter_order = self._prepare_filter_order(filter_order, removed_index, self.fs)
self.filter_window_type = filter_window_type
self._add_unfiltered = filter_add_unfiltered
self.fs = self._get_fs(**kwargs)
super().__init__(*args, **kwargs)
@staticmethod
def _prepare_filter_order(filter_order, removed_index, fs):
order = []
for i, o in enumerate(filter_order):
if i not in removed_index:
fo = int(o * fs)
fo = fo + 1 if fo % 2 == 0 else fo
order.append(fo)
return order
@staticmethod
def _prepare_filter_cutoff_period(filter_cutoff_period, fs):
"""Frequency must be smaller than the sampling frequency fs. Otherwise remove given cutoff period pair."""
cutoff_tmp = (lambda x: [x] if isinstance(x, tuple) else to_list(x))(filter_cutoff_period)
cutoff = []
removed = []
for i, (low, high) in enumerate(cutoff_tmp):
low = low if (low is None or low > 2. / fs) else None
high = high if (high is None or high > 2. / fs) else None
if any([low, high]):
cutoff.append((low, high))
else:
removed.append(i)
return cutoff, removed
@staticmethod
def _period_to_freq(cutoff_p):
return list(map(lambda x: (1. / x[0] if x[0] is not None else None, 1. / x[1] if x[1] is not None else None),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment