示例#1
0
def test():

    DType = np.complex128
    nx = 10
    nyA = 2
    A = DType(np.random.randn(nyA, nx) + 1j * np.random.randn(nyA, nx))
    nyB = 3
    B = DType(np.random.randn(nyB, nx) + 1j * np.random.randn(nyB, nx))

    #A.fill(1)
    #B.fill(1)

    # A=A.T.copy()
    # B=B.T.copy()

    C = np.zeros((nyA, nyB), DType)

    print("===================================")
    print("A", A)
    print("B", B)
    if DType == np.complex64:
        IntType = 0
    if DType == np.complex128:
        IntType = 1

    print("==========")
    dotSSE.dot(A, B, C, IntType)

    print("==========")
    D = np.dot(A, B.T)
    print(C - D)

    #A=np.complex64(np.random.rand(2000,100)+1j*np.random.rand(2000,100))
    A = np.complex64(np.ones((50000, 100)))
    B = A.copy()
    #C=np.zeros_like(A)

    N = 10
    T = ClassTimeIt.ClassTimeIt()
    for i in range(N):
        AA = np.dot(A.T, B)
        print(AA.shape)
        T.timeit("numpy")

    A = A.T.copy()
    B = B.T.copy()
    T = ClassTimeIt.ClassTimeIt()
    for i in range(N):

        #dotSSE.dot(A,B,C)
        C = NpDotSSE.dot_A_BT(A, B)
        print(C.shape)
        T.timeit("sse")
示例#2
0
    def CalcKapa_i_new(self,yr,Pa,rms):
        kapaout=0
        T=ClassTimeIt.ClassTimeIt("    Kapa")
        T.disable()
        iT=0
        for ipol in range(self.NJacobBlocks_X):
            J=self.LJacob[ipol]
            PaPol=self.GivePaPol(Pa,ipol)
            pa=np.abs(np.diag(PaPol))
            pa=pa.reshape(1,pa.size)
            T.timeit(iT); iT+=1
            nrow,_=J.shape
            flags=(self.DicoData["flags_flat"][ipol]==0)
            T.timeit(iT); iT+=1

            Weigths=self.Weights_flat[ipol].reshape((nrow,1))
            T.timeit(iT); iT+=1

            Jw=Weigths*J
            JP=Jw*pa
            T.timeit(iT); iT+=1

            trJPJH=np.sum(np.abs(JP[flags]*Jw[flags].conj()))
            T.timeit(iT); iT+=1

            YYH=np.abs(yr[ipol,flags])**2

            T.timeit(iT); iT+=1
            # Np=np.where(self.DicoData["flags_flat"]==0)[0].size
            # Take=(self.DicoData["flags_flat"]==0)
            
            T.timeit(iT); iT+=1
            R=(self.R_flat[ipol][flags])#Np*rms**2
            
            ww=(Weigths[flags]).ravel()
            
            trYYH_R=np.sum(ww**2*(YYH-R))
            T.timeit(iT); iT+=1
            kapa=np.abs(trYYH_R/trJPJH)
            #kapa=1
            kapaout+=np.sqrt(kapa)
            #if self.iAnt==0:
            #    print("new",self.iAnt,rms,np.sqrt(kapa),trYYH_R,trJPJH,pa)
        kapaout=np.max([1.,kapaout])

        return kapaout
示例#3
0
def SharedObjectToDico(SObject):
    if SObject == None: return None
    Prefix = SObject.prefixName
    Fields = SObject.DicoKeys
    log.print(ModColor.Str("SharedToDico: start [prefix = %s]" % Prefix))
    T = ClassTimeIt.ClassTimeIt("   SharedToDico")
    T.disable()

    DicoOut = {}
    T.timeit("1")
    for field in Fields:
        Sharedkey = "%s.%s" % (Prefix, field)
        #log.print( ModColor.Str("  %s -> %s"%(Sharedkey,key)))
        Shared = GiveArray(Sharedkey)
        DicoOut[field] = Shared
    T.timeit("2a")
    log.print(ModColor.Str("SharedToDico: done"))

    return DicoOut
