예제 #1
0
    def giveModel(self, ListPixParms):
        T = ClassTimeIt.ClassTimeIt("giveModel")
        T.disable()
        self.setSubDirty(ListPixParms)
        T.timeit("setsub")
        ModConstructor = ClassModModelMachine(self.GD)
        ModelMachine = ModConstructor.GiveMM(Mode=self.GD["Deconv"]["Mode"])
        #print "ModelMachine"
        #time.sleep(30)
        T.timeit("giveMM")
        self.ModelMachine = ModelMachine
        #self.ModelMachine.DicoSMStacked=self.DicoBasicModelMachine
        self.ModelMachine.setRefFreq(self.RefFreq, Force=True)
        self.ModelMachine.setFreqMachine(self.GridFreqs, self.DegridFreqs)
        self.MinorCycleConfig["ModelMachine"] = ModelMachine
        self.ModelMachine.setModelShape(self.SubDirty.shape)
        #self.ModelMachine.setListComponants(self.DeconvMachine.ModelMachine.ListScales)
        T.timeit("setlistcomp")

        self.DeconvMachine.Update(self.DicoSubDirty, DoSetMask=False)
        #self.DeconvMachine.updateMask(np.logical_not(self.SubMask))
        self.DeconvMachine.updateModelMachine(ModelMachine)
        #self.DeconvMachine.resetCounter()
        T.timeit("update")
        #print "update"
        #time.sleep(30)
        self.DeconvMachine.Deconvolve()
        T.timeit("deconv %s" % str(self.DicoSubDirty["ImageCube"].shape))
        #print "deconv"
        #time.sleep(30)

        ModelImage = self.ModelMachine.GiveModelImage()
        T.timeit("getmodel")

        # import pylab
        # pylab.clf()
        # pylab.subplot(2,2,1)
        # pylab.imshow(self.DicoDirty["MeanImage"][0,0,:,:],interpolation="nearest")
        # pylab.colorbar()
        # pylab.subplot(2,2,2)
        # pylab.imshow(self.DicoSubDirty["MeanImage"][0,0,:,:],interpolation="nearest")
        # pylab.colorbar()
        # pylab.subplot(2,2,3)
        # pylab.imshow(self.SubMask,interpolation="nearest")
        # pylab.colorbar()
        # pylab.subplot(2,2,4)
        # pylab.imshow(ModelImage[0,0],interpolation="nearest")
        # pylab.colorbar()
        # pylab.draw()
        # pylab.show(False)
        # pylab.pause(0.1)

        x, y = self.ArrayPixParms.T

        # PSF,MeanPSF=self.DeconvMachine.PSFServer.GivePSF()
        # ConvModel=ClassConvMachineImages(PSF).giveConvModel(ModelImage*np.ones((self.NFreqBands,1,1,1)))
        # #T.timeit("Conv1")
        # #print "done1"
        # #ConvModel=self.giveConvModel(ModelImage*np.ones((self.NFreqBands,1,1,1)))
        # # print "done2"
        # # T.timeit("Conv2")
        # # import pylab
        # # pylab.clf()
        # # pylab.subplot(1,3,1)
        # # pylab.imshow(ConvModel[0,0],interpolation="nearest")
        # # pylab.subplot(1,3,2)
        # # pylab.imshow(ConvModel1[0,0],interpolation="nearest")
        # # pylab.subplot(1,3,3)
        # # pylab.imshow((ConvModel-ConvModel1)[0,0],interpolation="nearest")
        # # pylab.colorbar()
        # # pylab.draw()
        # # pylab.show(False)
        # # stop

        # ModelOnes=np.zeros_like(ModelImage)
        # ModelOnes[:,:,x,y]=1
        # ConvModelOnes=ClassConvMachineImages(PSF).giveConvModel(ModelOnes*np.ones((self.NFreqBands,1,1,1)))

        # SumConvModel=np.sum(ConvModel[:,:,x,y])
        # SumConvModelOnes=np.sum(ConvModelOnes[:,:,x,y])
        # SumResid=np.sum(self.DeconvMachine._CubeDirty[:,:,x,y])

        # SumConvModel=np.max([SumConvModel,1e-6])

        # factor=(SumResid+SumConvModel)/SumConvModel

        # ###############
        #fMult=1.
        #if 1.<factor<2.:
        #    fMult=factor
        fMult = 1.
        SModel = ModelImage[0, 0, x, y] * fMult
        # ###########"
        # fMult=(np.mean(SumResid))/(np.mean(SumConvModelOnes))
        # SModel=ModelImage[0,0,x,y]+ModelOnes[0,0,x,y]*fMult
        # print fMult
        # print fMult
        # print fMult
        # print fMult
        # print fMult
        # print fMult
        # print fMult
        # ############

        AModel = self.ModelMachine.GiveSpectralIndexMap()[0, 0, x, y]
        T.timeit("spec index")

        return SModel, AModel
