Example #1
0
    def set_basemask(self,masklist=[],invert=False):
        """
        Set initial channel mask.

        Parameters:
            masklist:  [[min, max], [min2, max2], ...]
                       A list of pairs of start/end points (inclusive)
                               specifying the regions to be masked
            invert:    optional argument. If specified as True,
                       return an inverted mask, i.e. the regions
                   specified are excluded
        You can reset the mask selection by running this method with
        the default parameters.
        """
        # Verify input parameters
        if not (isinstance(masklist, list) or isinstance(masklist, tuple)) \
           or not isinstance(invert, bool):
            msg = 'Invalid mask definition'
            raise TypeError(msg)

        # Create base mask
        if ( len(masklist) > 0 ):
            self.mask = self.scan.create_mask(masklist,invert=invert)
        elif invert == True:
            self.mask = _n_bools(self.scan.nchan(self.scan.getif(0)),False)
        else:
            self.mask = _n_bools(self.scan.nchan(self.scan.getif(0)),True)
Example #2
0
    def set_parameters(self, *args, **kwargs):
        """
        Set the parameters to be fitted.
        Parameters:
              params:    a vector of parameters
              fixed:     a vector of which parameters are to be held fixed
                         (default is none)
              component: in case of multiple gaussians/lorentzians/sinusoidals,
                         the index of the target component
        """
        component = None
        fixed = None
        params = None

        if len(args) and isinstance(args[0], dict):
            kwargs = args[0]
        if kwargs.has_key("fixed"):
            fixed = kwargs["fixed"]
        if kwargs.has_key("params"):
            params = kwargs["params"]
        if len(args) == 2 and isinstance(args[1], int):
            component = args[1]
        if self.fitfunc is None:
            msg = "Please specify a fitting function first."
            raise RuntimeError(msg)
        if (
            self.fitfunc == "gauss" or self.fitfunc == "lorentz" or self.fitfunc == "sinusoid"
        ) and component is not None:
            if not self.fitted and sum(self.fitter.getparameters()) == 0:
                pars = _n_bools(len(self.components) * 3, False)
                fxd = _n_bools(len(pars), False)
            else:
                pars = list(self.fitter.getparameters())
                fxd = list(self.fitter.getfixedparameters())
            i = 3 * component
            pars[i : i + 3] = params
            fxd[i : i + 3] = fixed
            params = pars
            fixed = fxd
        self.fitter.setparameters(params)
        if fixed is not None:
            self.fitter.setfixedparameters(fixed)
        return
Example #3
0
    def set_parameters(self, *args, **kwargs):
        """
        Set the parameters to be fitted.
        Parameters:
              params:    a vector of parameters
              fixed:     a vector of which parameters are to be held fixed
                         (default is none)
              component: in case of multiple gaussians/lorentzians/sinusoidals,
                         the index of the target component
        """
        component = None
        fixed = None
        params = None

        if len(args) and isinstance(args[0], dict):
            kwargs = args[0]
        if kwargs.has_key("fixed"): fixed = kwargs["fixed"]
        if kwargs.has_key("params"): params = kwargs["params"]
        if len(args) == 2 and isinstance(args[1], int):
            component = args[1]
        if self.fitfunc is None:
            msg = "Please specify a fitting function first."
            raise RuntimeError(msg)
        if (self.fitfunc == "gauss" or self.fitfunc == "lorentz"
                or self.fitfunc == "sinusoid") and component is not None:
            if not self.fitted and sum(self.fitter.getparameters()) == 0:
                pars = _n_bools(len(self.components) * 3, False)
                fxd = _n_bools(len(pars), False)
            else:
                pars = list(self.fitter.getparameters())
                fxd = list(self.fitter.getfixedparameters())
            i = 3 * component
            pars[i:i + 3] = params
            fxd[i:i + 3] = fixed
            params = pars
            fixed = fxd
        self.fitter.setparameters(params)
        if fixed is not None:
            self.fitter.setfixedparameters(fixed)
        return
