NRAO Home > CASA > CASA Cookbook and User Reference Manual

6.4.1 Examples for imfit

The following are some examples using the B1608+656 Tutorial

http://casa.nrao.edu/Doc/Scripts/b1608_demo.py

as an example.

# First fit only a single component at a time  
# This is OK since the components are well-separated and not blended  
# Box around component A  
xfit_A_res = imfit(’b1608.demo.clean2.image’,box=’121,121,136,136’,  
                   newestimates=’b1608.demo.clean2.newestimate’)  
 
# Now extract the fit part of the return value  
xfit_A = xfit_A_res[’results’][’component0’]  
#xfit_A  
#  Out[7]:  
#{’flux’: {’error’: array([  6.73398035e-05,   0.00000000e+00,   0.00000000e+00,  
#         0.00000000e+00]),  
#          ’polarisation’: ’Stokes’,  
#          ’unit’: ’Jy’,  
#          ’value’: array([ 0.01753742,  0.        ,  0.        ,  0.        ])},  
# ’label’: ’’,  
# ’shape’: {’direction’: {’error’: {’latitude’: {’unit’: ’arcsec’,  
#                                                ’value’: 0.00041154866279462775},  
#                                   ’longitude’: {’unit’: ’arcsec’,  
#                                                 ’value’: 0.00046695916589535109}},  
#                         ’m0’: {’unit’: ’rad’, ’value’: -2.0541102061078207},  
#                         ’m1’: {’unit’: ’rad’, ’value’: 1.1439131060384089},  
#                         ’refer’: ’J2000’,  
#                         ’type’: ’direction’},  
#           ’majoraxis’: {’unit’: ’arcsec’, ’value’: 0.29100166137741568},  
#           ’majoraxiserror’: {’unit’: ’arcsec’,  
#                              ’value’: 0.0011186420613222663},  
#           ’minoraxis’: {’unit’: ’arcsec’, ’value’: 0.24738110059830495},  
#           ’minoraxiserror’: {’unit’: ’arcsec’,  
#                              ’value’: 0.0013431999725066338},  
#           ’positionangle’: {’unit’: ’deg’, ’value’: 19.369249322401796},  
#           ’positionangleerror’: {’unit’: ’rad’,  
#                                  ’value’: 0.016663189295782171},  
#           ’type’: ’Gaussian’},  
# ’spectrum’: {’frequency’: {’m0’: {’unit’: ’GHz’, ’value’: 1.0},  
#                            ’refer’: ’LSRK’,  
#                            ’type’: ’frequency’},  
#              ’type’: ’Constant’}}  
 
# Now the other components  
xfit_B_res = imfit(’b1608.demo.clean2.image’,box=’108,114,120,126’,  
                   newestimates=’b1608.demo.clean2.newestimate’,append=True)  
xfit_B = xfit_B_res[’results’][’component0’]  
 
xfit_C_res= imfit(’b1608.demo.clean2.image’,box=’108,84,120,96’)  
xfit_C = xfit_C_res[’results’][’component0’]  
 
xfit_D_res = imfit(’b1608.demo.clean2.image’,box=’144,98,157,110’)  
xfit_D = xfit_D_res[’results’][’component0’]  
 
print ""  
print "Imfit Results:"  
print "--------------"  
print "A  Flux = %6.4f Bmaj = %6.4f" % (xfit_A[’flux’][’value’][0],xfit_A[’shape’][’majoraxis’][’value’])  
print "B  Flux = %6.4f Bmaj = %6.4f" % (xfit_B[’flux’][’value’][0],xfit_B[’shape’][’majoraxis’][’value’])  
print "C  Flux = %6.4f Bmaj = %6.4f" % (xfit_C[’flux’][’value’][0],xfit_C[’shape’][’majoraxis’][’value’])  
print "D  Flux = %6.4f Bmaj = %6.4f" % (xfit_D[’flux’][’value’][0],xfit_D[’shape’][’majoraxis’][’value’])  
print ""

Now try fitting four components together. For this we will have to provide an estimate file. We will use the clean beam for the estimate of the component sizes:

estfile=open(’b1608.demo.clean2.estimate’,’w’)  
print >>estfile,’# peak, x, y, bmaj, bmin, bpa’  
print >>estfile,’0.017, 128, 129, 0.293arcsec, 0.238arcsec, 21.7deg’  
print >>estfile,’0.008, 113, 120, 0.293arcsec, 0.238arcsec, 21.7deg’  
print >>estfile,’0.008, 113,  90, 0.293arcsec, 0.238arcsec, 21.7deg’  
print >>estfile,’0.002, 151, 104, 0.293arcsec, 0.238arcsec, 21.7deg’  
estfile.close()

Then, this can be used in imfit:

xfit_all_res = imfit(’b1608.demo.clean2.image’,  
                     estimates=’b1608.demo.clean2.estimate’,  
                     logfile=’b1608.demo.clean2.imfitall.log’,  
                     newestimates=’b1608.demo.clean2.newestimate’,  
                     box=’121,121,136,136,108,114,120,126,108,84,120,96,144,98,157,110’)  
# Now extract the fit part of the return values  
xfit_allA = xfit_all_res[’results’][’component0’]  
xfit_allB = xfit_all_res[’results’][’component1’]  
xfit_allC = xfit_all_res[’results’][’component2’]  
xfit_allD = xfit_all_res[’results’][’component3’]

These results are almost identical to those from the individual fits. You can see a nicer printout of the fit results in the logfile.


More information about CASA may be found at the CASA web page

Copyright © 2010 Associated Universities Inc., Washington, D.C.

This code is available under the terms of the GNU General Public Lincense


Home | Contact Us | Directories | Site Map | Help | Privacy Policy | Search