def FDSN_create_bulk_list(target_path, input_dics, Stas_fdsn, event): """ Create bulkdata_list in case of --list_stas flag :param target_path: :param input_dics: :param Stas_fdsn: :param event: :return: """ if input_dics['fdsn_update'] != 'N': if os.path.exists(os.path.join(target_path, 'info', 'bulkdata.txt')): os.remove(os.path.join(target_path, 'info', 'bulkdata.txt')) if os.path.exists(os.path.join(target_path, 'info', 'bulkdata.txt')): print 'bulkdata.txt exists in the directory!' else: print 'Start creating a list for bulk request' bulk_list = [] for bulk_sta in Stas_fdsn: if input_dics['cut_time_phase']: t_start, t_end = calculate_time_phase(event, bulk_sta) else: t_start = event['t1'] t_end = event['t2'] bulk_list.append((bulk_sta[0], bulk_sta[1], bulk_sta[2], bulk_sta[3], t_start, t_end)) bulk_list_fio = open( os.path.join(target_path, 'info', 'bulkdata_list'), 'a+') pickle.dump(bulk_list, bulk_list_fio) bulk_list_fio.close()
def FDSN_create_bulk_list(target_path, input_dics, Stas_fdsn, event): """ Create bulkdata_list in case of --list_stas flag :param target_path: :param input_dics: :param Stas_fdsn: :param event: :return: """ if input_dics['fdsn_update'] != 'N': if os.path.exists(os.path.join(target_path, 'info', 'bulkdata.txt')): os.remove(os.path.join(target_path, 'info', 'bulkdata.txt')) if os.path.exists(os.path.join(target_path, 'info', 'bulkdata.txt')): print 'bulkdata.txt exists in the directory!' else: print 'Start creating a list for bulk request' bulk_list = [] for bulk_sta in Stas_fdsn: if input_dics['cut_time_phase']: t_start, t_end = calculate_time_phase(event, bulk_sta) else: t_start = event['t1'] t_end = event['t2'] bulk_list.append((bulk_sta[0], bulk_sta[1], bulk_sta[2], bulk_sta[3], t_start, t_end)) bulk_list_fio = open(os.path.join(target_path, 'info', 'bulkdata_list'), 'a+') pickle.dump(bulk_list, bulk_list_fio) bulk_list_fio.close()
def FDSN_create_bulk_list(target_path, input_dics, Stas_fdsn, event): """ Create bulkdata_list in case of --list_stas flag :param target_path: :param input_dics: :param Stas_fdsn: :param event: :return: """ if input_dics["fdsn_update"] != "N": if os.path.exists(os.path.join(target_path, "info", "bulkdata.txt")): os.remove(os.path.join(target_path, "info", "bulkdata.txt")) if os.path.exists(os.path.join(target_path, "info", "bulkdata.txt")): print "bulkdata.txt exists in the directory!" else: print "Start creating a list for bulk request" bulk_list = [] for bulk_sta in Stas_fdsn: if input_dics["cut_time_phase"]: t_start, t_end = calculate_time_phase(event, bulk_sta) else: t_start = event["t1"] t_end = event["t2"] bulk_list.append((bulk_sta[0], bulk_sta[1], bulk_sta[2], bulk_sta[3], t_start, t_end)) bulk_list_fio = open(os.path.join(target_path, "info", "bulkdata_list"), "a+") pickle.dump(bulk_list, bulk_list_fio) bulk_list_fio.close()
def FDSN_available(input_dics, event, target_path, event_number): """ Check the availablity of FDSN stations :param input_dics: :param event: :param target_path: :param event_number: :return: """ print "Check the availablity of FDSN stations: %s" \ % input_dics['fdsn_base_url'] client_fdsn = Client_fdsn(base_url=input_dics['fdsn_base_url'], user=input_dics['fdsn_user'], password=input_dics['fdsn_pass']) Sta_fdsn = [] try: if input_dics['fdsn_base_url'].lower() in ['resif']: # start_time = None # end_time = None start_time = event['t1'] end_time = event['t2'] else: start_time = event['t1'] end_time = event['t2'] available = client_fdsn.get_stations( network=input_dics['net'], station=input_dics['sta'], location=input_dics['loc'], channel=input_dics['cha'], starttime=start_time, endtime=end_time, latitude=input_dics['lat_cba'], longitude=input_dics['lon_cba'], minradius=input_dics['mr_cba'], maxradius=input_dics['Mr_cba'], minlatitude=input_dics['mlat_rbb'], maxlatitude=input_dics['Mlat_rbb'], minlongitude=input_dics['mlon_rbb'], maxlongitude=input_dics['Mlon_rbb'], level='channel') for network in available.networks: for station in network: for channel in station: Sta_fdsn.append([network.code, station.code, channel.location_code, channel.code, channel.latitude, channel.longitude, channel.elevation, channel.depth]) if input_dics['fdsn_bulk'] == 'Y': if input_dics['fdsn_update'] != 'N': if os.path.exists(os.path.join(target_path, 'info', 'bulkdata.txt')): os.remove(os.path.join(target_path, 'info', 'bulkdata.txt')) if os.path.exists(os.path.join(target_path, 'info', 'bulkdata.txt')): print 'bulkdata.txt exists in the directory!' else: print 'Start creating a list for bulk request' bulk_list = [] for bulk_sta in Sta_fdsn: if input_dics['cut_time_phase']: t_start, t_end = calculate_time_phase(event, bulk_sta) else: t_start = event['t1'] t_end = event['t2'] bulk_list.append((bulk_sta[0], bulk_sta[1], bulk_sta[2], bulk_sta[3], t_start, t_end)) bulk_list_fio = open(os.path.join(target_path, 'info', 'bulkdata_list'), 'a+') pickle.dump(bulk_list, bulk_list_fio) bulk_list_fio.close() except Exception as e: exc_file = open(os.path.join(target_path, 'info', 'exception'), 'a+') ee = 'fdsn -- Event: %s --- %s\n' % (str(event_number+1), e) exc_file.writelines(ee) exc_file.close() print 'ERROR: %s' % ee if len(Sta_fdsn) == 0: Sta_fdsn.append([]) Sta_fdsn.sort() return Sta_fdsn
def FDSN_download_core(i, j, dic, len_events, events, add_event, Sta_req, input_dics, client_fdsn): """ Downloading the waveforms, reponse files (StationXML) and metadata This program should be normally called by some higher-level functions """ dummy = 'Initializing' info_req = 'None' t11 = datetime.now() try: info_req = '[%s/%s-%s/%s-%s] ' % (i+1, len_events, j+1, len(Sta_req), input_dics['cha']) if Sta_req[j][2] == '--' or Sta_req[j][2] == ' ': Sta_req[j][2] = '' if input_dics['cut_time_phase']: t_start, t_end = calculate_time_phase(events[i], Sta_req[j]) else: t_start = events[i]['t1'] t_end = events[i]['t2'] if input_dics['waveform'] == 'Y': dummy = 'Waveform' client_fdsn.get_waveforms(Sta_req[j][0], Sta_req[j][1], Sta_req[j][2], Sta_req[j][3], t_start, t_end, filename=os.path.join(add_event[i], 'BH_RAW', '%s.%s.%s.%s' % (Sta_req[j][0], Sta_req[j][1], Sta_req[j][2], Sta_req[j][3]))) print '%ssaving waveform for: %s.%s.%s.%s ---> DONE' \ % (info_req, Sta_req[j][0], Sta_req[j][1], Sta_req[j][2], Sta_req[j][3]) if input_dics['response'] == 'Y': dummy = 'Response' client_fdsn.get_stations(network=Sta_req[j][0], station=Sta_req[j][1], location=Sta_req[j][2], channel=Sta_req[j][3], # starttime=t_start, endtime=t_end, filename=os.path.join(add_event[i], 'Resp', 'STXML.%s.%s.%s.%s' % (Sta_req[j][0], Sta_req[j][1], Sta_req[j][2], Sta_req[j][3])), level='response') print "%ssaving Response for: %s.%s.%s.%s ---> DONE" \ % (info_req, Sta_req[j][0], Sta_req[j][1], Sta_req[j][2], Sta_req[j][3]) dummy = 'Meta-data' dic[j] = {'info': '%s.%s.%s.%s' % (Sta_req[j][0], Sta_req[j][1], Sta_req[j][2], Sta_req[j][3]), 'net': Sta_req[j][0], 'sta': Sta_req[j][1], 'latitude': Sta_req[j][4], 'longitude': Sta_req[j][5], 'loc': Sta_req[j][2], 'cha': Sta_req[j][3], 'elevation': Sta_req[j][6], 'depth': Sta_req[j][7]} Syn_file = open(os.path.join(add_event[i], 'info', 'station_event'), 'a') syn = '%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,\n' \ % (dic[j]['net'], dic[j]['sta'], dic[j]['loc'], dic[j]['cha'], dic[j]['latitude'], dic[j]['longitude'], float(dic[j]['elevation']), float(dic[j]['depth']), events[i]['event_id'], events[i]['latitude'], events[i]['longitude'], events[i]['depth'], events[i]['magnitude'], input_dics['fdsn_base_url']) Syn_file.writelines(syn) Syn_file.close() print "%ssaving Metadata for: %s.%s.%s.%s ---> DONE" \ % (info_req, Sta_req[j][0], Sta_req[j][1], Sta_req[j][2], Sta_req[j][3]) t22 = datetime.now() if input_dics['time_fdsn'] == 'Y': time_fdsn = t22 - t11 time_file = open(os.path.join(add_event[i], 'info', 'time_fdsn'), 'a') size = getFolderSize(os.path.join(add_event[i])) ti = '%s,%s,%s,%s,%s,%s,%s,+,\n' % (Sta_req[j][0], Sta_req[j][1], Sta_req[j][2], Sta_req[j][3], time_fdsn.seconds, time_fdsn.microseconds, size/(1024.**2)) time_file.writelines(ti) time_file.close() except Exception as e: t22 = datetime.now() if input_dics['time_fdsn'] == 'Y': time_fdsn = t22 - t11 time_file = open(os.path.join(add_event[i], 'info', 'time_fdsn'), 'a') size = getFolderSize(os.path.join(add_event[i])) ti = '%s,%s,%s,%s,%s,%s,%s,-,\n' % (Sta_req[j][0], Sta_req[j][1], Sta_req[j][2], Sta_req[j][3], time_fdsn.seconds, time_fdsn.microseconds, size/(1024.**2)) time_file.writelines(ti) time_file.close() if len(Sta_req[j]) != 0: print '%s%s---%s.%s.%s.%s' % (info_req, dummy, Sta_req[j][0], Sta_req[j][1], Sta_req[j][2], Sta_req[j][3]) ee = 'fdsn -- %s---%s-%s---%s.%s.%s.%s---%s\n' \ % (dummy, i+1, j+1, Sta_req[j][0], Sta_req[j][1], Sta_req[j][2], Sta_req[j][3], e) else: ee = 'There is no available station for this event.' Exception_file = open(os.path.join(add_event[i], 'info', 'exception'), 'a') Exception_file.writelines(ee) Exception_file.close() print 'ERROR: %s' % ee
def ARC_download_core(i, j, dic, len_events, events, add_event, Sta_req, input_dics, client_arclink): """ Downloading waveforms, response files and metadata This program should be normally called by some higher-level functions """ dummy = 'Initializing' info_req = 'None' t11 = datetime.now() try: info_req = '[%s/%s-%s/%s-%s] ' % (i+1, len_events, j+1, len(Sta_req), input_dics['cha']) if Sta_req[j][2] == '--' or Sta_req[j][2] == ' ': Sta_req[j][2] = '' if input_dics['cut_time_phase']: t_start, t_end = calculate_time_phase(events[i], Sta_req[j]) else: t_start = events[i]['t1'] t_end = events[i]['t2'] if input_dics['waveform'] == 'Y': dummy = 'Waveform' client_arclink.saveWaveform(os.path.join(add_event[i], 'BH_RAW', '%s.%s.%s.%s' % (Sta_req[j][0], Sta_req[j][1], Sta_req[j][2], Sta_req[j][3])), Sta_req[j][0], Sta_req[j][1], Sta_req[j][2], Sta_req[j][3], t_start, t_end) print '%ssaving waveform for: %s.%s.%s.%s ---> DONE' \ % (info_req, Sta_req[j][0], Sta_req[j][1], Sta_req[j][2], Sta_req[j][3]) if input_dics['response'] == 'Y': dummy = 'Response' client_arclink.saveResponse(os.path.join(add_event[i], 'Resp', 'DATALESS.%s.%s.%s.%s' % (Sta_req[j][0], Sta_req[j][1], Sta_req[j][2], Sta_req[j][3])), Sta_req[j][0], Sta_req[j][1], Sta_req[j][2], Sta_req[j][3], t_start, t_end) print "%ssaving Response for: %s.%s.%s.%s ---> DONE" \ % (info_req, Sta_req[j][0], Sta_req[j][1], Sta_req[j][2], Sta_req[j][3]) if input_dics['paz'] == 'Y': dummy = 'PAZ' paz_arc = client_arclink.getPAZ(Sta_req[j][0], Sta_req[j][1], Sta_req[j][2], Sta_req[j][3], time=t_start) paz_file = open(os.path.join(add_event[i], 'Resp', 'PAZ.%s.%s.%s.%s.paz' % (Sta_req[j][0], Sta_req[j][1], Sta_req[j][2], Sta_req[j][3])), 'w') pickle.dump(paz_arc, paz_file) paz_file.close() print "%ssaving PAZ for : %s.%s.%s.%s ---> DONE" \ % (info_req, Sta_req[j][0], Sta_req[j][1], Sta_req[j][2], Sta_req[j][3]) dummy = 'Meta-data' dic[j] = {'info': '%s.%s.%s.%s' % (Sta_req[j][0], Sta_req[j][1], Sta_req[j][2], Sta_req[j][3]), 'net': Sta_req[j][0], 'sta': Sta_req[j][1], 'latitude': Sta_req[j][4], 'longitude': Sta_req[j][5], 'loc': Sta_req[j][2], 'cha': Sta_req[j][3], 'elevation': Sta_req[j][6], 'depth': Sta_req[j][7]} Syn_file = open(os.path.join(add_event[i], 'info', 'station_event'), 'a') syn = '%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,arc,\n' \ % (dic[j]['net'], dic[j]['sta'], dic[j]['loc'], dic[j]['cha'], dic[j]['latitude'], dic[j]['longitude'], float(dic[j]['elevation']), float(dic[j]['depth']), events[i]['event_id'], events[i]['latitude'], events[i]['longitude'], events[i]['depth'], events[i]['magnitude']) Syn_file.writelines(syn) Syn_file.close() print "%ssaving Metadata for: %s.%s.%s.%s ---> DONE" \ % (info_req, Sta_req[j][0], Sta_req[j][1], Sta_req[j][2], Sta_req[j][3]) t22 = datetime.now() if input_dics['time_arc'] == 'Y': time_arc = t22 - t11 time_file = open(os.path.join(add_event[i], 'info', 'time_arc'), 'a') size = getFolderSize(os.path.join(add_event[i])) ti = '%s,%s,%s,%s,%s,%s,%s,+,\n' % (Sta_req[j][0], Sta_req[j][1], Sta_req[j][2], Sta_req[j][3], time_arc.seconds, time_arc.microseconds, size/(1024.**2)) time_file.writelines(ti) time_file.close() except Exception as e: t22 = datetime.now() if input_dics['time_arc'] == 'Y': time_arc = t22 - t11 time_file = open(os.path.join(add_event[i], 'info', 'time_arc'), 'a') size = getFolderSize(os.path.join(add_event[i])) ti = '%s,%s,%s,%s,%s,%s,%s,-,\n' % (Sta_req[j][0], Sta_req[j][1], Sta_req[j][2], Sta_req[j][3], time_arc.seconds, time_arc.microseconds, size/(1024.**2)) time_file.writelines(ti) time_file.close() if len(Sta_req[j]) != 0: print '%s%s---%s.%s.%s.%s' % (info_req, dummy, Sta_req[j][0], Sta_req[j][1], Sta_req[j][2], Sta_req[j][3]) ee = 'arc -- %s---%s-%s---%s.%s.%s.%s---%s\n' \ % (dummy, i+1, j+1, Sta_req[j][0], Sta_req[j][1], Sta_req[j][2], Sta_req[j][3], e) else: ee = 'There is no available station for this event.' Exception_file = open(os.path.join(add_event[i], 'info', 'exception'), 'a') Exception_file.writelines(ee) Exception_file.close() print 'ERROR: %s' % ee
def FDSN_download_core(i, j, dic, len_events, events, add_event, Sta_req, input_dics, client_fdsn): """ Downloading the waveforms, reponse files (StationXML) and metadata This program should be normally called by some higher-level functions """ dummy = 'Initializing' info_req = 'None' t11 = datetime.now() try: info_req = '[%s/%s-%s/%s-%s] ' % (i + 1, len_events, j + 1, len(Sta_req), input_dics['cha']) if Sta_req[j][2] == '--' or Sta_req[j][2] == ' ': Sta_req[j][2] = '' if input_dics['cut_time_phase']: t_start, t_end = calculate_time_phase(events[i], Sta_req[j]) else: t_start = events[i]['t1'] t_end = events[i]['t2'] if input_dics['waveform'] == 'Y': dummy = 'Waveform' client_fdsn.get_waveforms( Sta_req[j][0], Sta_req[j][1], Sta_req[j][2], Sta_req[j][3], t_start, t_end, filename=os.path.join( add_event[i], 'BH_RAW', '%s.%s.%s.%s' % (Sta_req[j][0], Sta_req[j][1], Sta_req[j][2], Sta_req[j][3]))) print '%ssaving waveform for: %s.%s.%s.%s ---> DONE' \ % (info_req, Sta_req[j][0], Sta_req[j][1], Sta_req[j][2], Sta_req[j][3]) if input_dics['response'] == 'Y': dummy = 'Response' if os.path.isfile( os.path.join( add_event[i], 'BH_RAW', '%s.%s.%s.%s' % (Sta_req[j][0], Sta_req[j][1], Sta_req[j][2], Sta_req[j][3]))): client_fdsn.get_stations( network=Sta_req[j][0], station=Sta_req[j][1], location=Sta_req[j][2], channel=Sta_req[j][3], starttime=t_start, endtime=t_end, filename=os.path.join( add_event[i], 'Resp', 'STXML.%s.%s.%s.%s' % (Sta_req[j][0], Sta_req[j][1], Sta_req[j][2], Sta_req[j][3])), level='response') else: raise Exception("Waveform does not exist! (666)") print "%ssaving Response for: %s.%s.%s.%s ---> DONE" \ % (info_req, Sta_req[j][0], Sta_req[j][1], Sta_req[j][2], Sta_req[j][3]) dummy = 'Meta-data' dic[j] = { 'info': '%s.%s.%s.%s' % (Sta_req[j][0], Sta_req[j][1], Sta_req[j][2], Sta_req[j][3]), 'net': Sta_req[j][0], 'sta': Sta_req[j][1], 'latitude': Sta_req[j][4], 'longitude': Sta_req[j][5], 'loc': Sta_req[j][2], 'cha': Sta_req[j][3], 'elevation': Sta_req[j][6], 'depth': Sta_req[j][7] } Syn_file = open(os.path.join(add_event[i], 'info', 'station_event'), 'a') syn = '%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,\n' \ % (dic[j]['net'], dic[j]['sta'], dic[j]['loc'], dic[j]['cha'], dic[j]['latitude'], dic[j]['longitude'], float(dic[j]['elevation']), float(dic[j]['depth']), events[i]['event_id'], events[i]['latitude'], events[i]['longitude'], events[i]['depth'], events[i]['magnitude'], input_dics['fdsn_base_url']) Syn_file.writelines(syn) Syn_file.close() print "%ssaving Metadata for: %s.%s.%s.%s ---> DONE" \ % (info_req, Sta_req[j][0], Sta_req[j][1], Sta_req[j][2], Sta_req[j][3]) t22 = datetime.now() if input_dics['time_fdsn'] == 'Y': time_fdsn = t22 - t11 time_file = open(os.path.join(add_event[i], 'info', 'time_fdsn'), 'a') size = getFolderSize(os.path.join(add_event[i])) ti = '%s,%s,%s,%s,%s,%s,%s,+,\n' % ( Sta_req[j][0], Sta_req[j][1], Sta_req[j][2], Sta_req[j][3], time_fdsn.seconds, time_fdsn.microseconds, size / (1024.**2)) time_file.writelines(ti) time_file.close() except Exception as e: t22 = datetime.now() if input_dics['time_fdsn'] == 'Y': time_fdsn = t22 - t11 time_file = open(os.path.join(add_event[i], 'info', 'time_fdsn'), 'a') size = getFolderSize(os.path.join(add_event[i])) ti = '%s,%s,%s,%s,%s,%s,%s,-,\n' % ( Sta_req[j][0], Sta_req[j][1], Sta_req[j][2], Sta_req[j][3], time_fdsn.seconds, time_fdsn.microseconds, size / (1024.**2)) time_file.writelines(ti) time_file.close() if len(Sta_req[j]) != 0: ee = 'fdsn -- %s---%s-%s---%s.%s.%s.%s---%s\n' \ % (dummy, i+1, j+1, Sta_req[j][0], Sta_req[j][1], Sta_req[j][2], Sta_req[j][3], e) if not '666' in ee: print '%s%s---%s.%s.%s.%s' % (info_req, dummy, Sta_req[j][0], Sta_req[j][1], Sta_req[j][2], Sta_req[j][3]) else: ee = 'There is no available station for this event.' Exception_file = open(os.path.join(add_event[i], 'info', 'exception'), 'a') Exception_file.writelines(ee) Exception_file.close() if not '666' in ee: print 'ERROR: %s' % ee
def FDSN_available(input_dics, event, target_path, event_number): """ Check the availablity of FDSN stations :param input_dics: :param event: :param target_path: :param event_number: :return: """ print "Check the availablity of FDSN stations: %s" \ % input_dics['fdsn_base_url'] client_fdsn = Client_fdsn(base_url=input_dics['fdsn_base_url'], user=input_dics['fdsn_user'], password=input_dics['fdsn_pass']) Sta_fdsn = [] try: if input_dics['fdsn_base_url'].lower() in ['resif']: # start_time = None # end_time = None start_time = event['t1'] end_time = event['t2'] else: start_time = event['t1'] end_time = event['t2'] available = client_fdsn.get_stations( network=input_dics['net'], station=input_dics['sta'], location=input_dics['loc'], channel=input_dics['cha'], starttime=start_time, endtime=end_time, latitude=input_dics['lat_cba'], longitude=input_dics['lon_cba'], minradius=input_dics['mr_cba'], maxradius=input_dics['Mr_cba'], minlatitude=input_dics['mlat_rbb'], maxlatitude=input_dics['Mlat_rbb'], minlongitude=input_dics['mlon_rbb'], maxlongitude=input_dics['Mlon_rbb'], level='channel') for network in available.networks: for station in network: for channel in station: Sta_fdsn.append([ network.code, station.code, channel.location_code, channel.code, channel.latitude, channel.longitude, channel.elevation, channel.depth ]) if input_dics['fdsn_bulk'] == 'Y': if input_dics['fdsn_update'] != 'N': if os.path.exists( os.path.join(target_path, 'info', 'bulkdata.txt')): os.remove(os.path.join(target_path, 'info', 'bulkdata.txt')) if os.path.exists(os.path.join(target_path, 'info', 'bulkdata.txt')): print 'bulkdata.txt exists in the directory!' else: print 'Start creating a list for bulk request' bulk_list = [] for bulk_sta in Sta_fdsn: if input_dics['cut_time_phase']: t_start, t_end = calculate_time_phase(event, bulk_sta) else: t_start = event['t1'] t_end = event['t2'] bulk_list.append((bulk_sta[0], bulk_sta[1], bulk_sta[2], bulk_sta[3], t_start, t_end)) bulk_list_fio = open( os.path.join(target_path, 'info', 'bulkdata_list'), 'a+') pickle.dump(bulk_list, bulk_list_fio) bulk_list_fio.close() except Exception as e: exc_file = open(os.path.join(target_path, 'info', 'exception'), 'a+') ee = 'fdsn -- Event: %s --- %s\n' % (str(event_number + 1), e) exc_file.writelines(ee) exc_file.close() print 'ERROR: %s' % ee if len(Sta_fdsn) == 0: Sta_fdsn.append([]) Sta_fdsn.sort() return Sta_fdsn
def FDSN_download_core(i, j, dic, len_events, events, add_event, Sta_req, input_dics, client_fdsn): """ Downloading the waveforms, reponse files (StationXML) and metadata This program should be normally called by some higher-level functions """ dummy = "Initializing" info_req = "None" t11 = datetime.now() try: info_req = "[%s/%s-%s/%s-%s] " % (i + 1, len_events, j + 1, len(Sta_req), input_dics["cha"]) if Sta_req[j][2] == "--" or Sta_req[j][2] == " ": Sta_req[j][2] = "" if input_dics["cut_time_phase"]: t_start, t_end = calculate_time_phase(events[i], Sta_req[j]) else: t_start = events[i]["t1"] t_end = events[i]["t2"] if input_dics["waveform"] == "Y": dummy = "Waveform" client_fdsn.get_waveforms( Sta_req[j][0], Sta_req[j][1], Sta_req[j][2], Sta_req[j][3], t_start, t_end, filename=os.path.join( add_event[i], "BH_RAW", "%s.%s.%s.%s" % (Sta_req[j][0], Sta_req[j][1], Sta_req[j][2], Sta_req[j][3]) ), ) print "%ssaving waveform for: %s.%s.%s.%s ---> DONE" % ( info_req, Sta_req[j][0], Sta_req[j][1], Sta_req[j][2], Sta_req[j][3], ) if input_dics["response"] == "Y": dummy = "Response" if os.path.isfile( os.path.join( add_event[i], "BH_RAW", "%s.%s.%s.%s" % (Sta_req[j][0], Sta_req[j][1], Sta_req[j][2], Sta_req[j][3]) ) ): client_fdsn.get_stations( network=Sta_req[j][0], station=Sta_req[j][1], location=Sta_req[j][2], channel=Sta_req[j][3], starttime=t_start, endtime=t_end, filename=os.path.join( add_event[i], "Resp", "STXML.%s.%s.%s.%s" % (Sta_req[j][0], Sta_req[j][1], Sta_req[j][2], Sta_req[j][3]), ), level="response", ) else: raise Exception("Waveform does not exist! (666)") print "%ssaving Response for: %s.%s.%s.%s ---> DONE" % ( info_req, Sta_req[j][0], Sta_req[j][1], Sta_req[j][2], Sta_req[j][3], ) dummy = "Meta-data" dic[j] = { "info": "%s.%s.%s.%s" % (Sta_req[j][0], Sta_req[j][1], Sta_req[j][2], Sta_req[j][3]), "net": Sta_req[j][0], "sta": Sta_req[j][1], "latitude": Sta_req[j][4], "longitude": Sta_req[j][5], "loc": Sta_req[j][2], "cha": Sta_req[j][3], "elevation": Sta_req[j][6], "depth": Sta_req[j][7], } Syn_file = open(os.path.join(add_event[i], "info", "station_event"), "a") syn = "%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,\n" % ( dic[j]["net"], dic[j]["sta"], dic[j]["loc"], dic[j]["cha"], dic[j]["latitude"], dic[j]["longitude"], float(dic[j]["elevation"]), float(dic[j]["depth"]), events[i]["event_id"], events[i]["latitude"], events[i]["longitude"], events[i]["depth"], events[i]["magnitude"], input_dics["fdsn_base_url"], ) Syn_file.writelines(syn) Syn_file.close() print "%ssaving Metadata for: %s.%s.%s.%s ---> DONE" % ( info_req, Sta_req[j][0], Sta_req[j][1], Sta_req[j][2], Sta_req[j][3], ) t22 = datetime.now() if input_dics["time_fdsn"] == "Y": time_fdsn = t22 - t11 time_file = open(os.path.join(add_event[i], "info", "time_fdsn"), "a") size = getFolderSize(os.path.join(add_event[i])) ti = "%s,%s,%s,%s,%s,%s,%s,+,\n" % ( Sta_req[j][0], Sta_req[j][1], Sta_req[j][2], Sta_req[j][3], time_fdsn.seconds, time_fdsn.microseconds, size / (1024.0 ** 2), ) time_file.writelines(ti) time_file.close() except Exception as e: t22 = datetime.now() if input_dics["time_fdsn"] == "Y": time_fdsn = t22 - t11 time_file = open(os.path.join(add_event[i], "info", "time_fdsn"), "a") size = getFolderSize(os.path.join(add_event[i])) ti = "%s,%s,%s,%s,%s,%s,%s,-,\n" % ( Sta_req[j][0], Sta_req[j][1], Sta_req[j][2], Sta_req[j][3], time_fdsn.seconds, time_fdsn.microseconds, size / (1024.0 ** 2), ) time_file.writelines(ti) time_file.close() if len(Sta_req[j]) != 0: ee = "fdsn -- %s---%s-%s---%s.%s.%s.%s---%s\n" % ( dummy, i + 1, j + 1, Sta_req[j][0], Sta_req[j][1], Sta_req[j][2], Sta_req[j][3], e, ) if not "666" in ee: print "%s%s---%s.%s.%s.%s" % ( info_req, dummy, Sta_req[j][0], Sta_req[j][1], Sta_req[j][2], Sta_req[j][3], ) else: ee = "There is no available station for this event." Exception_file = open(os.path.join(add_event[i], "info", "exception"), "a") Exception_file.writelines(ee) Exception_file.close() if not "666" in ee: print "ERROR: %s" % ee
def FDSN_available(input_dics, event, target_path, event_number): """ Check the availablity of FDSN stations :param input_dics: :param event: :param target_path: :param event_number: :return: """ print "Check the availablity of FDSN stations: %s" % input_dics["fdsn_base_url"] client_fdsn = Client_fdsn( base_url=input_dics["fdsn_base_url"], user=input_dics["fdsn_user"], password=input_dics["fdsn_pass"] ) Sta_fdsn = [] try: if input_dics["fdsn_base_url"].lower() in ["resif"]: # start_time = None # end_time = None start_time = event["t1"] end_time = event["t2"] else: start_time = event["t1"] end_time = event["t2"] available = client_fdsn.get_stations( network=input_dics["net"], station=input_dics["sta"], location=input_dics["loc"], channel=input_dics["cha"], starttime=start_time, endtime=end_time, latitude=input_dics["lat_cba"], longitude=input_dics["lon_cba"], minradius=input_dics["mr_cba"], maxradius=input_dics["Mr_cba"], minlatitude=input_dics["mlat_rbb"], maxlatitude=input_dics["Mlat_rbb"], minlongitude=input_dics["mlon_rbb"], maxlongitude=input_dics["Mlon_rbb"], level="channel", ) for network in available.networks: for station in network: for channel in station: Sta_fdsn.append( [ network.code, station.code, channel.location_code, channel.code, channel.latitude, channel.longitude, channel.elevation, channel.depth, ] ) if input_dics["fdsn_bulk"] == "Y": if input_dics["fdsn_update"] != "N": if os.path.exists(os.path.join(target_path, "info", "bulkdata.txt")): os.remove(os.path.join(target_path, "info", "bulkdata.txt")) if os.path.exists(os.path.join(target_path, "info", "bulkdata.txt")): print "bulkdata.txt exists in the directory!" else: print "Start creating a list for bulk request" bulk_list = [] for bulk_sta in Sta_fdsn: if input_dics["cut_time_phase"]: t_start, t_end = calculate_time_phase(event, bulk_sta) else: t_start = event["t1"] t_end = event["t2"] bulk_list.append((bulk_sta[0], bulk_sta[1], bulk_sta[2], bulk_sta[3], t_start, t_end)) bulk_list_fio = open(os.path.join(target_path, "info", "bulkdata_list"), "a+") pickle.dump(bulk_list, bulk_list_fio) bulk_list_fio.close() except Exception as e: exc_file = open(os.path.join(target_path, "info", "exception"), "a+") ee = "fdsn -- Event: %s --- %s\n" % (str(event_number + 1), e) exc_file.writelines(ee) exc_file.close() print "ERROR: %s" % ee if len(Sta_fdsn) == 0: Sta_fdsn.append([]) Sta_fdsn.sort() return Sta_fdsn