def setUp(self): self.img_model = ImgModel() self.mask_model = MaskModel() self.spectrum_model = PatternModel() # setting up the calibration model but mocking the integration for speed self.calibration_model = CalibrationModel(self.img_model) self.calibration_model.num_points = 1000 dummy_x = np.linspace(0, 25, 1000) dummy_y = np.sin(dummy_x) self.calibration_model.integrate_1d = mock.Mock(return_value=(dummy_x, dummy_y)) self.phase_model = PhaseModel() self.widget = IntegrationWidget() self.integration_controller = IntegrationController( {'spectrum': data_path}, widget=self.widget, img_model=self.img_model, mask_model=self.mask_model, calibration_model=self.calibration_model, spectrum_model=self.spectrum_model, phase_model=self.phase_model) self.image_controller = self.integration_controller.image_controller self.calibration_model.load( os.path.join(data_path, 'CeO2_Pilatus1M.poni')) self.img_model.load(os.path.join(data_path, 'CeO2_Pilatus1M.tif'))
def setUp(self): self.img_model = ImgModel() self.mask_model = MaskModel() self.spectrum_model = PatternModel() self.calibration_model = CalibrationModel(self.img_model) self.calibration_model.integrate_1d = MagicMock( return_value=(self.calibration_model.tth, self.calibration_model.int)) self.phase_model = PhaseModel() self.integration_widget = IntegrationWidget() self.integration_controller = IntegrationController( {'spectrum': data_path}, widget=self.integration_widget, img_model=self.img_model, mask_model=self.mask_model, calibration_model=self.calibration_model, spectrum_model=self.spectrum_model, phase_model=self.phase_model) self.calibration_model.load( os.path.join(data_path, 'CeO2_Pilatus1M.poni')) self.img_model.load(os.path.join(data_path, 'CeO2_Pilatus1M.tif')) self.integration_spectrum_controller = self.integration_controller.spectrum_controller self.integration_image_controller = self.integration_controller.image_controller
def main(): print("Let's train your model !") args = parse() model = ImgModel(args.arch, args.hidden_units) if args.gpu: device = 'cuda' else: device = 'cpu' model.to(device) data = get_data(args.data_directory) criterion = torch.nn.NLLLoss() optimizer = torch.optim.Adam(filter(lambda p: p.requires_grad, model.parameters()), lr=args.learning_rate) train(model, data['train'], data['valid'], criterion, optimizer, epochs=args.epochs, device=torch.device(device)) if not (os.path.isdir(args.save_dir)): os.mkdir(args.save_dir) path = args.save_dir + '/model.pth' model.save(path) print("model finished!") return None
def main(): args = parse() model = ImgModel.load(args.model_checkpoint) if args.gpu : device = 'cuda' else : device = 'cpu' model.to(device) prediction = predict(args.image_input,model,torch.device(device),args.top_k) display_prediction(prediction,args.category_names)
def setUp(self): self.widget = IntegrationWidget() self.spectrum_model = PatternModel() self.img_model = ImgModel() self.spectrum_controller = PatternController({}, self.widget, self.img_model, None, None, self.spectrum_model) self.background_controller = BackgroundController({}, self.widget, self.img_model, self.spectrum_model) self.overlay_tw = self.widget.overlay_tw
def setUp(self): self.app = QtGui.QApplication(sys.argv) self.img_model = ImgModel() self.mask_model = MaskModel() self.spectrum_model = SpectrumModel() self.calibration_model = CalibrationModel(self.img_model) self.phase_model = PhaseModel() self.integration_widget = IntegrationWidget() self.integration_controller = IntegrationController({'spectrum': data_path}, widget=self.integration_widget, img_model=self.img_model, mask_model=self.mask_model, calibration_model=self.calibration_model, spectrum_model=self.spectrum_model, phase_model=self.phase_model) self.calibration_model.load(os.path.join(data_path, 'CeO2_Pilatus1M.poni')) self.img_model.load(os.path.join(data_path, 'CeO2_Pilatus1M.tif')) self.integration_spectrum_controller = self.integration_controller.spectrum_controller self.integration_image_controller = self.integration_controller.image_controller
def setUp(self): self.img_model = ImgModel() self.mask_model = MaskModel() self.spectrum_model = PatternModel() self.calibration_model = CalibrationModel(self.img_model) self.calibration_model.integrate_1d = MagicMock(return_value=(self.calibration_model.tth, self.calibration_model.int)) self.phase_model = PhaseModel() self.integration_widget = IntegrationWidget() self.integration_controller = IntegrationController({'spectrum': data_path}, widget=self.integration_widget, img_model=self.img_model, mask_model=self.mask_model, calibration_model=self.calibration_model, spectrum_model=self.spectrum_model, phase_model=self.phase_model) self.calibration_model.load(os.path.join(data_path, 'CeO2_Pilatus1M.poni')) self.img_model.load(os.path.join(data_path, 'CeO2_Pilatus1M.tif')) self.integration_spectrum_controller = self.integration_controller.spectrum_controller self.integration_image_controller = self.integration_controller.image_controller
def setUp(self): self.img_model = ImgModel() self.mask_model = MaskModel() self.spectrum_model = PatternModel() # setting up the calibration model but mocking the integration for speed self.calibration_model = CalibrationModel(self.img_model) self.calibration_model.num_points = 1000 dummy_x = np.linspace(0, 25, 1000) dummy_y = np.sin(dummy_x) self.calibration_model.integrate_1d = mock.Mock(return_value=(dummy_x, dummy_y)) self.phase_model = PhaseModel() self.widget = IntegrationWidget() self.integration_controller = IntegrationController({'spectrum': data_path}, widget=self.widget, img_model=self.img_model, mask_model=self.mask_model, calibration_model=self.calibration_model, spectrum_model=self.spectrum_model, phase_model=self.phase_model) self.image_controller = self.integration_controller.image_controller self.calibration_model.load(os.path.join(data_path, 'CeO2_Pilatus1M.poni')) self.img_model.load(os.path.join(data_path, 'CeO2_Pilatus1M.tif'))
class IntegrationControllerTest(unittest.TestCase): @classmethod def setUpClass(cls): cls.app = QtGui.QApplication([]) @classmethod def tearDownClass(cls): cls.app.quit() cls.app.deleteLater() def setUp(self): self.img_model = ImgModel() self.mask_model = MaskModel() self.spectrum_model = PatternModel() # setting up the calibration model but mocking the integration for speed self.calibration_model = CalibrationModel(self.img_model) self.calibration_model.num_points = 1000 dummy_x = np.linspace(0, 25, 1000) dummy_y = np.sin(dummy_x) self.calibration_model.integrate_1d = mock.Mock(return_value=(dummy_x, dummy_y)) self.phase_model = PhaseModel() self.widget = IntegrationWidget() self.integration_controller = IntegrationController( {'spectrum': data_path}, widget=self.widget, img_model=self.img_model, mask_model=self.mask_model, calibration_model=self.calibration_model, spectrum_model=self.spectrum_model, phase_model=self.phase_model) self.image_controller = self.integration_controller.image_controller self.calibration_model.load( os.path.join(data_path, 'CeO2_Pilatus1M.poni')) self.img_model.load(os.path.join(data_path, 'CeO2_Pilatus1M.tif')) def tearDown(self): del self.calibration_model del self.img_model del self.phase_model del self.widget del self.integration_controller del self.image_controller gc.collect() def _setup_batch_integration(self): # setting up filenames and working directories filenames = ['image_001.tif', 'image_002.tif'] input_filenames = [os.path.join(data_path, f) for f in filenames] working_dir = os.path.join(data_path, 'out') if not os.path.exists(working_dir): os.mkdir(working_dir) self.image_controller.working_dir['spectrum'] = os.path.join( working_dir) self.widget.spec_autocreate_cb.setChecked(True) return filenames, input_filenames, working_dir def test_batch_integration_of_multiple_files(self): filenames, input_filenames, working_dir = self._setup_batch_integration( ) self.image_controller.load_file(input_filenames) for filename in filenames: filename = filename.split('.')[0] + '.xy' filepath = os.path.join(working_dir, filename) self.assertTrue(os.path.exists(filepath)) os.remove(filepath) # cleaning up os.rmdir(working_dir) def test_batch_integration_with_automatic_background_subtraction(self): filenames, input_filenames, working_dir = self._setup_batch_integration( ) self.widget.bkg_spectrum_gb.setChecked(True) self.image_controller.load_file(input_filenames) self.assertTrue( os.path.exists(os.path.join(working_dir, 'bkg_subtracted'))) # check if two kind of files have been saved for filename in filenames: filename = filename.split('.')[0] + '.xy' orig_filepath = os.path.join(working_dir, filename) self.assertTrue(os.path.exists(orig_filepath)) os.remove(orig_filepath) bkg_subtracted_filepath = os.path.join(working_dir, 'bkg_subtracted', filename) self.assertTrue(os.path.exists(bkg_subtracted_filepath)) os.remove(bkg_subtracted_filepath) os.rmdir(os.path.join(working_dir, 'bkg_subtracted')) os.rmdir(working_dir) def test_switching_to_cake_mode_without_having_clicked_the_image_before( self): QTest.mouseClick(self.widget.img_mode_btn, QtCore.Qt.LeftButton) QTest.mouseClick(self.widget.img_mode_btn, QtCore.Qt.LeftButton)
class IntegrationFunctionalTest(unittest.TestCase): @classmethod def setUpClass(cls): cls.app = QtGui.QApplication([]) @classmethod def tearDownClass(cls): cls.app.quit() cls.app.deleteLater() def setUp(self): self.img_model = ImgModel() self.mask_model = MaskModel() self.spectrum_model = PatternModel() self.calibration_model = CalibrationModel(self.img_model) self.calibration_model.integrate_1d = MagicMock(return_value=(self.calibration_model.tth, self.calibration_model.int)) self.phase_model = PhaseModel() self.integration_widget = IntegrationWidget() self.integration_controller = IntegrationController({'spectrum': data_path}, widget=self.integration_widget, img_model=self.img_model, mask_model=self.mask_model, calibration_model=self.calibration_model, spectrum_model=self.spectrum_model, phase_model=self.phase_model) self.calibration_model.load(os.path.join(data_path, 'CeO2_Pilatus1M.poni')) self.img_model.load(os.path.join(data_path, 'CeO2_Pilatus1M.tif')) self.integration_spectrum_controller = self.integration_controller.spectrum_controller self.integration_image_controller = self.integration_controller.image_controller def tearDown(self): del self.integration_spectrum_controller del self.mask_model del self.img_model del self.calibration_model.cake_geometry del self.calibration_model.spectrum_geometry del self.calibration_model del self.integration_widget del self.integration_controller gc.collect() def enter_value_into_text_field(self, text_field, value): text_field.setText('') QTest.keyClicks(text_field, str(value)) QTest.keyPress(text_field, QtCore.Qt.Key_Enter) QtGui.QApplication.processEvents() def test_changing_number_of_integration_bins(self): # Edith wants to change the number of integration bins in order to see the effect of binning onto her line # shape. She sees that there is an option in the X tab and deselects automatic and sees that the sbinbox # becomes editable. self.assertFalse(self.integration_widget.bin_count_txt.isEnabled()) self.integration_widget.automatic_binning_cb.setChecked(False) self.assertTrue(self.integration_widget.bin_count_txt.isEnabled()) # she sees that the current value and wants to double it and notices that the spectrum looks a little bit # smoother previous_number_of_points = len(self.spectrum_model.pattern.x) self.enter_value_into_text_field(self.integration_widget.bin_count_txt, 2 * previous_number_of_points) self.calibration_model.integrate_1d.assert_called_with(num_points=2 * previous_number_of_points, mask=None, unit='2th_deg') # then she decides that having an automatic estimation may probably be better and changes back to automatic. # immediately the number is restored and the image looks like when she started self.integration_widget.automatic_binning_cb.setChecked(True) self.calibration_model.integrate_1d.assert_called_with(num_points=None, mask=None, unit='2th_deg') def test_changing_supersampling_amount_integrating_to_cake_with_mask(self): # Edith opens the program, calibrates everything and looks in to the options menu. She sees that there is a # miraculous parameter called supersampling. It is currently set to 1 which seems to be normal self.assertEqual(self.integration_widget.supersampling_sb.value(), 1) # then she sets it to two and she sees that the number of spectrum bin changes and that the spectrum looks # smoother # values before: px1 = self.calibration_model.spectrum_geometry.pixel1 px2 = self.calibration_model.spectrum_geometry.pixel2 img_shape = self.img_model.img_data.shape self.integration_widget.supersampling_sb.setValue(2) self.assertEqual(self.calibration_model.spectrum_geometry.pixel1, 0.5 * px1) self.assertEqual(self.calibration_model.spectrum_geometry.pixel2, 0.5 * px2) self.assertEqual(self.calibration_model.cake_geometry.pixel1, px1) self.assertEqual(self.calibration_model.cake_geometry.pixel2, px2) self.assertEqual(self.img_model.img_data.shape[0], 2 * img_shape[0]) self.assertEqual(self.img_model.img_data.shape[1], 2 * img_shape[1]) self.mask_model.load_mask(os.path.join(data_path, 'test.mask')) QTest.mouseClick(self.integration_widget.img_mask_btn, QtCore.Qt.LeftButton) QTest.mouseClick(self.integration_widget.img_mode_btn, QtCore.Qt.LeftButton) def test_saving_image(self): # the widget has to be shown to be able to save the image: self.integration_widget.show() # Tests if the image save procedures are working for the different possible file endings self.integration_image_controller.save_img(os.path.join(data_path, 'Test_img.png')) self.integration_image_controller.save_img(os.path.join(data_path, 'Test_img.tiff')) self.assertTrue(os.path.exists(os.path.join(data_path, 'Test_img.png'))) self.assertTrue(os.path.exists(os.path.join(data_path, 'Test_img.tiff'))) os.remove(os.path.join(data_path, 'Test_img.png')) os.remove(os.path.join(data_path, 'Test_img.tiff')) def test_saving_spectrum(self): # the widget has to be shown to be able to save the image: self.integration_widget.show() # Tests if the spectrum save procedures is are working for all fileendings def save_spectra_test_for_size_and_delete(self): self.integration_spectrum_controller.save_pattern(os.path.join(data_path, 'Test_spec.xy')) self.integration_spectrum_controller.save_pattern(os.path.join(data_path, 'Test_spec.chi')) self.integration_spectrum_controller.save_pattern(os.path.join(data_path, 'Test_spec.dat')) self.integration_spectrum_controller.save_pattern(os.path.join(data_path, 'Test_spec.png')) self.integration_spectrum_controller.save_pattern(os.path.join(data_path, 'Test_spec.svg')) self.assertTrue(os.path.exists(os.path.join(data_path, 'Test_spec.xy'))) self.assertTrue(os.path.exists(os.path.join(data_path, 'Test_spec.chi'))) self.assertTrue(os.path.exists(os.path.join(data_path, 'Test_spec.dat'))) self.assertTrue(os.path.exists(os.path.join(data_path, 'Test_spec.png'))) self.assertTrue(os.path.exists(os.path.join(data_path, 'Test_spec.svg'))) self.assertGreater(os.stat(os.path.join(data_path, 'Test_spec.xy')).st_size, 1) self.assertGreater(os.stat(os.path.join(data_path, 'Test_spec.chi')).st_size, 1) self.assertGreater(os.stat(os.path.join(data_path, 'Test_spec.dat')).st_size, 1) self.assertGreater(os.stat(os.path.join(data_path, 'Test_spec.png')).st_size, 1) self.assertGreater(os.stat(os.path.join(data_path, 'Test_spec.svg')).st_size, 1) os.remove(os.path.join(data_path, 'Test_spec.xy')) os.remove(os.path.join(data_path, 'Test_spec.chi')) os.remove(os.path.join(data_path, 'Test_spec.dat')) os.remove(os.path.join(data_path, 'Test_spec.png')) os.remove(os.path.join(data_path, 'Test_spec.svg')) save_spectra_test_for_size_and_delete(self) QTest.mouseClick(self.integration_spectrum_controller.widget.spec_q_btn, QtCore.Qt.LeftButton) save_spectra_test_for_size_and_delete(self) QTest.mouseClick(self.integration_spectrum_controller.widget.spec_d_btn, QtCore.Qt.LeftButton) save_spectra_test_for_size_and_delete(self) def test_undocking_and_docking_img_frame(self): QTest.mouseClick(self.integration_widget.img_dock_btn, QtCore.Qt.LeftButton) QTest.mouseClick(self.integration_widget.img_dock_btn, QtCore.Qt.LeftButton) def test_loading_multiple_images_and_batch_integrate_them(self): self.integration_widget.spec_autocreate_cb.setChecked(True) self.assertTrue(self.integration_widget.spec_autocreate_cb.isChecked()) self.integration_image_controller.load_file([os.path.join(data_path, 'image_001.tif'), os.path.join(data_path, 'image_002.tif')]) self.assertTrue(os.path.exists(os.path.join(data_path, 'image_001.xy'))) self.assertTrue(os.path.exists(os.path.join(data_path, 'image_002.xy'))) os.remove(os.path.join(data_path, 'image_001.xy')) os.remove(os.path.join(data_path, 'image_002.xy'))
class IntegrationControllerTest(unittest.TestCase): @classmethod def setUpClass(cls): cls.app = QtGui.QApplication([]) @classmethod def tearDownClass(cls): cls.app.quit() cls.app.deleteLater() def setUp(self): self.img_model = ImgModel() self.mask_model = MaskModel() self.spectrum_model = PatternModel() # setting up the calibration model but mocking the integration for speed self.calibration_model = CalibrationModel(self.img_model) self.calibration_model.num_points = 1000 dummy_x = np.linspace(0, 25, 1000) dummy_y = np.sin(dummy_x) self.calibration_model.integrate_1d = mock.Mock(return_value=(dummy_x, dummy_y)) self.phase_model = PhaseModel() self.widget = IntegrationWidget() self.integration_controller = IntegrationController({'spectrum': data_path}, widget=self.widget, img_model=self.img_model, mask_model=self.mask_model, calibration_model=self.calibration_model, spectrum_model=self.spectrum_model, phase_model=self.phase_model) self.image_controller = self.integration_controller.image_controller self.calibration_model.load(os.path.join(data_path, 'CeO2_Pilatus1M.poni')) self.img_model.load(os.path.join(data_path, 'CeO2_Pilatus1M.tif')) def tearDown(self): del self.calibration_model del self.img_model del self.phase_model del self.widget del self.integration_controller del self.image_controller gc.collect() def _setup_batch_integration(self): # setting up filenames and working directories filenames = ['image_001.tif', 'image_002.tif'] input_filenames = [os.path.join(data_path, f) for f in filenames] working_dir = os.path.join(data_path, 'out') if not os.path.exists(working_dir): os.mkdir(working_dir) self.image_controller.working_dir['spectrum'] = os.path.join(working_dir) self.widget.spec_autocreate_cb.setChecked(True) return filenames, input_filenames, working_dir def test_batch_integration_of_multiple_files(self): filenames, input_filenames, working_dir = self._setup_batch_integration() self.image_controller.load_file(input_filenames) for filename in filenames: filename = filename.split('.')[0] + '.xy' filepath = os.path.join(working_dir, filename) self.assertTrue(os.path.exists(filepath)) os.remove(filepath) # cleaning up os.rmdir(working_dir) def test_batch_integration_with_automatic_background_subtraction(self): filenames, input_filenames, working_dir = self._setup_batch_integration() self.widget.bkg_spectrum_gb.setChecked(True) self.image_controller.load_file(input_filenames) self.assertTrue(os.path.exists(os.path.join(working_dir, 'bkg_subtracted'))) # check if two kind of files have been saved for filename in filenames: filename = filename.split('.')[0] + '.xy' orig_filepath = os.path.join(working_dir, filename) self.assertTrue(os.path.exists(orig_filepath)) os.remove(orig_filepath) bkg_subtracted_filepath = os.path.join(working_dir, 'bkg_subtracted', filename) self.assertTrue(os.path.exists(bkg_subtracted_filepath)) os.remove(bkg_subtracted_filepath) os.rmdir(os.path.join(working_dir, 'bkg_subtracted')) os.rmdir(working_dir) def test_switching_to_cake_mode_without_having_clicked_the_image_before(self): QTest.mouseClick(self.widget.img_mode_btn, QtCore.Qt.LeftButton) QTest.mouseClick(self.widget.img_mode_btn, QtCore.Qt.LeftButton)
class IntegrationFunctionalTest(unittest.TestCase): @classmethod def setUpClass(cls): cls.app = QtGui.QApplication([]) @classmethod def tearDownClass(cls): cls.app.quit() cls.app.deleteLater() def setUp(self): self.img_model = ImgModel() self.mask_model = MaskModel() self.spectrum_model = PatternModel() self.calibration_model = CalibrationModel(self.img_model) self.calibration_model.integrate_1d = MagicMock( return_value=(self.calibration_model.tth, self.calibration_model.int)) self.phase_model = PhaseModel() self.integration_widget = IntegrationWidget() self.integration_controller = IntegrationController( {'spectrum': data_path}, widget=self.integration_widget, img_model=self.img_model, mask_model=self.mask_model, calibration_model=self.calibration_model, spectrum_model=self.spectrum_model, phase_model=self.phase_model) self.calibration_model.load( os.path.join(data_path, 'CeO2_Pilatus1M.poni')) self.img_model.load(os.path.join(data_path, 'CeO2_Pilatus1M.tif')) self.integration_spectrum_controller = self.integration_controller.spectrum_controller self.integration_image_controller = self.integration_controller.image_controller def tearDown(self): del self.integration_spectrum_controller del self.mask_model del self.img_model del self.calibration_model.cake_geometry del self.calibration_model.spectrum_geometry del self.calibration_model del self.integration_widget del self.integration_controller gc.collect() def enter_value_into_text_field(self, text_field, value): text_field.setText('') QTest.keyClicks(text_field, str(value)) QTest.keyPress(text_field, QtCore.Qt.Key_Enter) QtGui.QApplication.processEvents() def test_changing_number_of_integration_bins(self): # Edith wants to change the number of integration bins in order to see the effect of binning onto her line # shape. She sees that there is an option in the X tab and deselects automatic and sees that the sbinbox # becomes editable. self.assertFalse(self.integration_widget.bin_count_txt.isEnabled()) self.integration_widget.automatic_binning_cb.setChecked(False) self.assertTrue(self.integration_widget.bin_count_txt.isEnabled()) # she sees that the current value and wants to double it and notices that the spectrum looks a little bit # smoother previous_number_of_points = len(self.spectrum_model.pattern.x) self.enter_value_into_text_field(self.integration_widget.bin_count_txt, 2 * previous_number_of_points) self.calibration_model.integrate_1d.assert_called_with( num_points=2 * previous_number_of_points, mask=None, unit='2th_deg') # then she decides that having an automatic estimation may probably be better and changes back to automatic. # immediately the number is restored and the image looks like when she started self.integration_widget.automatic_binning_cb.setChecked(True) self.calibration_model.integrate_1d.assert_called_with(num_points=None, mask=None, unit='2th_deg') def test_changing_supersampling_amount_integrating_to_cake_with_mask(self): # Edith opens the program, calibrates everything and looks in to the options menu. She sees that there is a # miraculous parameter called supersampling. It is currently set to 1 which seems to be normal self.assertEqual(self.integration_widget.supersampling_sb.value(), 1) # then she sets it to two and she sees that the number of spectrum bin changes and that the spectrum looks # smoother # values before: px1 = self.calibration_model.spectrum_geometry.pixel1 px2 = self.calibration_model.spectrum_geometry.pixel2 img_shape = self.img_model.img_data.shape self.integration_widget.supersampling_sb.setValue(2) self.assertEqual(self.calibration_model.spectrum_geometry.pixel1, 0.5 * px1) self.assertEqual(self.calibration_model.spectrum_geometry.pixel2, 0.5 * px2) self.assertEqual(self.calibration_model.cake_geometry.pixel1, px1) self.assertEqual(self.calibration_model.cake_geometry.pixel2, px2) self.assertEqual(self.img_model.img_data.shape[0], 2 * img_shape[0]) self.assertEqual(self.img_model.img_data.shape[1], 2 * img_shape[1]) self.mask_model.load_mask(os.path.join(data_path, 'test.mask')) QTest.mouseClick(self.integration_widget.img_mask_btn, QtCore.Qt.LeftButton) QTest.mouseClick(self.integration_widget.img_mode_btn, QtCore.Qt.LeftButton) def test_saving_image(self): # the widget has to be shown to be able to save the image: self.integration_widget.show() # Tests if the image save procedures are working for the different possible file endings self.integration_image_controller.save_img( os.path.join(data_path, 'Test_img.png')) self.integration_image_controller.save_img( os.path.join(data_path, 'Test_img.tiff')) self.assertTrue(os.path.exists(os.path.join(data_path, 'Test_img.png'))) self.assertTrue( os.path.exists(os.path.join(data_path, 'Test_img.tiff'))) os.remove(os.path.join(data_path, 'Test_img.png')) os.remove(os.path.join(data_path, 'Test_img.tiff')) def test_saving_spectrum(self): # the widget has to be shown to be able to save the image: self.integration_widget.show() # Tests if the spectrum save procedures is are working for all fileendings def save_spectra_test_for_size_and_delete(self): self.integration_spectrum_controller.save_pattern( os.path.join(data_path, 'Test_spec.xy')) self.integration_spectrum_controller.save_pattern( os.path.join(data_path, 'Test_spec.chi')) self.integration_spectrum_controller.save_pattern( os.path.join(data_path, 'Test_spec.dat')) self.integration_spectrum_controller.save_pattern( os.path.join(data_path, 'Test_spec.png')) self.integration_spectrum_controller.save_pattern( os.path.join(data_path, 'Test_spec.svg')) self.assertTrue( os.path.exists(os.path.join(data_path, 'Test_spec.xy'))) self.assertTrue( os.path.exists(os.path.join(data_path, 'Test_spec.chi'))) self.assertTrue( os.path.exists(os.path.join(data_path, 'Test_spec.dat'))) self.assertTrue( os.path.exists(os.path.join(data_path, 'Test_spec.png'))) self.assertTrue( os.path.exists(os.path.join(data_path, 'Test_spec.svg'))) self.assertGreater( os.stat(os.path.join(data_path, 'Test_spec.xy')).st_size, 1) self.assertGreater( os.stat(os.path.join(data_path, 'Test_spec.chi')).st_size, 1) self.assertGreater( os.stat(os.path.join(data_path, 'Test_spec.dat')).st_size, 1) self.assertGreater( os.stat(os.path.join(data_path, 'Test_spec.png')).st_size, 1) self.assertGreater( os.stat(os.path.join(data_path, 'Test_spec.svg')).st_size, 1) os.remove(os.path.join(data_path, 'Test_spec.xy')) os.remove(os.path.join(data_path, 'Test_spec.chi')) os.remove(os.path.join(data_path, 'Test_spec.dat')) os.remove(os.path.join(data_path, 'Test_spec.png')) os.remove(os.path.join(data_path, 'Test_spec.svg')) save_spectra_test_for_size_and_delete(self) QTest.mouseClick( self.integration_spectrum_controller.widget.spec_q_btn, QtCore.Qt.LeftButton) save_spectra_test_for_size_and_delete(self) QTest.mouseClick( self.integration_spectrum_controller.widget.spec_d_btn, QtCore.Qt.LeftButton) save_spectra_test_for_size_and_delete(self) def test_undocking_and_docking_img_frame(self): QTest.mouseClick(self.integration_widget.img_dock_btn, QtCore.Qt.LeftButton) QTest.mouseClick(self.integration_widget.img_dock_btn, QtCore.Qt.LeftButton) def test_loading_multiple_images_and_batch_integrate_them(self): self.integration_widget.spec_autocreate_cb.setChecked(True) self.assertTrue(self.integration_widget.spec_autocreate_cb.isChecked()) self.integration_image_controller.load_file([ os.path.join(data_path, 'image_001.tif'), os.path.join(data_path, 'image_002.tif') ]) self.assertTrue(os.path.exists(os.path.join(data_path, 'image_001.xy'))) self.assertTrue(os.path.exists(os.path.join(data_path, 'image_002.xy'))) os.remove(os.path.join(data_path, 'image_001.xy')) os.remove(os.path.join(data_path, 'image_002.xy'))