Ejemplo n.º 1
0
    def test1_applycal_fluxscale_gcal_bcal(self):
        """Test 1: Apply calibration using fluxscal gcal and bcal tables. Create flagbackup for an MMS"""

        # Repository caltables are pre-v4.1, and we
        # must update them _before_ applycal to avoid contention
        casalog.post("Updating pre-v4.1 caltables: %s" % str(self.aux), "WARN",
                     "test1_applycal_fluxscale_gcal_bcal")
        cblocal = cbtool()
        for oldct in self.aux:
            cblocal.updatecaltable(oldct)
        casalog.post("Pre-v4.1 caltables updated", "INFO",
                     "test1_applycal_fluxscale_gcal_bcal")

        # Run applycal in MMS mode. Verify that the flagbackup is correctly created for the top-level MMS only
        applycal(vis=self.vis,
                 field='',
                 spw='',
                 selectdata=False,
                 gaintable=self.aux,
                 gainfield=['nearest', 'nearest', '0'],
                 interp=['linear', 'linear', 'nearest'],
                 spwmap=[],
                 flagbackup=True)

        # Verify that flagbackup works
        self.assertTrue(os.path.exists(self.vis + '.flagversions'),
                        'Backup of flags was not created')
        files = os.listdir(self.vis + '/SUBMSS')
        print files
        for ff in files:
            self.assertFalse(ff.__contains__('flagversions'))
Ejemplo n.º 2
0
def clearcal(
    vis=None,
    field=None,
    spw=None,
    intent=None,
    addmodel=None,
):

    casalog.origin('clearcal')

    # Do the trivial parallelization
    if ParallelTaskHelper.isParallelMS(vis):
        helper = ParallelTaskHelper('clearcal', locals())
        helper.go()
        return

    # Local versions of the tools
    tblocal = tbtool()
    cblocal = cbtool()
    mslocal = mstool()

    try:

        # we will initialize scr cols only if we don't create them
        doinit = False

        if (type(vis) == str) & os.path.exists(vis):
            tblocal.open(vis)
            doinit = tblocal.colnames().count('CORRECTED_DATA') > 0
            tblocal.close()

            # We ignore selection if creating the scratch columns
            if not doinit:
                casalog.post(
                    'Need to create scratch columns; ignoring selection.')

            cblocal.setvi(old=True, quiet=False)
            # Old VI for now
            cblocal.open(vis, addmodel=addmodel)
        else:
            raise Exception, \
                'Visibility data set not found - please verify the name'

        # If necessary (scr col not just created), initialize scr cols
        if doinit:
            cblocal.selectvis(field=field, spw=spw, intent=intent)
            cblocal.initcalset(1)
        cblocal.close()

        # Write history to the MS
        param_names = clearcal.func_code.co_varnames[:clearcal.func_code.
                                                     co_argcount]
        param_vals = [eval(p) for p in param_names]
        casalog.post('Updating the history in the output', 'DEBUG1')
        write_history(mslocal, vis, 'clearcal', param_names, param_vals,
                      casalog)

    except Exception, instance:

        print '*** Error ***', instance
Ejemplo n.º 3
0
 def test_getdata_putdata(self): 
     """test ms.getdata, putdata"""
     self.ms.close()
     # need writable MS for putdata:
     putms = 'ngc5921_put.ms'
     shutil.copytree(self.testms, putms)
     # add corrected_data
     cb = cbtool()
     cb.open(putms)
     cb.close()
     self.ms.open(putms, False)
     # items list
     rec = self.ms.getdata(['data', 'antenna1', 'scan_number'])
     self.assertEqual(rec['antenna1'][1], 27)
     self.assertEqual(rec['scan_number'][1], 1)
     data0 = rec['data']
     # double the data and write it into the MS
     doubleData = data0 * 2
     doubleRec = {'corrected_data': doubleData}
     self.ms.putdata(doubleRec)
     # make sure it is 2x
     rec = self.ms.getdata(['corrected_data'])
     testing.assert_array_almost_equal(rec['corrected_data'],
             data0*2, 7)
     self.ms.close()
     self.removeMS(putms)
     self.ms.open(self.testms) # reopen for tearDown
     print
Ejemplo n.º 4
0
def clearcal(
    vis=None,
    field=None,
    spw=None,
    intent=None,
    addmodel=None,
    ):

    casalog.origin('clearcal')

    # Do the trivial parallelization
    if ParallelTaskHelper.isParallelMS(vis):
        helper = ParallelTaskHelper('clearcal', locals())
        helper.go()
        return

    # Local versions of the tools
    tblocal = tbtool()
    cblocal = cbtool()
    mslocal = mstool()

    try:

        # we will initialize scr cols only if we don't create them
        doinit = False

        if (type(vis) == str) & os.path.exists(vis):
            tblocal.open(vis)
            doinit = tblocal.colnames().count('CORRECTED_DATA') > 0
            tblocal.close()

            # We ignore selection if creating the scratch columns
            if not doinit:
                casalog.post('Need to create scratch columns; ignoring selection.'
                             )

            cblocal.open(vis, addmodel=addmodel)
        else:
            raise Exception, \
                'Visibility data set not found - please verify the name'

        # If necessary (scr col not just created), initialize scr cols
        if doinit:
            cblocal.selectvis(field=field, spw=spw, intent=intent)
            cblocal.initcalset(1)
        cblocal.close()

        # Write history to the MS
        param_names = clearcal.func_code.co_varnames[:clearcal.func_code.co_argcount]
        param_vals = [eval(p) for p in param_names]
        casalog.post('Updating the history in the output', 'DEBUG1')
        write_history(mslocal, vis, 'clearcal', param_names,
                      param_vals, casalog)
        
    except Exception, instance:

        print '*** Error ***', instance
