def __init__(self, filename): self.filename = filename self.reg_list = pyregion.open(filename) min_ra, max_ra, min_dec, max_dec = [], [], [], [] for r in self.reg_list: # TODO: if necessary, box, ellipse and polygon can be added. if r.name == 'circle': c = r.coord_list # c_ra, c_dec, radius # how much RA does the radius correspond to radius_ra = np.rad2deg(2*np.arcsin(np.sin(np.deg2rad(c[2])/2)/np.cos(np.deg2rad(c[1])))) min_ra.append(c[0] - radius_ra) max_ra.append(c[0] + radius_ra) min_dec.append(c[1] - c[2]) max_dec.append(c[1] + c[2]) elif r.name == 'polygon': c = np.array(r.coord_list) # ra_i, dec_i, ra_i+1, dec_i+1 ra_mask = np.zeros(len(c), dtype=bool) ra_mask[::2] = True p_ra = c[ra_mask] p_dec = c[~ra_mask] min_ra.append(np.min(p_ra)) max_ra.append(np.max(p_ra)) min_dec.append(np.min(p_dec)) max_dec.append(np.max(p_dec)) else: logger.error('Region type {} not supported.'.format(r.name)) sys.exit(1) self.min_ra = np.min(min_ra) self.max_ra = np.max(max_ra) self.min_dec = np.min(min_dec) self.max_dec = np.max(max_dec)
def __init__(self, pathsMS, scheduler, check_flags=True, check_sun=False, min_sun_dist=10): """ pathsMS: list of MS paths scheduler: scheduler object check_flag: if true ignore fully flagged ms check_sun: if true check sun distance min_sun_dist: if check_sun and distance from the sun < than this deg, skip """ self.scheduler = scheduler # sort them, useful for some concatenating steps if len(pathsMS) == 0: logger.error('Cannot find MS files.') raise('Cannot find MS files.') self.mssListObj = [] for pathMS in sorted(pathsMS): ms = MS(pathMS) if check_flags and ms.isAllFlagged(): logger.warning('Skip fully flagged ms: %s' % pathMS) elif check_sun and ms.sun_dist.deg < min_sun_dist: logger.warning('Skip too close to sun (%.0f deg) ms: %s' % (ms.sun_dist.deg, pathMS)) else: self.mssListObj.append(MS(pathMS)) if len(self.mssListObj) == 0: raise('ALL MS files flagged.') self.mssListStr = [ms.pathMS for ms in self.mssListObj] self.resolution = self.mssListObj[0].getResolution(check_flags=False)
def check_run(self, log = "", commandType = ""): """ Produce a warning if a command didn't close the log properly i.e. it crashed NOTE: grep, -L inverse match, -l return only filename """ if (not os.path.exists(log)): logger.warning("No log file found to check results: " + log) return 1 if (commandType == "DPPP"): out = subprocess.check_output('grep -L "Finishing processing" '+log+' ; exit 0', shell = True, stderr = subprocess.STDOUT) out += subprocess.check_output('grep -l "Segmentation fault\|Killed" '+log+' ; exit 0', shell = True, stderr = subprocess.STDOUT) # # out += subprocess.check_output('grep -l "Aborted (core dumped)" '+log+' ; exit 0', shell = True, stderr = subprocess.STDOUT) out += subprocess.check_output('grep -i -l "Exception" '+log+' ; exit 0', shell = True, stderr = subprocess.STDOUT) out += subprocess.check_output('grep -l "**** uncaught exception ****" '+log+' ; exit 0', shell = True, stderr = subprocess.STDOUT) out += subprocess.check_output('grep -l "error" '+log+' ; exit 0', shell = True, stderr = subprocess.STDOUT) out += subprocess.check_output('grep -l "misspelled" '+log+' ; exit 0', shell = True, stderr = subprocess.STDOUT) elif (commandType == "CASA"): out = subprocess.check_output('grep -l "[a-z]Error" '+log+' ; exit 0', shell = True, stderr = subprocess.STDOUT) out += subprocess.check_output('grep -l "An error occurred running" '+log+' ; exit 0', shell = True, stderr = subprocess.STDOUT) out += subprocess.check_output('grep -l "\*\*\* Error \*\*\*" '+log+' ; exit 0', shell = True, stderr = subprocess.STDOUT) elif (commandType == "wsclean"): out = subprocess.check_output('grep -l "exception occur" '+log+' ; exit 0', shell = True, stderr = subprocess.STDOUT) out += subprocess.check_output('grep -l "Segmentation fault\|Killed" '+log+' ; exit 0', shell = True, stderr = subprocess.STDOUT) out += subprocess.check_output('grep -l "Aborted" '+log+' ; exit 0', shell = True, stderr = subprocess.STDOUT) out += subprocess.check_output('grep -L "Cleaning up temporary files..." '+log+' ; exit 0', shell = True, stderr = subprocess.STDOUT) elif (commandType == "python"): out = subprocess.check_output('grep -l "Traceback (most recent call last):" '+log+' ; exit 0', shell = True, stderr = subprocess.STDOUT) out += subprocess.check_output('grep -l "Segmentation fault\|Killed" '+log+' ; exit 0', shell = True, stderr = subprocess.STDOUT) out += subprocess.check_output('grep -i -l \'(?=^((?!error000).)*$).*Error.*\' '+log+' ; exit 0', shell = True, stderr = subprocess.STDOUT) out += subprocess.check_output('grep -i -l "Critical" '+log+' ; exit 0', shell = True, stderr = subprocess.STDOUT) out += subprocess.check_output('grep -l "ERROR" '+log+' ; exit 0', shell = True, stderr = subprocess.STDOUT) out += subprocess.check_output('grep -l "raise Exception" '+log+' ; exit 0', shell = True, stderr = subprocess.STDOUT) elif (commandType == "singularity"): out = subprocess.check_output('grep -l "Traceback (most recent call last):" '+log+' ; exit 0', shell = True, stderr = subprocess.STDOUT) out += subprocess.check_output('grep -i -l \'(?=^((?!error000).)*$).*Error.*\' '+log+' ; exit 0', shell = True, stderr = subprocess.STDOUT) out += subprocess.check_output('grep -i -l "Critical" '+log+' ; exit 0', shell = True, stderr = subprocess.STDOUT) elif (commandType == "general"): out = subprocess.check_output('grep -l -i "error" '+log+' ; exit 0', shell = True, stderr = subprocess.STDOUT) else: logger.warning("Unknown command type for log checking: '" + commandType + "'") return 1 if out != b'': out = out.split(b'\n')[0].decode() logger.error(commandType+' run problem on:\n'+out) raise RuntimeError(commandType+' run problem on:\n'+out) return 0
def distBrightSource(self, name): """ Get the distance in deg from some bright sources """ ateam={'CygA':{'ra':299.8679167, 'dec':40.7338889}, 'CasA':{'ra':350.8583333, 'dec':58.8000000}, 'TauA':{'ra':83.6333333, 'dec':22.0144444}, 'VirA':{'ra':187.7058333, 'dec':12.3911111}, '3C338':{'ra':247.160333, 'dec':39.551556}, '3C380':{'ra':277.382420,'dec':48.746156} } if name not in ateam.keys(): logger.error('Unknown source for distance: %s' % name) logger.error('Use: '+' '.join(ateam.keys())) raise coord_bright = SkyCoord(ra=ateam[name]['ra']*u.deg, dec=ateam[name]['dec']*u.deg) ra, dec = self.getPhaseCentre() return coord_bright.separation(SkyCoord(ra*u.deg, dec*u.deg)).deg
def check_run(self, log="", commandType=""): """ Produce a warning if a command didn't close the log properly i.e. it crashed NOTE: grep, -L inverse match, -l return only filename """ import subprocess if (not os.path.exists(log)): logger.warning("No log file found to check results: " + log) return 1 if (commandType == "BBS"): out = subprocess.check_output('grep -L success ' + log + ' ; exit 0', shell=False, stderr=subprocess.STDOUT) if out != '': logger.error('BBS run problem on:\n' + out.split("\n")[0]) return 1 elif (commandType == "DPPP"): out = subprocess.check_output('grep -L "Finishing processing" ' + log + ' ; exit 0', shell=True, stderr=subprocess.STDOUT) out += subprocess.check_output('grep -l "Exception" ' + log + ' ; exit 0', shell=True, stderr=subprocess.STDOUT) out += subprocess.check_output( 'grep -l "**** uncaught exception ****" ' + log + ' ; exit 0', shell=True, stderr=subprocess.STDOUT) out += subprocess.check_output('grep -l "error" ' + log + ' ; exit 0', shell=True, stderr=subprocess.STDOUT) #out += subprocess.check_output('grep -l "misspelled" '+log+' ; exit 0', shell = True, stderr = subprocess.STDOUT) if out != '': logger.error('DPPP run problem on:\n' + out.split("\n")[0]) return 1 elif (commandType == "CASA"): out = subprocess.check_output('grep -l "[a-z]Error" ' + log + ' ; exit 0', shell=True, stderr=subprocess.STDOUT) out += subprocess.check_output( 'grep -l "An error occurred running" ' + log + ' ; exit 0', shell=True, stderr=subprocess.STDOUT) out += subprocess.check_output('grep -l "\*\*\* Error \*\*\*" ' + log + ' ; exit 0', shell=True, stderr=subprocess.STDOUT) if out != '': logger.error('CASA run problem on:\n' + out.split("\n")[0]) return 1 elif (commandType == "wsclean"): out = subprocess.check_output('grep -l "exception occured" ' + log + ' ; exit 0', shell=True, stderr=subprocess.STDOUT) out = subprocess.check_output('grep -l "Segmentation fault" ' + log + ' ; exit 0', shell=True, stderr=subprocess.STDOUT) out += subprocess.check_output( 'grep -L "Cleaning up temporary files..." ' + log + ' ; exit 0', shell=True, stderr=subprocess.STDOUT) if out != '': logger.error('WSClean run problem on:\n' + out.split("\n")[0]) return 1 elif (commandType == "python"): out = subprocess.check_output( 'grep -l "Traceback (most recent call last):" ' + log + ' ; exit 0', shell=True, stderr=subprocess.STDOUT) out += subprocess.check_output( 'grep -i -l \'(?=^((?!error000).)*$).*Error.*\' ' + log + ' ; exit 0', shell=True, stderr=subprocess.STDOUT) out += subprocess.check_output('grep -i -l "Critical" ' + log + ' ; exit 0', shell=True, stderr=subprocess.STDOUT) if out != '': logger.error('Python run problem on:\n' + out.split("\n")[0]) return 1 elif (commandType == "general"): out = subprocess.check_output('grep -l -i "error" ' + log + ' ; exit 0', shell=True, stderr=subprocess.STDOUT) if out != '': logger.error('Run problem on:\n' + out.split("\n")[0]) return 1 else: logger.warning("Unknown command type for log checking: '" + commandType + "'") return 1 return 0