Пример #1
0
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]
Пример #2
0
def common_read(allsta, comps, allrecdate, allsec, allsps, alldata, allnsamp,
                sacseed):

    #print(len(alldata[:,17])
    # select component
    chan, chan_no = readwaves.select_channel(allsta, comps)

    # unify kelunji channel names
    #    tmpchan = chan.split(' Trans')
    #    chan = ''
    #    for i in range(0,len(tmpchan)):
    #        chan = chan + tmpchan[i]

    # get channel data of interest
    sta = allsta[chan_no].strip()
    sps = int(allsps[chan_no])

    if sacseed == True:
        chan_dat = alldata[:, chan_no]
    else:
        chan_dat = alldata[
            chan_no]  # edited as of 2017-09-26 to read new eqwave

    tmprecdate = allrecdate[chan_no]
    recdate = datetime.strptime(tmprecdate, "%Y%m%d%H%M%S")

    # remove trailing nans
    nantrue = True
    while nantrue == True:
        if chan_dat[-1] == np.nan:
            chan_dat = chan_dat[0:-1]
        else:
            nantrue = False

    chan_dat = chan_dat[0:allnsamp[chan_no]]
    chan_dat = chan_dat.reshape(1, len(chan_dat))

    # remove DC offset
    chan_dat = readwaves.remove_dc_offset(chan_dat)

    # check to see if response exists
    nat_freq, inst_ty, damping, sen, recsen, gain, pazfile, stlo, stla, netid \
        = response.get_response_info(sta,recdate,chan)

    # if info does not exist, ask for user input
    if nat_freq == -12345 and pazfile == 'NULL':
        inst_ty, mindate, maxdate, stlo, stla, netid, nat_freq, damping, \
            sen, recsen, gain, pazfile = response.enter_response_info(sta, chan, sps)

        # write new data to file
        response.write_response_info(sta, inst_ty, mindate, maxdate, stlo, \
            stla, netid, nat_freq, damping, sen, recsen, gain, chan, pazfile)

    return sta, inst_ty, sps, recdate, nat_freq, damping, sen, recsen, gain, \
           chan, chan_no, chan_dat, stlo, stla, pazfile, alldata, netid
Пример #3
0
                        # use stationlist file instead
                        except:

                            # fix some channels on the fly
                            if tr.stats.station == 'FORT' or tr.stats.station == 'KMBL' \
                               or tr.stats.station == 'BLDU' or tr.stats.station == 'FORT':
                                tr.stats.channel = tr.stats.channel.encode(
                                    'ascii', 'ignore').replace('EH', 'HH')
                                channel = tr.stats.channel

                            seedid = tr.get_id()
                            print 'Using stationlist data:', seedid

                            # 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)
Пример #4
0
# read mseed
st = read(mseedfile)

# loop thru traces
for tr in st:
    for i, channel in enumerate(plt_channels):
        if tr.stats.channel == channel:
            c = i+1
            seedid = tr.get_id()
            #channel = tr.stats.channel
            start_time = tr.stats.starttime
            
            print(seedid, channel)
            nat_freq, inst_ty, damping, sen, recsen, gain, pazfile, stlo, stla, netid \
                  = get_response_info(tr.stats.station, tr.stats.starttime.datetime, tr.stats.channel)

            # 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
            complex_array = corfftr + 1j*corffti
            n = len(corfftr)
            iwave = fft.ifft(complex_array,n)
Пример #5
0
         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)
     
     tr_new = tr.simulate(paz_remove=paz)
     print('dataless worked')
                 
 # if failed, use stationlist
 except:
     nat_freq, inst_ty, damping, sen, recsen, gain, pazfile, stlo, stla, netid \
           = get_response_info(tr.stats.station, eqdt.datetime, tr.stats.channel)
     #print(nat_freq, inst_ty, damping, sen, recsen, gain, pazfile, stlo, stla, netid)
     
     # eqdt.datetime
     
     #print(pazfile, tr.stats.station)
     # get fft of trace
     freq, wavfft = calc_fft(tr_new.data, tr.stats.sampling_rate)  
     
     # get response for given frequencies
     real_resp, imag_resp = paz_response(freq, pazfile, sen, recsen, \
                                         gain, inst_ty)
     #print(pazfile, sen, recsen, gain, inst_ty)
     
     # deconvolve response
     corfftr, corffti = deconvolve_instrument(real_resp, imag_resp, wavfft)
Пример #6
0
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]