eqcorrscan / EQcorrscan

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

[PACKAGING BUG] Template Creation - ValueError: Unknown window type (hanning) #514

Open tonino0013 opened 2 years ago

tonino0013 commented 2 years ago

What do you need help with?

Is this 'Unknow window type' a bug on eqcorrscan? or this error is related to FFTW?

Provide an example so that we can reproduce your problem

I have the followng code to create a template, whre stream is 24 hours data, Sfile is the seismic Nordic file from Seisan


template_base = Tribe().construct(method='from_meta_file', st=stream,
                             meta_file=Sfile, length=35,
                             lowcut=1, highcut=6, filt_order=4,
                             process_len=3600, 
                             swin='all', prepick=0.35, samp_rate=50, 
                             process=True,
                             seisan_chan_names=True)

I installed eqcorrscan within ANACONDA as the documents suggests. However, I have this error related to 'Hanning' windowing.

2022-08-10 11:09:43,030 eqcorrscan.core.template_gen    INFO    Pre-processing data

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
RuntimeError: Undefined plan with nthreads. This is a bug

Exception ignored in: 'pyfftw.pyfftw._fftw_plan_with_nthreads_null'
Traceback (most recent call last):
  File "/home/pob_osc/anaconda3/envs/eqcorrscan/lib/python3.10/site-packages/pyfftw/builders/_utils.py", line 285, in _Xfftn
    FFTW_object = pyfftw.FFTW(input_array, output_array, axes, direction,
RuntimeError: Undefined plan with nthreads. This is a bug

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
File ~/anaconda3/envs/eqcorrscan/lib/python3.10/site-packages/scipy/signal/windows/_windows.py:2214, in get_window(window, Nx, fftbins)
   2213 try:
-> 2214     beta = float(window)
   2215 except (TypeError, ValueError) as e:

ValueError: could not convert string to float: 'hanning'

During handling of the above exception, another exception occurred:

KeyError                                  Traceback (most recent call last)
File ~/anaconda3/envs/eqcorrscan/lib/python3.10/site-packages/scipy/signal/windows/_windows.py:2232, in get_window(window, Nx, fftbins)
   2231 try:
-> 2232     winfunc = _win_equiv[winstr]
   2233 except KeyError as e:

KeyError: 'hanning'

The above exception was the direct cause of the following exception:

ValueError                                Traceback (most recent call last)
Input In [12], in <cell line: 9>()
      1 # ------ Create the template ----- #
      2 # --- In this case just for P wave ---- #
      3 
   (...)
      6 
      7 # template_base = open(r'C:/Users/bolivia/Desktop/NSA/Cross_correlation/01_06_2021/R3BC1/2021_06_01t12_43_23.ms')
----> 9 template_base = Tribe().construct(method='from_meta_file', st=stream,
     10                               meta_file=Sfile, length=3600,
     11                               lowcut=1, highcut=6, filt_order=4,
     12                               process_len=3600,
     13                               swin='all', prepick=0.35, samp_rate=50,
     14                               process=True)
     16 print(template_base)
     18 fig = template_base[0].st.plot(equal_scale=False, size=(800, 600))

File ~/anaconda3/envs/eqcorrscan/lib/python3.10/site-packages/eqcorrscan/core/match_filter/tribe.py:1016, in Tribe.construct(self, method, lowcut, highcut, samp_rate, filt_order, length, prepick, swin, process_len, all_horiz, delayed, plot, plotdir, min_snr, parallel, num_cores, skip_short_chans, save_progress, **kwargs)
    908 def construct(self, method, lowcut, highcut, samp_rate, filt_order,
    909               length, prepick, swin="all", process_len=86400,
    910               all_horiz=False, delayed=True, plot=False, plotdir=None,
    911               min_snr=None, parallel=False, num_cores=False,
    912               skip_short_chans=False, save_progress=False, **kwargs):
    913     """
    914     Generate a Tribe of Templates.
    915 
   (...)
   1014     .. Note:: Templates will be named according to their start-time.
   1015     """
-> 1016     templates, catalog, process_lengths = template_gen.template_gen(
   1017         method=method, lowcut=lowcut, highcut=highcut, length=length,
   1018         filt_order=filt_order, samp_rate=samp_rate, prepick=prepick,
   1019         return_event=True, save_progress=save_progress, swin=swin,
   1020         process_len=process_len, all_horiz=all_horiz, plotdir=plotdir,
   1021         delayed=delayed, plot=plot, min_snr=min_snr, parallel=parallel,
   1022         num_cores=num_cores, skip_short_chans=skip_short_chans,
   1023         **kwargs)
   1024     for template, event, process_len in zip(templates, catalog,
   1025                                             process_lengths):
   1026         t = Template()

File ~/anaconda3/envs/eqcorrscan/lib/python3.10/site-packages/eqcorrscan/core/template_gen.py:358, in template_gen(method, lowcut, highcut, samp_rate, filt_order, length, prepick, swin, process_len, all_horiz, delayed, plot, plotdir, return_event, min_snr, parallel, num_cores, save_progress, skip_short_chans, **kwargs)
    352         st = pre_processing.dayproc(
    353             st=st, lowcut=lowcut, highcut=highcut,
    354             filt_order=filt_order, samp_rate=samp_rate,
    355             parallel=parallel, starttime=UTCDateTime(starttime),
    356             num_cores=num_cores)
    357     else:
--> 358         st = pre_processing.shortproc(
    359             st=st, lowcut=lowcut, highcut=highcut,
    360             filt_order=filt_order, parallel=parallel,
    361             samp_rate=samp_rate, num_cores=num_cores)
    362 data_start = min([tr.stats.starttime for tr in st])
    363 data_end = max([tr.stats.endtime for tr in st])

File ~/anaconda3/envs/eqcorrscan/lib/python3.10/site-packages/eqcorrscan/utils/pre_processing.py:230, in shortproc(st, lowcut, highcut, filt_order, samp_rate, parallel, num_cores, starttime, endtime, seisan_chan_names, fill_gaps, ignore_length, ignore_bad_data, fft_threads)
    228 else:
    229     for i, tr in enumerate(st):
--> 230         st[i] = process(
    231             tr=tr, lowcut=lowcut, highcut=highcut, filt_order=filt_order,
    232             samp_rate=samp_rate, starttime=starttime,
    233             clip=clip, seisan_chan_names=seisan_chan_names,
    234             fill_gaps=fill_gaps, length=length,
    235             ignore_length=ignore_length, ignore_bad_data=ignore_bad_data,
    236             fft_threads=fft_threads)
    237 if tracein:
    238     st.merge()

File ~/anaconda3/envs/eqcorrscan/lib/python3.10/site-packages/eqcorrscan/utils/pre_processing.py:572, in process(tr, lowcut, highcut, filt_order, samp_rate, starttime, clip, length, seisan_chan_names, ignore_length, fill_gaps, ignore_bad_data, fft_threads)
    570 if tr.stats.sampling_rate != samp_rate:
    571     Logger.debug('Resampling')
--> 572     tr = _resample(tr, samp_rate, threads=fft_threads)
    573 # Filtering section
    574 tr = tr.detrend('simple')    # Detrend data again before filtering

File ~/anaconda3/envs/eqcorrscan/lib/python3.10/site-packages/eqcorrscan/utils/pre_processing.py:651, in _resample(tr, sampling_rate, threads)
    647 x_r = x[::2]
    648 x_i = x[1::2]
    650 large_w = np.fft.ifftshift(
--> 651     get_window(native_str("hanning"), tr.stats.npts))
    652 x_r *= large_w[:tr.stats.npts // 2 + 1]
    653 x_i *= large_w[:tr.stats.npts // 2 + 1]

File ~/anaconda3/envs/eqcorrscan/lib/python3.10/site-packages/scipy/signal/windows/_windows.py:2234, in get_window(window, Nx, fftbins)
   2232     winfunc = _win_equiv[winstr]
   2233 except KeyError as e:
-> 2234     raise ValueError("Unknown window type.") from e
   2236 if winfunc is dpss:
   2237     params = (Nx,) + args + (None,)

ValueError: Unknown window type.

What help would you like?

Is this my fault in coding or a bug from the package?. Would you ind giving me some insigths about the problem? Under Ubuntu and MSwindows used to work with no problems.

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

calum-chamberlain commented 2 years ago

There are two issues here. The PyFFTW related one is related to #487 and you may need to downgrade to PyFFTW version 0.12 (conda install pyfftw=0.12). Apologies, the pyfftw build tagged 2 should have fixed that, but doesn't appear to have fixed it on all systems.

The issue that results in the error is related to this issue related to name changes in scipy. The version of scipy should have been pinned in the conda release to avoid this, but it looks like that didn't work. To fix this you should downgrade scipy to <1.9 (conda install 'scipy<1.9.0').

Sorry that you ran into these! I will try and patch the conda release to enforce these versions.

calum-chamberlain commented 2 years ago

For anyone that runs into this - I have just updated the package on conda-forge (build 1 of version 0.4.4) with stricter dependencies that should solve this issue. Please make sure you have installed build 1 of version 0.4.4 before reporting anymore issues about this (and sorry that this slipped through!).

To install a specific build find the right file for your system here - the build number is at the end of the file name, formatted like: /eqcorrscan-0.4.4-_.tar.bz2

and install using conda install eqcorrscan=0.4.4=<python><hash>_1 where and are as above for the filename you need.

If you are updating from a previous version conda should default to the most recent build and you shouldn't run into this issue.