def test_saturation_correction_shape_mismatch(self): det = Maxipix("Maxipix") det.saturation_threshold = 10 data = np.ones((3, 3)) * 11 mask = np.zeros((3, 4)) with self.assertRaises(ValueError): det._saturation_correction(data, mask, nb_frames=1)
def test_saturation_correction_nbframes_wrong_value(self): det = Maxipix("Maxipix") det.saturation_threshold = 10 data = np.ones((3, 3)) * 11 mask = np.zeros((3, 3)) with self.assertRaises(ValueError): det._saturation_correction(data, mask, nb_frames=0)
def test_saturation_correction_wrong_type(self): det = Maxipix("Maxipix") det.saturation_threshold = 10 data = 11 mask = np.zeros((3, 3)) with self.assertRaises(TypeError): det._saturation_correction(data, mask, nb_frames=1)
def test_saturation_correction_nbframes_2(self): det = Maxipix("Maxipix") det.saturation_threshold = 10 data = np.ones((3, 3)) * 11 mask = np.zeros((3, 3)) output = det._saturation_correction(data, mask, nb_frames=2) self.assertTrue(np.all(np.isclose(output[0], data))) self.assertTrue(np.all(np.isclose(output[1], mask)))
class TestMaxipix(unittest.TestCase): """Tests related to the Maxipix detector.""" def setUp(self) -> None: self.det = Maxipix("Maxipix") self.data = np.ones(self.det.unbinned_pixel_number) self.mask = np.zeros(self.det.unbinned_pixel_number) def test_unbinned_pixel_number_default(self): self.assertTupleEqual(self.det.unbinned_pixel_number, (516, 516)) def test_unbinned_pixel_size_default(self): self.assertTupleEqual(self.det.unbinned_pixel_size, (55e-06, 55e-06)) def test_mask_gaps(self): data, mask = self.det._mask_gaps(data=self.data, mask=self.mask) self.assertTrue(np.all(data[:, 255:261]) == 0) self.assertTrue(np.all(data[255:261, :]) == 0) self.assertTrue(np.all(mask[:, 255:261]) == 1) self.assertTrue(np.all(mask[255:261, :]) == 1)
def test_sum_roi_list_wrong_value_decreasing_x(self): with self.assertRaises(ValueError): Maxipix(name="Maxipix", sum_roi=[0, 256, 128, 35])
def test_sum_roi_none_default(self): det = Maxipix(name="Maxipix", sum_roi=None) self.assertEqual(det.sum_roi, [0, self.det.nb_pixel_y, 0, self.det.nb_pixel_x])
def test_rootdir_wrong_length(self): with self.assertRaises(ValueError): Maxipix(name="Maxipix", rootdir="")
def test_sum_roi_list_wrong_value_none(self): with self.assertRaises(ValueError): Maxipix(name="Maxipix", sum_roi=[None, 512, 12, 35])
def test_template_imagefile_correct(self): det = Maxipix(name="Maxipix", template_imagefile="S") self.assertEqual(det.template_imagefile, "S")
def test_roi_correct_tuple(self): det = Maxipix(name="Maxipix", roi=(2, 252, 1, 35)) self.assertEqual(det.roi, (2, 252, 1, 35))
def test_scandir_datadir_defined(self): dir_path = os.path.abspath(os.path.join(self.valid_path, os.pardir)) + "/" det = Maxipix(name="Maxipix", datadir=self.valid_path) self.assertEqual(det.scandir, dir_path.replace("\\", "/"))
def test_template_imagefile_wrong_type(self): with self.assertRaises(TypeError): Maxipix(name="Maxipix", template_imagefile=777)
def test_sample_name_None(self): det = Maxipix(name="Maxipix", sample_name=None) self.assertEqual(det.sample_name, None)
def test_sample_name_correct(self): det = Maxipix(name="Maxipix", sample_name="S") self.assertEqual(det.sample_name, "S")
def test_sample_name_wrong_length(self): with self.assertRaises(ValueError): Maxipix(name="Maxipix", sample_name="")
def test_sample_name_wrong_type(self): with self.assertRaises(TypeError): Maxipix(name="Maxipix", sample_name=777)
def test_rootdir_None(self): det = Maxipix(name="Maxipix", rootdir=None) self.assertEqual(det.rootdir, None)
def test_sum_roi_none_default_roi_defined(self): det = Maxipix(name="Maxipix", sum_roi=None, roi=(2, 252, 1, 35)) self.assertEqual(det.sum_roi, det.roi) self.assertEqual(det.sum_roi, (2, 252, 1, 35))
def test_scandir_datadir_none(self): det = Maxipix(name="Maxipix", datadir=None) self.assertEqual(det.scandir, None)
def test_sum_roi_empty_list(self): det = Maxipix(name="Maxipix", sum_roi=(), roi=(2, 252, 1, 35)) self.assertEqual(det.sum_roi, det.roi) self.assertEqual(det.sum_roi, (2, 252, 1, 35))
def test_rootdir_not_exist(self): with self.assertRaises(ValueError): Maxipix(name="Maxipix", rootdir="this directory does not exist")
def test_template_imagefile_None(self): det = Maxipix(name="Maxipix", template_imagefile=None) self.assertEqual(det.template_imagefile, None)
def test_roi_list_wrong_value_decreasing_y(self): with self.assertRaises(ValueError): Maxipix(name="Maxipix", roi=[128, 0, 12, 35])
def test_rootdir_exists(self): det = Maxipix(name="Maxipix", rootdir=self.valid_path) self.assertEqual(det.rootdir, self.valid_path)
def test_sum_roi_list_wrong_length(self): with self.assertRaises(ValueError): Maxipix(name="Maxipix", sum_roi=[2, 2])
def test_sum_roi_number(self): with self.assertRaises(TypeError): Maxipix(name="Maxipix", sum_roi=2)
def test_rootdir_wrong_type(self): with self.assertRaises(TypeError): Maxipix(name="Maxipix", rootdir=777)
def setUp(self) -> None: self.det = Maxipix("Maxipix") self.data = np.ones(self.det.unbinned_pixel_number) self.mask = np.zeros(self.det.unbinned_pixel_number)
def test_sum_roi_list_wrong_type(self): with self.assertRaises(TypeError): Maxipix(name="Maxipix", sum_roi=[2.0, 512, 12, 35])