casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables
task_importfitsidi.py
Go to the documentation of this file.
00001 import os
00002 import shutil
00003 from taskinit import casalog, mstool, write_history
00004 
00005 def importfitsidi(fitsidifile,vis):
00006         """Convert FITS-IDI visibility file into a CASA visibility file (MS).
00007 
00008         Keyword arguments:
00009         fitsidifile -- Name(s) of input FITS IDI file(s)
00010                 default: None; example='3C273XC1.IDI' or ['3C273XC1.IDI1', '3C273XC1.IDI2']
00011         vis -- Name of output visibility file (MS)
00012                 default: None; example: vis='3C273XC1.ms'
00013                 
00014         """
00015 
00016         #Python script
00017         retval = True
00018         try:
00019                 casalog.origin('importfitsidi')
00020                 casalog.post("")
00021                 myms = mstool()
00022                 if(type(fitsidifile)==str):
00023                         casalog.post('### Reading file '+fitsidifile, 'INFO')
00024                         myms.fromfitsidi(vis,fitsidifile)
00025                         myms.close()
00026                 elif(type(fitsidifile)==list):
00027                         clist = fitsidifile
00028                         casalog.post('### Reading file '+clist[0], 'INFO')
00029                         myms.fromfitsidi(vis,clist[0])
00030                         myms.close()
00031                         clist.pop(0)
00032                         tname = '_importfitsidi_tmp_'+vis
00033                         shutil.rmtree(tname, ignore_errors=True)
00034                         for fidifile in clist:
00035                                 casalog.post('### Reading file '+fidifile, 'INFO')
00036                                 myms.fromfitsidi(tname,fidifile)
00037                                 myms.close()
00038                                 myms.open(vis, nomodify=False)
00039                                 myms.concatenate(msfile=tname, freqtol='', dirtol='')
00040                                 myms.close()
00041                                 shutil.rmtree(tname, ignore_errors=True)
00042                 else:
00043                         raise Exception, 'Parameter fitsidifile should be of type str or list'                  
00044                 # write history
00045                 try:
00046                         param_names = importfitsidi.func_code.co_varnames[:importfitsidi.func_code.co_argcount]
00047                         param_vals = [eval(p) for p in param_names]   
00048                         retval &= write_history(myms, vis, 'importfitsidi', param_names,
00049                                                 param_vals, casalog)
00050                 except Exception, instance:
00051                         casalog.post("*** Error \'%s\' updating HISTORY" % (instance),
00052                                      'WARN')
00053 
00054         except Exception, instance: 
00055                 print '*** Error ***',instance
00056                 shutil.rmtree('_importfitsidi_tmp_'+vis, ignore_errors=True)
00057                 raise Exception, instance
00058 
00059