def MovePix(self, indiv, iPix, Flux, FluxWeighted=True, InReg=None):

        dx, dy = np.mgrid[-1:1:3 * 1j, -1:1:3 * 1j]
        Dx = np.int32(np.concatenate((dx.flatten()[0:4], dx.flatten()[5::])))
        Dy = np.int32(np.concatenate((dy.flatten()[0:4], dy.flatten()[5::])))

        # ArrayModel=self.PM.GiveModelArray(indiv)
        # ArrayModel_S=self.PM.ArrayToSubArray(indiv,Type="S")
        ArrayModel_S = indiv  # ArrayModel_S.reshape((1,ArrayModel_S.size))*np.ones((2,1))
        A = self.PM.ModelToSquareArray(ArrayModel_S,
                                       TypeInOut=("Parms", "Parms"),
                                       DomainOut="Parms")

        nf, npol, nx, nx = A.shape
        #A=np.mean(A,axis=0).reshape(1,npol,nx,nx)

        mapi, mapj = self.PM.SquareGrids["Parms"]["MappingIndexToXYPix"]
        i0, j0 = mapi[iPix], mapj[iPix]
        FluxWeighted = False
        if FluxWeighted:
            iAround = i0 + Dx
            jAround = j0 + Dy
            cx = ((iAround >= 0) & (iAround < nx))
            cy = ((jAround >= 0) & (jAround < nx))
            indIN = (cx & cy)
            iAround = iAround[indIN]
            jAround = jAround[indIN]
            sAround = A[0, 0, iAround, jAround].copy()
            #sInt=np.sum(sAround)
            #sAround[sAround==0]=sInt*0.05
            X = np.arange(iAround.size)
            DM = ClassDistMachine()
            DM.setRefSample(X, W=sAround, Ns=10)
            ind = int(round(DM.GiveSample(1)[0]))
            ind = np.max([0, ind])
            ind = np.min([ind, iAround.size - 1])
            ind = indIN[ind]

        # else:
        #     if InReg is None:
        #         reg=random.random()
        #     else:
        #         reg=InReg
        #     ind=int(reg*8)

        i1 = i0 + Dx[InReg]
        j1 = j0 + Dy[InReg]

        f0 = Flux  #alpha*A[0,0,i0,j0]

        _, _, nx, ny = A.shape
        condx = ((i1 > 0) & (i1 < nx))
        condy = ((j1 > 0) & (j1 < ny))
        if condx & condy:
            A[0, 0, i1, j1] += f0
            A[0, 0, i0, j0] -= f0
            AParm = self.PM.SquareArrayToModel(A, TypeInOut=("Parms", "Parms"))

            ArrayModel_S.flat[:] = AParm.flat[:]
        return indiv
Exemple #2
0
 def GiveCompacity(self,S):
     DM=ClassDistMachine()
     #S.fill(1)
     #S[0]=100
     DM.setRefSample(np.arange(S.size),W=np.sort(S),Ns=100,xmm=[0,S.size-1])#,W=sAround,Ns=10)
     #DM.setRefSample(S)#,W=sAround,Ns=10)
     xs,ys=DM.xyCumulD
     dx=xs[1]-xs[0]
     I=2.*(S.size-np.sum(ys)*dx)/S.size-1.
     return I