def ExecuteGlobk(JobServer, GamitConfig, sessions, dates): project = GamitConfig.NetworkConfig.network_id.lower() tqdm.write( ' >> %s Combining with GLOBK sessions with more than one subnetwork...' % print_datetime()) modules = ('os', 'shutil', 'snxParse', 'subprocess', 'platform', 'traceback', 'glob', 'dbConnection', 'math') JobServer.create_cluster(run_globk, (pyGlobkTask.Globk, pyGamitSession.GamitSession), globk_callback, modules=modules) for date in tqdm(dates, ncols=80, disable=None): pwd = GamitConfig.gamitopt['solutions_dir'].rstrip( '/') + '/' + date.yyyy() + '/' + date.ddd() GlobkComb = [] Fatal = False for GamitSession in sessions: if GamitSession.date == date: # add to combination GlobkComb.append(GamitSession) if os.path.isfile( os.path.join(GamitSession.solution_pwd, 'monitor.log')): cmd = 'grep -q \'FATAL\' ' + os.path.join( GamitSession.solution_pwd, 'monitor.log') fatal = os.system(cmd) else: fatal = 0 if fatal == 0: Fatal = True tqdm.write( ' >> GAMIT FATAL found in monitor of session %s %s (or no monitor.log file). ' 'This combined solution will not be added to the database.' % (GamitSession.date.yyyyddd(), GamitSession.DirName)) if not Fatal: # folder where the combination (or final solution if single network) should be written to pwd_comb = os.path.join(pwd, project + '/glbf') # globk combination object globk = pyGlobkTask.Globk(pwd_comb, date, GlobkComb) JobServer.submit(globk, project, date) JobServer.wait() JobServer.close_cluster() tqdm.write(' >> %s Done combining subnetworks' % print_datetime()) return
def ExecuteGlobk(cnn, JobServer, GamitConfig, sessions, dates): project = GamitConfig.NetworkConfig.network_id.lower() tqdm.write( ' >> %s Combining with GLOBK sessions with more than one subnetwork...' % print_datetime()) modules = ('os', 'shutil', 'snxParse', 'subprocess', 'platform', 'traceback', 'glob', 'dbConnection', 'math', 'datetime', 'pyDate') pbar = tqdm(total=len(dates), disable=None, desc=' >> GLOBK combinations completion', ncols=100) JobServer.create_cluster(run_globk, (pyGlobkTask.Globk, pyGamitSession.GamitSession), job_callback, progress_bar=pbar, modules=modules) net_type = GamitConfig.NetworkConfig.type for date in dates: pwd = GamitConfig.gamitopt['solutions_dir'].rstrip( '/') + '/' + date.yyyy() + '/' + date.ddd() GlobkComb = [] Fatal = False for GamitSession in sessions: if GamitSession.date == date: # add to combination GlobkComb.append(GamitSession) #if os.path.isfile(os.path.join(GamitSession.solution_pwd, 'monitor.log')): # cmd = 'grep -q \'FATAL\' ' + os.path.join(GamitSession.solution_pwd, 'monitor.log') # fatal = os.system(cmd) #else: # fatal = 0 # check the database to see that the solution was successful rn = cnn.query_float( 'SELECT * from gamit_stats WHERE "Project" = \'%s\' AND "Year" = %i AND ' '"DOY" = %i AND "subnet" = %i' % (GamitSession.NetName, GamitSession.date.year, GamitSession.date.doy, GamitSession.subnet if GamitSession.subnet is not None else 0)) # if fatal == 0: if not len(rn): Fatal = True tqdm.write( ' >> GAMIT FATAL found in monitor of session %s %s (or no monitor.log file). ' 'This combined solution will not be added to the database.' % (GamitSession.date.yyyyddd(), GamitSession.DirName)) break if not Fatal: # folder where the combination (or final solution if single network) should be written to pwd_comb = os.path.join(pwd, project + '/glbf') # globk combination object globk = pyGlobkTask.Globk(pwd_comb, date, GlobkComb, net_type) JobServer.submit(globk, project, date) JobServer.wait() pbar.close() JobServer.close_cluster() tqdm.write(' >> %s Done combining subnetworks' % print_datetime())
def ExecuteGlobk(GamitConfig, sessions, dates): global cnn project = GamitConfig.NetworkConfig.network_id.lower() tqdm.write(' >> Combining with GLOBK sessions with more than one subnetwork...') for date in tqdm(dates, ncols=80): pwd = GamitConfig.gamitopt['solutions_dir'].rstrip('/') + '/' + date.yyyy() + '/' + date.ddd() GlobkComb = [] Fatal = False for GamitSession in sessions: if GamitSession.date == date: # add to combination GlobkComb.append(GamitSession) cmd = 'grep -q \'FATAL\' ' + os.path.join(GamitSession.solution_pwd, 'monitor.log') fatal = os.system(cmd) if fatal == 0: Fatal = True tqdm.write(' >> GAMIT FATAL found in monitor of session %s %s. This combined solution will not be ' 'added to the database.' % (GamitSession.NetName, GamitSession.date.yyyyddd())) if not Fatal: if len(GlobkComb) > 1: # create the combination folder pwd_comb = os.path.join(pwd, project + '/glbf') if not os.path.exists(pwd_comb): os.makedirs(pwd_comb) else: # delete and recreate shutil.rmtree(pwd_comb) os.makedirs(pwd_comb) Globk = pyGlobkTask.Globk(pwd_comb, date, GlobkComb) Globk.execute() # after combining the subnetworks, parse the resulting SINEX polyhedron, variance = Globk.parse_sinex() else: # parse the sinex for the only session for this doy polyhedron, variance = GlobkComb[0].parse_sinex() # insert polyherdon in gamit_soln table for key, value in polyhedron.iteritems(): if '.' in key: try: cnn.insert('gamit_soln', NetworkCode=key.split('.')[0], StationCode=key.split('.')[1], Project=project, Year=date.year, DOY=date.doy, FYear=date.fyear, X=value.X, Y=value.Y, Z=value.Z, sigmax=value.sigX * sqrt(variance), sigmay=value.sigY * sqrt(variance), sigmaz=value.sigZ * sqrt(variance), sigmaxy=value.sigXY * sqrt(variance), sigmaxz=value.sigXZ * sqrt(variance), sigmayz=value.sigYZ * sqrt(variance), VarianceFactor=variance) except dbConnection.dbErrInsert as e: # tqdm.write(' --> Error inserting ' + key + ' -> ' + str(e)) pass else: tqdm.write(' >> Invalid key found in session %s -> %s' % (date.yyyyddd(), key)) return