Changes in trunk/python/asapmath.py [2646:2952]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/python/asapmath.py
r2646 r2952 1 import re 1 2 from asap.scantable import scantable 2 3 from asap.parameters import rcParams … … 90 91 else: 91 92 #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)) 93 95 s._add_history("average_time",varlist) 94 96 … … 391 393 p.quit() 392 394 del p 393 return sca btab395 return scantab 394 396 p.quit() 395 397 del p … … 611 613 p.quit() 612 614 del p 613 return sca btab615 return scantab 614 616 p.quit() 615 617 del p … … 814 816 p.quit() 815 817 del p 816 return sca btab818 return scantab 817 819 p.quit() 818 820 del p … … 822 824 823 825 @asaplog_post_dec 824 def merge(*args ):826 def merge(*args, **kwargs): 825 827 """ 826 828 Merge a list of scanatables, or comma-sperated scantables into one … … 828 830 Parameters: 829 831 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. 830 835 Example: 831 836 myscans = [scan1, scan2] … … 833 838 # or equivalent 834 839 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') 835 844 """ 836 845 varlist = vars() … … 841 850 else: 842 851 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 = '' 843 858 varlist["args"] = "%d scantables" % len(lst) 844 859 # need special formatting her for history... … … 849 864 msg = "Please give a list of scantables" 850 865 raise TypeError(msg) 851 s = scantable(stm._merge(lst ))866 s = scantable(stm._merge(lst, freq_tol)) 852 867 s._add_history("merge", varlist) 853 868 return s … … 949 964 950 965 @asaplog_post_dec 951 def splitant(filename, outprefix='',overwrite=False ):966 def splitant(filename, outprefix='',overwrite=False, getpt=True): 952 967 """ 953 968 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. 955 971 Notice this method can only be available from CASA. 956 972 Prameter … … 963 979 The default False is to return with warning 964 980 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). 966 983 """ 967 984 # Import the table toolkit from CASA 968 from casac import casac985 from taskinit import gentools 969 986 from asap.scantable import is_ms 970 tb = casac.table()987 tb = gentools(['tb'])[0] 971 988 # Check the input filename 972 989 if isinstance(filename, str): … … 978 995 raise IOError(s) 979 996 # 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'):983 997 if not is_ms(filename): 984 998 s = "File '%s' is not a Measurement set." % (filename) … … 996 1010 tb.open(tablename=filename,nomodify=True) 997 1011 ant1=tb.getcol('ANTENNA1',0,-1,1) 998 #anttab=tb.getkeyword('ANTENNA').split()[-1]999 1012 anttab=tb.getkeyword('ANTENNA').lstrip('Table: ') 1000 1013 tb.close() 1001 #tb.open(tablename=filename+'/ANTENNA',nomodify=True)1002 1014 tb.open(tablename=anttab,nomodify=True) 1003 1015 nant=tb.nrows() 1004 1016 antnames=tb.getcol('NAME',0,nant,1) 1005 1017 tb.close() 1006 tmpname='asapmath.splitant.tmp'1007 1018 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) 1011 1020 outname=prefix+antnames[antid]+'.asap' 1012 1021 scan.save(outname,format='ASAP',overwrite=overwrite) 1013 tbsel.close()1014 tb.close()1015 del tbsel1016 1022 del scan 1017 1023 outfiles.append(outname) 1018 os.system('rm -rf '+tmpname)1019 del tb1020 1024 return outfiles 1021 1025 1022 1026 @asaplog_post_dec 1023 def _array2dOp( scan, value, mode="ADD", tsys=False, insitu=None ):1027 def _array2dOp( scan, value, mode="ADD", tsys=False, insitu=None, skip_flaggedrow=False): 1024 1028 """ 1025 1029 This function is workaround on the basic operation of scantable … … 1032 1036 insitu: if False, a new scantable is returned. 1033 1037 Otherwise, the array operation is done in-sitsu. 1038 skip_flaggedrow: skip operation for row-flagged spectra. 1034 1039 """ 1035 1040 if insitu is None: insitu = rcParams['insitu'] … … 1040 1045 stm._setinsitu(insitu) 1041 1046 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 ) ) 1043 1048 elif len( value ) != nrow: 1044 1049 raise ValueError( 'len(value) must be 1 or conform to scan.nrow()' ) … … 1058 1063 s.set_selection( sel ) 1059 1064 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 ) 1061 1066 else: 1062 1067 #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 ) 1064 1069 s.set_selection(basesel) 1065 1070 return s
Note:
See TracChangeset
for help on using the changeset viewer.