# Path: seispy/decon.py
# class RFTrace(obspy.Trace):
#     def __init__(self, data=..., header=None):
#         super().__init__(data=data, header=header)
# 
#     @classmethod
#     def deconvolute(cls, utr, wtr, method='iter', **kwargs):
#         header = utr.stats.__getstate__()
#         for key, value in kwargs.items():
#             header[key] = value
#         if method.lower() == 'iter':
#             rf, rms, it = deconit(utr.data, wtr.data, utr.stats.delta, **kwargs)
#             header['rms'] = rms
#             header['iter'] = it
#         elif method.lower() == 'water':
#             rf, rms = deconwater(utr.data, wtr.data, utr.stats.delta, **kwargs)
#             header['rms'] = rms
#             header['iter'] = np.nan
#         else:
#             raise ValueError('method must be \'iter\' or \'water\'')
#         return cls(rf, header)
# 
# Path: seispy/geo.py
# def snr(x, y):
#     spow = rssq(x)**2
#     npow = rssq(y)**2
#     if npow == 0:
#         npow = 0.001
#     return 10 * np.log10(spow / npow)
# 
# def srad2skm(srad):
#     sdeg = srad * ((2*pi)/360)
#     return sdeg / deg2km(1)
# 
# def rotateSeisENtoTR(E, N, BAZ):
#     angle = mod(BAZ+180, 360)
#     R = N*cosd(angle) + E*sind(angle)
#     T = E*cosd(angle) - N*sind(angle)
#     return T, R
# 
# def skm2srad(skm):
#     sdeg = skm * deg2km(1)
#     return rad2deg(sdeg)
# 
# def rssq(x):
#     return np.sqrt(np.sum(x**2)/len(x))
# 
# def extrema(x, opt='max'):
#     if opt == 'max':
#         idx = np.intersect1d(np.where(np.diff(x) > 0)[0]+1, np.where(np.diff(x) < 0)[0])
#     elif opt == 'min':
#         idx = np.intersect1d(np.where(np.diff(x) < 0)[0]+1, np.where(np.diff(x) > 0)[0])
#     else:
#         raise ValueError('opt must be \'max\' or \'min\'')
#     return idx


import numpy as np
import obspy
from numpy.lib.arraysetops import isin
from obspy.io.sac import SACTrace
from obspy.signal.rotate import rotate2zne, rotate_zne_lqt
from scipy.signal import resample
from os.path import dirname, join, expanduser
from seispy.decon import RFTrace
from seispy.geo import snr, srad2skm, rotateSeisENtoTR, skm2srad, \
                       rssq, extrema
from obspy.signal.trigger import recursive_sta_lta
                    inc = self.SArrival.incident_angle
                # inc = self.search_inc(bazi)
            else:
                pass

        if method == 'NE->RT':
            self.comp = 'rtz'
            self.st.rotate('NE->RT', back_azimuth=bazi)
        elif method == 'RT->NE':
            self.st.rotate('RT->NE', back_azimuth=bazi)
        elif method == 'ZNE->LQT':
            self.comp = 'lqt'
            self.st.rotate('ZNE->LQT', back_azimuth=bazi, inclination=inc)
        elif method == 'LQT->ZNE':
            self.st.rotate('LQT->ZNE', back_azimuth=bazi, inclination=inc)
        else:
            pass

    def snr(self, length=50, phase='P'):
        st_noise = self.trim(length, 0, phase=phase, isreturn=True)
        st_signal = self.trim(0, length, phase=phase, isreturn=True)
        try:
            snr_E = snr(st_signal[0].data, st_noise[0].data)
        except IndexError:
            snr_E = 0
        try:
            snr_N = snr(st_signal[1].data, st_noise[1].data)
        except IndexError:
            snr_N = 0
        try:

# Path: seispy/decon.py
# class RFTrace(obspy.Trace):
#     def __init__(self, data=..., header=None):
#         super().__init__(data=data, header=header)
# 
#     @classmethod
#     def deconvolute(cls, utr, wtr, method='iter', **kwargs):
#         header = utr.stats.__getstate__()
#         for key, value in kwargs.items():
#             header[key] = value
#         if method.lower() == 'iter':
#             rf, rms, it = deconit(utr.data, wtr.data, utr.stats.delta, **kwargs)
#             header['rms'] = rms
#             header['iter'] = it
#         elif method.lower() == 'water':
#             rf, rms = deconwater(utr.data, wtr.data, utr.stats.delta, **kwargs)
#             header['rms'] = rms
#             header['iter'] = np.nan
#         else:
#             raise ValueError('method must be \'iter\' or \'water\'')
#         return cls(rf, header)
# 
# Path: seispy/geo.py
# def snr(x, y):
#     spow = rssq(x)**2
#     npow = rssq(y)**2
#     if npow == 0:
#         npow = 0.001
#     return 10 * np.log10(spow / npow)
# 
# def srad2skm(srad):
#     sdeg = srad * ((2*pi)/360)
#     return sdeg / deg2km(1)
# 
# def rotateSeisENtoTR(E, N, BAZ):
#     angle = mod(BAZ+180, 360)
#     R = N*cosd(angle) + E*sind(angle)
#     T = E*cosd(angle) - N*sind(angle)
#     return T, R
# 
# def skm2srad(skm):
#     sdeg = skm * deg2km(1)
#     return rad2deg(sdeg)
# 
# def rssq(x):
#     return np.sqrt(np.sum(x**2)/len(x))
# 
# def extrema(x, opt='max'):
#     if opt == 'max':
#         idx = np.intersect1d(np.where(np.diff(x) > 0)[0]+1, np.where(np.diff(x) < 0)[0])
#     elif opt == 'min':
#         idx = np.intersect1d(np.where(np.diff(x) < 0)[0]+1, np.where(np.diff(x) > 0)[0])
#     else:
#         raise ValueError('opt must be \'max\' or \'min\'')
#     return idx


# Path: seispy/eq.py
import numpy as np
import obspy
from numpy.lib.arraysetops import isin
from obspy.io.sac import SACTrace
from obspy.signal.rotate import rotate2zne, rotate_zne_lqt
from scipy.signal import resample
from os.path import dirname, join, expanduser
from seispy.decon import RFTrace
from seispy.geo import snr, srad2skm, rotateSeisENtoTR, skm2srad, \
                       rssq, extrema
from obspy.signal.trigger import recursive_sta_lta

                    inc = self.SArrival.incident_angle
                # inc = self.search_inc(bazi)
            else:
                pass

        if method == 'NE->RT':
            self.comp = 'rtz'
            self.st.rotate('NE->RT', back_azimuth=bazi)
        elif method == 'RT->NE':
            self.st.rotate('RT->NE', back_azimuth=bazi)
        elif method == 'ZNE->LQT':
            self.comp = 'lqt'
            self.st.rotate('ZNE->LQT', back_azimuth=bazi, inclination=inc)
        elif method == 'LQT->ZNE':
            self.st.rotate('LQT->ZNE', back_azimuth=bazi, inclination=inc)
        else:
            pass

    def snr(self, length=50, phase='P'):
        st_noise = self.trim(length, 0, phase=phase, isreturn=True)
        st_signal = self.trim(0, length, phase=phase, isreturn=True)
        try:
            snr_E = snr(st_signal[0].data, st_noise[0].data)
        except IndexError:
            snr_E = 0
        try:
            snr_N = snr(st_signal[1].data, st_noise[1].data)
        except IndexError:
            snr_N = 0
        try:

            snr_Z = snr(st_signal[2].data, st_noise[2].data)