Exemplo n.º 1
0
 def getGridAsImages(self,size,fontpath=None):
    if self.isHexagon:
       log.debug("Outputing images with hexagons");
       if fontpath is not None:
          labels = [["({},{}):{}"\
                     .format(x,y,np.ravel_multi_index((x,y),self.grid.shape[0:2]))\
                     for y in range(self.grid.shape[1])]\
                    for x in range(self.grid.shape[0])];
       else:
          labels = None;
       return [AGraphics.drawHexagonImage(self.grid[:,:,i],size,labels=labels,fontpath=fontpath) for i in range(self.vector_size)]
    else:
       log.debug("Outputing images with squares");
       imgs = [];
       for i in xrange(self.vector_size):
          imgs.append(AGraphics.drawMatrixImage(self.grid[:,:,i]));
       return imgs;
Exemplo n.º 2
0
 def getGridAsImages(self, size, fontpath=None):
     if self.isHexagon:
         log.debug("Outputing images with hexagons")
         if fontpath is not None:
             labels = [["({},{}):{}"\
                        .format(x,y,np.ravel_multi_index((x,y),self.grid.shape[0:2]))\
                        for y in range(self.grid.shape[1])]\
                       for x in range(self.grid.shape[0])]
         else:
             labels = None
         return [
             AGraphics.drawHexagonImage(self.grid[:, :, i],
                                        size,
                                        labels=labels,
                                        fontpath=fontpath)
             for i in range(self.vector_size)
         ]
     else:
         log.debug("Outputing images with squares")
         imgs = []
         for i in xrange(self.vector_size):
             imgs.append(AGraphics.drawMatrixImage(self.grid[:, :, i]))
         return imgs
Exemplo n.º 3
0
    def getUMatrixImage(self, size, fontpath=None):
        if self.isHexagon:
            log.debug("Outputing U-matrix with hexagons")

            (x, y, z) = self.grid[:, :, :].shape
            s = (x * 2 - 1, y * 2)
            umatrix = np.zeros(s)

            i, j = np.mgrid[0:x, 0:y]

            umatrix[:, :] = np.nan

            xs, ys = np.mgrid[0:x, 0:y]
            axs, ays = np.mgrid[0:x, 0:y - 1]
            bxs, bys = np.mgrid[0:x - 1, 0:y]
            cxs, cys = np.mgrid[0:x - 1, 1:y]

            amaskx, amasky = axs * 2, ays * 2 + (axs % 2) + 1
            bmaskx, bmasky = bxs * 2 + 1, bys * 2
            cmaskx, cmasky = cxs * 2 + 1, cys * 2 - 1

            uposx, uposy = xs * 2, ys * 2 + (xs % 2)

            avec = self.grid[axs, ays, :] - self.grid[axs, ays + 1, :]
            bvec = self.grid[bxs, bys, :] - self.grid[bxs + 1, bys, :]
            cvec = self.grid[cxs, cys, :] - self.grid[cxs + 1, cys - 1, :]

            umatrix[amaskx, amasky] = np.sqrt(np.sum(avec * avec, 2))
            umatrix[bmaskx, bmasky] = np.sqrt(np.sum(bvec * bvec, 2))
            umatrix[cmaskx, cmasky] = np.sqrt(np.sum(cvec * cvec, 2))

            temp = np.zeros((x, y))

            temp[axs, ays] += umatrix[amaskx, amasky]
            temp[bxs, bys] += umatrix[bmaskx, bmasky]
            temp[cxs, cys] += umatrix[cmaskx, cmasky]

            temp[axs, ays + 1] += umatrix[amaskx, amasky]
            temp[bxs + 1, bys] += umatrix[bmaskx, bmasky]
            temp[cxs + 1, cys - 1] += umatrix[cmaskx, cmasky]

            umatrix[uposx, uposy] = temp[xs, ys] / 6.0

            umax = np.nanmax(umatrix)

            umatrix = 1 - umatrix / umax

            def formatFeild(x, y):
                s = "({},{}):{}".format(
                    x / 2, y / 2,
                    np.ravel_multi_index((x / 2, y / 2), self.grid.shape[0:2]))
                if x % 4 == 0 and y % 2 == 0:
                    return s
                elif (x + 2) % 4 == 0 and y % 2 == 1:
                    return s
                else:
                    return ''

            if fontpath is not None:
                labels = [[formatFeild(x,y)\
                           for y in range(self.grid.shape[1]*2 )  ]\
                          for x in range(self.grid.shape[0]*2 -1)\
                         ]
            else:
                labels = None

            return AGraphics.drawHexagonImage(umatrix, size, labels, fontpath)
        else:
            log.error("Outputing U-matrix with squares, is not allowed")
            sys.exit(-1)
