- Timestamp:
- 07/31/12 15:51:18 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/python/scantable.py
r2610 r2611 1490 1490 if not isinstance(maskstring,str): 1491 1491 asaplog.post() 1492 asaplog.push(" Invalid mask expression")1492 asaplog.push("Mask expression should be a string.") 1493 1493 asaplog.post("ERROR") 1494 1494 … … 1498 1498 if maskstring == "": 1499 1499 maskstring = str(valid_ifs)[1:-1] 1500 ## split each selection 1500 ## split each selection "IF range[:CHAN range]" 1501 1501 sellist = maskstring.split(',') 1502 1502 for currselstr in sellist: … … 1504 1504 # spw and mask string (may include ~, < or >) 1505 1505 spwmasklist = self._parse_selection(selset[0], typestr='integer', 1506 offset=1,minval=min(valid_ifs),1506 minval=min(valid_ifs), 1507 1507 maxval=max(valid_ifs)) 1508 1508 for spwlist in spwmasklist: … … 1602 1602 return seldict 1603 1603 1604 @asaplog_post_dec 1605 def parse_idx_selection(self, mode, selexpr): 1606 """ 1607 Parse CASA type mask selection syntax of SCANNO, IFNO, POLNO, 1608 BEAMNO, and row number 1609 1610 Parameters: 1611 mode : which column to select. 1612 ['scan',|'if'|'pol'|'beam'|'row'] 1613 selexpr : A comma separated selection expression. 1614 examples: 1615 '' = all (returns []) 1616 '<2,4~6,9' = indices less than 2, 4 to 6 and 9 1617 (returns [0,1,4,5,6,9]) 1618 Returns: 1619 A List of selected indices 1620 """ 1621 if selexpr == "": 1622 return [] 1623 valid_modes = {'s': 'scan', 'i': 'if', 'p': 'pol', 1624 'b': 'beam', 'r': 'row'} 1625 smode = mode.lower()[0] 1626 if not (smode in valid_modes.keys()): 1627 msg = "Invalid mode '%s'. Valid modes are %s" %\ 1628 (mode, str(valid_modes.values())) 1629 asaplog.post() 1630 asaplog.push(msg) 1631 asaplog.post("ERROR") 1632 mode = valid_modes[smode] 1633 minidx = None 1634 maxidx = None 1635 if smode == 'r': 1636 minidx = 0 1637 maxidx = self.nrow() 1638 else: 1639 idx = getattr(self,"get"+mode+"nos")() 1640 minidx = min(idx) 1641 maxidx = max(idx) 1642 del idx 1643 sellist = selexpr.split(',') 1644 idxlist = [] 1645 for currselstr in sellist: 1646 # single range (may include ~, < or >) 1647 currlist = self._parse_selection(currselstr, typestr='integer', 1648 minval=minidx,maxval=maxidx) 1649 for thelist in currlist: 1650 idxlist += range(thelist[0],thelist[1]+1) 1651 msg = "Selected %s: %s" % (mode.upper()+"NO", str(idxlist)) 1652 asaplog.push(msg) 1653 return idxlist 1654 1604 1655 def _parse_selection(self, selstr, typestr='float', offset=0., 1605 1656 minval=None, maxval=None): … … 1611 1662 offset : The offset value to subtract from or add to 1612 1663 the boundary value if the selection string 1613 includes '<' or '>' 1664 includes '<' or '>' [Valid only for typestr='float'] 1614 1665 minval, maxval : The minimum/maximum values to set if the 1615 1666 selection string includes '<' or '>'. … … 1618 1669 A list of min/max pair of selections. 1619 1670 Example: 1620 _parseSelection('<3;5~7;9',typestr='int',offset=1,minval=0) 1621 returns [[0,2],[5,7],[9,9]] 1671 _parse_selection('<3;5~7;9',typestr='int',minval=0) 1672 --> returns [[0,2],[5,7],[9,9]] 1673 _parse_selection('<3;5~7;9',typestr='float',offset=0.5,minval=0) 1674 --> returns [[0.,2.5],[5.0,7.0],[9.,9.]] 1622 1675 """ 1623 1676 selgroups = selstr.split(';') … … 1625 1678 if typestr.lower().startswith('int'): 1626 1679 formatfunc = int 1680 offset = 1 1627 1681 else: 1628 1682 formatfunc = float … … 1630 1684 for currsel in selgroups: 1631 1685 if currsel.find('~') > 0: 1686 # val0 <= x <= val1 1632 1687 minsel = formatfunc(currsel.split('~')[0].strip()) 1633 1688 maxsel = formatfunc(currsel.split('~')[1].strip()) 1634 elif currsel.strip().startswith('<'): 1635 minsel = minval 1636 maxsel = formatfunc(currsel.split('<')[1].strip()) \ 1637 - formatfunc(offset) 1638 elif currsel.strip().startswith('>'): 1639 minsel = formatfunc(currsel.split('>')[1].strip()) \ 1689 elif currsel.strip().find('<=') > -1: 1690 bound = currsel.split('<=') 1691 try: # try "x <= val" 1692 minsel = minval 1693 maxsel = formatfunc(bound[1].strip()) 1694 except ValueError: # now "val <= x" 1695 minsel = formatfunc(bound[0].strip()) 1696 maxsel = maxval 1697 elif currsel.strip().find('>=') > -1: 1698 bound = currsel.split('>=') 1699 try: # try "x >= val" 1700 minsel = formatfunc(bound[1].strip()) 1701 maxsel = maxval 1702 except ValueError: # now "val >= x" 1703 minsel = minval 1704 maxsel = formatfunc(bound[0].strip()) 1705 elif currsel.strip().find('<') > -1: 1706 bound = currsel.split('<') 1707 try: # try "x < val" 1708 minsel = minval 1709 maxsel = formatfunc(bound[1].strip()) \ 1710 - formatfunc(offset) 1711 except ValueError: # now "val < x" 1712 minsel = formatfunc(bound[0].strip()) \ 1640 1713 + formatfunc(offset) 1641 maxsel = maxval 1714 maxsel = maxval 1715 elif currsel.strip().find('>') > -1: 1716 bound = currsel.split('>') 1717 try: # try "x > val" 1718 minsel = formatfunc(bound[1].strip()) \ 1719 + formatfunc(offset) 1720 maxsel = maxval 1721 except ValueError: # now "val > x" 1722 minsel = minval 1723 maxsel = formatfunc(bound[0].strip()) \ 1724 - formatfunc(offset) 1642 1725 else: 1643 1726 minsel = formatfunc(currsel)
Note:
See TracChangeset
for help on using the changeset viewer.