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

Problem with low sample rates #515

Closed
vSahakian opened this issue Sep 15, 2022 · 5 comments
Closed

Problem with low sample rates #515

vSahakian opened this issue Sep 15, 2022 · 5 comments

Comments

@vSahakian
Copy link

I'm using eqcorrscan for a slightly obscure application, on 1 minute sampled turbidity data on an oceanographic cabled array.

When generating templates of turbidity current events, I notice that the shortproc and processing functions are forcing a resample on line 570 of pre_processing.py (

if tr.stats.sampling_rate != samp_rate:
), which is undesirable for my purposes (I'd rather it not resample).

It appears to be because the sampling rate of the data ("tr.stats.sampling_rate") is very low (1/60 Hz), the precision of this float is such that tr.stats.sampling_rate turns out to be 0.01666666753590107, while it should be 0.016666666666666666 (which is what I'm specifying 1/60 as the sampling rate "samp_rate" in the template_gen function).

Is it possible to modify this to handle low sample rates?

I'm working on Python 3.9.12.

@calum-chamberlain
Copy link
Member

Thanks for raising this! This is an unusual use case, but hopefully the code can be useful for you.

Do all your traces have the same (imprecise) sampling-rate? If not then you should make sure they are all set to the same value if you expect them to be. Then I would suggest that you set samp_rate to that value. I don't think that the precision of samp_rate is changed anywhere (I hope it isn't), so that should compare as equal. Perhaps you have tried that though and this issue still happens?

It would be good to expose an option to not resample (e.g. by setting samp_rate=None to disable resampling), but in the matched-filter steps the sample-rate of the continuous data are compared to the sample rate of the template to ensure that they are the same and if they are not it will resample. If this is a floating point accuracy bug that gives different results for different epochs then that will be an issue. Keen to know what you have found in your experience and happy to try and help.

@vSahakian
Copy link
Author

Thanks for such a fast response!

I dug in a bit more and realized that the problem is in my conversion to a SAC file, so I can use the SAC method in template_gen. I convert csv files to miniseed, then convert and write to SAC (with a pick time), and subsequently template_gen reads these back in. Somewhere in either the writing or reading of the SAC file, the sampling rate gets converted from delta=60.0 to 0.01666666753590107 (instead of 1/60 or 0.01666666666666666).

I agree that forcing it to resample would not be ideal. What are your thoughts on either using np.isclose on line 570 of pre_processing.py (instead of a logical testing equality - the default could be atol=0 which is the same as identical values), or otherwise adding an option to read in mseed files to template_gen? If easier, I could make suggested code changes.

Thank you!

@calum-chamberlain
Copy link
Member

You can pass any Stream to most of the template creation functions/methods, but we don't support passing filenames - you have to read the file using obspy first, so you can pass miniseed to those (so long as you read the file first). You would use the from_meta_file method and pass a stream. In general I would avoid the SAC methods!

Also, generally it is better to use the object oriented API (Template and Tribe objects). The functions in template_gen are only there for legacy purposes. Similar to template_gen you should use the from_meta_file method.

Using np.isclose is a nice idea, we could do that, but I'm loath to introduce something that could be used to hide other issues (e.g. file conversion issues).

@vSahakian
Copy link
Author

Perfect, the from_meta_file method works! Thank you so much!

@calum-chamberlain
Copy link
Member

I really need to get back to finishing the local file tutorial in based on #468! If there is anything else you would like to see in a tutorial then let me know. I'm going to close this, but feel free to reply.

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

2 participants