def setUp(self): self.jcpds = jcpds() self.jcpds.compute_v0() self.jcpds.load_file(os.path.join(jcpds_path, 'au_Anderson.jcpds')) self.jcpds_editor_widget = JcpdsEditorWidget() self.jcpds_editor_widget.show_jcpds(self.jcpds, wavelength=0.31)
def setUp(self): self.calibration_model = CalibrationModel() dummy_x = np.linspace(0, 30) dummy_y = np.ones(dummy_x.shape) self.calibration_model.integrate_1d = MagicMock(return_value=(dummy_x, dummy_y)) self.jcpds = jcpds()
def add_jcpds(self, filename): try: jcpds_object = jcpds() jcpds_object.load_file(filename) self.phases.append(jcpds_object) self.reflections.append([]) except (ZeroDivisionError, UnboundLocalError, ValueError): raise PhaseLoadError(filename)
def setUp(self): self.jcpds = jcpds()
def test_reflection_editing_and_saving_of_files(self): # Erwin has selected a gold jcpds in the Dioptas interface with cubic symmetry # and wants to look for the reflections entered self.jcpds = jcpds() self.jcpds.load_file(os.path.join(jcpds_path, 'au_Anderson.jcpds')) self.jcpds_controller = JcpdsEditorController(jcpds_path, None, jcpds_phase=self.jcpds) self.jcpds_widget = self.jcpds_controller.widget # he sees that there are 13 reflections predefined in the table self.assertEqual(self.jcpds_widget.reflection_table.rowCount(), 13) # he checks if the values are correct: self.assertAlmostEqual(self.get_reflection_table_value(0, 4), 2.355, delta=0.001) self.assertEqual(self.get_reflection_table_value(1, 1), 0) self.assertAlmostEqual(self.get_reflection_table_value(12, 4), 0.6449, delta=0.0001) self.assertEqual(self.get_reflection_table_value(12, 3), 10) # then he decides to change the lattice parameter and sees that the values in the table are changing: self.enter_value_into_spinbox(self.jcpds_widget.lattice_a_sb, 4) self.assertEqual(self.jcpds_widget.reflection_table.rowCount(), 13) self.assertEqual(self.get_reflection_table_value(1, 4), 2) # After playing with the lattice parameter he sets it back to the original value and looks at the reflections # He thinks that he doesn't need the sixth reflection because it any way has to low intensity self.enter_value_into_spinbox(self.jcpds_widget.lattice_a_sb, 4.0786) self.jcpds_widget.reflection_table.selectRow(5) QTest.mouseClick(self.jcpds_widget.reflections_delete_btn, QtCore.Qt.LeftButton) self.assertEqual(self.jcpds_widget.reflection_table.rowCount(), 12) self.assertAlmostEqual(self.get_reflection_table_value(5, 4), 0.9358, delta=0.0002) self.assertEqual(len(self.jcpds.reflections), 12) # then he changed his mind and wants to add the reflection back: QTest.mouseClick(self.jcpds_widget.reflections_add_btn, QtCore.Qt.LeftButton) QtGui.QApplication.processEvents() self.assertEqual(len(self.jcpds.reflections), 13) self.assertEqual(self.jcpds_widget.reflection_table.rowCount(), 13) self.assertEqual(self.jcpds_widget.get_selected_reflections()[0], 12) self.assertEqual(self.get_reflection_table_value(12, 0), 0) # h self.assertEqual(self.get_reflection_table_value(12, 1), 0) # k self.assertEqual(self.get_reflection_table_value(12, 2), 0) # l self.assertEqual(self.get_reflection_table_value(12, 3), 0) # intensity self.assertEqual(self.get_reflection_table_value(12, 4), 0) # d # then he edits he and realizes how the d spacings are magically calculated self.insert_reflection_table_value(12, 0, 1) self.assertEqual(self.get_reflection_table_value(12, 4), 4.0786) self.insert_reflection_table_value(12, 1, 1) self.assertAlmostEqual(self.get_reflection_table_value(12, 4), calculate_cubic_d_spacing(1, 1, 0, 4.0786), delta=0.0001) self.insert_reflection_table_value(12, 2, 3) self.assertAlmostEqual(self.get_reflection_table_value(12, 4), calculate_cubic_d_spacing(1, 1, 3, 4.0786), delta=0.0001) # then she decides that everybody should screw with the table and clears it: QTest.mouseClick(self.jcpds_widget.reflections_clear_btn, QtCore.Qt.LeftButton) self.assertEqual(self.jcpds_widget.reflection_table.rowCount(), 0) self.assertEqual(len(self.jcpds.reflections), 0) self.assertEqual(len(self.jcpds_widget.get_selected_reflections()), 0) # he finds this phase much more promising and wants to give it a new name self.enter_value_into_text_field(self.jcpds_widget.comments_txt, 'HAHA this is a phase you will never see in your spectrum') self.assertEqual(self.jcpds.comments[0], 'HAHA this is a phase you will never see in your spectrum') # then he sees the save_as button and is happy to save his non-sense for later users filename = os.path.join(jcpds_path, 'au_mal_anders.jcpds') self.jcpds_controller.save_as_btn_clicked(filename) self.assertTrue(os.path.exists(filename)) # he decides to change the lattice parameter and then reload the file to see if everything is ok self.enter_value_into_spinbox(self.jcpds_widget.lattice_a_sb, 10) self.jcpds.load_file(filename) self.jcpds_controller = JcpdsEditorController(jcpds_path, None, jcpds_phase=self.jcpds) self.jcpds_widget = self.jcpds_controller.widget self.assertEqual(float(str(self.jcpds_widget.lattice_a_sb.text())), 4.0786) self.assertEqual(float(str(self.jcpds_widget.lattice_b_sb.text())), 4.0786) self.assertEqual(float(str(self.jcpds_widget.lattice_c_sb.text())), 4.0786) # then he decides to make this phase it little bit more useful and adds some peaks and saves this as a different # version and trys to load it again... QTest.mouseClick(self.jcpds_widget.reflections_add_btn, QtCore.Qt.LeftButton) QTest.mouseClick(self.jcpds_widget.reflections_add_btn, QtCore.Qt.LeftButton) QTest.mouseClick(self.jcpds_widget.reflections_add_btn, QtCore.Qt.LeftButton) self.insert_reflection_table_value(0, 0, 1) self.insert_reflection_table_value(0, 3, 100) self.insert_reflection_table_value(1, 1, 1) self.insert_reflection_table_value(1, 3, 50) self.insert_reflection_table_value(2, 2, 1) self.insert_reflection_table_value(2, 3, 20) filename = os.path.join(jcpds_path, 'au_mal_anders_vers2.jcpds') self.jcpds_controller.save_as_btn_clicked(filename) self.jcpds.load_file(filename) self.jcpds_controller = JcpdsEditorController(jcpds_path, None, jcpds_phase=self.jcpds)
def test_reflection_editing_and_saving_of_files(self): # Erwin has selected a gold jcpds in the Dioptas interface with cubic symmetry # and wants to look for the reflections entered self.jcpds = jcpds() self.jcpds.load_file(os.path.join(jcpds_path, 'au_Anderson.jcpds')) self.jcpds_controller = JcpdsEditorController(jcpds_path, None, jcpds_phase=self.jcpds) self.jcpds_widget = self.jcpds_controller.widget # he sees that there are 13 reflections predefined in the table self.assertEqual(self.jcpds_widget.reflection_table.rowCount(), 13) # he checks if the values are correct: self.assertAlmostEqual(self.get_reflection_table_value(0, 4), 2.355, delta=0.001) self.assertEqual(self.get_reflection_table_value(1, 1), 0) self.assertAlmostEqual(self.get_reflection_table_value(12, 4), 0.6449, delta=0.0001) self.assertEqual(self.get_reflection_table_value(12, 3), 10) # then he decides to change the lattice parameter and sees that the values in the table are changing: self.enter_value_into_spinbox(self.jcpds_widget.lattice_a_sb, 4) self.assertEqual(self.jcpds_widget.reflection_table.rowCount(), 13) self.assertEqual(self.get_reflection_table_value(1, 4), 2) # After playing with the lattice parameter he sets it back to the original value and looks at the reflections # He thinks that he doesn't need the sixth reflection because it any way has to low intensity self.enter_value_into_spinbox(self.jcpds_widget.lattice_a_sb, 4.0786) self.jcpds_widget.reflection_table.selectRow(5) QTest.mouseClick(self.jcpds_widget.reflections_delete_btn, QtCore.Qt.LeftButton) self.assertEqual(self.jcpds_widget.reflection_table.rowCount(), 12) self.assertAlmostEqual(self.get_reflection_table_value(5, 4), 0.9358, delta=0.0002) self.assertEqual(len(self.jcpds.reflections), 12) # then he changed his mind and wants to add the reflection back: QTest.mouseClick(self.jcpds_widget.reflections_add_btn, QtCore.Qt.LeftButton) QtGui.QApplication.processEvents() self.assertEqual(len(self.jcpds.reflections), 13) self.assertEqual(self.jcpds_widget.reflection_table.rowCount(), 13) self.assertEqual(self.jcpds_widget.get_selected_reflections()[0], 12) self.assertEqual(self.get_reflection_table_value(12, 0), 0) # h self.assertEqual(self.get_reflection_table_value(12, 1), 0) # k self.assertEqual(self.get_reflection_table_value(12, 2), 0) # l self.assertEqual(self.get_reflection_table_value(12, 3), 0) # intensity self.assertEqual(self.get_reflection_table_value(12, 4), 0) # d # then he edits he and realizes how the d spacings are magically calculated self.insert_reflection_table_value(12, 0, 1) self.assertEqual(self.get_reflection_table_value(12, 4), 4.0786) self.insert_reflection_table_value(12, 1, 1) self.assertAlmostEqual(self.get_reflection_table_value(12, 4), calculate_cubic_d_spacing(1, 1, 0, 4.0786), delta=0.0001) self.insert_reflection_table_value(12, 2, 3) self.assertAlmostEqual(self.get_reflection_table_value(12, 4), calculate_cubic_d_spacing(1, 1, 3, 4.0786), delta=0.0001) # then she decides that everybody should screw with the table and clears it: QTest.mouseClick(self.jcpds_widget.reflections_clear_btn, QtCore.Qt.LeftButton) self.assertEqual(self.jcpds_widget.reflection_table.rowCount(), 0) self.assertEqual(len(self.jcpds.reflections), 0) self.assertEqual(len(self.jcpds_widget.get_selected_reflections()), 0) # he finds this phase much more promising and wants to give it a new name self.enter_value_into_text_field( self.jcpds_widget.comments_txt, 'HAHA this is a phase you will never see in your spectrum') self.assertEqual( self.jcpds.comments[0], 'HAHA this is a phase you will never see in your spectrum') # then he sees the save_as button and is happy to save his non-sense for later users filename = os.path.join(jcpds_path, 'au_mal_anders.jcpds') self.jcpds_controller.save_as_btn_clicked(filename) self.assertTrue(os.path.exists(filename)) # he decides to change the lattice parameter and then reload the file to see if everything is ok self.enter_value_into_spinbox(self.jcpds_widget.lattice_a_sb, 10) self.jcpds.load_file(filename) self.jcpds_controller = JcpdsEditorController(jcpds_path, None, jcpds_phase=self.jcpds) self.jcpds_widget = self.jcpds_controller.widget self.assertEqual(float(str(self.jcpds_widget.lattice_a_sb.text())), 4.0786) self.assertEqual(float(str(self.jcpds_widget.lattice_b_sb.text())), 4.0786) self.assertEqual(float(str(self.jcpds_widget.lattice_c_sb.text())), 4.0786) # then he decides to make this phase it little bit more useful and adds some peaks and saves this as a different # version and trys to load it again... QTest.mouseClick(self.jcpds_widget.reflections_add_btn, QtCore.Qt.LeftButton) QTest.mouseClick(self.jcpds_widget.reflections_add_btn, QtCore.Qt.LeftButton) QTest.mouseClick(self.jcpds_widget.reflections_add_btn, QtCore.Qt.LeftButton) self.insert_reflection_table_value(0, 0, 1) self.insert_reflection_table_value(0, 3, 100) self.insert_reflection_table_value(1, 1, 1) self.insert_reflection_table_value(1, 3, 50) self.insert_reflection_table_value(2, 2, 1) self.insert_reflection_table_value(2, 3, 20) filename = os.path.join(jcpds_path, 'au_mal_anders_vers2.jcpds') self.jcpds_controller.save_as_btn_clicked(filename) self.jcpds.load_file(filename) self.jcpds_controller = JcpdsEditorController(jcpds_path, None, jcpds_phase=self.jcpds)