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()
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)
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))
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]]))
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]]))