Functions | |
def | update_spw |
def | spwchan_to_ranges |
def | spwchan_to_sets |
def | set_to_chanstr |
def | sets_to_spwchan |
def | update_spwchan |
def | expand_tilde |
def | spw_to_dict |
def | join_spws |
def | intersect_spws |
def | subtract_spws |
def update_spw.expand_tilde | ( | tstr, | |
conv_multiranges = False |
|||
) |
Expands a string like '8~11' to [8, 9, 10, 11]. Returns '*' if tstr is ''! conv_multiranges: If True, '*' will be returned if tstr contains ';'. (split can't yet handle multiple channel ranges per spw.) Examples: >>> from update_spw import expand_tilde >>> expand_tilde('8~11') [8, 9, 10, 11] >>> expand_tilde(None) '*' >>> expand_tilde('3~7^2;9~11') [3, 5, 7, 9, 10, 11] >>> expand_tilde('3~7^2;9~11', True) '*'
Definition at line 463 of file update_spw.py.
References tests.test_imcontsub.list.
Referenced by spw_to_dict().
def update_spw.intersect_spws | ( | spw1, | |
spw2 | |||
) |
Almost the opposite of join_spws(), this returns the list of spws that the spw:chan selection strings spw1 and spw2 have in common. Unlike join_spws(), channel ranges are ignored. '' in the input counts as 'select everything', so the intersection of '' with anything is anything. If the intersection really is everything, '' is returned instead of a set. Examples: >>> from update_spw import intersect_spws >>> intersect_spws('0~2:3~5,3:9~13', '') set([0, 1, 2, 3]) >>> intersect_spws('0~2:3~5,3:9~13', '0~2:7~9,5') set([0, 1, 2]) >>> intersect_spws('0~2:3~5;10~13,3:9~13', '0~2:7~9,5') set([0, 1, 2]) >>> intersect_spws('0~2:3~5,3:9~13', '10~12:7~9,5') # Empty set set([]) >>> intersect_spws('', '') # Everything ''
Definition at line 650 of file update_spw.py.
References asap.asapmath.keys, and spw_to_dict().
def update_spw.join_spws | ( | spw1, | |
spw2, | |||
span_semicolon = True |
|||
) |
Returns the union of spw selection strings spw1 and spw2. span_semicolon (default True): If True, for any spws that have > 1 channel range, the entire spw will be selected. Examples: >>> from update_spw import join_spws >>> join_spws('0~2:3~5,3:9~13', '') '' >>> join_spws('0~2:3~5,3:9~13', '1~3:4~7') '0:3~5,1~2:3~7,3' >>> join_spws('1~10:5~122,15~22:5~122', '1~10:5~122,15~22:5~122') '1~10:5~122,15~22:5~122' >>> join_spws('', '') '' >>> join_spws('1~10:5~122,15~22:5~122', '0~21') '0~21,22:5~122'
Definition at line 591 of file update_spw.py.
References set_to_chanstr(), and spw_to_dict().
Referenced by task_uvcontsub.uvcontsub(), task_uvcontsub2.uvcontsub2(), and task_uvcontsub3.uvcontsub3().
def update_spw.set_to_chanstr | ( | chanset, | |
totnchan = None |
|||
) |
Essentially the reverse of expand_tilde. Given a set or list of integers chanset, returns the corresponding string form. It will not use non-unity steps (^) if multiple ranges (;) are necessary, but it will use ^ if it helps to eliminate any ;s. totnchan: the total number of channels for the input spectral window, used to abbreviate the return string. It returns '' for the empty set and '*' if Examples: >>> from update_spw import set_to_chanstr >>> set_to_chanstr(set([0, 1, 2, 4, 5, 6, 7, 9, 11, 13])) '0~2;4~7;9;11;13' >>> set_to_chanstr(set([7, 9, 11, 13])) '7~13^2' >>> set_to_chanstr(set([7, 9])) '7~9^2' >>> set_to_chanstr([0, 1, 2]) '0~2' >>> set_to_chanstr([0, 1, 2], 3) '*' >>> set_to_chanstr([0, 1, 2, 6], 3) '*' >>> set_to_chanstr([0, 1, 2, 6]) '0~2;6' >>> set_to_chanstr([1, 2, 4, 5, 6, 7, 8, 9, 10, 11], 12) '1~2;4~11'
Definition at line 229 of file update_spw.py.
References tests.test_imcontsub.list.
Referenced by join_spws(), and sets_to_spwchan().
def update_spw.sets_to_spwchan | ( | spwsets, | |
nchans = {} |
|||
) |
Returns a spw:chan selection string for a dict of sets of selected channels keyed by spectral window ID. nchans is a dict of the total number of channels keyed by spw, used to abbreviate the return string. Examples: >>> from update_spw import sets_to_spwchan >>> # Use nchans to get '1' instead of '1:0~3'. >>> sets_to_spwchan({1: [0, 1, 2, 3]}, {1: 4}) '1' >>> sets_to_spwchan({1: set([1, 2, 3, 5, 7, 9]), 8: set([0])}) '1:1~3;5;7;9,8:0' >>> sets_to_spwchan({0: set([4, 5, 6]), 1: [4, 5, 6], 2: [4, 5, 6]}) '0~2:4~6' >>> sets_to_spwchan({0: [4], 1: [4], 3: [0, 1], 4: [0, 1], 7: [0, 1]}, {3: 2, 4: 2, 7: 2}) '0~1:4,3~4,7'
Definition at line 303 of file update_spw.py.
References nf_regression.append, and set_to_chanstr().
Referenced by update_spwchan().
def update_spw.spw_to_dict | ( | spw, | |
spwdict = {} , |
|||
conv_multiranges = True |
|||
) |
Expand an spw:chan string to {s0: [s0chans], s1: [s1chans, ...], ...} where s0, s1, ... are integers for _each_ selected spw, and s0chans is a set of selected chans (as integers) for s0. '' instead of a channel set means that all of the channels are selected. The spw:chan dict is unioned with spwdict. Returning an empty dict means everything should be selected (i.e. spw = ''). (split can't yet handle multiple channel ranges per spw.) conv_multiranges: If True, any spw with > 1 channel range selected will have ALL of its channels selected. (split can't yet handle multiple channel ranges per spw.) Examples: >>> from update_spw import spw_to_dict >>> spw_to_dict('', {}) {} >>> spw_to_dict('6~8:2~5', {})[6] set([2, 3, 4, 5]) >>> spw_to_dict('6~8:2~5', {})[8] set([2, 3, 4, 5]) >>> spw_to_dict('6~8:2~5', {6: ''})[6] '' >>> spw_to_dict('6~8:2~5', {6: '', 7: set([1, 7])})[7] set([1, 2, 3, 4, 5, 7]) >>> spw_to_dict('7', {6: '', 7: set([1, 7])})[7] '' >>> spw_to_dict('7:123~127;233~267', {6: '', 7: set([1, 7])})[7] # Multiple chan ranges '' >>> spw_to_dict('5,7:123~127;233~267', {6: '', 7: set([1, 7])})[5] '' >>> spw_to_dict('5:3~5,7:123~127;233~267', {6: '', 7: set([1, 7])})[5] set([3, 4, 5])
Definition at line 507 of file update_spw.py.
References expand_tilde().
Referenced by intersect_spws(), join_spws(), spwchan_to_sets(), and subtract_spws().
def update_spw.spwchan_to_ranges | ( | vis, | |
spw | |||
) |
Returns the spw:chan selection string spw as a dict of channel selection ranges for vis, keyed by spectral window ID. The ranges are stored as tuples of (start channel, end channel (inclusive!), step). Note that '' returns an empty set! Use '*' to select everything! Example: >>> from update_spw import spwchan_to_ranges >>> selranges = spwchan_to_ranges('uid___A002_X1acc4e_X1e7.ms', '7:10~20^2;40~55') ValueError: spwchan_to_ranges() does not support multiple channel ranges per spw. >>> selranges = spwchan_to_ranges('uid___A002_X1acc4e_X1e7.ms', '0~1:1~3,5;7:10~20^2') >>> selranges {0: (1, 3, 1), 1: (1, 3, 1), 5: (10, 20, 2), 7: (10, 20, 2)}
Definition at line 141 of file update_spw.py.
def update_spw.spwchan_to_sets | ( | vis, | |
spw | |||
) |
Returns the spw:chan selection string spw as a dict of sets of selected channels for vis, keyed by spectral window ID. Note that '' returns an empty set! Use '*' to select everything! Example (16.ms has spws 0 and 1 with 16 chans each): >>> from update_spw import spwchan_to_sets >>> vis = casa['dirs']['data'] + '/regression/unittest/split/unordered_polspw.ms' >>> spwchan_to_sets(vis, '0:0') {0: set([0])} >>> selsets = spwchan_to_sets(vis, '1:1~3;5~9^2,9') # 9 is a bogus spw. >>> selsets {1: [1, 2, 3, 5, 7, 9]} >>> spwchan_to_sets(vis, '1:1~3;5~9^2,8') {1: set([1, 2, 3, 5, 7, 9]), 8: set([0])} >>> spwchan_to_sets(vis, '') {}
Definition at line 169 of file update_spw.py.
References spw_to_dict().
Referenced by update_spwchan().
def update_spw.subtract_spws | ( | spw1, | |
spw2 | |||
) |
Returns the set of spws of spw selection string spw1 that are not in spw2. Like intersect_spws(), this intentionally ignores channel ranges. It assumes that spw1 and spw2 refer to the same MS (this only matters for ''). subtract_spws('', '0~5') is a tough case: it is impossible to know whether '' is equivalent to '0~5' without reading the MS's SPECTRAL_WINDOW subtable, so it returns 'UNKNOWN'. Examples: >>> from update_spw import subtract_spws >>> subtract_spws('0~2:3~5,3:9~13', '') # Anything - Everything set([]) >>> subtract_spws('0~2:3~5,3:9~13', '0~2:7~9,5') set([3]) >>> subtract_spws('', '0~2:7~9,5') # Everything - Something 'UNKNOWN' >>> subtract_spws('0~2,3:9~13', '4~7:7') # Something - Something Else set([0, 1, 2, 3]) >>> subtract_spws('', '') # Everything - Everything set([])
Definition at line 683 of file update_spw.py.
References asap.asapmath.keys, and spw_to_dict().
Referenced by task_uvcontsub.uvcontsub(), task_uvcontsub2.uvcontsub2(), and task_uvcontsub3.uvcontsub3().
def update_spw.update_spw | ( | spw, | |
spwmap = None |
|||
) |
Given an spw:chan selection string, return what it should be after the spws have been remapped (i.e. by split), and a map from input to output spws (spwmap). It does not change spw OR the *channels* part of the output spw string! (See update_spwchan) If given, spwmap will be used as a dictionary from (string) input spw to (string) output spws. Otherwise it will be freshly calculated. Supplying spwmap doesn't just save work: it is also necessary for chaining update_spw() calls when the first selection includes more spws than the subsequent one(s). HOWEVER, if given, spwmap must have slots for all the spws that will appear in the output MS, i.e. it can't be grown once made. Examples: >>> from update_spw import update_spw >>> myfitspw, spws = update_spw('0~3,5;6:1~7;11~13', None) >>> myfitspw '0~3,4;5:1~7;11~13' >>> myspw = update_spw('1,5;6:8~10', spws)[0] >>> myspw # not '0,1,2:8~10' '1,4;5:8~10' >>> update_spw('0~3,5;6:1~7;11~13,7~9:0~3,11,7~8:6~8', None)[0] '0~3,4;5:1~7;11~13,6~8:0~3,9,6~7:6~8' # Let's say we want updates of both fitspw and spw, but fitspw and spw # are disjoint (in spws). >>> fitspw = '1~10:5~122,15~22:5~122' >>> spw = '6~14' # Initialize spwmap with the union of them. >>> spwmap = update_spw(join_spws(fitspw, spw), None)[1] >>> myfitspw = update_spw(fitspw, spwmap)[0] >>> myfitspw '0~9:5~122,14~21:5~122' >>> myspw = update_spw(spw, spwmap)[0] >>> myspw '5~13' >>> myspw = update_spw('0,1,3;5~8:20~30;44~50^2', None)[0] >>> myspw '0,1,2;3~6:20~30;44~50^2'
Definition at line 24 of file update_spw.py.
def update_spw.update_spwchan | ( | vis, | |
sch0, | |||
sch1, | |||
truncate = False , |
|||
widths = {} |
|||
) |
Given an spw:chan selection string sch1, return what it must be changed to to get the same result if used with the output of split(vis, spw=sch0). '' is taken to mean '*' in the input but NOT the output! For the output '' means sch0 and sch1 do not intersect. truncate: If True and sch0 only partially overlaps sch1, return the update of the intersection. If (False and sch0 does not cover sch1), OR there is no intersection, raises a ValueError. widths is a dictionary of averaging widths (default 1) for each spw. Examples: >>> from update_spw import update_spwchan >>> newspw = update_spwchan('anything.ms', 'anything', 'anything') >>> newspw '*' >>> vis = casa['dirs']['data'] + '/regression/unittest/split/unordered_polspw.ms' >>> update_spwchan(vis, '0~1:1~3,5;7:10~20^2', '0~1:2~3,5;7:12~18^2') '0~1:1~2,2~3:1~4' >>> update_spwchan(vis, '7', '3') ValueError: '3' is not a subset of '7'. >>> update_spwchan(vis, '7:10~20^2', '7:12~18^3') ValueError: '7:12~18^3' is not a subset of '7:10~20^2'. >>> update_spwchan(vis, '7:10~20^2', '7:12~18^3', truncate=True) '0:1~4^3' >>> update_spwchan(vis, '7:10~20^2', '7:12~18^3', truncate=True, widths={7: 2}) '0:0~2^2'
Definition at line 368 of file update_spw.py.
References tests.test_imcontsub.list, sets_to_spwchan(), and spwchan_to_sets().
Referenced by task_split.split_core(), task_uvcontsub.uvcontsub(), task_uvcontsub2.uvcontsub2(), and task_uvcontsub3.uvcontsub3().