Beispiel #1
0
    def run(self, *args, **kwargs):
        l_cov = pyrat.data.active
        outsize = pyrat.data.shape[-2:]

        # STEP0: Random initialisation
        l_init = self.layer_fromfunc(self.init_random, size=outsize, nclass=self.nclass)
        P = ProgressBar('  ' + self.name, self.niter)
        P.update(0)
        for iter in range(self.niter):
            # STEP1: Calculate cluster centres (and their frequency)
            pyrat.activate([l_cov, l_init], silent=True)
            cc, nc = self.layer_accumulate(self.calc_centers, nclass=self.nclass, combine=self.combine_mean)
            pyrat.delete(l_init, silent=True)

            # STEP2: Eliminate empty classes
            for k, n in enumerate(nc):
                if n == 0:
                    del cc[k]
                    del nc[k]

            # STEP3: Calculate class memberships
            pyrat.activate(l_cov, silent=True)
            l_init = self.layer_process(self.assign_classes, centers=cc)
            P.update(iter+1)
        del P
        pyrat.activate(l_init)
        return l_init
Beispiel #2
0
    def run(self, *args, **kwargs):
        l_cov = pyrat.data.active
        outsize = pyrat.data.shape[-2:]

        # STEP0: Random initialisation
        l_init = self.layer_fromfunc(self.init_random, size=outsize, nclass=self.nclass)
        P = ProgressBar('  ' + self.name, self.niter)
        P.update(0)
        for iter in range(self.niter):
            # STEP1: Calculate cluster centres (and their frequency)
            pyrat.activate([l_cov, l_init], silent=True)
            cc, nc = self.layer_accumulate(self.calc_centers, nclass=self.nclass, combine=self.combine_mean)
            pyrat.delete(l_init, silent=True)

            # STEP2: Eliminate empty classes
            for k, n in enumerate(nc):
                if n == 0:
                    del cc[k]
                    del nc[k]

            # STEP3: Calculate class memberships
            pyrat.activate(l_cov, silent=True)
            l_init = self.layer_process(self.assign_classes, centers=cc)
            P.update(iter + 1)
        del P
        pyrat.activate(l_init)
        return l_init
Beispiel #3
0
    def run(self, *args, **kwargs):
        layer = pyrat.data.active

        # STEP1: Estimate spectrum
        self.vblock = False
        rgspec = self.layer_accumulate(self.estimate_spectrum, axis='range', combine=self.combine_spectrum,
                                       silent=False)
        self.vblock = True
        azspec = self.layer_accumulate(self.estimate_spectrum, axis='azimuth', combine=self.combine_spectrum,
                                       silent=False)

        # STEP2: Adjust spectra
        rgcorr, rgcent = self.spec_correction(rgspec, alpha=self.alpha, fix=self.fix, cutoff=self.cutoff,
                                              func=(self.func, self.alpha))
        azcorr, azcent = self.spec_correction(azspec, alpha=self.alpha, fix=self.fix, cutoff=self.cutoff,
                                              func=(self.func, self.alpha))

        if self.center is False:
            azcent, rgcent = None, None

        # STEP3: Weight / Unweight
        if self.axis == 'range' or self.axis == 'both':
            self.vblock = False
            outlayer1 = self.layer_process(self.unweight_spectrum, axis='range', correction=(azcorr, rgcorr),
                                           center=(azcent, rgcent), silent=False)
        if self.axis == 'azimuth' or self.axis == 'both':
            self.vblock = True
            outlayer2 = self.layer_process(self.unweight_spectrum, axis='azimuth', correction=(azcorr, rgcorr),
                                           center=(azcent, rgcent),
                                           layer=outlayer1, silent=False)

        pyrat.delete(outlayer1)
        pyrat.activate(outlayer2)
        return outlayer2
