Skip to content

Commit

Permalink
the complex_response of a ChannelResponseFilter now defaults to retur…
Browse files Browse the repository at this point in the history
…n a response which ignores time delay filters.
  • Loading branch information
kkappler committed Mar 30, 2021
1 parent 157b48d commit 63ff054
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 12 deletions.
48 changes: 38 additions & 10 deletions mt_metadata/timeseries/filters/channel_response_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ class ChannelResponseFilter(object):

def __init__(self, **kwargs):
self.filters_list = None
self.lambda_function = None
self.normalization_frequency = None

for k, v in kwargs.items():
Expand Down Expand Up @@ -128,18 +127,45 @@ def normalization_frequency(self, value):

self._normalization_frequency = value

@property
def non_delay_filters(self):
"""
Returns all the non-time_delay filters as a list
-------
"""
non_delay_filters = [
x for x in self.filters_list if x.type != "time delay"]
return non_delay_filters

@property
def delay_filters(self):
"""
Returns the delay of the set of filters
Returns all the time delay filters as a list
-------
"""
delay_filters = [
x for x in self.filters_list if x.type == "time_delay"]
x for x in self.filters_list if x.type == "time delay"]
return delay_filters

@property
def total_delay(self):
"""
Returns the total delay of all filters
-------
"""
delay_filters = self.delay_filters
total_delay = 0.0
for delay_filter in delay_filters:
total_delay += delay_filter.delay
return total_delay


def complex_response(self, frequencies, include_delay=False):
"""
Expand All @@ -155,15 +181,17 @@ def complex_response(self, frequencies, include_delay=False):
frequencies = np.array(frequencies)

if include_delay:
lambda_list = [lambda f: x.complex_response(
f) for x in self.filters_list]
filters_list = self.filters_list
else:
lambda_list = [lambda f: x.complex_response(
f) for x in self.filters_list]
print("hi")
evaluated_lambdas = [x(frequencies) for x in lambda_list]
filters_list = self.non_delay_filters

filter_stage = filters_list.pop(0)
result = filter_stage.complex_response(frequencies)
while len(filters_list):
filter_stage = filters_list.pop(0)
result *= filter_stage.complex_response(frequencies)

return self.lambda_function(frequencies)
return result

def compute_instrument_sensitivity(self, normalization_frequency=None):
"""
Expand Down
5 changes: 3 additions & 2 deletions mt_metadata/timeseries/filters/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,9 @@ def test_filter_generation_from_xml_via_obspy(inventory):
frequencies = np.logspace(-3, 3, 200)
# fltr.plot_complex_response(frequencies)
# fltr.plot_response(None, x_units='frequency')
channel_response = ChannelResponseFilter(filters_list=filters_list)
sens = channel_response.compute_instrument_sensitivity()
channel_response_filter = ChannelResponseFilter(filters_list=filters_list)
complex_channel_response = channel_response_filter.complex_response(frequencies)
sens = channel_response_filter.compute_instrument_sensitivity()

print(network)

Expand Down

0 comments on commit 63ff054

Please sign in to comment.