示例#4
0
def SharedToDico(Prefix):
    log.print(ModColor.Str("SharedToDico: start [prefix = %s]" % Prefix))
    T = ClassTimeIt.ClassTimeIt("   SharedToDico")
    T.disable()
    Lnames = ListNames()
    T.timeit("0: ListNames")
    keys = [Name for Name in Lnames if Prefix in Name]
    if len(keys) == 0: return None
    DicoOut = {}
    T.timeit("1")
    for Sharedkey in keys:
        key = Sharedkey.split(".")[-1]
        log.print(ModColor.Str("  %s -> %s" % (Sharedkey, key)))
        Shared = GiveArray(Sharedkey)
        DicoOut[key] = Shared
    T.timeit("2a")
    log.print(ModColor.Str("SharedToDico: done"))

    return DicoOut
示例#5
0
文件: NpCuda.py 项目: saopicc/killMS
def Test():

    A = np.float32(np.random.randn(*(2000, 2000)))
    A = np.complex64(np.ones((2000, 2000)) + 1j * np.ones((2000, 2000)))
    AT = A.T.copy()

    A_32 = A  #np.float32(A)
    AT_32 = AT  #np.float32(AT)

    T = ClassTimeIt.ClassTimeIt()
    # create two random matrices and copy them to the GPU
    g_A0 = cm.CUDAMatrix(A)
    g_AT0 = cm.CUDAMatrix(AT)

    # perform calculations on the GPU
    P0 = cm.dot(g_AT0, g_A0).asarray()
    #d = cm.sum(axis = 0)
    T.timeit("GPU0")
    del (g_AT0, g_A0)
    #T.reinit()

    # copy d back to the host (CPU) and print

    g_A1 = gpuarray.to_gpu(A)
    g_AT1 = gpuarray.to_gpu(AT)
    #time.sleep(5)

    #T.timeit("tranf0")
    g_P1 = culinalg.dot(g_AT1, g_A1)

    P1 = g_P1.get()

    #T.timeit("tranf1")
    T.timeit("GPU1")

    np_P = np.dot(AT, A)
    T.timeit("np")
    #print g_P-np_P

    print(np.max(np_P - P0))
    print(np.max(np_P - P1))
