Changeset 1576 for trunk


Ignore:
Timestamp:
06/29/09 13:40:55 (15 years ago)
Author:
Malte Marquarding
Message:

Ticket #169: allow direct settings of selections

Location:
trunk/python
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/python/scantable.py

    r1574 r1576  
    312312        return selector(self._getselection())
    313313
    314     def set_selection(self, selection=selector()):
     314    def set_selection(self, selection=None, **kw):
    315315        """
    316316        Select a subset of the data. All following operations on this scantable
     
    325325            scan.set_selection()     # unset the selection
    326326        """
     327        if selection is None:
     328            # reset
     329            if len(kw) == 0:
     330                selection = selector()
     331            else:
     332                # try keywords
     333                for k in kw:
     334                    if k not in selector.fields:
     335                        raise KeyError("Invalid selection key '%s', valid keys are %s" % (k, selector.fields))
     336                selection = selector(**kw)
    327337        self._setselection(selection)
    328338
  • trunk/python/selector.py

    r1542 r1576  
    77    scantables to specific rows.
    88    """
    9     def __init(self):
    10         _selector.__init__(self)
     9    fields = ["pols", "ifs", "beams", "scans", "cycles", "name", "query"]
     10
     11    def __init__(self, *args, **kw):
     12        if len(args) == 1:
     13            if isinstance(args[0], self.__class__) \
     14               or isinstance(args[0], _selector):
     15                _selector.__init__(self, args[0])
     16            else:
     17                raise TypeError("Argument can only be a selector object")
     18        else:
     19            _selector.__init__(self)
     20            for k,v  in kw.items():
     21                if k in self.fields:
     22                    func = getattr(self, "set_%s" % k)
     23                    func(v)
    1124
    1225    def reset(self):
     
    4558        else:
    4659            raise TypeError('Unknown pol type. Please use [0,1...] or ["XX","YY"...]')
    47    
     60
    4861    # for the americans
    4962    set_polarizations = set_polarisations
Note: See TracChangeset for help on using the changeset viewer.