예제 #2
0
    def __init__(self,
                 GD,
                 ExternalModelMachine=None,
                 DegridFreqs=None,
                 GridFreqs=None,
                 MainCache=None):
        self.GD = copy.deepcopy(GD)

        self.MainCache = MainCache
        self.NoiseMap = None
        self.NoiseMapRestored = None
        self.NoiseMapReShape = None
        self._id_InputMap = None
        self.ExternalModelMachine = ExternalModelMachine
        self.DegridFreqs = DegridFreqs
        self.GridFreqs = GridFreqs
        self.NFreqBands = len(GridFreqs)

        # MyLogger.setSilent(ListSilentModules)
        self.RefFreq = ExternalModelMachine.RefFreq
        # self.GD["Parallel"]["NCPU"]=1
        # self.GD["HMP"]["Alpha"]=[0,0,1]#-1.,1.,5]
        self.GD["HMP"]["Alpha"] = [0, 0, 1]
        # self.GD["Deconv"]["Mode"]="HMP"
        # self.GD["Deconv"]["CycleFactor"]=0
        # self.GD["Deconv"]["PeakFactor"]=0.0
        self.GD["Deconv"]["PSFBox"] = "full"
        self.GD["Deconv"]["MaxMinorIter"] = 10000
        self.GD["Deconv"]["RMSFactor"] = 3.
        # self.GD["HMP"]["Scales"]=[0]
        self.GD["HMP"]["Ratios"] = []
        # self.GD["MultiScale"]["Ratios"]=[]
        self.GD["HMP"]["NTheta"] = 4

        # self.GD["Deconv"]["AllowNegative"]=False
        # self.GD["HMP"]["Scales"]=[0,1,2,4,8,16,32,48,64,96,128]
        # self.GD["HMP"]["SolverMode"]="NNLS"
        # self.GD["HMP"]["Support"]=91
        # self.GD["HMP"]["Taper"]=31
        # self.GD["Deconv"]["Gain"]=.3

        self.GD["HMP"]["SolverMode"] = "PI"
        self.GD["HMP"]["Scales"] = [0]
        self.GD["Deconv"]["Gain"] = .1

        if self.NoiseMapReShape is not None:
            print >> log, "Deconvolving on SNR map"
            self.GD["Deconv"]["RMSFactor"] = 0.

        self.GD["HMP"]["AllowResidIncrease"] = 0.1
        # self.GD["HMP"]["SolverMode"]="PI"
        MinorCycleConfig = dict(self.GD["Deconv"])
        MinorCycleConfig["NCPU"] = self.GD["Parallel"]["NCPU"]
        MinorCycleConfig["NFreqBands"] = self.NFreqBands
        MinorCycleConfig["RefFreq"] = self.RefFreq
        MinorCycleConfig["GD"] = self.GD
        # MinorCycleConfig["RefFreq"] = self.RefFreq
        # MinorCycleConfig["CleanMaskImage"]=None
        self.MinorCycleConfig = MinorCycleConfig
        if self.GD["Deconv"]["Mode"] in ["HMP", "SSD"]:
            # for SSD we need to set up the HMP ModelMachine.
            self.GD["Deconv"]["Mode"] = "HMP"
            ModConstructor = ClassModModelMachine(self.GD)
            self.ModelMachine = ModConstructor.GiveMM(
                Mode=self.GD["Deconv"]["Mode"])
            self.ModelMachine.setRefFreq(self.RefFreq)
            MinorCycleConfig["ModelMachine"] = self.ModelMachine
            self.MinorCycleConfig = MinorCycleConfig
            from DDFacet.Imager.MSMF import ClassImageDeconvMachineMSMF

            self.DeconvMachine = ClassImageDeconvMachineMSMF.ClassImageDeconvMachine(
                MainCache=self.MainCache,
                ParallelMode=True,
                CacheFileName="HMP_Masking",
                **self.MinorCycleConfig)
        elif self.GD["Deconv"]["Mode"] == "Hogbom":
            from DDFacet.Imager.HOGBOM import ClassImageDeconvMachineHogbom
            self.DeconvMachine = ClassImageDeconvMachineHogbom.ClassImageDeconvMachine(
                MainCache=self.MainCache,
                ParallelMode=True,
                CacheFileName="HMP_Masking",
                **self.MinorCycleConfig)
        else:
            raise NotImplementedError(
                "Mode %s not compatible with automasking" %
                self.GD["Deconv"]["Mode"])
