casa
$Rev:20696$
|
00001 import os 00002 import shutil 00003 from taskinit import * 00004 00005 def imreframe(imagename=None, output=None, outframe=None, epoch=None, restfreq=None): 00006 try: 00007 casalog.origin('imreframe') 00008 if(output==imagename): 00009 output='' 00010 needregrid=False 00011 if(((outframe == 'topo') or (outframe=='geo')) and (epoch != '')): 00012 needregrid=True 00013 myia,me=gentools(['ia', 'me']) 00014 myia.open(imagename) 00015 c=myia.coordsys() 00016 hasspec,pixax,worldax=c.findcoordinate('spectral') 00017 if(not hasspec): 00018 raise Exception, 'Could not find spectral axis' 00019 if(outframe != ''): 00020 c.setconversiontype(spectral=outframe) 00021 if(restfreq != ''): 00022 c.setrestfrequency(value=qa.quantity(restfreq, 'Hz')) 00023 if(epoch != ''): 00024 c.setepoch(me.epoch('utc', epoch)) 00025 if(not needregrid): 00026 if(output != ''): 00027 myia.fromimage(outfile=output, infile=imagename, overwrite=True) 00028 myia.close() 00029 myia.open(output) 00030 myia.setcoordsys(c.torecord()) 00031 myia.done() 00032 else: 00033 outname='_temp_regrid_image' if(output=='') else output 00034 shp=myia.shape() 00035 ib=myia.regrid(outfile=outname, shape=shp, csys=c.torecord(), 00036 axes=pixax, overwrite=True) 00037 if(output==''): 00038 myia.done() 00039 ib.rename(name=imagename, overwrite=True) 00040 myia.done() 00041 ib.done() 00042 return True 00043 00044 except Exception, instance: 00045 if('myia' in locals()): 00046 myia.close() 00047 if('ib' in locals()): 00048 ib.close() 00049 raise instance 00050