Example #1
0
    def __set_mask(self):
        self.msk = None
        if self.interactive:
            # Interactive masking
            self.msk = sdutil.interactive_mask(self.scan,
                                               self.masklist,
                                               False,
                                               purpose='to calculate statistics')
            msks = self.scan.get_masklist(self.msk)
            if len(msks) < 1:
                raise Exception, 'No channel is selected. Exit without calculation.'
            lbl=self.scan.get_unit()
            casalog.post( 'final mask list ('+lbl+') = '+str(msks) )

            del msks

        # set the mask region
        elif ( len(self.masklist) > 0 and self.masklist!=[[]]):
            self.msk=self.scan.create_mask(self.masklist,invert=False)
            msks=self.scan.get_masklist(self.msk)
            if len(msks) < 1:
                del self.msk, msks
                raise Exception, 'Selected mask lists are out of range. Exit without calculation.'
            del msks
        else:
            # Full region
            casalog.post( 'Using full region' )
Example #2
0
    def execute(self):
        scan = self.worker.scan
        self.__init_blfile()

        nrow = scan.nrow()

        # parse string masklist
        maskdict = scan.parse_spw_selection(self.spw)
        valid_spw_list = []
        for (k,v) in maskdict.items():
            if len(v) > 0 and numpy.all(numpy.array(map(len, v)) > 0):
                valid_spw_list.append(k)
        
        basesel = scan.get_selection()

        # configure baseline function and its parameters
        self.__configure_baseline()
        
        for ifno in valid_spw_list:
            lmask = maskdict[ifno]
            sif = str(ifno)
            if len(sif) > 0:
                sel = sd.selector(basesel)
                sel.set_ifs([int(sif)])
                scan.set_selection(sel)
                del sel
                msg = "Working on IF%s" % (sif)
                casalog.post(msg)
                if (self.maskmode == 'interact'): print "===%s===" % (msg)
                del msg

            msk = None

            if (self.maskmode == 'interact'):
                msk = sdutil.interactive_mask(scan, lmask, False, purpose='to baseline spectra')
                msks = scan.get_masklist(msk)
                if len(msks) < 1:
                    msg = 'No channel is selected. Exit without baselining.'
                    casalog.post(msg, priorigy='SEVERE')
                    raise Exception(msg)

                casalog.post( 'final mask list ('+scan._getabcissalabel()+') ='+str(msks) )
                #header += "   Fit Range: "+str(msks)+"\n"
                del msks
            else:
                # Use baseline mask for regions to INCLUDE in baseline fit
                # Create mask using list, e.g. masklist=[[500,3500],[5000,7500]]
                if (len(lmask) > 0): msk = scan.create_mask(lmask)

            # register IF dependent mask
            self.params['mask'] = msk

            # call target baseline function with appropriate parameter set
            baseline_func = getattr(scan, self.funcname)
            baseline_func(**self.params)

            # reset selection
            if len(sif) > 0: scan.set_selection(basesel)

        ifs_org = basesel.get_ifs()
        ifs_new = list(set(ifs_org) & set(valid_spw_list))
        basesel.set_ifs(ifs_new)
        scan.set_selection(basesel)