예제 #3
0
    def __init__(self,
                 GD,
                 DicoVariablePSF,
                 RefFreq,
                 GridFreqs,
                 DegridFreqs,
                 MainCache=None,
                 IdSharedMem="",
                 DoWait=False):
        self.DicoVariablePSF = DicoVariablePSF
        GD = copy.deepcopy(GD)
        self.RefFreq = RefFreq
        self.GridFreqs = GridFreqs
        self.DegridFreqs = DegridFreqs
        self.GD = GD
        self.GD["Parallel"]["NCPU"] = 1
        #self.GD["HMP"]["Alpha"]=[0,0,1]#-1.,1.,5]
        self.GD["HMP"]["Alpha"] = [-1., 1., 5]
        self.GD["Deconv"]["Mode"] = "MORESANE"

        self.GD["Deconv"]["CycleFactor"] = 0
        self.GD["Deconv"]["PeakFactor"] = 0.0
        self.GD["Deconv"]["RMSFactor"] = self.GD["GAClean"]["RMSFactorInitHMP"]

        self.GD["Deconv"]["Gain"] = self.GD["GAClean"]["GainInitHMP"]
        self.GD["Deconv"]["AllowNegative"] = self.GD["GAClean"][
            "AllowNegativeInitHMP"]
        self.GD["Deconv"]["MaxMinorIter"] = self.GD["GAClean"][
            "MaxMinorIterInitHMP"]

        logger.setSilent(SilentModules)

        self.GD["HMP"]["Scales"] = self.GD["GAClean"]["ScalesInitHMP"]

        self.GD["HMP"]["Ratios"] = []
        #self.GD["MultiScale"]["Ratios"]=[]
        self.GD["HMP"]["NTheta"] = 4

        self.GD["HMP"]["SolverMode"] = "NNLS"
        #self.GD["MultiScale"]["SolverMode"]="PI"

        self.NFreqBands = len(DicoVariablePSF["freqs"])
        MinorCycleConfig = dict(self.GD["Deconv"])
        MinorCycleConfig["NCPU"] = self.GD["Parallel"]["NCPU"]
        MinorCycleConfig["NFreqBands"] = self.NFreqBands
        MinorCycleConfig["GD"] = self.GD
        MinorCycleConfig["GridFreqs"] = self.GridFreqs
        MinorCycleConfig["DegridFreqs"] = self.DegridFreqs

        #MinorCycleConfig["RefFreq"] = self.RefFreq

        ModConstructor = ClassModModelMachine(self.GD)
        ModelMachine = ModConstructor.GiveMM(Mode="MORESANE")
        ModelMachine.setRefFreq(self.RefFreq)
        MinorCycleConfig["ModelMachine"] = ModelMachine
        #MinorCycleConfig["CleanMaskImage"]=None
        self.MinorCycleConfig = MinorCycleConfig
        self.DeconvMachine = ClassImageDeconvMachineMoresane.ClassImageDeconvMachine(
            MainCache=MainCache,
            ParallelMode=False,
            RefFreq=self.RefFreq,
            CacheFileName="HMP_Init",
            IdSharedMem=IdSharedMem,
            **self.MinorCycleConfig)
        self.GD["Mask"]["Auto"] = False
        self.GD["Mask"]["External"] = None
        self.MaskMachine = ClassMaskMachine.ClassMaskMachine(self.GD)
        self.DeconvMachine.setMaskMachine(self.MaskMachine)

        self.Margin = 50

        #print "Start 3"
        self.DeconvMachine.Init(PSFVar=self.DicoVariablePSF,
                                PSFAve=self.DicoVariablePSF["PSFSideLobes"],
                                GridFreqs=self.GridFreqs,
                                DegridFreqs=self.DegridFreqs,
                                DoWait=DoWait,
                                RefFreq=self.RefFreq)

        if DoWait:
            print "IINit3"
            time.sleep(10)
            print "Start 4"

        self.DeconvMachine.Update(self.DicoDirty, DoSetMask=False)
        if DoWait:
            print "IINit4"
            time.sleep(10)
