Пример #1
0
 def testSortSubWedgesOnExperimentalCondition(self):
     # First check two sub wedges with identical experimental conditions
     list_sub_wedge = self.getTestListSubWedge()
     list_sub_wedge_sorted = UtilsSubWedge.sortSubWedgesOnExperimentalCondition(list_sub_wedge)
     # Check that we got a list with one element
     self.assertEqual(len(list_sub_wedge_sorted), 1)
     # Then modify one sub wedge
     list_sub_wedge_modified = self.getTestListSubWedge()
     list_sub_wedge_modified[1]["experimentalCondition"]["detector"]["distance"] += 100.0
     listSubWedgeSorted = UtilsSubWedge.sortSubWedgesOnExperimentalCondition(list_sub_wedge_modified)
     # Check that we got a list with two elements
     self.assertEqual(len(list_sub_wedge_modified), 2)
Пример #2
0
 def testMergeTwoSubWedgesAdjascentInRotationAxis(self):
     # First check two sub wedges which shouldn't be merged
     list_sub_wedge = self.getTestListSubWedge()
     sub_wedge_1 = list_sub_wedge[0]
     sub_wedge_2 = list_sub_wedge[1]
     sub_wedge_2["experimentalCondition"]["detector"]["distance"] += 100.0
     sub_wedge_should_not_be_merged = UtilsSubWedge.mergeTwoSubWedgesAdjascentInRotationAxis(sub_wedge_1, sub_wedge_2)
     self.assertIsNone(sub_wedge_should_not_be_merged)
     # Then check two adjascent images
     list_sub_wedge = self.getTestListSubWedge()
     sub_wedge_1 = list_sub_wedge[0]
     sub_wedge_2 = list_sub_wedge[1]
     sub_wedge_merged = UtilsSubWedge.mergeTwoSubWedgesAdjascentInRotationAxis(sub_wedge_1, sub_wedge_2)
     self.assertEqual(len(sub_wedge_merged["image"]), 2)
Пример #3
0
 def testSortIdenticalObjects(self):
     listObjects = []
     listSorted = UtilsSubWedge.sortIdenticalObjects(listObjects, UtilsSubWedge.compareTwoValues)
     self.assertEqual(listSorted, [])
     listObjects = [ 1 ]
     listSorted = UtilsSubWedge.sortIdenticalObjects(listObjects, UtilsSubWedge.compareTwoValues)
     self.assertEqual(listSorted, [[1]])
     listObjects = [ 1, 2 ]
     listSorted = UtilsSubWedge.sortIdenticalObjects(listObjects, UtilsSubWedge.compareTwoValues)
     self.assertEqual(listSorted, [[1], [2]])
     listObjects = [ 1, 1 ]
     listSorted = UtilsSubWedge.sortIdenticalObjects(listObjects, UtilsSubWedge.compareTwoValues)
     self.assertEqual(listSorted, [[1, 1]])
     listObjects = [ 1, 2, 1, 3, 4, 1, 5, 2, 2, 9, 3, 2]
     listSorted = UtilsSubWedge.sortIdenticalObjects(listObjects, UtilsSubWedge.compareTwoValues)
     self.assertEqual(listSorted, [[1, 1, 1], [2, 2, 2, 2], [3, 3], [4], [5], [9]])
Пример #4
0
 def run(self, in_data):
     sub_wedge_merge = []
     fast_characterisation = {}
     force_zero_rotation_axis_start = False
     if "fastCharacterisation" in in_data:
         fast_characterisation = in_data["fastCharacterisation"]
         force_zero_rotation_axis_start = fast_characterisation.get(
             "forceZeroRotationAxisStart", False)
         is_fast_characterisation = True
         list_subwedge_angles = fast_characterisation["listSubWedgeAngles"]
         no_images_in_subwedge = fast_characterisation["noImagesInSubWedge"]
         first_image_path = fast_characterisation["firstImagePath"]
         image_number = 1
         template = first_image_path.replace("0001", "{0:04d}")
         list_image_path = []
         for subwedge_angle in list_subwedge_angles:
             for sub_wedge_image_number in range(no_images_in_subwedge):
                 image_path = template.format(image_number)
                 list_image_path.append(image_path)
                 image_number += 1
     elif "imagePath" in in_data:
         list_image_path = in_data["imagePath"]
         is_fast_characterisation = False
         list_subwedge_angles = None
         no_images_in_subwedge = None
     else:
         raise RuntimeError(
             "Neither 'imagePath' nor 'fastCharacterisation' in input data."
         )
     sub_wedge_number = 1
     input_read_image_header = {"imagePath": list_image_path}
     read_image_header = ReadImageHeader(inData=input_read_image_header)
     read_image_header.execute()
     if read_image_header.isSuccess():
         list_subwedge = read_image_header.outData["subWedge"]
         global_axis_start = None
         if force_zero_rotation_axis_start:
             for subwedge in list_subwedge:
                 axis_start = subwedge["experimentalCondition"][
                     "goniostat"]["rotationAxisStart"]
                 if global_axis_start is None or global_axis_start > axis_start:
                     global_axis_start = axis_start
         for index_subwedge, subwedge in enumerate(list_subwedge):
             if is_fast_characterisation:
                 # Modify the start angle
                 index_angle = int(index_subwedge / no_images_in_subwedge)
                 angle_subwedge = list_subwedge_angles[index_angle]
                 goniostat = subwedge["experimentalCondition"]["goniostat"]
                 if force_zero_rotation_axis_start:
                     goniostat["rotationAxisStart"] -= global_axis_start
                 goniostat["rotationAxisStart"] = (
                     goniostat["rotationAxisStart"] + angle_subwedge) % 360
                 goniostat["rotationAxisEnd"] = (
                     goniostat["rotationAxisEnd"] + angle_subwedge) % 360
             else:
                 subwedge["subWedgeNumber"] = index_subwedge + 1
         sub_wedge_merge = UtilsSubWedge.subWedgeMerge(list_subwedge)
     out_data = {"subWedge": sub_wedge_merge}
     return out_data
