def test_constraint_global_noisy(self): hard_radius = 1. constraints = dimer_global(1, self.im.ndim) self.im.clear() self.im.draw_clusters(10, 2, hard_radius, 2*self.separation, 2*self.diameter) f0 = self.im.f(noise=self.pos_err) f0['signal'] = 180 f0['size'] = 6. result = refine_leastsq(f0, self.im.noisy_image(0.2*self.signal), self.diameter, self.separation, constraints=constraints, param_mode=dict(signal='global', size='global'), options=dict(maxiter=1000)) dists = [] for _, f_cl in result.groupby('cluster'): pos = result[['y', 'x']].values dists.append(np.sqrt(np.sum(((pos[0] - pos[1])/np.array(self.im.size))**2))) assert_allclose(dists, 2*hard_radius, atol=0.1) assert_coordinates_close(result[self.im.pos_columns].values, self.im.coords, 0.1) assert_allclose(result['signal'].values, 200, atol=2) assert_allclose(result['size'].values, 5.25, atol=1)
def test_constraint_global_noisy(self): hard_radius = 1. constraints = dimer_global(1, self.im.ndim) self.im.clear() self.im.draw_clusters(10, 2, hard_radius, 2 * self.separation, 2 * self.diameter) f0 = self.im.f(noise=self.pos_err) f0['signal'] = 180 f0['size'] = 6. result = refine_leastsq(f0, self.im.noisy_image(0.2 * self.signal), self.diameter, self.separation, constraints=constraints, param_mode=dict(signal='global', size='global'), options=dict(maxiter=1000)) dists = [] for _, f_cl in result.groupby('cluster'): pos = result[['y', 'x']].values dists.append( np.sqrt(np.sum( ((pos[0] - pos[1]) / np.array(self.im.size))**2))) assert_allclose(dists, 2 * hard_radius, atol=0.1) assert_coordinates_close(result[self.im.pos_columns].values, self.im.coords, 0.1) assert_allclose(result['signal'].values, 200, atol=2) assert_allclose(result['size'].values, 5.25, atol=1)
def test_constraint_global_dimer(self): hard_radius = 1. constraints = dimer_global(1, self.im.ndim) self.im.clear() self.im.draw_clusters(10, 2, hard_radius, 2 * self.separation, 2 * self.diameter) f0 = self.im.f(noise=self.pos_err) result = refine_leastsq(f0, self.im(), self.diameter, self.separation, constraints=constraints, options=dict(maxiter=1000)) dists = [] for _, f_cl in result.groupby('cluster'): pos = result[['y', 'x']].values dists.append( np.sqrt(np.sum( ((pos[0] - pos[1]) / np.array(self.im.size))**2))) assert_allclose(dists, 2 * hard_radius, atol=0.01) assert_coordinates_close(result[self.im.pos_columns].values, self.im.coords, 0.1)
def test_constraint_global_dimer(self): hard_radius = 1. constraints = dimer_global(1, self.im.ndim) self.im.clear() self.im.draw_clusters(10, 2, hard_radius, 2*self.separation, 2*self.diameter) f0 = self.im.f(noise=self.pos_err) result = refine_leastsq(f0, self.im(), self.diameter, self.separation, constraints=constraints, options=dict(maxiter=1000)) dists = [] for _, f_cl in result.groupby('cluster'): pos = result[['y', 'x']].values dists.append(np.sqrt(np.sum(((pos[0] - pos[1])/np.array(self.im.size))**2))) assert_allclose(dists, 2*hard_radius, atol=0.01) assert_coordinates_close(result[self.im.pos_columns].values, self.im.coords, 0.1)