def recenter(com, dim, arr): """ Recenters the simulation :param com: center_of_mass :param dim: dimensions of array :param array: the array :return: ver (vertical movement), hor (horizontal movement) """ ver = 0 hor = 0 com = np.asarray(com) center = np.asarray([dim[0] / 2, dim[1] / 2]) if not com.any(): com = center offcenter = center - com norm = cph.norm(offcenter[0], offcenter[1]) if norm > 2: if offcenter[0] > 0: cy.roll_rows_pointer(1, dim, arr) ver += 1 else: cy.roll_rows_pointer(-1, dim, arr) ver -= 1 if offcenter[1] > 0: cy.roll_columns_pointer(1, dim, arr) hor += 1 else: cy.roll_columns_pointer(-1, dim, arr) hor -= 1 return ver, hor
def basic_update(self, kwargs): logging.debug('Basic update') cf.ising_process(kwargs['updates'], kwargs['beta'], kwargs['dim_h'], kwargs['arr_h']) cf.add_stochastic_noise(kwargs['threshold'], kwargs['dim_h'], kwargs['arr_h']) cy.set_bounds(kwargs['bounds'], kwargs['dim_h'], kwargs['arr_h']) cy.roll_columns_pointer(kwargs['roll'][0], kwargs['dim_h'], kwargs['arr_h']) cy.roll_rows_pointer(kwargs['roll'][1], kwargs['dim_h'], kwargs['arr_h']) cy.set_bounds(kwargs['bounds'], kwargs['dim_h'], kwargs['arr_h']) cy.scroll_bars(kwargs['dim_h'], kwargs['arr_h'], kwargs['bars']) cf.scroll_noise(kwargs['dim_h'], kwargs['arr_h'], kwargs['fuzz']) cf.conway_process( cf.prepair_rule(kwargs['rules'], kwargs['head_position']), kwargs['dim_h'], kwargs['arr_h']) cy.set_bounds(kwargs['bounds'], kwargs['dim_h'], kwargs['arr_h']) if self.st.general.growth: _, _ = phi.recenter( cph.center_of_mass(kwargs['dim_h'], kwargs['arr_h']), kwargs['dim_h'], kwargs['arr_h'])
def test_roll_columns_pointer_back(self): arrout = tst_arr() cy.roll_columns_pointer(-1, tst_dim(), arrout) cy.roll_columns_pointer(-1, tst_dim(), arrout) testing.assert_array_equal(arrout, np.roll(tst_arr(), -2, axis=1))