Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow PySEP to use causal/acausal prefilter during instrument response removal #108

Open
bch0w opened this issue Mar 30, 2023 · 2 comments

Comments

@bch0w
Copy link
Member

bch0w commented Mar 30, 2023

Currently PySEP applies filtering during the instrument response removal (https://docs.obspy.org/packages/autogen/obspy.core.trace.Trace.remove_response.html), which does not have the typical ObsPy zerophase option for choosing causal or acausal filter.

pysep/pysep/pysep.py

Lines 1084 to 1092 in 3f5d7ab

tr.remove_response(
inventory=self.inv,
water_level=self.water_level,
pre_filt=_pre_filt,
taper=bool(self.taper_percentage),
taper_fraction=self.taper_percentage,
zero_mean=self.demean,
output=self.output_unit,
)

Instead remove response applies the 4-corner prefilter in the frequency domain using a cosine taper (https://docs.obspy.org/packages/autogen/obspy.signal.invsim.cosine_sac_taper.html). To my understanding this is an acausal filter (?).

To allow Users more flexibility (i.e., to use a causal filter on pre-filtering), we can stop using the ObsPy prefilt option and instead perform prefiltering within PySEP, prior to instrument response removal. This is how it was done in 'old Pysep'

pysep/util_write_cap.py

Lines 1202 to 1223 in d5f594b

def prefilter(st, fmin, fmax, zerophase, corners, filter_type):
"""
pre-filter traces. Filter options: bandpass, lowpass, highpass
"""
for tr in st:
station_key = tr.stats.network + '.' + tr.stats.station + '.' + \
tr.stats.location +'.'+ tr.stats.channel
print("--> station %14s Applying %s filter" % (station_key, filter_type))
if filter_type=='bandpass':
print("pass %.3f to %.3f Hz (%.3f to %.3f s) zerophase %s corners %i" % \
(fmin,fmax,1/fmax,1/fmin,zerophase,corners))
tr.filter(filter_type, freqmin=fmin, freqmax=fmax, \
zerophase=zerophase, corners=corners)
elif filter_type=='lowpass': # use fmax; ignore fmin
print("pass f < %.3f Hz (periods > %.3f s)" % (fmax,1/fmax))
tr.filter(filter_type, freq=fmax, zerophase=zerophase, \
corners=corners)
elif filter_type=='highpass': # use fmin; ignore fmax
print("pass f > %.3f Hz (periods < %.3f s)" % (fmin,1/fmin))
tr.filter(filter_type, freq=fmin, zerophase=zerophase, \
corners=corners)

This would give us the option to apply zerophase or not and control the causality of the filter. Particularly useful in cases where you want a causal filter.

Motivated by an email from @liamtoney, and discussion with @carltape

@aakash10gupta
Copy link
Member

I think the zerophase option would also be useful with the PySEP record section plotter.

@liamtoney
Copy link
Contributor

Instead remove response applies the 4-corner prefilter in the frequency domain using a cosine taper (https://docs.obspy.org/packages/autogen/obspy.signal.invsim.cosine_sac_taper.html). To my understanding this is an acausal filter (?).

According to my postdoc supervisor, the cosine taper in the frequency domain is indeed an acausal filter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants