def deleteFarStations(CentroidList, StationClusterList, Config): cfg = ConfigObj(dict=Config) stationdistance = int(cfg.Distance('stationdistance')) for i in CentroidList: for j in StationClusterList: if i.rank == j.member: if loc2degrees(i, j) > stationdistance: j.member = -1 #endfor for index, k in enumerate(StationClusterList): if k.member == -1: del StationClusterList[index] return StationClusterList
def addOK(station, stationList, Config, MetaList): cfg = ConfigObj(dict=Config) minDist = cfg.Distance('centroidmindistance') minAround = cfg.UInt('minstationaroundinitialcluster') t = 0 for i in stationList: sdelta = loc2degrees(station, i) if sdelta > minDist: aroundcounter = checkStationAroundInitialCentroid( station, Config, MetaList) if aroundcounter >= minAround: t = 1 else: t = 0 return t else: t = 0 return t return t
def run_parallel(options): ''' Starts station search procedure :type options: instance :param options: parameter to initialize the networklist class ''' isClient = (options.args != None) if not init(options): return False if isClient: # Run client clt = StationListClient(options) clt.run() return True else: # Run server # Create directory for clients # clientDir = os.path.join(options.evpath, 'keyfiles-' + str(time.time())) Logfile.add('Create keyfile directory ', clientDir, ' ') create_dir(clientDir) # Build network list # C = config.Config(options.evpath) Origin = C.parseConfig('origin') Conf = Globals.ConfigDict checkConfigFile(Conf) globalCfg = ConfigObj(dict=Conf) originCfg = ConfigObj(dict=Origin) ot = originCfg.Time() # str(Origin['time']) elat = originCfg.lat() # Origin['lat'] elon = originCfg.lon() # Origin['lon'] minDist = globalCfg.Distance('mindist') # Conf ['mindist'] maxDist = globalCfg.Distance('maxdist') # Conf ['maxdist'] duration = globalCfg.Duration() # Conf ['duration'] paramList = [ot, maxDist, minDist, elat, elon] BL = [] if 'blacklist' in Conf: K = (Conf['blacklist']).split(',') BL = ['# Network Code'] BL.extend(K) T = NetworkList(ot, elat, elon, minDist, maxDist, duration, blacklist=BL, mail=Conf['mail']) SERVER_NAME = 'network' # Handle Iris networks # inetworks = T.getIRISList() #inetworks = ['BF'] if len(inetworks) == 0: Logfile.error('No iris networks found') else: args = Server.joinClientArgs([IRIS_TAG, clientDir], paramList) ctrl = Server.ServerCtrl(nRetries=1, nParallel=1, waitTime=1.0, printStat=False) srv = Server.ServerBase(SERVER_NAME, checkProcessError, ctrl) #if WINDOWS: srv.control.ClientProc = MainProc if not srv.run(inetworks, args): return False #endif # Handle Geofon networks # gnetworks = T.getWEBDCList() #gnetworks = ['AF'] #gnetworks = ['FR'] #gnetworks = [] if len(gnetworks) == 0: Logfile.error('No geofon networks found') else: # Access network infos now from Geofo # args = Server.joinClientArgs([GEOFON_TAG, clientDir], paramList) ctrl = Server.ServerCtrl(nRetries=4, nParallel=1, waitTime=2.0, printStat=False) srv = Server.ServerBase(SERVER_NAME, checkProcessError, ctrl) #if WINDOWS: srv.control.ClientProc = MainProc if not srv.run(gnetworks, args): return False #endif # Print statistic nIres = len(inetworks) nWebDC = len(gnetworks) nAll = nIres + nWebDC if nIres != 0: Logfile.add(' ', 'Processed ' + str(nIres) + ' IRES networks') if nWebDC != 0: Logfile.add('Processed ' + str(nWebDC) + ' WEBDC networks') if nAll == 0: return Logfile.error('No networks found') if nIres == 0: err = 'No IRIS network found' elif nWebDC == 0: err = 'No WEBDC network found' else: err = None if err != None: Logfile.add(err) # showNextStep # evpath = options.evpath.split('/')[-1] keyfoldername = clientDir.split('/')[-1] Logfile.add(' ', 'NEXT PROCESSING STEP:', ' ') Logfile.add(' 1) change keyfolder value in global.conf to ' + keyfoldername) Logfile.add(' 2) python arraytool.py getdata ' + evpath, ' ') return True
def filterBestSolution(solution): evp = os.path.join('/', *solution.path.split('/')[:-2]) C = Config(evp) Conf = C.parseConfig('config') cfg = ConfigObj(dict=Conf) SL = [] M = [] fobj = open(os.path.join(solution.path, 'event.stations'), 'r') for s in fobj: try: line = s.split() net, sta, loc, comp = line[0].split('.') slat = line[1] slon = line[2] smember = line[3] M.append(smember) SL.append( Station(net, sta, loc, comp, lat=slat, lon=slon, member=smember)) except: Logfile.exception('filterBestSolution', '<' + s + '>') continue #endfor fobj.close() M = list(set(M)) Logfile.add('number of clusters ' + str(len(M)), 'number of stations ' + str(len(SL))) kd = obs_kilometer2degrees(cfg.Distance('intraclusterdistance')) Logfile.add('icd ' + str(kd)) maxdist = -1 for i in SL: counter = 0 for k in SL: if i.member == '8' and k.member == '8': if i.getName() != k.getName(): delta = loc2degrees(i, k) if delta > maxdist: maxdist = delta print i, i.member, ' <--> ', k, k.member, ' delta: ', delta, ' allowed ', kd if delta < kd: counter += 1 #endif #endif #endfor print i, 'less then allowd ', counter #endfor print 'masxdist ', maxdist