Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/python/asapmath.py

    r2646 r2952  
     1import re
    12from asap.scantable import scantable
    23from asap.parameters import rcParams
     
    9091    else:
    9192        #s = scantable(stm._average(alignedlst, mask, weight.upper(), scanav))
    92         s = scantable(stm._new_average(alignedlst, compel, mask, weight.upper(), scanav))
     93        s = scantable(stm._new_average(alignedlst, compel, mask,
     94                                       weight.upper(), scanav))
    9395    s._add_history("average_time",varlist)
    9496
     
    391393            p.quit()
    392394            del p
    393             return scabtab
     395            return scantab
    394396        p.quit()
    395397        del p
     
    611613            p.quit()
    612614            del p
    613             return scabtab
     615            return scantab
    614616        p.quit()
    615617        del p
     
    814816            p.quit()
    815817            del p
    816             return scabtab
     818            return scantab
    817819        p.quit()
    818820        del p
     
    822824
    823825@asaplog_post_dec
    824 def merge(*args):
     826def merge(*args, **kwargs):
    825827    """
    826828    Merge a list of scanatables, or comma-sperated scantables into one
     
    828830    Parameters:
    829831        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.
    830835    Example:
    831836        myscans = [scan1, scan2]
     
    833838        # or equivalent
    834839        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')
    835844    """
    836845    varlist = vars()
     
    841850    else:
    842851        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 = ''
    843858    varlist["args"] = "%d scantables" % len(lst)
    844859    # need special formatting her for history...
     
    849864            msg = "Please give a list of scantables"
    850865            raise TypeError(msg)
    851     s = scantable(stm._merge(lst))
     866    s = scantable(stm._merge(lst, freq_tol))
    852867    s._add_history("merge", varlist)
    853868    return s
     
    949964
    950965@asaplog_post_dec
    951 def splitant(filename, outprefix='',overwrite=False):
     966def splitant(filename, outprefix='',overwrite=False, getpt=True):
    952967    """
    953968    Split Measurement set by antenna name, save data as a scantables,
    954     and return a list of filename.
     969    and return a list of filename. Note that frequency reference frame
     970    is imported as it is in Measurement set.
    955971    Notice this method can only be available from CASA.
    956972    Prameter
     
    963979                    The default False is to return with warning
    964980                    without writing the output. USE WITH CARE.
    965 
     981       getpt        Whether to import direction from MS/POINTING
     982                    table or not. Default is True (import direction).
    966983    """
    967984    # Import the table toolkit from CASA
    968     from casac import casac
     985    from taskinit import gentools
    969986    from asap.scantable import is_ms
    970     tb = casac.table()
     987    tb = gentools(['tb'])[0]
    971988    # Check the input filename
    972989    if isinstance(filename, str):
     
    978995            raise IOError(s)
    979996        # 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'):
    983997        if not is_ms(filename):
    984998            s = "File '%s' is not a Measurement set." % (filename)
     
    9961010    tb.open(tablename=filename,nomodify=True)
    9971011    ant1=tb.getcol('ANTENNA1',0,-1,1)
    998     #anttab=tb.getkeyword('ANTENNA').split()[-1]
    9991012    anttab=tb.getkeyword('ANTENNA').lstrip('Table: ')
    10001013    tb.close()
    1001     #tb.open(tablename=filename+'/ANTENNA',nomodify=True)
    10021014    tb.open(tablename=anttab,nomodify=True)
    10031015    nant=tb.nrows()
    10041016    antnames=tb.getcol('NAME',0,nant,1)
    10051017    tb.close()
    1006     tmpname='asapmath.splitant.tmp'
    10071018    for antid in set(ant1):
    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))
     1019        scan=scantable(filename,average=False,antenna=int(antid),getpt=getpt)
    10111020        outname=prefix+antnames[antid]+'.asap'
    10121021        scan.save(outname,format='ASAP',overwrite=overwrite)
    1013         tbsel.close()
    1014         tb.close()
    1015         del tbsel
    10161022        del scan
    10171023        outfiles.append(outname)
    1018         os.system('rm -rf '+tmpname)
    1019     del tb
    10201024    return outfiles
    10211025
    10221026@asaplog_post_dec
    1023 def _array2dOp( scan, value, mode="ADD", tsys=False, insitu=None):
     1027def _array2dOp( scan, value, mode="ADD", tsys=False, insitu=None, skip_flaggedrow=False):
    10241028    """
    10251029    This function is workaround on the basic operation of scantable
     
    10321036    insitu:  if False, a new scantable is returned.
    10331037             Otherwise, the array operation is done in-sitsu.
     1038    skip_flaggedrow: skip operation for row-flagged spectra.
    10341039    """
    10351040    if insitu is None: insitu = rcParams['insitu']
     
    10401045    stm._setinsitu(insitu)
    10411046    if len( value ) == 1:
    1042         s = scantable( stm._arrayop( scan, value[0], mode, tsys ) )
     1047        s = scantable( stm._arrayop( scan, value[0], mode, tsys, skip_flaggedrow ) )
    10431048    elif len( value ) != nrow:
    10441049        raise ValueError( 'len(value) must be 1 or conform to scan.nrow()' )
     
    10581063            s.set_selection( sel )
    10591064            if len( value[irow] ) == 1:
    1060                 stm._unaryop( s, value[irow][0], mode, tsys )
     1065                stm._unaryop( s, value[irow][0], mode, tsys, skip_flaggedrow )
    10611066            else:
    10621067                #stm._arrayop( s, value[irow], mode, tsys, 'channel' )
    1063                 stm._arrayop( s, value[irow], mode, tsys )
     1068                stm._arrayop( s, value[irow], mode, tsys, skip_flaggedrow )
    10641069        s.set_selection(basesel)
    10651070    return s
Note: See TracChangeset for help on using the changeset viewer.