eqcorrscan / EQcorrscan

Earthquake detection and analysis in Python.
https://eqcorrscan.readthedocs.io/en/latest/
Other
163 stars 85 forks source link

Empty Template Constructing from Seisan Meta-File #370

Closed GB123185 closed 4 years ago

GB123185 commented 4 years ago

Hi! Firstly, I'm quite enjoying learning about how to use this software. Outstanding work! Now, this is probably a pretty simple issue to resolve, but I'm struggling to determine why I am unable to generate a template that uses a Seisan S-file as the metafile input and a Seisan waveform as the input into an Obspy Stream object. I suspect that it may be an issue with the input S-file, but I'm unable to find what I may be missing in that file.

The simple template generation script is here:

import glob
from obspy.core.event impor_events
from eqcorrscan.core.match_filter import Tribe
from obspy.core import read,Stream,Stats
import os
import logging
logging.basicConfig(level=logging.INFO,format="%(asctime)s\t%(name)s\t%(levelname)s\t%(message)s")

# READ IN THE WAVEFORMS
stream = read('/home/sfiles/2018-01-24-0227-15S.NSN___011')
metafile = read_events('/home/sfiles/24-0227-16L.S201801',format='NORDIC')
# CREATE TEMPLATE
template = Tribe().construct(method='from_meta_file',st=stream,meta_file=metafile,length=30,
        lowcut=2,highcut=10,filt_order=4,
        process_len=86400,swin='all',prepick=0.1,samp_rate=40,process=True)

The output is here, with some user Warnings removed (e.g., AIN column, :

(eqcorrscan) [u58888@localhost sfiles]$ python test.py 
2020-02-04 17:50:30,483 eqcorrscan.core.template_gen    INFO    Pre-processing data
/home/u58888/anaconda3/envs/eqcorrscan/lib/python3.7/site-packages/obspy/signal/detrend.py:31: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
  if not np.issubdtype(data.dtype, float):
2020-02-04 17:50:30,591 eqcorrscan.core.match_filter.tribe  ERROR   Empty Template

There are definitely waveforms being read in, since when I print the stream out, I can see the list of Traces. I can also confirm that Pick information from the Seisan file is also being read in, since, e.g., the following command returns: >>> print(wav[0].picks[5])

Pick
         resource_id: ResourceIdentifier(id="smi:local/74ba267b-ef44-41c1-8aca-68efb551ee81")
                time: UTCDateTime(2018, 1, 24, 2, 29, 52, 190000)
         waveform_id: WaveformStreamID(network_code='NA', station_code='MGCD', channel_code='SN')
               onset: 'emergent'
          phase_hint: 'S'
            polarity: 'undecidable'
     evaluation_mode: 'manual'

I've attached the S-file for your reference as well. I'm just curious why I'm unable to generate a Template? It's most likely a very simple error in my script or in the S-file that I've completely overlooked, but I would greatly appreciate another set of eyes!
Thanks for your help. Greg B.
24-0227-16L .S201801.txt

calum-chamberlain commented 4 years ago

With nordic files the full seed id isn't stored, only the station and first and last characters of the channel name. Internally the template creation routines require a full matching seed id (network, station, location and channel) between the pick and the data in the stream. It would be worth checking that the data in the stream has the same seed id as the picks.

I often add the expected/known location code, network code and full channel code to the picks after I read nordic files to get around this. An alternative is to change the waveform metadata, but then you have to keep remembering to change this when using the templates.

Let me know if that turns out to be the issue, otherwise I will dig deeper tomorrow.

GB123185 commented 4 years ago

Hi Calum, That may very well be the issue here. Just to test if it is, I've made the following addition to my script to revise the Obspy Pick attributes:

metafile[0].picks[0].waveform_id.network_code='AU'                                                     
metafile[0].picks[0].waveform_id.location_code=''  
metafile[0].picks[0].waveform_id.channel_code='BHZ'
metafile[0].picks[0].update 

The terminal output then returns the following:

2020-02-05 00:23:19,305 eqcorrscan.core.template_gen    INFO    Working on channel ARMA.BHZ
2020-02-05 00:23:19,306 eqcorrscan.core.template_gen    INFO    Found Trace AU.ARMA..BHZ | 2018-01-24T02:27:15.995000Z - 2018-01-24T02:36:29.995000Z | 40.0 Hz, 22161 samples

I believe I can now store/save the template. I believe I'm on the right track! I just need to revise the remaining stations. I did have to change the channel code from 'BZ' to 'BHZ' for the code to work. Thanks for the help mate.

Cheers, Greg

calum-chamberlain commented 4 years ago

Did you work this one out in the end? Do you think anything needs to be changed in the code, otherwise I will close this issue.

GB123185 commented 4 years ago

Hi Calum, Yes I was able to work it out. You can close the issue. Cheers, Greg

On Tue, Mar 31, 2020 at 1:54 PM Calum Chamberlain notifications@github.com wrote:

Did you work this one out in the end? Do you think anything needs to be changed in the code, otherwise I will close this issue.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/eqcorrscan/EQcorrscan/issues/370#issuecomment-606367881, or unsubscribe https://github.com/notifications/unsubscribe-auth/AOOU7W26AFZY75SFKTKMRGDRKFLM5ANCNFSM4KPRXDRQ .