Beispiel #1
0
    def PrepareJHJ_EKF(self,Pa_in,rms):
        self.L_JHJinv=[]
        incr=1
        # pylab.figure(1)
        # pylab.clf()
        # pylab.imshow(np.abs(self.JHJ),interpolation="nearest")
        # pylab.draw()
        # pylab.show(False)
        # pylab.pause(0.1)

        for ipol in range(self.NJacobBlocks_X):
            PaPol=self.GivePaPol(Pa_in,ipol)
            Pinv=ModLinAlg.invSVD(PaPol)
            JHJ=self.L_JHJ[ipol]#*(1./rms**2)
            JHJ+=Pinv
            if self.DoReg:
                JHJ+=self.LQxInv[ipol]*(self.gamma**2)
            JHJinv=ModLinAlg.invSVD(JHJ)
            self.L_JHJinv.append(JHJinv)
Beispiel #2
0
    def PrepareJHJ_LM(self):

        self.L_JHJinv=[]
        if self.DataAllFlagged:
            return

        for ipol in range(self.NJacobBlocks_X):

            M=self.L_JHJ[ipol]
            if self.DoTikhonov:
                self.LambdaTkNorm=self.LambdaTk*np.mean(np.abs(np.diag(M)))
                
                # Lin.shape= (self.NDir,self.NJacobBlocks_X,self.NJacobBlocks_Y)
                Linv=np.diag(self.Linv[:,ipol,:].ravel())
                Linv*=self.LambdaTkNorm/(1.+self.LambdaLM)
                M2=M+Linv

                # pylab.clf()
                # pylab.subplot(1,2,1)
                # pylab.imshow(np.abs(M),interpolation="nearest")
                # pylab.colorbar()
                # pylab.subplot(1,2,2)
                # pylab.imshow(np.abs(Linv),interpolation="nearest")
                # pylab.colorbar()
                # pylab.draw()
                # pylab.show(False)
                # pylab.pause(0.1)
                # stop

            else:
                M2=M


            JHJinv=ModLinAlg.invSVD(M2)
            #JHJinv=ModLinAlg.invSVD(self.JHJ)
            self.L_JHJinv.append(JHJinv)
Beispiel #3
0
    def Stack_SingleTime(self, iA0, iA1):

        self.DicoDATA.reload()
        self.DicoGrids.reload()
        DicoMSInfos = self.DicoMSInfos

        #indRow = np.where((self.DicoDATA["times"]==self.times[iTime]))[0]
        #ch0,ch1=self.DicoGrids["DomainEdges_Freq"][iFreq],self.DicoGrids["DomainEdges_Freq"][iFreq+1]
        nrow, nch, _ = self.DicoDATA["data"].shape
        ch0, ch1 = 0, nch

        #print(ch0,ch1)
        C0 = (self.DicoDATA["A0"] == iA0) & (self.DicoDATA["A1"] == iA1)
        indRow = np.where(C0)[0]

        f = self.DicoDATA["flag"][indRow, ch0:ch1, :]
        d = self.DicoDATA["data"][indRow, ch0:ch1, :]
        dp = self.DicoDATA["data_p"][indRow, ch0:ch1, :]
        nrow, nch, _ = d.shape
        weights = (self.DicoDATA["weights"][indRow, ch0:ch1]).reshape(
            (nrow, nch, 1))
        A0s = self.DicoDATA["A0"][indRow]
        A1s = self.DicoDATA["A1"][indRow]
        times = self.DicoDATA["times"][indRow]
        NTimesBin = np.unique(times).size

        i_TimeBin = np.int64(
            np.argmin(np.abs(
                times.reshape((-1, 1)) -
                np.sort(np.unique(times)).reshape((1, -1))),
                      axis=1).reshape(-1, 1)) * np.ones((1, nch))
        i_ch = np.int64((np.arange(nch).reshape(1, -1)) * np.ones((nrow, 1)))
        i_A0 = A0s.reshape((-1, 1)) * np.ones((1, nch))
        i_A1 = A1s.reshape((-1, 1)) * np.ones((1, nch))

        i_TimeBin = np.int64(i_TimeBin).ravel()
        i_ch = np.int64(i_ch).ravel()
        i_A0 = np.int64(i_A0).ravel()
        i_A1 = np.int64(i_A1).ravel()
        na = self.na

        def Give_R(din):
            d0 = (din[:, :, 0] + din[:, :, -1]) / 2.

            R = np.zeros((nch, NTimesBin), din.dtype)

            ind0 = i_ch * NTimesBin + i_TimeBin

            R.flat[:] = d0.flat[ind0]
            R = d0.T

            Rf = np.ones((R.shape), dtype=np.float64)
            Rf[R == 0] = 0

            return R, Rf

        iMS = self.DicoDATA["iMS"]

        f0, _ = self.Freq_minmax

        dcorr = d
        dcorr[f == 1] = 0

        RMS = scipy.stats.median_abs_deviation((dcorr[dcorr != 0]).ravel(),
                                               scale="normal")
        df = (dcorr[dcorr != 0]).ravel()
        if df.size > 100:
            RMS = np.sqrt(np.abs(np.sum(df * df.conj())) / df.size)

        dp[dp == 0] = 1.

        R, Rf = Give_R(dcorr)
        Rp, Rpf = Give_R(dp)
        Rp[Rpf == 0] = 1.
        #Rp/=np.abs(Rp)
        R /= Rp

        if np.max(np.abs(R)) == 0: return

        C = np.dot(R.T.conj(), R)
        Cn = np.dot(Rf.T, Rf)
        Cn[Cn == 0] = 1.
        C /= Cn

        # import pylab
        # pylab.clf()
        # pylab.subplot(2,2,1)
        # pylab.imshow(np.abs(C),aspect="auto",interpolation="nearest")
        # pylab.colorbar()
        # pylab.title("%i, %i"%(iA0,iA1))
        # pylab.subplot(2,2,2)
        # pylab.imshow(np.abs(R),aspect="auto",interpolation="nearest")
        # pylab.colorbar()
        # pylab.subplot(2,2,3)
        # pylab.imshow(np.abs(Cn),aspect="auto",interpolation="nearest")
        # pylab.colorbar()
        # pylab.title("%i, %i"%(iA0,iA1))
        # pylab.subplot(2,2,4)
        # pylab.imshow(np.abs(Rf),aspect="auto",interpolation="nearest")
        # pylab.colorbar()
        # pylab.draw()
        # pylab.show(block=False)
        # pylab.pause(0.1)
        # return

        # ################################

        Cp = np.dot(Rp.T.conj(), Rp)
        Cpn = np.dot(Rpf.T, Rpf)
        Cpn[Cpn == 0] = 1.
        Cp /= Cpn
        C /= Cp

        C = np.abs(C)
        invC = ModLinAlg.invSVD(C[:, :])

        w = np.abs(np.sum(invC, axis=0))

        WOUT = self.DicoDATA["WOUT"][indRow, ch0:ch1]

        for ii, iRow in enumerate(indRow):
            for ich in np.arange(ch0, ch1):
                self.DicoDATA["WOUT"][iRow, ich] = w[ii]