Exemplo n.º 1
0
    def initialize_scan(self):
        if self.splitant:
            if not is_ms(self.infile):
                msg = 'input data must be in MS format'
                raise Exception, msg
            
            import datetime
            dt = datetime.datetime.now()
            self.temp_prefix = "temp-sdsave" + dt.strftime("%Y%m%d%H%M%S")
            self.split_infiles = sd.splitant(filename=self.infile,
                                             outprefix=self.temp_prefix,
                                             overwrite=self.overwrite,
                                             getpt=self.getpt)
            self.scans = []
            self.antenna_names = []
            for split_infile in self.split_infiles:
                work_scan = sd.scantable(split_infile, average=False)
                # scantable selection
                #work_scan.set_selection(self.get_selector_by_list())
                work_scan.set_selection(self.get_selector(work_scan))
                self.scans.append(work_scan)

                # retrieve antenna names
                self.antenna_names.append(split_infile.split('.')[1])
            
        else:
            scan = sd.scantable(self.infile,
                                average=False,
                                antenna=self.antenna,
                                getpt=self.getpt)

            # scantable selection
            scan.set_selection(self.get_selector(scan))
            #self.scan.set_selection(self.get_selector_by_list())
            self.scan = scan
Exemplo n.º 2
0
    def initialize_scan(self):
        if self.splitant:
            if not is_ms(self.infile):
                msg = 'input data must be in MS format'
                raise Exception, msg

            import datetime
            dt = datetime.datetime.now()
            self.temp_prefix = "temp-sdsave" + dt.strftime("%Y%m%d%H%M%S")
            self.split_infiles = sd.splitant(filename=self.infile,
                                             outprefix=self.temp_prefix,
                                             overwrite=self.overwrite,
                                             getpt=self.getpt)
            self.scans = []
            self.antenna_names = []
            for split_infile in self.split_infiles:
                work_scan = sd.scantable(split_infile, average=False)
                # scantable selection
                #work_scan.set_selection(self.get_selector_by_list())
                work_scan.set_selection(self.get_selector(work_scan))
                self.scans.append(work_scan)

                # retrieve antenna names
                self.antenna_names.append(split_infile.split('.')[1])

        else:
            scan = sd.scantable(self.infile,
                                average=False,
                                antenna=self.antenna,
                                getpt=self.getpt)

            # scantable selection
            scan.set_selection(self.get_selector(scan))
            #self.scan.set_selection(self.get_selector_by_list())
            self.scan = scan
Exemplo n.º 3
0
def splitant(filename, outprefix='',overwrite=False, getpt=True):
    """
    Split Measurement set by antenna name, save data as a scantables,
    and return a list of filename. Note that frequency reference frame
    is imported as it is in Measurement set.
    Notice this method can only be available from CASA.
    Prameter
       filename:    the name of Measurement set to be read.
       outprefix:   the prefix of output scantable name.
                    the names of output scantable will be
                    outprefix.antenna1, outprefix.antenna2, ....
                    If not specified, outprefix = filename is assumed.
       overwrite    If the file should be overwritten if it exists.
                    The default False is to return with warning
                    without writing the output. USE WITH CARE.
       getpt        Whether to import direction from MS/POINTING
                    table or not. Default is True (import direction).
    """
    # Import the table toolkit from CASA
    from taskinit import gentools
    from asap.scantable import is_ms
    tb = gentools(['tb'])[0]
    # Check the input filename
    if isinstance(filename, str):
        import os.path
        filename = os.path.expandvars(filename)
        filename = os.path.expanduser(filename)
        if not os.path.exists(filename):
            s = "File '%s' not found." % (filename)
            raise IOError(s)
        # check if input file is MS
        if not is_ms(filename):
            s = "File '%s' is not a Measurement set." % (filename)
            raise IOError(s)
    else:
        s = "The filename should be string. "
        raise TypeError(s)
    # Check out put file name
    outname=''
    if len(outprefix) > 0: prefix=outprefix+'.'
    else:
        prefix=filename.rstrip('/')
    # Now do the actual splitting.
    outfiles=[]
    tb.open(tablename=filename,nomodify=True)
    ant1=tb.getcol('ANTENNA1',0,-1,1)
    anttab=tb.getkeyword('ANTENNA').lstrip('Table: ')
    tb.close()
    tb.open(tablename=anttab,nomodify=True)
    nant=tb.nrows()
    antnames=tb.getcol('NAME',0,nant,1)
    tb.close()
    for antid in set(ant1):
        scan=scantable(filename,average=False,antenna=int(antid),getpt=getpt)
        outname=prefix+antnames[antid]+'.asap'
        scan.save(outname,format='ASAP',overwrite=overwrite)
        del scan
        outfiles.append(outname)
    return outfiles
Exemplo n.º 4
0
 def __get_outform(self):
     if is_scantable(self.infile):
         outform = 'ASAP'
     elif is_ms(infile):
         outform = 'MS2'
     else:
         outform = 'SDFITS'
     return outform
Exemplo n.º 5
0
 def __get_outform(self):
     if is_scantable(self.infile):
         outform = 'ASAP'
     elif is_ms(infile):
         outform = 'MS2'
     else:
         outform = 'SDFITS'
     return outform
