casa
$Rev:20696$
|
00001 from casac import * 00002 from tw_utils import * 00003 import os 00004 from time import * 00005 import numpy as numarray 00006 # very simple for now, class to do MS testing in regression framework 00007 00008 import pylab 00009 import string 00010 import tw_func 00011 from plotms import plotms 00012 00013 class VisTest: 00014 def __init__(self, msName, write=True, 00015 resultDir='WEBPAGES/visTest/', 00016 imDir='IMAGES/'): 00017 00018 import shutil 00019 self.msTool=casac.ms() 00020 self.msTool.open(msName) 00021 self.write=write 00022 self.msName=msName 00023 00024 if self.write: 00025 self.resultDir=resultDir+strftime('/%Y_%m_%d/') 00026 if os.access(self.resultDir,os.F_OK) is False: 00027 print self.resultDir+' directory DNE, so am making one!' 00028 os.mkdir(self.resultDir) 00029 else: 00030 print self.resultDir+' directory exists; will add to it!' 00031 self.imDir=imDir 00032 if os.access(imDir,os.F_OK) is False: 00033 print imDir+' directory DNE, so am making one!' 00034 os.mkdir(imDir) 00035 else: 00036 print imDir+' directory exists; will add to it!' 00037 00038 t=localtime( time() ) 00039 self.fname='Regression-%s-%s-%s-%s-%s-%s.html'%(t[0],t[1],t[2],t[3],t[4],t[5]) 00040 self.html=self.resultDir+self.fname 00041 self.body1=[] 00042 self.body2=[] 00043 self.htmlPub=htmlPub(self.html,'Measurement Set tests') 00044 else: 00045 print 'stats-only mode; will not write to html file!' 00046 00047 00048 def simple_stats(self,sigma=10): 00049 # likely improvements later: iterate through spws, 00050 00051 # add a conformity test, for nrows etc 00052 00053 ampstats=self.msTool.statistics("DATA","amp") 00054 phastats=self.msTool.statistics("DATA","phase") 00055 00056 if self.write: 00057 listnam=string.split(self.msTool.name(), '/') 00058 imnam=listnam[len(listnam)-2]+'_'+listnam[len(listnam)-1] 00059 saveDir=self.imDir+imnam+'-ampuv.png' 00060 self.ampuv(saveDir) 00061 header='amp vs. uvdist of %s' % self.msName 00062 body1=['The figure generated with msplot:'] 00063 body2=['maximum: %f'%(ampstats['DATA']['rms']),'minimum: %f'%(ampstats['DATA']['min']),'rms: %f'%(ampstats['DATA']['rms'])] 00064 self.htmlPub.doBlk(body1, body2, saveDir,header) 00065 returnFlag= 1 00066 if(ampstats['DATA']['rms'] > 2*sigma): returnFlag=-1 00067 return ampstats['DATA']['rms'], ampstats['DATA']['max'], ampstats['DATA']['min'], phastats['DATA']['rms'], phastats['DATA']['max'], phastats['DATA']['min'], returnFlag 00068 # return rms1, max1, min1, returnFlag 00069 00070 def done(self) : 00071 if self.write: 00072 self.htmlPub.doFooter() 00073 print 'webpage construction successful!' 00074 print 'images in '+os.path.abspath(self.imDir) 00075 print 'webpage at '+os.path.abspath(self.html) 00076 return '%s'%(os.path.abspath(self.html)) 00077 else: #return 0 if no writing of file is done 00078 return 'none' 00079 00080 def ampuv(self,saveDir): 00081 plotms(self.msName,xaxis="uvdist",avgchannel="all",coloraxis="baseline",plotfile=saveDir) 00082 00083