示例#6
0
    def doEKFStep(self,Gains,P,evP,rms,Gains0Iter=None):
        T=ClassTimeIt.ClassTimeIt("    EKF")
        T.disable()
        if not(self.HasKernelMatrix):
            self.CalcKernelMatrix(rms)
            self.SelectChannelKernelMat()
            T.timeit("CalcKernelMatrix")

        # print(self.iAnt,"MMMM",np.max(Gains),np.max(P),np.max(evP))
        # print(self.iAnt,"MMMM",np.max(Gains),np.max(P),np.max(evP))
        # print(self.iAnt,"MMMM",np.max(Gains),np.max(P),np.max(evP))

            
        z=self.DicoData["data_flat"]#self.GiveDataVec()

        f=(self.DicoData["flags_flat"]==0)
        ind=np.where(f)[0]
        Pa=P[self.iAnt]
        Ga=self.GiveSubVecGainAnt(Gains)
        self.Ga=Ga
        self.rms=rms

        #if self.iAnt==1:
        #    print(evP.ravel())
        self.rmsFromData=None
        if ind.size==0 or self.DataAllFlagged or self.ZeroSizedData:
            return Ga.reshape((self.NDir,self.NJacobBlocks_X,self.NJacobBlocks_Y)),Pa,{"std":-1.,"max":-1.,"kapa":-1.},0
        
        if self.DoReg:
            self.setQxInvPol()
        
        self.CalcJacobianAntenna(Gains)
        T.timeit("Jacob")
        
        # if Gains0Iter!=None:
        #     Ga=self.GiveSubVecGainAnt(Gains0Iter)

        Jx=self.J_x(Ga)
        T.timeit("J_x")

        

        self.PrepareJHJ_EKF(Pa,rms)
        T.timeit("PrepareJHJ")

        # estimate x
        zr=(z-Jx)
        zr[self.DicoData["flags_flat"]]=0
        
        T.timeit("Resid")
        
        kapa=self.CalcKapa_i(zr,Pa,rms)
        
        # try:
        #     kapa=self.CalcKapa_i_new(zr,Pa,rms)
        #     self.DicoData["Ga"]=Ga
        #     self.DicoData["zr"]=zr
        #     self.DicoData["rms"]=rms
        #     self.DicoData["KernelMat_AllChan"]=self.KernelMat_AllChan
        #     #killMS.Other.MyPickle.Save(self.DicoData,"DicoData_%i.pickle"%self.iAnt)
        #     #print(np.array([1])/0)
        # except:
        #     self.DicoData["Ga"]=Ga
        #     self.DicoData["zr"]=zr
        #     self.DicoData["rms"]=rms
        #     self.DicoData["Pa"]=Pa
        #     self.DicoData["KernelMat_AllChan"]=self.KernelMat_AllChan
        #     killMS.Other.MyPickle.Save(self.DicoData,"DicoData_crash_%i.pickle"%self.iAnt)
        #     stop

        # Weighted std estimate 
        zrs=zr[f]
        ws=np.absolute(self.DicoData["Rinv_flat"][f])
        std=np.sqrt(np.sum(ws*np.absolute(zrs)**2)/np.sum(ws))

        # # Original std estimate 
        # std=np.std(zr[f])


        InfoNoise={"std":std,"max":np.max(np.abs(zr[f])),"kapa":kapa}
        #print(self.iAnt,InfoNoise)
        #T.timeit("kapa")

        self.rmsFromData=np.std(zr[f])
        T.timeit("rmsFromData")

        # if np.isnan(self.rmsFromData):
        #     print(zr)
        #     print(zr[f])
        #     print(self.rmsFromData)
        #     stop

        # if self.iAnt==51:
        #     #self.DicoData["flags_flat"].fill(0)
        #     f=(self.DicoData["flags_flat"]==0)
        #     fig=pylab.figure(2)
        #     pylab.clf()
        #     pylab.plot((z[f]))#[::11])#[::11])
        #     pylab.plot((Jx[f]))#[::11])#[::11])

        #     #pylab.plot(zr[f])#[::11])#[::11])
        #     #pylab.draw()
        #     ifile=0
        #     while True:
        #         fname="png/png.%5.5i.png"%ifile
        #         if os.path.isfile(fname) :
        #             fig.savefig(fname)
        #             break
        #         ifile+=1
                
                
        #     #pylab.show(False)
        #     #pylab.pause(0.1)
        #     #stop


        x3=self.ApplyK_vec(zr,rms,Pa)
        
        T.timeit("ApplyK_vec")
        x0=Ga.flatten()
        x4=x0+self.LambdaKF*x3.flatten()

        # estimate P

        #Pa_new1=Pa-np.dot(evPa,Pa)
        evPa=evP[self.iAnt]
        Pa_new1=np.dot(evPa,Pa)
        #Pa_new1=Pa


        T.timeit("EstimateP")
        # ##################
        # for iPar in range(Pa.shape[0]):
        #     J_Px=self.J_x(Pa[iPar,:])
        #     xP=self.ApplyK_vec(J_Px,rms,Pa)
        #     evPa[iPar,:]=xP.flatten()
        # evPa= Pa-evPa
        # Pa_new1=evPa

        del(self.LJacob)
        T.timeit("Rest")
        
        # if self.iAnt==0:
        #     print(x4,Pa_new1,InfoNoise,evPa,Pa)

        # if np.max(np.abs(x4))>10:
        #     self.DicoData["Ga"]=Ga
        #     self.DicoData["Jx"]=Jx
        #     self.DicoData["zr"]=zr
        #     self.DicoData["rms"]=rms
        #     self.DicoData["Pa"]=Pa
        #     self.DicoData["x4"]=x4
        #     self.DicoData["ch0ch1"]=(self.ch0,self.ch1)
        #     self.DicoData["KernelMat_AllChan"]=self.KernelMat_AllChan
        #     killMS.Other.MyPickle.Save(self.DicoData,"DicoData_diverge_%i.pickle"%self.iAnt)
        #     stop

        return x4.reshape((self.NDir,self.NJacobBlocks_X,self.NJacobBlocks_Y)),Pa_new1,InfoNoise,1
