Changeset 1846 for trunk/python
- Timestamp:
- 08/04/10 14:52:53 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/python/scantable.py
r1845 r1846 1 """This module defines the scantable class.""" 2 1 3 import os 2 4 try: … … 25 27 return wrap 26 28 27 28 29 def is_scantable(filename): 30 """Is the given file a scantable? 31 32 Parameters: 33 34 filename: the name of the file/directory to test 35 36 """ 29 37 return (os.path.isdir(filename) 30 38 and not os.path.exists(filename+'/table.f1') … … 33 41 34 42 class scantable(Scantable): 35 """ 36 The ASAP container for scans 43 """\ 44 The ASAP container for scans (single-dish data). 37 45 """ 38 46 … … 40 48 def __init__(self, filename, average=None, unit=None, getpt=None, 41 49 antenna=None, parallactify=None): 42 """ 50 """\ 43 51 Create a scantable from a saved one or make a reference 44 Parameters: 45 filename: the name of an asap table on disk 46 or 47 the name of a rpfits/sdfits/ms file 48 (integrations within scans are auto averaged 49 and the whole file is read) 50 or 51 [advanced] a reference to an existing 52 scantable 53 average: average all integrations withinb a scan on read. 54 The default (True) is taken from .asaprc. 52 53 Parameters: 54 55 filename: the name of an asap table on disk 56 or 57 the name of a rpfits/sdfits/ms file 58 (integrations within scans are auto averaged 59 and the whole file is read) or 60 [advanced] a reference to an existing scantable 61 62 average: average all integrations withinb a scan on read. 63 The default (True) is taken from .asaprc. 64 55 65 unit: brightness unit; must be consistent with K or Jy. 56 Over-rides the default selected by the filler 57 (input rpfits/sdfits/ms) or replaces the value 58 in existing scantables 59 getpt: for MeasurementSet input data only: 60 If True, all pointing data are filled. 61 The deafult is False, which makes time to load 62 the MS data faster in some cases. 63 antenna: Antenna selection. integer (id) or string (name 64 or id). 65 parallactify: Indicate that the data had been parallatified. 66 Default is taken form rc file. 66 Over-rides the default selected by the filler 67 (input rpfits/sdfits/ms) or replaces the value 68 in existing scantables 69 70 getpt: for MeasurementSet input data only: 71 If True, all pointing data are filled. 72 The deafult is False, which makes time to load 73 the MS data faster in some cases. 74 75 antenna: Antenna selection. integer (id) or string (name or id). 76 77 parallactify: Indicate that the data had been parallatified. Default 78 is taken from rc file. 79 67 80 """ 68 81 if average is None: … … 136 149 @print_log_dec 137 150 def save(self, name=None, format=None, overwrite=False): 138 """ 151 """\ 139 152 Store the scantable on disk. This can be an asap (aips++) Table, 140 153 SDFITS or MS2 format. 141 Parameters: 154 155 Parameters: 156 142 157 name: the name of the outputfile. For format "ASCII" 143 158 this is the root file name (data in 'name'.txt … … 155 170 The default False is to return with warning 156 171 without writing the output. USE WITH CARE. 157 Example: 172 Example:: 173 158 174 scan.save('myscan.asap') 159 175 scan.save('myscan.sdfits', 'SDFITS') 176 160 177 """ 161 178 from os import path … … 188 205 189 206 def copy(self): 190 """ 191 Return a copy of this scantable. 192 Note: 207 """Return a copy of this scantable. 208 209 *Note*: 210 193 211 This makes a full (deep) copy. scan2 = scan1 makes a reference. 194 Parameters: 195 none196 Example: 212 213 Example:: 214 197 215 copiedscan = scan.copy() 216 198 217 """ 199 218 sd = scantable(Scantable._copy(self)) … … 201 220 202 221 def drop_scan(self, scanid=None): 203 """ 222 """\ 204 223 Return a new scantable where the specified scan number(s) has(have) 205 224 been dropped. 206 Parameters: 225 226 Parameters: 227 207 228 scanid: a (list of) scan number(s) 229 208 230 """ 209 231 from asap import _is_sequence_or_number as _is_valid … … 255 277 Return a specific scan (by scanno) or collection of scans (by 256 278 source name) in a new scantable. 257 Note: 279 280 *Note*: 281 258 282 See scantable.drop_scan() for the inverse operation. 259 Parameters: 283 284 Parameters: 285 260 286 scanid: a (list of) scanno or a source name, unix-style 261 287 patterns are accepted for source name matching, e.g. 262 288 '*_R' gets all 'ref scans 263 Example: 289 290 Example:: 291 264 292 # get all scans containing the source '323p459' 265 293 newscan = scan.get_scan('323p459') … … 268 296 # get a susbset of scans by scanno (as listed in scan.summary()) 269 297 newscan = scan.get_scan([0, 2, 7, 10]) 298 270 299 """ 271 300 if scanid is None: … … 273 302 #print "Please specify a scan no or name to " \ 274 303 # "retrieve from the scantable" 275 asaplog.push( 'Please specify a scan no or name to retrieve from the scantable' ) 304 asaplog.push( 'Please specify a scan no or name to retrieve' 305 ' from the scantable' ) 276 306 print_log( 'ERROR' ) 277 307 return … … 311 341 312 342 def summary(self, filename=None): 313 """ 343 """\ 314 344 Print a summary of the contents of this scantable. 315 Parameters: 345 346 Parameters: 347 316 348 filename: the name of a file to write the putput to 317 349 Default - no file output 350 318 351 """ 319 352 info = Scantable._summary(self, True) … … 346 379 def get_spectrum(self, rowno): 347 380 """Return the spectrum for the current row in the scantable as a list. 348 Parameters: 381 382 Parameters: 383 349 384 rowno: the row number to retrieve the spectrum from 385 350 386 """ 351 387 return self._getspectrum(rowno) … … 353 389 def get_mask(self, rowno): 354 390 """Return the mask for the current row in the scantable as a list. 355 Parameters: 391 392 Parameters: 393 356 394 rowno: the row number to retrieve the mask from 395 357 396 """ 358 397 return self._getmask(rowno) … … 360 399 def set_spectrum(self, spec, rowno): 361 400 """Return the spectrum for the current row in the scantable as a list. 362 Parameters: 401 402 Parameters: 403 363 404 spec: the spectrum 364 405 rowno: the row number to set the spectrum for 406 365 407 """ 366 408 assert(len(spec) == self.nchan()) … … 369 411 def get_coordinate(self, rowno): 370 412 """Return the (spectral) coordinate for a a given 'rowno'. 371 NOTE: 413 414 *Note*: 415 372 416 * This coordinate is only valid until a scantable method modifies 373 417 the frequency axis. … … 376 420 specified frame (e.g. LSRK/TOPO). To get the 'real' coordinate, 377 421 use scantable.freq_align first. Without it there is no closure, 378 i.e. 379 c = myscan.get_coordinate(0) 380 c.to_frequency(c.get_reference_pixel()) != c.get_reference_value() 381 382 Parameters: 422 i.e.:: 423 424 c = myscan.get_coordinate(0) 425 c.to_frequency(c.get_reference_pixel()) != c.get_reference_value() 426 427 Parameters: 428 383 429 rowno: the row number for the spectral coordinate 384 430 … … 387 433 388 434 def get_selection(self): 389 """ 435 """\ 390 436 Get the selection object currently set on this scantable. 391 Parameters: 392 none393 Example: 437 438 Example:: 439 394 440 sel = scan.get_selection() 395 441 sel.set_ifs(0) # select IF 0 396 442 scan.set_selection(sel) # apply modified selection 443 397 444 """ 398 445 return selector(self._getselection()) 399 446 400 447 def set_selection(self, selection=None, **kw): 401 """ 448 """\ 402 449 Select a subset of the data. All following operations on this scantable 403 450 are only applied to thi selection. 404 Parameters: 405 selection: a selector object (default unset the selection),406 407 or408 409 any combination of410 "pols", "ifs", "beams", "scans", "cycles", "name", "query" 411 412 Examples: 451 452 Parameters: 453 454 selection: a selector object (default unset the selection), or 455 any combination of "pols", "ifs", "beams", "scans", 456 "cycles", "name", "query" 457 458 Examples:: 459 413 460 sel = selector() # create a selection object 414 461 self.set_scans([0, 3]) # select SCANNO 0 and 3 … … 420 467 scan.summary() # will only print summary of scanno 0 an 3 421 468 scan.set_selection() # unset the selection 469 422 470 """ 423 471 if selection is None: … … 434 482 435 483 def get_row(self, row=0, insitu=None): 436 """ 484 """\ 437 485 Select a row in the scantable. 438 486 Return a scantable with single row. 439 Parameters: 440 row: row no of integration, default is 0. 441 insitu: if False a new scantable is returned. 442 Otherwise, the scaling is done in-situ 443 The default is taken from .asaprc (False) 487 488 Parameters: 489 490 row: row no of integration, default is 0. 491 insitu: if False a new scantable is returned. Otherwise, the 492 scaling is done in-situ. The default is taken from .asaprc 493 (False) 494 444 495 """ 445 496 if insitu is None: insitu = rcParams['insitu'] … … 468 519 #def stats(self, stat='stddev', mask=None): 469 520 def stats(self, stat='stddev', mask=None, form='3.3f'): 470 """ 521 """\ 471 522 Determine the specified statistic of the current beam/if/pol 472 523 Takes a 'mask' as an optional parameter to specify which 473 524 channels should be excluded. 474 Parameters: 525 526 Parameters: 527 475 528 stat: 'min', 'max', 'min_abc', 'max_abc', 'sumsq', 'sum', 476 529 'mean', 'var', 'stddev', 'avdev', 'rms', 'median' … … 478 531 should be determined. 479 532 form: format string to print statistic values 480 Example: 533 534 Example:: 535 481 536 scan.set_unit('channel') 482 537 msk = scan.create_mask([100, 200], [500, 600]) 483 538 scan.stats(stat='mean', mask=m) 539 484 540 """ 485 541 mask = mask or [] … … 557 613 558 614 def chan2data(self, rowno=0, chan=0): 559 """ 615 """\ 560 616 Returns channel/frequency/velocity and spectral value 561 617 at an arbitrary row and channel in the scantable. 562 Parameters: 618 619 Parameters: 620 563 621 rowno: a row number in the scantable. Default is the 564 622 first row, i.e. rowno=0 565 623 chan: a channel in the scantable. Default is the first 566 624 channel, i.e. pos=0 625 567 626 """ 568 627 if isinstance(rowno, int) and isinstance(chan, int): … … 574 633 575 634 def stddev(self, mask=None): 576 """ 635 """\ 577 636 Determine the standard deviation of the current beam/if/pol 578 637 Takes a 'mask' as an optional parameter to specify which 579 638 channels should be excluded. 580 Parameters: 639 640 Parameters: 641 581 642 mask: an optional mask specifying where the standard 582 643 deviation should be determined. 583 644 584 Example: 645 Example:: 646 585 647 scan.set_unit('channel') 586 648 msk = scan.create_mask([100, 200], [500, 600]) 587 649 scan.stddev(mask=m) 650 588 651 """ 589 652 return self.stats(stat='stddev', mask=mask); … … 591 654 592 655 def get_column_names(self): 593 """ 656 """\ 594 657 Return a list of column names, which can be used for selection. 595 658 """ … … 597 660 598 661 def get_tsys(self, row=-1): 599 """ 662 """\ 600 663 Return the System temperatures. 664 665 Parameters: 666 667 row: the rowno to get the information for. (default all rows) 668 601 669 Returns: 670 602 671 a list of Tsys values for the current selection 672 603 673 """ 604 674 if row > -1: … … 608 678 609 679 def get_weather(self, row=-1): 680 """\ 681 Return the weather informations. 682 683 Parameters: 684 685 row: the rowno to get the information for. (default all rows) 686 687 Returns: 688 689 a dict or list of of dicts of values for the current selection 690 691 """ 692 610 693 values = self._get_column(self._get_weather, row) 611 694 if row > -1: … … 659 742 660 743 def get_time(self, row=-1, asdatetime=False): 661 """ 744 """\ 662 745 Get a list of time stamps for the observations. 663 746 Return a datetime object for each integration time stamp in the scantable. 664 Parameters: 747 748 Parameters: 749 665 750 row: row no of integration. Default -1 return all rows 666 751 asdatetime: return values as datetime objects rather than strings 667 Example: 668 none 752 669 753 """ 670 754 from time import strptime … … 681 765 682 766 def get_inttime(self, row=-1): 683 """ 767 """\ 684 768 Get a list of integration times for the observations. 685 769 Return a time in seconds for each integration in the scantable. 686 Parameters: 770 771 Parameters: 772 687 773 row: row no of integration. Default -1 return all rows. 688 Example: 689 none 774 690 775 """ 691 776 return self._get_column(self._getinttime, row) … … 693 778 694 779 def get_sourcename(self, row=-1): 695 """ 780 """\ 696 781 Get a list source names for the observations. 697 782 Return a string for each integration in the scantable. 698 783 Parameters: 784 699 785 row: row no of integration. Default -1 return all rows. 700 Example: 701 none 786 702 787 """ 703 788 return self._get_column(self._getsourcename, row) 704 789 705 790 def get_elevation(self, row=-1): 706 """ 791 """\ 707 792 Get a list of elevations for the observations. 708 793 Return a float for each integration in the scantable. 709 Parameters: 794 795 Parameters: 796 710 797 row: row no of integration. Default -1 return all rows. 711 Example: 712 none 798 713 799 """ 714 800 return self._get_column(self._getelevation, row) 715 801 716 802 def get_azimuth(self, row=-1): 717 """ 803 """\ 718 804 Get a list of azimuths for the observations. 719 805 Return a float for each integration in the scantable. 806 720 807 Parameters: 721 808 row: row no of integration. Default -1 return all rows. 722 Example: 723 none 809 724 810 """ 725 811 return self._get_column(self._getazimuth, row) 726 812 727 813 def get_parangle(self, row=-1): 728 """ 814 """\ 729 815 Get a list of parallactic angles for the observations. 730 816 Return a float for each integration in the scantable. 731 Parameters: 817 818 Parameters: 819 732 820 row: row no of integration. Default -1 return all rows. 733 Example: 734 none 821 735 822 """ 736 823 return self._get_column(self._getparangle, row) … … 748 835 749 836 def get_directionval(self, row=-1): 750 """ 837 """\ 751 838 Get a list of Positions on the sky (direction) for the observations. 752 839 Return a float for each integration in the scantable. 753 Parameters: 840 841 Parameters: 842 754 843 row: row no of integration. Default -1 return all rows 755 Example: 756 none 844 757 845 """ 758 846 return self._get_column(self._getdirectionvec, row) … … 760 848 @print_log_dec 761 849 def set_unit(self, unit='channel'): 762 """ 850 """\ 763 851 Set the unit for all following operations on this scantable 764 Parameters: 765 unit: optional unit, default is 'channel' 766 one of '*Hz', 'km/s', 'channel', '' 852 853 Parameters: 854 855 unit: optional unit, default is 'channel'. Use one of '*Hz', 856 'km/s', 'channel' or equivalent '' 857 767 858 """ 768 859 varlist = vars() … … 776 867 @print_log_dec 777 868 def set_instrument(self, instr): 778 """ 869 """\ 779 870 Set the instrument for subsequent processing. 780 Parameters: 871 872 Parameters: 873 781 874 instr: Select from 'ATPKSMB', 'ATPKSHOH', 'ATMOPRA', 782 875 'DSS-43' (Tid), 'CEDUNA', and 'HOBART' 876 783 877 """ 784 878 self._setInstrument(instr) … … 788 882 @print_log_dec 789 883 def set_feedtype(self, feedtype): 790 """ 884 """\ 791 885 Overwrite the feed type, which might not be set correctly. 792 Parameters: 886 887 Parameters: 888 793 889 feedtype: 'linear' or 'circular' 890 794 891 """ 795 892 self._setfeedtype(feedtype) … … 799 896 @print_log_dec 800 897 def set_doppler(self, doppler='RADIO'): 801 """ 898 """\ 802 899 Set the doppler for all following operations on this scantable. 803 Parameters: 900 901 Parameters: 902 804 903 doppler: One of 'RADIO', 'OPTICAL', 'Z', 'BETA', 'GAMMA' 904 805 905 """ 806 906 varlist = vars() … … 813 913 @print_log_dec 814 914 def set_freqframe(self, frame=None): 815 """ 915 """\ 816 916 Set the frame type of the Spectral Axis. 817 Parameters: 917 918 Parameters: 919 818 920 frame: an optional frame type, default 'LSRK'. Valid frames are: 819 921 'TOPO', 'LSRD', 'LSRK', 'BARY', 820 922 'GEO', 'GALACTO', 'LGROUP', 'CMB' 821 Examples: 923 924 Example:: 925 822 926 scan.set_freqframe('BARY') 927 823 928 """ 824 929 frame = frame or rcParams['scantable.freqframe'] … … 846 951 847 952 def set_dirframe(self, frame=""): 848 """ 953 """\ 849 954 Set the frame type of the Direction on the sky. 850 Parameters: 955 956 Parameters: 957 851 958 frame: an optional frame type, default ''. Valid frames are: 852 959 'J2000', 'B1950', 'GALACTIC' 853 Examples: 960 961 Example: 962 854 963 scan.set_dirframe('GALACTIC') 964 855 965 """ 856 966 varlist = vars() … … 868 978 869 979 def get_unit(self): 870 """ 980 """\ 871 981 Get the default unit set in this scantable 982 872 983 Returns: 984 873 985 A unit string 986 874 987 """ 875 988 inf = self._getcoordinfo() … … 879 992 880 993 def get_abcissa(self, rowno=0): 881 """ 994 """\ 882 995 Get the abcissa in the current coordinate setup for the currently 883 996 selected Beam/IF/Pol 884 Parameters: 997 998 Parameters: 999 885 1000 rowno: an optional row number in the scantable. Default is the 886 1001 first row, i.e. rowno=0 1002 887 1003 Returns: 1004 888 1005 The abcissa values and the format string (as a dictionary) 1006 889 1007 """ 890 1008 abc = self._getabcissa(rowno) … … 894 1012 895 1013 def flag(self, mask=None, unflag=False): 896 """ 1014 """\ 897 1015 Flag the selected data using an optional channel mask. 898 Parameters: 1016 1017 Parameters: 1018 899 1019 mask: an optional channel mask, created with create_mask. Default 900 1020 (no mask) is all channels. 901 1021 unflag: if True, unflag the data 1022 902 1023 """ 903 1024 varlist = vars() … … 916 1037 917 1038 def flag_row(self, rows=[], unflag=False): 918 """ 1039 """\ 919 1040 Flag the selected data in row-based manner. 920 Parameters: 1041 1042 Parameters: 1043 921 1044 rows: list of row numbers to be flagged. Default is no row 922 1045 (must be explicitly specified to execute row-based flagging). 923 1046 unflag: if True, unflag the data. 1047 924 1048 """ 925 1049 varlist = vars() … … 936 1060 937 1061 def clip(self, uthres=None, dthres=None, clipoutside=True, unflag=False): 938 """ 1062 """\ 939 1063 Flag the selected data outside a specified range (in channel-base) 940 Parameters: 1064 1065 Parameters: 1066 941 1067 uthres: upper threshold. 942 1068 dthres: lower threshold 1069 943 1070 clipoutside: True for flagging data outside the range [dthres:uthres]. 944 1071 False for glagging data inside the range. 945 unflag : if True, unflag the data. 1072 unflag: if True, unflag the data. 1073 946 1074 """ 947 1075 varlist = vars() … … 959 1087 @print_log_dec 960 1088 def lag_flag(self, start, end, unit="MHz", insitu=None): 961 #def lag_flag(self, frequency, width=0.0, unit="GHz", insitu=None): 962 """ 1089 """\ 963 1090 Flag the data in 'lag' space by providing a frequency to remove. 964 1091 Flagged data in the scantable gets interpolated over the region. 965 1092 No taper is applied. 966 Parameters: 1093 1094 Parameters: 1095 967 1096 start: the start frequency (really a period within the 968 1097 bandwidth) or period to remove … … 970 1099 unit: the frequency unit (default "MHz") or "" for 971 1100 explicit lag channels 972 Notes: 1101 1102 *Notes*: 1103 973 1104 It is recommended to flag edges of the band or strong 974 1105 signals beforehand. 1106 975 1107 """ 976 1108 if insitu is None: insitu = rcParams['insitu'] … … 1003 1135 @print_log_dec 1004 1136 def create_mask(self, *args, **kwargs): 1005 """ 1137 """\ 1006 1138 Compute and return a mask based on [min, max] windows. 1007 1139 The specified windows are to be INCLUDED, when the mask is 1008 1140 applied. 1009 Parameters: 1141 1142 Parameters: 1143 1010 1144 [min, max], [min2, max2], ... 1011 1145 Pairs of start/end points (inclusive)specifying the regions … … 1017 1151 unit conversions, default is row=0 1018 1152 only necessary if frequency varies over rows. 1019 Example: 1153 1154 Examples:: 1155 1020 1156 scan.set_unit('channel') 1021 a)1157 # a) 1022 1158 msk = scan.create_mask([400, 500], [800, 900]) 1023 1159 # masks everything outside 400 and 500 1024 1160 # and 800 and 900 in the unit 'channel' 1025 1161 1026 b)1162 # b) 1027 1163 msk = scan.create_mask([400, 500], [800, 900], invert=True) 1028 1164 # masks the regions between 400 and 500 1029 1165 # and 800 and 900 in the unit 'channel' 1030 c) 1031 mask only channel 400 1166 1167 # c) 1168 #mask only channel 400 1032 1169 msk = scan.create_mask([400]) 1170 1033 1171 """ 1034 1172 row = kwargs.get("row", 0) … … 1067 1205 1068 1206 def get_masklist(self, mask=None, row=0): 1069 """ 1207 """\ 1070 1208 Compute and return a list of mask windows, [min, max]. 1071 Parameters: 1209 1210 Parameters: 1211 1072 1212 mask: channel mask, created with create_mask. 1073 1213 row: calcutate the masklist using the specified row 1074 1214 for unit conversions, default is row=0 1075 1215 only necessary if frequency varies over rows. 1216 1076 1217 Returns: 1218 1077 1219 [min, max], [min2, max2], ... 1078 1220 Pairs of start/end points (inclusive)specifying 1079 1221 the masked regions 1222 1080 1223 """ 1081 1224 if not (isinstance(mask,list) or isinstance(mask, tuple)): … … 1106 1249 1107 1250 def get_mask_indices(self, mask=None): 1108 """ 1251 """\ 1109 1252 Compute and Return lists of mask start indices and mask end indices. 1110 1253 Parameters: 1111 1254 mask: channel mask, created with create_mask. 1255 1112 1256 Returns: 1257 1113 1258 List of mask start indices and that of mask end indices, 1114 1259 i.e., [istart1,istart2,....], [iend1,iend2,....]. 1260 1115 1261 """ 1116 1262 if not (isinstance(mask,list) or isinstance(mask, tuple)): … … 1147 1293 1148 1294 def get_restfreqs(self, ids=None): 1149 """ 1295 """\ 1150 1296 Get the restfrequency(s) stored in this scantable. 1151 1297 The return value(s) are always of unit 'Hz' 1152 Parameters: 1298 1299 Parameters: 1300 1153 1301 ids: (optional) a list of MOLECULE_ID for that restfrequency(s) to 1154 1302 be retrieved 1303 1155 1304 Returns: 1305 1156 1306 dictionary containing ids and a list of doubles for each id 1307 1157 1308 """ 1158 1309 if ids is None: … … 1173 1324 1174 1325 def set_restfreqs(self, freqs=None, unit='Hz'): 1175 """ 1176 ********NEED TO BE UPDATED begin************ 1326 """\ 1177 1327 Set or replace the restfrequency specified and 1178 1328 If the 'freqs' argument holds a scalar, … … 1186 1336 E.g. 'freqs=[1e9, 2e9]' would mean IF 0 gets restfreq 1e9 and 1187 1337 IF 1 gets restfreq 2e9. 1188 ********NEED TO BE UPDATED end************ 1338 1189 1339 You can also specify the frequencies via a linecatalog. 1190 1340 1191 1341 Parameters: 1342 1192 1343 freqs: list of rest frequency values or string idenitfiers 1193 1344 unit: unit for rest frequency (default 'Hz') 1194 1345 1195 Example: 1346 1347 Example:: 1348 1196 1349 # set the given restfrequency for the all currently selected IFs 1197 1350 scan.set_restfreqs(freqs=1.4e9) … … 1207 1360 scan.set_restfreqs(freqs=[[1.4e9, 1.41e9], [1.67e9]]) 1208 1361 1209 1210 Note: 1362 *Note*: 1363 1211 1364 To do more sophisticate Restfrequency setting, e.g. on a 1212 1365 source and IF basis, use scantable.set_selection() before using 1213 this function. 1214 # provided your scantable is called scan 1215 selection = selector() 1216 selection.set_name("ORION*") 1217 selection.set_ifs([1]) 1218 scan.set_selection(selection) 1219 scan.set_restfreqs(freqs=86.6e9) 1366 this function:: 1367 1368 # provided your scantable is called scan 1369 selection = selector() 1370 selection.set_name("ORION*") 1371 selection.set_ifs([1]) 1372 scan.set_selection(selection) 1373 scan.set_restfreqs(freqs=86.6e9) 1220 1374 1221 1375 """ … … 1283 1437 1284 1438 def shift_refpix(self, delta): 1285 """ 1439 """\ 1286 1440 Shift the reference pixel of the Spectra Coordinate by an 1287 1441 integer amount. 1288 Parameters: 1442 1443 Parameters: 1444 1289 1445 delta: the amount to shift by 1290 Note: 1446 1447 *Note*: 1448 1291 1449 Be careful using this with broadband data. 1450 1292 1451 """ 1293 1452 Scantable.shift_refpix(self, delta) 1294 1453 1295 1454 def history(self, filename=None): 1296 """ 1455 """\ 1297 1456 Print the history. Optionally to a file. 1298 Parameters: 1457 1458 Parameters: 1459 1299 1460 filename: The name of the file to save the history to. 1461 1300 1462 """ 1301 1463 hist = list(self._gethistory()) … … 1346 1508 @print_log_dec 1347 1509 def average_time(self, mask=None, scanav=False, weight='tint', align=False): 1348 """ 1510 """\ 1349 1511 Return the (time) weighted average of a scan. 1350 Note: 1512 1513 *Note*: 1514 1351 1515 in channels only - align if necessary 1352 Parameters: 1516 1517 Parameters: 1518 1353 1519 mask: an optional mask (only used for 'var' and 'tsys' 1354 1520 weighting) … … 1365 1531 align: align the spectra in velocity before averaging. It takes 1366 1532 the time of the first spectrum as reference time. 1367 Example: 1533 1534 Example:: 1535 1368 1536 # time average the scantable without using a mask 1369 1537 newscan = scan.average_time() 1538 1370 1539 """ 1371 1540 varlist = vars() … … 1398 1567 @print_log_dec 1399 1568 def convert_flux(self, jyperk=None, eta=None, d=None, insitu=None): 1400 """ 1569 """\ 1401 1570 Return a scan where all spectra are converted to either 1402 1571 Jansky or Kelvin depending upon the flux units of the scan table. … … 1405 1574 specify EITHER jyperk OR eta (and D which it will try to look up 1406 1575 also if you don't set it). jyperk takes precedence if you set both. 1407 Parameters: 1576 1577 Parameters: 1578 1408 1579 jyperk: the Jy / K conversion factor 1409 1580 eta: the aperture efficiency … … 1412 1583 Otherwise, the scaling is done in-situ 1413 1584 The default is taken from .asaprc (False) 1585 1414 1586 """ 1415 1587 if insitu is None: insitu = rcParams['insitu'] … … 1427 1599 @print_log_dec 1428 1600 def gain_el(self, poly=None, filename="", method="linear", insitu=None): 1429 """ 1601 """\ 1430 1602 Return a scan after applying a gain-elevation correction. 1431 1603 The correction can be made via either a polynomial or a … … 1436 1608 will occur if the instrument is not known). 1437 1609 The data and Tsys are *divided* by the scaling factors. 1438 Parameters: 1610 1611 Parameters: 1612 1439 1613 poly: Polynomial coefficients (default None) to compute a 1440 1614 gain-elevation correction as a function of … … 1464 1638 Otherwise, the scaling is done in-situ 1465 1639 The default is taken from .asaprc (False) 1640 1466 1641 """ 1467 1642 … … 1482 1657 @print_log_dec 1483 1658 def freq_align(self, reftime=None, method='cubic', insitu=None): 1484 """ 1659 """\ 1485 1660 Return a scan where all rows have been aligned in frequency/velocity. 1486 1661 The alignment frequency frame (e.g. LSRK) is that set by function 1487 1662 set_freqframe. 1663 1488 1664 Parameters: 1489 1665 reftime: reference time to align at. By default, the time of … … 1495 1671 Otherwise, the scaling is done in-situ 1496 1672 The default is taken from .asaprc (False) 1673 1497 1674 """ 1498 1675 if insitu is None: insitu = rcParams["insitu"] … … 1508 1685 @print_log_dec 1509 1686 def opacity(self, tau=None, insitu=None): 1510 """ 1687 """\ 1511 1688 Apply an opacity correction. The data 1512 1689 and Tsys are multiplied by the correction factor. 1690 1513 1691 Parameters: 1514 1692 tau: (list of) opacity from which the correction factor is … … 1523 1701 Otherwise, the scaling is done in-situ 1524 1702 The default is taken from .asaprc (False) 1703 1525 1704 """ 1526 1705 if insitu is None: insitu = rcParams['insitu'] … … 1537 1716 @print_log_dec 1538 1717 def bin(self, width=5, insitu=None): 1539 """ 1718 """\ 1540 1719 Return a scan where all spectra have been binned up. 1541 Parameters: 1720 1721 Parameters: 1722 1542 1723 width: The bin width (default=5) in pixels 1543 1724 insitu: if False a new scantable is returned. 1544 1725 Otherwise, the scaling is done in-situ 1545 1726 The default is taken from .asaprc (False) 1727 1546 1728 """ 1547 1729 if insitu is None: insitu = rcParams['insitu'] … … 1558 1740 @print_log_dec 1559 1741 def resample(self, width=5, method='cubic', insitu=None): 1560 """ 1742 """\ 1561 1743 Return a scan where all spectra have been binned up. 1562 1744 1563 1745 Parameters: 1746 1564 1747 width: The bin width (default=5) in pixels 1565 1748 method: Interpolation method when correcting from a table. … … 1569 1752 Otherwise, the scaling is done in-situ 1570 1753 The default is taken from .asaprc (False) 1754 1571 1755 """ 1572 1756 if insitu is None: insitu = rcParams['insitu'] … … 1581 1765 @print_log_dec 1582 1766 def average_pol(self, mask=None, weight='none'): 1583 """ 1767 """\ 1584 1768 Average the Polarisations together. 1585 Parameters: 1769 1770 Parameters: 1771 1586 1772 mask: An optional mask defining the region, where the 1587 1773 averaging will be applied. The output will have all … … 1589 1775 weight: Weighting scheme. 'none' (default), 'var' (1/var(spec) 1590 1776 weighted), or 'tsys' (1/Tsys**2 weighted) 1777 1591 1778 """ 1592 1779 varlist = vars() … … 1599 1786 @print_log_dec 1600 1787 def average_beam(self, mask=None, weight='none'): 1601 """ 1788 """\ 1602 1789 Average the Beams together. 1790 1603 1791 Parameters: 1604 1792 mask: An optional mask defining the region, where the … … 1607 1795 weight: Weighting scheme. 'none' (default), 'var' (1/var(spec) 1608 1796 weighted), or 'tsys' (1/Tsys**2 weighted) 1797 1609 1798 """ 1610 1799 varlist = vars() … … 1616 1805 1617 1806 def parallactify(self, pflag): 1618 """ 1807 """\ 1619 1808 Set a flag to indicate whether this data should be treated as having 1620 1809 been 'parallactified' (total phase == 0.0) 1810 1621 1811 Parameters: 1622 1812 pflag: Bool indicating whether to turn this on (True) or 1623 1813 off (False) 1814 1624 1815 """ 1625 1816 varlist = vars() … … 1629 1820 @print_log_dec 1630 1821 def convert_pol(self, poltype=None): 1631 """ 1822 """\ 1632 1823 Convert the data to a different polarisation type. 1633 1824 Note that you will need cross-polarisation terms for most conversions. 1825 1634 1826 Parameters: 1635 1827 poltype: The new polarisation type. Valid types are: 1636 1828 "linear", "circular", "stokes" and "linpol" 1829 1637 1830 """ 1638 1831 varlist = vars() … … 1654 1847 @print_log_dec 1655 1848 def smooth(self, kernel="hanning", width=5.0, order=2, plot=False, insitu=None): 1656 """ 1849 """\ 1657 1850 Smooth the spectrum by the specified kernel (conserving flux). 1658 Parameters: 1851 1852 Parameters: 1853 1659 1854 kernel: The type of smoothing kernel. Select from 1660 1855 'hanning' (default), 'gaussian', 'boxcar', 'rmedian' … … 1674 1869 Otherwise, the scaling is done in-situ 1675 1870 The default is taken from .asaprc (False) 1676 Example: 1677 none 1871 1678 1872 """ 1679 1873 if insitu is None: insitu = rcParams['insitu'] … … 1729 1923 def poly_baseline(self, mask=None, order=0, plot=False, uselin=False, 1730 1924 insitu=None): 1731 """ 1925 """\ 1732 1926 Return a scan which has been baselined (all rows) by a polynomial. 1733 Parameters: 1927 1928 Parameters: 1929 1734 1930 mask: an optional mask 1735 1931 order: the order of the polynomial (default is 0) … … 1741 1937 Otherwise, the scaling is done in-situ 1742 1938 The default is taken from .asaprc (False) 1743 Example: 1939 1940 Example:: 1941 1744 1942 # return a scan baselined by a third order polynomial, 1745 1943 # not using a mask 1746 1944 bscan = scan.poly_baseline(order=3) 1945 1747 1946 """ 1748 1947 if insitu is None: insitu = rcParams['insitu'] … … 1815 2014 threshold=3, chan_avg_limit=1, plot=False, 1816 2015 insitu=None): 1817 """ 2016 """\ 1818 2017 Return a scan which has been baselined (all rows) by a polynomial. 1819 2018 Spectral lines are detected first using linefinder and masked out … … 1821 2020 1822 2021 Parameters: 2022 1823 2023 mask: an optional mask retreived from scantable 1824 edge: an optional number of channel to drop at 1825 the edge of spectrum. If only one value is 2024 2025 edge: an optional number of channel to drop at the edge of 2026 spectrum. If only one value is 1826 2027 specified, the same number will be dropped from 1827 2028 both sides of the spectrum. Default is to keep … … 1829 2030 edge selection for different IFs (a number of spectral 1830 2031 channels can be different) 2032 1831 2033 order: the order of the polynomial (default is 0) 2034 1832 2035 threshold: the threshold used by line finder. It is better to 1833 2036 keep it large as only strong lines affect the 1834 2037 baseline solution. 2038 1835 2039 chan_avg_limit: 1836 2040 a maximum number of consequtive spectral channels to … … 1842 2046 users of this method should find the default value 1843 2047 sufficient. 2048 1844 2049 plot: plot the fit and the residual. In this each 1845 2050 indivual fit has to be approved, by typing 'y' 1846 2051 or 'n' 2052 1847 2053 insitu: if False a new scantable is returned. 1848 2054 Otherwise, the scaling is done in-situ 1849 2055 The default is taken from .asaprc (False) 1850 2056 1851 Example: 1852 scan2=scan.auto_poly_baseline(order=7) 2057 2058 Example:: 2059 2060 scan2 = scan.auto_poly_baseline(order=7, insitu=False) 2061 1853 2062 """ 1854 2063 if insitu is None: insitu = rcParams['insitu'] … … 1961 2170 @print_log_dec 1962 2171 def rotate_linpolphase(self, angle): 1963 """ 2172 """\ 1964 2173 Rotate the phase of the complex polarization O=Q+iU correlation. 1965 2174 This is always done in situ in the raw data. So if you call this 1966 2175 function more than once then each call rotates the phase further. 1967 Parameters: 2176 2177 Parameters: 2178 1968 2179 angle: The angle (degrees) to rotate (add) by. 1969 Examples: 2180 2181 Example:: 2182 1970 2183 scan.rotate_linpolphase(2.3) 2184 1971 2185 """ 1972 2186 varlist = vars() … … 1978 2192 @print_log_dec 1979 2193 def rotate_xyphase(self, angle): 1980 """ 2194 """\ 1981 2195 Rotate the phase of the XY correlation. This is always done in situ 1982 2196 in the data. So if you call this function more than once 1983 2197 then each call rotates the phase further. 1984 Parameters: 2198 2199 Parameters: 2200 1985 2201 angle: The angle (degrees) to rotate (add) by. 1986 Examples: 2202 2203 Example:: 2204 1987 2205 scan.rotate_xyphase(2.3) 2206 1988 2207 """ 1989 2208 varlist = vars() … … 1995 2214 @print_log_dec 1996 2215 def swap_linears(self): 1997 """ 2216 """\ 1998 2217 Swap the linear polarisations XX and YY, or better the first two 1999 2218 polarisations as this also works for ciculars. … … 2007 2226 @print_log_dec 2008 2227 def invert_phase(self): 2009 """ 2228 """\ 2010 2229 Invert the phase of the complex polarisation 2011 2230 """ … … 2013 2232 self._math._invert_phase(self) 2014 2233 self._add_history("invert_phase", varlist) 2015 print_log()2016 2234 return 2017 2235 2018 2236 @print_log_dec 2019 2237 def add(self, offset, insitu=None): 2020 """ 2238 """\ 2021 2239 Return a scan where all spectra have the offset added 2022 Parameters: 2240 2241 Parameters: 2242 2023 2243 offset: the offset 2024 2244 insitu: if False a new scantable is returned. 2025 2245 Otherwise, the scaling is done in-situ 2026 2246 The default is taken from .asaprc (False) 2247 2027 2248 """ 2028 2249 if insitu is None: insitu = rcParams['insitu'] … … 2031 2252 s = scantable(self._math._unaryop(self, offset, "ADD", False)) 2032 2253 s._add_history("add", varlist) 2033 print_log()2034 2254 if insitu: 2035 2255 self._assign(s) … … 2039 2259 @print_log_dec 2040 2260 def scale(self, factor, tsys=True, insitu=None): 2041 """ 2261 """\ 2262 2042 2263 Return a scan where all spectra are scaled by the give 'factor' 2043 Parameters: 2264 2265 Parameters: 2266 2044 2267 factor: the scaling factor (float or 1D float list) 2045 2268 insitu: if False a new scantable is returned. … … 2048 2271 tsys: if True (default) then apply the operation to Tsys 2049 2272 as well as the data 2273 2050 2274 """ 2051 2275 if insitu is None: insitu = rcParams['insitu'] … … 2071 2295 def set_sourcetype(self, match, matchtype="pattern", 2072 2296 sourcetype="reference"): 2073 """ 2297 """\ 2074 2298 Set the type of the source to be an source or reference scan 2075 using the provided pattern: 2076 Parameters: 2299 using the provided pattern. 2300 2301 Parameters: 2302 2077 2303 match: a Unix style pattern, regular expression or selector 2078 2304 matchtype: 'pattern' (default) UNIX style pattern or 2079 2305 'regex' regular expression 2080 2306 sourcetype: the type of the source to use (source/reference) 2307 2081 2308 """ 2082 2309 varlist = vars() … … 2107 2334 @print_log_dec 2108 2335 def auto_quotient(self, preserve=True, mode='paired', verify=False): 2109 """ 2336 """\ 2110 2337 This function allows to build quotients automatically. 2111 2338 It assumes the observation to have the same number of 2112 2339 "ons" and "offs" 2113 Parameters: 2340 2341 Parameters: 2342 2114 2343 preserve: you can preserve (default) the continuum or 2115 2344 remove it. The equations used are … … 2151 2380 @print_log_dec 2152 2381 def mx_quotient(self, mask = None, weight='median', preserve=True): 2153 """ 2382 """\ 2154 2383 Form a quotient using "off" beams when observing in "MX" mode. 2155 Parameters: 2384 2385 Parameters: 2386 2156 2387 mask: an optional mask to be used when weight == 'stddev' 2157 2388 weight: How to average the off beams. Default is 'median'. … … 2160 2391 preserve: Output = Toff * (on/off) - Toff 2161 2392 remove: Output = Toff * (on/off) - Ton 2393 2162 2394 """ 2163 2395 mask = mask or () … … 2174 2406 @print_log_dec 2175 2407 def freq_switch(self, insitu=None): 2176 """ 2408 """\ 2177 2409 Apply frequency switching to the data. 2178 Parameters: 2410 2411 Parameters: 2412 2179 2413 insitu: if False a new scantable is returned. 2180 2414 Otherwise, the swictching is done in-situ 2181 2415 The default is taken from .asaprc (False) 2182 Example: 2183 none 2416 2184 2417 """ 2185 2418 if insitu is None: insitu = rcParams['insitu'] … … 2194 2427 @print_log_dec 2195 2428 def recalc_azel(self): 2196 """ 2197 Recalculate the azimuth and elevation for each position. 2198 Parameters: 2199 none 2200 Example: 2201 """ 2429 """Recalculate the azimuth and elevation for each position.""" 2202 2430 varlist = vars() 2203 2431 self._recalcazel() … … 2271 2499 2272 2500 def get_fit(self, row=0): 2273 """ 2501 """\ 2274 2502 Print or return the stored fits for a row in the scantable 2275 Parameters: 2503 2504 Parameters: 2505 2276 2506 row: the row which the fit has been applied to. 2507 2277 2508 """ 2278 2509 if row > self.nrow(): … … 2289 2520 2290 2521 def flag_nans(self): 2291 """ 2522 """\ 2292 2523 Utility function to flag NaN values in the scantable. 2293 2524 """
Note:
See TracChangeset
for help on using the changeset viewer.