Ejemplo n.º 1
0
    def set_grid(self, g):
        """Set self.grid to supplied grid, scaling the supplied grid
        if nessacary"""
        g = np.array(g)

        if g.shape[0] > 1:
            # 2d grid
            if not self.grid.shape == g.shape:
                g = scale_array(g, *self.grid.shape)
            self.grid[:, :] = g[:, :]
        else:
            # 1d grid
            if not self.grid.shape[1] == g.shape[1]:
                g = scale_array(g, g.shape[0], self.grid.shape[1])
            self.grid[0, :] = g[0]
        self.refresh_wrap()
Ejemplo n.º 2
0
 def set_grid_dims(self, dims=None, num_generations=None):
     if dims is not None:
         i = dims[0] if dims[0] > 2 else 3
         j = dims[1] if dims[1] > 2 else 3
         self.grid_dims = i, j
     else:
         if num_generations < 1:
             num_generations = 1
         self.num_generations = num_generations
         self.grid_dims = gens_to_dims(self.num_generations)
     if self.initial_grid is not None:
         self.initial_grid = scale_array(self.initial_grid, *self.grid_dims)
     else:
         self.intitial_grid = np.zeros(self.grid_dims)
Ejemplo n.º 3
0
 def test_scale_same(self):
     a = np.ones((10, 10))
     toshape = 10, 10
     b = utils.scale_array(a, toshape[0], toshape[1])
     self.assertTrue(b.shape == toshape)
     self.assertTrue(np.array_equal(a, b))
Ejemplo n.º 4
0
 def test_scale_down(self):
     a = np.ones((10, 10))
     toshape = 3, 6
     b = utils.scale_array(a, toshape[0], toshape[1])
     self.assertTrue(b.shape == toshape)
     self.assertTrue(np.array_equal(b, a[:b.shape[0], :b.shape[1]]))
Ejemplo n.º 5
0
 def test_scale_up(self):
     a = np.ones((10, 10))
     toshape = 14, 20
     b = utils.scale_array(a, toshape[0], toshape[1])
     self.assertTrue(b.shape == toshape)
     self.assertTrue(np.array_equal(a, b[:a.shape[0], :a.shape[1]]))