Exemplo n.º 4
0
   def getUMatrixImage(self,size,fontpath=None):
      if self.isHexagon:
         log.debug("Outputing U-matrix with hexagons");
         
         (x,y,z) = self.grid[:,:,:].shape;
         s = (x*2-1,y*2)
         umatrix = np.zeros(s);
         
         i,j = np.mgrid[0:x,0:y];
         
         umatrix[:,:] = np.nan;
         
         xs,ys = np.mgrid[0:x,0:y];
         axs,ays = np.mgrid[0:x,0:y-1];
         bxs,bys = np.mgrid[0:x-1,0:y];
         cxs,cys = np.mgrid[0:x-1,1:y];
         
         amaskx, amasky = axs *2,ays*2+(axs % 2) +1;
         bmaskx, bmasky = bxs *2 +1 ,bys*2;
         cmaskx, cmasky = cxs *2 +1 ,cys*2 -1;

         uposx,uposy = xs *2,ys*2+(xs % 2);
         
         avec = self.grid[axs,ays,:] - self.grid[axs,ays+1,:];
         bvec = self.grid[bxs,bys,:] - self.grid[bxs+1,bys,:];
         cvec = self.grid[cxs,cys,:] - self.grid[cxs+1,cys-1,:];
         
         
         umatrix[amaskx,amasky] = np.sqrt(np.sum(avec * avec,2));
         umatrix[bmaskx,bmasky] = np.sqrt(np.sum(bvec * bvec,2));
         umatrix[cmaskx,cmasky] = np.sqrt(np.sum(cvec * cvec,2));
         
         
         temp = np.zeros((x,y));
         
         temp[axs,ays] += umatrix[amaskx,amasky];
         temp[bxs,bys] += umatrix[bmaskx,bmasky];
         temp[cxs,cys] += umatrix[cmaskx,cmasky];
         
         temp[axs,ays+1] += umatrix[amaskx,amasky];
         temp[bxs+1,bys] += umatrix[bmaskx,bmasky];
         temp[cxs+1,cys-1] += umatrix[cmaskx,cmasky];
         
         umatrix[uposx,uposy] = temp[xs,ys] / 6.0;
         
         umax = np.nanmax(umatrix);
         
         umatrix = 1 - umatrix/umax;

         def formatFeild(x,y):
            s = "({},{}):{}".format(x/2,y/2,np.ravel_multi_index((x/2,y/2),self.grid.shape[0:2]));
            if x % 4 == 0 and y % 2 == 0:
               return s;
            elif (x + 2) % 4 == 0 and y % 2 == 1:
               return s;
            else:
               return '';
         
         if fontpath is not None:
            labels = [[formatFeild(x,y)\
                       for y in range(self.grid.shape[1]*2 )  ]\
                      for x in range(self.grid.shape[0]*2 -1)\
                     ];
         else:
            labels = None;

         return AGraphics.drawHexagonImage(umatrix,size,labels,fontpath);
      else:
         log.error("Outputing U-matrix with squares, is not allowed");
         sys.exit(-1);