eqcorrscan / EQcorrscan

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

[HELP] IndexError: index 0 is out of bounds for axis 0 with size 0 #592

Open zhong-yy opened 4 days ago

zhong-yy commented 4 days ago

What do you need help with?

When I run party.lag_calc(...), I encounter the following IndexError

...

File ~/miniconda3/envs/myenv/lib/python3.10/site-packages/EQcorrscan-0.5.dev0-py3.10-linux-x86_64.egg/eqcorrscan/utils/pre_processing.py:638, in _multi_resample.<locals>.<lambda>(args)
    631 to_resample = (
    632     (tr.data, tr.stats.delta,
    633      tr.stats.sampling_rate / float(sampling_rate),
    634      sampling_rate, _get_window(\"hann\", tr.stats.npts), tr.id)
    635     for tr in st)
    636 with ThreadPoolExecutor(max_workers) as executor:
    637     # Unpack tuple using lambda
--> 638     results = executor.map(lambda args: _resample(*args), to_resample,
    639                            chunksize=chunksize)
    640 for r, tr in zip(results, st):
    641     tr.data = r

File ~/miniconda3/envs/myenv/lib/python3.10/site-packages/EQcorrscan-0.5.dev0-py3.10-linux-x86_64.egg/eqcorrscan/utils/pre_processing.py:672, in _resample(data, delta, factor, sampling_rate, large_w, _id)
    668 Logger.debug(f\"Running resample for {_id} with {npts} data points\")
    669 Logger.debug(f\"{_id}: delta={delta}, factor={factor}, \"
    670              f\"sampling_rate out={sampling_rate}\")
    671 Logger.debug(f\"Sanity check data for {_id}, start and \"
--> 672              f\"end: {data[0]} -- {data[-1]}\")
    673 Logger.debug(f\"dtype for {_id}: {data.dtype}\")
    674 if data.dtype == np.dtype('float64'):

IndexError: index 0 is out of bounds for axis 0 with size 0"

Setting ignore_length=True can sometimes solve this problem. However, sometimes another error occurs after setting ignore_length=True:

...
File ~/miniconda3/envs/myenv/lib/python3.10/site-packages/EQcorrscan-0.5.dev0-py3.10-linux-x86_64.egg/eqcorrscan/utils/pre_processing.py:886, in _group_process(filt_order, highcut, lowcut, samp_rate, process_length, parallel, cores, stream, ignore_length, ignore_bad_data, overlap)
    881         Logger.warning(
    882             f\"Data quality insufficient between {kwargs['starttime']}\"
    883             f\" and {_endtime}\")
    884         continue
--> 886 if _endtime < stream[0].stats.endtime:
    887     Logger.warning(
    888         \"Last bit of data between {0} and {1} will go unused \"
    889         \"because it is shorter than a chunk of {2} s\".format(
    890             _endtime, stream[0].stats.endtime, process_length))
    891 return processed_streams

File ~/miniconda3/envs/myenv/lib/python3.10/site-packages/obspy/core/stream.py:645, in Stream.__getitem__(self, index)
    643     return self.__class__(traces=self.traces.__getitem__(index))
    644 else:
--> 645     return self.traces.__getitem__(index)

IndexError: list index out of range"

In addition, the documentation doesn't recommend setting ignore_length=True (why?).

The above errors are from the develop version. When I use the master version, there is another error:

...
File ~/miniconda3/envs/eqcorrscan0.5/lib/python3.10/site-packages/EQcorrscan-0.5.0-py3.10-linux-x86_64.egg/eqcorrscan/utils/pre_processing.py:771, in _fill_gaps(tr)
    769 tr = tr.split()
    770 gaps = tr.get_gaps()
--> 771 tr = tr.detrend().merge(fill_value=0)[0]
    772 gaps = [{'starttime': gap[4], 'endtime': gap[5]} for gap in gaps]
    773 if len(gaps):

File ~/miniconda3/envs/eqcorrscan0.5/lib/python3.10/site-packages/obspy/core/stream.py:645, in Stream.__getitem__(self, index)
    643     return self.__class__(traces=self.traces.__getitem__(index))
    644 else:
--> 645     return self.traces.__getitem__(index)

IndexError: list index out of range"

The error will disappear if the pre_processed=True. Maybe it is related to the preprocessing part inside lag_calc?

The index error also occurs for Party.client_lag_calc().

Provide an example so that we can reproduce your problem

Here is a minimum working example: example.zip

What help would you like?

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