Beispiel #4
0
    def run(self, *args, **kwargs):
        lay0 = pyrat.data.active

        # STEP1: Estimate spectra
        lay1 = pyrat.filter.unweight(layer=lay0, center=True, fix=True, cutoff=self.cutoff)
        lay2 = pyrat.filter.weight(layer=lay0, center=False, fix=False, func='Hamming', alpha=0.5, cutoff=self.cutoff)
        lay3 = self.layer_process(self.cda, layer=[lay1, lay2])

        pyrat.delete(lay1)
        pyrat.delete(lay2)
        pyrat.activate(lay3)
Beispiel #5
0
    def main(self, *args, **kwargs):
        """
        Main routine doing the (parallel) block processing, calling the (overloaded) filter method.
        Before the actual processing, pre() is called, as well as post() after completing it.
        """

        if self.checkinput():
            self.pre(*args, **kwargs)
            newlayer = self.layer_process(self.filter, silent=False, **kwargs)
            pyrat.data.activateLayer(newlayer)
            self.post(*args, **kwargs)

            if self.delete is True:
                pyrat.delete(self.input)
            return newlayer
        else:
            return False
Beispiel #6
0
 def run(self, *args, **kwargs):
     P = ProgressBar('  ' + self.name, self.iter)
     P.update(0)
     for k in range(self.iter):
         if k != 0:
             oldlayer = newlayer
         newlayer = self.layer_process(self.srad,
                                       looks=self.looks,
                                       step=self.step,
                                       iter=k,
                                       scale=self.scale,
                                       type=self.type)
         if k != 0:
             pyrat.delete(oldlayer, silent=True)
         pyrat.activate(newlayer, silent=True)
         P.update(k + 1)
     del P
     pyrat.activate(newlayer)
     return newlayer
Beispiel #7
0
    def run(self, *args, **kwargs):

        if isinstance(self.layer, list):  # Means the init layer is also active
            l_cov = self.layer[0]
            l_init = self.layer[1]
        else:
            l_cov = self.layer
            l_init = []
            outsize = pyrat.data.shape[-2:]

        meta = pyrat.getmeta(layer=l_cov)

        # STEP0: Do random initialisation if l_init is empty
        if len(l_init) == 0:
            l_init = self.layer_fromfunc(self.init_random,
                                         size=outsize,
                                         nclass=self.nclass)

        P = pyrat.tools.ProgressBar('  ' + self.name, self.niter)
        P.update(0)
        for iter in range(self.niter):
            # STEP1: Calculate cluster centres (and their frequency)
            pyrat.activate([l_cov, l_init], silent=True)
            cc, nc = self.layer_accumulate(self.calc_centers,
                                           nclass=self.nclass,
                                           combine=self.combine_mean)
            pyrat.delete(l_init, silent=True)

            # STEP2: Eliminate empty classes
            cc = [cc[k] for k, n in enumerate(nc) if n != 0]
            nc = [nc[k] for k, n in enumerate(nc) if n != 0]

            # STEP3: Calculate class memberships
            pyrat.activate(l_cov, silent=True)
            l_init = self.layer_process(self.assign_classes, centers=cc)
            P.update(iter + 1)
        del P
        meta['Class Centers'] = cc
        pyrat.setmeta(meta, layer=l_init)
        pyrat.activate(l_init)
        return l_init
Beispiel #8
0
    def run(self, *args, **kwargs):
        """
        Main routine doing the (parallel) block processing, calling the (overloaded) filter method.
        Before the actual processing, pre() is called, as well as post() after completing it.
        """
        try:
            para = [foo['var'] for foo in self.para]
            self.checkpara(kwargs, para)
            logging.info(self.name + '  ' + str(dict((k, v) for k, v in self.__dict__.items()
                                                     if k in para or k in kwargs)))
            if self.checkinput():
                self.pre(*args, **kwargs)
                newlayer = self.layer_process(self.filter, silent=False, **kwargs)
                pyrat.data.activateLayer(newlayer)
                self.post(*args, **kwargs)

                if self.delete is True:
                    pyrat.delete(self.input)
                return newlayer
            else:
                return False
        except Exception as ex:
            self.crash_handler(ex)