Ejemplo n.º 5
0
 def setUp(self):
     
     # Set-up MMS
     self.vis = "ngc5921.applycal.mms"
     self.vis_sorted = "ngc5921.applycal.sorted.mms"
     setUpFile(self.vis,'vis')
     
     # Set-up reference MMS
     self.ref = "ngc5921.applycal.ms"
     self.ref_sorted = "ngc5921.applycal.sorted.ms"
     setUpFile(self.ref,'ref')
     
     # Set-up auxiliary files
     self.aux = ["ngc5921.fluxscale", "ngc5921.gcal", "ngc5921.bcal"]
     setUpFile(self.aux ,'aux')
     
     # Repository caltables are pre-v4.1, and we
     # must update them _before_ applycal to avoid contention
     casalog.post("Updating pre-v4.1 caltables: %s" % str(self.aux),"WARN","test1_applycal_fluxscale_gcal_bcal")
     cblocal = cbtool()
     for oldct in self.aux:
         cblocal.updatecaltable(oldct)
     casalog.post("Pre-v4.1 caltables updated","INFO","test_mpi4casa_applycal")        
     
     # Tmp files
     self.vis2 = self.vis + '.2'
     self.vis3 = self.vis + '.3'
     self.vis_sorted2 = self.vis_sorted + '.2'
     self.vis_sorted3 = self.vis_sorted + '.3'
     
     # Tmp aux files
     self.aux2 = []
     self.aux3 = []
     for file in self.aux:
         self.aux2.append(file + '.2')
         self.aux3.append(file + '.3')
     
     # Set up cluster
     self.client = MPICommandClient()
     self.client.set_log_mode('redirect')
     self.client.start_services()          
Ejemplo n.º 6
0
    def test1_applycal_fluxscale_gcal_bcal(self):
        """Test 1: Apply calibration using fluxscal gcal and bcal tables. Create flagbackup for an MMS"""

        # Repository caltables are pre-v4.1, and we
        # must update them _before_ applycal to avoid contention
        casalog.post("Updating pre-v4.1 caltables: %s" % str(self.aux),"WARN","test1_applycal_fluxscale_gcal_bcal")
        cblocal = cbtool()
        for oldct in self.aux:
            cblocal.updatecaltable(oldct)
        casalog.post("Pre-v4.1 caltables updated","INFO","test1_applycal_fluxscale_gcal_bcal")
                
        # Run applycal in MMS mode. Verify that the flagbackup is correctly created for the top-level MMS only
        applycal(vis=self.vis,field='',spw='',selectdata=False,gaintable=self.aux,
                 gainfield=['nearest','nearest','0'],
                 interp=['linear', 'linear','nearest'],spwmap=[], flagbackup=True)
                
        # Verify that flagbackup works
        self.assertTrue(os.path.exists(self.vis+'.flagversions'), 'Backup of flags was not created') 
        files = os.listdir(self.vis+'/SUBMSS')
        print files
        for ff in files:
            self.assertFalse(ff.__contains__('flagversions'))
Ejemplo n.º 7
0
 def test_getdata2_putdata2(self): 
     """test ms.getdata2, putdata2"""
     self.ms.close()
     # need writable MS for putdata:
     putms = 'ngc5921_put.ms'
     shutil.copytree(self.testms, putms)
     # add corrected_data
     cb = cbtool()
     cb.open(putms)
     cb.close()
     self.ms.open(putms, False)
     # items list
     rec = self.ms.getdata2(['data', 'antenna1', 'scan_number'])
     self.assertEqual(rec['antenna1'][1], 27)
     self.assertEqual(rec['scan_number'][1], 1)
     data0 = rec['data']
     # double the data and write it into the MS
     doubleData = data0 * 2
     doubleRec = {'corrected_data': doubleData}
     self.ms.putdata2(doubleRec)
     # make sure it is 2x
     rec = self.ms.getdata2(['corrected_data'])
     self.assertEqual(rec['corrected_data'].shape, (2,63,22653))
     testing.assert_array_almost_equal(rec['corrected_data'], data0*2)
     # divide by 2 (=data again) and put it back, use ifraxis
     rec = self.ms.getdata2(['corrected_data'], ifraxis=True)
     halfData = rec['corrected_data']*0.5
     self.assertEqual(halfData.shape, (2,63,378,60))
     halfRec = {'corrected_data': halfData}
     self.ms.putdata2(halfRec)
     rec = self.ms.getdata2(['data','corrected_data'])
     testing.assert_array_almost_equal(rec['corrected_data'],
             rec['data'])
     self.ms.close()
     self.removeMS(putms)
     self.ms.open(self.testms) # reopen for tearDown
     print
Ejemplo n.º 8
0
import os
from taskinit import casalog, cbtool, mstool
from mstools import write_history
from parallel.parallel_task_helper import ParallelTaskHelper

_ms = mstool()
_cb = cbtool()


def delmod(vis=None, otf=None, field=None, scr=None):

    casalog.origin('delmod')

    # Do the trivial parallelization
    if ParallelTaskHelper.isParallelMS(vis):
        helper = ParallelTaskHelper('delmod', locals())
        helper.go()
        return

    #Python script
    try:

        # only if vis exists...
        if ((type(vis) == str) & (os.path.exists(vis))):
            # ... and we are asked to do something...
            # open without adding anything!
            _cb.open(vis, addcorr=False, addmodel=False)
            _cb.delmod(otf=otf, field=field, scr=scr)
            _cb.close()
        else:
            raise Exception, 'Visibility data set not found - please verify the name'