Пример #5
0
 def testCompareTwoValues(self):
     self.assertTrue(UtilsSubWedge.compareTwoValues(1, 1))
     self.assertFalse(UtilsSubWedge.compareTwoValues(1, 2))
     self.assertTrue(UtilsSubWedge.compareTwoValues(1.0, 1.0))
     self.assertFalse(UtilsSubWedge.compareTwoValues(1.0, 1.01))
     self.assertTrue(UtilsSubWedge.compareTwoValues(1.0, 1.01, 0.1))
     self.assertTrue(UtilsSubWedge.compareTwoValues("EDNA", "EDNA"))
     self.assertFalse(UtilsSubWedge.compareTwoValues("EDNA", "DNA"))
     # Comparison of two different types should raise an exception
     try:
         bTmp = UtilsSubWedge.compareTwoValues("EDNA", 1)
         raise RuntimeError("Problem - exception not raised")
     except:
         self.assertTrue(True)
     # Comparison of anything but double, int or string should raise an exception
     try:
         bTmp = UtilsSubWedge.compareTwoValues([1], [1])
         raise RuntimeError("Problem - exception not raised")
     except:
         self.assertTrue(True)
Пример #6
0
 def testIsSameExperimentalCondition(self):
     exp_cond_ref = self.getTestExperimentalCondition()
     exp_cond_same_as_ref = self.getTestExperimentalCondition()
     self.assertTrue(UtilsSubWedge.isSameExperimentalCondition(exp_cond_ref, exp_cond_same_as_ref))
     exp_cond_different_exp_time = self.getTestExperimentalCondition()
     exp_cond_different_exp_time["beam"]["exposureTime"] += 1
     self.assertFalse(UtilsSubWedge.isSameExperimentalCondition(exp_cond_ref, exp_cond_different_exp_time))
     exp_cond_different_wavelength = self.getTestExperimentalCondition()
     exp_cond_different_wavelength["beam"]["wavelength"] += 1
     self.assertFalse(UtilsSubWedge.isSameExperimentalCondition(exp_cond_ref, exp_cond_different_wavelength))
     exp_cond_different_beam_position_x = self.getTestExperimentalCondition()
     exp_cond_different_beam_position_x["detector"]["beamPositionX"] += 1
     self.assertFalse(UtilsSubWedge.isSameExperimentalCondition(exp_cond_ref, exp_cond_different_beam_position_x))
     exp_cond_different_beam_position_y = self.getTestExperimentalCondition()
     exp_cond_different_beam_position_y["detector"]["beamPositionY"] += 1
     self.assertFalse(UtilsSubWedge.isSameExperimentalCondition(exp_cond_ref, exp_cond_different_beam_position_y))
     exp_cond_different_distance = self.getTestExperimentalCondition()
     exp_cond_different_distance["detector"]["distance"] += 1
     self.assertFalse(UtilsSubWedge.isSameExperimentalCondition(exp_cond_ref, exp_cond_different_distance))
     exp_cond_different_name = self.getTestExperimentalCondition()
     exp_cond_different_name["detector"]["name"] = "EDNA"
     self.assertFalse(UtilsSubWedge.isSameExperimentalCondition(exp_cond_ref, exp_cond_different_name))
     exp_cond_different_number_pixel_x = self.getTestExperimentalCondition()
     exp_cond_different_number_pixel_x["detector"]["numberPixelX"] += 1
     self.assertFalse(UtilsSubWedge.isSameExperimentalCondition(exp_cond_ref, exp_cond_different_number_pixel_x))
     exp_cond_different_number_pixel_y = self.getTestExperimentalCondition()
     exp_cond_different_number_pixel_y["detector"]["numberPixelY"] += 1
     self.assertFalse(UtilsSubWedge.isSameExperimentalCondition(exp_cond_ref, exp_cond_different_number_pixel_y))
     exp_cond_different_serial_number = self.getTestExperimentalCondition()
     exp_cond_different_serial_number["detector"]["serialNumber"] = "EDNA"
     self.assertFalse(UtilsSubWedge.isSameExperimentalCondition(exp_cond_ref, exp_cond_different_serial_number))
     exp_cond_different_two_theta = self.getTestExperimentalCondition()
     exp_cond_different_two_theta["detector"]["twoTheta"] += 1
     self.assertFalse(UtilsSubWedge.isSameExperimentalCondition(exp_cond_ref, exp_cond_different_two_theta))
     exp_cond_different_oscillation_width = self.getTestExperimentalCondition()
     exp_cond_different_oscillation_width["goniostat"]["oscillationWidth"] += 1
     self.assertFalse(UtilsSubWedge.isSameExperimentalCondition(exp_cond_ref, exp_cond_different_oscillation_width))
     exp_cond_different_rotation_axis = self.getTestExperimentalCondition()
     exp_cond_different_rotation_axis["goniostat"]["rotationAxis"] = "EDNA"
     self.assertFalse(UtilsSubWedge.isSameExperimentalCondition(exp_cond_ref, exp_cond_different_rotation_axis))
Пример #7
0
 def testMergeListOfSubWedgesWithAdjascentRotationAxis(self):
     # Check a list of ten adjascent images
     list_of_10_sub_wedges = self.getTestListOf10SubWedges()
     sub_wedge_merged = UtilsSubWedge.mergeListOfSubWedgesWithAdjascentRotationAxis(list_of_10_sub_wedges)
     self.assertEqual(len(sub_wedge_merged[0]["image"]), 10)