Script example: How to remove a contaminating source from uv data Authors: Debra Shepherd & Kumar Golap Use: This would be useful if, say, you have multiple observations of a target source that you want to concatinate and image but there is a variable source in the field that must be subtracted before you can obtain a good image. Starting datasets: A.ms, B.ms & C.ms containing calibrated source data ===================================================== Steps: 1. Image the calibrated data, mask all sources 2. Isolate the model components associated with the variable source only and Fourier transform this model into the model data column of the original MS. 3. Subtract the model uv data from the observed data to retain only information about the target source. 4. Make a new image of just the target source to make sure the procedure worked. ===================================================== ################################################################## # Step 1: Image the calibrated data, mask all sources default clean clean(vis='A.ms', imagename='Afull', cleanbox='interactive', npercycle=100, imsize=[1024,1024], cell=['0.05arcsec','0.05arcsec'], field='0', mode='mfs', alg='clark', niter=500, weighting='briggs', rmode='norm', robust=0.5) # Mask all sources, make sure the residual image looks very clean Inputs above are for illustrations purposes only, choose clean deconvolution parameters that are suited to your project. ################################################################## # Step 2: Isolate the model components associated with the variable source only and # Fourier transform this model into the model data column of the original MS. # You want to remove model components associated with the source so only the variable source components are left in a model image. First create a mask that will isolate the region where the outflow source is located: # First define a region-of-interest that has only the target source model components Use the viewer to define the region (set position tracking to pixel, not world to get actual pixel values). srcregion = rg.box(blc=[x1,y1], trc=[x2,y2]) # where x1, y1 represent the pixel values of the bottom left corner of the region and x2, y2 represent the pixel values of the top right corner of the region # In an xterm or terminal window: copy the full model image into a new file that will contain only the model components of the variable source you want to get rid of: cp -r Afull.model AfullvarOnly.model # Now, back in CASA, set the pixels in the source region to be 0.0 in the model so you are only left with model components associated with the variable source: ia.open('AfullvarOnly.model') # open the new file ia.set(pixels=0.0, region=srcregion) # set all pixels in the source region to 0.0 ia.close # close the modified model viewer # Check: view resulting model # Model components associated with the target source are gone # Fourier transform the model components and fill the model data column with this new model of just the variable source ft(vis='A.ms', field='0', model='AfullvarOnly.model') # In the next steps you will modify the actual DATA column in the MS Just to make sure, copy the ms into a save file (you can delete this later if you are satisified you do not want the original data) cp -r A.ms A.ms.save ################################################################## # Step 3: Subtract the model uv data from the observed data to retain only information # about the target source. # Now subtract the MODEL column from the DATA and CORRECTED_DATA columns ...using the tb tool tb.open('A.ms', nomodify=False) # open A.ms with the table tool dat=tb.getcol('CORRECTED_DATA') # copy CORRECTED_DATA into array called dat mod=tb.getcol('MODEL_DATA') # copy MODEL_DATA into array called mod # Subtract the model from corrected data and putting it in both the DATA and CORRECTED_DATA columns (you need it in DATA too in case you want to self-cal later) dat=dat-mod # the 'dat' array now contains only uv data associated with the target source, not the variable source represented in the MODEL_DATA column. # Put the data in this array into the CORRECTED_DATA and DATA columns: tb.putcol('CORRECTED_DATA', dat) # replace CORRECTED_DATA with dat tb.putcol('DATA', dat) # replace observed DATA with dat tb.done # close the table tool and detach the MS. ################################################################## # Step 4: Make a new image of just the target source to make sure the # procedure worked. default clean clean(vis="A.ms", imagename="AfullwithoutVar", mode="mfs", alg="clark", niter=500, gain=0.1, threshold=0.0, cleanbox='interactive', npercycle=100, imsize=[1024,1024], cell=['0.05arcsec','0.05arcsec'], stokes="I",field="0",spw="0,1", weighting="briggs", rmode="norm", robust=0.5) viewer # use the viewer to ensure that the Afull.image and AfullwithoutVar.image have exactly the same target source characteristics and flux densities. They should. ################################################################ # Repeat the above procedures for datasets B.ms and C.ms ... ################################################################ # Concatinate datasets together cp -r A.ms All.ms concat(vis='All.ms', concatvis='B.ms') concat(vis='All.ms', concatvis='C.ms') ################################################################ # Now image using clean or mosaic tasks. default clean clean(vis="All.ms", imagename="AllnoVar", mode="mfs", alg="clark", niter=500, gain=0.1, threshold=0.0, cleanbox='interactive', npercycle=100, imsize=[1024,1024], cell=['0.05arcsec','0.05arcsec'], stokes="I",field="0",spw="0,1", weighting="briggs", rmode="norm", robust=0.5) ################################################################ # Export your new science results as a fits image to send to your collaborators: default exportfits exportfits(imagename='AllnoVar.image', fitsimage='AllnoVar.fits')