def retry_stationlist_fft(tr, pickDat):
    seedid = tr.get_id()
    channel = tr.stats.channel
    start_time = tr.stats.starttime

    recdate = pickDat['origintime']
    #print(seedid, channel, start_time, recdate.datetime)
    nat_freq, inst_ty, damping, sen, recsen, gain, pazfile, stlo, stla, netid \
          = get_response_info(tr.stats.station, recdate.datetime, tr.stats.channel)

    # get fft of trace
    freq, wavfft = calc_fft(tr.data, tr.stats.sampling_rate)
    mi = (len(freq) / 2)
    mi = int(round(mi))

    # get response for given frequencies
    real_resp, imag_resp = paz_response(freq, pazfile, sen, recsen, \
                                        gain, inst_ty)

    # deconvolve response
    corfftr, corffti = deconvolve_instrument(real_resp, imag_resp, wavfft)

    if inst_ty == 'N':
        dispamp = sqrt((tr.stats.delta)**2 *
                       (corfftr**2 + corffti**2)) / ((2 * pi * freq)**2)
    else:
        dispamp = sqrt(
            (tr.stats.delta)**2 * (corfftr**2 + corffti**2)) / (2 * pi * freq)

    staloc = {'latitude': stla, 'longitude': stlo}

    return freq[1:mi], dispamp[1:mi]
Example #2
0
def common_resp(freq, nat_freq, damping, sen, recsen, gain, wavfft, inst_ty):

    # calculate FAP instrument response
    if pazfile == 'NULL':
        real_resp, imag_resp = response.fap_response(freq, nat_freq, damping, \
                                                     sen, recsen, gain, inst_ty)

    # or use PAZ file
    else:
        real_resp, imag_resp = response.paz_response(freq, pazfile, sen, recsen, \
                                                     gain, inst_ty)

    # deconvolve instrument response from record and return corrected FFT
    corfftr, corffti = response.deconvolve_instrument(real_resp, imag_resp,
                                                      wavfft)

    return corfftr, corffti, real_resp, imag_resp
Example #3
0
                            # get data from stationlist.dat
                            nat_freq, inst_ty, damping, sen, recsen, gain, pazfile, stlo, stla, netid \
                                  = get_response_info(tr.stats.station, recdate, tr.stats.channel)

                            if not stlo == -12345:

                                # get fft of trace
                                freq, wavfft = calc_fft(
                                    tr.data, tr.stats.sampling_rate)

                                # get response for given frequencies
                                real_resp, imag_resp = paz_response(freq, pazfile, sen, recsen, \
                                                                    gain, inst_ty)

                                # deconvolve response
                                corfftr, corffti = deconvolve_instrument(
                                    real_resp, imag_resp, wavfft)

                                # make new instrument corrected velocity trace
                                pgv, ivel = get_cor_velocity(
                                    corfftr, corffti, freq, inst_ty)

                                # overwrite tr.data
                                tr.data = ivel.real

                                addRecDat = True

                        #####################################################################
                        # now do ffts
                        #####################################################################
                        # checks for errors in FFT
                        #try:
