from casac import casac import os import numpy as np import pdb iaim = casac.image() iamask = casac.image() qa = casac.quanta() rg = casac.regionmanager() def automask(image='', maskimage='', fracofpeak=0, rmsthresh=3.0, resolution=None, twopass=False): """ image : dirty image or residual to mask maskimage: name of mask to create. If already existant has to be same shape and coordsys as image fracofpeak : Fraction of peak to use as masking threshold (a number between 0 and 1) if 0 then rmsthresh or a value based on the rms of the image is used rmsthresh : Threshold in sigma to use; default is 3 sigma resolution: if image has no restoring beam ..this value is used for resolution of image (e.g '4arcsec') twopass: set to True if faint fluffy stuff is wanted else false if a less agressive masking is needed especially a multi pass masking after some cleaning """ # print '2pass ', twopass iaim.open(image)
def __init__(self, imageName, write=True, resultDir='WEBPAGES/imageTest/', imDir='IMAGES/'): import shutil self.imTool = casac.image() self.imTool.open(imageName) #open('tables/squint_corr.restored') # fix up images that don't have CASA-canonical stokes and spec: # assume for now that direction is in 01 at least, mycs = self.imTool.coordsys() findstok = mycs.findcoordinate("stokes") if not findstok['return']: myImagename = imageName + ".k" self.imTool.adddegaxes(stokes=True, outfile=myImagename, overwrite=True) mystokpix = self.imTool.summary()['ndim'] # ct from 0 self.imTool.close() shutil.rmtree(imageName) shutil.move(myImagename, imageName) self.imTool.open(imageName) mycs.done() mycs = self.imTool.coordsys() else: mystokpix = findstok['pixel'] findspec = mycs.findcoordinate("spectral") if not findspec['return']: myImagename = imageName + ".s" self.imTool.adddegaxes(spectral=True, outfile=myImagename, overwrite=True) myspecpix = self.imTool.summary()['ndim'] # ct from 0 self.imTool.close() shutil.rmtree(imageName) shutil.move(myImagename, imageName) self.imTool.open(imageName) mycs.done() mycs = self.imTool.coordsys() else: myspecpix = findspec['pixel'] curr_order = [mystokpix, myspecpix] if curr_order != [2, 3]: myImagename = imageName + ".t" self.imTool.transpose(order="01%1i%1i" % (mystokpix, myspecpix), outfile=myImagename, overwrite=True) shutil.rmtree(imageName) shutil.move(myImagename, imageName) self.imTool.open(imageName) self.rgTool = casac.regionmanager() self.qaTool = casac.quanta() self.getArr() #instead make explicit call to getArr() self.write = write self.imageName = imageName self.iterate = 0 #for multiple cubeFit() tests if self.write: self.resultDir = resultDir + strftime('/%Y_%m_%d/') if os.access(self.resultDir, os.F_OK) is False: print self.resultDir + ' directory DNE, so am making one!' os.mkdir(self.resultDir) else: print self.resultDir + ' directory exists; will add to it!' self.imDir = imDir if os.access(imDir, os.F_OK) is False: print imDir + ' directory DNE, so am making one!' os.mkdir(imDir) else: print imDir + ' directory exists; will add to it!' t = localtime(time()) self.fname = 'Regression-%s-%s-%s-%s-%s-%s.html' % ( t[0], t[1], t[2], t[3], t[4], t[5]) self.html = self.resultDir + self.fname self.body1 = [] self.body2 = [] self.htmlPub = htmlPub(self.html, 'Image tests') else: print 'stats-only mode; will not write to html file!'
from casac import casac import os import numpy as np import pdb iaim=casac.image() iamask=casac.image() qa=casac.quanta() rg=casac.regionmanager() def automask(image='', maskimage='', fracofpeak=0, rmsthresh=3.0, resolution=None, twopass=False): """ image : dirty image or residual to mask maskimage: name of mask to create. If already existant has to be same shape and coordsys as image fracofpeak : Fraction of peak to use as masking threshold (a number between 0 and 1) if 0 then rmsthresh or a value based on the rms of the image is used rmsthresh : Threshold in sigma to use; default is 3 sigma resolution: if image has no restoring beam ..this value is used for resolution of image (e.g '4arcsec') twopass: set to True if faint fluffy stuff is wanted else false if a less agressive masking is needed especially a multi pass masking after some cleaning """ # print '2pass ', twopass iaim.open(image) stat=iaim.statistics(mask='abs("'+image+'") > 0.0') csys=iaim.coordsys() rb=iaim.restoringbeam() numpix=10 shp=iaim.shape() resol=qa.quantity(resolution, 'arcsec')
def __init__(self, imageName, write=True, resultDir='WEBPAGES/imageTest/', imDir='IMAGES/'): import shutil self.imTool=casac.image() self.imTool.open(imageName) #open('tables/squint_corr.restored') # fix up images that don't have CASA-canonical stokes and spec: # assume for now that direction is in 01 at least, mycs=self.imTool.coordsys() findstok=mycs.findcoordinate("stokes") if not findstok['return']: myImagename=imageName+".k" self.imTool.adddegaxes(stokes=True,outfile=myImagename,overwrite=True) mystokpix=self.imTool.summary()['ndim'] # ct from 0 self.imTool.close() shutil.rmtree(imageName) shutil.move(myImagename,imageName) self.imTool.open(imageName) mycs.done() mycs=self.imTool.coordsys() else: mystokpix=findstok['pixel'] findspec=mycs.findcoordinate("spectral") if not findspec['return']: myImagename=imageName+".s" self.imTool.adddegaxes(spectral=True,outfile=myImagename,overwrite=True) myspecpix=self.imTool.summary()['ndim'] # ct from 0 self.imTool.close() shutil.rmtree(imageName) shutil.move(myImagename,imageName) self.imTool.open(imageName) mycs.done() mycs=self.imTool.coordsys() else: myspecpix=findspec['pixel'] curr_order=[mystokpix,myspecpix] if curr_order != [2,3]: myImagename=imageName+".t" self.imTool.transpose(order="01%1i%1i" % (mystokpix,myspecpix),outfile=myImagename,overwrite=True) shutil.rmtree(imageName) shutil.move(myImagename,imageName) self.imTool.open(imageName) self.rgTool=casac.regionmanager() self.qaTool=casac.quanta() self.getArr() #instead make explicit call to getArr() self.write=write self.imageName=imageName self.iterate=0 #for multiple cubeFit() tests if self.write: self.resultDir=resultDir+strftime('/%Y_%m_%d/') if os.access(self.resultDir,os.F_OK) is False: print self.resultDir+' directory DNE, so am making one!' os.mkdir(self.resultDir) else: print self.resultDir+' directory exists; will add to it!' self.imDir=imDir if os.access(imDir,os.F_OK) is False: print imDir+' directory DNE, so am making one!' os.mkdir(imDir) else: print imDir+' directory exists; will add to it!' t=localtime( time() ) self.fname='Regression-%s-%s-%s-%s-%s-%s.html'%(t[0],t[1],t[2],t[3],t[4],t[5]) self.html=self.resultDir+self.fname self.body1=[] self.body2=[] self.htmlPub=htmlPub(self.html,'Image tests') else: print 'stats-only mode; will not write to html file!'