Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/python/asapmath.py

    r2952 r2646  
    1 import re
    21from asap.scantable import scantable
    32from asap.parameters import rcParams
     
    9190    else:
    9291        #s = scantable(stm._average(alignedlst, mask, weight.upper(), scanav))
    93         s = scantable(stm._new_average(alignedlst, compel, mask,
    94                                        weight.upper(), scanav))
     92        s = scantable(stm._new_average(alignedlst, compel, mask, weight.upper(), scanav))
    9593    s._add_history("average_time",varlist)
    9694
     
    393391            p.quit()
    394392            del p
    395             return scantab
     393            return scabtab
    396394        p.quit()
    397395        del p
     
    613611            p.quit()
    614612            del p
    615             return scantab
     613            return scabtab
    616614        p.quit()
    617615        del p
     
    816814            p.quit()
    817815            del p
    818             return scantab
     816            return scabtab
    819817        p.quit()
    820818        del p
     
    824822
    825823@asaplog_post_dec
    826 def merge(*args, **kwargs):
     824def merge(*args):
    827825    """
    828826    Merge a list of scanatables, or comma-sperated scantables into one
     
    830828    Parameters:
    831829        A list [scan1, scan2] or scan1, scan2.
    832         freq_tol: frequency tolerance for merging IFs. numeric values
    833                   in units of Hz (1.0e6 -> 1MHz) and string ('1MHz')
    834                   is allowed.
    835830    Example:
    836831        myscans = [scan1, scan2]
     
    838833        # or equivalent
    839834        sameallscans = merge(scan1, scan2)
    840         # with freqtol
    841         allscans = merge(scan1, scan2, freq_tol=1.0e6)
    842         # or equivalently
    843         allscans = merge(scan1, scan2, freq_tol='1MHz')
    844835    """
    845836    varlist = vars()
     
    850841    else:
    851842        lst = tuple(args)
    852     if kwargs.has_key('freq_tol'):
    853         freq_tol = str(kwargs['freq_tol'])
    854         if len(freq_tol) > 0 and re.match('.+[GMk]Hz$', freq_tol) is None:
    855             freq_tol += 'Hz'
    856     else:
    857         freq_tol = ''
    858843    varlist["args"] = "%d scantables" % len(lst)
    859844    # need special formatting her for history...
     
    864849            msg = "Please give a list of scantables"
    865850            raise TypeError(msg)
    866     s = scantable(stm._merge(lst, freq_tol))
     851    s = scantable(stm._merge(lst))
    867852    s._add_history("merge", varlist)
    868853    return s
     
    964949
    965950@asaplog_post_dec
    966 def splitant(filename, outprefix='',overwrite=False, getpt=True):
     951def splitant(filename, outprefix='',overwrite=False):
    967952    """
    968953    Split Measurement set by antenna name, save data as a scantables,
    969     and return a list of filename. Note that frequency reference frame
    970     is imported as it is in Measurement set.
     954    and return a list of filename.
    971955    Notice this method can only be available from CASA.
    972956    Prameter
     
    979963                    The default False is to return with warning
    980964                    without writing the output. USE WITH CARE.
    981        getpt        Whether to import direction from MS/POINTING
    982                     table or not. Default is True (import direction).
     965
    983966    """
    984967    # Import the table toolkit from CASA
    985     from taskinit import gentools
     968    from casac import casac
    986969    from asap.scantable import is_ms
    987     tb = gentools(['tb'])[0]
     970    tb = casac.table()
    988971    # Check the input filename
    989972    if isinstance(filename, str):
     
    995978            raise IOError(s)
    996979        # check if input file is MS
     980        #if not os.path.isdir(filename) \
     981        #       or not os.path.exists(filename+'/ANTENNA') \
     982        #       or not os.path.exists(filename+'/table.f1'):
    997983        if not is_ms(filename):
    998984            s = "File '%s' is not a Measurement set." % (filename)
     
    1010996    tb.open(tablename=filename,nomodify=True)
    1011997    ant1=tb.getcol('ANTENNA1',0,-1,1)
     998    #anttab=tb.getkeyword('ANTENNA').split()[-1]
    1012999    anttab=tb.getkeyword('ANTENNA').lstrip('Table: ')
    10131000    tb.close()
     1001    #tb.open(tablename=filename+'/ANTENNA',nomodify=True)
    10141002    tb.open(tablename=anttab,nomodify=True)
    10151003    nant=tb.nrows()
    10161004    antnames=tb.getcol('NAME',0,nant,1)
    10171005    tb.close()
     1006    tmpname='asapmath.splitant.tmp'
    10181007    for antid in set(ant1):
    1019         scan=scantable(filename,average=False,antenna=int(antid),getpt=getpt)
     1008        tb.open(tablename=filename,nomodify=True)
     1009        tbsel=tb.query('ANTENNA1 == %s && ANTENNA2 == %s'%(antid,antid),tmpname)
     1010        scan=scantable(tmpname,average=False,getpt=True,antenna=int(antid))
    10201011        outname=prefix+antnames[antid]+'.asap'
    10211012        scan.save(outname,format='ASAP',overwrite=overwrite)
     1013        tbsel.close()
     1014        tb.close()
     1015        del tbsel
    10221016        del scan
    10231017        outfiles.append(outname)
     1018        os.system('rm -rf '+tmpname)
     1019    del tb
    10241020    return outfiles
    10251021
    10261022@asaplog_post_dec
    1027 def _array2dOp( scan, value, mode="ADD", tsys=False, insitu=None, skip_flaggedrow=False):
     1023def _array2dOp( scan, value, mode="ADD", tsys=False, insitu=None):
    10281024    """
    10291025    This function is workaround on the basic operation of scantable
     
    10361032    insitu:  if False, a new scantable is returned.
    10371033             Otherwise, the array operation is done in-sitsu.
    1038     skip_flaggedrow: skip operation for row-flagged spectra.
    10391034    """
    10401035    if insitu is None: insitu = rcParams['insitu']
     
    10451040    stm._setinsitu(insitu)
    10461041    if len( value ) == 1:
    1047         s = scantable( stm._arrayop( scan, value[0], mode, tsys, skip_flaggedrow ) )
     1042        s = scantable( stm._arrayop( scan, value[0], mode, tsys ) )
    10481043    elif len( value ) != nrow:
    10491044        raise ValueError( 'len(value) must be 1 or conform to scan.nrow()' )
     
    10631058            s.set_selection( sel )
    10641059            if len( value[irow] ) == 1:
    1065                 stm._unaryop( s, value[irow][0], mode, tsys, skip_flaggedrow )
     1060                stm._unaryop( s, value[irow][0], mode, tsys )
    10661061            else:
    10671062                #stm._arrayop( s, value[irow], mode, tsys, 'channel' )
    1068                 stm._arrayop( s, value[irow], mode, tsys, skip_flaggedrow )
     1063                stm._arrayop( s, value[irow], mode, tsys )
    10691064        s.set_selection(basesel)
    10701065    return s
Note: See TracChangeset for help on using the changeset viewer.