def test_read(self): fr = FitResult("test") res = np.ones((10, 25)) chi2 = np.ones((10, )) pval = np.ones((10, )) self.assertRaises(RuntimeError, fr.add_data, (1, ), res, chi2, pval) fr.create_empty((10, 25, 4), (10, 4), 3) fr.add_data((0, 0), res, chi2, pval) fr.add_data((2, 0), res, chi2, pval) fr.add_data((0, 3), res, chi2, pval) fname = "./test_data/tmp_fitresult.npz" fr.save(fname) fexists = os.path.isfile(fname) if fexists: fr1 = FitResult.read(fname) self.assertTrue(np.array_equal(fr1.data[0][:, :, 0], res)) self.assertTrue(np.array_equal(fr1.chi2[0][:, 0], chi2)) self.assertTrue(np.array_equal(fr1.pval[0][:, 0], pval)) self.assertTrue(np.array_equal(fr1.data[2][:, :, 0], res)) self.assertTrue(np.array_equal(fr1.chi2[2][:, 0], chi2)) self.assertTrue(np.array_equal(fr1.pval[2][:, 0], pval)) self.assertTrue(np.array_equal(fr1.data[0][:, :, 3], res)) self.assertTrue(np.array_equal(fr1.chi2[0][:, 3], chi2)) self.assertTrue(np.array_equal(fr1.pval[0][:, 3], pval)) self.assertEqual(fr1.corr_id, "test")
def test_get_data(self): fr = FitResult("") res = np.ones((10, 25)) chi2 = np.ones((10, )) pval = np.ones((10, )) self.assertRaises(RuntimeError, fr.add_data, (1, ), res, chi2, pval) fr.create_empty((10, 25, 4), (10, 4), 3) fr.add_data((0, 0), res, chi2, pval) self.assertTrue(np.array_equal(fr.data[0][:, :, 0], np.ones((10, 25)))) self.assertTrue(np.array_equal(fr.chi2[0][:, 0], np.ones((10, )))) fr.add_data((2, 0), res, chi2, pval) self.assertTrue(np.array_equal(fr.data[2][:, :, 0], np.ones((10, 25)))) self.assertTrue(np.array_equal(fr.chi2[2][:, 0], np.ones((10, )))) fr.add_data((0, 3), res, chi2, pval) self.assertTrue(np.array_equal(fr.data[0][:, :, 3], np.ones((10, 25)))) self.assertTrue(np.array_equal(fr.chi2[0][:, 3], np.ones((10, ))))