示例#7
0
文件: ClassMS.py 项目: saopicc/killMS
    def ReadMSInfo(self, MSname, DoPrint=True):
        T = ClassTimeIt.ClassTimeIt()
        T.enableIncr()
        T.disable()
        #print(MSname+'/ANTENNA')

        # open main table
        table_all = table(MSname, ack=False)

        #print(MSname+'/ANTENNA')
        ta = table(table_all.getkeyword('ANTENNA'), ack=False)
        #ta=table(MSname+'::ANTENNA',ack=False)

        StationNames = ta.getcol('NAME')

        na = ta.getcol('POSITION').shape[0]
        self.StationPos = ta.getcol('POSITION')
        #nbl=(na*(na-1))/2+na

        A0, A1 = table_all.getcol("ANTENNA1"), table_all.getcol("ANTENNA2")
        ind = np.where(A0 == A1)[0]
        self.HasAutoCorr = (ind.size > 0)
        A = np.concatenate([A0, A1])

        nas = np.unique(A).size
        self.nbl = (nas**2 - nas) // 2
        if self.HasAutoCorr:
            self.nbl += nas
        if A0.size % self.nbl != 0:
            log.print(ModColor.Str("MS is non conformant!"))
            raise

        #nbl=(na*(na-1))/2
        ta.close()
        T.timeit()

        #table_all=table(MSname,ack=False)
        self.ColNames = table_all.colnames()
        TimeIntervals = table_all.getcol("INTERVAL")
        SPW = table_all.getcol('DATA_DESC_ID')
        if self.SelectSPW != None:
            self.ListSPW = self.SelectSPW
            #print("dosel")
        else:
            self.ListSPW = sorted(list(set(SPW.tolist())))
        T.timeit()

        self.F_nrows = table_all.getcol("TIME").shape[0]
        F_time_all = table_all.getcol("TIME")[SPW == self.ListSPW[0]]

        self.F_A0 = table_all.getcol("ANTENNA1")[SPW == self.ListSPW[0]]
        self.F_A1 = table_all.getcol("ANTENNA2")[SPW == self.ListSPW[0]]

        #nbl=(np.where(F_time_all==F_time_all[0])[0]).shape[0]
        T.timeit()

        F_time_slots_all = np.array(sorted(list(set(F_time_all.tolist()))))
        F_ntimes = F_time_slots_all.shape[0]

        T.timeit()

        ta_spectral = table(table_all.getkeyword('SPECTRAL_WINDOW'), ack=False)
        reffreq = ta_spectral.getcol('REF_FREQUENCY')
        chan_freq = ta_spectral.getcol('CHAN_FREQ')
        self.NChanOrig = chan_freq.size
        chan_freq = chan_freq[:, self.ChanSlice]
        self.dFreq = ta_spectral.getcol("CHAN_WIDTH").flatten()[self.ChanSlice]
        self.ChanWidth = ta_spectral.getcol('CHAN_WIDTH')[:, self.ChanSlice]
        if chan_freq.shape[0] > len(self.ListSPW):
            print(
                ModColor.Str(
                    "  ====================== >> More SPW in headers, modifying that error...."
                ))
            chan_freq = chan_freq[np.array(self.ListSPW), :]
            reffreq = reffreq[np.array(self.ListSPW)]

        T.timeit()

        wavelength = 299792456. / reffreq
        NSPW = chan_freq.shape[0]
        self.ChanFreq = chan_freq
        self.Freq_Mean = np.mean(chan_freq)
        wavelength_chan = 299792456. / chan_freq

        if NSPW > 1:
            print("Don't deal with multiple SPW yet")

        Nchan = wavelength_chan.shape[1]
        NSPWChan = NSPW * Nchan
        ta = table(table_all.getkeyword('FIELD'), ack=False)
        rarad, decrad = ta.getcol('PHASE_DIR')[self.Field][0]
        if rarad < 0.: rarad += 2. * np.pi

        T.timeit()

        radeg = rarad * 180. / np.pi
        decdeg = decrad * 180. / np.pi
        ta.close()

        self.DoRevertChans = False
        if Nchan > 1:
            self.DoRevertChans = (self.ChanFreq.flatten()[0] >
                                  self.ChanFreq.flatten()[-1])
        if self.DoRevertChans:
            log.print(
                ModColor.Str(
                    "  ====================== >> Revert Channel order!"))
            wavelength_chan = wavelength_chan[0, ::-1]
            self.ChanFreq = self.ChanFreq[0, ::-1]
            self.ChanWidth = -self.ChanWidth[0, ::-1]
            self.dFreq = np.abs(self.dFreq)

        T.timeit()

        MS_STOKES_ENUMS = [
            "Undefined", "I", "Q", "U", "V", "RR", "RL", "LR", "LL", "XX",
            "XY", "YX", "YY", "RX", "RY", "LX", "LY", "XR", "XL", "YR", "YL",
            "PP", "PQ", "QP", "QQ", "RCircular", "LCircular", "Linear",
            "Ptotal", "Plinear", "PFtotal", "PFlinear", "Pangle"
        ]
        tp = table(table_all.getkeyword('POLARIZATION'), ack=False)
        # get list of corrype enums for first row of polarization table, and convert to strings via MS_STOKES_ENUMS.
        # self.CorrelationNames will be a list of strings
        self.CorrelationIds = tp.getcol('CORR_TYPE', 0, 1)[0]
        self.CorrelationNames = [(ctype >= 0 and ctype < len(MS_STOKES_ENUMS)
                                  and MS_STOKES_ENUMS[ctype]) or None
                                 for ctype in self.CorrelationIds]
        self.Ncorr = len(self.CorrelationNames)
        # NB: it is possible for the MS to have different polarization

        table_all.close()

        self.na = na
        self.Nchan = Nchan
        self.NSPW = NSPW
        self.NSPWChan = NSPWChan
        self.F_tstart = F_time_all[0]
        self.F_times_all = F_time_all
        self.F_times = F_time_slots_all
        self.F_ntimes = F_time_slots_all.shape[0]

        self.dt = TimeIntervals[0]
        self.DTs = F_time_all[-1] - F_time_all[0] + self.dt
        self.DTh = self.DTs / 3600.

        self.radec = self.OriginalRadec = (rarad, decrad)
        self.rarad = rarad
        self.decrad = decrad
        self.reffreq = reffreq
        self.StationNames = StationNames
        self.wavelength_chan = wavelength_chan
        self.rac = rarad
        self.decc = decrad
        #self.nbl=nbl
        self.StrRA = rad2hmsdms(self.rarad, Type="ra").replace(" ", ":")
        self.StrDEC = rad2hmsdms(self.decrad, Type="dec").replace(" ", ".")

        if self.ToRADEC is not None:
            ranew, decnew = rarad, decrad
            # get RA/Dec from first MS, or else parse as coordinate string
            if self.ToRADEC == "align":
                stop
                if first_ms is not None:
                    ranew, decnew = first_ms.rarad, first_ms.decrad
                which = "the common phase centre"
            else:
                which = "%s %s" % tuple(self.ToRADEC)
                SRa, SDec = self.ToRADEC
                srah, sram, sras = SRa.split(":")
                sdecd, sdecm, sdecs = SDec.split(":")
                ranew = (np.pi / 180) * 15. * (
                    float(srah) + float(sram) / 60. + float(sras) / 3600.)
                decnew = (np.pi / 180) * np.sign(float(sdecd)) * (abs(
                    float(sdecd)) + float(sdecm) / 60. + float(sdecs) / 3600.)
            # only enable rotation if coordinates actually change
            if ranew != rarad or decnew != decrad:
                print(ModColor.Str("MS %s will be rephased to %s" %
                                   (self.MSName, which)),
                      file=log)
                self.OldRadec = rarad, decrad
                self.NewRadec = ranew, decnew
                rarad, decrad = ranew, decnew
            else:
                self.ToRADEC = None

        T.timeit()
