def common_fft(chan_dat, inst_ty, sps, seltask): # view wave and trim if necessary print(chan_dat) start_index, stop_index = plotting.trim_wave(chan_dat, sps, inst_ty, False) #taper_dat = chan_dat[0, start_index:stop_index] taper_dat = chan_dat[start_index:stop_index] taper_dat = taper_dat.reshape(1, len(taper_dat)) # taper time-domain before fft taper_dat, costaper = spectral_analysis.cosine_taper(taper_dat) # do acausal filter in time domain using 4th order Butterworth filter # lofreq, hifreq, filtwave = spectral_analysis.acausal_butter_filter(inst_ty, sps, taper_dat, seltask) # filtwave = taper_dat.reshape(1, len(filtwave)) # get FFT of data stream for full record # freq, wavfft = spectral_analysis.calc_fft(filtwave, sps) freq, wavfft = spectral_analysis.calc_fft(taper_dat[0], sps) # filter FFT using 4th order Butterworth filter lofreq, hifreq, wavfft = spectral_analysis.butter_filter_user( inst_ty, sps, freq, wavfft, seltask) # get time offset for filenames dt = start_index / float(sps) return freq, lofreq, hifreq, wavfft, dt
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]
def get_fft_spectra(tr_trim, sttr, ettr, channel): tr_trim.taper(0.02, type='hann', max_length=None, side='both') freq, wavfft = calc_fft(tr_trim.data, tr_trim.stats.sampling_rate) mxidx = (len(freq)/2) mxidx = int(round(mxidx)) # get fft freqs and amps freqs = abs(freq[1:mxidx]) spec_amps = abs(wavfft.real[1:mxidx]) # get displacement spectra if channel[1] == 'N': # if accelerometer disp_amps = spec_amps / (2.*(pi)*freqs)**2 else: # if seismometer disp_amps = spec_amps / (2.*(pi)*freqs) # smooth spectra if len(freq) > 10000: sw = 201 elif len(freq) > 5000: sw = 101 elif len(freq) > 1000: sw = 51 elif len(freq) > 500: sw = 21 else: sw = 5 # smooth spectra if sw > 11: smoothed_disp = exp(savitzky_golay(log(disp_amps), sw, 3)) else: smoothed_disp = exp(savitzky_golay(log(disp_amps), sw, 2)) # log-log interpolate to "interp_freqs" smoothed_interp_disp = exp(interp(log(interp_freqs), log(freqs), log(smoothed_disp), \ left=nan, right=nan)) return tr_trim, freqs, disp_amps, smoothed_disp, smoothed_interp_disp
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) # make new instrument corrected velocity trace pgv, ivel = get_cor_velocity( corfftr, corffti, freq, inst_ty) # overwrite tr.data tr.data = ivel.real
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]