eqcorrscan / EQcorrscan

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

[HELP] - create template through FDSN client #563

Closed Lukesovarenata closed 4 days ago

Lukesovarenata commented 6 months ago

What do you need help with?

Hi, I would like to use EQcorrscan for my research. I followed the manual and have trouble obtaining data through FDSN client "GFZ" or "NIEP". The data exists and can be downloaded by basic client.get_waveforms() - see proof of data existence.txt

I try method from 5.1. Quick Start - 5.1.1. Matched-filter earthquake detection and also from Template creation (old API)

I'm not a Python expert nor programmer - I'm just using ObsPy for basic data processing, so maybe I'm making some basic mistakes... Thanks for any help in advance.

Provide an example so that we can reproduce your problem

example 1 - Parfield 2004 catalog.txt example 2 - EMSC catalog.txt Example 3 - from Template creation .txt

What help would you like?

Suggest how I can generate templates directly from the client GFZ or NIEP without having to download data yourself

What is your setup? (please complete the following information):**

Operating System: Microsoft Windows [Version 10.0.22621.3007] win-64 Python version: Python 3.11.7 EQcorrscan version: Version 0.5.0

calum-chamberlain commented 6 months ago

I have only looked at the first example. Your code:

import logging

logging.basicConfig(
    level=logging.ERROR,
    format="%(asctime)s\t%(name)s\t%(levelname)s\t%(message)s")

%matplotlib inline
from obspy import UTCDateTime
from obspy.clients.fdsn import Client
from eqcorrscan.utils.catalog_utils import filter_picks

client = Client("NCEDC")
t1 = UTCDateTime(2004, 9, 28)
t2 = t1 + 86400
catalog = client.get_events(
    starttime=t1, endtime=t2, minmagnitude=2.5, minlatitude=35.7, maxlatitude=36.1,
    minlongitude=-120.6, maxlongitude=-120.2, includearrivals=True)
fig = catalog.plot(projection="local", resolution="h")
catalog = filter_picks(catalog=catalog, evaluation_mode="manual", top_n_picks=20)

34 events

from eqcorrscan import Tribe
client = Client("GFZ")
tribe = Tribe().construct(
    method="from_client", lowcut=4.0, highcut=15.0, samp_rate=50.0, length=6.0,
    filt_order=4, prepick=0.5, client_id=client, catalog=catalog, data_pad=20.,
    process_len=21600, min_snr=5.0, parallel=True)
print(tribe)

Gets events from the NCEDC which have picks made on stations within the NCEDC. You have then requested data for stations in the NCEDC from the GFZ FDSN service. While data exist in the GFZ FDSN service, the data that you have asked for do not. Please use catalogues with picks for stations that you have available.

The output is fairly explicit:

2024-01-26 09:38:11,262 eqcorrscan.core.template_gen    ERROR   No data available for request.
HTTP Status code: 204
Detailed response of server:

2024-01-26 09:38:11,263 eqcorrscan.core.template_gen    ERROR   Found no data for this station: {'network': 'NC', 'station': 'BAP', 'location': '*', 'channel': 'SHZ', 'starttime': UTCDateTime(2004, 9, 28, 17, 15, 4, 250000), 'endtime': UTCDateTime(2004, 9, 28, 23, 15, 4, 250000)}

... repeated for other stations

The code is looking for data for the station stated in the error message, but those data are not available from GFZ.

Lukesovarenata commented 6 months ago

I'm sorry - I tried it many times with various modifications and in the end, I chose a very stupid example... Please - look at this example: EXAMPLE 4.txt

calum-chamberlain commented 6 months ago

This error comes from missing components in the pick waveform ID from the ISC. EQcorrscan should provide a more helpful error message than this.

You show that data exist for seed ids R0.BISRR..HH?, but the pick.waveform_id is missing the channel code. Please edit the events to include a channel code. In this case you could do:

for event in catalog:
    for pick in event.picks:
        if pick.waveform_id.channel_code is None:
            if pick.phase_hint.upper().startswith("P"):
                component = "Z"
            elif pick.phase_hint.upper().startswith("S"):
                component = "N"  # Or you might need to have "1" or "2" or "E", up to you how you handle this,
            else:
                component = "?"  # Just get all components
            pick.waveform_id.channel_code = f"HH{component}"

You might find similar issues if the network code or location code are missing from other picks. Pick seed ids need to be complete, and it is a failing of EQcorrscan that it does not warn you about this. I will open a pull request to add a useful error message.