示例#8
0
    def doLMStep(self,Gains):
        # if self.iAnt==55:
        #     print(self.iAnt,Gains)
        T=ClassTimeIt.ClassTimeIt("doLMStep")
        T.disable()

        #Gains.fill(1.)
        
#         A=np.random.randn(10000,100)+1j*np.random.randn(10000,100)
#         B=np.random.randn(10000,100)+1j*np.random.randn(10000,100)
#         AT=A.T#.conj().copy()
# #        AT=A.T
#         # A=np.require(A,requirements='F_CONTIGUOUS')
#         # AT=np.require(AT,requirements='F_CONTIGUOUS')
#         # A=np.require(A,requirements='F')
#         # AT=np.require(AT,requirements='F')


#         T=ClassTimeIt.ClassTimeIt("doLMStep")
#         for i in range(20):
#             np.dot(AT,B)

#         T.timeit("%i"%i)

        
        if not(self.HasKernelMatrix):
            self.CalcKernelMatrix()
            self.SelectChannelKernelMat()
            T.timeit("CalcKernelMatrix")

        Ga=self.GiveSubVecGainAnt(Gains)


        if self.DoCompress:
            flags_key="flags_flat_avg"
            data_key="data_flat_avg"
            if self.DoMergeStations:
                flags_key="flags_flat_avg_merged"
                data_key="data_flat_avg_merged"
        else:
            flags_key="flags_flat"
            data_key="data_flat"
            
        f=(self.DicoData[flags_key]==0)
        
        # ind=np.where(f)[0]
        # if self.iAnt==56:
        #     print ind.size/float(f.size),np.abs(Gains[self.iAnt,0,0,0])

        
        if self.DataAllFlagged:
            return Ga.reshape((self.NDir,self.NJacobBlocks_X,self.NJacobBlocks_Y)),None,{"std":-1.,"max":-1.,"kapa":None}



        # if ind.size==0:
        #     return Ga.reshape((self.NDir,self.NJacobBlocks_X,self.NJacobBlocks_Y)),None,{"std":-1.,"max":-1.,"kapa":None}


        z=self.DicoData[data_key]#self.GiveDataVec()
        

        self.CalcJacobianAntenna(Gains)
        T.timeit("CalcJacobianAntenna")
        self.PrepareJHJ_LM()
        T.timeit("PrepareJHJ_L")



        T.timeit("GiveSubVecGainAnt")
        Jx=self.J_x(Ga)
        T.timeit("Jx")
        zr=z-Jx

        zr[self.DicoData[flags_key]]=0
        T.timeit("resid")

        # JH_z_0=np.load("LM.npz")["JH_z"]
        # x1_0=np.load("LM.npz")["x1"]
        # z_0=np.load("LM.npz")["z"]
        # Jx_0=np.load("LM.npz")["Jx"]




        InfoNoise={"std":np.std(zr[f]),"max":np.max(np.abs(zr[f])),"kapa":None}


        JH_z=self.JH_z(zr)
        T.timeit("JH_z")
        #self.JHJinv=ModLinAlg.invSVD(self.JHJ)
        #self.JHJinv=np.linalg.inv(self.JHJ)
        xi=Ga.flatten()
        T.timeit("self.JHJinv_x")
        

        if self.DoTikhonov:
            self.LambdaTkNorm
            Gi=xi.reshape((self.NDir,self.NJacobBlocks_X,self.NJacobBlocks_Y))
            JH_z=JH_z.reshape((self.NDir,self.NJacobBlocks_X,self.NJacobBlocks_Y))
            for polIndex in range(self.NJacobBlocks_X):
                gireg=Gi[:,polIndex,:]
                #gi=JH_z[:,polIndex,:]
                x0reg=self.X0[:,polIndex,:]
                Linv=(self.Linv[:,polIndex,:])
                JH_z[:,polIndex,:]-=self.LambdaTkNorm*Linv*(gireg-x0reg)
        dx = (1./(1.+self.LambdaLM)) * self.JHJinv_x(JH_z)

        
        
        # #print self.iAnt
        # if True:#self.iAnt==55:
        #     f=(self.DicoData[flags_key]==0)
        #     import pylab
        #     fig=pylab.figure(1)
        #     op0=np.abs
        #     op1=np.real
        #     pylab.clf()
        #     pylab.subplot(1,3,1)
        #     #pylab.plot(op0(z[f])[::1]**2)#[::11])
        #     pylab.plot( op1( z[f])[::1] )#[::11])
        #     #pylab.ylim(0,800)
        #     pylab.subplot(1,3,2)
        #     #pylab.plot(op0(Jx[f])[::1]**2)#[::11])
        #     pylab.plot( op1(Jx[f])[::1] )#[::11])
        #     #pylab.ylim(0,800)
        #     pylab.subplot(1,3,3)
        #     #pylab.plot(op0(zr[f])[::1])#[::11])
        #     pylab.plot( op1(zr[f])[::1] )#[::11])
        #     #pylab.ylim(-30,30)
        #     pylab.draw()
        #     pylab.show(block=False)
        #     pylab.pause(0.1)
            
        #     # iF=0
        #     # while True:
        #     #     fName="Graph_%i_%i.png"%(self.iAnt,iF)
        #     #     import os
        #     #     if not os.path.isfile(fName):
        #     #         break
        #     #     else:
        #     #         iF+=1
        #     # fig.savefig(fName)
            


        # # pylab.figure(2)
        # # pylab.clf()
        # # #pylab.plot((z)[::11])
        # # #pylab.plot((Jx-Jx_0)[::11])
        # # #pylab.plot(zr[::11])
        # # #pylab.plot(JH_z.flatten())
        # # #pylab.plot(JH_z_0.flatten())
        # # pylab.plot(x1.flatten())
        # # pylab.plot(x1_0.flatten())
        # # pylab.draw()
        # # pylab.show(False)
        # # pylab.pause(0.1)

        # stop
        # # np.savez("LM",JH_z=JH_z,x1=x1,z=z,Jx=Jx)
 
        # print JH_z.shape

        dx+=xi
        del(self.LJacob)
        T.timeit("rest")
        # print self.iAnt,np.mean(x1),x1.size,ind.size
        
        xout=dx.reshape((self.NDir,self.NJacobBlocks_X,self.NJacobBlocks_Y))
        # print self.iAnt,xout.ravel()
        return xout,None,InfoNoise