예제 #4
0
    def __init__(self,
                 GD,
                 NFreqBands,
                 RefFreq,
                 MainCache=None,
                 IdSharedMem=""):
        """Constructs initializer. 
        Note that this should be called pretty much when setting up the imager,
        before APP workers are started, because the object registers APP handlers.
        """
        self.GD = copy.deepcopy(GD)
        self.GD["Parallel"]["NCPU"] = 1
        # self.GD["HMP"]["Alpha"]=[0,0,1]#-1.,1.,5]
        self.GD["HMP"]["Alpha"] = self.GD["GAClean"]["AlphaInitHMP"]
        self.GD["Deconv"]["Mode"] = "HMP"
        self.GD["Deconv"]["CycleFactor"] = 0
        self.GD["Deconv"]["PeakFactor"] = 0.0
        self.GD["Deconv"]["RMSFactor"] = self.GD["GAClean"]["RMSFactorInitHMP"]
        self.GD["Deconv"]["Gain"] = self.GD["GAClean"]["GainInitHMP"]
        self.GD["Deconv"]["AllowNegative"] = self.GD["GAClean"][
            "AllowNegativeInitHMP"]
        self.GD["Deconv"]["MaxMinorIter"] = int(
            self.GD["GAClean"]["MaxMinorIterInitHMP"])

        self.GD["HMP"]["Scales"] = self.GD["GAClean"]["ScalesInitHMP"]

        self.GD["HMP"]["Ratios"] = self.GD["GAClean"]["RatiosInitHMP"]
        # self.GD["MultiScale"]["Ratios"]=[]
        self.GD["HMP"]["NTheta"] = self.GD["GAClean"]["NThetaInitHMP"]

        # print "!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
        # # self.GD["HMP"]["Scales"] = [0,1,2,4,8,16,24,32,48,64]
        # # self.GD["HMP"]["Taper"] = 32
        # # self.GD["HMP"]["Support"] = 32#self.GD["HMP"]["Scales"][-1]
        # self.GD["Deconv"]["RMSFactor"] = 1.
        # self.GD["Deconv"]["AllowNegative"] = True

        self.GD["HMP"]["SolverMode"] = "NNLS"
        # self.GD["MultiScale"]["SolverMode"]="PI"

        self.NFreqBands = NFreqBands
        self.RefFreq = RefFreq
        MinorCycleConfig = dict(self.GD["Deconv"])
        MinorCycleConfig["NCPU"] = self.GD["Parallel"]["NCPU"]
        MinorCycleConfig["NFreqBands"] = self.NFreqBands
        MinorCycleConfig["RefFreq"] = RefFreq

        ModConstructor = ClassModModelMachine(self.GD)
        ModelMachine = ModConstructor.GiveMM(Mode=self.GD["Deconv"]["Mode"])
        ModelMachine.setRefFreq(self.RefFreq)
        MinorCycleConfig["ModelMachine"] = ModelMachine

        self.MinorCycleConfig = MinorCycleConfig
        self.DeconvMachine = ClassImageDeconvMachineMSMF.ClassImageDeconvMachine(
            MainCache=MainCache,
            ParallelMode=True,
            CacheFileName="HMP_Init",
            IdSharedMem=IdSharedMem,
            GD=self.GD,
            **MinorCycleConfig)

        self.GD["Mask"]["Auto"] = False
        self.GD["Mask"]["External"] = None
        self.MaskMachine = ClassMaskMachine.ClassMaskMachine(self.GD)