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