def get_amplitude(st, dt, seed_id): '''ampl_n = 0 ampl_e = 0 tr_n = st.select(component="N") if tr_n != None or len(tr_n)>0: ampl_n = max(abs(tr_n[0].data)) tr_e = st.select(component="E") if tr_e != None or len(tr_e)>0: ampl_e = max(abs(tr_e[0].data)) ampl = max(ampl_n, ampl_e)''' #stream correcting with NamedTemporaryFile() as tf: respf = tf.name old_iris_client = iris.Client() # fetch RESP information from "old" IRIS web service, see obspy.fdsn # for accessing the new IRIS FDSN web services arr = seed_id.split('.') old_iris_client.resp(arr[0], arr[1], arr[2], arr[3], dt, dt + 1800, filename=respf) # make a copy to keep our original data st_orig = st.copy() # define a filter band to prevent amplifying noise during the deconvolution pre_filt = (0.005, 0.006, 30.0, 35.0) # this can be the date of your raw data or any date for which the # SEED RESP-file is valid date = dt seedresp = { 'filename': respf, # RESP filename # when using Trace/Stream.simulate() the "date" parameter can # also be omitted, and the starttime of the trace is then used. 'date': date, # Units to return response in ('DIS', 'VEL' or ACC) 'units': 'DIS' } # Remove instrument response using the information from the given RESP file st.simulate(paz_remove=None, pre_filt=pre_filt, seedresp=seedresp) #################### ampl = max(abs(st[0].data)) for each in st: a = max(abs(each.data)) if a > ampl: ampl = a #print ampl return ampl
def processList(data): #print data[0] print "SLEEP", data[6], data[7] time.sleep(float(data[7] / 1000)) dt = UTCDateTime(data[5]) timeSeriesClient = iris.Client() client = Client("IRIS") netStation = data[0].split('.') network = netStation[0] station = netStation[1] magList = [] try: respData = timeSeriesClient.resp(network, station, '*', '*', dt) #print "SEEDLIST SUCCESS ", respData[0] seedList = parseResponse(respData.decode()) for each2 in seedList: arr = each2.split('.') try: st = client.get_waveforms(arr[0], arr[1], arr[2], arr[3], dt, dt + 1800) print "TIMESERIES SUCCESS", each2 ampl = get_amplitude(st, dt, each2) local_mag = calculate_local_magnitude(data[3], data[4], data[1], data[2], ampl) #print local_mag magList.append(local_mag) #print "Appended to magnitude list" except: #print "TIMESERIES FAIL", each2 continue print magList if len(magList) > 0: #print "Magnitude list obtained" retVal = str(data[6])+ "," + data[0]+ ","+ data[1] +"," +\ data[2] +","+ str(sum(magList)/float(len(magList))) #print "Returning value:", retVal return retVal else: return 'FAIL' except: print 'SEEDLIST FAIL ', data[0] return 'FAIL'
def main(): eventID = 4417721 client = Client("IRIS") cat = client.get_events(eventid=eventID) #print cat timeSeriesClient = iris.Client() eventLatitude = 40.8287 eventLongitude = -125.1338 eventTime = '2012-04-12T07:15:49.1700' eventMagnitude = 7.1 magUnit = 'MW' dt = UTCDateTime(eventTime) print "EARTHQUAKE", str(eventLatitude), str( eventLongitude), str(eventMagnitude) + " " + magUnit netStationList = set() #getting list of stations for US networks for each_net in USNETS: try: inventory = client.get_stations(network = each_net, latitude=eventLatitude,\ longitude=eventLongitude, maxradius=5) #print type(inventory) for each in inventory: each_content = each.get_contents() lat, lon = get_coordinates(each[0]) channelList = each_content['stations'] for each_channel in channelList: netStationList.add((each_channel.split()[0], lat, lon)) except: #print "Failed for", each_net continue #print inventory.get_contents() #print netStationList #getting time series data in a loop for each1 in netStationList: netStation = each1[0].split('.') network = netStation[0] station = netStation[1] magList = [] try: data = timeSeriesClient.resp(network, station, '*', '*', dt) #print "SEEDLIST SUCCESS ", each1[0] seedList = parseResponse(data.decode()) for each2 in seedList: arr = each2.split('.') try: st = client.get_waveforms(arr[0], arr[1], arr[2], arr[3], dt, dt + 1800) #print "TIMESERIES SUCCESS", each2 ampl = get_amplitude(st, dt, each2) local_mag = calculate_local_magnitude( eventLatitude, eventLongitude, each1[1], each1[2], ampl) magList.append(local_mag) #print each2, each1[1], each1[2], local_mag #print "TIMESERIES SUCCESS", each2 except: #print "TIMESERIES FAIL", each2 continue if len(magList) > 0: print each1[0], each1[1], each1[2], sum(magList) / float( len(magList)) except: #print 'SEEDLIST FAIL ', each1[0] continue