def get_graph_indices(self, event):
     """Translate mouse position on graph to indicies in grid"""
     col = clip_numeric(int(event.xdata + 0.5),
                        0, self.ca_config.grid_dims[1] - 1)
     row = clip_numeric(int(event.ydata + 0.5),
                        0, self.ca_config.grid_dims[0] - 1)
     return row, col
Exemplo n.º 2
0
 def test(self):
     res = utils.clip_numeric(i, lowclip, highclip)
     if i < lowclip:
         self.assertTrue(res == lowclip)
     elif i > highclip:
         self.assertTrue(res == highclip)
     else:
         self.assertTrue(res == i)
Exemplo n.º 3
0
def randomise2d(grid, background_state, proportions):
    """ Takes a grid, the background state, and
    proportions for each state in a list of tuples ([(1,0.4), (2,0.3)]) """
    grid[:, :] = background_state
    numcells_per_state = np.zeros(len(proportions), dtype=int)
    for i, p in enumerate(proportions):
        proportion = clip_numeric(p[1], 0, 1)
        numcells_per_state[i] = int(proportion * grid.size)
    randindicies = np.random.choice(grid.size,
                                    np.sum(numcells_per_state),
                                    replace=False)
    g = np.copy(grid).reshape(grid.size)
    used = 0
    for i, p in enumerate(proportions):
        state = p[0]
        indicies = randindicies[used:numcells_per_state[i]]
        g[indicies] = state
        used += numcells_per_state[i]

    return g.reshape(grid.shape)