def __init__(self, size=[160, 120], neighborarea=[8, 8]):
     self.size = size
     shape = size
     nsensels = shape[0] * shape[1] 
 
     # for each sensel, create an area
     lengths = np.array(neighborarea)
 
     neighbor_coords = [None] * nsensels
     self.neighbor_indices_flat = [None] * nsensels
 
     flattening = Flattening.by_rows(tuple(shape))
     cmg = cmap(lengths)
     self.cmg = cmg
     for coord in coords_iterate(shape):
         k = flattening.cell2index[coord]
         cm = cmg.copy()
         cm[:, :, 0] += coord[0]
         cm[:, :, 1] += coord[1]
         cm[:, :, 0] = cm[:, :, 0] % shape[0]
         cm[:, :, 1] = cm[:, :, 1] % shape[1]
         neighbor_coords[k] = cm
 
         indices = np.zeros(lengths, 'int32')
         for a, b in coords_iterate(indices.shape):
             c = tuple(cm[a, b, :])
             indices[a, b] = flattening.cell2index[c]
 
         self.neighbor_indices_flat[k] = np.array(indices.flat)
    def init_structures(self, shape):
        self.shape = shape
        self.nsensels = shape[0] * shape[1]

        self.ydd = np.zeros(shape, dtype='float32')

        # for each sensel, create an area
        self.lengths = np.ceil(self.max_displ *
                               np.array(self.shape)).astype('int32')
        # print(' Field Shape: %s' % str(self.shape))
        # print('    Fraction: %s' % str(self.max_displ))
        # print(' Search area: %s' % str(self.lengths))

        self.neighbor_coords = [None] * self.nsensels
        self.neighbor_indices = [None] * self.nsensels
        self.neighbor_indices_flat = [None] * self.nsensels
        self.neighbor_similarity_flat = [None] * self.nsensels
        self.neighbor_similarity_best = np.zeros(self.nsensels,
                                                 dtype='float32')
        self.neighbor_argsort_flat = [None] * self.nsensels
        self.neighbor_num_bestmatch_flat = [None] * self.nsensels

        self.flattening = Flattening.by_rows(shape)
        logger.info('Creating structure shape %s lengths %s' %
                    (self.shape, self.lengths))
        cmg = cmap(self.lengths)
        for coord in coords_iterate(self.shape):
            k = self.flattening.cell2index[coord]
            cm = cmg.copy()
            cm[:, :, 0] += coord[0]
            cm[:, :, 1] += coord[1]
            cm[:, :, 0] = cm[:, :, 0] % self.shape[0]
            cm[:, :, 1] = cm[:, :, 1] % self.shape[1]
            self.neighbor_coords[k] = cm

            indices = np.zeros(self.lengths, 'int32')
            for a, b in coords_iterate(indices.shape):
                c = tuple(cm[a, b, :])
                indices[a, b] = self.flattening.cell2index[c]

            self.neighbor_indices[k] = indices
            self.neighbor_indices_flat[k] = np.array(indices.flat)
            self.neighbor_similarity_flat[k] = np.zeros(
                indices.size, 'float32')
            self.neighbor_argsort_flat[k] = np.zeros(indices.size, 'float32')
            self.neighbor_num_bestmatch_flat[k] = np.zeros(
                indices.size, 'uint')
    def init_structures(self, shape):
        self.shape = shape
        self.nsensels = shape[0] * shape[1]

        self.ydd = np.zeros(shape, dtype='float32')

        # for each sensel, create an area
        self.lengths = np.ceil(self.max_displ * 
                               np.array(self.shape)).astype('int32')
        # print(' Field Shape: %s' % str(self.shape))
        # print('    Fraction: %s' % str(self.max_displ))
        # print(' Search area: %s' % str(self.lengths))

        self.neighbor_coords = [None] * self.nsensels
        self.neighbor_indices = [None] * self.nsensels
        self.neighbor_indices_flat = [None] * self.nsensels
        self.neighbor_similarity_flat = [None] * self.nsensels
        self.neighbor_similarity_best = np.zeros(self.nsensels, dtype='float32')
        self.neighbor_argsort_flat = [None] * self.nsensels
        self.neighbor_num_bestmatch_flat = [None] * self.nsensels

        self.flattening = Flattening.by_rows(shape)
        logger.info('Creating structure shape %s lengths %s' % 
                  (self.shape, self.lengths))
        cmg = cmap(self.lengths)
        for coord in coords_iterate(self.shape):
            k = self.flattening.cell2index[coord]
            cm = cmg.copy()
            cm[:, :, 0] += coord[0]
            cm[:, :, 1] += coord[1]
            cm[:, :, 0] = cm[:, :, 0] % self.shape[0]
            cm[:, :, 1] = cm[:, :, 1] % self.shape[1]
            self.neighbor_coords[k] = cm

            indices = np.zeros(self.lengths, 'int32')
            for a, b in coords_iterate(indices.shape):
                c = tuple(cm[a, b, :])
                indices[a, b] = self.flattening.cell2index[c]

            self.neighbor_indices[k] = indices
            self.neighbor_indices_flat[k] = np.array(indices.flat)
            self.neighbor_similarity_flat[k] = np.zeros(indices.size, 'float32')
            self.neighbor_argsort_flat[k] = np.zeros(indices.size, 'float32')
            self.neighbor_num_bestmatch_flat[k] = np.zeros(indices.size, 'uint')