Exemplo n.º 6
0
    def parameter_check(self):
        # by default, the task overwrite infile
        if len(self.outfile) == 0:
            self.project = self.infile
        else:
            self.project = self.outfile

        sdutil.assert_outfile_canoverwrite_or_nonexistent(
            self.project, self.outform, self.overwrite)

        #check the format of the infile
        filename = sdutil.get_abspath(self.infile)
        if isinstance(self.infile, str):
            if is_scantable(filename):
                informat = 'ASAP'
            elif is_ms(filename):
                informat = 'MS2'
            else:
                informat = 'SDFITS'
        else:
            informat = 'UNDEFINED'

        # Check the formats of infile and outfile are identical when overwrite=True.
        # (CAS-3096). If not, print warning message and exit.
        outformat = self.outform.upper()
        if (outformat == 'MS'): outformat = 'MS2'
        if self.overwrite and os.path.exists(self.project) \
           and (sdutil.get_abspath(self.project) == sdutil.get_abspath(self.infile)) \
           and (outformat != informat):
            msg = "The input and output data format must be identical when "
            msg += "their names are identical and overwrite=True. "
            msg += "%s and %s given for input and output, respectively." % (
                informat, outformat)
            raise Exception, msg

        # check restfreq
        self.rfset = (self.restfreq != '') and (self.restfreq != [])
        self.restore = self.rfset

        if self.mode.lower()[0] not in self.valid_modes:
            raise Exception, "Invalide mode, '%s'" % self.mode

        # check whether any flag operation is done or not
        self.anyflag = False
Exemplo n.º 7
0
    def parameter_check(self):
        # by default, the task overwrite infile
        if len(self.outfile)==0: 
            self.project = self.infile
        else:
            self.project = self.outfile

        sdutil.assert_outfile_canoverwrite_or_nonexistent(self.project,
                                                          self.outform,
                                                          self.overwrite)
        
        #check the format of the infile
        filename = sdutil.get_abspath(self.infile)
        if isinstance(self.infile, str):
            if is_scantable(filename):
                informat = 'ASAP'
            elif is_ms(filename):
                informat = 'MS2'
            else:
                informat = 'SDFITS'
        else:
            informat = 'UNDEFINED'
                
        # Check the formats of infile and outfile are identical when overwrite=True.
        # (CAS-3096). If not, print warning message and exit.
        outformat = self.outform.upper()
        if (outformat == 'MS'): outformat = 'MS2'
        if self.overwrite and os.path.exists(self.project) \
           and (sdutil.get_abspath(self.project) == sdutil.get_abspath(self.infile)) \
           and (outformat != informat):
            msg = "The input and output data format must be identical when "
            msg += "their names are identical and overwrite=True. "
            msg += "%s and %s given for input and output, respectively." % (informat, outformat)
            raise Exception, msg

        # check restfreq
        self.rfset = (self.restfreq != '') and (self.restfreq != [])
        self.restore = self.rfset

        if self.mode.lower()[0] not in self.valid_modes:
            raise Exception, "Invalide mode, '%s'" % self.mode

        # check whether any flag operation is done or not
        self.anyflag = False
Exemplo n.º 8
0
def splitant(filename, outprefix='', overwrite=False, getpt=True):
    """
    Split Measurement set by antenna name, save data as a scantables,
    and return a list of filename. Note that frequency reference frame
    is imported as it is in Measurement set.
    Notice this method can only be available from CASA.
    Prameter
       filename:    the name of Measurement set to be read.
       outprefix:   the prefix of output scantable name.
                    the names of output scantable will be
                    outprefix.antenna1, outprefix.antenna2, ....
                    If not specified, outprefix = filename is assumed.
       overwrite    If the file should be overwritten if it exists.
                    The default False is to return with warning
                    without writing the output. USE WITH CARE.
       getpt        Whether to import direction from MS/POINTING
                    table or not. Default is True (import direction).
    """
    # Import the table toolkit from CASA
    from taskinit import gentools
    from asap.scantable import is_ms
    tb = gentools(['tb'])[0]
    # Check the input filename
    if isinstance(filename, str):
        import os.path
        filename = os.path.expandvars(filename)
        filename = os.path.expanduser(filename)
        if not os.path.exists(filename):
            s = "File '%s' not found." % (filename)
            raise IOError(s)
        # check if input file is MS
        if not is_ms(filename):
            s = "File '%s' is not a Measurement set." % (filename)
            raise IOError(s)
    else:
        s = "The filename should be string. "
        raise TypeError(s)
    # Check out put file name
    outname = ''
    if len(outprefix) > 0: prefix = outprefix + '.'
    else:
        prefix = filename.rstrip('/')
    # Now do the actual splitting.
    outfiles = []
    tb.open(tablename=filename, nomodify=True)
    ant1 = tb.getcol('ANTENNA1', 0, -1, 1)
    anttab = tb.getkeyword('ANTENNA').lstrip('Table: ')
    tb.close()
    tb.open(tablename=anttab, nomodify=True)
    nant = tb.nrows()
    antnames = tb.getcol('NAME', 0, nant, 1)
    tb.close()
    for antid in set(ant1):
        scan = scantable(filename,
                         average=False,
                         antenna=int(antid),
                         getpt=getpt)
        outname = prefix + antnames[antid] + '.asap'
        scan.save(outname, format='ASAP', overwrite=overwrite)
        del scan
        outfiles.append(outname)
    return outfiles