Changeset 907 for trunk/python


Ignore:
Timestamp:
03/20/06 15:17:06 (18 years ago)
Author:
vor010
Message:

LineFinder? & auto_poly_baseline: a support of
new scantable format has been added. Now findLines accept a mask and edge
parameters, which can therefore be different for different rows. Constructor
need now just a scan table. Boost types removed from STLineFinder. auto_poly_baseline can accept a nested tuple of edges, which would be interpreted as
different edge parameters for different IFs

Location:
trunk/python
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/python/asaplinefind.py

    r889 r907  
    77    Example:
    88       fl=linefinder()
    9        fl.set_scan(sc,edge=(50,))
     9       fl.set_scan(sc)
    1010       fl.set_options(threshold=3)
    11        nlines=fl.find_lines()
     11       nlines=fl.find_lines(edge=(50,0))
    1212       if nlines!=0:
    1313          print "Found ",nlines," spectral lines"
     
    6565        return
    6666
    67     def set_scan(self, scan, mask=None, edge=(0,0)):
     67    def set_scan(self, scan):
    6868        """
    6969        Set the 'data' (scantable) to work with.
    7070        Parameters:
    7171             scan:    a scantable
    72              mask:       an optional mask retreived from scantable
    73              edge:       an optional number of channel to drop at
    74                          the edge of spectrum. If only one value is
     72        """
     73        if not scan:
     74           raise RuntimeError, 'Please give a correct scan'
     75        return
     76    def find_lines(self,nRow=0,mask=None,edge=(0,0)):
     77        """
     78        Search for spectral lines in the scan assigned in set_scan.
     79        Parameters:
     80             nRow:       a row in the scantable to work with
     81             mask:       an optional mask (e.g. retreived from scantable)
     82             edge:       an optional number of channels to drop at
     83                         the edge of the spectrum. If only one value is
    7584                         specified, the same number will be dropped from
    7685                         both sides of the spectrum. Default is to keep
    7786                         all channels
     87        A number of lines found will be returned
    7888        """
    79         if not scan:
    80            raise RuntimeError, 'Please give a correct scan'
    81         if not scan._check_ifs():
    82            raise RuntimeError, 'IFs with different numbers of channels are not yet supported'
    83 
    8489        if isinstance(edge,int):
    8590           edge=(edge,)
     
    96101        if mask is None:
    97102            from numarray import ones
    98             self.finder.setscan(scan,ones(scan.nchan(-1)),tuple(edge))
     103            return self.finder.findlines(ones(scan.nchan(nRow)),list(edge),nRow)
    99104        else:
    100             self.finder.setscan(scan,mask,tuple(edge))
    101         return
    102     def find_lines(self,nRow=0):
    103         """
    104         Search for spectral lines in the scan assigned in set_scan.
    105         Current Beam/IF/Pol is used, Row is specified by parameter
    106         A number of lines found will be returned
    107         """
    108         return self.finder.findlines(nRow)
     105            return self.finder.setscan(mask,list(edge),nRow)
    109106    def get_mask(self,invert=False):
    110107        """
  • trunk/python/scantable.py

    r889 r907  
    10331033                        specified, the same number will be dropped from
    10341034                        both sides of the spectrum. Default is to keep
    1035                         all channels
     1035                        all channels. Nested tuples represent individual
     1036                        edge selection for different IFs (a number of spectral
     1037                        channels can be different)
    10361038            order:      the order of the polynomial (default is 0)
    10371039            threshold:  the threshold used by line finder. It is better to
     
    10511053        from asap import _is_sequence_or_number as _is_valid
    10521054
    1053         if not _is_valid(edge, int):
     1055        # check whether edge is set up for each IF individually
     1056        individualEdge = False;
     1057        if len(edge)>1:
     1058           if isinstance(edge[0],list) or isinstance(edge[0],tuple):
     1059           individualEdge = True;
     1060
     1061        if not _is_valid(edge, int) and not individualEdge:
    10541062            raise RuntimeError, "Parameter 'edge' has to be an integer or a \
    1055             pair of integers specified as a tuple"
     1063            pair of integers specified as a tuple. Nested tuples are allowed \
     1064            to make individual selection for different IFs."
     1065       
     1066        curedge = (0,0)
     1067        if individualEdge:
     1068           for edge_par in edge:
     1069               if not _is_valid(edge,int):
     1070                  raise RuntimeError, "Each element of the 'edge' tuple has \
     1071                  to be a pair of integers or an integer."
     1072        else:
     1073           curedge = edge;
    10561074
    10571075        # setup fitter
     
    10671085        else:
    10681086            workscan=self
     1087
     1088        fl.set_scan(workscan)
    10691089
    10701090        rows=range(workscan.nrow())
     
    10741094            msg = " Scan[%d] Beam[%d] IF[%d] Pol[%d] Cycle[%d]" %        (workscan.getscan(r),workscan.getbeam(r),workscan.getif(r),workscan.getpol(r), workscan.getcycle(r))
    10751095            asaplog.push(msg, False)
    1076             fl.set_scan(workscan, mask, edge)
    1077             fl.find_lines(r)
     1096
     1097            # figure out edge parameter
     1098            if individualEdge:
     1099               if len(edge)>=workscan.getif(r):
     1100                  raise RuntimeError, "Number of edge elements appear to be less than the number of IFs"
     1101                  curedge = edge[workscan.getif(r)]
     1102           
     1103            # setup line finder
     1104            fl.find_lines(r,mask,curedge)
    10781105            f.set_scan(workscan, fl.get_mask())
    10791106            f.x = workscan._getabcissa(r)
Note: See TracChangeset for help on using the changeset viewer.