seismo-live / seismo_live

Live Jupyter Notebooks for Seismology
http://seismo-live.org
78 stars 74 forks source link

Causality discussion and typos in Filtering Basics notebook #45

Open liamtoney opened 1 year ago

liamtoney commented 1 year ago

Thanks for these great resources.

I was trying to understand causal / acausal filtering today in the context of ObsPy's functions and came across the Basics in filtering notebook.

In the Causal versus acausal section of the notebook, there looks to be a typo where the "causal" filters have zerophase=True while the "acausal" filter has zerophase=False.

tr_filt = tr.copy()            # causal filter / not zero phase. Order = 2
tr_filt.filter('lowpass', freq=f, zerophase=True, corners=2)
tr_filt2 = tr.copy()           # causal filter / not zero phase. Order = set by ncorners
tr_filt2.filter('lowpass', freq=f, zerophase=True, corners=ncorners)
tr_filt3 = tr.copy()           # acausal filter / zero phase. Order = set by ncorners
tr_filt3.filter('lowpass', freq=f, zerophase=False, corners=ncorners)

Presumably, these should be switched?

On a related note, in the solutions the following discussion:

3) The difference between the two causal filters (red and blue) are minor, even when the order of the filter is increased. But the acausal filter (green) shows a phase shift relative to the original data. This phase shift increases drastically when increasing the order of the filter.

"causal" and "acausal" would need to be swapped here — the trace in green has a phase shift due to its causal nature, not the opposite.

4) Zooming into a time window from 4.5 s to 5 s and setting the maximum amplitude to 400, we see that the phase shift is also shifting the first onset. We would pick it incorrectly. Therefore, whenever the scientific task involves the correct time picking of phases, we have to work with causal filters. When only the frequency content is important, we can also work with acausal filters.

It is my understanding that the final two sentences here are correct, but in this case for the wrong reason. The causal filter does introduce a phase shift but it is typically used in phase picking applications to avoid pre-onset artifacts arising from acausal filtering of impulsive arrivals, correct? It might be good to clarify here.

I would be happy to draft a quick PR to address these comments, if they make sense to the notebook creators.

megies commented 1 year ago

In the Causal versus acausal section of the notebook, there looks to be a typo where the "causal" filters have zerophase=True while the "acausal" filter has zerophase=False.

I agree, that looks like an error in there. The wording is also weird: "The output of a causal filter depends only on past and present input, while the output also depends on future input." The second half of the sentence is about acausal filter only mentioned in the following sentence. It probably should be ..., while the output [of an acausal filter] also depends on future input.

"causal" and "acausal" would need to be swapped here — the trace in green has a phase shift due to its causal nature, not the opposite.

Agreed.

It is my understanding that the final two sentences here are correct, but in this case for the wrong reason.

I guess the wording could be improved but in general it seems OK like you said.


It would be good to have these things fixed. Sadly, currently we don't have a set workflow for making updates to seismo live, so it means quite some work, so not sure how/when an update would make it to the live webpage.

CC @heinerigel