Example #4
0
    def __init__(self,plotter=None, scan=None):
        """
        Create a interactive masking object.
        Either or both 'plotter' or/and 'scan' should be defined.

        Parameters:
           plotter: an ASAP plotter object for interactive selection
           scan: a scantable to create a mask interactively
        """
        # Return if GUI is not active
        if not rcParams['plotter.gui']:
            msg = 'GUI plotter is disabled.\n'
            msg += 'Exit interactive mode.'
            asaplog.push(msg)
            asaplog.post("ERROR")
            return
        # Verify input parameters
        if scan is None and plotter is None:
            msg = "Either scantable or plotter should be defined."
            raise TypeError(msg)

        self.scan = None
        self.p = None
        self.newplot = False
        if scan and isinstance(scan, scantable):
            self.scan = scan
        from asap.asapplotter import asapplotter
        if plotter and isinstance(plotter,asapplotter):
            self.p = plotter
            if self.scan is None and isinstance(self.p._data,scantable):
                self.scan = self.p._data
        if self.scan is None:
            msg = "Invalid scantable."
            raise TypeError(msg)

        self.mask = _n_bools(self.scan.nchan(self.scan.getif(0)),True)
        self.callback = None
        self.event = None
        self.once = False
        self.showmask = True
        self.rect = {}
        self.xold = None
        self.yold = None
        self.xdataold = None
        self.ydataold = None
        self._polygons = []
Example #5
0
 def _create_flag_from_array(self,x,masklist,invert):
     # Return True for channels which should be EXCLUDED (flag)
     if len(masklist) <= 1:
         asaplog.push()
         asaplog.post("masklist should be a list of 2 elements")
         asaplog.push("ERROR")
     n = len(x)
     # Base mask: flag out all channels
     mask = _n_bools(n, True)
     minval = min(masklist[0:2])
     maxval = max(masklist[0:2])
     for i in range(n):
         if minval <= x[i] <= maxval:
             mask[i] = False
     if invert:
         mask = mask_not(mask)
     return mask
Example #6
0
 def set_scan(self, thescan=None, mask=None):
     """
     Set the 'data' (a scantable) of the fitter.
     Parameters:
         thescan:     a scantable
         mask:        a msk retrieved from the scantable
     """
     if not thescan:
         msg = "Please give a correct scan"
         raise TypeError(msg)
     self.fitted = False
     self.data = thescan
     self.mask = None
     if mask is None:
         self.mask = _n_bools(self.data.nchan(), True)
     else:
         self.mask = mask
     return
Example #7
0
 def set_scan(self, thescan=None, mask=None):
     """
     Set the 'data' (a scantable) of the fitter.
     Parameters:
         thescan:     a scantable
         mask:        a msk retrieved from the scantable
     """
     if not thescan:
         msg = "Please give a correct scan"
         raise TypeError(msg)
     self.fitted = False
     self.data = thescan
     self.mask = None
     if mask is None:
         self.mask = _n_bools(self.data.nchan(), True)
     else:
         self.mask = mask
     return
Example #8
0
    def set_data(self, xdat, ydat, mask=None):
        """
        Set the absissa and ordinate for the fit. Also set the mask
        indicating valid points.
        This can be used for data vectors retrieved from a scantable.
        For scantable fitting use 'fitter.set_scan(scan, mask)'.
        Parameters:
            xdat:    the abcissa values
            ydat:    the ordinate values
            mask:    an optional mask

        """
        self.fitted = False
        self.x = xdat
        self.y = ydat
        if mask == None:
            self.mask = _n_bools(len(xdat), True)
        else:
            self.mask = mask
        return
Example #9
0
    def set_data(self, xdat, ydat, mask=None):
        """
        Set the absissa and ordinate for the fit. Also set the mask
        indicating valid points.
        This can be used for data vectors retrieved from a scantable.
        For scantable fitting use 'fitter.set_scan(scan, mask)'.
        Parameters:
            xdat:    the abcissa values
            ydat:    the ordinate values
            mask:    an optional mask

        """
        self.fitted = False
        self.x = xdat
        self.y = ydat
        if mask == None:
            self.mask = _n_bools(len(xdat), True)
        else:
            self.mask = mask
        return