def ARC_reporter(i, add_event, events, input_dics, Sta_req, len_sta_ev, req_type, t_wave_1): """ Writing reports for the request :param i: :param add_event: :param events: :param input_dics: :param Sta_req: :param len_sta_ev: :param req_type: :param t_wave_1: :return: """ report = open(os.path.join(add_event[i], 'info', 'report_st'), 'a') eventsID = events[i]['event_id'] report.writelines('<><><><><><><><><><><><><><><><><>\n') report.writelines(eventsID + '\n') report.writelines('---------------ARC---------------\n') report.writelines('---------------%s---------------\n' % input_dics['cha']) rep = 'ARC-Available stations for channel %s and for event-%s: %s\n' \ % (input_dics['cha'], i, len(Sta_req)) report.writelines(rep) rep = 'ARC-%s stations for channel %s and for event-%s: %s\n' \ % (req_type, input_dics['cha'], i, len_sta_ev) report.writelines(rep) report.writelines('----------------------------------\n') t_wave = datetime.now() - t_wave_1 rep = 'Time for %sing Waveforms from ArcLink: %s\n' % (req_type, t_wave) report.writelines(rep) report.writelines('----------------------------------\n') report.close() if input_dics['req_parallel'] == 'Y': report_parallel_open = open(os.path.join(add_event[i], 'info', 'report_parallel'), 'a') report_parallel_open.writelines('---------------ARC---------------\n') report_parallel_open.writelines('Request\n') report_parallel_open.writelines('Number of Nodes: %s\n' % input_dics['req_np']) size = getFolderSize(os.path.join(add_event[i])) ti = '%s,%s,%s,+,\n' % (t_wave.seconds, t_wave.microseconds, size/(1024.**2)) report_parallel_open.writelines('Total Time : %s\n' % t_wave) report_parallel_open.writelines(ti) report_parallel_open.close() print "\n------------------------" print 'ArcLink for event-%s is Done' % (i+1) print 'Total Time: %s' % t_wave print "------------------------"
def FDSN_reporter(i, add_event, events, input_dics, Sta_req, len_sta_ev, req_type, t_wave_1): """ Writing reports for the request """ report = open(os.path.join(add_event[i], "info", "report_st"), "a") eventsID = events[i]["event_id"] report.writelines("<><><><><><><><><><><><><><><><><>\n") report.writelines(eventsID + "\n") report.writelines("---------------%s---------------\n" % input_dics["fdsn_base_url"]) report.writelines("---------------%s---------------\n" % input_dics["cha"]) rep = "FDSN-Available stations for channel %s and for event-%s: %s\n" % (input_dics["cha"], i, len(Sta_req)) report.writelines(rep) rep = "FDSN-%s stations for channel %s and for event-%s: %s\n" % (req_type, input_dics["cha"], i, len_sta_ev) report.writelines(rep) report.writelines("----------------------------------\n") t_wave = datetime.now() - t_wave_1 rep = "Time for %sing Waveforms from FDSN: %s\n" % (req_type, t_wave) report.writelines(rep) report.writelines("----------------------------------\n") report.close() if input_dics["req_parallel"] == "Y": report_parallel_open = open(os.path.join(add_event[i], "info", "report_parallel"), "a") report_parallel_open.writelines("---------------%s---------------\n" % input_dics["fdsn_base_url"]) report_parallel_open.writelines("Request\n") if input_dics["fdsn_bulk"] == "Y": report_parallel_open.writelines("Number of Nodes: (bulk) %s\n" % input_dics["req_np"]) else: report_parallel_open.writelines("Number of Nodes: %s\n" % input_dics["req_np"]) size = getFolderSize(os.path.join(add_event[i])) ti = "%s,%s,%s,+,\n" % (t_wave.seconds, t_wave.microseconds, size / (1024.0 ** 2)) report_parallel_open.writelines("Total Time : %s\n" % t_wave) report_parallel_open.writelines(ti) report_parallel_open.close() print "\n------------------------" print "FDSN for event-%s is Done" % (i + 1) print "Total Time: %s" % t_wave print "------------------------"
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_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