示例#9
0
    def AverageKernelMatrix(self, DicoData, K):
        T = ClassTimeIt.ClassTimeIt("AverageKernelMatrix")
        T.disable()
        #A0,A1=DicoData[""]
        A0 = DicoData["A0"]
        A1 = DicoData["A1"]

        NDir, Np, Npol = K.shape

        NpBlBlocks = DicoData["NpBlBlocks"][0]
        A0A1 = sorted(list(set([(A0[i], A1[i]) for i in range(A0.size)])))

        NpOut = len(A0A1)
        NDirAvg = self.SM_Compress.NDir
        KOut = np.zeros((NDir, NDirAvg, NpOut, Npol), K.dtype)
        KOut0 = np.zeros((NDir, NDirAvg, NpOut, Npol), K.dtype)

        IndList = [(np.where((A0 == ThisA0) & (A1 == ThisA1))[0])
                   for (ThisA0, ThisA1) in A0A1]

        f = DicoData["flags"]
        fp = f[:, :, 0, 0].copy()
        T.timeit("stuff")

        Labels = np.zeros((Np, Npol), np.int64)
        for iBl, ind in enumerate(IndList):
            Labels[ind, :] = iBl

        for iDirAvg in range(NDirAvg):
            K_Compress = self.PM_Compress.predictKernelPolCluster(
                DicoData, self.SM_Compress, iDirection=iDirAvg)
            T.timeit("K_Compress")
            k_rephase = K_Compress[:, :, 0].conj()

            for iDir in range(NDir):
                p = K[iDir, :, :]  #.copy()
                w = np.ones(p.shape, np.float64)
                w[p == 0] = 0.
                w[fp] = 0.
                #p[fp]=0.

                #w.fill(1.)
                #print("!!")
                pp = w * p * k_rephase
                #pp.fill(1)
                #sw=

                Sr = scipy.ndimage.sum(pp.real,
                                       labels=Labels,
                                       index=np.arange(len(IndList)))
                Si = scipy.ndimage.sum(pp.imag,
                                       labels=Labels,
                                       index=np.arange(len(IndList)))
                Sw = scipy.ndimage.sum(w,
                                       labels=Labels,
                                       index=np.arange(len(IndList)))

                ind0 = np.where(Sw > 0)[0]
                if ind0.size == 0: continue
                KOut0[iDir, iDirAvg, ind0, 0] = (Sr + 1j * Si)[ind0] / Sw[ind0]

                #if Sw.min()>0: stop

                # for iBl,ind in enumerate(IndList):
                #     # KOut[iDir,iDirAvg,iBl,0]=np.mean(pp[ind])
                #     sw=np.sum(w[ind,:])
                #     #print("0",iBl,sw)
                #     # print("!!")
                #     if sw==0: continue
                #     ppp=pp[ind,:]
                #     #print(pp[ind,:].size,sw)
                #     #print("1",iBl,np.sum(ppp))
                #     KOut[iDir,iDirAvg,iBl,0]=np.sum(ppp)/sw
                #     #KOut[iDir,iDirAvg,iBl,0]=sw
                # #print(KOut[iDir,iDirAvg].flat[:],KOut0[iDir,iDirAvg].flat[:],KOut[iDir,iDirAvg].flat[:]-KOut0[iDir,iDirAvg].flat[:])
                # #print(KOut[iDir,iDirAvg].flat[:]-KOut0[iDir,iDirAvg].flat[:])
                # #print("===============")
                # #if KOut[iDir,iDirAvg].max()>0.: stop

            T.timeit("Avg")
        #KOut0[np.isnan(KOut0)]=0.
        KOut = KOut0
        KOut = KOut.reshape((NDir, NDirAvg * NpOut, Npol))

        KOut[:, :, 3] = KOut[:, :, 0]
        n0, n1, _ = KOut.shape

        # Mask=(KOut[:,:,0].reshape((n0,n1,1))==0)
        # _,n0,n1=Mask.shape
        # MaskMergeDir=np.ones((NDirAvg,1,1),Mask.dtype)*np.any(Mask,axis=0).reshape((1,n0,n1))
        # Mask=MaskMergeDir
        # KOut[:,:,0][Mask[:,:,0]]=0.
        # KOut[:,:,3][Mask[:,:,0]]=0.

        return KOut
示例#10
0
def ListNames():

    T = ClassTimeIt.ClassTimeIt("   SharedToDico")

    ll = list(SharedArray.list())
    return [(AR.name).decode("ascii") for AR in ll]