def response_corrected_fft(tr, pickDat):
    import matplotlib.pyplot as plt
    from numpy import fft, sqrt

    seedid = tr.get_id()
    channel = tr.stats.channel
    start_time = tr.stats.starttime

    # check if HSR AU data
    use_stationlist = False
    if tr.stats.network == 'AU' and tr.stats.channel.startswith('HH'):
        use_stationlist = True
    elif tr.stats.network == 'AU' and tr.stats.channel.startswith('BH'):
        use_stationlist = True
    elif tr.stats.network == 'AU' and tr.stats.start_time.year >= 2017:
        use_stationlist = True
    elif tr.stats.network == 'OA' and tr.stats.channel.startswith('HH'):
        use_stationlist = True
    elif tr.stats.network == '2O' and tr.stats.channel.startswith('HH'):
        use_stationlist = True
    elif tr.stats.network == 'AU' and tr.stats.channel.startswith('EH'):
        use_stationlist = True
    elif tr.stats.network == 'AU' and tr.stats.channel.startswith('SH'):
        use_stationlist = True
    elif tr.stats.network == '' and tr.stats.channel.startswith(
            'EN'):  # for DRS
        use_stationlist = True
    elif tr.stats.network == '7M':
        use_stationlist = True
    elif tr.stats.station == 'AS32' or tr.stats.station == 'ARPS' or tr.stats.station == 'ARPS' or tr.stats.network == 'MEL':
        use_stationlist = True
    #print('use_stationlist', use_stationlist)

    if use_stationlist == True:
        #recdate = datetime.strptime(ev['timestr'], "%Y-%m-%dT%H:%M:%S.%fZ")
        recdate = pickDat['origintime']
        #print(seedid, channel)
        nat_freq, inst_ty, damping, sen, recsen, gain, pazfile, stlo, stla, netid \
              = get_response_info(tr.stats.station, recdate.datetime, tr.stats.channel)

        # get fft of trace
        freq, wavfft = calc_fft(tr.data, tr.stats.sampling_rate)
        mi = (len(freq) / 2)
        mi = int(round(mi))

        # get response for given frequencies
        real_resp, imag_resp = paz_response(freq, pazfile, sen, recsen, \
                                            gain, inst_ty)

        # deconvolve response
        corfftr, corffti = deconvolve_instrument(real_resp, imag_resp, wavfft)

        if inst_ty == 'N':
            dispamp = sqrt((tr.stats.delta)**2 *
                           (corfftr**2 + corffti**2)) / ((2 * pi * freq)**2)
        else:
            dispamp = sqrt((tr.stats.delta)**2 *
                           (corfftr**2 + corffti**2)) / (2 * pi * freq)

        staloc = {'latitude': stla, 'longitude': stlo}

    # just use IRIS dataless volume - much easier, but less transparent!
    else:
        if tr.stats.network == 'AU':
            try:
                paz = au_parser.get_paz(seedid, start_time)
                staloc = au_parser.get_coordinates(seedid, start_time)
            except:
                paz = cwb_parser.get_paz(seedid, start_time)
                staloc = cwb_parser.get_coordinates(seedid, start_time)
        elif tr.stats.network == 'GE':
            paz = ge_parser.get_paz(seedid, start_time)
            staloc = ge_parser.get_coordinates(seedid, start_time)
        elif tr.stats.network == 'IU':
            paz = iu_parser.get_paz(seedid, start_time)
            staloc = iu_parser.get_coordinates(seedid, start_time)
        elif tr.stats.network == 'II':
            paz = ii_parser.get_paz(seedid, start_time)
            staloc = ii_parser.get_coordinates(seedid, start_time)
        elif tr.stats.network == 'S1':
            paz = s1_parser.get_paz(seedid, start_time)
            staloc = s1_parser.get_coordinates(seedid, start_time)
        elif tr.stats.network == '1K':
            paz = d1k_parser.get_paz(seedid, start_time)
            staloc = d1k_parser.get_coordinates(seedid, start_time)
        elif tr.stats.network == '1H':
            paz = d1h_parser.get_paz(seedid, start_time)
            staloc = d1h_parser.get_coordinates(seedid, start_time)
        elif tr.stats.network == '1P':
            paz = d1p_parser.get_paz(seedid, start_time)
            staloc = d1p_parser.get_coordinates(seedid, start_time)
        elif tr.stats.network == '1Q':
            paz = d1q_parser.get_paz(seedid, start_time)
            staloc = d1q_parser.get_coordinates(seedid, start_time)
        elif tr.stats.network == '6F':
            paz = d6f_parser.get_paz(seedid, start_time)
            staloc = d6f_parser.get_coordinates(seedid, start_time)
        elif tr.stats.network == '7B':
            paz = d7b_parser.get_paz(seedid, start_time)
            staloc = d7b_parser.get_coordinates(seedid, start_time)
        elif tr.stats.network == '7D':
            paz = d7d_parser.get_paz(seedid, start_time)
            staloc = d7d_parser.get_coordinates(seedid, start_time)
        elif tr.stats.network == '7G':
            paz = d7g_parser.get_paz(seedid, start_time)
            staloc = d7g_parser.get_coordinates(seedid, start_time)
        elif tr.stats.network == '7H':
            paz = d7h_parser.get_paz(seedid, start_time)
            staloc = d7h_parser.get_coordinates(seedid, start_time)
        elif tr.stats.network == '7I':
            paz = d7i_parser.get_paz(seedid, start_time)
            staloc = d7i_parser.get_coordinates(seedid, start_time)
        elif tr.stats.network == '7J':
            paz = d7j_parser.get_paz(seedid, start_time)
            staloc = d7j_parser.get_coordinates(seedid, start_time)
        elif tr.stats.network == '7K':
            paz = d7k_parser.get_paz(seedid, start_time)
            staloc = d7k_parser.get_coordinates(seedid, start_time)
        elif tr.stats.network == '7M':
            try:
                paz = d7m_parser.get_paz(seedid, start_time)
                staloc = d7m_parser.get_coordinates(seedid, start_time)
            except:
                paz = d7n_parser.get_paz(seedid, start_time)
                staloc = d7n_parser.get_coordinates(seedid, start_time)
        elif tr.stats.network == '7S':
            paz = d7s_parser.get_paz(seedid, start_time)
            staloc = d7s_parser.get_coordinates(seedid, start_time)
        elif tr.stats.network == '7T':
            paz = d7t_parser.get_paz(seedid, start_time)
            staloc = d7t_parser.get_coordinates(seedid, start_time)
        elif tr.stats.network == '8K':
            paz = d8k_parser.get_paz(seedid, start_time)
            staloc = d8k_parser.get_coordinates(seedid, start_time)

        # simulate response
        if tr.stats.channel.endswith('SHZ') or tr.stats.channel.endswith(
                'EHZ'):
            tr = tr.simulate(
                paz_remove=paz,
                water_level=10)  #  testing water level for SP instruments
        else:
            tr = tr.simulate(paz_remove=paz)

        # get fft
        freq, wavfft = calc_fft(tr.data, tr.stats.sampling_rate)
        mi = (len(freq) / 2)
        mi = int(round(mi))

        corfftr = wavfft.real
        corffti = wavfft.imag

        if tr.stats.channel[1] == 'N':
            dispamp = sqrt((tr.stats.delta)**2 *
                           (corfftr**2 + corffti**2)) / ((2 * pi * freq)**2)
        else:
            dispamp = sqrt((tr.stats.delta)**2 *
                           (corfftr**2 + corffti**2)) / (2 * pi * freq)

    return freq[1:mi], dispamp[1:mi]