def test_get_mean_colwise(self): """test get_mean colwise""" data = [[0, 1, 3], [0.01, 10, 3.5], [0.02, 21, 4.0]] p = self.SAXSProfile() p.add_data(data) gp = MockGP(1, 2) m = IMP.kernel.Model() s = IMP.isd.Scale.setup_particle(IMP.kernel.Particle(m), 3.0) functions = {} functions['mean'] = MockFunction() functions['covariance'] = MockFunction() p.set_interpolant(gp, {'sigma': s}, functions, 'test', IMP.kernel.Model(), None) test = p.get_mean(colwise=True) expected_q = numpy.linspace(0, 0.02, num=200) expected_I = numpy.array( map(gp.get_posterior_mean, [[i] for i in expected_q])) expected_err = numpy.array( map(lambda a: numpy.sqrt(gp.get_posterior_covariance([a], [1.0])), expected_q)) expected_mean = numpy.array( map(lambda a: functions['mean'](a), expected_q)) self.assertEqual(len(test), 4) self.assertEqual(set(['q', 'I', 'err', 'mean']), set(test.keys())) self.assertTrue((expected_q == test['q']).all()) self.assertTrue((expected_I == test['I']).all()) self.assertTrue((expected_err == test['err']).all()) self.assertTrue((expected_mean == test['mean']).all())
def test_get_mean_colwise(self): """test get_mean colwise""" data = [[0, 1, 3], [0.01, 10, 3.5], [0.02, 21, 4.0]] p = self.SAXSProfile() p.add_data(data) gp = MockGP(1, 2) m = IMP.Model() s = IMP.isd.Scale.setup_particle(IMP.Particle(m), 3.0) functions = {} functions['mean'] = MockFunction() functions['covariance'] = MockFunction() p.set_interpolant( gp, {'sigma': s}, functions, 'test', IMP.Model(), None) test = p.get_mean(colwise=True) expected_q = numpy.linspace(0, 0.02, num=200) expected_I = numpy.array(list(map(gp.get_posterior_mean, [[i] for i in expected_q]))) expected_err = numpy.array(list(map(lambda a: numpy.sqrt( gp.get_posterior_covariance( [a], [1.0])), expected_q))) expected_mean = numpy.array(list(map(lambda a: functions['mean'](a), expected_q))) self.assertEqual(len(test), 4) self.assertEqual(set(['q', 'I', 'err', 'mean']), set(test.keys())) self.assertTrue((expected_q == test['q']).all()) self.assertTrue((expected_I == test['I']).all()) self.assertTrue((expected_err == test['err']).all()) self.assertTrue((expected_mean == test['mean']).all())
def test_get_raw_data_colwise(self): """test get_raw_data colwise """ data = [[0, 0.1, 3], [0.01, 10, 3.5], [0.02, 21, 4.0]] self.write_data(data) p = self.SAXSProfile() p.add_data(self.datafile) test = p.get_raw_data(colwise=True) self.assertEqual(len(test), 3) self.assertEqual(set(test.keys()), set(['q', 'I', 'err'])) self.assertEqual(test['q'], [i[0] for i in data]) self.assertEqual(test['I'], [i[1] for i in data]) self.assertEqual(test['err'], [i[2] for i in data])
def test_get_data_colwise(self): """test get_data colwise """ data = [[0, 0.1, 3], [0.01, 10, 3.5], [0.02, 21, 4.0]] self.write_data(data) p = self.SAXSProfile() p.add_data(self.datafile) test = p.get_data(colwise=True) self.assertEqual(len(test), 4) self.assertEqual(set(test.keys()), set(["id", "q", "I", "err"])) self.assertEqual(test["id"], range(3)) self.assertEqual(test["q"], [i[0] for i in data]) self.assertEqual(test["I"], [i[1] for i in data]) self.assertEqual(test["err"], [i[2] for i in data])