Changeset 1845 for trunk/python


Ignore:
Timestamp:
08/04/10 12:36:57 (14 years ago)
Author:
Malte Marquarding
Message:

changed set_restfreqs to support use of the old behaviour. If list of float/int is given the items are applied one per IF. Also fixed some broken code for the other cases

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/python/scantable.py

    r1843 r1845  
    11961196            # set the given restfrequency for the all currently selected IFs
    11971197            scan.set_restfreqs(freqs=1.4e9)
    1198             # set multiple restfrequencies to all the selected data
     1198            # set restfrequencies for the n IFs  (n > 1) in the order of the
     1199            # list, i.e
     1200            # IF0 -> 1.4e9, IF1 ->  1.41e9, IF3 -> 1.42e9
     1201            # len(list_of_restfreqs) == nIF
     1202            # for nIF == 1 the following will set multiple restfrequency for
     1203            # that IF
    11991204            scan.set_restfreqs(freqs=[1.4e9, 1.41e9, 1.42e9])
    1200             # If the number of IFs in the data is >= 2 the IF0 gets the first
    1201             # value IF1 the second... NOTE that freqs needs to be
    1202             # specified in list of list (e.g. [[],[],...] ).
    1203             scan.set_restfreqs(freqs=[[1.4e9],[1.67e9]])
    1204             #set the given restfrequency for the whole table (by name)
    1205             scan.set_restfreqs(freqs="OH1667")
     1205            # set multiple restfrequencies per IF. as a list of lists where
     1206            # the outer list has nIF elements, the inner s arbitrary
     1207            scan.set_restfreqs(freqs=[[1.4e9, 1.41e9], [1.67e9]])
     1208
    12061209
    12071210        Note:
     
    12091212            source and IF basis, use scantable.set_selection() before using
    12101213            this function.
    1211             # provide your scantable is called scan
     1214            # provided your scantable is called scan
    12121215            selection = selector()
    12131216            selection.set_name("ORION*")
     
    12211224        # simple  value
    12221225        if isinstance(freqs, int) or isinstance(freqs, float):
    1223             # TT mod
    1224             #self._setrestfreqs(freqs, "",unit)
    1225             self._setrestfreqs([freqs], [""],unit)
     1226            self._setrestfreqs([freqs], [""], unit)
    12261227        # list of values
    12271228        elif isinstance(freqs, list) or isinstance(freqs, tuple):
    12281229            # list values are scalars
    12291230            if isinstance(freqs[-1], int) or isinstance(freqs[-1], float):
    1230                 self._setrestfreqs(freqs, [""], unit)
    1231             # list values are tuples, (value, name)
     1231                if len(freqs) == 1:
     1232                    self._setrestfreqs(freqs, [""], unit)
     1233                else:
     1234                    # allow the 'old' mode of setting mulitple IFs
     1235                    sel = selector()
     1236                    savesel = self._getselection()
     1237                    iflist = self.getifnos()
     1238                    if len(freqs)>len(iflist):
     1239                        raise ValueError("number of elements in list of list "
     1240                                         "exeeds the current IF selections")
     1241                    iflist = self.getifnos()
     1242                    for i, fval in enumerate(freqs):
     1243                        sel.set_ifs(iflist[i])
     1244                        self._setselection(sel)
     1245                        self._setrestfreqs([fval], [""], unit)
     1246                    self._setselection(savesel)
     1247
     1248            # list values are dict, {'value'=, 'name'=)
    12321249            elif isinstance(freqs[-1], dict):
    1233                 #sel = selector()
    1234                 #savesel = self._getselection()
    1235                 #iflist = self.getifnos()
    1236                 #for i in xrange(len(freqs)):
    1237                 #    sel.set_ifs(iflist[i])
    1238                 #    self._setselection(sel)
    1239                 #    self._setrestfreqs(freqs[i], "",unit)
    1240                 #self._setselection(savesel)
    1241                 self._setrestfreqs(freqs["value"],
    1242                                    freqs["name"], unit)
     1250                values = []
     1251                names = []
     1252                for d in freqs:
     1253                    values.append(d["value"])
     1254                    names.append(d["name"])
     1255                self._setrestfreqs(values, names, unit)
    12431256            elif isinstance(freqs[-1], list) or isinstance(freqs[-1], tuple):
    12441257                sel = selector()
     
    12461259                iflist = self.getifnos()
    12471260                if len(freqs)>len(iflist):
    1248                     raise ValueError("number of elements in list of list exeeds the current IF selections")
    1249                 for i in xrange(len(freqs)):
     1261                    raise ValueError("number of elements in list of list exeeds"
     1262                                     " the current IF selections")
     1263                for i, fval in enumerate(freqs):
    12501264                    sel.set_ifs(iflist[i])
    12511265                    self._setselection(sel)
    1252                     self._setrestfreqs(freqs[i], [""], unit)
     1266                    self._setrestfreqs(fval, [""], unit)
    12531267                self._setselection(savesel)
    12541268        # freqs are to be taken from a linecatalog
     
    12591273                sel.set_ifs(iflist[i])
    12601274                self._setselection(sel)
    1261                 self._setrestfreqs(freqs.get_frequency(i),
    1262                                    freqs.get_name(i), "MHz")
     1275                self._setrestfreqs([freqs.get_frequency(i)],
     1276                                   [freqs.get_name(i)], "MHz")
    12631277                # ensure that we are not iterating past nIF
    12641278                if i == self.nif()-1: break
Note: See TracChangeset for help on using the changeset viewer.